简体   繁体   English

c ++ opengl:如何为3D图形和2D菜单组合2种不同的投影类型?

[英]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. 我想对3D场景使用倾斜投影进行菜单和透视投影。 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. 一般来说,我问如何在我的3d场景中为opengl创建菜单。

Programming using the c++ language. 使用c ++语言编程。

Thanks! 谢谢!

No problem. 没问题。 Just draw your 3D scene with appropriate modelview and projection matrices loaded. 只需使用适当的模型视图和投影矩阵绘制3D场景。 Then load up 2D matrices, turn off depth test, and render your menus. 然后加载2D矩阵,关闭深度测试,并渲染菜单。 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
  • Draw your 3D scene. 绘制3D场景。
  • Push the projection matrix. 按下投影矩阵。
  • (Maybe clear the depth buffer). (也许清除深度缓冲区)。
  • Set up 2D projection. 设置2D投影。
  • Draw your 2D menu. 绘制2D菜单。
  • Pop the projection matrix. 弹出投影矩阵。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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