[NEWBIE]Strange problem: I can see through objects!

  • Follow


Hello,
I'm trying to plot some cylinders
using the GLU library:
  
 Q=gluNewQuadric();
 glColorf(1.0f,0.0f,0.0f);
 gluCylinder(Q,0.2f,0.2f,2.0f,20,10); 
 gluDisk(Q,0.0f,0.2f,20,1);
 glTranslatef(...);

 glColorf(0.0f,1.0f,0.0f);
 gluCylinder(Q,0.2f,0.2f,2.0f,20,10); 
 gluDisk(Q,0.0f,0.2f,20,1);
 glTranslatef(...);
 
 glColorf(0.0f,0.0f,1.0f);
 gluCylinder(Q,0.2f,0.2f,2.0f,20,10); 
 gluDisk(Q,0.0f,0.2f,20,1);

The objects are correctly drawn but I see
strange behaviours when a cylinder should hide
another: rotating the whole scene with
a glRotate preceding the command list,
I see the cylinder behind and not that
before...I don't know if I'm clear enough:
the cylinder closer to the camera disappears 
in that portions that should hide the
cylinder in the background.
What may be the cause of this?
Thanks!
0
Reply patrick 12/4/2004 7:32:50 PM

enable depth-testing
glEnable(GL_DEPTH_TEST);

use a appropriate depth-comparision function

e.g. glDepthFunc(GL_LEQUAL);

and make sure that your drawing context supports z-buffering/depthbuffering


hth psy


0
Reply Sebastian 12/5/2004 7:16:10 AM


Yes.  Whenever it is possible for an object to obscure another you have
to make sure that your z-plane is sorted and handled correctly.  Don't
feel bad, this is the first mistake I made, it is one I still often
make.

0
Reply donoteatmikezila 12/6/2004 8:34:32 PM

On Mon, 06 Dec 2004 12:34:32 -0800, donoteatmikezil wrote:

> Yes.  Whenever it is possible for an object to obscure another you have
> to make sure that your z-plane is sorted and handled correctly.  Don't
> feel bad, this is the first mistake I made, it is one I still often
> make.

I tryed with:
glClearDepth(1.0f);   
glDepthFunc(GL_LEQUAL); 
glEnable(GL_DEPTH_TEST);
in the gl-init function; but all objects 
disappeared in a black window...

I'm reading the opengl 2.0 specifications,
I find it very hard... 

Thanks for your attention.
Patrick 
0
Reply patrick 12/6/2004 8:58:28 PM

patrick carosso wrote:

> I tryed with:
> glClearDepth(1.0f);
> glDepthFunc(GL_LEQUAL);
> glEnable(GL_DEPTH_TEST);
> in the gl-init function; but all objects
> disappeared in a black window...

Make sure, your rendering context also has an associated depth
buffer. Otherwise the behaviour with enabled depth test is
undefined.
 
> I'm reading the opengl 2.0 specifications,
> I find it very hard...

Well, the spec is not the best resource for learning OpenGL.
Better go for the "OpenGL Programming Guide" aka "Red Book".

-- 
Wolfgang Draxinger

0
Reply Wolfgang 12/6/2004 9:44:48 PM

"Wolfgang Draxinger" <wdraxinger@darkstargames.de> wrote in message
news:cp2jsd$5tm$1@svr7.m-online.net...
> patrick carosso wrote:
>
> > I tryed with:
> > glClearDepth(1.0f);
> > glDepthFunc(GL_LEQUAL);
> > glEnable(GL_DEPTH_TEST);
> > in the gl-init function; but all objects
> > disappeared in a black window...
>
> Make sure, your rendering context also has an associated depth
> buffer. Otherwise the behaviour with enabled depth test is
> undefined.
>
> > I'm reading the opengl 2.0 specifications,
> > I find it very hard...
>
> Well, the spec is not the best resource for learning OpenGL.
> Better go for the "OpenGL Programming Guide" aka "Red Book".
>
> -- 
> Wolfgang Draxinger
>

And make sure you "near" and "far" are reasonable and "near" is strictly >
0.0 for your
viewing setup.

jbw


0
Reply JB 12/7/2004 5:22:00 AM

I didn'd clear the depth buffer!

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

And now it works!

Thank you all!

0
Reply patrick 12/7/2004 8:45:38 PM

6 Replies
370 Views

(page loaded in 0.362 seconds)

Similiar Articles:













7/24/2012 5:18:10 AM


Reply: