XNA Creators Club Online
Page 1 of 1 (10 items)
Sort Posts: Previous Next

Split screen support.... help....

Last post 4/19/2007 6:16 PM by Corpse Like. 9 replies.
  • 4/19/2007 8:58 AM

    Split screen support.... help....

    Hi All,

    I am trying to implement split screen support for my 3d test app and I am having some weird issues.

    I have managed to split the viewport into 2 seperate areas and I can get the content to be drawn on 1 of the views (not both), whenever I try to get the content drawn on both, the right hand viewport displays correctly but the left is always blank and when I update the model it's not refreshing the right hand view port (it's drawing over the existing scene).

    If I only draw to the left hand view port, the updates work perfectly.

     

    Additional info:

    In order to split the screen I have created 2 new viewport objects and based on the default viewport simply split them as required.

    Then in my draw method I assign the first viewport to the default view port and proceed to draw the scene.

    This is followed by setting the viewport to the second viewport and proceeding to draw the scene.

     

    Are there any tutorials out there that may be of use?

     

    Any pointers will do...

     

    Later,

     

    Corpse.

  • 4/19/2007 9:22 AM In reply to

    Re: Split screen support.... help....

    Is this basically what you're doing?
    Jim Perry - Microsoft XNA MVP
    If people spent a minute searching the forums and reading the FAQs before posting I'd be out of a job.
      Got some XNA Game Studio/XNA Framework development info to share with the community? Put it on the XNA Wiki.
        Please mark posts as Answers or Good Feedback when appropriate.
  • 4/19/2007 10:14 AM In reply to

    Re: Split screen support.... help....

    Yep, thats exactly what im doing except I dont have the halfprojection matrix (is this required?)

     

    Reading through the code it's a pity that the DrawScene method is not implemented so I could see exactly what it was doing.

     

    The article describes have 2 implemented camera classes (which I assume will have a camerapos vector and view and proj matrixes), so what the point of the halfprojection matrix?

     

    In my app I simply have a camerapos vector a view and projection matrix, any chance I need 2 of these to draw on the viewports?

     

    Thanks,

     

    Corpse.

     

     

  • 4/19/2007 11:10 AM In reply to

    Re: Split screen support.... help....

    Corpse Like:

    but the left is always blank and when I update the model it's not refreshing the right hand view port (it's drawing over the existing scene).

    This makes me think you amy have sized both viewports to draw over the same area, I'd double check your code, and if that isn't the problem, could you post code snippets of the relevant areas so we can get a better idea of what may be the problem?

  • 4/19/2007 11:12 AM In reply to

    Re: Split screen support.... help....

    The half projection matrix is because the aspect ratio is half what it normally would be because each view port is half of the normally 4:3 rectangle.  The code sample seems a bit odd to me though, since it creates the regular projections matrix, but never uses it.  If you wanted a horizontally split screen you'd use an 8:3 aspect ratio.  You'll need two different camera positions otherwise each screen will look exactly the same.

     

    -Wil Burton
  • 4/19/2007 11:42 AM In reply to

    Re: Split screen support.... help....

    Hi all,
     
    Here is the relevant bits of code....
     
     
    //Declare matrix
     private Matrix View, Projection, View2, Projection2, HalfProjection
    //Declare camerapos
    private Vector3 cameraPosition = new Vector3(-0.1565399f, 117.545f, -71.0242f);

    //declare additional viewports (as per MS sample)
    Viewport singlePlayer;
    Viewport leftView, rightView;

    //in load graphics content
                    Viewport port = graphics.GraphicsDevice.Viewport;
                    //the view matrix represents the user eye view
                    View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
                    //Projection view is what the user will see
                    Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), (float)port.Width / port.Height, 1.0f, 10000.0f);
                    //Half view projection matrix
                    HalfProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), (float)port.Width / port.Height, 1.0f, 10000f);
                   
                    //Camera 2's properties
                    View2 = View;
                    Projection2 = Projection;
                    //Viewport configuration
                    singlePlayer = graphics.GraphicsDevice.Viewport;
                    leftView = singlePlayer;
                    rightView = singlePlayer;
                    //Split the screen horizontally
                    leftView.Width = leftView.Width / 2;
                    rightView.Width = rightView.Width / 2;
                    rightView.X = leftView.Width + 1;
    //end of loadcontent

    //in the draw method
    protected override void Draw(GameTime gameTime)
            {         
                graphics.GraphicsDevice.Clear(Color.Black);
               
                //Draw left view port
                graphics.GraphicsDevice.Viewport = leftView;
                UpdateCamera(View1, Projection1);
                //Draw the right viewport
                graphics.GraphicsDevice.Viewport = rightView;
                UpdateCamera(View2, Projection2);
         
                base.Draw(gameTime);
            }
    //end of draw

    //in the update camera
    private void UpdateCamera(Matrix View, Matrix Projection)
    {
                        transforms = new Matrix[tempAnim.Model.Bones.Count];
                        foreach (ModelMesh mesh in tempAnim.Model.Meshes)
                        {
                                foreach (BasicEffect effect in mesh.Effects)
                                {
                                    effect.View = View;
                                    effect.Projection = Projection;
                                }
                         }
    }
     
     
     
     

    I have tried to use the HalfProjection matrix (which results in a totally blank screen) when drawing.

    I really hope it's something obvious and nooby.....

    Thanks for all the help....

     

    Corpse.

     

     

     

     

  • 4/19/2007 11:50 AM In reply to

    Re: Split screen support.... help....

    Your leftView & rightView ViewPorts are pointing to the same default view port.  You'll need to actually create 2 new view ports and set the width/height/etc. on them.  You probably are going to want another camera definition as well, like I said earlier, other wise both ports will look the same.

    -Wil Burton
  • 4/19/2007 4:02 PM In reply to

    Re: Split screen support.... help....

    ok here are 2 screenshots of the results I have achieved with the above mentioned code.

    Lefthand view

     

    Righthand view

     

    I did some readinf on the graphicsdevice.viewport property and according to the help by assigning the leftview (and then drawing the geometry) and then assigning the rightview (and then drawing the geometry) it's supposed to update them (as per the MS example).

     

    So I am totally confussed..... once again a desperate plea for help.....

    One point of interest is that whichever view is the last to be updated is the one which is drawn correctly.

     

    Thanks in advance,

     

    Corpse.

  • 4/19/2007 4:49 PM In reply to

    Re: Split screen support.... help....

    I don't see where you're ever actually drawing anything in the code you posted?
    XNA Framework Developer - blog - homepage
  • 4/19/2007 6:16 PM In reply to

    Re: Split screen support.... help....

    I apologies, I am using the ModelAnimator class provided by dastle which handles the mesh drawing automatically.

     

    I just found a message on the animationcomponents forum which should help me (basically I need to tell the component not to draw anything but let me do all the drawing).

     

    On the other hand the viewport documentation in the help file (and the above mentioned Microsoft split screen sample) work beautifully (I updated the FontSample to have multiple views without a hitch).

     

    XNA team thanks for such elegance and simplicity.... if only I would have used it correctly in the first place :D

     

    Thanks for all who answered.

    I am that 1 baby step closer......

     

    Regards,

     

    Corpse.

     

     

Page 1 of 1 (10 items) Previous Next