Hello
I just wrote two functions in my new class that, init(), creates a SDL_Surface
containing a string of text using a bitmap font and, draw(), blits that surface
onto the screen at the coordinates stored in te class.
Everyhing works fine and the text looks nice, but then I decided to make a
border around the text. So I made the surface that stores the string 2px bigger
(and nudged the letters 1px) and SDL_FillRect’ed it with white, and since the
bitmap letters have a black bg, that should make only the white border show.
The problem is that it doesn’t seem to matter how big I make the surface (with
SDL_CreateRGBSurface()), only the letters will show (and they still look nice!)
If I comment out the loop that blits the letters, nothing shows on the screen.
Have I misunderstood the SDL_FillRect(), or what is happening here?
Thanks! / Johan
(In the code below, the number 10s should be 2, but I exaggerated the size to
show what I mean)
from: main.cpp
star MyStar;
MyStar.init(“TestName”);
MyStar.setXY(20,20); // sets the coords stored in the class…
MyStar.draw(screen);
SDL_Flip(screen);
end: main.cpp
from: star.cpp
void star::init(string newName)
{
name = newName;
// Make the name a image with the bitmapfont
SDL_Surface *bitmapFont;
bitmapFont = SDL_LoadBMP("bitmapfont/lemyellow.bmp");
Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
// *** This is where I create the surface ***
nameImg = SDL_CreateRGBSurface(SDL_SWSURFACE,
name.length()*BMPFONT_CHARWIDTH + 10,// <--
BMPFONT_CHARHEIGHT + 10, // <--
32, rmask, gmask, bmask, amask);
if(nameImg == NULL)
{
fprintf(stderr, "CreateRGBSurface failed: %s\n", SDL_GetError());
exit(1);
}
// *** And here I try to fill it with white ***
SDL_FillRect(nameImg, NULL, 0xFFFFFF);
SDL_Rect src, dest;
src.w = BMPFONT_CHARWIDTH;
src.h = BMPFONT_CHARHEIGHT;
src.y = 2;
dest.y = 1;
for (int i = 0; i < name.length(); i++)
{
dest.x = 1 + i*BMPFONT_CHARWIDTH;
if (name[i] >= 33 && name[i] <= 126)
{
src.x = (name[i] - 33)*(BMPFONT_CHARWIDTH+1) + 1;
}
else
src.x = 847;
SDL_BlitSurface(bitmapFont, &src, nameImg, &dest);
}
}
void star::draw(SDL_Surface *screen)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_BlitSurface(nameImg, NULL, screen, &dest);
}
end: star.cpp___________________________________________________________
Yahoo! Messenger - want a free and easy way to contact your friends online? http://uk.messenger.yahoo.com