简体   繁体   English

使用OpenGL for 2D

[英]Using OpenGL for 2D

I have started with OpenGL and learned about model,view,and the projection matrix. 我已经开始使用OpenGL并了解了模型,视图和投影矩阵。 From my understanding the projection matrix is only needed to project a 3D entity onto a 2D surface(the screen). 根据我的理解,仅需要投影矩阵将3D实体投影到2D表面(屏幕)上。 So if I want to create a 2D game would I even need to mess around with the projection matrix? 所以,如果我想创建一个2D游戏,我甚至需要搞乱投影矩阵?

It can still be nice to use a projection matrix for defining your coordinate system. 使用投影矩阵来定义坐标系统仍然很不错。 By default a window will be defined between [-1,1] for both x and y no matter what resolution and aspect ratio. 默认情况下,无论分辨率和宽高比如何,都会在[-1,1]之间为x和y定义一个窗口。 If you don't fix this using a projection matrix, you'll have to compensate in other ways. 如果您不使用投影矩阵解决此问题,则必须以其他方式进行补偿。 You want a square to render as a square, not a rectangle. 您希望将正方形渲染为正方形,而不是矩形。

Depending on your GL version you can call glOrtho , construct it manually or use glm::ortho . 根据您的GL版本,您可以调用glOrtho ,手动构建它或使用glm::ortho

In my experience, working on the default [-1,1] system is extremely unpractical. 根据我的经验,处理默认的[-1,1]系统是非常不切实际的。 For example : You don't want rotations around the z axis to deform your geometry. 例如:您不希望绕z轴旋转会使几何体变形。

不。当纯粹处理两个维度时,可以将投影矩阵保留为单位矩阵。

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

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