SDL2 and SDL_ttf text blending

Hi,

I want to render text on a texture with transparency. I’m using this method:

1 I’m loading a PNG with IMG_Load from SDL_image. It has transparent
regions.
2) I’m creating a SDL_Surface with TTF_RenderUTF8_Blended
3) blitting the render over the surface loaded in (1)

The point is that if I use TTF_RenderUTF8_Solid in (2), the blitting
produces the expected result: the text is on top of the image, including
previously transparent pixels.

But I use the Blended version, it blends nicely but only in those pixels of
the destination surface that don’t have transparency.

Why is this happening? or, why isn’t this behavior consistent between both
functions?

Thank you,

A

IIRC, I believe _Blended should be used when your text itself has an alpha
channel. It may be removing the transparency on the destination surface
because no alpha was set on the text?On Fri, Apr 26, 2013 at 9:46 AM, ?lvaro Castro-Castilla < alvaro.castro.castilla at gmail.com> wrote:

Hi,

I want to render text on a texture with transparency. I’m using this
method:

1 I’m loading a PNG with IMG_Load from SDL_image. It has transparent
regions.
2) I’m creating a SDL_Surface with TTF_RenderUTF8_Blended
3) blitting the render over the surface loaded in (1)

The point is that if I use TTF_RenderUTF8_Solid in (2), the blitting
produces the expected result: the text is on top of the image, including
previously transparent pixels.

But I use the Blended version, it blends nicely but only in those pixels
of the destination surface that don’t have transparency.

Why is this happening? or, why isn’t this behavior consistent between both
functions?

Thank you,

A


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

TTF_RenderUTF8_Solid does not use alpha transparency (and therefore does
not use alpha blending). That’s why it works in this case. _Blended will
give you nicer-looking results. I think your problem is that SDL2 probably
still preserves the destination alpha (as SDL 1.2 does). You get the color
result you want, but the destination alpha stays the same as it was before
the blit. I’m not sure how to resolve your particular issue perfectly, but
you could try seeing if SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_ADD)
works as you expect. Be sure to reset it afterward.

Jonny DOn Fri, Apr 26, 2013 at 9:51 AM, Alex Barry <alex.barry at gmail.com> wrote:

IIRC, I believe _Blended should be used when your text itself has an alpha
channel. It may be removing the transparency on the destination surface
because no alpha was set on the text?

On Fri, Apr 26, 2013 at 9:46 AM, ?lvaro Castro-Castilla < alvaro.castro.castilla at gmail.com> wrote:

Hi,

I want to render text on a texture with transparency. I’m using this
method:

1 I’m loading a PNG with IMG_Load from SDL_image. It has transparent
regions.
2) I’m creating a SDL_Surface with TTF_RenderUTF8_Blended
3) blitting the render over the surface loaded in (1)

The point is that if I use TTF_RenderUTF8_Solid in (2), the blitting
produces the expected result: the text is on top of the image, including
previously transparent pixels.

But I use the Blended version, it blends nicely but only in those pixels
of the destination surface that don’t have transparency.

Why is this happening? or, why isn’t this behavior consistent between
both functions?

Thank you,

A


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

Yes, that’s what happens. It preserves the alpha of the destination.
I’ve tried with NONE, ADD, BLEND, MOD as blending modes but I don’t get the
desired result.

Isn’t this a common application of blitting? Sticking two textures together
as layers.

Thanks!

AOn Fri, Apr 26, 2013 at 3:59 PM, Jonathan Dearborn wrote:

TTF_RenderUTF8_Solid does not use alpha transparency (and therefore does
not use alpha blending). That’s why it works in this case. _Blended will
give you nicer-looking results. I think your problem is that SDL2 probably
still preserves the destination alpha (as SDL 1.2 does). You get the color
result you want, but the destination alpha stays the same as it was before
the blit. I’m not sure how to resolve your particular issue perfectly, but
you could try seeing if SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_ADD)
works as you expect. Be sure to reset it afterward.

Jonny D

On Fri, Apr 26, 2013 at 9:51 AM, Alex Barry <alex.barry at gmail.com> wrote:

IIRC, I believe _Blended should be used when your text itself has an
alpha channel. It may be removing the transparency on the destination
surface because no alpha was set on the text?

On Fri, Apr 26, 2013 at 9:46 AM, ?lvaro Castro-Castilla < @Alvaro_Castro-Castil> wrote:

Hi,

I want to render text on a texture with transparency. I’m using this
method:

1 I’m loading a PNG with IMG_Load from SDL_image. It has transparent
regions.
2) I’m creating a SDL_Surface with TTF_RenderUTF8_Blended
3) blitting the render over the surface loaded in (1)

The point is that if I use TTF_RenderUTF8_Solid in (2), the blitting
produces the expected result: the text is on top of the image, including
previously transparent pixels.

But I use the Blended version, it blends nicely but only in those pixels
of the destination surface that don’t have transparency.

Why is this happening? or, why isn’t this behavior consistent between
both functions?

Thank you,

A


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


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