Seperate viewports

Started by
9 comments, last by emforce 14 years, 8 months ago
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

Game Development Tutorials - My new site that tries to teach LWJGL 3.0 and OpenGL to anyone willing to learn a little.

Advertisement
RSSetViewports()'s second argument is an array of view ports. Put your two view ports into an array and call it once.
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?

Game Development Tutorials - My new site that tries to teach LWJGL 3.0 and OpenGL to anyone willing to learn a little.

This line:

D3D10_VIEWPORT vp[1];

defines an array of length 1. You wrote two values to the array. This is a buffer overflow.
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

Game Development Tutorials - My new site that tries to teach LWJGL 3.0 and OpenGL to anyone willing to learn a little.

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.
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);

Game Development Tutorials - My new site that tries to teach LWJGL 3.0 and OpenGL to anyone willing to learn a little.

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.
ok sorry i will start to review my knowledge of C++.

p.s i did try &vp[0] but i got a syntax error.

Game Development Tutorials - My new site that tries to teach LWJGL 3.0 and OpenGL to anyone willing to learn a little.

And did you try vp without the &?
Your last posted code also has '1' for the number of viewports, so only the first one will count there.

This topic is closed to new replies.

Advertisement