Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ opengl: how can i combine 2 different projection types for 3d graphics and 2d menus?

I would like to use Oblique projection for menus and perspective projection for the 3d-scene. is there a way to combine between this two projections ?

In general I'm asking how can I create menus in opengl for my 3d scene.

Programming using the c++ language.

Thanks!

like image 923
ufk Avatar asked Dec 28 '22 20:12

ufk


2 Answers

No problem. Just draw your 3D scene with appropriate modelview and projection matrices loaded. Then load up 2D matrices, turn off depth test, and render your menus. Here's an example of what it might look like.

glEnable(GL_DEPTH_TEST)
glMatrixMode(GL_MODELVIEW);
--code to load my Perspective Modelview Matrix
glMatrixMode(GL_PROJECTION);
--code to load my Perspective Projection Matrix
--code to draw my 3D scene
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glMatrixMode(GL_PROJECTION);
--code to setup my "menu" coords, probably something like
  gluOrtho2D
glDisable(GL_DEPTH_TEST)
--code to draw the menus
like image 63
Michael Daum Avatar answered Jan 17 '23 17:01

Michael Daum


  • Draw your 3D scene.
  • Push the projection matrix.
  • (Maybe clear the depth buffer).
  • Set up 2D projection.
  • Draw your 2D menu.
  • Pop the projection matrix.
like image 33
Chris Lercher Avatar answered Jan 17 '23 15:01

Chris Lercher