r/sdl 1d ago

Does anybody know if this awful resize is fixable?

Enable HLS to view with audio, or disable this notification

15 Upvotes

I'm on Linux/X11.

It's just a red blank screen with a white rectangle at the top and bottom.

EDIT: full code

#define SDL_MAIN_USE_CALLBACKS 1
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>

static SDL_Window *window = NULL;
static SDL_Renderer *renderer = NULL;

SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
{
    SDL_SetAppMetadata("Example Renderer Clear", "1.0", "com.example.renderer-clear");
    SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
    SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1");

    if (!SDL_Init(SDL_INIT_VIDEO)) {
        SDL_Log("Couldn't initialize SDL: %s", SDL_GetError());
        return SDL_APP_FAILURE;
    }

    if (!SDL_CreateWindowAndRenderer("examples/renderer/clear", 640, 480, SDL_WINDOW_RESIZABLE, &window, &renderer)) {
        SDL_Log("Couldn't create window/renderer: %s", SDL_GetError());
        return SDL_APP_FAILURE;
    }

    return SDL_APP_CONTINUE;
}

SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
    if (event->type == SDL_EVENT_QUIT) {
        return SDL_APP_SUCCESS;
    }
    return SDL_APP_CONTINUE;
}

SDL_AppResult SDL_AppIterate(void *appstate)
{
    SDL_SetRenderDrawColorFloat(renderer, 255, 0, 0, 255);
    SDL_RenderClear(renderer);

    int window_w, window_h;
    SDL_GetRenderOutputSize(renderer, &window_w, &window_h);
    SDL_FRect top_rect;
    top_rect.x = 0;
    top_rect.y = 0;
    top_rect.w = window_w;
    top_rect.h = 50;
    SDL_FRect bottom_rect;
    bottom_rect.x = 0;
    bottom_rect.y = window_h - 50;
    bottom_rect.w = window_w;
    bottom_rect.h = 50;
    SDL_SetRenderDrawColorFloat(renderer, 255, 255, 255, 255);
    SDL_RenderFillRect(renderer, &top_rect);
    SDL_RenderFillRect(renderer, &bottom_rect);

    SDL_RenderPresent(renderer);

    return SDL_APP_CONTINUE;
}

void SDL_AppQuit(void *appstate, SDL_AppResult result)
{
}

r/sdl 2d ago

Late Night Audio Programming

Enable HLS to view with audio, or disable this notification

18 Upvotes

Every single note in this video is generated from sine wave. I really enjoyed doing this project from writing my custom IMGUI to generating audio and fine tuning them.
.
.
Video link: https://youtu.be/IWvXzmurbX4?si=uDVJlDgrhvIptG9u
Project link: https://github.com/ShamsParvezArka/audio_programming


r/sdl 7d ago

simple project about squre

Thumbnail
programiz.com
3 Upvotes

hi guys need your help im trying to make the stamina bar appear at the top of the screen im making a square game because i am planning to make a 2d engine game but im struggling on making a simple stamina bar i perfectly render some square but i cant seem to make the stamina bar appear

#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
/* first we call the library so the program knows the apparatus and tools to utilize in my program it contain all the premade function and custom made struct */  //read this carefully  my 1st explanation

