开发者

OpenGL texture mapping

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 behavi开发者_Go百科or? 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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