#include "SDL/SDL.h"
#include <string>
#include "SDL/SDL_image.h"
const int SCREEN_WIDTH = 700;
const int SCREEN_HEIGHT = 500;
const int SCREEN_BPP = 32;
SDL_Surface *guy = NULL;
SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;
SDL_Surface *load_image(std::string filename)
{
SDL_Surface* loadedImage = NULL;
SDL_Surface* optimizedImage = NULL;
loadedImage = IMG_Load(filename.c_str());
if(loadedImage != NULL)
{
optimizedImage = SDL_Display Format(loadedImage);
SDL_FreeSurface(loadedImage);
}
if(optimizedImage != NULL)
{
Uint32 colorkey = SDL_MapRGB(optimizdImage->format, 0, 0xFF, 0xFF);
SDL_SetColorkey(optimizedImage, SDL_RLEACCEL | SDL_SRCOLORKEY, colorkey);
}
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, NULL, destination, &offset);
}
int main(int argc, char** args)
{
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return 1;
}
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SCREEN_SWSURFACE);
SDL_WM_SetCaption("Look At Me", NULL);
guy = load_image("SuperChar2.png");
background = load_image("background.png");
apply_surface(0,0,background,screen);
apply_surface(100,120,guy,screen);
if(SDL_Flip(screen)==-1)
{
return 1;
}
SDL_Delay(5000);
SDL_FreeSurface(guy);
SDL_FreeSurface(background);
SDL_Quit();
}
First SDL Try a Failure
optimizedImage = SDL_Display Format(loadedImage);
should be
optimizedImage = SDL_DisplayFormat(loadedImage);
You've also got case issues with your SDL_SetColorKey calls and some other typos. Be sure to type the function names and other items exactly as they appear in the tutorial.
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SCREEN_SWSURFACE);
I fixed most of the typos, but there was still one in this line. I don't know what it is can you help?
Both in game development and teaching yourself, you're bound to run into many "failures". This, however, is the best way to learn. Don't give up and keep on trying to find out what's wrong.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement