I'm finding a way to understand why glActiveTexture
is needed. I have the code below:
glGenTextures(1, &textureId); glBindTexture(GL_TEXTURE_2D, textureId);
If I imagine that the GL_TEXTURE_2D
is a picture's frame hanging on the wall and textureId
is the real picture, the glBindTexture
is the only command for assigning a real picture to the frame, so, what are GL_TEXTURE0
and glActiveTexture
?
Will my code below work fine?
glActiveTexture(GL_TEXTURE0); glGenTextures(1, &textureId); glBindTexture(GL_TEXTURE_2D, textureId); glActiveTexture(GL_TEXTURE1); glTexImage2D(GL_TEXTURE_2D, .....) glTexParameteri(GL_TEXTURE_2D, ...)
I'm currently working with OpenGL2.1.
glActiveTexture selects the active texture unit, and glBindTexture binds a texture to the active texture unit.
In your case, the target would be GL_TEXTURE_2D . So to answer your question: Select the texture-unit i by using glActiveTexture(GL_TEXTURE0+i) and then disable it with glDisable(GL_TEXTURE_2D) .
If I imagine that the GL_TEXTURE_2D is a picture's frame hangging on the wall and textureId is the real picture,
Actually a very good analogy :)
so, what GL_TEXTURE0 and glActiveTexture are?
Think about a wall with multiple picture frames, the first frame being labeled GL_TEXTURE0, the second GL_TEXTURE1 and so on.
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