1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#include "SDL/SDL.h"
//screen attributes
const int SCREEN_HEIGHT = 500;
const int SCREEN_WIDTH = 500;
const int SCREEN_BPP = 32;
//screen
SDL_Surface *screen = NULL;
//the surface
SDL_Surface *surface = NULL;
//function to draw a surface to the screen
void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination)
{
SDL_Rect offsets;
offsets.x=x;
offsets.y=y;
SDL_BlitSurface(source,NULL,destination,&offsets);
}
int main(int argc, char* args[])
{
//Initialize SDL
SDL_Init(SDL_INIT_EVERYTHING);
//Set screen to video mode
screen = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,SDL_SWSURFACE);
//==========================================================================
//Here I'm trying to create an empthy surface:
//allocate memory
surface = new SDL_Surface;
//set width and height
surface->clip_rect.w = 300;
surface->clip_rect.h = 300;
//Draw the surface white (this comand crashes the program)
SDL_FillRect(surface,&surface->clip_rect,SDL_MapRGB(surface->format,0xff,0xff,0xff));
//apply the surface to the screen
apply_surface( 100, 100, surface, screen);
//flip screen
SDL_Flip(screen);
//whait before ending
SDL_Delay(5000);
//free surface
SDL_FreeSurface(surface);
//==========================================================================
//quit SDL
SDL_Quit();
return 0;
}
|