- Code: Select all
#include <SDL/SDL.h>
#include <iostream>
using namespace std;
void DrawPixel(SDL_Surface *screen, int x, int y, Uint8 R, Uint8 G, Uint8 B);
void Slock(SDL_Surface *screen);
void Sulock(SDL_Surface *screen);
int main(){
if( SDL_Init( SDL_INIT_VIDEO|SDL_INIT_AUDIO ) < 0 )
{
cout << "Unable to init SDL: " << SDL_GetError() << endl;
return 1;
}
atexit(SDL_Quit);
SDL_Surface *screen;
screen = SDL_SetVideoMode( 640, 480, 32, SDL_HWSURFACE|SDL_DOUBLEBUF );
if ( screen == NULL )
{
cout << "Unable to set 640x480 video: " << SDL_GetError() << endl;
return 1;
}
return 0;
}
void DrawPixel(SDL_Surface *screen, int x, int y, Uint8 R, Uint8 G, Uint8 B){
Uint32 color = SDL_MapRGB(screen->format, R, G, B);
switch (screen->format->BytesPerPixel)
{
case 1: // Assuming 8-bpp
{
Uint8 *bufp;
bufp = (Uint8 *)screen->pixels + y*screen->pitch + x;
*bufp = color;
}
break;
case 2: // Probably 15-bpp or 16-bpp
{
Uint16 *bufp;
bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x;
*bufp = color;
}
break;
case 3: // Slow 24-bpp mode, usually not used
{
Uint8 *bufp;
bufp = (Uint8 *)screen->pixels + y*screen->pitch + x * 3;
if(SDL_BYTEORDER == SDL_LIL_ENDIAN)
{
bufp[0] = color;
bufp[1] = color >> 8;
bufp[2] = color >> 16;
} else{
bufp[2] = color;
bufp[1] = color >> 8;
bufp[0] = color >> 16;
}
}
break;
case 4: // Probably 32-bpp
{
Uint32 *bufp;
bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x;
*bufp = color;
}
break;
}
}
void Slock(SDL_Surface *screen){
if ( SDL_MUSTLOCK(screen) )
{
if ( SDL_LockSurface(screen) < 0 )
{
return;
}
}
}
void Sulock(SDL_Surface *screen){
if ( SDL_MUSTLOCK(screen) )
{
SDL_UnlockSurface(screen);
}
}
and the output from the compiler looks like this.
- Code: Select all
cd '/home/gareth/documents/Programming/C-C++/sdl1/debug' && WANT_AUTOCONF_2_5="1" WANT_AUTOMAKE_1_6="1" make -k
make all-recursive
Making all in src
compiling sdl1.cpp (g++)
linking sdl1 (libtool)
linking sdl1 (g++)
sdl1.o: In function `main':/home/gareth/documents/Programming/C-C++/sdl1/src/sdl1.cpp:13: undefined reference to `SDL_Init'
:/home/gareth/documents/Programming/C-C++/sdl1/src/sdl1.cpp:15: undefined reference to `SDL_GetError'
:/home/gareth/documents/Programming/C-C++/sdl1/src/sdl1.cpp:18: undefined reference to `SDL_Quit'
:/home/gareth/documents/Programming/C-C++/sdl1/src/sdl1.cpp:21: undefined reference to `SDL_SetVideoMode'
:/home/gareth/documents/Programming/C-C++/sdl1/src/sdl1.cpp:25: undefined reference to `SDL_GetError'
sdl1.o: In function `DrawPixel(SDL_Surface*, int, int, unsigned char, unsigned char, unsigned char)':/home/gareth/documents/Programming/C-C++/sdl1/src/sdl1.cpp:33: undefined reference to `SDL_MapRGB'
sdl1.o: In function `Slock(SDL_Surface*)':/home/gareth/documents/Programming/C-C++/sdl1/src/sdl1.cpp:79: undefined reference to `SDL_LockSurface'
sdl1.o: In function `Sulock(SDL_Surface*)':/home/gareth/documents/Programming/C-C++/sdl1/src/sdl1.cpp:89: undefined reference to `SDL_UnlockSurface'
collect2: ld returned 1 exit status
make[2]: *** [sdl1] Error 1
make[2]: Target `all' not remade because of errors.
make[2]: Nothing to be done for `all-am'.
make[1]: *** [all-recursive] Error 1
make: *** [all-recursive-am] Error 2
make: Target `all' not remade because of errors.
*** Exited with status: 2 ***
At first I thought the #include <SDL/SDL.h> statement was wrong but upon trying different combinations I got a ton more of errors, this second load of errors was repeated for every combination bar the original file so I'm assuming the statement was correct.
Any help would be appreciated.