Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


glColor in DirectX

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post

Link to post
Share on other sites
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 -

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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
mtrl.emissive.r = r;
mtrl.emissive.g = g;
mtrl.emissive.b = b;
mtrl.emissive.a = 1;
m_d3ddevice->SetMaterial( &mtrl );

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!