The problem with the SDL

I used the SDL to add a picture in the background, and the program works but it truned white and then it showed "the program stoped working". My picture "hellow.bmp" is 304*304 and the picture "background.bmp"is also 304*304

where I learned the code:http://lazyfoo.net/SDL_tutorials/lesson02/index.php


My source code:

#include <SDL.h>
#include <SDL_image.h>
#include <string>
using namespace std;
const int SCREEN_WIDTH=1200;
const int SCREEN_HEIGHT=800;
const int SCREEN_BPP=32;
SDL_Surface*myimage=NULL;
SDL_Surface*screen=NULL;
SDL_Surface*background=NULL;
SDL_Surface*load_image(std::string danny)
{
SDL_Surface*loadedimage=NULL;
SDL_Surface*optimazedimage=NULL;
loadedimage=SDL_LoadBMP(danny.c_str());
if(loadedimage!=NULL)
{
optimazedimage=SDL_DisplayFormat(loadedimage);
SDL_FreeSurface(optimazedimage);

}
return optimazedimage;
}
void apply_Surface (int x, int y, SDL_Surface*source,SDL_Surface*destination)

{
SDL_Rect offset;
offset.x=x;
offset.y=y;
SDL_BlitSurface(source,NULL,destination,&offset);

}
int main(int argc, char*args[])
{
if (SDL_Init(SDL_INIT_EVERYTHING)==-1)
{
return 1;
}

screen=SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,SDL_SWSURFACE);
if(screen == NULL )
{
return 1;
}



myimage=load_image("hellow.bmp");
background=load_image("backgroung.bmp");
apply_Surface(320,0,background,screen);
apply_Surface(0,240,background,screen);
apply_Surface(320,240,background,screen);
apply_Surface( 180, 140, myimage, screen );
if(SDL_Flip(screen)==-1)
{
return 1;
}

SDL_Delay(7000);
SDL_FreeSurface(myimage);
SDL_FreeSurface(background);
SDL_Quit();
return 0;


}
Topic archived. No new replies allowed.