Jump to content
  • Advertisement
Sign in to follow this  
Winegums

Texturing a triangle strip

This topic is 4134 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, so i'm trying to texture a triangle strip, and realise i have no idea how. basically i'm rendering a terrain using a 3d array: float mMesh[MAP_SIZE][MAP_SIZE][3]; //3d coordinates of each point of the mesh the render loop is :
 for (int X = 1; X < (MAP_SIZE-1); X += 1 )
 {
 glBegin(GL_TRIANGLE_STRIP);
      for (int Z = 1; Z < (MAP_SIZE-1); Z += 1 )
      {
glVertex3f(mMesh[X][Z][0], mMesh[X][Z][1], mMesh[X][Z][2]);		// Draw Vertex
glVertex3f(mMesh[X+1][Z][0], mMesh[X+1][Z][1], mMesh[X+1][Z][2]);	// Draw Vertex

       }
 glEnd();
 }

Share this post


Link to post
Share on other sites
Advertisement
You could do something like this:
for (mapX = 1; mapX < MapWidth; mapX +=4){
for (mapZ = 1; mapZ < MapHeight * 3; mapZ+=4){
glBegin(GL_TRIANGLE_STRIP);
Height = HeightMap[mapX][mapZ];
glTexCoord2f(0,0);
glVertex3f(float(mapX),Height,float(mapZ));

Height = HeightMap[mapX][mapZ+4];
glTexCoord2f(0,1);
glVertex3f(float(mapX),Height,float(mapZ+4));

Height = HeightMap[mapX+4][mapZ];
glTexCoord2f(1,0);
glVertex3f(float(mapX+4),Height,float(mapZ));

Height = HeightMap[mapX+4][mapZ+4];
glTexCoord2f(1,1);
glVertex3f(float(mapX+4),Height,float(mapZ+4));
glEnd();

Succes!
www.nextdawn.nl

Share this post


Link to post
Share on other sites
The triangle strip (and glEnd) should be between the FOR loops:
And I would also define the LOD (level of detail) (ie size)
Instead of coding "4" a dozen times, which will make a longer process when you want to change it later.


int iLod = 4;

for (int mapX = 1; mapX < MAP_SIZE; mapX += iLod)
{
glBegin(GL_TRIANGLE_STRIP);
for (int mapZ = 1; mapZ < MAP_SIZE; mapZ += iLod)
{
// glTexCoord2f(...
// glVertex3f(...
// etc etc ...
}
glEnd();
}




Since your mMesh[MAP_SIZE][MAP_SIZE] is actually an array, it's '0' indexed.
And I'll assume this is going to hold your heightmap data.
if you did the following (as I corrected above):

for (int mapX = 1; mapX < MAP_SIZE; mapX += iLod)

You will actually miss the first row/col of pixels.

It could possibly be this instead:

for (int mapX = 0; mapX <= MAP_SIZE -1; mapX += iLod)

[Edited by - darren_mfuk on March 25, 2007 7:01:28 AM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!