Jump to content
  • Advertisement
Sign in to follow this  
bapti

Problem getting texture to display on terrain

This topic is 4873 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!