Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

bogdanontanu

How they do alpha in DirectDraw? Help!

This topic is 6923 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

u all know Starcraft ...? anyway it has a lot o transparency/alfa blending but works on any 2d card and only req DDraw not D3D.... i try to make a game like that.. but cant do transparent units .. i try with Lock+add+Unlock ..it works but it is extra slow even on my Vodoo3 card I dont think it can be done like this But how the hell else? Please Help.....

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I think Starcraft runs in a paletted 8-bit mode (256 colors). This is why
the program runs fast, even with all the translucent menus that they put
on the screen. I think they use 50% blending of RGB(0,0,128) to get the
blue translucent menus and use 50% blending of RGB(128,128,128) for the
grey ones.

50% blending is simply taking two colors and dividing them by 2:
(A+B)/2

Which is fast.

Share this post


Link to post
Share on other sites
thank u anonymous helper...

I know they use 8 bit with pallete
and i understand that this helps a lot at
pallete animations and low memory req....

but can u also eplain how they do all that cloaked units
can be 64 of them in one screen...which are not 50% i think
and all units have shadows on each other (b/w thought)

... and after all how do u do (color_a+color_b)/2
in palete mode
u must search a color in ur index to match the resulting color?

Thanks in advance


Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The well known way to do "alpha" in 8 bit mode is to use "alpha tables":
Let''s say you want to implement semitransparent menus. I.e. everything under the menus looks 50% darker. You''ll need to create a table like this:

byte alphaTable[256];

for( i = 0; i < 256; i++ )
{
// r1-g1-b1: palette color

r1 = palette[0] / 2;
g1 = palette[i][1] / 2;
b1 = palette[i][2] / 2;

// r2-g2-b2: 50% darker than r1-g1-b1
// ...it may not exist, so we have to
// find a closest match. It''s index is
// placed in alphaTable[i].

r2 = r1 / 2;
g2 = g1 / 2;
b2 = b1 / 2;

dmin = 256;
for( j = 0; j < 256; j++ )
{
r3 = palette[j][0];
g3 = palette[j][1];
b3 = palette[j][2];
dr = r3 - r2; if( dr < 0 ) dr = -dr;
dg = g3 - g2; if( dg < 0 ) dg = -dg;
db = b3 - b2; if( db < 0 ) db = -db;
d = ( dr + dg + db ) / 3;
if( d < dmin )
{
d = dmin;
alphaTable[i] = j;
}
}
}

So now you can use alphaTable to perform super-fast alpha.
For example, here is a routine to draw a semi-transparent rect:

void DrawAlphaRect( int x1, int y1, int x2, int y2 )
{
int x, y;
byte pixel;

for( y = x1; y <= x2; y++ )
{
for( x = x1; x <= x2; x++ )
{
pixel = GetPixel( x, y );
SetPixel( alphaTable[pixel] );
}
}
}

Think about this:

* Palette should have 2 versions of every color: dark and light.
* You can have more than one "alphaTables" for different levels of alpha.
* r1 = palette[i][0] / 2;
g1 = palette[i][1] / 2;
b1 = palette[i][2] / 2;
...can be changed to something like...
r1 = palette[i][0] / 2;
g1 = 0;
b1 = 0;
...that will create "darken red" alpha effect.

---------

Cheers!
Meduzza

Share this post


Link to post
Share on other sites
ALL I can say....Meduzza...
is that YOU ARE GOOD....

Thanks a lot....

i was doing it in 16bit (565) but still i was wondering
how the hell did they do it in 8bits...
Now i Know ...thanks to You...

Share this post


Link to post
Share on other sites
One more little thing...
I do this game in pure 32bit Assembler

and even if i can read C++ i wonder why are u all
guys only use C...?
C its at least clumpsy not to say more..

anyway You write it more like pseudocode so even i can understand it....

dont flame on me ..please...

Share this post


Link to post
Share on other sites
People often stick with C because
(a) They are reluctant to give up a tool (in this case, a language) that has worked well for them in the past, and
(b) They learned from other people who are reluctant to give up that language

Personally, I prefer C++, and believe it''s a slightly better language. But if I''d learnt C first, I might well consider that the gains from moving over would be outweighed by learning to think within a totally different paradigm. I think people who learn C++ without learning C first have an advantage in that they don''t have to ''unlearn'' and ''relearn'' anything.

Share this post


Link to post
Share on other sites
Another one of the reasons is because some parts of C++ are inherently slower (exception handling and such). C is more basic, but less robust. Assembly is even MORE basic, but even less robust.

NOTE: I''m not trying to start a C/C++ war, please don''t a debate.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!