These instructions assume you're in Windows. For other platforms you need to adapt the instructions somewhat, but the steps are largely the same; some platforms are easier than others.
First off, you'll need development tools. This step varies a lot depending on your development (and target) platform; for Windows, grab the latest Visual Studio, likely the community edition but whatever works for you.
There's basically two ways to get SDL3. You could download the release from SDL website, or you can fetch the latest sources from github and building it yourself.
If you downloaded a release, you can skip forward to setting up development environment. Otherwise, let's fetch the sources with git.
If you don't have git, here's installation instructions. Once you do have git, you can fetch the sources from GitHub using the following command:
git clone https://github.com/libsdl-org/SDL.git
That command fetches the source code into the SDL
directory under the current one, so if you're in Windows you'll likely want to set up a sane directory structure first, e.g,
cd \
md dev
cd dev
git clone https://github.com/libsdl-org/SDL.git
That sequence of commands first goes to the root of your drive, creates the directory dev
, changes to that directory and then fetches the SDL
sources under it.
Next up we need to build the library. For Windows, open SDL.sln
under SDL/VisualC
and build the project. You may want to repeat the build for debug and release to produce both sets of binaries, but release should be enough (and should work fine even if your own project is a debug build).
Once this is done, you need to create another project that will work as the basis of this tutorial. Assuming we're at \dev
as I suggested above, create a new project into \dev\gptut
. For me, the steps were as follows, but your mileage may vary:
gptut
c:\dev
printf()
to. This is largely a matter of preference.OK
.Add a new .cpp
file to the project. I named mine main.cpp
. Paste the following into the file:
#include "SDL3/SDL.h"
#include "SDL3/SDL_main.h"
int main(int argc, char** argv)
{
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS))
{
return -1;
}
SDL_Quit();
return 0;
}
If you try to compile this, you'll find it doesn't build. You need to fix three things: include path, link to SDL3 library, and copy the DLL over.
Edit gptut project properties, go to C/C++
-> General
and edit the Additional Include Directories
(note that you may want to edit both debug and release configuration; to edit both at once, change "configuration" to "all configurations" before editing). If you're following my recommendations, the additional include directories might say C:\dev\SDL\include
.
If you try to build now, the compilation should succeed but linker will complain about unresolved external symbols.
Back in gptut project properties, go to Linker
-> Input
and add SDL3.lib to the Additional Dependencies
. Following my suggestions, said field might start with C:\dev\SDL\VisualC\x64\Release\SDL3.lib;
. Note that it's not the only thing in the field, make sure not to remove the old items.
Now the project should link, but if you run it, it will complain about not finding SDL3.dll
.
Fix this by copying C:\dev\SDL\VisualC\x64\Release\SDL3.dll
to c:\dev\gptut\
.
Now the program should start and quit immediately. If you got this far, congratulations, you've successfully set up the development environment!
Next up we'll get to 02 - SDL Skeleton and Putting Pixels..
Any comments etc. can be emailed to me.