#### Archived

This topic is now archived and is closed to further replies.

## Recommended Posts

Hello, I''m attempting to use OpenGL to render landscape from a heightfield (which was/are procedurally generated from some GIS data). I ran into a strange glitch, and thought that someone with experience might recognize the problem. Currently I''m rendering a 512x512 grid as triangle strips. There''s only height data for maybe a third of the area, the rest is simply 0 (probably wasting a good deal of time drawing useless triangles, but I''m not worried about that right now). The problem is when I look in the positive x direction, the bottom plane pokes through and screws things up for some reason. as in the following screenshot: http://www.engr.orst.edu/~gilham/temp/problem1.jpg Looking the opposite direction is no problem: http://www.engr.orst.edu/~gilham/temp/problem2.jpg On a hunch, I changed my outer loop to draw the strips in descending order with respect to x, changing my outer loop to for(int x = heightMap.getSize()-2; x >= 0; x--). The result was that the problem is now visable when looking down the NEGATIVE x axis: http://www.engr.orst.edu/~gilham/temp/problem3.jpg And looking down the positive x axis in this case looks fine: http://www.engr.orst.edu/~gilham/temp/problem4.jpg I thought it might be depth buffer related and tried moving the far clip plane closer, but all that does is shift the artifact closer. I also tried rendering from x = 0 to heightMap.getSize() / 2, and as expected only half the terrain is rendered, but the artifact remains. I''ve also tried different dimensions of heightmaps (128x128 to 1024x1024), and the same thing happens. Any help would be much appreciated!! Pertinent sections of my code are posted below (the constant COBOL is just a scaling factor we use, I''m not sure why my partner chose that name. I tried factoring it out but things look exactly the same).

glMatrixMode(GL_PROJECTION);

gluPerspective(70, m_aspectRatio, 1,HEIGHTMAP_DIMENSION*COBOL);

camera->update();

glDrawBuffer(GL_BACK);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPolygonMode(GL_FRONT, GL_FILL);
glCullFace(GL_BACK);

int h; int a; float color;
float ambientColorBase = .25f;
float heightColorScale = (float)heightMap.maxZ / .75f;
for(int x = 0; x < heightMap.getSize()-1; x++) {
glBegin(GL_TRIANGLE_STRIP);
for(int y = 0; y < heightMap.getSize()-1; y += 2) {

h = heightMap.height[x][y];
color = h/heightColorScale + ambientColorBase;
glColor3f(color, color, .4);
glVertex3i(x*COBOL, y*COBOL, h);

h = heightMap.height[x+1][y];
color = h/heightColorScale + ambientColorBase;
glColor3f(color, color, .4);
glVertex3i((x+1)*COBOL, y*COBOL, h);

h = heightMap.height[x][y+1];
color = h/heightColorScale + ambientColorBase;
glColor3f(color, color, .4);
glVertex3i(x*COBOL, (y+1)*COBOL, h);

h = heightMap.height[x+1][y+1];
color = h/heightColorScale + ambientColorBase;
glColor3f(color, color, .4);
glVertex3i((x+1)*COBOL, (y+1)*COBOL, h);
}
glEnd();


##### Share on other sites
Hey. It looks like you terrain is drawing over its self. You probably dont have depth-write or depth-test enabled.

try adding this to your code somewhere before the terrain is renderd (i dont remember the enum/function names 100% so youll probably have to look them up):

start:
glClearColor(0, 0, 0, 0);
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glEnable(GL_DEPTH_WRITE);
glEnable(GL_DEPTH_TEST);
glDepthFunction(GL_LESS);
...
RenderTerrin();
...
SwapBuffer();
...
goto start;

I hope that helps.

##### Share on other sites
Wow, thanks a bunch! Simply glEnable(GL_DEPTH_TEST) did the trick. For some stupid reason I thought that would be used automatically.

Cool. No problem

• ### Forum Statistics

• Total Topics
628401
• Total Posts
2982463

• 9
• 10
• 9
• 19
• 24