Sign in to follow this  

[SDL] Storing perpixel alpha after alphablended blit

Recommended Posts

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:
[code]SDL_Surface *a = TTF_RenderText_Blended(font, "Hello!", color);[/code]
...and (b) like that:
SDL_Surface *tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, b->w, b->h, 32, 0, 0, 0, 0);
b = SDL_DisplayFormatAlpha(x);[/code]

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

...and blit (a) on (b):
[code]SDL_BlitSurface(a, NULL, b, NULL);[/code]

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 :)

Share this post

Link to post
Share on other sites
Excatly that's the point! If I fill (b) with '[i]SDL_FillRect(b, NULL, SDL_MapRGBA(b->format, 0, 0, 0, 0))[/i]' and blit (b) on the screen I see nothing because all pixel's of (b) have alpha '0'.
If I would call [i]SDL_FillRect(b, NULL, SDL_MapRGBA(b->format, 0, 0, 0, 128)), [/i](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?

Share this post

Link to post
Share on other sites
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: 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?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this