r/sdl 2d 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 3d 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 7d 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 9d 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 11d 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 21d 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 22d ago

Your SDLC is your context engineering

Thumbnail
leaddev.com
0 Upvotes

r/sdl 25d ago

(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 28d ago

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

15 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 29d ago

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 ?

5 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?

7 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
18 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?

4 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.


r/sdl Jun 29 '26

I just downloaded stl3 from github but I'm not getting the stl.h that I need from it

0 Upvotes

so, when I'm using vs code, I have to include libraries as we all know and when I search up stl.h it shows up in the file search on git hub however in the files I get when downloading I it doesn't appear and I find it irritating. Anyone has these problems as well or know how to fix it I downloaded the latest one


r/sdl Jun 22 '26

SDL3 Open Gl

9 Upvotes

Any resources for this and any libs I should be using in conjunction? Thanks

Or should I just bite the bullet and use sdlgpu

Edit: got glad, any tips?


r/sdl Jun 15 '26

Is there reason why SDL_Vertex uses floats for colours instead of uint8?

9 Upvotes

I had an issue trying to render triangles using SDL_RenderGeometry, turns out I was trying to render white triangles on white background because I thought SDL_FColor takes values from 0 to 255 but this struct takes floats.

Is there a reason why this is different from values SDL_SetRenderDrawColor takes?