hi,
I am kinda new to SDL (a couple of hours) and I am stuck. i am trying to load
a bmp image on a surface. Here’s the code , the screen just initializes and
closes(after the delay) and I get this SDL_BlitSurface() error :-
SDL_UpperBlit: passed a NULL surface. The docs say if NULL is passed the
entire surface is copied, that does’nt seem to be happening.
thanks for your time
Nasir----------------------------------
#include “SDL.h”
void display_bmp(SDL_Surface *screen,char *file_name)
{
SDL_Surface *image;
image = SDL_LoadBMP(file_name);
if(image=NULL)
{
printf("failed loading image \n");
}
if((SDL_BlitSurface(image,NULL,screen,NULL))<0)
printf("Error BlitSurface : %s\n",SDL_GetError());
SDL_UpdateRect(screen,0,0,0,0);
/* Free the allocated BMP surface */
SDL_FreeSurface(image);
}
int main()
{
// Initialize SDL-Video Subsystem
if(SDL_Init(SDL_INIT_VIDEO)<0)
{
printf(“Could Not Initialize the SDL-VIDEO Subsystem %s”,SDL_GetError());
exit(1);
}
// Initialize tje SDL-Audio Subsystem
if(SDL_InitSubSystem(SDL_INIT_AUDIO)<0)
{
printf("Could Not Initialize the SDL-AUDIO Subsystem %s",SDL_GetError());
}
// Clean up resources on Exit : SDL_Quit() shutsdown all subsystems
atexit(SDL_Quit);
// Set up Video Mode
SDL_Surface *screen;
// SDL_Surface *SDL_SetVideoMode(height,width,bits-per-pixel,flags)
screen = SDL_SetVideoMode(640,480,0,SDL_SWSURFACE|SDL_ANYFORMAT);
if(screen==NULL)
{
printf("Cannot set Video Mode %s",SDL_GetError());
exit(1);
}
printf("Set video mode at 640x480 at %d
bits-per-pixel\n",screen->format->BitsPerPixel);
display_bmp(screen,"background.bmp");
SDL_Delay(1000); // wait for 1000 milliseconds before returning
return 0;