Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

A few problems with SDL in Ubuntu - Dapper

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
GMorgan
LXF regular


Joined: Thu Jan 12, 2006 6:58 pm
Posts: 684
Location: South Wales, UK

PostPosted: Mon Jul 17, 2006 5:19 pm    Post subject: A few problems with SDL in Ubuntu - Dapper Reply with quote

I'm turning my programming attention towards SDL but I'm running into a few difficulties. I've been following the first tutorial on this website. The program I'm running is below.

Code:
#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:
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.
Back to top
View user's profile Send private message
Nigel
LXF regular


Joined: Fri Apr 08, 2005 9:03 pm
Posts: 1141
Location: Gloucestershire, UK

PostPosted: Mon Jul 17, 2006 5:30 pm    Post subject: RE: A few problems with SDL in Ubuntu - Dapper Reply with quote

Looks like you're not including the SDL libraries in your link... is it a home-brewed makefile ?
_________________
Hope this helps,

Nigel.
Back to top
View user's profile Send private message
GMorgan
LXF regular


Joined: Thu Jan 12, 2006 6:58 pm
Posts: 684
Location: South Wales, UK

PostPosted: Mon Jul 17, 2006 6:11 pm    Post subject: RE: A few problems with SDL in Ubuntu - Dapper Reply with quote

I'm using Kdevelop, I started it as a simple hello world.

//edit - I've switched to a simple SDL project and it works now but the question is what has changed. I don't want to be unnecessarily tied to one IDE//
Back to top
View user's profile Send private message
Nigel
LXF regular


Joined: Fri Apr 08, 2005 9:03 pm
Posts: 1141
Location: Gloucestershire, UK

PostPosted: Tue Jul 18, 2006 10:05 am    Post subject: RE: A few problems with SDL in Ubuntu - Dapper Reply with quote

Check the makefile it has generated. I'll bet the new version includes the SDL libraries in the link whereas the old one didn't.
Look for options something like
Code:
 -lSDL -lSDL_mixer

_________________
Hope this helps,

Nigel.
Back to top
View user's profile Send private message
GMorgan
LXF regular


Joined: Thu Jan 12, 2006 6:58 pm
Posts: 684
Location: South Wales, UK

PostPosted: Tue Jul 18, 2006 3:26 pm    Post subject: RE: A few problems with SDL in Ubuntu - Dapper Reply with quote

I do have entries along these sorts of lines

LIBSDL_CFLAGS = @LIBSDL_CFLAGS@
LIBSDL_LIBS = @LIBSDL_LIBS@
LIBSDL_RPATH = @LIBSDL_RPATH@

# set the include path found by configure
AM_CPPFLAGS = $(LIBSDL_CFLAGS) $(all_includes)

# the library search path.
sdl1a_LDFLAGS = $(all_libraries) $(LIBSDL_RPATH)
sdl1a_LDADD = $(LIBSDL_LIBS)
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../config.h
CONFIG_CLEAN_FILES =
bin_PROGRAMS = sdl1a$(EXEEXT)
PROGRAMS = $(bin_PROGRAMS)

but I couldn't find the options mentioned when I greped the makefile.

I'm having trouble with seg faults on the second tutorial but I'll try to solve it myself before I come crying too much.
Back to top
View user's profile Send private message
Nigel
LXF regular


Joined: Fri Apr 08, 2005 9:03 pm
Posts: 1141
Location: Gloucestershire, UK

PostPosted: Wed Jul 19, 2006 10:39 am    Post subject: RE: A few problems with SDL in Ubuntu - Dapper Reply with quote

That's the downside of using an IDE... most of them will try to cater for so many possible situations that the makefiles they produce are horrendous tangles of spaghetti... almost as bad as the ones I write by hand Rolling Eyes
Still, if you're up & running, I'd stick with Kdevelop - switching IDEs mid-project is not for the faint-hearted !
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast