PDA

View Full Version : Like soaking in a totally Black surface...(not knowing where the problem is)



sbbg
02-02-2005, 06:11 AM
Hello, I'm a newbie to OpenGL, and currently using GLUT to do some experiment.

Here is a problem I got when I try to light a glutSolidTeapot by a light in direction of (0, 0, -1). But I got the teapot that half of it "soaking" in a totally non-transparent surface, and the it seems also has the perspective problem( some surface near the eye become totally transparent) like this:

the snapshot (http://mail.cs.nchu.edu.tw/~s9256033/glutProblem.tiff)

And I'm sorry that I don't know where exactly the problem is... so the full-code about only 50 lines is at:

the code (http://mail.cs.nchu.edu.tw/~s9256033/light.C)
(the header's path is for Mac OS X)

I would be really grateful to hear from any possible suggestion, Thank a lot.

Aeluned
02-02-2005, 06:24 AM
looks like depth testing isn't enabled.

try glEnable(GL_DEPTH_TEST) and glWriteMask(GL_TRUE).

EDIT: post scriptum: same here, link to code dud'n work.

Good recovery Relic! :p

Relic
02-02-2005, 06:30 AM
The link to the code doesn't work for me, but from the image it looks like a simple depth buffer problem.

Make sure you have
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
in your code.

Also check if your viewing frustum is overly deep.
Make the zFar/zNear ratio as small as possible without clipping your teapot.

If the teapot is unit size use something like:

// For clarity:
GLdouble zNear = 1.0; // Must be > 0.0!
GLdouble zFar = 5.0; // Must be > zNear
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, 1.0, zNear, zFar);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, (float) (-0.5 * (zFar - zNear))); // Move origin in the z center, here 2.0 in world coordinates. But z-translation need to be negative in this matrix, read about the handedness of coordinate systems in the RedBook.

For debugging set the glClearColor to something you don't normally use, like magenta, to avoid black-screen-of-death and to see if the black parts inside the teapot are actually background pixels. They shouldn't be if your problem is depth testing.

Aeluned beat me, but dropped the ball, it's glDepthMask(GL_TRUE). ;)

sbbg
02-02-2005, 08:47 AM
Thanks for you two's reply. I must apologize for my mis-typing about the code's link. It should work now.

Although I did enabled GL_DEPTH_TEST, I don't know if I put the statement in right place...XD, and I will check the left part of your suggestion later.

And may I ask that why should I make the perspective diff( Zfar-Znear ) as small as possible? I just wonder why? Is that gonna make debugging easier?

Thanks again! :p

ZbuffeR
02-02-2005, 01:01 PM
About the zfar-znear, it is about depth precision, and the stripes you have clearly show that you need more :)
http://www.geocities.com/vmelkon/zprecision.html

Second problem, face winding. You are culling the wrong faces, see the "bugs" section here :
http://pyopengl.sourceforge.net/documentation/manual/glutSolidTeapot.3GLUT.html

sbbg
02-03-2005, 01:25 AM
Hello, seems the problem came with the glEnable(GL_CULL_FACE), after getting rid of the statement and glFrontFace(), everything goes fine :p !!

But allow me to ask further that, even I follow the suggestion of shorten (Zfar-Znear) and to cull the face in order of
glFrontFace(GL_CW);
glutSolidTeapot(size);
glFrontFace(GL_CCW);

but my code just can't work properly, and here\'s (http://mail.cs.nchu.edu.tw/~s9256033/light2.C) the code I've made change on ZBuffer and cull face by the suggestions above. May anyone help once again?

Thank you

Relic
02-03-2005, 02:37 AM
Ouch: glEnable( GL_DEPTH_TEST | GL_CULL_FACE );

glEnable takes an enum not a bitfield.
You must call one glEnable per feature you want to enable.

sbbg
02-04-2005, 12:57 AM
Thanks for your help & sorry for my foolish... XD

It's really nice to have this forum here. I feel much more confident to learn OpenGL. Thank you all!! :p