Converting from SDL2 to SDL3 on Windows
These notes were made when converting an existing C game that used SDL2 to SDL3 on Windows. The game was originally developed for Linux Format and I had got it running on Windows with SDL2.
Windows include paths have been made consistent with Linux. The include files path for SDL3 need to be SDL3\… when setting them up. For SDL2, I had them in a folder c:\SDL2\include but noted that in SDL2.h include files were like this:
#include "SDL_main.h" #include "SDL_stdinc.h"
While in SDL3’s SDL.h they are
#include <SDL3/SDL_stdinc.h> #include <SDL3/SDL_assert.h>
So I put them c:\SDL3\SDL3
When you include them in your software they are like this:
#include <SDL3/SDL.h> #include <SDL3/SDL_image.h>
Which is how they are in Linux.
The rest of these notes are taken from the differences between the SDL2 and SDL3 versions of the game. They are not complete but intended to give you an idea of some of the changes you may need to do.
SDL_TTF
TTF_RenderUTF8_Blended( is now TTF_RenderText_Blended with an extra text length parameter.
SDL_Rects are mostly replaced by SDL_FRect
This is a big change. Everywhere I was passing in an SDL_Rect became an SDL_Frect which is four floats rather than four ints.
SDL_RenderCopy is now SDL_RenderTexture and the last two params are now SDL_FRects.
To fix this I used a load of (float) casts.
SDL_RenderDrawLine becomes SDL_RenderLine and has an SDL_FRect parameter instaed of SDL_Rect.
Same for SDL_RenderDrawPoint which becomes SDL_RenderPoint.
SDL_GetMouseState keeps the same name but returns float * for both parameters now.
Setup changes slightly
There’s no SDL_SetMainReady() and SDL2main.lib is gone.
Also gone is SDL_INIT_EVERYTHING in SDL_Init()– you have to or the specific subunits. E.g. SDL_INIT_VIDEO | SDL_INIT_EVENTS
Also there’s no SDL_RENDERER_PRESENTVSYNC for SDL_CreateRenderer. Vsync is disabled by default as I found when my game ran about 30x faster and finished in a few seconds! Instead you need to call SDL_SetRenderVSync(renderer, 1) where 1 is syncing with each retrace, or 2 with every 2nd retrace.
Several of the events have been renamed, so SDL_KEYDOWN becomes SDL_EVENT_KEY_DOWN, SDL_MOUSEBUTTONDOWN becomes SDL_EVENT_MOUSE_BUTTON_DOWN and similar for other events. Also event.key.keysym.sym becomes event.key.key.
Finally SDL_FreeSurface( becomes SDL_DestroySurface.
I’m sure there are more but changing these was sufficent to get my game compiling and running correctly with SDL3.