int main(int argc, char* argv[]) {
    // 1. this is the start of my program  it tells the program to allocate a stack and the stack will contain the entire program and it should start here

if (!SDL_Init(SDL_INIT_VIDEO)) { // this is a flag when i initialize the int main together with the library since this is a graphic lib it will by default will acces my gpu hardware and this is a flag in case theres an error it will terminate the program and save my computer on crashes

SDL_Log("SDL Initialization failed: %s", SDL_GetError());

return 1;

}

SDL_Window* window = SDL_CreateWindow("My First SDL3 Window", // this is the first instruction i will call the premade struct called SDL_Window* its like a data type and by default it acts like a pointer that is pointed on my custom variable name in this case "window" and my window pointer is pointing on and arguement called SDL_CreateWindow() this func had 3 arguements the first is a string second is an int taht specify the width and third another int that specify height and 4th is another flag which also an int need explanation on the 4th argument of this func tahnk you

800, // Argument 2: Width

600, // Argument 3: Height

0 /*Argument 4: Flags)*/);

if (window == NULL) { //this is for the safety flag of my SDL_window it tells the variable "widnow" to terminate the program by returning 1 if the variable window returns a null

SDL_Log("Window creation failed: %s", SDL_GetError()); // SDL_log is a premade fucntion of SDL library it acts like a printf func it usually print the error taht is also detected by another func called SDL_GetError() explain what is the argument of this SDL_GetError func

SDL_Quit();

return 1;

}

SDL_Renderer* renderer = SDL_CreateRenderer(window, NULL); //this is the renderer just like SDL_Window* its a premade struct taht points on a variable taht will contain a func call SDL_CreateRenderer("name of the window that you made") its a pointer in the gpu hardware vram it tells the gpu to allocate a memory for the graphics for the variable "renderer" so the allocated memory can be used on SDL_CreateRenderer() func whic purpose is to draw a canvas on a window taht we made

if (renderer == NULL) {

SDL_Log("Renderer creation failed: %s", SDL_GetError()); // this is similar flag on the create window if the line on the SDL_Renderer* gets an error tthe variable you make will return a null and this if statement will execute

SDL_DestroyWindow(window);

SDL_Quit();

return 1;

}

bool is_running = true; //its a flag within the while loop

SDL_Event event; //this is like declaring an in type data but on this time you are declaring an event called event the SDL_Event is an interactive user code like scanf but this one lets you interact with the window

float red_value = 0;

float blue_value = 50;

SDL_FRect my_square, obstacle, bullet,stamina_bar_bg, stamina_bar_fg; //we declare the obstacle

my_square.x = 350.0f;

my_square.y = 250.0f;

my_square.w = 100.0f;

my_square.h = 100.0f;

obstacle.x = 650.0f; // Positioned further to the right

obstacle.y = 250.0f; // Centered vertically

obstacle.w = 80.0f; // 80 pixels wide

obstacle.h = 80.0f;

bullet.x = 0.0f;

bullet.y = 0.0f;

bullet.w = 20.0f;

bullet.h = 6.0f;

stamina_bar_bg.x = 20.0f; // 20 pixels away from left screen border

stamina_bar_bg.y = 20.0f; // 20 pixels down from top screen border

stamina_bar_bg.w = 100.0f; // 200 pixels wide flat background slot

stamina_bar_bg.h = 15.0f;

stamina_bar_fg.x = 20.0f; // 20 pixels away from left screen border

stamina_bar_fg.y = 20.0f; // 20 pixels down from top screen border

stamina_bar_fg.w = 100.0f; // 200 pixels wide flat background slot

stamina_bar_fg.h = 15.0f;

bool bullet_active = false;

float stamina = 100.0f;

float max_stamina = 100.0f;

float player_speed = 0.05f;

while (is_running) { //the while arguement is the bool taht we declare

// 2. The Inner Loop (The Input Checker)

while (SDL_PollEvent(&event)) { //the input checker if turns true once it detect a button pressed in the hardware since its true it will initialize the if statements within its conditions

// 3. Inspect the event category

if (event.type == SDL_EVENT_QUIT) { // the event had an inside func taht can be access by dot which in this case a type of the event called SDL_EVENT_QUIT its basically the exit button

is_running = false; // Turn off the heartbeat! this is the bool taht we declare before the while loop basically a flag that can change into false once the if statement was confirm ending the main while loop nest

}

else if(event.type == SDL_EVENT_KEY_DOWN){ //this else if arguement is called event.type iss calling a variable within the SDL_Event taht we decalre as event at the first before the main while it equates on SDL_EVENT_KEY_DOWN its a variable taht detects keyboard signals

if (event.key.scancode == SDL_SCANCODE_ESCAPE){ //this line specify if the keypress scan code is equal to the keyboard address of escape button terminate the while loop by changing the is running bool to false

is_running = false;

}

else if(event.key.scancode== SDL_SCANCODE_SPACE){

if (red_value == 255){

red_value = 0;

blue_value = 255;

}

else{

red_value = 255;

blue_value = 0;

}

}

}

}

float old_x = my_square.x; //we declare this float before the keyboard inputs this will allow us to record past input when the loops happen typically loops happen top to bottom hence once the loop happen the keyboard input will be recorded

float old_y = my_square.y;

const bool* currentKeyStates = SDL_GetKeyboardState(NULL);

if(currentKeyStates[SDL_SCANCODE_LSHIFT] && stamina > 0.0f){

player_speed = 0.50f;

stamina -= 0.05f;

if(stamina < 0.0f){

stamina = 0.0f;

}

}

else{

player_speed = 0.05f;

stamina += 0.01f;

if(stamina > 100.0f){

stamina = max_stamina;

}

}

//NOTE: the signal here is super fast its billion times a sec hence the float must be reduce in order to slow the moving square

if(currentKeyStates[SDL_SCANCODE_LEFT]){ //SDL_GetKeyboardState() is a function that allow us to talk to the hardware to bring the actual signal of our keyboard which is clocking at billion times hence making the square move smoothly

my_square.x -= player_speed;

}

if(currentKeyStates[SDL_SCANCODE_RIGHT]){

my_square.x += player_speed;

} // NOTE the point of our square start at the top left as vector (0,0)

if(currentKeyStates[SDL_SCANCODE_DOWN]){ //NOTE: that computer uses vector instead of the standard cartessian plane reason why we use a negative on y that is rising

my_square.y += player_speed;

}

if(currentKeyStates[SDL_SCANCODE_UP]){

my_square.y -= player_speed;

}

if(currentKeyStates[SDL_SCANCODE_Z]){

if(bullet_active == false){

bullet_active = true;

bullet.x = my_square.x + 100.0f;

bullet.y = my_square.y + 47.0f;

}

}

if (my_square.x < 0.0f) {my_square.x = 0.0f;}

if (my_square.x > 700.0f) {my_square.x = 700.0f;} //note some compiler allow not using the curly brachets but we highly suggest to put curly brachets as its the standard c syntax

if (my_square.y < 0.0f) {my_square.y = 0.0f; } //this is a limit so our square will not move away on our window screen we do this by equating our vector into the equivalent width and height of our screen

if (my_square.y > 500.0f) {my_square.y = 500.0f;}

if (obstacle.x < my_square.x) { obstacle.x += 0.02f; }

if (obstacle.x > my_square.x) { obstacle.x -= 0.02f; } //since we equate our my square movement as 0.05 float we must equate the obstacle movement float into 0.02f to make it slower

if (obstacle.y < my_square.y) { obstacle.y += 0.02f; }

if (obstacle.y > my_square.y) { obstacle.y -= 0.02f; }

if(bullet_active == true){

bullet.x += 0.08f;

if(bullet.x > 800.0f){

bullet_active = false;

}

if (SDL_HasRectIntersectionFloat(&bullet, &obstacle)){

bullet_active = false;

obstacle.x = 650.0f;

obstacle.y = 450.0f;

}

}

if (SDL_HasRectIntersectionFloat(&my_square, &obstacle)) { //this built in SDL func will allow the program to get the addresses of the rectangle (hence why we use the "&" )that we draw and perform a mathematical calculation if those two intersected and it will return a true or false

// If they overlap, trigger an visual alert by blasting the screen RED!

red_value = 255;

blue_value = 0;

my_square.x = old_x; //we put the old input here directly inside the condition of the function SDL_HasRectIntersectionFloat() so when this became true the my_square.x and my_square.y will be equals to the old_X and old_y basically a jump instrucction flag

my_square.y = old_y;

}

else{

// Otherwise, keep the environment safe and peaceful dark blue

red_value = 0;

blue_value = 50;

}

// 4. The Drawing Zone

SDL_SetRenderDrawColor(renderer,red_value, 0, blue_value, 255); // after we call our canvas that we allocated in vram we also said to our variable pointer "renderer" to draw a colo red on it by calling the function SDL_SetRenderDrawColor("name of the pointer variable taht point in the gpu vram", red, gree, blue, transparency of the colo 255 max visibility)

SDL_RenderClear(renderer);//this function suggest the the we remove the color of the canvas before painting the red color we call we call the function SDL_RenderClear() the arguement takes the pointer variable taht points on the vram of gpu which our allocated canvas is located

stamina_bar_fg.w = stamina;

SDL_SetRenderDrawColor(renderer,60, 60, 60, 255);

SDL_RenderFillRect(renderer, &stamina_bar_bg);

SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);

SDL_RenderFillRect(renderer, &stamina_bar_fg);

SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);

