A simple wrapper for SDL2, using modern C++
This interface is intended to provide an easy way to start using SDL for graphics, in a more "C++" way, without worrying about writing your own wrapper, or including a bunch of C-style code in your project. This is some source code I had lying around for personal use, to get up and running with graphics quickly while making games. I plan on cleaning this up and extending further with new features over time, such as adding my sprite renderer and timing functions.
There are two parts: smart pointer wrappers for various raw pointers used by SDL, and a class called Render_Context that lets you do some basic renderering.
By default, You will need both SDL2 and SDL2_images. You can omit images by defining GFX_OMIT_IMAGES if you just want drawing primitives.
- RAII: The Render_Context class automatically initializes SDL graphics and cleans up when the destructor is called.
- Error Handling: SDL2 functions return integer error codes. This wrapper throws an exception if an SDL function fails.
- Simple: Functions have simple names that are easy to understand and remember.
- The feature set is extremely limited for now, and only includes the SDL functions I use for some tile-based games and test programs.
- Smart pointers are still pointers, and must be handled correctly.
- Render_Context is not copyable or moveable, and you can only have 1 Render_Context safely.
- Read the source code first and change what you want, it's very short.
- Sprite renderer
- Timing functions
- Wrapper for SDL events
- Shaders and other fun things, using SDL_gpu (waiting for SDL 3)