Well, there is a lot going on here. It should work fine without using an
alpha channel. Don’t use any SDL_SetAlpha() calls, don’t use SDL_SRCALPHA,
and set the color key of _srf to black.
I think the main problem with your alpha-blending approach is that you pass
0 as the Amask argument to SDL_CreateRGBSurface(). I recommend using a
32-bit surface and passing explicit mask arguments (from the old docs):
SDL_Surface *surface;
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
surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
rmask, gmask, bmask, amask);
…
You should also stick to software surfaces. SDL 1.2 does not do much in
the way of hardware acceleration and if you’re doing alpha blending, you
might just be making it slower by using HW surfaces.
If you have a blank RGBA surface, blitting to it will not change the alpha
values, so you’ll see nothing at first. Use SDL_SetAlpha(surface, 0,
surface->format->alpha) to disable alpha-blending, then do your blitting
onto the new surface. TTF_RenderText_Solid() should have set the color key
for you. Use SDL_SetAlpha(surface, SDL_SRCALPHA, surface->format->alpha)
to enable alpha-blending again when you’re done. The ‘alpha’ argument
won’t actually make any difference if you’re using alpha-blending. This
should work with TTF_RenderText_Blended() too, so you can get even
nicer-looking text.
Last thing. In your loop there, you need SDL_FreeSurface(_auxSrf) after
the blit to free the surface that SDL_ttf allocated. You will probably
need to find a good place to free _srf too, but after you’re done using it.
Jonny DOn Mon, Feb 6, 2012 at 7:15 PM, psychoalienx wrote:
**
First thanks for your answers,
Jonny,
My code looks like this
Code:
_srf=SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA
,w,(numLines*(_format->leading + _format->size)),24,0,0,0,0);
SDL_SetAlpha(_srf,SDL_SRCALPHA | SDL_RLEACCEL,0);
do{
_auxSrf=TTF_RenderText_Solid(_format->_font, textLines[i].c_str(),
_format->textColor);
SDL_Rect rect;
rect.x=getX();
rect.y=getY()+(i*(_format->leading + _format->size));
if(SDL_BlitSurface(_auxSrf,NULL,_srf,&rect)) printf(“No se pudo copiar
en Screen %s”,SDL_GetError());
i++;
}while(i < textLines.size());
When I set the alpha parameter in SDL_SetAlpha function to 255, the whole
surface disappear including the text. That makes transparent the entire
surface, not just the background. I had also tried with SDL_SetColorKey
(black) and disabled the alpha blending: SDL_SetAlpha(_srf,SDL_RLEACCEL,0);
Now, I will try with the SDL_gfx that Andreas suggests, unless you can see
what I am doing wrong.
Thanks again.
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org