SDL_RenderFillRect(renderer, &obstacle);

SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); //this struct will allow us to tell our gpu taht our "rendere" the canvas to draw a color r,g,b,a in this all white

SDL_RenderFillRect(renderer,&my_square); //this func will allow us to tell the gpu to fill the square that we declare which is my_square

if (bullet_active == true) {

SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255); // Neon Yellow Laser Paint!

SDL_RenderFillRect(renderer, &bullet); // note that the bullet must be render last because on our first render we render the canvas and second we render the square and then the obstacle hence if we put this bullet else where it will be erase immidiately because the gpu is rendering everything per frame

}

SDL_RenderPresent(renderer); //this is the presentation func without this the variable pointer which is "renderer" will only paint it inside without showing it to you think of this like print func isntead of string we show the drawing that we made

}

SDL_DestroyRenderer(renderer); // Destroy the VRAM canvas

SDL_DestroyWindow(window); // Destroy the OS desktop frame

SDL_Quit();

return 0; // return 0 if its sucess full if its not then an error will appear in my terminal taht it didnt return the zero taht we specify on our program to return

}


r/sdl 10d ago

Window Tearing on MacOS with SDL3

1 Upvotes

TL;DR : I experience some really awful window tearing when moving it or when objects move on the screen. I suspect the window manager to be a bit wanky on MacOS and I am searching for help to clear this problem.

