PDA

View Full Version : Unwanted transparent terrain



Gothic
01-01-2006, 11:06 AM
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?

RigidBody
01-01-2006, 12:40 PM
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.

Gothic
01-02-2006, 12:57 AM
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:

glNewList(1,GL_COMPILE);

while ( !end_of_point_data )
{

glPushMatrix();

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)
{
glBegin(GL_QUAD_STRIP);

// lots of calls to glColor3f and glVertex3f

glEnd();
}

}

glNewList(1,GL_COMPILE);

The main drawing routine just does

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glRotatef // rotates the map
glCallList(1);

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

http://img484.imageshack.us/img484/6431/teren5ce.png

Gothic
01-02-2006, 02:24 AM
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.

memfr0b
01-02-2006, 07:27 AM
Neither the screenshot nor the code show any obvious bug. So i suggest you make sure that you have

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

Gothic
01-02-2006, 12:07 PM
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

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);

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

The way it should be drawn:
http://img271.imageshack.us/img271/8518/prav1kk.png

And the incorrectly drawn one:
http://img271.imageshack.us/img271/9237/narobe3td.png

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:/?

01-02-2006, 12:41 PM
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. :D

Gothic
01-02-2006, 11:55 PM
I managed to solve the problem, thanks for helping out! My zNear value was too low and that made the depth buffer severly innacurate.