Yongwei Xing
Yongwei Xing

Reputation: 13451

set the texture for by glUniform1i

I have a question about how to set the texture by glUniform1i. I have seen code like below.

glActiveTexture(GL_TEXTURE0); 
glBindTexture(GL_TEXTURE_2D, texture0);
glUniform1i(_textureUniform, 0);
glActiveTexture(GL_TEXTURE1); 
glBindTexture(GL_TEXTURE_2D, texture1);
glUniform1i(_textureUniform, 1);

Does it mean, if I use the number i in the glUniform1i, then I have to use glActiveTexture(GL_TEXTURE **i** )?

Upvotes: 66

Views: 33033

Answers (1)

Tim
Tim

Reputation: 35943

Yes, you are correct. The uniform value for a sampler refers to the texture unit, not the texture id.

Upvotes: 62

Related Questions