Home Game Development xna – Rendering a number of RenderTargets to the display screen

xna – Rendering a number of RenderTargets to the display screen

0
xna – Rendering a number of RenderTargets to the display screen

[ad_1]

Let’s say I’ve a background and a set of entities.
I’ve managed to attract the background right into a Texture2D utilizing a RenderTarget
I’ve additionally managed to attract all my entities into one other RenderTarget

Now I wish to take these two Textures and render them on the display 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 identical factor occurs for the entities: I set the render goal to the related one (not the identical because the one for the background), begin the spritebatch (once more, not the identical one), draw the entities and finish the spritebatch.

If I set BlendMode to additive, the result’s right (they mix collectively). However, if I set to to AlphaBlend, then I can solely render one in every of them (relying on the SpriteSortMode).

I’ve come so far as understanding that the issue lies in not preserving… one thing, however I’m not positive how you can protect it 😛

By the best way, I learn that a number of render targets aren’t supported for the XBOX… Soooooooo… what’s the different of doing what I’m doing now?

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here