Jump to content
  • Advertisement
Sign in to follow this  

[SDL] Storing perpixel alpha after alphablended blit

This topic is 2412 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

Share this post

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

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

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!