SDL and OpenGL stuck with coordinates


#1

I want to use OpenGL way of rendering things because it is more flexible, but, I’m kinda stuck at this point. I don’t understand why are coordinates between -1 and 1. How can I change them to world coordinates 2D, so that my shape can go beyond the visible area and to have the coordinate system with floats like SFML?
and what does glRotatef do? Thanks :).


#2

That’s a pretty big topic to describe in one post, regarding coordinate transformations. The short answer is, you need some convention, maybe -1 to +1, or 0 to +1, or 1 to #pixels, and OpenGL happens to pick the first one. As long as you’re consistent, then it doesn’t matter which one is used really. I’d recommend reading some good tutorials on this topic, like this one : https://learnopengl.com/#!Getting-started/Coordinate-Systems, which discusses all the transformation steps you really should understand to program with OpenGL.

Regarding the glRotatef function, that’s old school OpenGL I believe, and is not used anymore by 99% of coders. So if you want to use modern OpenGL then ignore that function. And if you need that kind of functionality, then best invest some time looking at something like the glm library (https://glm.g-truc.net/0.9.9/index.html), which will make your life easier :slight_smile:


#3

Thank you very much!