Bltting RGBA surfaces associatively

I want to blit one RGBA surface onto another, but there appears to be no way to do this in SDL. I guess we’re supposed to write our own functions for this or something.
Anyway, I think I worked out the correct formulas, but I am stumped as to how to access the pixel values to actually implement it.

I found several pages that talk about setting and getting rgb values from a surface, but none of them mention how to get the alpha values as well. How do you do this?

SDL_BlitSurface?

Storyyeller wrote:> I want to blit one RGBA surface onto another, but there appears to be

no way to do this in SDL. I guess we’re supposed to write our own
functions for this or something.
Anyway, I think I worked out the correct formulas, but I am stumped as
to how to access the pixel values to actually implement it.

I found several pages that talk about setting and getting rgb values
from a surface, but none of them mention how to get the alpha values
as well. How do you do this?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

With SDL 1.2, you do need to write your own blitter if you want to combine
the source and destination alpha values. SDL will give you three kinds of
blits: Direct copies, colorkeyed transparency, or alpha-blend preserving
destination alpha. There’s a table on this page:
http://code.bluedinosaurs.com/tutorials/blending.html

That table indicates what kind of blits are available and when you should
use SDL_SetAlpha() to enable or disable SDL_SRCALPHA. Sprig (
http://code.bluedinosaurs.com/SPriG.html) has a blitter (look for
SPG_BlendBlit in SPG_surface.c) that you can look at and I believe SDL_gfx (
http://www.ferzkopp.net/joomla/content/view/19/14/) does too, though I’ll be
the first to admit that Sprig’s is simple and slow (and I have no experience
with SDL_gfx’s).

Jonny DOn Sun, Jan 10, 2010 at 1:59 PM, Andre de Leiradella < aleirade at sct.microlink.com.br> wrote:

SDL_BlitSurface?

Storyyeller wrote:

I want to blit one RGBA surface onto another, but there appears to be no
way to do this in SDL. I guess we’re supposed to write our own functions for
this or something.
Anyway, I think I worked out the correct formulas, but I am stumped as to
how to access the pixel values to actually implement it.

I found several pages that talk about setting and getting rgb values from
a surface, but none of them mention how to get the alpha values as well. How
do you do this?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

As Jonny said, SDL_gfx has a alpha to alpha blitter which was originally
used to assemble multiple SDL_ttf rendered text surfaces into a single
new surface while maintaining transparency.
The source code is here and should be easily adaptable:
http://sdlgfx.svn.sourceforge.net/viewvc/sdlgfx/SDL_gfxBlitFunc.c?revision=1&view=markup

Jonathan Dearborn wrote:> With SDL 1.2, you do need to write your own blitter if you want to

combine the source and destination alpha values. SDL will give you
three kinds of blits: Direct copies, colorkeyed transparency, or
alpha-blend preserving destination alpha. There’s a table on this page:
http://code.bluedinosaurs.com/tutorials/blending.html

That table indicates what kind of blits are available and when you
should use SDL_SetAlpha() to enable or disable SDL_SRCALPHA. Sprig
(http://code.bluedinosaurs.com/SPriG.html) has a blitter (look for
SPG_BlendBlit in SPG_surface.c) that you can look at and I believe
SDL_gfx (http://www.ferzkopp.net/joomla/content/view/19/14/) does too,
though I’ll be the first to admit that Sprig’s is simple and slow (and
I have no experience with SDL_gfx’s).

Jonny D

On Sun, Jan 10, 2010 at 1:59 PM, Andre de Leiradella <aleirade at sct.microlink.com.br <mailto:aleirade at sct.microlink.com.br>> wrote:

SDL_BlitSurface?

Storyyeller wrote:

    I want to blit one RGBA surface onto another, but there
    appears to be no way to do this in SDL. I guess we're supposed
    to write our own functions for this or something.
    Anyway, I think I worked out the correct formulas, but I am
    stumped as to how to access the pixel values to actually
    implement it.

    I found several pages that talk about setting and getting rgb
    values from a surface, but none of them mention how to get the
    alpha values as well. How do you do this?
    ------------------------------------------------------------------------

    _______________________________________________
    SDL mailing list
    SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
    http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
     

_______________________________________________
SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Andreas Schiffler wrote:

As Jonny said, SDL_gfx has a alpha to alpha blitter which was originally
used to assemble multiple SDL_ttf rendered text surfaces into a single
new surface while maintaining transparency.
The source code is here and should be easily adaptable:
http://sdlgfx.svn.sourceforge.net/viewvc/sdlgfx/SDL_gfxBlitFunc.c?revision=1&view=markup

Blending multiple SDL_ttf images is exactly what I would like to achieve also. I tried with many SDL_SetSurfaceBlendMode but with no proper alpha channel result. I am unable to build sdl_gfx against SDL 1.3 for example:

Error 3 error C2039: ‘offset’ : is not a member of ‘SDL_Surface’ c:\libs\sdl_gfx-2.0.20\sdl_gfxblitfunc.c 63 SDL_gfx

do you plan to update sdl_gfx for SDL 1.3? Or maybe you could contribute your blitters to SDL and new SDL_BlendModes could be added? :wink:

Or maybe there is a way to do this with SDL 1.3 already and I am just too stupid to figure this out? Any advice? To clarify:

I want to make a surface that is a combination of multiple sdl_ttf surfaces, for example a text with shadow. How do I preserve alpha values in resulting surface?