set the texture for by glUniform1i

Opengl

Opengl Problem Overview


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** )?

Opengl Solutions


Solution 1 - Opengl

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionYongwei XingView Question on Stackoverflow
Solution 1 - OpenglTimView Answer on Stackoverflow