# Basic question : Directx Hexadecimal color codes

This topic is 4320 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am trying to understand the hexadecimal color codes. My understanding is that it stands for RGB(2 Bytes each). So the hexadecimal code should be(I know this is not correct) RED - &HFF0000 GREEN - &H00FF00 BLUE - &H0000FF But it works only when the code is as follows RED = &HFF0000 GREEN = &H1FF00 BLUE = &H1FF How does the above code is formed. What does the 1 indicate in green & blue?

##### Share on other sites
I work with DirectX everyday (Not managed) and I have to say I have no idea what codes you are talking about :)

##### Share on other sites
What are RED, GREEN, and BLUE exactly? What language is this?

##### Share on other sites
Sorry its not actual code.

It has to be

Const RED as long = &HFF0000

in vb.

Anyway I am interested in the hexadecimal(ARGB) colour code. Any help?

##### Share on other sites
The color is a hex DWORD (unsigned long, 4 bytes). It takes two hex digits to make a byte, so each color is only 1 byte, not two. You've got the right idea for the masks.

I can only guess that VB has some silly limits on hex numbers, much like early assemblers. The value probably has to start with a decimal numeric digit... ie: 0-9. It would probably work as &H0FF00 and &H0FF, though I can't imagine how it likes the red mask. It made sense back for the assemblers, as the "hex" notation was a postfix ie: 0FF00h, and it needed the 0 to know it was parsing a number. Have a hex prefix then still needing a decimal digit before any hex ones is just baffling, but I can't imagine any other way to interpret what you're seeing.

##### Share on other sites
I'm a little rusty on my VB6 - been a good couple of years since I did any work with it [smile]

Anyway, IIRC, you can put an additional '&' at the end of the hex constant to preserve the full 32bit width - otherwise VB does some crazy stuff with truncating the values. You also have to be a bit careful with the signed bit iirc.

I'm pretty sure one of the older SDK's that supported VB6 had implementations of the D3DCOLOR_XRGB() and D3DCOLOR_ARGB() helper functions, so you might want to look those up.

Also, don't use the standard RGB() function - it generates Win32/GDI compatible 24bit BGR codes iirc. Be warned about matching your colour with the pixel format - I've seen more than enough people get tripped up by setting a 32bit pixel colour for a 16bit texture (or similar) and wondering why it doesn't look right [smile]

hth
Jack

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 11
• 9
• 9
• 40
• ### Forum Statistics

• Total Topics
634130
• Total Posts
3015704
×