Archived

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

skreuzer

Palettized Art

Recommended Posts

Hello All, I am currently writing my first Windows based game using Direct X 8.0 and Ian Parberry''s "Learn Computer Game Programming w/ DirectX 7.0" In my game I have a bitmap file containing letters and numbers which are loadedin, chopped up and then used to display the current score, the high scores list etc. The images are all black, but during the course of the game I may want to dispaly the text in red or blue or some other wacky color (whatever looks good) I thought this may be a possible solution: To read in say the image "A" and then change the part of the palette which is black to something else on the fly thus "improperly" displaying the image for desired results. (Confused yet?) Is this somehow possible? If so, someone care to share. Please email me if you would like to take a look at the bitmap file. SK skreuzer@mac.com

Share this post


Link to post
Share on other sites
hello skreuzer,

not to say this is the only way to do so, but its quite a good way that i have done it.

i saved my letters and numbers in a file like you said, but had the background be the "transparent color". you simply make color 0 be the transparent color. so when you are drawing one of the letters or numbers (ill call letters and numbers "character" from now on), when you are drawing one of the characters to screen, you wont draw anything in the bitmap that is color 0. this way it wont show up as a rectangle. then, if its not 0 you can pick any color to draw it in.

some pseudo code:
(screen[] is the screen, screenWidth is width of the screen, alpha_height is height of character bitmap, alpha_width is width of character bitmap, alpha[] is the bitmap of the character, color is the color you want to draw your character, SX is x coordinate where you wanna draw character, SY is the y coordinate where you wanna draw character)

draw_character_function(byte *screen, byte *alpha, byte color)
{
int x,y;
for ( y = 0; y < alpha_height; y++ )
{
for ( x = 0; x < alpha_width; x++ )
{
if ( alpha[ y * alpha_height + x] ) /* if this pixel isnt transparent. -aka- the color isnt 0 (zero) */
screen[ (SY + y) * screenWidth + (SX + x) ] = color;
}
}
}


if that doesnt make sense, just ask again, i''ll try to clarify.

that should draw you a nice transparent character of any color in your palette. this way, you dont have to make every single character thats drawn the same color, you can mix ''em up.

hope that helps.

 - jeremiah
 http://fakemind.com

Share this post


Link to post
Share on other sites