PDA

View Full Version : multitexturing and vertex arrays?



Joe Montana
06-07-2005, 03:52 PM
I cant seem to get the textures to come out properly. The vertices and normals do but not the textures. im doing.
Application:


glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 3, GL_FLOAT, stride, m_pTMVertexArray[lTile][lMask] +0 );

glEnableClientState( GL_NORMAL_ARRAY );
glNormalPointer( GL_FLOAT, stride, m_pTMVertexArray[lTile][lMask] + 3 );

glClientActiveTextureARB(GL_TEXTURE0_ARB );
glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D, m_pTextureIDsVertexArray[lTile][lMask][0]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glTexCoordPointer( 2, GL_FLOAT, stride, m_pTMVertexArray[lTile][lMask] + 6 ); //use the modified one caues its 0- m_iSize


glClientActiveTextureARB(GL_TEXTURE1_ARB );
glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D, m_pTextureIDsVertexArray[lTile][lMask][1]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glTexCoordPointer( 2, GL_FLOAT, stride, m_pTMVertexArray[lTile][lMask] + 8 ); //use

//render using a base texture and vertex info

glDrawArrays( GL_QUADS, 0, m_TMNumVertices[lTile][lMask] );


glDisableClientState( GL_VERTEX_ARRAY );

glDisableClientState( GL_NORMAL_ARRAY );

glClientActiveTextureARB(GL_TEXTURE0_ARB);
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glDisable( GL_TEXTURE_2D );

glClientActiveTextureARB(GL_TEXTURE1_ARB);
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glDisable( GL_TEXTURE_2D );

//glClientActiveTextureARB(GL_TEXTURE2_ARB);
//glDisableClientState( GL_TEXTURE_COORD_ARRAY );
//glDisable( GL_TEXTURE_2D );

The shader goes like this...



uniform sampler2D RoamTex;
uniform sampler2D AlphaTexC1;

...
...

The result is a texture from another part of my program getting drawn,

Any ideas,?

Thanks

Joe Montana
06-07-2005, 03:54 PM
forgot this too.

before the above code i set shader texture uniform variables for the textures


m_roamShader.UseShaders (true);

m_roamShader.Update1DiVariable ("RoamTex",0);
m_roamShader.Update1DiVariable ("AlphaTexC1",1);

sqrt[-1]
06-07-2005, 06:41 PM
You are getting glClientActiveTexture confused with glActiveTexture (Which you are not doing).

glClientActiveTexture is for setting up client states like the source texture coordinates in vertex arrays. (glEnableClientState, glTexCoordPointer)

glActiveTexture is for the server side state. All these calls:
glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D,m_pTextureIDsVertexArr ay[lTile][lMask][1]);
glTexParameterf(...)

are server side...

If you are in any doubt about what textures are bound where, might I suggest you grab a XML frame with GLIntercept (http://glintercept.nutty.org) and inspect the render call?

Should look like this: http://glintercept.nutty.org/Demo03/gliInterceptLog.xml

Joe Montana
06-08-2005, 03:24 AM
Great! Thanks for the help , it works now and more importantly i understand why.

As an aside note on the missing textures i had, i noticed that if I didnt mipmap my textures with gluBuildMipMaps and then called the following code
the texture was always black? Just curious why



glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
Thanks again.

Joe Montana
06-08-2005, 03:25 AM
thanks also fo the GLIntercept link!

sqrt[-1]
06-08-2005, 05:09 AM
The black texture is from enabling mip-mapping but not supplying all the mipmaps. This is a common mistake people make.

When you specify GL_LINEAR_MIPMAP_NEAREST (or anything with MIPMAP in the name) it enables mipmapping on that texture.

kon
06-08-2005, 05:42 AM
Mipmapping can only be defined for the GL_TEXTURE_MIN_FILTER!
The GL_TEXTURE_MAG_FILTER can only be set to GL_NEAREST or GL_LINEAR!