Original Post
Hi! everybody.
The code below should create a window with image.bmp as its background image.But when I run it creates a window without the image.I tried everything,my image is in the same folder of my project and main.cpp. The code is exactly same from a youtube tutorial and works fine for many people.Please tell what's wrong in this.
Thanks in advance.
#include
SDL_Surface *screen=NULL;
SDL_Surface *background=NULL;
bool gamerunning = true;
SDL_Event event;
void apply_surface(int x,int y,SDL_Surface *source,SDL_Surface *destination){
SDL_Rect rect;
rect.x=x;
rect.y=y;
SDL_BlitSurface(source,NULL,destination,▭);
}
int main(int argc,char *argv[]){
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption("Apply Images",NULL);
screen=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
background=SDL_LoadBMP("image.bmp");
//Game Loop
while(gamerunning){
if(SDL_PollEvent(&event)){
if(event.type==SDL_QUIT)
gamerunning=false;
}
//Apply surface
apply_surface(0,0,background,screen);
//Update Screen
SDL_Flip(screen);
}
SDL_Quit();
return 0;
}
The code below should create a window with image.bmp as its background image.But when I run it creates a window without the image.I tried everything,my image is in the same folder of my project and main.cpp. The code is exactly same from a youtube tutorial and works fine for many people.Please tell what's wrong in this.
Thanks in advance.
#include
SDL_Surface *screen=NULL;
SDL_Surface *background=NULL;
bool gamerunning = true;
SDL_Event event;
void apply_surface(int x,int y,SDL_Surface *source,SDL_Surface *destination){
SDL_Rect rect;
rect.x=x;
rect.y=y;
SDL_BlitSurface(source,NULL,destination,▭);
}
int main(int argc,char *argv[]){
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption("Apply Images",NULL);
screen=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
background=SDL_LoadBMP("image.bmp");
//Game Loop
while(gamerunning){
if(SDL_PollEvent(&event)){
if(event.type==SDL_QUIT)
gamerunning=false;
}
//Apply surface
apply_surface(0,0,background,screen);
//Update Screen
SDL_Flip(screen);
}
SDL_Quit();
return 0;
}