Just recently started learning SDL and have this problem, this program should properly display my background and message on the screen, but instead its just a black screen. Did the Blit, did the Flip, maybe im missing something? Heres the code:
P.S i know i might forgot to add some simple line or something, but i just cant find it ^^
#include <SDL.h>
#include <string>
SDL_Surface* Load_image(std::string filename)
{
SDL_Surface* loadedimage = 0;
SDL_Surface* optimizedimage = 0;
loadedimage = SDL_LoadBMP(filename.c_str());
if ( loadedimage != 0 )
{
SDL_Surface* optimizedimage = SDL_DisplayFormat(loadedimage);
SDL_FreeSurface(loadedimage);
}
return optimizedimage;
}
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,0,destination,&offset);
}
int main(int argc,char** argv)
{
SDL_Surface* screen = 0;
SDL_Surface* background = 0;
SDL_Surface* message = 0;
if ( SDL_Init(SDL_INIT_EVERYTHING) == -1 )
{
return 1;
}
screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
if ( screen == 0 )
{
return 1;
}
SDL_WM_SetCaption("Hello world","player.bmp");
message = Load_image("hello.bmp");
background = Load_image("background.bmp");
apply_surface(0,0,background,screen);
apply_surface(180,140,message,screen);
if ( SDL_Flip(screen) == -1 )
{
return 1;
}
SDL_Delay(2000);
SDL_FreeSurface(message);
SDL_FreeSurface(background);
SDL_Quit();
return 0;
}