OpenGL中的glActiveTexture和GL_TEXTURE0的功能是什么? [英] What is the function of glActiveTexture and GL_TEXTURE0 in OpenGL?
问题描述
我正在寻找一种理解为什么需要glActiveTexture
的方法.我有以下代码:
I'm finding a way to understand why glActiveTexture
is needed. I have the code below:
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
如果我想像GL_TEXTURE_2D
是挂在墙上的图片框架,而textureId
是真实的图片,则glBindTexture
是向该框架分配真实图片的唯一命令,那么GL_TEXTURE0
和glActiveTexture
?
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, ...)
我目前正在使用OpenGL2.1.
I'm currently working with OpenGL2.1.
推荐答案
如果我以为GL_TEXTURE_2D是挂在墙上的图片框架,而textureId是真实的图片,
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 :)
那么,GL_TEXTURE0和glActiveTexture是什么?
so, what GL_TEXTURE0 and glActiveTexture are?
考虑一面有多个画框的墙,第一个画框标记为GL_TEXTURE0,第二个画框标记为GL_TEXTURE1,依此类推.
Think about a wall with multiple picture frames, the first frame being labeled GL_TEXTURE0, the second GL_TEXTURE1 and so on.
这篇关于OpenGL中的glActiveTexture和GL_TEXTURE0的功能是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!