InSDL is a small C++ framework built on top of SDL3, SDL3_ttf, and SDL3_image. It wraps the most common startup, input, drawing, text, texture, and audio tasks into a compact API.
- Overview
- Installation
- Quick Start
- Rendering Modes
- Core Loop
- API Reference
- Examples
- Notes and Limitations
The framework lives inside the insdl namespace and exposes convenient aliases:
insdl::Appinsdl::Rectinsdl::Textureinsdl::Textinsdl::Audioinsdl::InputState
The main header is:
#include <InSDL/InSDL.hpp>That header pulls in all of the public framework headers and SDL scancode definitions.
The repository already contains the required SDL libraries and headers in include/ and lib/.
The provided makefile builds the sample application from src/main.cpp:
makeUseful targets:
make compilebuilds the executablemake runlaunches the executablemake cleanremoves the build artifact
If you want to build another file, set SRC:
make SRC=examples/my_game.cppWhen using InSDL in your own project, add the include/ directory to your compiler's include paths and link against:
SDL3SDL3_ttfSDL3_image
Minimal application:
#include <InSDL/InSDL.hpp>
int main() {
insdl::App app;
app.init(800, 600, "My InSDL App");
while (!app.quit) {
insdl::handleEvent(app);
app.clear();
app.update();
}
return 0;
}What this does:
- creates a window
- sets up SDL rendering
- processes events every frame
- clears the screen
- presents the frame
app.init() supports two rendering modes:
app.init(width, height, title, surface = false, resizeable = false, fontPath = "");surface = falseusesSDL_Renderersurface = trueusesSDL_Surface
Recommended for most use cases.
Advantages:
- texture rendering
- text rendering
- rectangle rendering with floating-point geometry
- rotation and flipping support for textures
Useful for simpler software-style drawing.
Advantages:
- direct surface filling
- no renderer required for basic rectangle fills
Limitations:
- texture and text rendering helpers are renderer-based and should be used in renderer mode
The framework expects the following order inside your game loop:
while (!app.quit) {
insdl::handleEvent(app);
// game logic
app.update();
}Important details:
handleEvent(app)updates input state and triggers bindingsapp.update()presents the frame and updates delta time- call
handleEvent(app)once per frame before reading input state
Main application object that owns the window, renderer or surface, input state, and binding tables.
insdl::App app;The class is non-copyable and non-movable. It automatically calls exit() in its destructor.
void init(int width, int height, std::string name, bool surface = false, bool resizeable = false, std::string fontPath = "")
Initializes SDL, creates the window, and sets up either a renderer or a window surface.
width,height: window sizename: window titlesurface:truefor surface mode,falsefor renderer moderesizeable: enables SDL window resizingfontPath: optional font path for text rendering
If fontPath is empty, InSDL uses its bundled default font.
Returns true when the application initialized successfully.
Returns the last framework-level error message.
Returns the underlying SDL window pointer.
Returns the renderer pointer in renderer mode, or nullptr in surface mode.
Returns the window surface pointer in surface mode, or nullptr in renderer mode.
Clears the frame using the currently stored color.
Sets the current fill color and clears/fills the frame background.
Alias for clear().
Presents the current frame.
- calls
SDL_RenderPresent()in renderer mode - calls
SDL_UpdateWindowSurface()in surface mode - updates the frame delta time
Returns the time in seconds between the previous two update() calls.
Sets the window icon from a texture object.
Overrides the current font path used by future text objects.
Changes the stored window size and/or title.
- pass
-1to keep a dimension unchanged - pass an empty title to keep the current title
Binds callbacks to key press and key release.
funcruns on key downfuncUpruns on key up
Binds a callback to a mouse button press.
Binds a callback to mouse movement.
The callback receives int x, int y.
Releases SDL resources and closes the application.
bool quitstd::vector<...> keyBindingsstd::vector<...> keyUpBindingsstd::vector<...> mouseBindingsstd::vector<...> mouseMotionBindingsinsdl::inputState inputcolorStruct colorwindowStruct windowDatastd::string font
You usually only need to access quit, input, and sometimes font.
Processes SDL events for:
- quit events
- key down
- key up
- mouse button down
- mouse motion
It also updates app.input.
Legacy helper that only checks for SDL_EVENT_QUIT.
It is not needed in normal usage. Prefer handleEvent(app).
Frame-based input state tracker.
Resets pressed/released flags for the new frame and refreshes the mouse position.
Marks a key as held down and sets the pressed flag on the first frame of the press.
Marks a key as released and sets the released flag for the current frame.
Stores the latest mouse coordinates.
Returns true while a key is held.
Returns true only on the frame when the key transitions from up to down.
Returns true only on the frame when the key transitions from down to up.
Return mouse coordinates as integers.
Return mouse coordinates as floats.
Rectangle helper that adapts to renderer mode or surface mode automatically.
insdl::Rect rect(app, x, y, w, h);Creates a rectangle bound to the given application.
setRect(int x, int y, int w, int h)setPosition(int x, int y)setSize(int w, int h)setX(int x)setY(int y)setWidth(int w)setHeight(int h)addX(int x)addY(int y)addWidth(int w)addHeight(int h)subX(int x)subY(int y)subWidth(int w)subHeight(int h)
int getX()int getY()int getWidth()int getHeight()rectData getData()
getData() returns a copy of the internal data structure.
Fills the rectangle with a color.
- if a color component is
-1, the previously stored value is reused
In surface mode, redraws the rectangle using its stored color.
void fillTexture(texture* textureObject, double deg = 0, SDL_FlipMode mode = SDL_FLIP_NONE, SDL_FPoint point = {0, 0})
Draws a texture inside the rectangle in renderer mode.
Draws text inside the rectangle in renderer mode.
Returns true when two rectangles intersect.
Returns true when the mouse cursor is inside the rectangle.
operator<< prints rectangle geometry and color.
RAII wrapper around an SDL surface and texture loaded from an image file.
insdl::Texture texture(app.renderer(), "assets/image.png");The constructor requires a valid renderer.
Returns true when the image and texture loaded successfully.
Returns the last texture error.
Releases the surface and texture resources.
Returns a copy of the internal texture data.
operator<< prints the file path.
RAII wrapper for text rendered with SDL_ttf.
insdl::Text title(app.renderer(), "Hello", app.font, 255, 255, 255);Parameters:
renderer: valid SDL renderertextContent: string to renderfontPath: path to a.ttffontr,g,b: text color
Returns true when the font, surface, and texture are ready.
Returns the last text error.
Releases the text surface, texture, and font.
Re-renders the text with new content.
Changes the text color and re-renders it.
-1keeps the current channel value
Returns a copy of the internal text data.
operator<< prints the string, font path, and RGB color.
RAII wrapper for WAV playback.
insdl::Audio sound("assets/click.wav");The loader expects a WAV file.
Returns true when the WAV data, audio stream, and device are ready.
Returns the last audio error.
Queues the loaded WAV data for playback.
Resumes the audio device.
Pauses the audio device.
Stops playback and frees resources.
Returns a copy of the internal audio data.
operator<< prints the WAV file path.
Sleep helpers based on std::this_thread::sleep_for.
Examples:
insdl::delayMs(16);
insdl::delaySec(1);#include <InSDL/InSDL.hpp>
int main() {
insdl::App app;
app.init(800, 600, "Input Demo");
while (!app.quit) {
insdl::handleEvent(app);
if (app.input.isKeyPressed(SDL_SCANCODE_SPACE)) {
app.fill(30, 30, 30);
}
if (app.input.isKeyDown(SDL_SCANCODE_W)) {
// move up
}
app.update();
}
}insdl::Rect box(app, 50, 50, 200, 120);
box.fill(255, 80, 80);insdl::Text label(app.renderer(), "Hello SDL", app.font, 255, 255, 255);
insdl::Rect area(app, 20, 20, 300, 80);
area.fillText(&label);insdl::Texture image(app.renderer(), "assets/logo.png");
insdl::Rect slot(app, 100, 100, 256, 256);
slot.fillTexture(&image);insdl::Audio click("assets/click.wav");
if (click.ok()) {
click.play();
}Texture,Text, andAudioare move-only objects.TextusesTTF_RenderText_Solid, so it is optimized for simple solid-color text.Audiocurrently targets WAV files.handleEvent(app)should be called once per frame before reading input state.exitEvent(app)exists for compatibility but is not needed in normal usage.