I'm working in XNA and I hit the following problem: My goal was to have a number of different textures be drawn to a texture and then draw the final texture to the screen with a given alpha value.
The problem is that the texture I draw to is full screen and filled with a color rather than transparency, so it blocks out everything behind it.
Everything is 2d, here is my code:
public void Draw(SpriteBatch sb)
{
if (opacity > 0)
{
gd.SetRenderTarget(formTexture);
gd.Clear(Color.Transparent);
for (int i=0; i<formItems.Count; i++)
{
((FormItem)formItems[i]).draw(sb);
}
sb.Begin(SpriteSortMode.Immediate, BlendState.Additive);
for (int i=0; i<formItems.Count; i++)
{
FormItem fi = (formItems[i] as FormItem);
if (fi.glow != null)
{
sb.Draw(fi.glow, new Rectangle((int) fi.location.X + fi.width/2 - fi.glow.Width/2, (int) fi.location.Y + fi.height/2 - fi.glow.Height/2, fi.glow.Width, fi.glow.Height), Color.White);
}
}
sb.End();
gd.SetRenderTarget(null);
sb.Begin();
sb.Draw(formTexture, new Rectangle(0, 0, gd.Viewport.Width, gd.Viewport.Height), Color.White*opacity);
sb.End();
}
}
formTexture is a RenderTarget2D object, gd is the graphics device. This is how formTexture is initialized:
formTexture = new RenderTarget2D(this.gd, this.windowWidth, this.windowHeight);