0
\$\begingroup\$

How do I handle resolution change in OpenGL and SDL2, in combination?

Let´s assume I have a GUI window with a fixed position, so it will be on the right corner of the window, and after resolution change it will be at the same position, just resized due to the resolution change. How do I handle the resolution change?

How do I apply these changes to my game physics? For example, with collision boxes, do I need to define some variable like resolutionRatio and multiply it against the collision rectangle dimensions?

\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

Games are usually made somewhat like this:

  • One part of the program models and simulates your game world, using arbitrary units for measurement. That's world space.

  • This game world is viewed through some sort of camera (possibly multiple cameras).

  • The HUD/GUI is drawn on top of what the camera shows, using another set of units (pixels are an option). That's screen space.

When you switch resolutions, the shape and size of your screen space changes. The GUI may have to adapt -- it is your choice whether the GUI elements scale and/or reposition themselves.

World space, however, is unaffected. You only have to adjust the zooming level of your camera to an adequate value. The simulation still works with its usual units, and the camera maps them to screen-space coordinates.

Edit: I see that you've already touched this concept in another answer, so I'll hinge on that. You're spot on with the "virtual position" vector: that's your world-space coordinates. The only missing piece is that one world-space unit does not have to equate one screen pixel: you can very well simulate everything in meters, then the camera maps 1 world-space meter to 32 screen-space pixels, so a one-meter object takes up 32px on-screen.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .