A little over a year ago, I wrote a post about how to render to a fixed, virtual resolution so that we can render independently of the actual window size resolution. That approach utilized the XNA framework to perform what we needed. Since Microsoft effectively killed XNA by pushing forward with DirectX / WinRT, myself and others have moved on to other libraries. In this post, I will show you how to do the same thing but with SDL2. Honestly, this approach is even easier (as long as you are using SDL2 that is!)
The concept of rendering to a virtually sized target is labeled as “Logical Size” in SDL2. Rendering a game to a logical size makes the scaling of that game to match different window sizes much easier. Imagine that we created our game under the assumption of 800×600 (an old school, 4:3 aspect ratio). On a user’s machine that has their system resolution set to 1920×1080, we have two choices: 1) show the game in a tiny window or 2) stretch the picture to fit the full screen. Both of these options are pretty terrible. In the first, the window will be too small to see anything useful (depending on the textures and fonts used in the game). In the second, the stretched picture will look awful because the aspect ratios do not even match. This is where SDL2’s logical rendering comes into play.
After establishing your renderer, all you really need to do is call the SDL_RenderSetLogicalSize function with the appropriate parameters.… Continue reading
I have confirmed that everything below works for Visual Studio 2013.
Links updated to the latest release (2.0.3).
The Simple DirectMedia Library (SDL) version 2 has been released after a long time in development. It seems that the author has more time on his hands and more corporate backing from his new position at Valve Software. I’ve heard that they use SDL for various small time projects that don’t require heavy rendering. Even so, SDL does a formidable job at making things easy.
I wrote this guide under the following setup, but I’m sure that it can be applied to other version of Windows (and maybe even Visual Studio).
Anyway, try your setup and let me know how it goes. Follow these steps to get all setup and ready to code:
- Download the development libraries
- Download the 32-bit binary or the 64-bit binary
- Extract both zips to a convenient location
- Open Visual Studio and create an empty C++ project
- Right click the created project in the Solution Explorer, go to Properties
- Click VC++ Directories under Configuration Properties
- In the “Include Directorires” line, add the include directory from the extracted development library
- In the “Library Directories” line, add the libx86 directory from the extracted development library
- Click Linker –> Input under Configuration Properties
- In the “Additional Dependencies” line, add “SDL2.lib” and “SDL2main.lib” strings
- Click Linker –> System under Configuration Properties
- In the “SubSystem” line, change the selection to WINDOWS(/SUBSYSTEM: WINDOWS)
- Finally, copy the SDL2.dll file from the extracted 32-bit binary folder to your project’s output directory alongside the executable
OK, the ugly project setup is finished.… Continue reading