Getting SDL on your System:
To begin, you must have the SDL libraries somewhere on your system so that your development environment can see them. Because SDL is open source, you can obtain the libraries for free at http://www.libsdl.org.
Once you have the SDL libraries on your hard drive somewhere, I'd take a minute to look through them. There should be three folders: docs, include, and lib; along with a number of other files. Read the readme's and familiarize yourself with some of the contents.
In the docs folder, believe it or not, you can find documentations on various SDL functions. This is a very good resource when you need to know the parameters a certain function takes. It is very useful and detailed; I personally use these a bunch.
In the include folder, you can find the header files for SDL. I personally wouldn't spend much time looking through all of these; the only thing you will need to include to use SDL is SDL.h.
In the lib folder, you can find three files: SDL.lib, SDLmain.lib, and SDL.dll. SDLmain.lib and SDL.lib are static libraries to which you will link your application, and SDL.dll is a dynamic link library, which means you must put it in the same folder as your application. I will talk more about these later in the tutorial.
Setting up the VC++ Envirnment
Aight, now lets get to work on setting up the VC++ environment so you can begin using SDL. This section will assume you have Microsoft Visual C++ (because that's what I have. If I ever decide to get DevC++, I'll post that too). The first thing we need to do is let VC++ know where it can find the .lib and the .h files for SDL.
Okay, open up VC++ (no duh). Then, select Tools, Options, as shown below.
The options box will appear. Select the directories tab, as shown below.
Here you will see a list of directories (it may be different than mine, I have multiple libraries set up already). You need to add the path to the SDL include files to the list. To do so, just lick the first blank line in the list, and you should see something like the screen below.
Here you either type in the directory to the include folder, or you browse it by clicking the dots. Though your directory may be different than mine, yours will look something like the below picture.
Now that you did this, you must do the exact same thing for the SDL lib files. Select Library files from the dropdown menu. Then you should see something like the screen below.
From here, the process is exactly the same as above. Click the next available space, and add the directory that contains SDLmain.lib and SDL.lib. When you are done, yours should look something like the below screen.
Aight, you’re done with that. If you think about it, that was actually easy.
Creating an SDL Project
Okay, assuming that you are following this tutorial in order and have already set the VC++ environment, I am now going to walk you through the steps that you need to repeat each and every time you make a project that uses SDL.
1. The first thing to do is create the project. select File, New, chose Win32 Application, and then name it whatever you want. Hit okay, then you will be prompted for the type of WIN32 project you would like to make. Select Empty Project, then click finish.
2. Next, you need to copy SDL.dll from the SDL libs directory into your project's directory.
3. Now select Project, Settings, then select the Link tab in the dialog box that appears
4. In the Object/Library Modules text box, type in sdl.lib and sdlmain.lib. Make sure to use spaces to separate each item in the text box.
5. Next, select the C/C++ tab. From the category dropdown menu, select the code generation option.
6. From the Use Run-Time Library drop-down menu, select multithreaded DLL.
7. Hit the okay button, then drink a keg of Bawls to celebrate. You can now begin deving in SDL.
Testing the Envirnment
Okay, the point of this tutorial is to set up SDL, not teach you how to use it. So I am not going to explain or comment my code, just bear with me.
Now, we're going to test your project just to be sure you set it up correctly. Make a new .cpp file. (file, new, cpp source file) and name it whatever.
Now, just paste the code below into the new .cpp file.
Code: Select all
#include "sdl.h"
#include <stdio.h>
int main(int argc, char* argv[]) {
if(SDL_Init(SDL_INIT_VIDEO)==-1) {
fprintf(stderr,"Something is screwed, couldn't initialize.\n");
}
else {
fprintf(stderr,"It worx! W00t! Initialized properly!\n");
SDL_Quit();
}
return(0);
}
Aight, compile and run the code. If it works, then I have done my job well. If not, scroll up and try to find the problem. Good luck people, I hope you enjoyed my first tutorial. It would be appreciated if you Private Message me and tell me if this tutorial is of any help to anyone. Sorry if it’s a bit choppy and/or hard to follow, it is my first.
People, post SDL tutorial here if you ever feel good enough to make one. Just please, keep your information accurate. If there is a problem with mine, please contact me immidiately.