Jump to content
  • Advertisement

Archived

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

Spk

Changing a scene object's color on the fly

This topic is 5320 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

Hi ! I''m currently writting a 3D chess game, and this is my first time using D3D. In my application, the user is able to select a chess piece through the 3D view. Ive got the picking code working fine, and now I would like to give the user a hint about what he has selected. I want to do this by drawing the selected model with a green color layer over it. In OpenGL I would do this in a very simple way, by calling glColor3f(green) just before drawing the selected object''s triangles. That would cause my object to appear with a green color all over it. However, in D3D, it doesn''t seem to be as easy. My scene supports lighting and material color : the black chess pieces have a black color material, and the white ones have a white color material. But I think I went the wrong way, and should have used per-vertex color instead of using materials for the pieces colors. Now my question is : how do I dynamically change the color an object in my scene ? I''ve done some researchs, and found a couple of possible ways to explore : use per-vertex color by changing the .color component of each single vertex of my object''s vertexbuffer, or use a shader. The first method looked like to be the easiest to implement. However, I''m limited by my engine''s design : I''m using only one vertexbuffer per model (pawn, bishop, etc) to save ressources, and changing the the vertex colors of one model would make all the other pieces using the same model also appear green, which is not what I want. Using a vertex shader sounded too complicated for something which seemed to be so trivial to do in OpenGL. So does anybody have any ideas/hints/solutions to my problem? I hope i''ve been clear enough Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
1) Change the material color when drawing the selected object.
or
2) Set TFactor, change TextureStageState cascade.
or
3) Add a "selected" texture.
or
4) Play tricks with fog on one object

I could go on... there''s SO many ways, just pick one. Changing the material color is the easiest, since you''re not using vertex color, and you already know how to use them.

Share this post


Link to post
Share on other sites
i have been thinking about a little bit of a hack for per-stage coloring, what if you set D3DTSS_TEXCOORDINDEX to D3DTCI_CAMERASPACEPOSITION (or any would work, this is only to insure there are texture coordintes for vertices without them), D3DTSS_TEXTURETRANSFORMFLAGS to D3DTTFF_COUNT2, D3DTSS_ADDRESSU and D3DTSS_ADDRESSV to D3DTADDRESS_CLAMPBORDER, and the D3DTSS_BORDERCOLOR to the color you want. finally, set the texture stage transform to something with enough of a translation to always cause the coordinates to fall outside 0, 1, and the border color will be selected.

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!