Hidden surface removal problem still need your help

Hi everyone:
I got a problem to remove hidden surface. When I draw a sealed surface, glEnable(GL_DEPTH_TEST) is working ok. When I draw a complex object for example streetlamp, the hidden surface can’t be removed. It always cover the surface that I want.
Could you please help me to solve this problem. Thanks in advance

There can be many reasons for this, could you give us some more info like what api/toolkit etc. you are using?

Some obvious things to check:
Have you requested a display with a depth buffer? i.e. in glut: glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
GLUT_DEPTH must be there for depth buffer to work in glut.
Also if you forget to clear the depth buffer at the begining of your display loop i.e. glClear(GL_DEPTH_BUFFER_BIT); then it might not work.

Thanks! I’m using MFC and OpenGl.It’s my first time to use opengl. I just use #include <gl\gl.h> // OpenGL Libraries
#include <gl\glu.h> // GLU OpenGL Libraries

I didn’t use glut library. I’m confusing.

I use this glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); before display.

Ok well, I program from Linux and I don’t know anything about MFC - to be honest I don’t even know what it is! (I can guess though :wink: )

But anyway if you have set:
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);

And you are clearing the depth buffer before each redraw,

And you have requested a depth buffer for your opengl viewport. (I don’t know how you’ll do this with MFC, but it must be possible)

If you have done all these things and it still doesn’t work, then you have a bug (presumably in your graphic driver) or gremlins in your pc or something crazy like that.

Hope this helps.

Thanks RedArrow. I try your code in SetUpRc(). bug is still there. It maks me crazy. I try to use Deep Exploration (commercial software)to display my file, it works good.
My MFC is VC++ 6.0.

Can you tell us how you draw your lamp? OpenGL needs an object to be drawn from convex polygons to show things properly.

Thanks. I read .obj file and according to vertices coordinate and face points to draw Lamp.Usually there are three points or four points in one face. I download sample file from this website to test my application http://www.cis.uab.edu/info/grads/hux/Data/obj.html. You can see that streetlamp.

Thanks a lot dvm!

The link you gave doesn’t work. Error 404…

Hmm, then maybe there’s an error in the way you load the .obj file. I had similar errors once, when I tried to load a .3ds model. The model looked crap in my app though all was fine in 3ds max. So I’d suggest you check about .obj file format here and google around to find a proper .obj loader.
BTW I’m not sure but I think Nate Robbins’ tutorials use .obj files so take a look
Good luck!

Just a repost — worth a check on your viewing direction wrt your model origin

Julian

Hi

I had almost exactly the same problem.

By default you are looking from 0,0,0

Sooooo, if your model is created around the 0,0,0 point you are effectively inside it. This causes “wierd” effects like surfaces that should be in front to be viewed as behind…

As a quick check, try and add a global Z offset to your model so that it isn’t around the 0,0,0 position.

I guess you can alter the viewing position etc but I haven’t figured out how to do that yet.

HTH a little

Julian

Thanks everybody! That link I provide, I found if you click it, doesn’t work, if you copy and paste to your URL, it works! strange!

Thanks for your help!!!

Originally poseted by joolz

I guess you can alter the viewing position etc but I haven’t figured out how to do that yet.
This is easy enough just use gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz);
where eyex, eyey & eyez are the position of the camera.
centerx, centery & centerz are the focal point of the camera.
and upx, upy & upz define which direction is up (mostly you want upx = 0, upy = 1 & upz = 0)

so gluLookAt(-10.0, 0.0, -10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); would position you a bit behind and looking at the orign.

Hi friends! It looks my glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS/GREATER); not working in my SetUpRc() function. Feel very frustrating!

Hi dorbie:

Do you have any idea for me! Thanks in advance!