0
votes

I have two objects drawn on screen in openGL, one is a sphere using the GLU object and one is a texture mapped star. Regardless of the z coordinates, the texture mapped star always seems to draw in front. Is this normal openGL behavior? Is there a way to prevent this?

Note: I am working within the worldwind framework, so maybe something else is going on causing this. But I'm just wondering is it normal for the texture mapped objects to appear in front? I don't think so but I'm not sure...

1
If both objects are 3d, and you render star after glu object, then you probably forgot to enabele depth test and zbuffer.SigTerm
depth testing is enabled, but the star is 2d. I guess that would make a difference. I should've mentioned that.Jeff Storey
@Jeff: by 2D you mean you're rendering it without perspective? In other words, orthogonal projection. Or you meant it's just a plane? Besides that, are you translating the camera or the objects during the render process?jweyrich
@jweyrich. It is an orthogonal projection and 2d vertices are used to draw the shape. There is an xy translation just to get the item to correct xy point, but other than that, no other translations.Jeff Storey
"depth testing is enabled, but the star is 2d.". In this case it just happens to be always in front of the sphere, i.e. has smaller z coordinate. If you don't like it, either draw star using 3d functions (glVertex3f), using same projection matrix as you use with glu object and ensure that it is behind glu object OR (if star is in different projection - say in viewport space) draw star (with depth write disabled (glDepthMask)) BEFORE glu object.SigTerm

1 Answers

0
votes

This isn't a bug in worldwind, this is actually desired behavior. Using glVertex2f() is the same as using glVertex3f() and setting z = 0. So it simply draws the star at a plane very close to the viewer (also depending on your projection).

To solve your issue, you can either disable depth writes using glDepthMask(0), then draw the star, call glDepthMask(1) and then draw the sphere, which will now be in front of the star.

You can also use glDepthFunc(GL_GREATER) on the star or glDisable(GL_DEPTH_TEST) on the sphere to quickly achieve the same effect.

To make anything more complicated (such as star intersecting the sphere), you need to use matrices to put the star at the desired position.