Sign in to follow this  
emforce

Seperate viewports

Recommended Posts

hi guys i am trying to render 2 viewports because i want to be able to do a sort of split screen game. i tried this

D3D10_VIEWPORT vp;
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	vp.Width    = mClientWidth/2;
	vp.Height   = mClientHeight;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;

	D3D10_VIEWPORT vp2;
	vp.TopLeftX = mClientWidth/2;
	vp.TopLeftY = 0;
	vp.Width    = mClientWidth/2;
	vp.Height   = mClientHeight;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;

	md3dDevice->RSSetViewports(2, &vp);
	md3dDevice->RSSetViewports(2, &vp2);



but to no avail i simply get a viewport in the right hand side of the screen

Share this post


Link to post
Share on other sites
RSSetViewports()'s second argument is an array of view ports. Put your two view ports into an array and call it once.

Share this post


Link to post
Share on other sites
so i tried the following


D3D10_VIEWPORT vp[1];


vp[0].TopLeftX = 0;
vp[0].TopLeftY = 0;
vp[0].Width = mClientWidth/2;
vp[0].Height = mClientHeight;
vp[0].MinDepth = 0.0f;
vp[0].MaxDepth = 1.0f;


vp[1].TopLeftX = mClientWidth/2;
vp[1].TopLeftY = 0;
vp[1].Width = mClientWidth/2;
vp[1].Height = mClientHeight;
vp[1].MinDepth = 0.0f;
vp[1].MaxDepth = 1.0f;

md3dDevice->RSSetViewports(2, &vp[1]);



but i get a runtime error stating

Run-Time Check Failure #2 - Stack around the variable 'vp' was corrupted.

what am i doing wrong can you please help me?

Share this post


Link to post
Share on other sites
This line:

D3D10_VIEWPORT vp[1];

defines an array of length 1. You wrote two values to the array. This is a buffer overflow.

Share this post


Link to post
Share on other sites
ah thought [1] defined an array of length 2 because i thought [0] counted as 1.
Ahh well you live you learn.

Anyways now that i have that working my viewports are now not showing anything. just a blank screen

Share this post


Link to post
Share on other sites
That might have something to do with the fact that you're passing the address of the second element to the function rather than the first.

Share this post


Link to post
Share on other sites
ok so i tried to pass the array to the function but i get the error
cannot convert parameter 2 from 'D3D10_VIEWPORT (*)[2]' to 'const D3D10_VIEWPORT *'

here is my source



D3D10_VIEWPORT vp[2];


vp[0].TopLeftX = 0;
vp[0].TopLeftY = 0;
vp[0].Width = mClientWidth/2;
vp[0].Height = mClientHeight;
vp[0].MinDepth = 0.0f;
vp[0].MaxDepth = 1.0f;


vp[1].TopLeftX = mClientWidth/2;
vp[1].TopLeftY = 0;
vp[1].Width = mClientWidth/2;
vp[1].Height = mClientHeight;
vp[1].MinDepth = 0.0f;
vp[1].MaxDepth = 1.0f;


md3dDevice->RSSetViewports(1, &vp);


Share this post


Link to post
Share on other sites
Give some serious thought to learning C++ before messing with DirectX. You're getting stuck on some really simple things. Find a good C++ book and work through the exercises.

In any case, you can get the address of the first element of an array by either using &vp[0] or just vp.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this