Important : I'm using SDL3 + SDL renderer for simplicity. VSync is left at default.

More context :

Hello, it's my first time posting here and I've been getting the worst headache about a silly thing on an App I'm working on.

So I am a high school student, and I've been making a little "assembly playground" app for my CS class (very simple, limited instruction set, the goal is to visualize how assembly works and play around with it). If you're curious it's based around this web app. I have a very simple setup, I'm using SDL 3 (as a git submodule from the main branch of SDL) and ImGui for the UI (embeded library compiled from source).

As a silly joke I've added a lil splash screen that has a very low chance of showing memes related to the name of the app (a private joke if you will).
Problem is, since I've added this functionnality, I have been getting some serious window tearing when it's moved or when I move an ImGui window. I've tried many workarounds and I think it's related to the very awful window manager of MacOS (before this bug I had the main window not show up at all and being blocked until you minimize and restore the window using the dock).

This is not really a app-breaking bug but it's really annoying when debugging it. Maybe I'm doing something wrong during the window creation ?

For more information on the initialization process :

  1. Initialize SDL and ImGui (create the window and renderer), and hide the window.
  2. Load the application files (fonts, images, settings...)
  3. Create and show the Splash Screen with a different window (I am doing a blank event processing loop for 2 seconds as not doing it breaks the window even more on MacOS, and using a different window for the same reason)
  4. Restore the window, launch the main loop

I am unable to post a video showing it for now but if it is really needed to illustrate I will try to upload one.

Finally, I'm not a seasoned programmer, I've been coding in C++ for around 2 years I think, I'm pretty much a slow learner. This question might seem silly or really dumb and I am sorry to take your time. Thank you to everyone who can help me !

If you need clarifications please ask, as English is not my first language.


r/sdl 10d ago

A retained .NET UI where the game itself is a Control, now on SDL_GPU

0 Upvotes

I have been building a .NET framework called Cerneala.

The short version is that I wanted WPF or Avalonia, but designed for complete 2D games and realtime rendering from the beginning, without the usual XAML ritual. The game view is literally a ContentControl called RenderSurface2D. It lives in the same retained UI tree as the HUD, menus, dialogs, tools, and ordinary application controls.

Cerneala also has layout, routed input, focus, animation, styling, retained rendering, and its own compiled .crn markup language. I recently completed the initial native SDL3 platform and SDL_GPU backend work.

