View Full Version : Unwanted transparent terrain
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?
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.
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:
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
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glRotatef // rotates the map
Here's a pic, note the upper right region.
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.
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))
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
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. :D
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.