Skip to main content
GameDev.net gamedev.net
🔒 Locked

Rendering to multiple windows

Started by Bimble Bob Apr 12, 2007 at 8:04 AM 7 replies 800+ views
Original Post
Bimble Bob
Bimble Bob
It's these annoying swap chains again. I've been trying to get it to render to multiple windows but it's just not working. I can setup two windows and two swap chains with depth buffers and all. But it will only draw to the second window (Second meaning the second one to be created and therefore the second one that gets drawn to). The first window just shows a bright green colour. What I do is I make a swap chain the render target, draw things, then go and make the next swap chain the render target, draw etc. Once all of them have been done I Present them all. I think this is where I am going wrong. Do I need to draw to one render target, present it THEN do another? Setting the render target:

f(FAILED(m_swapChains.at(targetNum)->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &backBuffer)))
					return;

				m_d3d9Device->SetRenderTarget(0, backBuffer);			
				//backBuffer->Release();

				D3DPRESENT_PARAMETERS pp;
				m_swapChains.at(targetNum)->GetPresentParameters(&pp);

				if(FAILED(m_d3d9Device->SetDepthStencilSurface(m_depthStencilBuffers.at(targetNum))))
					return;

				//Clear(false, true, true);

				viewport.X = 0;
				viewport.Y = 0;
				viewport.Width = pp.BackBufferWidth;
				viewport.Height = pp.BackBufferHeight;
				viewport.MinZ = 0.0f;
				viewport.MaxZ = 1.0f;

				m_d3d9Device->SetViewport(&viewport);			

				m_activeWindow = pp.hDeviceWindow;
				m_activeSwapChain = targetNum;
				m_d3d9PP = pp;

Presenting them all:

	void D3D9RenderDevice::Present()
	{
		for(int i = 0; i < m_numSwapChains; i++)
		{
			D3DPRESENT_PARAMETERS pp;
			m_swapChains.at(i)->GetPresentParameters(&pp);
			m_swapChains.at(i)->Present(NULL, NULL, pp.hDeviceWindow, NULL, 0);
		}
	}

Another odd problem is that when (trying to) render to multiple windows if I resize the window over a certain size nothing is drawn. it just clears it and that's all. I seem to be able to stretch it horizontally as far as I want but if I stretch it too much vertically it just disappears. I've checked all the backbuffer widths and viewport settings and I can't see anything wrong. What usually causes this behavior :S
It's not a bug... it's a feature!
Mike.Popoloski
Mike.Popoloski
I think there may be multiple ways to do this, but the method I have used is different from yours. First, I set the render target for the window I want, using the method you have shown. Then, I call begin scene, start rendering everything, call end scene, call present with null for all parameters. Then, set the render target for the next window, begin the scene, render, etc.
Mike Popoloski | Journal | SlimDX
Bimble Bob
Bimble Bob
That's the other method I thought of but the way I'm trying to do it now is so much more convenient for the way I've set things up. Is it in any way possible for me to do it?
It's not a bug... it's a feature!
Johnhl
Johnhl
The Present() member function of the Device interface takes an optional window handle as a parameter you can use this to ensure its shown to the right window.
Bimble Bob
Bimble Bob
m_swapChains.at(i)->Present(NULL, NULL, pp.hDeviceWindow, NULL, 0);

I already do this.
It's not a bug... it's a feature!
Johnhl
Johnhl
Oh sorry, what are your presentation parameters this is just a guess but this might only work if your using Discard or Copy as your presentation method. This is just a guess though
Bimble Bob
Bimble Bob
I'm using the Discard method.
It's not a bug... it's a feature!
Bimble Bob
Bimble Bob
An update: It works so far as now both windows do display something. However the first window doesn't clear properly it leaves a trail. I'm not sure why this is. I've tried adding a clear call after calling Present() and SetRenderTarget() but neither seem to work as I hoped.
It's not a bug... it's a feature!
Bimble Bob
Bimble Bob
Nevermind I have fixed it:

bool D3D9RenderDevice::BeginScene(bool pixel, bool depth, bool stencil)	{		//Check if there is a scene already running		//and end it if there is		if(m_sceneRunning)			EndScene();		for(int i = 0; i < m_numSwapChains; i++)		{			SetRenderTarget(i);			Clear(pixel, depth, stencil);		}				//Begin the scene		if(FAILED(m_d3d9Device->BeginScene()))			return false;		m_sceneRunning = true;		return true;	}


I just looped thorugh each swap chain and got it cleared individually.
Everything works fine now ^_^
It's not a bug... it's a feature!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.