Using texture in GL shader in ARKit


Using texture in GL shader in ARKit



I am trying to use GLKTextureLoader to load a texture into a custom shader written in GLSL. It loads all the vertex and fragment shader bits just fine, but when I try to load a texture it quits.



This is how I'm trying to accomplish it:


do {
guard let CGImage = #imageLiteral(resourceName: "image01").cgImage else { print("no CGImage"); return nil}
let texture = try GLKTextureLoader.texture(with: CGImage, options: nil)
} catch {
print("Texture not loaded", (error))
}



it seems to get the CGImage, but fails on the GLKTextureLoader.texture bit.
Here is the error:


GLKTextureLoader.texture


Error Domain=GLKTextureLoaderErrorDomain Code=17 "(null)" UserInfo={GLKTextureLoaderErrorKey=Invalid EAGL context}



I've tried logging the GL errors with NSLog("GL Error = %u", glGetError()); but that just gives me GL Error = 0


NSLog("GL Error = %u", glGetError());


GL Error = 0



This is the first real project I'm trying with swift, is there something obvious I'm missing? Or is mixing ARKit with GLSL shaders just impossible?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV