Unwanted transparent terrain

Hello, I created a small program that displays a terrain patch. I also added the ability to rotate the terrain in arbitrary directions. The problem is that you can see through the hills/terrain from most of the angles. How can I draw the terrain so it looks solid?

can you give some more information about your code or maybe post a screenshot. what do you mean with “transparent”- real transparency, or can you just see something that you do not expect to see because it should be hidden? in that case, it could be a depth buffer problem.

There’s lots of code so I’ll try to write it out in pseudo code.

On the beginning I draw the map and save it as a display list:


while ( !end_of_point_data )


glTranslatef // sets the correct x and y for a given set of points

// then I draw the points by doing
for (each point in the given set)

// lots of calls to glColor3f and glVertex3f





The main drawing routine just does



glRotatef // rotates the map

Here’s a pic, note the upper right region.

forgot to type in that the calls to glNewList and glPushMatrix do end with glEndList and glPopMatrix.

The pic doesn’t show clearly though that you can see through the front hills when the map is rotated so you’re looking at it sidways. Although you can see that it isn’t apparent what is exactly at the front and what at the back.

Neither the screenshot nor the code show any obvious bug. So i suggest you make sure that you have

[ul][]enabled depth testing (glEnable(GL_DEPTH_TEST))[]your context actually has a depth buffer (glGetIntegerv(GL_DEPTH_BITS))[]your depth test function is correct (glDepthFunc(GL_LESS))[]blending and alpha test are disabled (glDisable(GL_BLEND), glDisable(GL_ALPHA_TEST))[/ul]

I tried by adding all of your suggestions into my init routine but the problem seems to only get worse. I did find out if I don’t enable the depthbuffer that from one angle the landscape looks correct, after inserting


into init it looks horribly wrong from the same angle. Attaching the pics below:

The way it should be drawn:

And the incorrectly drawn one:

Note that the second one was after I added depth testing. The yellow color means low altitude and you can see through it although there is higher terrain in front of it. Similar effect occurs from other angles.
Any other suggestions:/?

Check your glCullFace, glFrontFace, and glEnable(GL_CULL_FACE) settings. From these last images, it looks like you’re getting back-faces. This happens to me all the time. :smiley:

I managed to solve the problem, thanks for helping out! My zNear value was too low and that made the depth buffer severly innacurate.