Texturing a triangle strip

Started by
3 comments, last by darren_mfuk 17 years, 1 month ago
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();
 }
Advertisement
Take a look at these tutorials: NeHe. You will find all your answers there.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Lesson 6 covers texture mapping....

http://nehe.gamedev.net
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
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]
----------------------------------------Now just hit that link that says 'Rate This User' [wink]

This topic is closed to new replies.

Advertisement