Restoring DirectX interface after alt+tab

This is a discussion on Restoring DirectX interface after alt+tab within the Game Programming forums, part of the General Programming Boards category; I am writing a DirectX class to wrap my graphics interface, but I need to be able to restore the ...

  1. #1
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189

    Restoring DirectX interface after alt+tab

    I am writing a DirectX class to wrap my graphics interface, but I need to be able to restore the interface after it is lost due to the user alt+tabbing to another application. I can detect the situation, and I am going to simply release the existing interface and create a new one, but I was wonderig if there is a better way.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    You must recreate the device and reset the device. Then you must re-create all managed assets. If you have a texture manager or a resource manager that will load from disk if the resource is not loaded then this process is nearly automatic. As the game engine requests textures and meshes your resource system hands them out and eventually everything that is needed for the game is slowly built back up.



    Code:
    ...
    ...
    GetApp()->getDevice()->SetTexture(0,GetApp()->getResMgr()->getTexture(MAIN_CHARACTER_MODEL);
    ...
    ...
    Now if getTexture() has code in it to load the texture from disk if it has not been loaded then all is well and you don't have to change any render code to handle lost devices. The only thing you have to do is write the code that actually catches the lost device condition and responds to it.
    Last edited by VirtualAce; 09-15-2008 at 05:45 PM.

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    well I tried
    Code:
    switch(this->device->Present(0 , 0 , 0 , 0)){
       case D3DERR_DEVICELOST: // application lost focus, reset
    
          while(this->device->Reset(&this->d3d_parameters) == D3DERR_DEVICELOST) Sleep(0);
     this->device->Release();
     this->d3d->Release();
     this->d3d = Direct3DCreate9(D3D_SDK_VERSION);
     this->d3d->CreateDevice(D3DADAPTER_DEFAULT , D3DDEVTYPE_HAL , hwnd , this->VertexProcessingMethod , &this->d3d_parameters , &this->device);
          break;
      default:
          break;
    }
    which does retake the screen, but there seems to be a conflict, as i get flashing pieces of the desktop or other appications. Right now all my application
    is doing is clearing the back buffer, there are no other resources created, I want to get the alt tab thing figured out before i start adding code to handle
    the meshes etc, so that i can add that into the alt tab handlign code as well where appropriate.
    Last edited by abachler; 09-16-2008 at 03:20 AM.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 10:13 AM
  2. D3DX - ALT + TAB / Drawing stuff
    By Tonto in forum Game Programming
    Replies: 8
    Last Post: 10-31-2006, 09:04 PM
  3. Visual C++
    By Golffor1 in forum C++ Programming
    Replies: 1
    Last Post: 08-04-2003, 05:30 PM
  4. code for Alt + Tab keys
    By Sumir in forum Windows Programming
    Replies: 2
    Last Post: 10-12-2002, 04:49 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21