Jump to content
  • Advertisement
Sign in to follow this  
rdeboer

C# Can't create an alpha texture to render to

This topic is 5416 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

It has an error whenever I try to create a texture with Format.A8B8G8R8: Texture m_texture = new Texture(device, 512, 512, 1, Usage.RenderTarget, Format.A8B8G8R8, Pool.Default); Using Format.X8B8G8R8 works fine, but I don't get an alpha channel. I am doing this to see if my texture has an alpha channel: Surface surface = m_texture.GetSurfaceLevel(0); SurfaceLoader.Save("wheresthealpha.dds", ImageFileFormat.Dds, surface); And loading it in DirectX texture tool.

Share this post


Link to post
Share on other sites
Advertisement
Are you absolutely sure that the card supports A8B8G8R8? There's a subtle difference between that and A8R8G8B8 [smile]

Share this post


Link to post
Share on other sites
Dont forget to change your renderstate and add the following

RenderState.AlphaBlendEnable : bool(true)
RenderState.SourceBlend : d3d.blen
RenderState.DestinationBlend : d3d.blend

my guess

Share this post


Link to post
Share on other sites
Yep the A8R8G8B8 solved the create texture problem. Now I'm just having difficulty storing what I need in the alpha channel. I need text in an alpha texture. I am rendering text like this:

font.DrawText(null, "Hello this is text",new Rectangle(0,0,512,512),DrawTextFormat.NoClip,m_colour);

And initially the texture is cleared with:
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, m_clearColour, 1.0f, 0);

I suspect that font drawtext does not store alpha values or my alpha channel starts off completely opaque. I can render the text twice, once in white into an alpha channel, and again in the right colour to the rgb channels but I'm not sure how to copy a texture to the alpha channel. If text could be drawn once then that would be even better.

Share this post


Link to post
Share on other sites
I was told that it would be possible to do using TextureStates but I'm not sure on what arguments are required

device.SetTexture(0,alphaTexture);
device.SetTexture(1,texture);

device.TextureState[0].ColorOperation = ?
device.TextureState[0].ColorArgument1 = ?
device.TextureState[0].ColorArgument2 = ?
device.TextureState[0].AlphaOperation = ?
device.TextureState[1].ColorOperation = ?
device.TextureState[1].ColorArgument1 = ?
device.TextureState[1].ColorArgument2 = ?
device.TextureState[1].AlphaOperation = ?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!