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();
}
Texturing a triangle strip
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 :
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
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.
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]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement