Problems using Mutlitexture and VBO

Apprentice
Posts: 9
Joined: 2010.02
Post: #1
Hi,
i like to use 2 textures for my geometrie (vbo), but i get only one texture in my shader. Here my setup:
Code:
// Textur Layer 0
    glActiveTexture (GL_TEXTURE0);
    glClientActiveTexture(GL_TEXTURE0);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, [_model texture]);
    
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glBindBuffer(GL_ARRAY_BUFFER, [_model bufferTexCoords]);
       glTexCoordPointer(2, GL_FLOAT, 0, 0);
    
    [_shaderManager sendUniform1Int:@"texture" parameter:0];

    // Textur Layer 1
    glActiveTexture (GL_TEXTURE1);
    glClientActiveTexture(GL_TEXTURE1);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, _glowTexture);
    
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glBindBuffer(GL_ARRAY_BUFFER, [_model bufferTexCoords]);
    glTexCoordPointer(2, GL_FLOAT, 0, 0);
    
    [_shaderManager sendUniform1Int:@"glowTexture" parameter:1];

Here my simple shader
Code:
uniform sampler2D texture;
uniform sampler2D glowTexture;

void main()
{      
    gl_FragColor = texture2D(glowTexture, gl_TexCoord[0].st);
   // gl_FragColor = texture2D(texture, gl_TexCoord[0].st);
}

But what i get, is only the texture "texture". Any suggestions.

BTW: Booth textures are loaded correctly
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #2
I haven't looked tooo closely, but I have had problems in the past when uniforms are unused, and could be worth a quick try in this case. Perhaps try using both textures in the shader and see if that works? eg. gl_FragColor = texture2D(glowTexture, gl_TexCoord[0].st) * 0.5 + texture2D(texture, gl_TexCoord[0].st) * 0.5;

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #3
You may also want to open the app in Gl Profiler to verify your textures are actually loaded.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #4
You don't need to call glEnable(GL_TEXTURE_2D) if you're using shaders.

The most likely causes of failure are that your textures are not mipmap complete, or your uniforms are not being set properly.
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2010.02
Post: #5
Hi,
thanks for your suggestions. The problem was my shader-manager (i have bound the wrong shader, sorry ;-).
Ok, i have one more question, my setup for vbo's with mutlitexturing (both texture-stages use the same uv's) looks like this:

Code:
// Textur-Koordinaten
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glBindBuffer(GL_ARRAY_BUFFER, [_model bufferTexCoords]);
    glTexCoordPointer(2, GL_FLOAT, 0, 0);    
    
    if(!_useGlowMap)
    {
        [_shaderManager sendUniform1Int:@"texture" parameter:0];  
        [_shaderManager sendUniform1Int:@"useGlowMap" parameter:0];
    }
    else
    {
        // Textur Layer 0
        glActiveTexture (GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, [_model texture]);        
        
        // Textur Layer 1
        glActiveTexture (GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, _glowTexture);
        
        [_shaderManager sendUniform1Int:@"texture" parameter:0];    
        [_shaderManager sendUniform1Int:@"glowTexture" parameter:1];
        [_shaderManager sendUniform1Int:@"useGlowMap" parameter:1];
    }

is this the right way, to use multitexturing with vbo's. I can't find any descriptions, for using vbo's with multitextures.
Is glClientActiveTexture not necessarily ?
How clean up the texture-stages, to fall back to normal rendering (and texturing):
Code:
        glActiveTexture (GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D,  0);

        glActiveTexture (GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D,  1);
is this right? Thanks in advance
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2008.01
Post: #6
If you want to pass multiple texture coordinates with vbo, you need to use glClientActiveTexture before calling glTexCoordPointer.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #7
If both units are really using the same UVs, then you only need to pass in one texture coordinate attribute. You can use it any way you want, in the shader.
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2010.02
Post: #8
Thank you for help!
Quote this message in a reply
Post Reply