Transparent PNG above dimmed background

Hi,

In my SDL application I am using PNG images with transparencies (alpha channel)
in order to create, for example, rounded edges for buttons etc.

This works perfectly 99% of the time, however I have one exception…

In some circumstances I display popup dialog menus to display messages or
request input from the user. Before the surface containing the popup menu is
blitted to the screen, the background is dimmed to emphasize focus on the
dialog. This is done using the following code:

void dim_screen (SDL_Rect* rect)
{
SDL_SetAlpha(screen, SDL_SRCALPHA | SDL_RLEACCEL, 160);
SDL_FillRect(screen, rect, SDL_MapRGB(screen->format,1,1,1));

SDL_UpdateRect(screen, rect->x, rect->y, rect->w, rect->h);
SDL_SetAlpha(screen, SDL_SRCALPHA | SDL_RLEACCEL, 255);

}

The problem with this is that the rounded corners of the dialog window are no
longer transparent when blitted over the screen with the semi-transparent
fillrect and are close to black.

Any help is appreciated!

you probably need to think about having a mask area for the corners of your
buttons so creating a new surface doing all your shading business plotting
in some black corners then applying a mask to the new black corners or
similarOn 11 June 2010 14:38, Dan J wrote:

Hi,

In my SDL application I am using PNG images with transparencies (alpha
channel)
in order to create, for example, rounded edges for buttons etc.

This works perfectly 99% of the time, however I have one exception…

In some circumstances I display popup dialog menus to display messages or
request input from the user. Before the surface containing the popup menu
is
blitted to the screen, the background is dimmed to emphasize focus on the
dialog. This is done using the following code:

void dim_screen (SDL_Rect* rect)
{
SDL_SetAlpha(screen, SDL_SRCALPHA | SDL_RLEACCEL, 160);
SDL_FillRect(screen, rect, SDL_MapRGB(screen->format,1,1,1));

SDL_UpdateRect(screen, rect->x, rect->y, rect->w, rect->h);
SDL_SetAlpha(screen, SDL_SRCALPHA | SDL_RLEACCEL, 255);
}

The problem with this is that the rounded corners of the dialog window are
no
longer transparent when blitted over the screen with the semi-transparent
fillrect and are close to black.

Any help is appreciated!


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

checked for viruses and spam by CanIt.
http://www.canit4.3d.net.uk/

Neil White <neil cloudsprinter.com> writes:

you probably need to think about having a mask area for the corners of your
buttons so?creating?a new?surface?doing all your shading business plotting in
some black?corners?then applying a mask to the new black?corners?or similar
Hi,
In my SDL application I am using PNG images with transparencies (alpha channel)
in order to create, for example, rounded edges for buttons etc.
This works perfectly 99% of the time, however I have one exception…
In some circumstances I display popup dialog menus to display messages or
request input from the user. Before the surface containing the popup menu is
blitted to the screen, the background is dimmed to emphasize focus on the
dialog. This is done using the following code:
void dim_screen (SDL_Rect* rect)
{
? ?SDL_SetAlpha(screen, SDL_SRCALPHA | SDL_RLEACCEL, 160);
? ?SDL_FillRect(screen, rect, SDL_MapRGB(screen->format,1,1,1));
? ?SDL_UpdateRect(screen, rect->x, rect->y, rect->w, rect->h);
? ?SDL_SetAlpha(screen, SDL_SRCALPHA | SDL_RLEACCEL, 255);
}
The problem with this is that the rounded corners of the dialog window are no
longer transparent when blitted over the screen with the semi-transparent
fillrect and are close to black.
Any help is appreciated!


SDL mailing listSDL
lists.libsdl.orghttp://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
checked for viruses and spam by CanIt.http://www.canit4.3d.net.uk/


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

I just realized that the corners of the dialog window are not black, they are
1,1,1…the color of the FillRect blitted before the window, however without
the alpha transparency of the surface. So, the transparency of the PNG is still
there.

I’m assuming this is happening because per-pixel alpha overrides per-surface
alpha? Is there a workaround for this?> On 11 June 2010 14:38, Dan J <djantzen stevens.edu> wrote:

I believe not. You will probably have to mix them yourself.

Jonny DOn Mon, Jun 14, 2010 at 4:36 PM, Dan J wrote:

Neil White <neil cloudsprinter.com> writes:

you probably need to think about having a mask area for the corners of
your
buttons so creating a new surface doing all your shading business plotting
in
some black corners then applying a mask to the new black corners or similar
On 11 June 2010 14:38, Dan J <djantzen stevens.edu> wrote:
Hi,
In my SDL application I am using PNG images with transparencies (alpha
channel)
in order to create, for example, rounded edges for buttons etc.
This works perfectly 99% of the time, however I have one exception…
In some circumstances I display popup dialog menus to display messages or
request input from the user. Before the surface containing the popup menu
is
blitted to the screen, the background is dimmed to emphasize focus on the
dialog. This is done using the following code:
void dim_screen (SDL_Rect* rect)
{
SDL_SetAlpha(screen, SDL_SRCALPHA | SDL_RLEACCEL, 160);
SDL_FillRect(screen, rect, SDL_MapRGB(screen->format,1,1,1));
SDL_UpdateRect(screen, rect->x, rect->y, rect->w, rect->h);
SDL_SetAlpha(screen, SDL_SRCALPHA | SDL_RLEACCEL, 255);
}
The problem with this is that the rounded corners of the dialog window
are no
longer transparent when blitted over the screen with the semi-transparent
fillrect and are close to black.
Any help is appreciated!


SDL mailing listSDL
lists.libsdl.orghttp://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
checked for viruses and spam by CanIt.http://www.canit4.3d.net.uk/


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

I just realized that the corners of the dialog window are not black, they
are
1,1,1…the color of the FillRect blitted before the window, however
without
the alpha transparency of the surface. So, the transparency of the PNG is
still
there.

I’m assuming this is happening because per-pixel alpha overrides
per-surface
alpha? Is there a workaround for this?


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

I don’t understand why this is happening though…I am setting an alpha
value,blitting a black rect (semi-transparent) and then turning the alpha
value back to normal. Only after resetting the alpha to fully opaque is
the png (with per-pixel transparent corners) blitted to the screen. Why
would the surface “below” it have any effect on the png?

That’s just how SDL 1.2 works. The destination alpha is the result alpha.
Does SDL 1.3 have OpenGL’s blending modes?

Jonny DOn Tue, Jun 15, 2010 at 5:39 AM, Dan J wrote:

I don’t understand why this is happening though…I am setting an alpha
value,blitting a black rect (semi-transparent) and then turning the alpha
value back to normal. Only after resetting the alpha to fully opaque is
the png (with per-pixel transparent corners) blitted to the screen. Why
would the surface “below” it have any effect on the png?


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

I am the GSOC student working on XRender support in SDL. SDL 1.3 will
soon have OpenGL like blending modes on x11 systems using xrender. SDL
1.3 does have blending modes defined now but they are not implemented
on x11. The clone repository already has code implemented for drawing
lines and rectangles using XRender with true alpha blending. Note that
all the blending modes haven’t been implemented yet, just the
traditional blend operator.-----------------------------------------------------------------------------

Sunny Sachanandani
BITS Pilani, Pilani Campus
2008B4A7580P

+91-9784313832
+91-9967247780

On Tue, Jun 15, 2010 at 6:49 PM, Jonathan Dearborn wrote:

That’s just how SDL 1.2 works. ?The destination alpha is the result alpha.
?Does SDL 1.3 have OpenGL’s blending modes?
Jonny D

On Tue, Jun 15, 2010 at 5:39 AM, Dan J wrote:

I don’t understand why this is happening though…I am setting an alpha
value,blitting a black rect (semi-transparent) and then turning the alpha
value back to normal. Only after resetting the alpha to fully opaque is
the png (with per-pixel transparent corners) blitted to the screen. Why
would the surface “below” it have any effect on the png?


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

Excellent. Thanks Sunny. For now, Dan, I suggest using some sort of alpha
mask surface as the destination unless you want to perform the blending
yourself.

Jonny DOn Tue, Jun 15, 2010 at 8:36 AM, Sunny Sachanandani < sunnysachanandani at gmail.com> wrote:

I am the GSOC student working on XRender support in SDL. SDL 1.3 will
soon have OpenGL like blending modes on x11 systems using xrender. SDL
1.3 does have blending modes defined now but they are not implemented
on x11. The clone repository already has code implemented for drawing
lines and rectangles using XRender with true alpha blending. Note that
all the blending modes haven’t been implemented yet, just the
traditional blend operator.


Sunny Sachanandani
BITS Pilani, Pilani Campus
2008B4A7580P

+91-9784313832
+91-9967247780

On Tue, Jun 15, 2010 at 6:49 PM, Jonathan Dearborn <@Jonathan_Dearborn> wrote:

That’s just how SDL 1.2 works. The destination alpha is the result
alpha.
Does SDL 1.3 have OpenGL’s blending modes?
Jonny D

On Tue, Jun 15, 2010 at 5:39 AM, Dan J wrote:

I don’t understand why this is happening though…I am setting an alpha
value,blitting a black rect (semi-transparent) and then turning the
alpha

value back to normal. Only after resetting the alpha to fully opaque is
the png (with per-pixel transparent corners) blitted to the screen. Why
would the surface “below” it have any effect on the png?


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