Just have a quick question about GLKit in the iOS 5.0 framework.
If you use GLKTextureLoader, does it just load the texture in the currently active texture unit? I've looked at examples and I don't see anywhere that you have to say the GLKTextureInfo in variable x is bound to GL_TEXTURE0.
I've seen examples where people use glActiveTexture in conjunction with GLKTextureLoader, but it looks like the texture just automagically gets locked into the active texture unit. Once I load it, I just have to pass in texture coordinates?
Thanks in advance.
Yes, there is some automagic going on. After loading a 2nd texture, that texture would then be bound to GL_TEXTURE0 but if you want it in GL_TEXTURE1:
glActiveTexture(GL_TEXTURE1);
glBindTexture(someTexture.target, someTexture.name);
glUniform1i(u_someSampler, 1); // u_someSampler retrieved from prev call to glGetUniformLocation
After GLKTextureLoader loads your GLKTextureInfo object, then you're ready to bind the texture yourself. So when GLKLTextureLoader has finished loading, your loaded texture is not bound to any texture unit. When you're ready to draw, you call:
glActiveTexture(GL_TEXTURE0); // to specify texture unit 0
glBindTexture(textureInfo.target, textureInfo.name);
I would highly reccommend the book Learning OpenGL ES for iOS: A Hands-On Guide to Modern 3D Graphics Programming, as it does a great job of demonstrating what goes on inside the GLKit classes. You could also reference this demo code I wrote, which uses GLKTextureLoader: https://github.com/joekim/MobileMeetup/tree/master/GLKitDemo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With