I'm trying to scale my window, for example from 440*420 to 320*240.

How can I easily do this?

  • \$\begingroup\$ Are you talking about manually resizing the window? Or controlling the size of the window when it gets created? Keep in mind in some window managers, resizing the window is not allowed, so you can never force it, and controlling the window size is only meant as a hint to the window manager. \$\endgroup\$
    – TomTsagk
    Oct 16 '19 at 16:22
  • \$\begingroup\$ @TomTsagk I mean scaling the window within the code so that any content inside it gets warped to fit the new window size. Kinda like if you were to resize an image inside of Word. \$\endgroup\$
    – Aresiel
    Oct 16 '19 at 16:26
  • \$\begingroup\$ Do you mean scaling the content of your game, so that it supports multiple window sizes? \$\endgroup\$
    – TomTsagk
    Oct 16 '19 at 16:27
  • \$\begingroup\$ @TomTsagk Kinda, more specifically so that it will fit the given proportions without being too big or small. To be more specific I am trying to get Open Syobon Action to fit within 320*240. \$\endgroup\$
    – Aresiel
    Oct 16 '19 at 16:29
  • \$\begingroup\$ Hello Aresiel and Welcome to Game Development. Could you maybe explain what you mean with the scaling. Maybe an example like a quick draw or an example when to rescale the window. \$\endgroup\$
    – PSquall
    Oct 24 '19 at 10:35

It's been a while since I last used SDL 1.2, but from what I remember there are two options.

First, SDL by default works in software mode. If you're not using OpenGL, then you'd have to grab the screen buffer SDL_Surface and scale it to your window's size (probably SDL_Image has a function to do that).

Second option is if you're using OpenGL. After resizing the window, you have to change the projection matrix, and the viewport. Projection matrix defines how much the user sees, viewport scales it to the window. If you set matrix as if the window is 320x240, and set the viewport to 440*420 (window size), your rendered scene will be warped to match the window/viewport.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.