简体   繁体   English

glActiveTexture不起作用

[英]glActiveTexture Doesn't Work

The following: 下列:

glActiveTexture(GL_TEXTURE0 + 0);

unsigned i, w;
unsigned tex_test = Memento::_LoadImageIntoTexture("ground.png", i, w);

glBindTexture(GL_TEXTURE_2D, tex_test);
glUniform1ui(program.GetUniformLocation("tex"), 0);

Will run fine, and the image I expect is shown properly. 将运行正常,并且我期望的图像可以正确显示。 However... 然而...

glActiveTexture(GL_TEXTURE0 + 1);

unsigned i, w;
unsigned tex_test = Memento::_LoadImageIntoTexture("ground.png", i, w);

glBindTexture(GL_TEXTURE_2D, tex_test);
glUniform1ui(program.GetUniformLocation("tex"), 1);

When I attempt to change the active texture to anything other than 0, nothing is displayed. 当我尝试将活动纹理更改为0以外的任何值时,什么都没有显示。 This is driving me crazy because I just can't find any solution, and it makes no sense. 这让我发疯,因为我只是找不到任何解决方案,这没有任何意义。 Help? 救命?

From OpenGL specs for glActiveTexture : glActiveTexture OpenGL规范glActiveTexture

A texture unit consists of the texture enable state, texture matrix stack, texture environment and currently bound texture. 纹理单元由纹理启用状态,纹理矩阵堆栈,纹理环境和当前绑定的纹理组成。 Modifying any of these states has an effect only on the active texture unit. 修改这些状态​​中的任何一个仅对活动纹理单元有影响。

You probably forgot to call glEnable(GL_TEXTURE_2D) , and/or glTexEnv(...) if you use non default values. 如果使用非默认值,您可能忘记了调用glEnable(GL_TEXTURE_2D)和/或glTexEnv(...)

My guess is that the texture loading function is messing with the active texture unit. 我的猜测是纹理加载功能正在与活动纹理单元混淆。 Personally I think that a new "proxy" texture unit should be introduced, that can not be used as a smapling source, but can be used for loading image data. 我个人认为应该引入一个新的“代理”纹理单元,该单元不能用作贴图源,但可以用于加载图像数据。 That would allow to perform texture loading without messing with the texture units' state. 这将允许执行纹理加载而不会弄乱纹理单元的状态。

Anyway, what happens if you change your code to this: 无论如何,如果将代码更改为此:

unsigned i, w;
unsigned tex_test = Memento::_LoadImageIntoTexture("ground.png", i, w);

unsigned int texture_unit = 1;
glActiveTexture(GL_TEXTURE0 + texture_unit);
glBindTexture(GL_TEXTURE_2D, tex_test);
glUniform1ui(program.GetUniformLocation("tex"), texture_unit);

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

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