After setup SDL in Dev-C++ , let's see how simple it is to create a window ! At the beginning , the most difficult part is to setup an environment for a successful compilation. The programming part is relative simple , since it is just making a logic flow. Once you can make it , then you are on the half way of success !
In Dev-C++ , select File -> New -> Project
Click on "Empty Project" , then type in SDLWin for project name.
Create a folder "ATest" and save the project in there.
After saved the project file , click on "ICON New" and select "Source File CTRL+ N ".
Then Yes for add new file to the current project.
You should see a blank file attaching to Project SDLWin on left hand side.
Select File -> Save As CTRL + F12 -> give it a name "test.cpp"
Type in the following program code and save it.
Or you can download this attachment and Add it to Project SDLWin.
Select Execute -> Compile & Run F9
You should be able to see this window pops up for 5 sec.
If you see it , that's a good good sign. That means you win !
You made a window for 5 sec !!!
That's quite simple , isn't it?
So , let's check the document of SDL to see what we did.
The document locate in :
Since we are going to use the function that defined in SDL.h , thus we include
SDL_Surface's represent areas of "graphical" memory, memory that can be drawn to.
Later , we will fill the color in the window , so it needs a SDL Surface to store the color information.
SDL_Quit shuts down all SDL subsystems and frees the resources allocated to them. This should always be called before you exit.
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) exit(1);
Initializes SDL. This should be called before all other SDL functions.
We can initialize video , audio , cd rom , joy stick , timer by their flag. Since we only
use video function here , so only put in flag "SDL_INIT_VIDEO"
SDL_WM_SetCaption("SDL Window", NULL);
This is what the caption will show in the bar of a window.
screen = SDL_SetVideoMode( 640 , 480 , 32 , SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_ANYFORMAT);
The attributes of the windows been set in here. Width=640 , Height =480 , 32 bit per pixel
Check the document for more flags.
SDL_FillRect(screen , NULL , 0x66FF00);
This function performs a fast fill of the given rectangle with color. If dstrect is NULL, the whole surface will be filled with color.
The color format is 0xRRGGBB
Use this function to update screen.
SDL_Delay( 5000 );
Ask the system delay 5000 msec
Lesson 3 END
That's very amazing & impressive , isn't it?
The SDL almost wrap all heavy work and let user be able to create a window
in a minute !
Let's continue with the excited Lesson 4 : Load a bmp image file into a window
Copyright © 2009 bdragon All rights reserved.
SDLgamer Menu >