Sign in to follow this  
Lord_Taren

Using Direct3D.Sprite to draw 2D images in 3D game

Recommended Posts

I am having some trouble uning the Sprite class to draw 2D images in my 3D game. I am using Visual Studio .NET 2003 and Managed DirectX 9 to create the game. I have a lot of the 3D portions of the game completed and I need to start drawing interface components and stuff. I decided to use the Sprite class to do it. The main problem I am having is not being able to get the sprite class to draw certain parts of the image transparent. I am using black in the image as the parts i want transparent. Here's my situation soo far. I have a image that is 128 x 128. It's a 24 bit bitmap with black as the transparent color. Here is where I load the texture: xTmpTexture = TextureLoader.FromFile(GrafixEnv.Device, sTextureName, 0, 0, 1, 0, Direct3D.Format.X8R8G8B8, Direct3D.Pool.Managed, Direct3D.Filter.None, Direct3D.Filter.Point, System.Drawing.Color.Black.ToArgb(), ref dxImageInfo ); and here is where I draw the sprite: //* Begin the drawing sequence this.m_dxSprite.Begi(Direct3D.SpriteFlags.AlphaBlend); //* Draw the sprite this.m_dxSprite.Draw( (Direct3D.Texture)this.m_dxTexture, srcRect, m_v3Position, this.m_v3Position, System.Drawing.Color.White.ToArgb()); this.m_dxSprite.End(); When the image gets drawn to the screen All the black from the bitmap is being drawn as well.

Share this post


Link to post
Share on other sites
The best way is to code the alpha into the image in advance. So edit in something like Photoshop and save as a targa .tga file. The sprite will then automaticlly be rendered with alpha. Colour keying is not used much anymore.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lord_Taren
Here is where I load the texture:
xTmpTexture = TextureLoader.FromFile(GrafixEnv.Device, sTextureName, 0, 0, 1, 0, Direct3D.Format.X8R8G8B8, Direct3D.Pool.Managed, Direct3D.Filter.None, Direct3D.Filter.Point, System.Drawing.Color.Black.ToArgb(), ref dxImageInfo
);

Colourkeying works by replacing the given colour with a transparent (alpha == 0) pixel. Direct3D.Format.X8R8G8B8 does not support alpha so it does nothing. Direct3D.Format.A8R8G8B8 would be a better choice.

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