Atl+Tab Direct 3d anomaly

Started by
2 comments, last by mdfmKoRn 22 years, 3 months ago
I can''t get my game to stop acting weird when I alt+tab out of it. Here''s what I put in the Windows message pump to stop it:
  
case WM_ACTIVATE:
{
    WinActive=LOWORD(wParam)!=WA_INACTIVE;
    if ( WinActive==false )
	DeInit();
    else
        InitD3D( hWnd );
    return 0;
}
  
DeInit() looks like this:
  
VOID DeInit()
{
    if( pD3DDevice != NULL) 
        pD3DDevice->Release();

    if( pD3D != NULL)
        pD3D->Release();
}
  
I can alt+tab out, but if I click on a few other windows, my game regains the focus on its own and proceeds to draw without responding to the mouse or keyboard. Anybody know what''s going on? How do I make my game Alt+Tab friendly? ---- Herb M. (mdfmKoRn) www.sky-meyg.com s3202@attbi.com
Advertisement
A good method I''ve found is to use TestCooperativeLevel method of the IDirect3DDevice8 interface...so JUST before you call BeginScene in your rendering loop, you test the cooperative level...if you get back a D3DERR_DEVICEERR (or something like that..check the docs) then the user has alt+tabbed out of your program.

You''ll have to call Reset to rest the device, then (depending on how you declared your vertex buffers), you''ll have to reload the vertex and texture information...

ie.
  HRESULT beginRendering(){   HRESULT hr;   hr = lpD3DDevice->TestCooperativeLevel();   if(FAILED(hr))   (       if(hr == D3DERR_DEVICEERR)       {           //reset the direct3d device, and reload the         //textures         lpD3DDevice->Reset();         hr = loadTextures();         if(FAILED(hr))         {             return E_FAIL;         }                 }   }   lpD3DDevice->Clear(..);   return(lpD3DDevice->BeginScene());}  

something like that..
Learn about game programming!Games Programming in C++: Start to Finish
I ended up implementing something like that in the long run. Now, when I alt+tab out, there are little black boxes left here and there on the screen.

----
Herb M. (mdfmKoRn)
www.sky-meyg.com
s3202@attbi.com
You have to check for windows messages when application loses focus. Stop all rendering when this happends. Resume rendering when your application receives focus (you''ll probably have to Reset the device, due to D3DERR_DEVICELOST).

This topic is closed to new replies.

Advertisement