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

Started by
3 comments, last by Lord_Taren 19 years, 5 months ago
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.
-------------------Emil Diegoediego@miami.edu
Advertisement
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.
------------------------See my games programming site at: www.toymaker.info
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.
Stay Casual,KenDrunken Hyena
Wouldnt the device have to support that texture format then?

(RGBA)
Thanx for the help Drunken Hyena. I completely overlooked the fact that I was using the wrong picel format. That's what happens when you vopy & paste from other sections of code.

-------------------Emil Diegoediego@miami.edu

This topic is closed to new replies.

Advertisement