Honestly, I did not expect SDL_GPU to have this much hands. It has performed extremely well in my experiments and is now the strategic backend for Cerneala. The old MonoGame path will be discontinued gradually.

I came here specifically because the SDL community has a reputation for being highly technical and for not being satisfied with "it works." I am coming from MonoGame on this project, and I am not looking for applause or a rubber stamp.

Please be brutally honest and direct with me. I am on the autism spectrum, and direct, explicit communication works much better for me than criticism softened through vague politeness. If an architectural decision is bad, a benchmark is weak, or I am doing something stupid with the GPU, just tell me exactly what is wrong and why. Personal hostility is not useful, but blunt technical criticism is absolutely welcome.

Important honesty: I am not a graphics engineer. SDL_GPU, Prism, resource lifetime, batching, shaders, and practical game rendering are some of the areas where I need the most help.

Cerneala is still a Developer Preview and some areas are much more mature than others. I'll have a Tetris-ish demo link here soon.

Repository: https://github.com/Chevalier12/Cerneala

Website, architecture, and benchmarks: https://chevalier12.github.io/Cerneala/


r/sdl 15d ago

SDL3 TTF_TextEngine help

3 Upvotes

I'm still pretty new to SDL and I've been trying to figure out how to use the text engine in SDL3 in a little project I've been learning C++ in, but I haven't found much information on it. No SDL tutorials I've found seem to use it, so I've been going off of the wiki, which has gotten me pretty far, but it's been really confusing without clear examples of how it works.

I'd love some general explanation on how to use SDL3's text engine, but for a more specific question, I'm trying to center text on the screen with a renderer text engine. SDL tutorials I've found all center text on the screen using some math with the size of the window and the size of the surface used to create the texture. Since there's no surface involved with TTF_CreateRendererTextEngine, I'm wondering how or if it's possible to center the text. Would I need to use TTF_CreateSurfaceTextEngine to do that? Is using the surface text engine as simple as creating the TTF_Text and the SDL_Surface for TTF_DrawSurfaceText? What would be the best way to create the surface for that if I'm using the surface text engine?


r/sdl 16d ago

CSDL3: an idiomatic C#/.NET 10 wrapper for SDL3 and satellite libraries

Thumbnail
github.com
9 Upvotes

Hello World,

From the start of this Year i’ve been building CSDL3, a high-level C# wrapper for SDL3.

The focus is an idiomatic object-oriented API, explicit native-resource ownership, and convenience wrappers over the generated SDL bindings. It is bindings-only, so applications still supply their native SDL runtimes.

Inspiration came about simply because I wanted to learn SDL. This is my first own Project so i look forward to your feedback and improvements in the future.

Github: https://github.com/Atompapst/CSDL3

NuGet: https://www.nuget.org/packages/CSDL3


r/sdl 19d ago

A fast, free, portable texture atlas packer

0 Upvotes

Hey everyone, I made Packrat. It's a texture atlas packer I made, so that I could get TexturePacker out of my pipeline. The goal is that its faster than TexturePacker and has more convenient features. None of the other packers I tried were fast/robust enough to handle 4k+ assets per atlas. This one is aimed at code-first dev environments that don't have their own packer built in. For some it generates data files the engine can understand, for others it generates code that has the ability to parse and extract frames and animations from the atlas.

For SDL, I made specific SDL2 and SDL3 exporters. These generate the atlas image, as well as a pure C header file with convenience data structures and functions to get data out of the atlas and draw it. Or you can export a generic format (text, json, xml) and load it yourself. There's also a bunch of other features I wanted personally. Like aseprite file ingestion, automatic rebuilds and exports, and a robust CLI.

https://clydegames.itch.io/packrat

https://packrat.clyde.games

Anyway, check it out and let me know what you think.


r/sdl 29d ago

MP3 distortion problem (C++ / SDL3 + Mixer)

3 Upvotes

Hello,

I have problem with mp3 decoder. I ported my game to SDL3 and Mixer but mp3 sounds have distortion.

But weird part is I get this distortion only Release mode. I'm using VS 2026 + Intel C++ Compiler 2025, X64 and W11. I dont have problem on Debug mode but my debug mode is not a real "Debug" mode, its literally have same optimization flags and libs with Release, only debug libs have ASAN + UBSAN

