Sign in to follow this  
ryt

I need help with D3DXCOLOR

Recommended Posts

Whats the difference between D3DCOLOR and D3DXCOLOR besides D3DCOLOR uses values from 0 to 255 and D3DXCOLOR from 0.0f to 1.0f? Also I know that D3DCOLOR can be rapresented like 0xff000000, can like this D3DXCOLOR be rapresented? For now i have been using D3DCOLOR. But now I wanted to switch to D3DXCOLOR. I tried to make: D3DXCOLOR color; color = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); and I assumed it will be white color but insted I got dark red. How is that possible?

Share this post


Link to post
Share on other sites
Quote:
Original post by ryt
Whats the difference between D3DCOLOR and D3DXCOLOR besides D3DCOLOR uses values from 0 to 255 and D3DXCOLOR from 0.0f to 1.0f?
D3DXCOLOR is from the D3DX library and provides misc. helper member functions to use with it (in C++).

Quote:
Original post by ryt
Also I know that D3DCOLOR can be rapresented like 0xff000000, can like this D3DXCOLOR be rapresented?
It can be used wherever a DWORD (Or D3DCOLOR) is expected; it'll be implicity cast. E.g.:

void someFunc(D3DCOLOR nColor) {}

D3DXCOLOR clr(1.0f, 1.0f, 1.0f, 1.0f);
someFunc(clr);



Quote:
Original post by ryt
For now i have been using D3DCOLOR. But now I wanted to switch to D3DXCOLOR. I tried to make:
D3DXCOLOR color;
color = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
and I assumed it will be white color but insted I got dark red. How is that possible?
It should come out white, yes. Sounds like a problem with your code rather than D3DXCOLOR. Can we see some relevant code?

Share this post


Link to post
Share on other sites
First of all calling D3DXCOLOR color creates color with default empty constructor,
then color = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); makes a new color with constructor D3DXCOLOR(r,g,b,a) and assign it to color variable.
Simpler way is D3DXCOLOR color(1.0f,1.0f,1.0f,1.0f);

Well why is dark red? Maybe because of setup of your scene and lighting? Maybe you're changing the variable later in your procedure?

If we don't have some piece of code is hard to tell why isn't showing your colors right. Anyway your code should work and it is correct.

Try also constructor D3DXCOLOR(0xFFFFFFFF);

ako imas nekih pitanja mozes mi poslati preko poruke [smile] pozdrav

Share this post


Link to post
Share on other sites
I dont know if this will help but anyway:


//this is my struct
struct vector3
{
vector3(){}
vector3(float x, float y, float z)
{
_x = x; _y = y; _z = z;
}
vector3(float x, float y, float z, D3DXCOLOR color)
{
_x = x; _y = y; _z = z; _color = color;
}
float _x, _y, _z;
D3DXCOLOR _color;
static const DWORD FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
};
//here I set the color
...pPoints[i*numberOfVerticesPerRow+j] = vector3(x, 0.0f, z, D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f));
//this is where I draw
pDevice->BeginScene();
pDevice->SetStreamSource(0, pPointPlaneVertexBuffer, 0, sizeof(vector3));
pDevice->SetFVF(vector3::FVF);
pDevice->SetIndices(pPointPlaneIndexBuffer);
pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, numberOfVertices, 0, numberOfTriangles);
pDevice->EndScene();




Compailer says 0 errors.
I runed again and again I see dark red.
Lighting is disabled.
Also I tried D3DXCOLOR(0xffffffff), and again its dark red. The only time when I set the color is this that I put in source.

Share this post


Link to post
Share on other sites
Quote:
Original post by ryt
I dont know if this will help but anyway:

*** Source Snippet Removed ***
Compailer says 0 errors.
I runed again and again I see dark red.
Lighting is disabled.
Also I tried D3DXCOLOR(0xffffffff), and again its dark red. The only time when I set the color is this that I put in source.
A D3DXCOLOR is 4 floats internally, not 1 D3DCOLOR, so your vertex struct isn't valid. D3D expects a particular memory layout, which you're not giving it. The Debug runtimes usually scream about this sort of error.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
A D3DXCOLOR is 4 floats internally, not 1 D3DCOLOR, so your vertex struct isn't valid. D3D expects a particular memory layout, which you're not giving it.


I didnt know that, thx. Actualy its defined as float r, g, b, a, I didnt noticed that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this