Skip to main content
GameDev.net gamedev.net
🔒 Locked

Heightmap Rendering Help!

Started by Hlubocky Jan 18, 2002 at 5:56 PM 3 replies 550+ views
Original Post
Hlubocky
Hlubocky
I''m having some issues trying to draw a heightmap tarrain. I have a 100 by 100 array of random positive values (I know it is small but it is just a test). When I draw it the triangles tear and flicker and I believe it may be a problem with the way I am drawing the triangles in openGL. Is all that I have to do: Loop through the array one row at a time and at each vertex create two triangles, one with the current vertex (j,i), the next one over (j+1,i) and one down from the original (j,i+1) and another triangle with (j+1,i), (j+1,i+1), and (j, i+1)? It seems that this should connect all of the vertices and not leave any gaps or holes, but I may be wrong. If you have done this sort of thing before could you tell me how to draw the triangles? All posts I have found have to deal with how to create the heightmap. The one Neon Helium tutorial uses quads, which I don''t see how you can use if 4 points may not all be on the same plane. Someone clue me in please! Thanks for your help! Brian Hlubocky hlubocky@uiuc.edu
Grizwald
Grizwald
make sure your array is only filled once...and also that you aren''t reading past its limit...because then you could be getting system memory stuff that can change and keep your triangles moving
I love me and you love you.
Hlubocky
Hlubocky
The triangles really aren''t moving in the sense that the mesh is changing heights, but the whole thing flickers and odd artifacts appear along the edges of the triangles when the mesh is lit. Could someone who has done this tell me how to draw the triangles and if my method is the correct way to do it!

Thanks!
Hamster
Hamster
This might work, then again it might not. I'm afraid I'm without compiler at the minute, so this is just off the top of my head. This has been drawn out with the assumption that the ground should be lying on the horizontal plane. The variable naming isn't too good in terms of cartesian vectors or anything, but this should get the idea across.

    
//If you are using just a one dimensional array for your map

//values, then map[i][j] is equivalent to:

//map[i + j*MAP_SIZE_X];


glBegin(GL_TRIANGLES);

for( i=0; i<(MAP_SIZE_X-1); i++ )
{
for( j=0; j<(MAP_SIZE_Z-1); j++ )
{

glVertex3f( i, map[i][j], j );
glVertex3f( i+1, map[i+1][j], j );
glVertex3f( i, map[i][j+1], j+1 );

glVertex3f( i+1, map[i+1][j], j );
glVertex3f( i+1, map[i+1][j+1], j+1 );
glVertex3f( i, map[i][j+1], j+1 );


}
}

glEnd();



Edited by - hamster on January 18, 2002 7:34:28 PM
python_regious
python_regious
Make sure you are setting your projection matrix correctly. If you set the near plane to 0.0, then you can have very bad z-fighting, which would cause what you are seeing.

Death of one is a tragedy, death of a million is just a statistic.
If at first you don't succeed, redefine success.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.