Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

nitzan

viewport question

This topic is 5286 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am setting up view ports for a split-screen multi-player game. What I am trying to do is, after splitting the screen and drawing in each viewport, I want to again draw on the full screen several things. My problem is that for some reason when I set the viewport back to full screen, I can''t draw anything new. Meaning I can''t seem to see what I draw after setting the view back to full screen. This is how I am setting everything:
				g_d3d_device->EndScene();

				D3DVIEWPORT8 bottomViewPort;

				bottomViewPort.X      = 0;
				bottomViewPort.Y      = window_height/2;
				bottomViewPort.Width  = window_width;
				bottomViewPort.Height = window_height/2;
				bottomViewPort.MinZ   = 0.0f; // ? 
				bottomViewPort.MaxZ   = 1.0f; // ? 

				g_d3d_device->SetViewport( &bottomViewPort );

				g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL , 0xff000000, 1.0f, 0 );
				g_d3d_device->BeginScene();

				D3DXMatrixIdentity(&d3d_view_matrix);
				
				D3DXMatrixLookAtLH(&d3d_view_matrix,&D3DXVECTOR3( 0.0f, 0.0f, 1.0f ),
													&D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),
													&D3DXVECTOR3( 0.0f, 1.0f, 0.0f ));
				
				// set the transformation, need to update when camera moves
				g_d3d_device->SetTransform(D3DTS_VIEW,&d3d_view_matrix);
				
				D3DXMatrixIdentity(&d3d_world_matrix);
				g_d3d_device->SetTransform(D3DTS_WORLD, &d3d_world_matrix);

				D3DXMatrixPerspectiveFovLH(	&matProj,		//Result Matrix
											D3DX_PI/6,		//Field of View, in radians. (PI/4) is typical
											-((float)window_width / (float)window_height)*2,	//Aspect ratio
											0.2f,			//Near view plane
											2001.0f );		// Far view plane
				// set the projection matrix
				g_d3d_device->SetTransform( D3DTS_PROJECTION, &matProj );

// DRAW BOTTOM VIEW

				g_d3d_device->EndScene();

				D3DVIEWPORT8 topViewPort;

				topViewPort.X      = 0;
				topViewPort.Y      = 0;
				topViewPort.Width  = window_width;
				topViewPort.Height = window_height/2;
				topViewPort.MinZ   = 0.0f; // ? 
				topViewPort.MaxZ   = 1.0f; // ? 

				g_d3d_device->SetViewport( &topViewPort );

				g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL , 0xff000000, 1.0f, 0 );
				g_d3d_device->BeginScene();

				D3DXMatrixIdentity(&d3d_view_matrix);
				
				D3DXMatrixLookAtLH(&d3d_view_matrix,&D3DXVECTOR3( 0.0f, 0.0f, 1.0f ),
													&D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),
													&D3DXVECTOR3( 0.0f, 1.0f, 0.0f ));
				
				// set the transformation, need to update when camera moves
				g_d3d_device->SetTransform(D3DTS_VIEW,&d3d_view_matrix);
				
				D3DXMatrixIdentity(&d3d_world_matrix);
				g_d3d_device->SetTransform(D3DTS_WORLD, &d3d_world_matrix);

				D3DXMatrixPerspectiveFovLH(	&matProj,		//Result Matrix
											D3DX_PI/6,		//Field of View, in radians. (PI/4) is typical
											-((float)window_width / (float)window_height)*2,	//Aspect ratio
											0.2f,			//Near view plane
											2001.0f );		// Far view plane
				// set the projection matrix
				g_d3d_device->SetTransform( D3DTS_PROJECTION, &matProj );

// DRAW TOP VIEW

				D3DVIEWPORT8 fullViewPort;

				fullViewPort.X      = 0;
				fullViewPort.Y      = 0;
				fullViewPort.Width  = window_width;
				fullViewPort.Height = window_height;
				fullViewPort.MinZ   = 0.0f; // ? 
				fullViewPort.MaxZ   = 1.0f; // ? 

				g_d3d_device->SetViewport( &fullViewPort );

// set to 2dview
		D3DXMATRIX matOrtho; 
		D3DXMATRIX matIdentity;

		//Setup the orthogonal projection matrix and the default world/view matrix
		D3DXMatrixOrthoLH(&matOrtho, (float)window_width, (float)window_height, 0.0f, 2000.0f);
		D3DXMatrixIdentity(&matIdentity);
		D3DXMatrixIdentity(&d3d_world_matrix);

		g_d3d_device->SetTransform(D3DTS_PROJECTION, &matOrtho);
		g_d3d_device->SetTransform(D3DTS_WORLD, &d3d_world_matrix);
		g_d3d_device->SetTransform(D3DTS_VIEW, &matIdentity);

		//Make sure that the z-buffer and lighting are disabled
		g_d3d_device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
		g_d3d_device->SetRenderState(D3DRS_LIGHTING, FALSE);


// DRAW SOME 2D STUFF OVER EVERYTHING

 
Does anyone have any ideas ? Thanks, Nitzan

Share this post


Link to post
Share on other sites
Advertisement
Hello,

I am going to be honest in that I am only answering based on reading a few lines of your post and not your code, as based on the question I don''t think I need to read the code to answer so here goes.

To render to multiple views you have to do the following

1. Create your Projection Matrix and Camera Matrix PER Viewport(although you can have one that does it for both of them usually its different).

Then do it like this.

1. Get the original viewport from the device and store it away
The above happens only once(don''t do it ever render loop as you don''t need too unless you change the screen size etc, in which case you do).

Then

1. THis first step really depends on if you want to clear the entire screen. So lets just assume you do.
Reset the original Viewport to the device
2. Clear the Backbuffer(again since you reset the viewport it will do it all, if you only want pieces then don''t reset the entire backbuffer, or use rects to determine what gets cleared).

3. Set your new activeviewport on the device.
4. Set your projection matrix and camera matrix and world(unless each object has its own then set that in your multi-object render loop)
5. Render your stuff
6. Set the second activeviewport on the device
7. Set your projection matrix and camera matrix and world(bla bla)
8. render your stuff
9. end scene
10. present

This is how I do it with directX and it works great for me.

One thing you have to remember is. to set the matrices after you set the viewport(although I am sure technically in some cases it doesn''t matter, you should do it to make sure it gets applied to the proper viewport).

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!