Presentation is loading. Please wait.

Presentation is loading. Please wait.

Games at Bolton Simple Directmedia Layer Andrew Williams 01204-903839.

Similar presentations


Presentation on theme: "Games at Bolton Simple Directmedia Layer Andrew Williams 01204-903839."— Presentation transcript:

1 Games at Bolton Simple Directmedia Layer Andrew Williams A.Williams@bolton.ac.uk A.Williams@bolton.ac.uk 01204-903839

2 Games at Bolton What is SDL?  SDL is a library (a standardized set of functions) for doing: –Games –Multimedia type applications  It is rather lightweight –Nothing like as much functionality as BlitzBasic, for example You might create something like BlitzBasic with SDL

3 Games at Bolton SDL History  Created by Sam Lantinga  Used by Loki Games in their short-lived attempt to port various games to Linux  Licensed under the LGPL: –http://www.libsdl.org/license.phphttp://www.libsdl.org/license.php –Our use of the library falls within the LGPL

4 Games at Bolton SDL Resources  SDL Homepage: –http://www.libsdl.org/http://www.libsdl.org/ You can download SDL from the SDL homepage –http://sdldoc.csn.ul.ie/http://sdldoc.csn.ul.ie/ A documentation project for SDL –http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/gfxsdl/index A (rather good) series of tutorials

5 Games at Bolton SDL vs DirectX  SDL –Simple –Started on Linux Now cross-platform –Patchy documentation –Development is ad hoc Some talented people working part-time –Something of a hobby  DirectX –Very sophisticated –Standard on Windows Windows only –Superb documentation –Development is very well organized Very bright people –Strategic product for Microsoft

6 Games at Bolton SDL vs DirectX  Not really a like-for-like comparison –On Windows, SDL sits on top of DirectX to get the very best acceleration out of modern graphics hardware  DirectX is highly integrated –Direct3D –DirectSound  SDL uses –OpenGL –SDL_mixer

7 Games at Bolton SDL components  SDL –The basic library  SDL_mixer –Dynamic audio mixing and streaming  SDL_image –Loading image files (apart from BMP)  We'll use other stuff as we find it

8 Games at Bolton SDL Basics  Initializing the SDL system SDL_Init(Uint32 flags); Uint32 means 32-bit unsigned integer flags is the parameter to the function We have to create a number to tell SDL which parts we want to initialize. We have several possibilities: –SDL_INIT_TIMER –SDL_INIT_VIDEO –SDL_INIT_AUDIO –SDL_INIT_JOYSTICK –etc

9 Games at Bolton SDL Basics  In the first tutorial, we initialize the video and the audio  We combine the numbers with a bit-wise OR operation (don't worry if you don't understand that): SDL_Init(INIT_VIDEO | INIT_AUDIO);

10 Games at Bolton SDL Basics  In practice, it's not a good idea to assume that the function succeeded. We should really test it: if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0 ) { printf("Unable to init SDL: %s\n", SDL_GetError()); return 1; }

11 Games at Bolton SDL Basics  Creating a surface to draw on 1.Declare a variable 2.Call the function 3.Check for error SDL_Surface *screen; screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE|SDL_DOUBLEBUF); if ( screen == NULL ) { printf("Unable to set 640x480 video: %s\n", SDL_GetError()); return 1; }

12 Games at Bolton Drawing the Scene void DrawScene(SDL_Surface *screen) { Slock(screen); for(int x=0;x<640;x++) { for(int y=0;y<480;y++) { DrawPixel(screen,x,y,y/2,y/3,x/3); } Sulock(screen); SDL_Flip(screen); }

13 Games at Bolton Drawing the Scene void DrawScene(SDL_Surface *screen) { Slock(screen); for(int x=0;x<640;x++) { for(int y=0;y<480;y++) { DrawPixel(screen,x,y,y/2,y/3,x/3); } Sulock(screen); SDL_Flip(screen); } Question: What do the parameters to DrawPixel represent?

14 Games at Bolton Drawing the Scene void DrawScene(SDL_Surface *screen) { Slock(screen); for(int x=0;x<640;x++) { for(int y=0;y<480;y++) { DrawPixel(screen,x,y,y/2,y/3,x/3); } Sulock(screen); SDL_Flip(screen); } Question: What do Slock and Sulock do?

15 Games at Bolton Exercises  Questions –What does atexit(SDL_QUIT); do? –What is the error condition for SDL_Init(...) ?  Tasks –Alter DrawScene(...) so that the calls to DrawPixel(..) use constant values (eg 50 or 100 ) instead of y/2, y/2 and x/3 What happens?


Download ppt "Games at Bolton Simple Directmedia Layer Andrew Williams 01204-903839."

Similar presentations


Ads by Google