Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Openrct2 | 11,886 | a day ago | 1,521 | gpl-3.0 | C++ | |||||
An open source re-implementation of RollerCoaster Tycoon 2 🎢 | ||||||||||
Devilutionx | 6,444 | 2 days ago | 331 | other | C++ | |||||
Diablo build for modern operating systems | ||||||||||
Magnum | 4,407 | 7 days ago | 91 | other | C++ | |||||
Lightweight and modular C++11 graphics middleware for games and data visualization | ||||||||||
Vcmi | 3,232 | 2 days ago | 340 | gpl-2.0 | C++ | |||||
Open-source engine for Heroes of Might and Magic III | ||||||||||
Xray 16 | 2,375 | 2 days ago | 226 | other | C++ | |||||
Improved version of the X-Ray Engine, the game engine used in the world-famous S.T.A.L.K.E.R. game series by GSC Game World. Join OpenXRay! ;) | ||||||||||
Teeworlds | 2,119 | 19 days ago | 376 | other | C++ | |||||
A retro multiplayer shooter | ||||||||||
Antimicro | 1,681 | 6 months ago | 240 | C++ | ||||||
[NOT maintained anymore] Graphical program used to map keyboard buttons and mouse controls to a gamepad. Useful for playing games with no gamepad support | ||||||||||
Sdl Gpu | 1,017 | a year ago | 71 | mit | C | |||||
A library for high-performance, modern 2D graphics with SDL written in C. | ||||||||||
Openspades | 1,013 | 13 days ago | 237 | gpl-3.0 | C++ | |||||
Compatible client of Ace of Spades 0.75 | ||||||||||
Lagrange | 999 | 2 days ago | 112 | bsd-2-clause | C | |||||
A Beautiful Gemini Client |
This library provides C++ bindings/wrapper for SDL2 and satellite libraries.
try {
using namespace SDL2pp;
// Init SDL; will be automatically deinitialized when the object is destroyed
SDL sdl(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
// Likewise, init SDL_ttf library
SDLTTF sdl_ttf;
// Straightforward wrappers around corresponding SDL2 objects
// These take full care of proper object destruction and error checking
Window window("libSDL2pp demo",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480, SDL_WINDOW_RESIZABLE);
Renderer renderer(window, -1, SDL_RENDERER_ACCELERATED);
Texture sprite1(renderer, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STATIC, 16, 16);
Texture sprite2(renderer, "sprite.png"); // SDL_image support
Font font("Vera.ttf", 20); // SDL_ttf font
// Initialize audio mixer
Mixer mixer(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 4096);
Chunk sound("effect.ogg"); // OGG sound file
// Create texture from surface containing text rendered by SDL_ttf
Texture text(renderer, font.RenderText_Solid("Hello, world!",
SDL_Color{255, 255, 255, 255}));
unsigned char pixels[16 * 16 * 4];
// Note proper constructor for Rect
sprite1.Update(Rect(0, 0, 16, 16), pixels, 16 * 4);
// Most setter methods are chainable
renderer.SetLogicalSize(640, 480).SetDrawColor(0, 16, 32).Clear();
// Also note a safe way to specify null rects and points
renderer.Copy(sprite1, NullOpt, NullOpt);
// There are multiple convenient ways to construct e.g. a Rect;
// Objects provide extensive set of getters
renderer.Copy(text, NullOpt, Rect(Point(0, 0), text.GetSize()));
// Copy() is overloaded, providing access to both SDL_RenderCopy and SDL_RenderCopyEx
renderer.Copy(sprite2, NullOpt, NullOpt, 45.0);
renderer.Present();
// Play our sound one time on a first available mixer channel
mixer.PlayChannel(-1, sound);
// You can still access wrapped C SDL types
SDL_Renderer* sdl_renderer = renderer.Get();
// Of course, C SDL2 API is still perfectly valid
SDL_Delay(2000);
// All SDL objects are released at this point or if an error occurs
} catch (SDL2pp::Exception& e) {
// Exception stores SDL_GetError() result and name of function which failed
std::cerr << "Error in: " << e.GetSDLFunction() << std::endl;
std::cerr << " Reason: " << e.GetSDLError() << std::endl;
} catch (std::exception& e) {
// This also works (e.g. "SDL_Init failed: No available video device")
std::cerr << e.what() << std::endl;
}
There's also more elaborate tutorial.
Currently, the library provides wrapper classes for
each with a subset of methods corresponding to SDL functions working with specific types of objects and, in some cases, additional convenience methods. These classes support:
Set of functional extensions above SDL2 is also available:
Dependencies:
To build standalone version:
cmake .
cmake --build .
Following variables may be supplied to CMake to affect build:
SDL2PP_WITH_IMAGE
- enable SDL_image support (default ON)SDL2PP_WITH_MIXER
- enable SDL_mixer support (default ON)SDL2PP_WITH_TTF
- enable SDL_ttf support (default ON)SDL2PP_WITH_EXAMPLES
- enable building example programs (only for standalone build, default ON)SDL2PP_WITH_TESTS
- enable building tests (only for standalone build, default ON)SDL2PP_STATIC
- build static library instead of shared (only for standalone build, default OFF)SDL2PP_ENABLE_LIVE_TESTS
- enable tests which require X11 and/or audio device to run (only for standalone build, default ON)To install the library system-wide, run:
cmake .
cmake --build .
cmake --install .
You can change installation prefix with CMAKE_INSTALL_PREFIX cmake variable:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local .
cmake --build .
cmake --install .
SDL2pp installs pkg-config
file, so it can be used with any build
system that interacts with pkg-config
, including CMake, meson and
GNU Autotools. It also installs CMake module file, which can be used
from CMake directly:
find_package(SDL2pp REQUIRED)
target_link_libraries(mytarget SDL2pp::SDL2pp)
The library is easy to integrate into other CMake projects (and as the library has no stable API yet, this way of using it is still recommended).
Just place the library into dedicated directory in your project (for example, extlib/libSDL2pp) and add
set(SDL2PP_WITH_IMAGE ON) # if you need SDL_image support
set(SDL2PP_WITH_MIXER ON) # if you need SDL_mixer support
set(SDL2PP_WITH_TTF ON) # if you need SDL_ttf support
add_subdirectory(extlib/libSDL2pp)
into your core CMakeLists.txt. This will act similar to how
find_package
usually does, and will provide SDL2pp::SDL2pp
target for your project. You will then be able it as usual:
target_link_libraries(mytarget SDL2pp::SDL2pp)
If bundled, libSDL2pp does not build examples and becomes a static library. See hoverboard project as an example of using both bundled and systemwide SDL2pp.
The library still doesn't cover all aspects of SDL2, and the development is generally guided by the author's needs and interest without a goal for covering all SDL2 functions as soon as possible. However, if you need specific bits which are not yet implemented in the library, feel free to drop an issue. Patches are of course more than welcome.
It should be noted, however, that I currently do not plan to implement any wrappers over non object-oriented SDL2 code, as these will not bring any benefits over using plain C API. E.g. I see no point in implementing SDL2pp::Delay() as it won't bring any convenience over SDL_Delay().
The same strongly applies to the SDL2 bits which duplicate C++17 standard library, e.g. threads and atomic ops.
Projects using libSDL2pp:
libSDL2pp comes under zlib license, the same license as SDL2. See COPYING.txt.