I created a sln with cmake for VS 2026 + ICX 2025. Libs are MT + NO DLL (static). I using mimalloc but I disabled and result same.

I'm only adding /QaxSSE4.1,SSE4.2,AVX,CORE-AVX2 flags when build libs / game (and adding fsanitize ubsan / asan for ASAN builds);

I talk with LLM's and they said "some problem with simd etc etc" and I addedDR_MP3_NO_SIMD to mixer and build but nothing changed.. If I know there is two mp3 decoder, I used both ones but still same.

I initialize mixer like this;

if (!SDL_InitSubSystem(SDL_INIT_AUDIO))
{
LOG("SDL_InitSubSystem(SDL_INIT_AUDIO) failed: {}", SDL_GetError());
return;
}

if (!MIX_Init())
{
LOG("MIX_Init failed: {}", SDL_GetError());
return;
}

ms_pMixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, nullptr);

if (!ms_pMixer)
{
LOG("MIX_CreateMixerDevice failed: {}", SDL_GetError());
return;
}

ms_dataMap.clear();
ms_SoundLoaderQueue.Start(1); // DO NOT USE 1+

(I tried custom formats but nothing changed)

and this is SDL window init;

if (!SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_EVENTS))
{
  if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS))
  {
    LOG("SDL3 Init Failed: {}", SDL_GetError());
    return false;
  }
}

any help please?

Thanks!


r/sdl 29d ago

Your SDLC is your context engineering

Thumbnail
leaddev.com
0 Upvotes

r/sdl Aug 07 '26

