Sign in to follow this  
biggy

Vertex Array + Multitexture Probs

Recommended Posts

basically i am trying to render my terrain using vertex arrays. But when i try to multitexture only the ground texture is rendered (detailmap does not render). it works when i am using ordinary lists, but when i tried vertex arrays I can't get both texs to render no matter work. I've tried all sorts (plus most of the solutions posted on here) with little success. Here is my code i am using. I think this is the 'proper' way to do it but it doesn't seem to work. maybe i am missing something somewhere else??
void RenderVertexArray()
{
 

for(int z=0; z<m_iNumPatchesPerSide; z++)
	for(int x=0; x<m_iNumPatchesPerSide; x++)
	{	
		i = GetPatchNumber(x, z);
		
		if( m_bpPatchVisible[i] )
		{
			iNumIndices = m_iNumIndices[ m_pPatches[GetPatchNumber(x, z)].m_iLOD ];
			
			// Setup first tex coords (ground)
			glClientActiveTextureARB( GL_TEXTURE0_ARB );
			glEnableClientState( GL_TEXTURE_COORD_ARRAY );
			glTexCoordPointer(2, GL_FLOAT, sizeof(GeoTex), m_vTex + (m_iNumVertsPerPatch * i));
			
			// setup 2nd tex coords (detailmap)
			glClientActiveTextureARB( GL_TEXTURE1_ARB );
			glEnableClientState( GL_TEXTURE_COORD_ARRAY );
			glTexCoordPointer(2, GL_FLOAT, sizeof(GeoTex), m_vTex2 + (m_iNumVertsPerPatch * i));
			
			
			// bind ground tex
			glActiveTextureARB( GL_TEXTURE0_ARB );
			glEnable( GL_TEXTURE_2D );
			glBindTexture( GL_TEXTURE_2D, m_Texture.GetID() );
			
			// bind detail tex
			glActiveTextureARB( GL_TEXTURE1_ARB );
			glEnable( GL_TEXTURE_2D );
			glBindTexture( GL_TEXTURE_2D, m_DetailMap.GetID() );
			glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB );
			glTexEnvi( GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2 );	
			
			glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(GeoNorm), m_vNormal + (m_iNumVertsPerPatch * i) );
			glVertexPointer(3, GL_FLOAT, sizeof(GeoVertex), m_vVertices + (m_iNumVertsPerPatch * i) );
			
			glDrawElements( GL_TRIANGLES, iNumIndices, GL_UNSIGNED_SHORT, usIndices);
		}
	}
	
	glDisable( GL_BLEND );
	
	// unbind detail tex
	glActiveTextureARB( GL_TEXTURE1_ARB );
	glDisable( GL_TEXTURE_2D );
	glBindTexture( GL_TEXTURE_2D, 0 );
	
	// unbind ground tex
	glActiveTextureARB( GL_TEXTURE0_ARB );
	glDisable( GL_TEXTURE_2D );
	glBindTexture( GL_TEXTURE_2D, 0 );

}


Share this post


Link to post
Share on other sites
I think you should disable the GL_TEXTURE_COORD_ARRAY like you enabled it.

glClientActiveTexture(GL_TEXTURE0);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

glClientActiveTexture(GL_TEXTURE1);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

(... and the other disablings..)

Share this post


Link to post
Share on other sites
yeah i tried fiddling with those enable/disable statements in so many different ways but none of it makes a difference somehow.

Share this post


Link to post
Share on other sites
i want to combine a detail map with the terrain texture to get a more detailed look. As I said this works using the usual multitexturing way when I am not using vertex arrays. The above seems like it should work but does not.

Share this post


Link to post
Share on other sites
Fixed it.

turns out the multitexture code was fine but the tex coords were not set up right. So it was multitexturing but in such a way that it didn't look like it. whoops.

Sorry about that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this