Jump to content
  • Advertisement
Sign in to follow this  

Change Alpha Color Without Recreating Polygon

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

I found an awesome method to create a sphere polygon with normals, as well as texture coordinates for tu and tv, but I severely modified it to support changing its color / alpha as well and made it my own thing. That way I don't have to resort to using D3DXCreateSphere() which doesnt support texture coords. Works great, but I wanted to fade from one sphere into another, similar to fading from day sky to night sky. Is there a way to change alpha values of a color without recreating the entire object every frame with the new colors? Note I'm not using HLSL, and just DirectX9 and C++. Thanks.

Share this post

Link to post
Share on other sites

If you wish to change all vertices of your sphere to the same alpha colour, you can do something with SetTextureStageState calls, but it's such a long time since I've done this style of programming that I would need to spend some time working out the correct calls.

However, what it sounds like you really want to do is interpolate between a "day" texture and a "night" texture, so it will be much simpler if you just draw a single sphere with two textures and D3DTOP_LERP - again, use a bunch of SetTextureStageState calls.

Share this post

Link to post
Share on other sites

I'll look into using some SetTextureStageState calls but I think it's messed up that after all these years, I've been setting colors and alphas to polygons upon its creation for years. And all this time if I ever needed to change anything, it involved SetTextureStageState's this whole time. Now alls I gotta do is figure out the right states.



I fixed it after finding a similar post on gamedev:


DWORD AlphaValue;
AlphaValue = D3DCOLOR_ARGB(100,255,255,255);

mpDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
mpDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
mpDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
mpDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
mpDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

mpDevice->SetTextureStageState(0, D3DTSS_CONSTANT, AlphaValue);
mpDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_CONSTANT);
mpDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
mpDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);


works like a charm and you can dynamically change the alphas WITHOUT recreating the polygons

Edited by Psychopathetica

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!