Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

[Problem solved !
I canno't answer with the response because i have less than 10 reputations. I have to wait 8 hours.]

Currently, i'm trying to display 3 viewports.

1st : This viewport is the entire screen (with camera1 transformation, like zoom)

        viewportDefault = GraphicsDevice.Viewport;

2nd : This viewport is over the 1st viewport, but only width:400 height:200 at left bottom of the screen (with camera2 transformation)

        viewport2 = new Viewport(0, 520, 400, 200);

3rd : This viewport is over the others, the entire screen, fond Color.Transparant. Just to display some text all over the screen, for me. (without camera transformation)

        viewportDevStrings = viewportDefault;

Here is my code :

    protected override void LoadContent()
    {
        //viewports
        viewportDefault = GraphicsDevice.Viewport;
        viewport2 = new Viewport(0, 520, 400, 200);
        viewportDevStrings = viewportDefault;
    }

    protected override void Draw(GameTime gameTime)
    {

                GraphicsDevice.Viewport = viewportDefault;
                DrawScene(camera1.transformation);

                if(ThisIsABool)
                {
                    GraphicsDevice.Viewport = viewport2;
                    DrawScene(camera2.transformation);
                }

                GraphicsDevice.Viewport = viewportDevStrings;
                DrawStrings();
    }

The problem is, when ThisIsABool == true, viewport2 is the entire screen... When i look the "Watch added", here they are :

viewportDefault {X:0 Y:0 Width:1280 Height:720 MinDepth:0 MaxDepth:1}
viewport1 {X:0 Y:520 Width:400 Height:200 MinDepth:0 MaxDepth:1} viewportDevStrings {X:0 Y:0 Width:1280 Height:720 MinDepth:0 MaxDepth:1}

Do you have some suggestions ? :( Hope you can help...

--------------------------EDIT---------------------------

    public void DrawScene(Matrix transform)
    {
       DrawScene1(transform);
       DrawScene2(transform);
       DrawScene3();
    }


    public void DrawScene1(Matrix transform)
    {
       spriteBatch.Begin(
       SpriteSortMode.Deferred,
       BlendState.AlphaBlend,
       SamplerState.LinearClamp,
       null,
       null,
       null,
       transform
       );

       GraphicsDevice.Clear(Color.Black);
       map_background1.Draw(spriteBatch);
       map_background2.Draw(spriteBatch);
       map_background3.Draw(spriteBatch);

       spriteBatch.End();
    }


    public void DrawScene2(Matrix transform)
    {
       spriteBatch.Begin(
       SpriteSortMode.Deferred,
       BlendState.AlphaBlend,
       SamplerState.LinearClamp,
       null,
       null,
       null,
       transform
       );

       character.Draw(spriteBatch);
       door.Draw(spriteBatch);
       monster.Draw(spriteBatch);

       spriteBatch.End();
    }


    public void DrawScene3()
    {
        BlendState blendState = new BlendState();
        blendState.ColorSourceBlend = Blend.DestinationColor;
        blendState.ColorDestinationBlend = Blend.SourceColor;

        spriteBatch.Begin(
        SpriteSortMode.Immediate,
        blendState,
        SamplerState.LinearClamp,
        null,
        null,
        null
        );

        spriteBatch.Draw(RenderTargetForShadows, Vector2.Zero, Color.White);

        spriteBatch.End();
    }
share|improve this question
    
Can you display your DrawScene code. I am thinking that you may have something wrong in your spritebatch.begin method –  Jastill Jan 31 '13 at 23:53
    
@Jastill I edited my messagge and added the code. –  Sharpnel Feb 1 '13 at 0:09
    
i'm at work currently so I cannot create an XNA project to test any of this. (im no pro, just trying to help). this link -> msdn.microsoft.com/en-us/library/… makes me feel like you need to resize your transform. –  Jastill Feb 1 '13 at 0:44
add comment

closed as too localized by Tetrad Feb 1 '13 at 19:39

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 0 down vote accepted

Well...
There was a conflict with the shadow RenderTarget2D. (Nobody could fixed this problem without the shadow RenderTarget2D code i have...)

But, in doubt :
on the 1st viewport, the renderTarget2D was at the screen size, but on the 2nd viewport, i had to create an other renderTarget2D with the 2nd viewport size.

After this, i had to "generate" the 2 renderTarget2D before any draw() in viewports.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.