Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw Order in OpenGL

Tags:

c++

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?

like image 568
Evan Marks Avatar asked Mar 02 '23 03:03

Evan Marks


1 Answers

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.

like image 126
Nils Pipenbrinck Avatar answered Mar 06 '23 19:03

Nils Pipenbrinck