VBO+multitexturing

Hello, :slight_smile: yes, still him…

This time, I will use VBO and multitexturing.

Without VBO multitexturing works.
With VBO multitexturing works too (but where is the problem?!) BUT it is very strange because the textures are well mixed on polygons but without the alphamap. So the mix is uniform on all terrain surface.
It is normal because I don’t put these code lines that are useful with multitexturing:

glMultiTexCoord2fARB( GL_TEXTURE0_ARB, u, v);
glMultiTexCoord2fARB( GL_TEXTURE1_ARB, u, v);

( I use 2 texture units )

In fact, I don’t see where I could put these lines because with VBO I use this function in order to render the scene:

glDrawElements( GL_TRIANGLES, 3*nbLODfaces, GL_UNSIGNED_INT, NULL);

So how can I define texture coordinates fot the 2 texture unit with this last function? I have to rewrite this function in order to do that? Maybe it will be less powerful…

thank you.

There was a recent topic about it, make a search !

http://www.opengl.org/discussion_boards/ubb/ultimatebb.php?ubb=get_topic;f=3;t=014549

MultiTexCoord* are of no use when using vertex arrays.

thank you, I didn’t search enough.

But this is what I do and the result is still the same…( the mix process is in two passes because I have only two texture units on my graphic card).

     glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    
    glEnable(GL_TEXTURE_2D);
    
    
    glBindBuffer( GL_ARRAY_BUFFER, vertexBuffer );
    glVertexPointer( 3, GL_FLOAT, 0, NULL);
    
    glBindBuffer( GL_ARRAY_BUFFER, normalBuffer );
    glNormalPointer( GL_FLOAT, 0, NULL);
    
    
    //TRactiveTextureReplace(terrainTexList[1].glID);//CHECK_GL;
    
    
    
    for(int passe=0;passe<2;passe++)
    {
    
    if(passe==0)
    {
        glBlendFunc(GL_ONE, GL_ZERO);
        glActiveTexture( GL_TEXTURE0_ARB );
        glEnable( GL_TEXTURE_2D );
        
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        glBindBuffer( GL_ARRAY_BUFFER, texCoordBuffer );
        glTexCoordPointer(2, GL_FLOAT, 0, NULL);
        glBindTexture( GL_TEXTURE_2D, terrainTexList[1].glID );

        glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB );
        glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE );
        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE );
        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR );
        
        glActiveTexture( GL_TEXTURE1_ARB );
        glEnable( GL_TEXTURE_2D );
        
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        glBindBuffer( GL_ARRAY_BUFFER, texCoordBuffer );
        glTexCoordPointer(2, GL_FLOAT, 0, NULL);
        glBindTexture( GL_TEXTURE_2D, terrainTexList[2].glID );
        
        glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB );
        glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE );
        
        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS );
        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR );
        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE );
        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR );
        
    }
    if(passe==1)
    {
        glEnable(GL_BLEND);
        glBlendFunc(GL_ONE, GL_ONE);
        
        glActiveTexture( GL_TEXTURE0_ARB );
        glEnable( GL_TEXTURE_2D );
        
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        glBindBuffer( GL_ARRAY_BUFFER, texCoordBuffer );
        glTexCoordPointer(2, GL_FLOAT, 0, NULL);
        glBindTexture( GL_TEXTURE_2D, terrainTexList[0].glID );
        
        glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB );
        glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE );
        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE );
        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR );

        glActiveTexture(GL_TEXTURE1_ARB );
        glEnable( GL_TEXTURE_2D );
        
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        glBindBuffer( GL_ARRAY_BUFFER, texCoordBuffer );
        glTexCoordPointer(2, GL_FLOAT, 0, NULL);
        glBindTexture( GL_TEXTURE_2D, terrainTexList[2].glID );

        glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB );
        glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE );
        
        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS );
        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR );
        
        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE );
        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_ONE_MINUS_SRC_COLOR );
        

        
    }
    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, faceBuffer );
    //glDrawRangeElements( GL_TRIANGLES, 0, 3*nbLODfaces-1, 3*nbLODfaces, GL_UNSIGNED_INT, NULL );
    glDrawElements( GL_TRIANGLES, 3*nbLODfaces, GL_UNSIGNED_INT, NULL);
    }
    
    
    
    
    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
    glBindBuffer( GL_ARRAY_BUFFER, 0 );
    
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    
    glActiveTexture( GL_TEXTURE0_ARB );
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    
    glActiveTexture( GL_TEXTURE1_ARB );
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
     

thank you.

glClientActiveTexture… Look at this function documentation. It is needed before specifying the texture coordinates array.

Have you tried to have a look at nehe tutorials ?

http://nehe.gamedev.net/

Thank you, Nehe’s pdf don’t talk about VBO with multitexturing…and I don’t look all his tutorials…

I look glClientActiveTexture spec … I replaced glActiveTexture by the last, but now I don’t have any texture on the terrain.

Moreover when I look at opengl errors I saw: GL_INVALID_ENUM

This value is generated if in glEnableClientState I don’t put the good argument…but at the line where the error occurs I have:
glEnableClientState(GL_VERTEX_ARRAY);

Where is the problem with GL_VERTEX_ARRAY ? I think that it is not the good line where the error occurs…

Don’t replace them ! They have different purposes !

glActiveTexture is for texture functions (enabling, bindings, TexEnv…), whereas glClientActiveTexture is for the texture coordinates array !

If that does not suffice to you, make a deep search, this has been covered dozen of times.

Ok thank you very much, I have understood and now it works. the specs are not very accurate about the use of glClientActiveTexture for the newbie.