I looked up some R G B values for certain colours, such as "Indian red" for example, which has the RGB values (238, 64, 4).

If I use those values into a D3DXCOLOR structure like this: D3DXCOLOR(238, 64, 4, 255), the colours display oddly - as white! This displays as yellow: D3DXCOLOR(238, 64, 0, 255). Why is this?

  • \$\begingroup\$ Website is correct. Maybe you misplaced colors order and use RGBA instead of ABGR or BGRA? \$\endgroup\$ – Kromster Dec 31 '11 at 12:30
  • \$\begingroup\$ no I haven't, and the function prototype shows they are supposed to be in the order RGBA \$\endgroup\$ – Dollarslice Dec 31 '11 at 13:12
  • \$\begingroup\$ How did you render them? And onto what surface? And the website is indeed correct, see wolframalpha.com/input/?i=color+%28176%2C+31%2C+32%29 \$\endgroup\$ – DMan Dec 31 '11 at 19:18
  • \$\begingroup\$ Not too much info to work with here... Maybe you draw something semi-transparent over your wrongly colored objects? Any shaders active? \$\endgroup\$ – PrinceCharles Dec 31 '11 at 20:04

The problem is that D3DXCOLOR does not accept 4 integer values from 0 to 255 for RGBA, but rather 4 floats from 0 to 1.

anything above 1 is treated effectively as 1. So to get the right values divide the RGB value you want by 255 to get a value from 0 to 1.


  • \$\begingroup\$ Hah, that'll explain why my suggestion didn't help. Next time I'll recommend (128, 128, 128, 255) for a mid-grey colour, which would have come out white. :) \$\endgroup\$ – Kylotan Jan 4 '12 at 19:34

Try some well-known colours - D3DXCOLOR(255, 0, 0, 255) should be red, D3DXCOLOR(0, 255, 0, 255) should be green, and D3DXCOLOR(0, 0, 255, 255) should be blue. If the components are switched in some way, that should show you how.

D3DXCOLORs don't have any intrinsic method of rendering, so it is presumably the manner in which you are using those values which is broken in some way. Perhaps you could post your rendering code and show how you are getting these colours to appear on the screen.

  • \$\begingroup\$ I just tested it and the primary values do indeed display correctly and as expected. I'll post the code none the less. \$\endgroup\$ – Dollarslice Jan 1 '12 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.