Jump to content
  • Advertisement


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


Terrain artifacts help please!

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

If you intended to correct an error in the post then please contact us.

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).

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



      glPolygonMode(GL_FRONT, GL_FILL);

      int h; int a; float color;
      float ambientColorBase = .25f;
      float heightColorScale = (float)heightMap.maxZ / .75f;
      for(int x = 0; x < heightMap.getSize()-1; x++) {
         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);

Share this post

Link to post
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):

glClearColor(0, 0, 0, 0);
goto start;

I hope that helps.

Share this post

Link to post
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.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!