glColor in DirectX

Started by
4 comments, last by BillyBillyBilly 20 years, 1 month ago
OpenGL has a glColor() function that sets whatever is rendered next to have a different color based on the parameters. What is the closest equivalent of that in DirectX? The only thing I can think of is ambient lights, but those are sort of expensive. Anyone have any insights? Thanks a lot.
Advertisement
Use a vertex shader, move a constant colour into the output register. Otherwise D3D has no immediate mode functions and each of your vertices will have to have a colour component in an FVF buffer or in another stream.

------------
- outRider -
You can do this per-mesh using materials.
Using DirectX 8 or later, you can do it in a clever way:

Define a vertex buffer that contains a single color, and has a stride of 0. That way, the same color value will be used for all vertices. You will get a warning from the debug runtime; you''ll have to live with that.

To use fixed function processing with multiple vertex streams, you need to call CreateVertexShader, passing it a stream declaration, but a NULL for the actual vertex shader code declaration; that will tell DirectX to use fixed-function processing.
enum Bool { True, False, FileNotFound };
there is also D3DRS_TEXTUREFACTOR/D3DTA_TFACTOR
This is my Direct3D version of glColor (in DirectX 7):

void RendererEngine_Direct3D::SetColor(float r, float g, float b)
{
// set up an emissive color
D3DMATERIAL7 mtrl;
mtrl.emissive.r = r;
mtrl.emissive.g = g;
mtrl.emissive.b = b;
mtrl.emissive.a = 1;
m_d3ddevice->SetMaterial( &mtrl );
}

This topic is closed to new replies.

Advertisement