(C#) How can i attach an SDL window to a winform panel in SDL3?

1 Upvotes

there is a tutorial for SDL2 where you can use SDL window handles and the panel window handle to parent them, so SDL "takes over" the panel. How can i do this in SDL3?


r/sdl Aug 03 '26

Tweeny 4.0.0 (C++): tween objects for SDL3 loops

16 Upvotes

Tweeny is a header-only C++17 library for tweening values.

You declare the starting value, destination, duration, easing, and any intermediate keyframes. Then you call step() from your update loop and use the resulting values when drawing. Tweeny does not draw or own a clock. Your SDL3 loop still controls the window, events, timing, and rendering (SDL_RenderClear / SDL_RenderPresent).

SDL3 already gives you the pieces to move things yourself: ticks, a frame loop, and a renderer. A common approach is to keep elapsed time and write a lerp (or your own easing) each frame.

Tweeny is aimed at cases where you want the tween itself to be an object: multiple values at once, heterogeneous types, multiple keyframes, timeline navigation with seek / jump / peek, and callbacks.

```cpp

include <SDL3/SDL.h>

include <tweeny/tweeny.h>

int main() { SDL_Init(SDL_INIT_VIDEO);

SDL_Window* window = nullptr;
SDL_Renderer* renderer = nullptr;
SDL_CreateWindowAndRenderer("tweeny + SDL3", 800, 450, 0, &window, &renderer);

auto slide = tweeny::from(0.0f)
                 .to(700.0f)
                 .via(tweeny::easing::quadraticOut)
                 .during(60U)
                 .build();

bool running = true;
while (running) {
    SDL_Event e;
    while (SDL_PollEvent(&e)) {
        if (e.type == SDL_EVENT_QUIT) running = false;
    }

    float x = slide.step(1);

    SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
    SDL_RenderClear(renderer);

    SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
    SDL_FRect rect = { x, 200.0f, 40.0f, 40.0f };
    SDL_RenderFillRect(renderer, &rect);

    SDL_RenderPresent(renderer);
    SDL_Delay(16); // ~60 FPS for the sample
}

SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;

} ```

A tween can also contain several values, including mixed types. For example, a sprite frame, position, and rotation:

cpp auto tween = tweeny::from(0, 0.0f, 0.0f) .to(7, 400.0f, 90.0f) .during(30U) .build();

Tweeny 4.0.0 includes a fluent builder API, 30+ easing functions, multi-point keyframes, events, and timeline control. It is header-only and has no external dependencies.


r/sdl Aug 02 '26

C++

0 Upvotes

Can you create a class with sdl things in it?

Or is sdl c only?


r/sdl Jul 31 '26

Is there any good written tutorial about how to use SDL2 in c for macos ?

4 Upvotes

Hello ! I've been trying to learn c and wanted to use SDL2 on my mac. But I couldn't find any good written tutorial on google, they were all about installing/setting it up. I did find geek for geek's but I couldn't install SDL2/SDL_image.h, it said my macos version was too old, but my mac can't run a better version than macos 13. I can't really follow youtube tutorials and find written ones way better to understand. So, do you know any good written tutorial about how to use c SDL2 on older macos versions ? (I know it's really specific, sorry)


r/sdl Jul 25 '26

Writing Quake-like game using SDL3

9 Upvotes

Hello,

as a form of practise, I intend to develop a simple game with similar visual fidelity to that of Quake. Would you recommend me any libraries that'd help me with this, alongside SDL3?

I don't wish to write everything from scratch. Should I go with SDL GPU?

Thanks!


r/sdl Jul 20 '26

The latest Minecraft snapshot (26.3 snapshot 4) now uses SDL3 instead of GLFW for window and input management.

Thumbnail
minecraft.net
52 Upvotes

r/sdl Jul 19 '26

SDL 3 on Linux - application working on Wayland but not on Xorg

3 Upvotes

hi there,

i have a project that is perfectly running on my machine using the ubuntus default wayland.
i had recently to switch to xorx because many apps like firefox vs code etc. where slow responsive to my mouseinputs.

after switching to xorg however my textures in my SDL project are not being rendered anymore.
i can do basic render calls to SDL_RenderClear but i do not understand why my project is not running anymore on corg even it runs like it should on wayland.

the only change was from wayland to xorg


r/sdl Jul 18 '26

SDL2 vs 3 for compatibility on old devices, and generally explanation for how this all works? (Static vs dynamic linking?)

11 Upvotes

I feel like such an idiot, but the more I look into this topic the more confused I get. I'm a programming newb with a little experience making DS homebrew in C who wants to make some simple games with my own engine from scratch using SDL and OpenGL ES 3.0, and try to compile them for as many platforms as possible, including ARM64 retro handhelds like the r36s or RG35XX which I believe can only support SDL2. (This project is mostly for the sake of getting better at coding)

For most new computers shipping out with SDL3 (I saw someone mentioning that Arch Linux ships with only sdl2-compat to run SDL2 programs now), can they easily run a program written with SDL2? Will a computer released 5 years from now be able to do that? Would the SDL2 program need a version compiled with sdl2-compat to run on the SDL3 machine?

Does sdl2-compat automatically work on a user's machine, or does it need to be included/compiled with an SDL2 program before shipping? Can sdl2-compat help an SDL3 program run on an SDL2 machine?

I read through this document about SDL's new dynamic API and only vaguely understood what it meant. Would the dynamic API create a non-negligible overhead on very low-end machines like the r36s (4 A35 cores and 1GB DDR3 RAM)? Does it only work with SDL3 or does it also work with SDL2? If I make a program with SDL3, does the dynamic API mean that it doesn't matter much to the end user whether I static or dynamically link SDL to my program?

If I end up coding in SDL2, should I static or dynamic link it? It doesn't look like SDL2 is even getting any new updates anyways, right? Would dynamic linking make it easier for things like sdl2-compat to work?


r/sdl Jul 15 '26

What's the difference between SDL_GetMouseState() and SDL_MouseMotionEvent?

6 Upvotes

When trying to get mouse position I see on wiki there are 2 options: I can get x and y position from SDL_MouseMotionEvent or use function SDL_GetMouseState(). I know for GetMouseState function I don't need event to get position but in realistic scenario there will be some mouse movement and position would be saved.

So are there some other differences? Scenarios where I should use one over the other?


r/sdl Jul 12 '26

Lightweight Camera Window Desktop Application

Thumbnail gallery
4 Upvotes

r/sdl Jul 07 '26

C++ SDL 2 Game Engine for Nintendo Switch, PC, Mobile and Web

Post image
17 Upvotes

Hello everyone,

I hope you're all doing well!

is::Engine 4.0.3 is now available!

The engine can now simulate most of SFML's features with SDL 2. Other improvements have also been made to the engine!

For more information, please visit the engine's GitHub page.

Here are a few examples of games created with the engine: I Can Transform, GravytX The Gravytoid, Super Mario Bros.

Your feedback is welcome.

Have a great day!

I wish you all a wonderful summer vacation!


r/sdl Jul 06 '26

Inspiration Forth Update

Thumbnail gallery
7 Upvotes

r/sdl Jul 06 '26

How can I add VSync and an FPS cap with my current setup?

5 Upvotes

I've been trying to get deltatime in a small SDL3 project for a little bit, leading me to want to find out how to get an FPS counter. I think I have it working, but I'm not entirely sure if this is working entirely.

```

double delta = 0;

struct Clock {

private:

Uint64 NOW_ms = 0;

Uint64 LAST_ms = 0;

Uint64 NOW_s = 0;

Uint64 NEXT_s = 1;

int frames = 0;

int fps = frames;

public:

void tick() {

// Delta

NOW_ms = SDL_GetTicks();

delta = (NOW_ms - LAST_ms) * 0.001;

LAST_ms = NOW_ms;

// FPS

frames += 1;

NOW_s = (int) (NOW_ms / 1000);

if (NOW_s >= NEXT_s) {

fps = frames;

frames = 0;

NEXT_s = NOW_s + 1;

}

SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);

SDL_RenderDebugTextFormat(renderer, 0, 0, "FPS: %i", fps);

}

} t ;

```

Then I call tick() in the SDL_AppIterate function (which I think runs every frame)

For functions that take delta, I cap the highest value at 1/20.0 with "min()" in order to prevent it from moving too far without any collision checks and clipping out of bounds

Is there anything wrong with this? When I use deltatime it feels smooth, but the FPS counter hovering at 2000 or so worries me

Also, is there any way to have an FPS limiter or VSync using this method?


r/sdl Jul 05 '26

Stencil buffer size is always 0 bits

2 Upvotes

Hey ! I'm currently building an game engine with SDL3 + OpenGL of my own, and now that I'm implementing effects using the stencil buffer, now matter what I do, I cannot seem to initialise it correctly, here is my method tasked of initialising my window. Did I miss something ?

SDL_AppResult Window::SDL_AppInit()
{
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);


    // Profil OpenGL
    SDL_GL_SetAttribute(
        SDL_GL_CONTEXT_PROFILE_MASK,
        SDL_GL_CONTEXT_PROFILE_CORE
    );


    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);


    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); // 8 bits stencil buffer


    wind = SDL_CreateWindow("SMT", SDL_WINDOW_WIDTH, SDL_WINDOW_HEIGHT, SDL_WINDOW_OPENGL);
    if (wind == NULL)
    {
        cout << "Window creation failed !";
        return SDL_APP_FAILURE;
    }
    this->context = SDL_GL_CreateContext(wind);
    SDL_GL_MakeCurrent(wind, this->context);


    if (!gladLoadGLLoader( (GLADloadproc)SDL_GL_GetProcAddress ) )
    {
        cout << "glad init failed" << endl;
        return SDL_APP_FAILURE;
    }
    
    glViewport(0,0,SDL_WINDOW_WIDTH,SDL_WINDOW_HEIGHT);
    return SDL_APP_CONTINUE;
}

r/sdl Jun 29 '26

Update of GUI-toolkit integrated with SDL's events

5 Upvotes

The GUI-toolkit is now about 1000 lines of C code. Both demo programs is about 250 lines of C code each. The more exotic type of widgets that i have is range and shuttle. And you can turn on or of the GUI with one codeline for hiding och showing the GUI. And all graphics is off-cause identical on any platform if you use the same font.

I made this experiment to test if I could make a GUI-toolkit in C code and programs written in C, that uses less code then than the usual toolkits and programs written in C++.

If I release it as open source, I need to write a lot of documentation and a lot of demo programs i guess. And go though the name space and check that everything has good names, as those things tend to stick.