Directx9 splitscreen view

Started by
12 comments, last by Victhor 9 years, 8 months ago

I recently got my first ever freelance job (or programming job in general for that matter) and I need to rewrite an old plugin for winamp to have two splitscreens, each screen rendering with slightly altered input to create a fake stereoscopic effect. now I've been searching around for a few hours, and I have found some tutorials about directx9 but none of them cover how to create a split screen in C++ (which I learned a few days ago). I think I'm kinda locked into using this old version of directx and I have not been able to find the original documentation on the framework. I'm looking for advice or sources of good information about this subject. At the point I'm at I usually post on a relevant forum and take a break. My first employer has been razzing me about getting as much work done as possible, and I am currently feeling exhausted. I guess that's not super relevant to readers of this, but any helpful advice, or links to useful material would be greatly appreciated. Thanks! If you need any more information please let me know!

Advertisement
Official documentation for the Direct 3D 9 pipeline is here.

Also browse the Getting Started links of this subforum for additional information.

Splitscreen is done using the same render target (usually your current backbuffer) and rendering your scene twice to different viewports.

Viewport documentation. IDirect3DDevice9::SetViewport (Associated API function)
This (further down: "View Ports") looks like a tutorial for both C++ and C#. Checked, worked.

PS: Welcome to the forum wink.png

thank you! you are like an angle bird from on high! (no idea how to say that)

Is directx9 and direct3D9 the same thing? if not, what is the difference?

Directx is a series of technologies (including sound, input, 2D, 3D), whereas Direct3D is the 3D component (obviously!).

awesome! thanks!

thank you! you are like an angle bird from on high! (no idea how to say that)


Nah, don't use angles, prefer vectors tongue.png

so I edited the viewport for the system, and then all the 3d objects went away, but the 2D objects written from drawprimitiveup were still there. After that I messed with it some more and now everything is displaying back to normal, but what's weird is I have the system set up to display 2 viewports? Why is there no change? here's the code. any theories?


void DXContext::SetViewport()
{
	D3DVIEWPORT9 v;
	v.X = 0;
	v.Y = 0;
	v.Width = m_client_width;
	v.Height = m_client_height/2;
	v.MinZ = 0.0f;
	v.MaxZ = 1.0f;
	m_lpDevice->SetViewport(&v);

    D3DVIEWPORT9 v2;
	v2.X = 0;
	v2.Y = m_client_height/2;
	v2.Width = m_client_width;
	v2.Height = m_client_height/2;
	v2.MinZ = 0.0f;
	v2.MaxZ = 1.0f;
	m_lpDevice->SetViewport(&v2);

}

Going to get back at it tomorrow. let me know if you know anything I can use here. so sleepy


Splitscreen is done using the same render target (usually your current backbuffer) and rendering your scene twice to different [emphasis mine - Buckeye] viewports.

Your code just resets the viewport with the second SetViewport call, and all rendering is done with vp2.

Instead,

1. set viewport1 and view matrix for "top" view

2. render scene (to "top" half of buffer)

3. Present top half of buffer to top half of client area

3. set viewport2 and view matrix for "bottom" view

4. render scene "slightly altered" (to "bottom" half of buffer)

5. Present bottom half of buffer to bottom half of client area

The Present call has to match the current viewport:


RECT cRect;
cRect.left = 0;
cRect.right = width;
// EDIT - previously did not set cRect.bottom correctly
if( renderingTopHalf)
{
   cRect.top = 0;
   cRect.bottom = height/2;
}
else
{
   cRect.top = height/2;
   cRect.bottom = height;
}
device->Present(&cRect, &cRect, 0, 0);

FYI: The dev->Clear(...) will clear only the portion of the target/depth buffer in the current viewport. So, if desired for debugging or other purposes, you can set the clear color differently for each pass.

Like so: same and different

In the linked pix, I rendered the scenes side-by-side, rather than top/bottom. I moved the eyepoint in the left side to the right a little, and the eyepoint in the right side to the left a little to create a "cross-your-eyes" stereo effect.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

okay so... some new issues. I've got the screen displaying the same image twice, which is good. For some reason I can't get the viewports to work correctly. I've looked at the example linked by unbird for view ports and I just cannot figure out how they get it so that when it presents it show the split screen image. It only seems to show the single image for me. now I can't show my code because it is place around a bunch of long and expansive code but basically it's like this:

some other part of the frame work calls beginscene then it calls my function

for(2 times)

{

function does all the drawing stuff

endscene()

setViewport(second viewport)

beginscene()

}

setViewport(first viewport)

beginscene()

function ends

the frame work later calls endscene()

lastly, the framework presents the image. I have altered it so that it presents the same image twice one over the other.

any advice? I know this is very sloppy but I've been at my wits end trying to do all of this. I just learned c++ and I'm sick now. Client has stopped bothering me since I've been e-mailing him daily progress. I'm thinking that if I can make a sloppy prototype of something that works, then I can redo a clean version of it, but I need something that works first. Anyways.

The second issue I am having is that when i enter fullscreen mode, the screen goes back to just one screen and with no split screen. I imagine this will fix when I can get the viewports setup. Any advice is appreciated!

This topic is closed to new replies.

Advertisement