Wednesday, October 24, 2007

A Crash Course using SDL

Section 1.0: Making SDL Work



Section 1.1: Setting up SDL

To obtain SDL simply click the link below

SDL Package



Once you have downloaded the folder carefully go through the following instructions!


  1. Unzip the folder to your desktop


  2. You should find the 6 sub folders. Make a sub folder on your desktop and call it SDL


  3. Go into each of the include folders in all 6 sub folders and copy all of the header files and drag them into the SDL folder in which you have just created.

  4. Copy that SDL folder into the VC\include directory.


  5. Now go back to the SDL Family folder and in each of those sub folders there are lib folders. In each of those lib folders copy all those files to you VC\lib folder.

  6. Then in each of those lib folders there are .dll files. Copy all of those .dll files into the C:\WINDOWS\system32 folder.

  7. You're now ready to setup your Project, and start working with the SDL Family!





Section 1.2: Setting up your IDE


  • Open up Visual C++ and create a new Project

  • Under Templates choose Win32 console applications

  • The Win32 Console Wizard will pop up click next

  • Under Application type make sure the Console Application is checked

  • Under Additional Options check Empty Projects and click Finish

  • Go to Solution Explorer go to your 'Source Files' folder and create new item

  • Create new .cpp source file, and name it and click Finish





Section 1.3: Testing SDL with a Quick Code



#include "SDL\SDL.h"

bool gameIsRunning;

SDL_Event the_event;

int main( int argc, char* args[] )
{
gameIsRunning = true;

//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption("Text on our Window!", NULL);

while(gameIsRunning)
{
while(SDL_PollEvent(&the_event))
{
if(the_event.type == SDL_QUIT) gameIsRunning = false;
}
}

//Quit SDL
SDL_Quit();



Now simply hit F5 for a quick compile and run.. If you get a window with a black background with the title, “First SDL Test!” like figure 1.3 below then you have successfully finished all of section 1.
Figure 1.3 First SDL Test!

Figure 1.3 A screen shot of our first SDL Project successfully made.

I will now discuss the graphics part of SDL and how SDL handles graphics in C++.