Sign in to follow this  
bapti

Problem getting texture to display on terrain

Recommended Posts

bapti    122
Hi, i've started coding a 3D terrain but for some reason I can't get the texture to display correctly on the terrain. All i'm getting is one colour from the texture instead of the pattern which is a grid. The image should load ok cause it's a library written by someone else. Can anyone see any problems with the code? void CTerrain::Render() { float TexLeft, TexBottom, TexTop; int x,z; glEnable( GL_CULL_FACE ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_TerrainTexture.GetID( ) ); for( z = 0; z < (m_iTerrainSize - 1) ; z++ ) { //begin a new triangle strip glBegin( GL_TRIANGLE_STRIP ); //loop through the X-axis of the terrain //this is where the triangle strip is constructed for( x = 0; x < (m_iTerrainSize - 1) ; x++ ) { TexLeft = (float)(x / m_iTerrainSize); TexBottom = (float)(z / m_iTerrainSize); TexTop = (float)(( z+1 ) / m_iTerrainSize); glColor3ub( 255, 255, 255 ); glTexCoord2f( TexLeft, TexBottom ); glVertex3f( float(x), m_fpHeightData[(z*m_iTerrainSize)+x], float(z) ); glColor3ub( 255, 255, 255 ); glTexCoord2f( TexLeft, TexTop ); glVertex3f( float(x), m_fpHeightData[((z+1)*m_iTerrainSize)+x], float(z+1) ); }// end X ForLoop glEnd( ); }// end Z ForLoop }

Share this post


Link to post
Share on other sites
nts    968
try doing this instead for coord generation, looks like you have int rounding there


TexLeft = ((float)x / (float)m_iTerrainSize);
TexBottom = ((float)z / (float)m_iTerrainSize);
TexTop = ((float)( z+1 ) / (float)m_iTerrainSize);


HTH

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