Jump to content
  • Advertisement
Sign in to follow this  

DirectX Alphablending + Background Removal

This topic is 2613 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 there. Im trying to do a couple things really. One thing Im trying to do is make a ghost sprite in 2D that has the ability to go from completely transparent (invisible) to opaque while still having the background of the ghost sprite stay removed, and the values in between will have the ghost however see through i want. Right now the closest I gotten was a ghost sprite see through when the alpha value is 255 with the background of the ghost removed but as the values get smaller, its more opaque but the background of the ghost fades back with it. Heres what i got so far using VB6 and DirectX8:


and im using these renderstates and texturestagestates

Direct3D_Device.SetRenderState D3DRS_SRCBLEND, D3DBLEND_ONE
Direct3D_Device.SetTextureStageState 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1
Direct3D_Device.SetTextureStageState 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE

The alpha values are then controlled by the Alpha values 0-255 with 255 being transparent but not fully. Im hoping to make it from invisible to fully opaque if its possible.

Private Sub Create_Polygon()

Vertex_List(0) = Create_TLVertex(0, 0, 0, 1, D3DColorRGBA(255, 255, 255, Alpha), 0, 0, 0)
Vertex_List(1) = Create_TLVertex(100, 0, 0, 1, D3DColorRGBA(255, 255, 255, Alpha), 0, 1, 0)
Vertex_List(2) = Create_TLVertex(0, 100, 0, 1, D3DColorRGBA(255, 255, 255, Alpha), 0, 0, 1)
Vertex_List(3) = Create_TLVertex(100, 100, 0, 1, D3DColorRGBA(255, 255, 255, Alpha), 0, 1, 1)

End Sub

And heres where it renders

Direct3D_Device.Clear 0, ByVal 0, D3DCLEAR_TARGET, D3DColorRGBA(0, 255, 0, 0), 1#, 0
Direct3D_Device.SetRenderState D3DRS_ALPHABLENDENABLE, True
Direct3D_Device.SetTexture 0, Texture
Direct3D_Device.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex_List(0), Len(Vertex_List(0))
Direct3D_Device.Present ByVal 0, ByVal 0, 0, ByVal 0

Also another problem I'm having is for my epic title intro to my game. Its beautiful so far with the fading out effects but for one of my parts of the intro I wanted to have the the story image fade to white, and from fully white to fade back down to the main title logo. I know im suppose to use another white polygon that fills the screen but this happens to be related to my alphablending problems apparently lol. If anyone has any ideas how I can pull this off I'd appreciate it. Thanks in advance. You dont have to know VB, C++ code i can handle too :P

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!