Advertisement

[SDL] Storing perpixel alpha after alphablended blit

Started by August 08, 2011 07:55 PM
2 comments, last by Modred 13 years, 4 months ago
I want to blit SDL_Surface (a), which has perpixel alpha, on SDL_Surface (b), which also has perpixel alpha, and lateron I want to blit (b) onto the screen (d) without losing the alphaeffect.

So (a) get's created that way, for example:
SDL_Surface *a = TTF_RenderText_Blended(font, "Hello!", color);
...and (b) like that:

SDL_Surface *tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, b->w, b->h, 32, 0, 0, 0, 0);
b = SDL_DisplayFormatAlpha(x);


Then I fill (b) with complete transparency:
SDL_FillRect(b, NULL, SDL_MapRGBA(b->format, 0, 0, 0, 0))

...and blit (a) on (b):
SDL_BlitSurface(a, NULL, b, NULL);


The thing is... When blitting the pixel's alphavalue of (b) isn't changed. All pixels still have '0' as alpha value(To be certain: They have the alpha value they got when filling (b)). Any ways to perform this action right?
(Please don't ask why I need this to be done. I can workaround it, sure. But it got me curious, that's why I am asking.)

Thanks :)
Once you blit b to the screen you do see

Hello!

right? If so then the alpha values did change or you wouldn't see the text.

Sprite Creator 3 VX & XP

WARNING: I edit my posts constantly.

Advertisement
Excatly that's the point! If I fill (b) with 'SDL_FillRect(b, NULL, SDL_MapRGBA(b->format, 0, 0, 0, 0))' and blit (b) on the screen I see nothing because all pixel's of (b) have alpha '0'.
If I would call SDL_FillRect(b, NULL, SDL_MapRGBA(b->format, 0, 0, 0, 128)), (b) would appear half transparent when blitted on (d).

So the problem is: When I blit (a) on (b), why aren't the pixel's alpha values of (b) overwritten(overblended) with the alpha values of (a)'s pixels?
Ok, I'm afraid I have to push this again. I came across the same thing again and still have no solution.

So the thing is: I want a TTF rendered (blended -> creates 32bit surfaces with alpha channel) text to appear letter by letter. Therefor I want to create a buffer - surface where the text is drawn on, so that every letter only gets rendered once. BUT, I still want to keep the alpha-values of the surface created by TTF_RenderText_Blended, so that the text appears antialised when I blit the buffer-surface on the screen.

The Problem: According to this: http://wiki.libsdl.org/moin.cgi/SDL_SetAlpha there is no possibility to blit 2 surfaces and 'merge' their per-pixel-alpha. Is there any way around copying the memory myself, line after line?

This topic is closed to new replies.

Advertisement