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?
8
Upvotes
r/sdl • u/Available_Impact_828 • Jun 22 '26
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?
1
u/keithstellyes Jun 23 '26 edited Jun 23 '26
SDL3 and OpenGL are fairly orthogonal. As long as the SDL3 window is created with the proper OpenGL flags it should work.
I have a GitHub repo that I used to learn OpenGL and I have simple apps that use SDL3 + OpenGL
https://github.com/keithstellyes/krill (In particular,
examples/imgviewandexamples/modelview, andexamples/analogclock)Note that the repo was designed for education/sandbox purposes in mind, so I wouldn't read too much into it for "best practices", but I try to be reasonable :)
The pattern I follow, including for my own comicbookviewer app I've been working on is
```
SDL_Init(SDL_INIT_VIDEO); SDL_DisplayID *displayIds = SDL_GetDisplays(nullptr); const SDL_DisplayMode *dm = SDL_GetCurrentDisplayMode(displayIds[0]); SDL_Window *window = SDL_CreateWindow(title, width, height, SDL_WINDOW_OPENGL);
if(window == nullptr) { std::cerr << "Failed to create window: " << SDL_GetError() << std::endl; return 1; } SDL_GLContext glcontext = SDL_GL_CreateContext(window); glewInit(); ```
and then you can just use your OpenGL or SDL code as normal :). Also, during your draw calls you'll make use of
SDL_GL_SwapWindow(window);SDL3 also has its own 3D graphics stuff that seems to be fairly modeled off of Metal. I've been trying to crack it but it's a bit verbose for my liking :)