multiple displays

Started by
2 comments, last by streamer 15 years, 11 months ago
Hi All, I am trying to experiment with displaying on multiple displays. I have an extended display setup where I have my laptop screen as primary display and another monitor as secondary display. I want to programatically switch between these displays and present the window that I have created. Basically, below are the steps I follow for a single monitor setup. 1) Create Device (specify Adapter as D3DADAPTER_DEFAULT) 2) Create Surface 3) Load Image 4) Copy Surface to Back Buffer 5) Present How do I create the device with multiple adapters? and switch between the adapters on the fly.
Advertisement
Hi
First question is are you gonna use two (or more ) monitors in fullscreen or in windowed mode.

You can get adapter count as:

adapterCount = m_pD3D->GetAdapterCount();

Here is windowed mode rendering.


Fullscreen is made as:

Create as many windows as your adapter count is:

m_hWnd[0] = CreateWindowEx( NULL, D3D_WND_CLASS, 			"win",			WS_POPUP | WS_VISIBLE,			0, 0, iWidth, iHeight, NULL, NULL, hInstance, NULL );m_hWnd[1] = CreateWindowEx( NULL, D3D_WND_CLASS, 			"win",			WS_POPUP | WS_VISIBLE,			0, 0, iWidth, iHeight, NULL, NULL, hInstance, NULL );


and create presentation parameters as:
// for dual head devices you need thisDWORD behaviorFlags = D3DCREATE_ADAPTERGROUP_DEVICE |	D3DCREATE_HARDWARE_VERTEXPROCESSING;D3DPRESENT_PARAMETERS *m_pPresentParams;m_pPresentParams = new D3DPRESENT_PARAMETERS[m_Device.iNumAdapters];memset( m_pPresentParams, 0, sizeof( D3DPRESENT_PARAMETERS ) * m_Device.iNumAdapters );for (UINT i = 0; i < m_Device.iNumAdapters ; i++ )	{		MODE_INFO *mode = m_Device.Adapters.CurrMode;		m_pPresentParams.BackBufferWidth = iWidth;		m_pPresentParams.BackBufferHeight = iHeight;		m_pPresentParams.BackBufferFormat = D3DFMT_X8R8G8B8;		m_pPresentParams.BackBufferCount = 1;		m_pPresentParams.MultiSampleType = D3DMULTISAMPLE_NONE;		m_pPresentParams.MultiSampleQuality = 0;		m_pPresentParams.SwapEffect = D3DSWAPEFFECT_FLIP;		m_pPresentParams.hDeviceWindow = m_hWnd;		m_pPresentParams.Windowed = FALSE;//FALSE;		m_pPresentParams.EnableAutoDepthStencil = TRUE;		m_pPresentParams.AutoDepthStencilFormat = D3DFMT_D16;		m_pPresentParams.Flags = 0;		m_pPresentParams.FullScreen_RefreshRateInHz = 60;		m_pPresentParams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;	}// create devicem_pD3D->CreateDevice( 0, D3DDEVTYPE_HAL,		m_hWnd[0], behaviorFlags, m_pPresentParams,		&m_pd3dDevice );// Get back buffer info	for ( UINT i = 0; i < m_Device.iNumAdapters; i++ )	{		LPDIRECT3DSWAPCHAIN9 pSwapChain = NULL;		m_pd3dDevice->GetSwapChain( i, &pSwapChain );		LPDIRECT3DSURFACE9 pBackBuffer = NULL;		pSwapChain->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );		pBackBuffer->GetDesc( &m_Device.Adapters.sdBackBuffer );		SAFE_RELEASE( pBackBuffer );		SAFE_RELEASE( pSwapChain );	}


and rendering is made as:
LPDIRECT3DSURFACE9 pRenderTarget = NULL;	hr = m_pd3dDevice->GetRenderTarget( 0, &pRenderTarget );	LPDIRECT3DSURFACE9 pDepthStencil = NULL;// Render each of the adapter swap chains	UINT numSwapChains = m_pd3dDevice->GetNumberOfSwapChains();m_pd3dDevice->GetSwapChain( 0, &pSwapChain );pSwapChain->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );m_pd3dDevice->SetRenderTarget( 0, pBackBuffer );m_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,0, 1.0f, 0 );m_pd3dDevice->BeginScene();// draw m_pd3dDevice->EndScene();m_pd3dDevice->GetSwapChain(1, &pSwapChain );pSwapChain->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );m_pd3dDevice->SetRenderTarget( 0, pBackBuffer );m_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,0, 1.0f, 0 );m_pd3dDevice->BeginScene();// draw m_pd3dDevice->EndScene();hr = m_pd3dDevice->SetRenderTarget( 0, pRenderTarget );SAFE_RELEASE( pRenderTarget );m_pd3dDevice->Present(0,0,0,0);


Sorry for ugly code it is croped from one of my project [smile], but it works.
Thanks for the response.

I understand that this can be accomplished by creating 2 windows.

But, is there no way of just creating one window, displaying it on one monitor and then switching the displayed window over to the secondary monitor. My intention is to create only one window.
Yes [smile]

Create windowed application, and just move window coordinate to secondary screen, and back (ie from 0,0 to 1280,0 ) with MoveWindow()

This topic is closed to new replies.

Advertisement