Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
Website is correct. Maybe you misplaced colors order and use RGBA instead of ABGR or BGRA? –  Krom Stern Dec 31 '11 at 12:30
    
no I haven't, and the function prototype shows they are supposed to be in the order RGBA –  Asher Einhorn Dec 31 '11 at 13:12
    
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 –  DMan Dec 31 '11 at 19:18
    
Not too much info to work with here... Maybe you draw something semi-transparent over your wrongly colored objects? Any shaders active? –  PrinceCharles Dec 31 '11 at 20:04

2 Answers 2

up vote 6 down vote accepted

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.

PAIN!

share|improve this answer
    
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. :) –  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.

share|improve this answer
    
I just tested it and the primary values do indeed display correctly and as expected. I'll post the code none the less. –  Asher Einhorn Jan 1 '12 at 18:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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