Problems with SFont

This topic is 4236 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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 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 on other sites
Ok, that makes sense, but then why do I get the errors?

Share on other sites
Those should be warnings not errors.

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 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 on other sites
See edit on previous post...Thanks for the help.