Hello,
This probably has a simple solution so sorry in advance. I’m trying to load two active textures and select one. Here’s the relevant code:
// Load the green texture.
GLuint greenTex;
GLuint whiteTex;
GLubyte greenTexture[] = { 0, 255, 0, 255 };
glGenTextures(1, &greenTex);
glActiveTexture(GL_TEXTURE0 + 0);
glBindTexture(GL_TEXTURE_2D, greenTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, greenTexture);
// Load the white texture
GLubyte whiteTexture[] = { 255, 255, 255, 255 };
glGenTextures(1, &whiteTex);
glActiveTexture(GL_TEXTURE0 + 1);
glBindTexture(GL_TEXTURE_2D, whiteTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, whiteTexture);
Later on in display part:
// Pick white texture.
GLuint colorTextureUnif = glGetUniformLocation(mainProgram.progName, "colorTexture");
glUniform1i(colorTextureUnif, 1);
My fragment shader is pretty simple. Note I tested colorCoord and did all the plumbing:
#version 330
in vec3 vertexNormal;
in vec3 modelSpacePosition;
in vec2 colorCoord;
uniform sampler2D colorTexture;
out vec4 outputColor;
void main(void)
{
outputColor = texture(colorTexture, colorCoord);
}
Basically green is always shown despite glUniform1i pointing to GL_TEXTURE1
Thanks in advance