Window Resizing : can't figure out what I'm doing wrong

Started by
7 comments, last by Toonkides 19 years, 5 months ago
Within my Renderscene function I have this code.

switch(g_pd3dDevice->TestCooperativeLevel())
	{
	case D3DERR_DEVICELOST :
		Cleanup() ;
		return ;

	case D3DERR_DEVICENOTRESET :
		// release the objects
		if(g_pVB != NULL)
			g_pVB->Release() ;

		if(g_pTexture[0] != NULL)
			g_pTexture[0]->Release() ;
	
		if(g_pTexture[1] != NULL)
			g_pTexture[1]->Release() ;

		// reset the device
		g_pd3dDevice->Reset(&d3dpp) ;

		// recreate and initialize the objects
		ZeroMemory(&d3dpp, sizeof(d3dpp)) ;
		d3dpp.Windowed					= TRUE ;
		d3dpp.SwapEffect				= D3DSWAPEFFECT_DISCARD ;
		d3dpp.BackBufferWidth			= g_width ;
		d3dpp.BackBufferHeight			= g_height ;
		d3dpp.BackBufferFormat			= D3DFMT_UNKNOWN ;
		d3dpp.EnableAutoDepthStencil	= TRUE ;
		d3dpp.AutoDepthStencilFormat	= D3DFMT_D16 ;

		// create the D3DDevice
		if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,
			D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice)))
			return ;

		// turn of culling
		g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE) ;
		// turn off D3D lighting
		g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE) ;
		// turn on the zbuffer
		g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, TRUE) ;
		g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE) ;
		InitGeometry() ;
		break ;
	}

In my Message Proc I have this code :

case WM_SIZE :
		GetClientRect(hWnd, &rc) ;
		g_width = rc.right - rc.left ;		// reset the width
		g_height = rc.bottom - rc.top ;		// reset the height
		return 0 ;

I have tried releasing->reseting->recreating/initializing the objects within the WM_SIZE message but then the application doesn't even load. Any suggestions? TIA
Advertisement
Use the debugger and step through your code.
never learned the thing :(, but the program actually runs, it's just not showing anything on the screen.

In the WM_SIZE message I "SAFERELEASE()" all the objects
then I test the coop levels in the render function which resets the device then I recreate my objects.

What could be wrong?
I once had a similar sounding problem and it was because I was using the D3DXFont class and I was forgetting to reset it as well. So, if you are using any of those D3DX helper classes, make sure you call their reset methods.
Also, make a special case in WM_SIZE. Sometimes you get WM_SIZE called on startup with size 0 by 0. Reset will not work if you try to create a backbuffer of width or height = 0.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

My program is very basic actually it just loads a few points into the VB and applies a texture to them as well.

No fonts.

I didn't know about the WM_SIZE on startup, how do I get around this ?

TIA
Quote:Original post by Toonkides
I didn't know about the WM_SIZE on startup, how do I get around this ?

case WM_SIZE:  if(0 == (rc.left - rc.right) || 0 == (rc.bottom - rc.top))    return 0;  // the rest here
After trying that I also noticed that when i put a messagebox call within my render scene :

switch(g_pd3dDevice->TestCooperativeLevel())	{	case D3DERR_DEVICELOST :		Cleanup() ;		return ;	case D3DERR_DEVICENOTRESET :                MessageBox(NULL, TEXT("TEST"), TEXT("TESTING"), MB_OK) ;		// reset the device		g_pd3dDevice->Reset(&d3dpp) ;		// turn of culling		g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE) ;		// turn off D3D lighting		g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE) ;		// turn on the zbuffer		g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, TRUE) ;		g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE) ;		// recreate and initialize the objects		d3dpp.BackBufferWidth			= g_width ;		d3dpp.BackBufferHeight			= g_height ;		// create the D3DDevice		if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,			D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice)))			return ;		InitGeometry() ;		break ;	}


And it's not even executing. I thought that when you release all the objects the testcoop will automatically be setup for the device not reset. Am I missing something obvious?
I figured it out :

It turns out that if I went to my original configuration this would have worked. My problem was exactly what Endurion & Oluseyi were saying.

Thx guys, sorry to spam the boards; it was a journey!

<3

This topic is closed to new replies.

Advertisement