Public Group

# Texturing a triangle strip

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

## 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 on other sites
Take a look at these tutorials: NeHe. You will find all your answers there.

##### Share on other sites
Lesson 6 covers texture mapping....

http://nehe.gamedev.net

##### Share on other sites
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 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]

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 9
• 34
• 16
• ### Forum Statistics

• Total Topics
634124
• Total Posts
3015659
×