简体   繁体   中英

Draw Order in OpenGL

I am rendering an OpenGL scene that include some bitmap text. It is my understanding the order I draw things in will determine which items are on top.

However, my bitmap text, even though I draw it last, is not on top!

For instance, I am drawing:

1) Background
2) Buttons
3) Text

All at the same z depth. Buttons are above the background, but text is invisible. It I change the z depth of the text, I can see it, but I then have other problems.

I am using the bitmap text method from Nehe's Tutorials.

How can I make the text visible without changing the z depth?

You can simply disable the z-test via

  glDisable (GL_DEPTH_TEST);  // or something related..

If you do so the Z of your text-primitives will be ignored. Primitives are drawn in the same order as your call the gl-functions.

Another way would be to set some constant z-offset via glPolygonOffset (not recommended) or set the depth-compare mode to something like GL_LESS_EQUAL (the EQUAL is the important one). That makes sure that primitives drawn with the same depth are rendered ontop of each other.

Hope that helps.

您也可以使用glDepthFunc(GL_ALWAYS)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM