Skip to main content
GameDev.net gamedev.net
🔒 Locked

Color Codes Question?

Started by clabinsky Dec 20, 2002 at 2:07 AM 3 replies 350+ views
Original Post
clabinsky
clabinsky
Ok, this is probably very simple but I have tried finding info and downloaded som program that should help, but I still cannot get it right. The problem is that I need to create background colors but I do not get the hex codes, using C++ and direct X. For example, I have a function: void paintCircle(int radii, unsigned int color) { //do the painting } To call this function and get a red circle what should the argument of color be? What should the data type be? Is there an easy way to calculate this? If anyone knows a good article about it, I''d appreciate a URL. Thanks!
Why make it simple when you can make it sooo nice and complicated?
ZoomBoy
ZoomBoy
1st assumption is that your unsigned int colour refers to 32 bit colour and that usually works out to a 4 Byte quantity = in the format RGBA or other types
R = red Range of 0 to 255
G = Green Range of 0 to 255
B = Blue Range of 0 to 255
A = Alpha Range of 0 to 255

Black would = 0, 0, 0, 0
White would = 255, 255, 255, (0 or whatever)

A reasonable Green R0, G215, B0, A0

Now to combine the components, you are going to have to shift them
And IF the format is RGBA
colour = (Red << 24) + (Green << 16) + (Blue << 8) + Alpha

But if you can get a pixel off of a screen, you can just store the value and display it onscreen

ZoomBoy
Developing a iso-tile 2D RPG with skills, weapons, and adventure. See my old Hex-Tile RPG GAME, character editor, diary, 3D Art resources at Check out my web-site

clabinsky
clabinsky
Thanks a lot!

It is partly what I wanted. I have done it that way and from your answer I realize that either I am doing somthing else wrong or I might not have been thorough enough in my question.

With DX, I am using the DDBLTFX structure and I am actually using the function argument to set the .dwFillColor of the struct.

Is that correct, because I never seem to get the colors I want...

Sorry for not being more precise from the start.

Regards

//EDIT: I seem to miss information here: I am working in 16 bit colors with DX

[edited by - clabinsky on December 20, 2002 3:41:16 AM]
Why make it simple when you can make it sooo nice and complicated?
ZoomBoy
ZoomBoy
Hehe I work in 16bit

You have the usual 565 deciphering to do
0-63, 0-128, 0-63 are the ranges

colour = (Red << 11) + (Green << 6??) + (Blue)

I use digit numbers for my colours
Red 63648
Blue 543
Green 24543
Blackish 2407
Total White 65535
Total Black 0

ZoomBoy
Developing a iso-tile 2D RPG with skills, weapons, and adventure. See my old Hex-Tile RPG GAME, character editor, diary, 3D Art resources at Check out my web-site






[edited by - ZoomBoy on December 20, 2002 6:24:51 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.