C# Can't create an alpha texture to render to
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.
Are you absolutely sure that the card supports A8B8G8R8? There's a subtle difference between that and A8R8G8B8 [smile]
Dont forget to change your renderstate and add the following
RenderState.AlphaBlendEnable : bool(true)
RenderState.SourceBlend : d3d.blen
RenderState.DestinationBlend : d3d.blend
my guess
RenderState.AlphaBlendEnable : bool(true)
RenderState.SourceBlend : d3d.blen
RenderState.DestinationBlend : d3d.blend
my guess
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.
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.
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 = ?
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 = ?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement