Accessing normal and float textures from fragment shader...


I’m trying to access both float and normal textures in a fragment shader… In my program I’m simply trying to apply the the textures to a square (one at a time). However it seems that whenever a float texture is binded to TEXTURE0 the normal GL_RGBA texture is read wrong and both float textures are can be applied correctly. When the normal GL_RGBA is binded TEXTURE0 this texture is applied correctly, but the float textures are not.

Can anybody help me with this problem?

void enablePaintBrushShader(void)

  // check if the dynamic texture variable exists in linked shader program and set texture
  if(dynamicTextureLocation != -1) {
    glActiveTexture(GL_TEXTURE2);                               // Actives openGLs texture0
    glBindTexture(texture_target, dynamicTextures[bufferRead]); // Binds the texture
    glUniform1iARB(dynamicTextureLocation, 2);                  // Set uniform variable in shader (to texture0)

  // check if the uv texture variable exists in linked shader program and set texture
  if(uvTextureLocation != -1) {
    glActiveTexture(GL_TEXTURE1);               // Actives openGLs texture1
    glBindTexture(texture_target, uvTexture);   // Binds the texture
    glUniform1iARB(uvTextureLocation, 1);       // Set uniform variable in shader (to texture1)

  // check if the normal texture variable exists in linked shader program and set texture
  if(normalTextureLocation != -1) {
    glActiveTexture(GL_TEXTURE0);                 // Actives openGLs texture2
    glBindTexture(texture_target, normalTexture); // Binds the texture
    glUniform1iARB(normalTextureLocation, 0);     // Set uniform variable in shader (to texture2)

void disableShaders(void)

void RenderTexture(void)
  ViewOrtho();                  // Set orthogonal projection mode
  glLoadIdentity ();
  glViewport(0,0,TEXTURE_WIDTH, TEXTURE_HEIGHT);  // Viewport

  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBufferObjects[bufferWrite]);
  glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);     // render attachment 0

    glMultiTexCoord2i(GL_TEXTURE0, 0, 0);
    glMultiTexCoord2i(GL_TEXTURE1, 0, 0);
    glMultiTexCoord2i(GL_TEXTURE2, 0, 0);
    glVertex2i(0, 0);

    glMultiTexCoord2i(GL_TEXTURE0, 0, textureCoordHeightFactor);
    glMultiTexCoord2i(GL_TEXTURE1, 0, textureCoordHeightFactor);
    glMultiTexCoord2i(GL_TEXTURE2, 0, textureCoordHeightFactor);
    glVertex2i(0, TEXTURE_HEIGHT);

    glMultiTexCoord2i(GL_TEXTURE0, textureCoordWidthFactor, textureCoordHeightFactor);
    glMultiTexCoord2i(GL_TEXTURE1, textureCoordWidthFactor, textureCoordHeightFactor);
    glMultiTexCoord2i(GL_TEXTURE2, textureCoordWidthFactor, textureCoordHeightFactor);

    glMultiTexCoord2i(GL_TEXTURE0, textureCoordWidthFactor, 0);
    glMultiTexCoord2i(GL_TEXTURE1, textureCoordWidthFactor, 0);
    glMultiTexCoord2i(GL_TEXTURE2, textureCoordWidthFactor, 0);
    glVertex2i(TEXTURE_WIDTH, 0);

  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);  // Unbind fbo 0

  ViewPerspective();  // Set Perspective projection mode

// VS
void main() 
  // now normalize the light's direction. Note that according to the
  // OpenGL specification, the light is stored in eye space.
  gl_TexCoord[0] = gl_MultiTexCoord0;
  gl_TexCoord[1] = gl_MultiTexCoord1;
  gl_TexCoord[2] = gl_MultiTexCoord2;
  gl_Position = ftransform();

// FS
uniform sampler2D uvTexture;
uniform sampler2D normalTexture;
uniform sampler2D dynamicTexture;
void main()
  vec4 texelColorA = texture2D(dynamicTexture,  gl_TexCoord[2].st); // Get current color of texel
  vec4 texelColorB = texture2D(uvTexture,       gl_TexCoord[1].st); // Get current color of texel
  vec4 texelColorC = texture2D(normalTexture,   gl_TexCoord[0].st); // Get current color of texel
  gl_FragColor = texelColorA;

Hi bbliksted,

What hardware/driver are you using? What’s wrong about the results you’re seeing?

Thanks -