SDL_ttf/alpha issue - sorry - typo fixed:

Sorry about the near-duplicate post - the first one had a critical typo:

Hi,

I’ve taken over a project that has a function (see below) that is supposed to
return a SDL_Surface* containing text with a black outline. ?The surface
surrounding the text is supposed to be transparent. ?However, the entire
SDL_Surface comes out transparent. ?I have tested having the function return
some of the intermediate surfaces, and everything other than the "tmp"
surfaces immediately returned by TTF_RenderUTF8_Blended() comes out
transparent. Do I need to do something with SDL_SetAlpha() on the "tmp"
surfaces before I blit them to the “out” surface?

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define rmask 0xff000000
#define gmask 0x00ff0000
#define bmask 0x0000ff00
#define amask 0x000000ff
#else
#define rmask 0x000000ff
#define gmask 0x0000ff00
#define bmask 0x00ff0000
#define amask 0xff000000
#endif

SDL_Surface* black_outline(unsigned char *t, TTF_Font *font, SDL_Color *c) {
???SDL_Surface *out, *tmp, *tmp2;
???SDL_Rect dstrect;

    tmp = TTF_RenderUTF8_Blended(font, t, black);

???tmp2 = SDL_CreateRGBSurface(SDL_SWSURFACE,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?(tmp->w)+5,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?(tmp->h)+5,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 32,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? rmask, gmask,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bmask, amask);

???out = SDL_DisplayFormatAlpha(tmp2);
???SDL_FreeSurface(tmp2);

???dstrect.w = tmp->w;
???dstrect.h = tmp->h;

? ? ? ? for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
? ? ? ? ? for (dstrect.y = 1; dstrect.y < 4; dstrect.y++)
? ? ? ? ? ? SDL_BlitSurface( tmp, NULL, out, &dstrect );

? ? ? ? /* NOTE: if I return “out” at this point it is transparent */

???SDL_FreeSurface(tmp);

???/* — Put the color version of the text on top! — */
???tmp = TTF_RenderUTF8_Blended(font, t, *c);
???dstrect.x = dstrect.y = 2;
???SDL_BlitSurface(tmp, NULL, out, &dstrect);

???SDL_FreeSurface(tmp);

???/* — Convert to the screen format for quicker blits — */

???tmp = SDL_DisplayFormatAlpha(out);
???SDL_FreeSurface(out);

???return tmp;
}–
David Bruce