Sign in to follow this  
Erik1234

Alpha blending question...

Recommended Posts

Erik1234    122
Hello, I am writing this hack for a pc game that hooks directx funciton calls. Yesterday, I just managed to make a hack where the walls are 50% transparent, so you can see the enemies through the walls. The way I did this was this: if the game created a texture, and the texture was in the format in which it had an alpha channel, I would edit the texture so that alpha channel for each pixel was at 50%. If the texture did not have an alpha channel I would create a new texture with 50% of an alpha channel and draw the new texture instead of the old texture. Now, most the textures in this game do not have an alpha channel, so I will be doubling or tripling the amount of memory textures take in the video memory, slowing down the game. Is there any way to make the walls in the game 50% transparent without manipulating the textures? IE: have transparent walls where the alpha channel in the texture is at 100%, or even have transparent walls where there is no alpha channel at all. I was hoping that somebody here already knew the answer to this and that they could save me time and/or point me in the right direction. - Erik

Share this post


Link to post
Share on other sites
Alex-R    126
You should use alpha-blending for this.

// enable alpha-blending
lpD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
// set the source blend state
lpD3DDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
// set the destination blend state
lpD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

For more information see DirectX SDK. Good luck :)

Share this post


Link to post
Share on other sites
Alex-R    126
This is because your texture have no transparency, i think. Try to set D3DBLEND_BLENDFACTOR renderstate to some value (don't forget to set D3DPBLEND_BLENDFACTOR state to enabled).
If there will be no effect, read about 'D3DBLEND Enumerated Type' in DirectX SDK.

Share this post


Link to post
Share on other sites
Riekistyx    100
providing answers to hackers LAWL i love it!

keep that blend func in there and try doing SetTextureStageState

heres a sample pulling from a game im working on.


//Set the colors
lAlpha = long(Color.a * 255.0f);
lRed = long(Color.r * 255.0f);
lGreen = long(Color.g * 255.0f);
lBlue = long(Color.b * 255.0f);
RealColor = lAlpha << 24 | lRed << 16 | lGreen << 8 | lBlue;

pDev->SetRenderState(D3DRS_TEXTUREFACTOR, RealColor);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR); //tfactor is texture factor
pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); //mod between real texture alpha and yours

//... some other code

//Do this to reset texture args back to defaults (go back to solid)
pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);



I hope this helps if it does pm me how you hook or a msdn article ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this