Vertices problems

Hello

Im using a heigh map loader, (code bellow), everything went ok, the quads “changes” sometimes, Its hard to explain because my english its quite bad…

GLfloat Height(BYTE *pHeightMap, int X, int Y)
{

int x = X % MAP_SIZE;
int y = Y %MAP_SIZE;
if(!pHeightMap) return 0;
return pHeightMap[x + (y * MAP_SIZE)];
}

void RenderHeightMap(BYTE pHeightMap)
{
GLfloat x,y,z;
int X=0,Y=0;
if(!pHeightMap) return;
for ( X = 0; X < MAP_SIZE; X += STEP_SIZE )
for ( Y = 0; Y < MAP_SIZE; Y += STEP_SIZE )
{
x = X;
y = Height(pHeightMap, X, Y );
z = Y;
glTexCoord2f(0,0);
glVertex3f(x, y*ELEVATION, z);

  	x = X;
  	y = Height(pHeightMap, X, Y + STEP_SIZE );
  	z = Y + STEP_SIZE ;
  	glTexCoord2f(1,0);
  	glVertex3f(x,y*ELEVATION, z);

  	x = X + STEP_SIZE;
  	y = Height(pHeightMap, X + STEP_SIZE, Y + STEP_SIZE );
  	z = Y + STEP_SIZE ;
  	glTexCoord2f(1,1);
  	glVertex3f(x, y*ELEVATION, z);

  	x = X + STEP_SIZE;
  	y = Height(pHeightMap, X + STEP_SIZE, Y );
  	z = Y;
  	glTexCoord2f(0,1);
  	glVertex3f(x, y*ELEVATION, z);
  }

}

Thanks

When working with quads, you need to make sure all four of your vertices, on each quad, lie on the same plane. If they don’t, they’ll look funky. Don’t know if this is your problem, though.

I have also experienced problems with visual disturbances on QUADS when part of them is clipped outside the view frustrum (texture or color changes). I think that it is because OpenGL implementations usualy draw one quad as two triangles and when you clip part of the quad, you get different polygon and it is also differently divided into triangles.

Try to keep the quad in one plane and also when providing texture coordinates try not to stretch or shrink the texture in one direction too much.

Hope it helps

Platinum