Sign in to follow this  
bschneid

Problems with SFont

Recommended Posts

I'm trying to use SFont with SDL and C++. I included the SFont.c in my project as their site says, but I get compiler warnings when it reaches that file. They are: In function 'Uint32 GetPixel(blahblah)...return of negative value '-1' to ' argument of negative value '-1' to ' I get those because an unsigned integer can't be negative, correct? So then why is a function that is supposed to return an unsigned integer designed to return a -1? I'm probably missing something here, but can anyone help? EDIT: Here is the function from SFont.c that is giving me trouble:
static Uint32 GetPixel(SDL_Surface *Surface, Sint32 X, Sint32 Y)
{
   Uint8  *bits;
   Uint32 Bpp;

   assert(X>=0);
   assert(X<Surface->w);
   
   Bpp = Surface->format->BytesPerPixel;
   bits = ((Uint8 *)Surface->pixels)+Y*Surface->pitch+X*Bpp;

   // Get the pixel
   switch(Bpp) {
      case 1:
         return *((Uint8 *)Surface->pixels + Y * Surface->pitch + X);
         break;
      case 2:
         return *((Uint16 *)Surface->pixels + Y * Surface->pitch/2 + X);
         break;
      case 3: { // Format/endian independent 
         Uint8 r, g, b;
         r = *((bits)+Surface->format->Rshift/8);
         g = *((bits)+Surface->format->Gshift/8);
         b = *((bits)+Surface->format->Bshift/8);
         return SDL_MapRGB(Surface->format, r, g, b);
         }
         break;
      case 4:
         return *((Uint32 *)Surface->pixels + Y * Surface->pitch/4 + X);
         break;
   }

   return -1;
}

Share this post


Link to post
Share on other sites
The bit pattern of -1 when interpreted as an unsigned value is the maximum value a unsigned can hold (assuming twos complement representation). Thus it makes a convenient error value.

Share this post


Link to post
Share on other sites
Yes they are but it still doesn't compile...is there a way to ignore warnings with Dev-C++? (yeah, yeah, laugh at me for using it...)

EDIT: Nvm, I got it working. Thanks for the help SiCrane. SiCrane.Rating++;

Share this post


Link to post
Share on other sites
If they are only warnings then it should compile. If it doesn't compile there must be some errors. What are those errors?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this