Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OpenGL for 2D

Tags:

c++

opengl

I have started with OpenGL and learned about model,view,and the projection matrix. From my understanding the projection matrix is only needed to project a 3D entity onto a 2D surface(the screen). So if I want to create a 2D game would I even need to mess around with the projection matrix?

like image 661
lambda Avatar asked Jun 12 '13 02:06

lambda


2 Answers

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. 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.

In my experience, working on the default [-1,1] system is extremely unpractical. For example : You don't want rotations around the z axis to deform your geometry.

like image 55
Grimmy Avatar answered Oct 03 '22 15:10

Grimmy


No. When dealing purely with two dimensions, you can leave the projection matrix as the identity matrix.

like image 41
icktoofay Avatar answered Oct 03 '22 15:10

icktoofay