Let's say I have a background and a set of entities.
I have managed to draw the background into a Texture2D using a RenderTarget
I have also managed to draw all my entities into another RenderTarget
Now I want to take these two Textures and render them on the screen as so:
// Top-level rendering entitiesSystem.Process(); background.Process(); Texture2D entitiesTexture = entitiesSystem.EntitiesTexture; Texture2D backgroundTexture = background.BackgroundTexture; graphicsDevice.SetRenderTarget(null); graphicsDevice.Clear(Color.Black); spriteBatch.Begin(); spriteBatch.Draw( backgroundTexture, LevelManager.LEVEL_RECTANGLE, null, Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 1 ); spriteBatch.Draw( entitiesTexture, LevelManager.LEVEL_RECTANGLE, null, Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 0 ); spriteBatch.End();
Here is how the background system renders the background:
graphicsDevice.SetRenderTarget(BackgroundTexture); spriteBatch.Begin(); for (int i = 0; i < 2; i++) spriteBatch.Draw(textures[i], positions[i], Color.White); spriteBatch.End();
Almost the same thing happens for the entities: I set the render target to the relevant one (not the same as the one for the background), start the spritebatch (again, not the same one), draw the entities and end the spritebatch.
If I set BlendMode to additive, the result is correct (they blend together). However, if I set to to AlphaBlend, then I can only render one of them (depending on the SpriteSortMode).
I have come as far as understanding that the problem lies in not preserving... something, but I am not sure how to preserve it :P
By the way, I read that multiple render targets are not supported for the XBOX... Soooooooo... what is the alternative of doing what I am doing now?