Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the function of glActiveTexture and GL_TEXTURE0 in OpenGL?

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.

like image 301
Bình Nguyên Avatar asked Jan 09 '13 08:01

Bình Nguyên


People also ask

What does glActiveTexture do?

glActiveTexture selects the active texture unit, and glBindTexture binds a texture to the active texture unit.

How do I disable texture in opengl?

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) .


1 Answers

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.

like image 81
datenwolf Avatar answered Sep 28 '22 10:09

datenwolf