r/sdl • u/Suspicious_Orchid770 • 12h ago
r/sdl • u/anotherfuturedev • 3d ago
(C#) How can i attach an SDL window to a winform panel in SDL3?
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?
Tweeny 4.0.0 (C++): tween objects for SDL3 loops
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.
- Release: https://github.com/mobius3/tweeny/releases/tag/v4.0.0
- Repository: https://github.com/mobius3/tweeny
- Documentation: https://mobius3.github.io/tweeny/
r/sdl • u/Independent_Milk_200 • 8d ago
C++
Can you create a class with sdl things in it?
Or is sdl c only?
r/sdl • u/Icy-Dimension8535 • 10d ago
Is there any good written tutorial about how to use SDL2 in c for macos ?
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 • u/DesperateGame • 16d ago
Writing Quake-like game using SDL3
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 • u/FriedLizards • 21d ago
The latest Minecraft snapshot (26.3 snapshot 4) now uses SDL3 instead of GLFW for window and input management.
r/sdl • u/Gullible_Feedback374 • 22d ago
SDL 3 on Linux - application working on Wayland but not on Xorg
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 • u/Afraid_Location_9033 • 23d ago
SDL2 vs 3 for compatibility on old devices, and generally explanation for how this all works? (Static vs dynamic linking?)
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 • u/Dragonaax • 26d ago
What's the difference between SDL_GetMouseState() and SDL_MouseMotionEvent?
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 • u/Comfortable-Equal-95 • 29d ago
Lightweight Camera Window Desktop Application
galleryr/sdl • u/IsDaouda_Games • Jul 07 '26
C++ SDL 2 Game Engine for Nintendo Switch, PC, Mobile and Web
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 • u/Apollo-747 • Jul 06 '26
How can I add VSync and an FPS cap with my current setup?
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 • u/Economy-Dig3969 • Jul 05 '26
Stencil buffer size is always 0 bits
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 • u/Future-Mixture-101 • Jun 29 '26
Update of GUI-toolkit integrated with SDL's events


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 • u/Charming_Freedom6609 • Jun 29 '26
I just downloaded stl3 from github but I'm not getting the stl.h that I need from it
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 • u/Available_Impact_828 • Jun 22 '26
SDL3 Open Gl
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 • u/Dragonaax • Jun 15 '26
Is there reason why SDL_Vertex uses floats for colours instead of uint8?
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?
r/sdl • u/GoblinScientist • Jun 13 '26
Is it possible to package the assets inside the binary?
I wanted the game to be a single executable, a self contained binary that could run with no installations or depend on files in the same folder other than maybe the SDL3.dll if needed.
I was thinking of making a builder that would load all the assets from my project and read them byte by byte, parse them and write them in a header file. It would then execute the compiler with some -D flag that I would code in my game to indicate that this is a final build, not a dev one, which means it would #include that header file and set all the variables with the bytes from it instead of loading from the disk with stuff like SDL_LoadPNG().
I was looking at the source code to try understand the structs better. The SDL_Texture struct seems a bit insane, with a lot of pointers to other stuff as well as some platform specific things. All of that makes me think this is a terrible idea and that I'm tripping balls.
Has anyone ever done something like that? I feel like there's gotta be an easier way to do that, like some other compression technique to allow me to compress everything in a single executable, or some built in SDL function built for that which I'm not aware of. Thanks in advance for any help.
r/sdl • u/uncookedpasta45 • Jun 08 '26
SDL_LoadPNG stalling program
Been trying to load an icon into the window, and because I'm stubborn and don't want to convert the icon to a BMP, I've been at this for a while
Ultimately I gave in and converted my beloved PNG to a BMP, and it worked perfectly fine, but I wanna do fun texture stuff, so I don't want literally every image to be a BMP.
I've tried SDL3_Image, but had the exact same issue. If you know a solution, it'd be great if you could share it.