Jump to content
  • Advertisement
Sign in to follow this  
SiS-Shadowman

Resizing the back- and depthbuffer

This topic is 3562 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using DirectX 9 and I try to resize the back and depthbuffer so I can change the window size (where d3d renders to) and avoid my screen getting pixelated (anyone knows a better term for that?). From here (Resizing the window) I got an explanation how to do this, without calling device->reset. This is the code I could come up with (code found here):
void CD3D::CreateSwapChain()
{
	D3DPRESENT_PARAMETERS scparam;
	memset(&scparam, 0, sizeof(scparam));

	scparam.Windowed               = true;
	scparam.hDeviceWindow          = m_WindowHandle; // This is the same handle I used in createdevice

	scparam.BackBufferCount        = 1;
	scparam.BackBufferFormat       = m_d3ddm.Format; // <= is queried before and set to D3DFMT_X8R8G8B8
	scparam.BackBufferHeight       = m_iScreenheight;
	scparam.BackBufferWidth        = m_iScreenwidth;
	
	scparam.SwapEffect             = D3DSWAPEFFECT_COPY;
	scparam.PresentationInterval   = D3DPRESENT_INTERVAL_ONE;

	// Create a swapchain
	V( m_pd3dDevice->CreateAdditionalSwapChain( &scparam, &m_pSwap ) );
	// Get the backbuffer from the swapchain
	V( m_pSwap->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &m_pSwapRenderSurf ) );
	// Create a depth buffer
	V( m_pd3dDevice->CreateDepthStencilSurface( m_iScreenwidth, m_iScreenheight, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, false, &m_pSwapDepthSurf, 0) );

	// Get the backbuffer and depth buffer from the device and store them away for reset/resize usage
	V( m_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &m_pDevRenderSurf ) );
	V( m_pd3dDevice->GetDepthStencilSurface( &m_pDevDepthSurf ) );

	// Set the device's rendertarget to the backbuffer from the swap chain, and set the depth buffer to the one you've created
	V( m_pd3dDevice->SetRenderTarget( 0, m_pSwapRenderSurf ) );
	V( m_pd3dDevice->SetDepthStencilSurface( m_pSwapDepthSurf ) );

	D3DVIEWPORT9 vp;

	vp.X = 0;
	vp.Y = 0;
	vp.Width = m_iScreenwidth;
	vp.Height = m_iScreenheight;
	vp.MinZ = 0;
	vp.MaxZ = 1;

	V( m_pd3dDevice->SetViewport(&vp) );
}


I'm calling this function right after I create the device. I don't get any error (using the debug runtimes), but some warnings (like "Direct3D9: (WARN) :Ignoring redundant SetSamplerState Sampler: 0, State: 21" or "Direct3D9: (WARN) :Ignoring redundant SetRenderState - 22"), but they also appear when I do NOT call this function, so my guess is that they're unrelated and I can take care of those warnings after resizing does work. The thing is, if I call CreateSwapChain(), the CStatic control (that's the control I want my scene to be rendered in) stays black. It doesn't if I don't call CreateSwapChain(): The Scene is rendered as it should. Can anybody tell me what could possibly go wrong here?

Share this post


Link to post
Share on other sites
Advertisement
The redundant render state warnings just mean that you're setting a render state to a value that it's already set to, and that's fine to ignore.

For the problem of the screen staying black, are you calling IDirect3DSwapChain9::Present() instead of IDirect3DDevice9::Present()? Presenting the device will just present the device swap chain, which isn't the one you're using (And should be 1x1 probably).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!