Skip to main content
gamedev.net
🔒 Locked

Resizing a surface.

Started by PumpkinPieman 2 replies 750+ views
Original Post
PumpkinPieman
PumpkinPieman
Right now I've come to a little problem where I somehow have to resize the screen in my MFC editor, and when I do I want to have the device change its window size so it doesn't stretch the surface out of proportion. I thought of using a swap chain and just killing and creating another one when the window is resized. But then I had problems with my window [MFC] painting whilst the swap chain was destroyed, and it ending up crashing. Since MFC has no real linear flow to the execution of the code(or does it?) nothing I’ve tried has worked. Does anyone know a solution or some type of work around for this kind of problem? Thanks
Kest
Kest
Override the OnPaint message function and only allow it to paint when the device is prepared.

Using MFC shouldn't be any different than using a normal window. Oh, and you can use timers to simulate a game loop. But I don't think that has much to do with your problem.
peter_b
peter_b
What you must do is that when your main frame receives a WM_SIZE msg, you must release all swapchains. Call reset for the backbuffer. And then recreate the swapchains.

If the main window dont resize but only the client view windows. You need to release thier swapchains, and recreate them with the new size.

This is what im doing using wtl. and it works. For both resizeing the main frame, and resizing the client windows.


Code for resetting device on resizing the main frame:
void graphics_manager_d3d_t::reset(int screen_width, int screen_height, bool fullscreen){	// save screen information	m_screen_width = screen_width;	m_screen_height = screen_height;	m_fullscreen = fullscreen;	HRESULT hr = 0;	if(FAILED(hr = m_d3dx_font->OnLostDevice()))		debug_assert(false, DXGetErrorString9(hr));	if(FAILED(hr = m_d3dx_line->OnLostDevice()))		debug_assert(false, DXGetErrorString9(hr));		// release all swapchains	for(std::map<int, swap_chain_t>::iterator iter = m_swap_chain_map.begin(); iter != m_swap_chain_map.end(); ++iter)		iter->second.m_d3d_swap_chain->Release();	// reinitialize the render device if it was lost	D3DPRESENT_PARAMETERS d3dpp = get_present_parameters(m_hwnd, m_screen_width, m_screen_height, m_fullscreen);	if(FAILED(hr = m_d3d_device->Reset(&d3dpp)))		debug_assert(false, DXGetErrorString9(hr));	// recreate swap chains	for(std::map<int, swap_chain_t>::iterator iter = m_swap_chain_map.begin(); iter != m_swap_chain_map.end(); ++iter)	{		swap_chain_t swap_chain = iter->second;		HRESULT hr = 0;		D3DPRESENT_PARAMETERS d3dpp = get_present_parameters(swap_chain.m_hwnd, 0, 0, false);		if(FAILED(hr = m_d3d_device->CreateAdditionalSwapChain(&d3dpp, &swap_chain.m_d3d_swap_chain)))			debug_assert(false, DXGetErrorString9(hr));				iter->second = swap_chain;	}	if(FAILED(hr = m_d3dx_font->OnResetDevice()))		debug_assert(false, DXGetErrorString9(hr));	if(FAILED(hr = m_d3dx_line->OnResetDevice()))		debug_assert(false, DXGetErrorString9(hr));}


You dont need to reset the device if only the swap chains change size, but not the main window.
Shields up! Rrrrred alert!
PumpkinPieman
PumpkinPieman
Resetting it worked well, I guess I'm going to have to rewrite my graphics code; it's getting a bit old and lacking things I need. :P

Topic Locked

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

Sign in to reply to this topic.