Hi!
There could already have been similar projects, but I couldn’t find
any so I’ve started mine and am announcing it now.
I’m writing a C++ wrapper library for SDL2. Well, not really writing,
as I currently only implement features needed for my other projects,
but still it’s usable and already saves much work automatically handing
object destruction and error checking and adding some syntactic sugar.
As said, it has little functionality yet, as there’re only wrappers
for SDL itself (SDL_Init/SDL_Quit), and Window, Renderer, Texture,
Point and Rect clases, and wrapper methods are only enough for basic
texture and point/line/rect drawing. However, new stuff is easily
implementable, so feel free to use and/or and submit patches and
requests for covering more SDL2 features.
Code: https://github.com/AMDmi3/libSDL2pp
License: zlib, same as SDL
Synopsis:
try {
// Init SDL; will be automatically deinitialized when the object is destroyed
SDL2pp::SDL sdl(SDL_INIT_VIDEO);
// Straightforward wrappers around corresponding SDL2 objects
// These take full care of proper object destruction and error checking
SDL2pp::Window window(“libSDL2pp demo”,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480, SDL_WINDOW_RESIZABLE);
SDL2pp::Renderer renderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL2pp::Texture sprite(renderer, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STATIC, 16, 16);
unsigned char pixels[16 * 16 * 4];
// Note proper constructor for Rect
sprite.Update(SDL2pp::Rect(0, 0, 16, 16), pixels, 16 * 4);
renderer.Clear();
// Also note a way to specify null rects
renderer.Copy(sprite, SDL2pp::Rect::Null(), SDL2pp::Rect::Null());
renderer.Present();
// 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
std::cerr << "Exception: " << e.what() << std::endl;
std::cerr << "SDL Error: " << e.GetSDLError() << std::endl;
}–
Dmitry Marakasov . 55B5 0596 FF1E 8D84 5F56 9510 D35A 80DD F9D2 F77D
@Dmitry_Marakasov …: jabber: amdmi3 at jabber.ru http://www.amdmi3.ru