Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What do you understand by 2D mode? Do you mean orthographic projection? Then I have good news: Depth testing works there perfectly as well. gluOrtho2D is basically the same like glOrtho(..., -1, 1); i.e. you have the Z range -1 ... 1 to spend.</p> <p><strong>EDIT due to comment:</strong></p> <p>It is perfectly possible to combine rendering several projections in one single frame:</p> <pre><code>void render_perspective_scene(void); void render_ortho_scene(void); void render_HUD(); void display() { float const aspect = (float)win_width/(float)win_height; glViewport(0,0,win_width,win_height); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-aspect*near/lens, aspect*near/lens, -near/lens, near/lens, near, far); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); render_perspective_scene(); // just clear the depth buffer, so that everything that's // drawn next will overlay the previously rendered scene. glClear(GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-aspect*scale, aspect*scale, -scale, scale, 0, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); render_ortho_scene(); // Same for the HUD, only that we render // that one in pixel coordinates. glClear(GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, win_width, 0, win_height, 0, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); render_HUD(); } </code></pre> <p>Of course if you've fallen for those bad tutorials that place the projection matrix setup in the reshape handler you're of course mind blocked, to see that obvious solution.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload