OpenGL - 绘制 GUI
我使用 glm::perspective(80.0f, 4.0f/3.0f, 1.0f, 120.0f);
并将其乘以
glm::mat4 view = glm::lookAt(
glm::vec3(0.0f, 0.0f, 60.5f),
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 1.0f, 0.0f)
);
我的问题涉及 OpenGL 和数学的主题。它与在我的视口上绘制 GUI 有关。我不知道如何获得正确的坐标来绘制,例如覆盖窗口 1/4 的正方形。如果我不使用透视图和 glm::lookAt(...)
(矩阵缩进),我将能够通过在 <-1.0 内设置 X,Y 坐标来绘制 GUI, 1.0>.当我将顶点放在 (-1.0, -1.0) 上时,它将定位在窗口的左下角。
如何使用perspective和lookAt获得相同的效果?
I use glm::perspective(80.0f, 4.0f/3.0f, 1.0f, 120.0f);
and multiply it by
glm::mat4 view = glm::lookAt(
glm::vec3(0.0f, 0.0f, 60.5f),
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 1.0f, 0.0f)
);
My question touches the subject of OpenGL and Maths. It relates to drawing GUI on my viewport. I do not know how to get proper coordinates in order to draw, e.g. a square that covers ¼ of the window. If I don't use perspectives and glm::lookAt(...)
(matrix indentity), I will be able to draw my GUI by setting coords from X,Y in <-1.0, 1.0>. And when I put a vertex on (-1.0, -1.0), it will be localized at the bottom left corner of the window.
How to gain the same effect using perspective and lookAt?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要试图将事情塞进某个特定的预测中。只需将您的投影切换到更适合您的 GUI 绘图需求的投影即可。 OpenGL 是一个状态机,在渲染单个图像的过程中多次切换参数是完全正常的。
Don't try to fiddle things into one certain projection. Just switch your projection to something that better suits your GUI drawing needs. OpenGL is a state machine, and it's perfectly normal to switch the parameters multiple times throughout rendering a single image.