Witam uczę się biblioteki graficznej z kursu LazyFoo jednak napotykam na problem.
Odświeżając ekran za pomocą SDL_Flip(screen) wywala mi program. Oto kod.
#include "SDL.h"
#include "SDL_image.h"
SDL_Surface * load_image(const char * filename);
int init(SDL_Surface * destination);
void apply_surface(int x, int y, SDL_Surface * source , SDL_Surface * destination);
void clean_up(void);
int main(void)
{
SDL_Surface * screen = NULL;
SDL_Surface * image = NULL;
if( init(screen) == -1)
{
return 1;
}
if ( (image = load_image("obrazek.png") ) == NULL )
{
return 1;
}
apply_surface(0,0,image,screen);
SDL_Flip(screen); // tutaj wywala
SDL_Delay(1000);
clean_up();
return 0;
}
//***********************************************
SDL_Surface * load_image(const char * filename)
{
SDL_Surface * loadedImage = NULL;
SDL_Surface * optimizedImage = NULL;
loadedImage = IMG_Load(filename);
if(loadedImage != NULL)
{
optimizedImage = SDL_DisplayFormat(loadedImage);
SDL_FreeSurface(loadedImage);
}
if(optimizedImage != NULL)
return optimizedImage;
else
return NULL;
}
int init(SDL_Surface * destination)
{
if ( SDL_Init( SDL_INIT_EVERYTHING ) == -1)
return -1;
if( (destination = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE)) == NULL)
return -1;
SDL_WM_SetCaption("obrazek",NULL);
return 0;
}
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);
}
void clean_up(void)
{
SDL_Quit();
}
Z góry dziękuje za pomoc