Positions in the space and transparency.

Hey, guys,
I wanna draw a ball inside a wire cube.
and the cube is drawn before the ball.
the problem is that the ball looks like floating on the surface of the cube instead of inside it.
that is i cannot see the front edges of the cube , for they are covered by the ball.

is there anything function i’d call to achieve the space relationships between objects?

Thanks.

In your initial setup:
glEnable(GL_DEPTH_TEST);

In your display:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

How are you drawing your objects?
Are you using gl Push/pop matrix when drawing them?

Also is the depth buffer enable?

Originally posted by Unicron:
[b]Hey, guys,
I wanna draw a ball inside a wire cube.
and the cube is drawn before the ball.
the problem is that the ball looks like floating on the surface of the cube instead of inside it.
that is i cannot see the front edges of the cube , for they are covered by the ball.

is there anything function i’d call to achieve the space relationships between objects?

Thanks.[/b]

I did glEnable(GL_DEPTH_TEST )and glClear(…)
but the result was : the majority of the scene became black.

by the way, i used glPushMatrix at the very beginning, drew the cube, then transformations, then drew the ball, followed by glPopMatrix. is it OK?

I got it now.

The reason might be :

  1. i forgot to clear the depth_buffer_bit
  2. i enabled blending( after i clear the depth buffer bit, the scene appeared but the ball moves to the back of the cube, and once the blending was disabled, the ball was placed inside the cube, could anyone tell me why ?)

I am thankful to any help.