I just started learning SDL so I can make games in C++,
but for some reason my code fails to compile.
The code:
#include "SDL/SDL.h"
#include <string>
using std::string;
int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;
SDL_Surface *message = NULL;
SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;
SDL_Surface *load_image(string filename)
{
SDL_Surface* loadedImage = NULL;
SDL_Surface* optimizedImage = NULL;
loadedImage = SDL_LoadBMP(filename.c_str());
if(loadedImage != NULL)
{
optimizedImage = SDL_Display_Format(loadedImage);
SDL_FreeSurface(loadedImage);
}
return optimizedImage;
}
void applySurface(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 = SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
if(screen == NULL) { return 1; }
SDL_WM_SetCaption("Hello World", NULL);
message = load_image("message.bmp");
background = load_image("background.bmp");
apply_surface(0, 0, background, screen);
apply_surface(200, 200, message, screen);
if(SDL_Flip(screen) == -1) { return 1; }
SDL_Delay(5000);
SDL_FreeSurface(message);
SDL_FreeSurface(background);
SDL_Quit();
return 0;
}
Here's the errors I got:
||=== Test_SDL, Release ===|
C:\Programming\C++\Newbie\TutorialStuff\Hello_SDL\main.cpp||In function `SDL_Surface* load_image(std::string)'
C:\Programming\C++\Newbie\TutorialStuff\Hello_SDL\main.cpp|20|error: `SDL_Display_Format' was not declared in this scope|
C:\Programming\C++\Newbie\TutorialStuff\Hello_SDL\main.cpp|20|warning: unused variable 'SDL_Display_Format'|
C:\Programming\C++\Newbie\TutorialStuff\Hello_SDL\main.cpp||In function `int SDL_main(int, char**)'
C:\Programming\C++\Newbie\TutorialStuff\Hello_SDL\main.cpp|40|error: `SetVideoMode' was not declared in this scope|
C:\Programming\C++\Newbie\TutorialStuff\Hello_SDL\main.cpp|45|error: `apply_surface' was not declared in this scope|
C:\Programming\C++\Newbie\TutorialStuff\Hello_SDL\main.cpp|40|warning: unused variable 'SetVideoMode'|
||=== Build finished: 3 errors, 2 warnings ===|
I don't know what went wrong, it's either the code or SDL isn't set up properly...
I would like someone to tell me what's wrong, and
be able to fix it and explain.
Any help appreciated!
~ Xarver
P.S. I have attached a zip file with the things.