Original Post
My function "ApplySurface" does not work, and by no stretch of the imagination I know why. Can you help me?
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <string>
using namespace std;
SDL_Surface * LoadImage(const string &filename);
void ApplySurface(short x, short y, SDL_Surface *source, SDL_Surface *destination);
//Variables
SDL_Surface *screen = NULL;
SDL_Surface *image = NULL;
SDL_Event event;
bool end = false;
int main(int argc, char *args[])
{
if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return 1;
}
screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
if(screen == NULL)
{
return 1;
}
image = LoadImage("monster.jpg");
if(image == NULL)
{
return 1;
}
//ApplySurface(0,0,image,screen); //Here it stops!
if(SDL_Flip(screen) == -1)
{
return 1;
}
while(!end)
{
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
end = true;
}
}
}
return 0;
}
SDL_Surface * LoadImage(const string &filename)
{
SDL_Surface * Image = NULL;
SDL_Surface * OptimizedImage = NULL;
Image = IMG_Load(filename.c_str());
if((Image) != NULL)
{
OptimizedImage = SDL_DisplayFormat(Image);
SDL_FreeSurface(Image);
}
}
void ApplySurface(short x, short y, SDL_Surface *source, SDL_Surface *destination)
{
SDL_Rect rect;
rect.x = x;
rect.y = y;
SDL_BlitSurface(source, NULL, destination, ▭);
}
Thanks Stromberg.