Colouring Units

Started by
7 comments, last by TUna 24 years, 2 months ago
Hey For games like StarCraft where there are up to 8 players, do the artists draw 8 differently colored versions of each unit or do they somehow convert the colors before blitting? I presume a custom blitter would be the only way to do that? Thanks
Advertisement
It all depends on what vga mode you using. If you are using 256 colors create a nice palette with 8 different colors going from black to the color to white. Then use you custom blitter to draw the original picture plus an offset color.

i.e. blit(screen, picture, 0) // original colors
blit(screen, picture, 32) // red
so on...

your blitter will be like any other but before you write the color you simply add the offset value.
I think what the anonymous poster is suggesting is that when you blit the image, you have to do some additional color keying.

Think - most libraries have a method of drawing a sprite with a transparent colour key. DDBLT_SRCKEY for DirectDraw Blts. Well, to do the special colour technique you are talking to (StarCraft, Age of Empires, many others..) you would need a special sprite drawing function that not only does a transparent colour key, but also a ''mask'' colour key. By that I mean that when it is drawing the sprite, every pixel it checks the following:

1. Is the pixel the transparent colour? If so, don''t draw it.

2. Is the pixel the ''mask'' colour? If so, draw it using colour RGB.

3. If it is anything else, just draw it.

The function could be something like

ERROR_Type DDRAW_BltWithColour(Sprite *sprite, int x, int y, int colourKey, int maskKey, int maskColour);

You would call it with your sprite, the colourKey that should be transparent, maskKey, the colour to replace by maskColour. For each ''team'' you would change maskColour to the team colour.

Make sense?
Yeap... thanks...
Looks like I''m gonna have to develop my own custom sprite format then. I don''t suppose that will be too hard Just make a simple .BMP converter or summing.
Why write your own file format? You just have to specify a specific colour as your masking colour. I''m using an 8bit display, and I''ve got it setup so that palette index 0 is my transparency and palette index 1 is my ''clothing'' index.
Hmm I just thought running through an array or something like that would be faster than locking a DX surface while using the custom blitter and then unlocking it again?
I assumed they just used palette switching. The art is in 8-bit, and the team colored areas are colored in several shades of magenta. Pallette colors could be dynamically changed. Also, if you just want one color for team colors, you could make them transparent, and first blit an appropriately colored block behind the image (with a mask of the image), then blit the image. Either might be faster than doing custom blits.

Dare To Think Outside The Box
_____________________________
|____________________________|
http://www.inversestudios.com
Write more poetry.http://www.Me-Zine.org

Palette switching won''t work here because you want
units from different sides to appear correctly when
they are on the same screen.

I''m not sure about StarCraft, but WarCraft II used
4 colors per player, and those colors are lined up
next to each other in the palette. So to draw their
graphics, they test each value to see if it''s the
player color and add an appropriate offset it matches,
like this:

unsigned char pixel = *image_data++;
if( (pixel & 0xFC) == 0xD0 )
pixel += color_offset;
*dest_data++ = pixel;

In the case that you are drawing player 0 (i.e. the
color offset you are adding is 0) you can execute a
special loop that copies directly without checking.

Thanks for the ideas, but I think I''ll go with the custom blitter as I''d prefer to use more than 256 colours

This topic is closed to new replies.

Advertisement