Download Using Opengl 2d Games
Posted : adminOn 3/3/2018Gladiator 2000 Italian there. Litera Text Medium Font. OpenGL expects the vertex positions you give to be in 'clip space'. Which is the same as 'NDC space' before the perspective division. In 2D, you won't have perspective division, so you can think of clip space and NDC space as the same thing. X=-1 is the left edge of the screen X=+1 is the right edge Y=-1 is the bottom Y=+1 is the top These are the cords OpenGL expects to get regardless of your window size. So if you are outputting positions that have X=10 because you want your object to be 10 pixels wide.
I want to learn to use OpenGL to load sprites and make the sprites move. I cant seem to find a single tutorial on 2D OpenGL game programming. From what I've read. I've found a plethora of 'modern' OpenGL (3.0+) tutorials for 3D, but I have found next to nothing when looking for information on how to use it for 2D game development.
That is wrong because X=10 is waaaaaaay offscreen. You need to transform/scale your output positions to conform to NDC space. This is usually done by multiplying the positions by some kind of projection matrix. In modern OpenGL this would be done by your vertex shader. If you're interested in learning about OpenGL. Microsoft Autoroute Euro 2013 Full Lz009. This tutorial is excellent: Or. Since you're just doing basic 2D work.
You could use a wrapper lib like SFML/SDL which do all of this for you. 1 2 3 4 5 glm::mat4 scale_mat = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f)); //this gets you a transformation matrix which will scale a 3d vector by.5 glm::mat4 scale_mat = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f,.1f,.3f)); //this gets matrix for scaling by.5 in x dim,.1 in y dim, and.3 in z dim glm also has the functionality to make perspective matrices, view matrices, rotation matrices, translation matrices, and so forth. What's nice about it is that the operators such as +, -, *, and /, are overloaded to do the appropriate math when multiplying vectors/matrices/scalars.