简体   繁体   English

在OpenGL中glActiveTexture和GL_TEXTURE0的功能是什么?

[英]What is the function of glActiveTexture and GL_TEXTURE0 in OpenGL?

I'm finding a way to understand why glActiveTexture is needed. 我正在找到一种方法来理解为什么需要glActiveTexture 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 ? 如果我想象GL_TEXTURE_2D是挂在墙上的图片框架而textureId是真实图片,那么glBindTexture是唯一一个为帧分配实际图片的命令,那么, GL_TEXTURE0glActiveTexture什么?

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. 我目前正在使用OpenGL2.1。

If I imagine that the GL_TEXTURE_2D is a picture's frame hangging on the wall and textureId is the real picture, 如果我想象GL_TEXTURE_2D是挂在墙上的图片框架而textureId是真实的图片,

Actually a very good analogy :) 其实这是一个非常好的比喻:)

so, what GL_TEXTURE0 and glActiveTexture are? 那么,GL_TEXTURE0和glActiveTexture是什么?

Think about a wall with multiple picture frames, the first frame being labeled GL_TEXTURE0, the second GL_TEXTURE1 and so on. 想想有多个相框的墙,第一帧标记为GL_TEXTURE0,第二帧标记为GL_TEXTURE1,依此类推。

OpenGL introduced multitexturing at some point (which is basically using more than one texture on one geometry pass ); OpenGL在某个时刻引入了多重纹理(基本上在一个几何通道上使用了多个纹理 ); in order to keep older code working, they couldn't just add additional parameter to all the functions. 为了使旧代码保持工作,他们不能只为所有函数添加额外的参数。 That's why you have to explicitly specify which texture unit you are addressing. 这就是你必须明确指定要处理的纹理单元的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM