🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: rec.games.programmer
3 messages
3 total messages Started by efonseca Fri, 17 Jul 1998 00:00
Alpha Blending Techniques - PLEASE HELP!
#2341
Author: efonseca
Date: Fri, 17 Jul 1998 00:00
24 lines
1637 bytes
Hello guys.

I'm a newbie programmer... and I need to find some algorithms to
perform Alpha Blending... I'm making a card game, and I need to
have the effect of a shadow below the cards (drop shadow a la Photoshop).

A friend of mine told me about Alpha Blending. Do you guys have
some algorithms, tutorials, or something like to help me?

I'm developing the card game on VC++ and Delphi.

Please, I really need help on this one. I know Delphi and C a lot,
but I did not find anything about this subject...

Thanks a lot

________________________________
Eduardo B. Fonseca
NetGames Online CEO
eduardo@fnn.net
________________________________

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
Re: Alpha Blending Techniques - PLEASE HELP!
#2342
Author: gmcbay
Date: Fri, 17 Jul 1998 00:00
72 lines
3325 bytes
Alpha Blending (in the sense of your card game) is just mixing two color
values in a weighted manner.

I don't know how your card game is implemented, but to accomplish these
shadows, what you want to is read the values of pixels in your target region,
get the R/G/B values, and then darken them up by lowering each component by a
set amount.

Pseudo-code:

DARKEN_VALUE = 30

foreach([x, y] of pixel_in_shadow_region)
{
   pix = GetPixelOfUnderlyingRegion(x, y);

   red = GetRedComponent(pix);
   green = GetGreenComponent(pix);
   blue = GetBlueComponent(pix);

   red = red - DARKEN_VALUE;
   green = green - DARKEN_VALUE;
   blue = blue - DARKEN_VALUE;

   pix = RGB(red, green, blue);

   SetPixelOfUnderlyingRegion(pix, x, y);
}

Of course, how you actually implement it and the functions you use depend on
the game and how it is constructed.  If you're using standard GDI, look
at the GetPixel/SetPixel functions and RGB/Get*Value macros. If you're adverse
to the relative slowness of using Get/SetPixel (shouldn't really effect a card
game much), look into memory DIBs.

If you're using DirectX, you could either get the DC of the surface (and
use the above method) or use Lock() to get access to the surface's pixel
information).

Just be sure to draw the shadow for each card as you draw the card to keep the
zorder correct.

In article <6omgsn$kgk$1@nnrp1.dejanews.com>,
  eduardo@fnn.net wrote:
> Hello guys.
>
> I'm a newbie programmer... and I need to find some algorithms to
> perform Alpha Blending... I'm making a card game, and I need to
> have the effect of a shadow below the cards (drop shadow a la Photoshop).
>
> A friend of mine told me about Alpha Blending. Do you guys have
> some algorithms, tutorials, or something like to help me?
>
> I'm developing the card game on VC++ and Delphi.
>
> Please, I really need help on this one. I know Delphi and C a lot,
> but I did not find anything about this subject...
>
> Thanks a lot
>
> ________________________________
> Eduardo B. Fonseca
> NetGames Online CEO
> eduardo@fnn.net
> ________________________________
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
>

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
Re: Alpha Blending Techniques - PLEASE HELP!
#2340
Author: Lasse Skyum
Date: Mon, 20 Jul 1998 00:00
24 lines
1385 bytes
I think this would be better:

because if ect. the red-component is
under DARKEN_VALUE it will... eh... fuck-up :)
(This also looks better)

DARKEN_VALUE = 0.5 // Or whatever

foreach([x, y] of pixel_in_shadow_region)
{
   pix = GetPixelOfUnderlyingRegion(x, y);

   red = GetRedComponent(pix);
   green = GetGreenComponent(pix);
   blue = GetBlueComponent(pix);

   red = red * DARKEN_VALUE;
   green = green * DARKEN_VALUE;
   blue = blue * DARKEN_VALUE;

   pix = RGB(red, green, blue);

   SetPixelOfUnderlyingRegion(pix, x, y);
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads