简体   繁体   English

Opengl,2D固定形状,在3D场景中使用移动相机

[英]Opengl, 2d stationary shapes, in a 3d scene with a moving camera

I have a 3d scene drawn out in Opengl, the camera is allowed to pan around the scene. 我在Opengl中绘制了一个3D场景,相机可以在场景中平移。 How do I go about adding 2d shapes to the window that will be unaffected by the camera moving? 如何将2D形状添加到不受摄像机移动影响的窗口中?

Generally this is done by drawing in two steps. 通常,这是通过分两步完成的。 Assuming that you would like the 2D shapes to always be "on top" of scene like a GUI, I would render your 3D scene, then use glOrtho2D and draw your shapes. 假设您希望2D形状始终像GUI一样始终位于场景的“顶部”,我将渲染3D场景,然后使用glOrtho2D绘制形状。 You'll probably want to also disable depth testing. 您可能还需要禁用深度测试。 Be sure to set back up for your 3D each frame. 确保为每帧3D备份。

After drawing the scene, you can set the camera matrix to an orthographic view, and draw the 2D overlay. 绘制场景后,可以将相机矩阵设置为正交视图,并绘制2D叠加层。

If the outline of your 2d overlay is free-form in any way, you can use an alpha mask to implement it. 如果2D叠加层的轮廓是任意形式的,则可以使用Alpha蒙版来实现。

You can use another toolkit and embed the OpenGL frame. 您可以使用其他工具包并嵌入OpenGL框架。 SDL is popular and portable. SDL受欢迎且可移植。

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

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