#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <SDL/SDL.h>
using namespace std;
SDL_Surface* back;
SDL_Surface* image;
SDL_Surface* screen;
int xpos=0,ypos=0;
int InitImages()
{
back = SDL_LoadBMP("bg.bmp");
image = SDL_LoadBMP("lol.bmp");
return 0;
}
void DrawIMG(SDL_Surface* img, int x, int y, int w, int h, int x2, int y2)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_Rect dest2;
dest2.x = x2;
dest2.y = y2;
dest2.h = h;
dest2.w = w;
SDL_BlitSurface(img, &dest2, screen, &dest);
}
void DrawIMG(SDL_Surface* img, int x, int y)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_BlitSurface(img, NULL, screen, &dest);
}
void DrawBG()
{
DrawIMG(back, 0, 0);
}
void DrawScene()
{
DrawIMG(back, xpos-2, ypos-2, 132, 132, xpos-2, ypos-2);
DrawIMG(image, xpos, ypos);
SDL_Flip(screen);
}
int main(int argc, char argv[])
{
Uint8* keys;
if(SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0)
{
cout << "unable to init SDL: %s\n",SDL_GetError();
exit(1);
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(640,480,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
if(screen == NULL)
{
cout << "Unable to set graphics mode: %s\n",SDL_GetError();
exit(1);
}
InitImages();
DrawBG();
int done = 0;
while(done == 0)
{
SDL_Event event;
while(SDL_PollEvent(&event) )
{
if(event.type == SDL_QUIT)
{
done = 1;
}
if(event.type == SDL_KEYDOWN)
{
if(event.key.keysym.sym = SDLK_ESCAPE)
{
done = 1;
}
}
}
keys = SDL_GetKeyState(NULL);
if(keys[SDLK_UP]){ypos -= 1; }
if(keys[SDLK_DOWN]){ypos += 1; }
if(keys[SDLK_LEFT]){xpos -= 1; }
if(keys[SDLK_RIGHT]){xpos += 1; }
DrawScene();
}
return 0;
}
SDL compiling problems in Dev c++
hi, i have a problem when trying to compile my SDL code.
this is the error messages:
[Linker error] undefined reference to `SDL_RWFromFile'
[Linker error] undefined reference to `SDL_LoadBMP_RW'
[Linker error] undefined reference to `SDL_RWFromFile'
[Linker error] undefined reference to `SDL_LoadBMP_RW'
[Linker error] undefined reference to `SDL_UpperBlit'
[Linker error] undefined reference to `SDL_UpperBlit'
[Linker error] undefined reference to `SDL_Flip'
[Linker error] undefined reference to `SDL_Init'
[Linker error] undefined reference to `SDL_GetError'
[Linker error] undefined reference to `SDL_Quit'
[Linker error] undefined reference to `SDL_SetVideoMode'
[Linker error] undefined reference to `SDL_GetError'
[Linker error] undefined reference to `SDL_PollEvent'
[Linker error] undefined reference to `SDL_GetKeyState'
[Linker error] undefined reference to `WinMain@16'
ld returned 1 exit status
and here is my code:
Add the following to the linker options under project->project options->parameters
-lmingw32
-lSDLmain
-lSDL
-lSDL_ttf
Although the last one is only needed if you are using the TTF library.
Hope that helps..:)
-lmingw32
-lSDLmain
-lSDL
-lSDL_ttf
Although the last one is only needed if you are using the TTF library.
Hope that helps..:)
Quote:Original post by vgmtech
Add #include <sdl/sdlimage.h>
A: It's SDL_Image.h
B: He isn't using sdl_image, and probably doesnt have it.
It's -l as in lowercase 'L', not I [wink]. And it's -lmingw32. What erros do you get now? If you link in all the libraries in the same order Mr. Fletcher has listed, you should have working code.
If you want to create a SDL program using Dev-C++ I recommend to create a SDL project. You can find it in the new project dialog and then the multimedia tab. It has two options: pure SDL and the combination of SDL and OpenGL. Then add you code to the project and it will compile fine.
You need to link the library's in a specific order to get it to work.
-lmingw32
-lSDLmain
-lSDL
These three have to be linked in that order.
-lmingw32
-lSDLmain
-lSDL
These three have to be linked in that order.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement