Jump to content

View more

Image of the Day

 #indiedev  #indiegame #screenshotsaturday https://t.co/xKIzRQMdHm
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.

Sign up now

Change Alpha Color Without Recreating Polygon

2: Adsense
  • You cannot reply to this topic
2 replies to this topic

#1 Psychopathetica   Members   


Posted 19 March 2017 - 08:42 PM

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.

#2 mhagain   Members   


Posted 20 March 2017 - 06:02 AM

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.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.

#3 Psychopathetica   Members   


Posted 20 March 2017 - 11:58 AM

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, 20 March 2017 - 12:11 PM.