void DirectXGraphics::renderGame(Game *game) { GameStateManager *gsm = game->getGSM(); World *world = gsm->getWorld(); GameText *text = game->getText(); // CHECK TO SEE IF WE STILL HAVE THE GPU HRESULT result = graphicsDevice->TestCooperativeLevel(); // IF WE HAVE THE GPU, RENDER THE GAME if (SUCCEEDED(result)) { // NOW PREPARE TO RENDER THE LISTS USING // BATCH TEXTURE RENDERING startDirectXFrameRendering(); spriteHandler->Begin(D3DXSPRITE_ALPHABLEND); // RENDER THE WORLD RENDER LIST renderWorldRenderList(); // RENDER THE GUI RENDER LIST renderGUIRenderList(); // RENDER THE TEXT renderText(text); // WRAP UP RENDERING RESOURCES if (FAILED(spriteHandler->End())) { text->writeDebugOutput("\nspriteHandler->End(): FAILED"); } endDirectXFrameRendering(); } // WE'VE LOST THE GPU, SLEEP UNTIL WE GET IT BACK else if (result == D3DERR_DEVICELOST) { spriteHandler->OnLostDevice(); textFont->OnLostDevice(); Sleep(100); } // WE'VE GOT IT BACK, RELOAD EVERYTHING. NOTE THAT // WE'LL ONLY GET THIS MESSAGE ONCE. else if (result == D3DERR_DEVICENOTRESET) { if (FAILED(graphicsDevice->Reset(&presentParameters))) { game->getText()->writeDebugOutput("\ngraphicsDevice->Reset: FAILED - Reloading GPU images"); game->reloadAllDevices(); } else { spriteHandler->OnResetDevice(); textFont->OnResetDevice(); } } }
/* createDirectXDeviceAndSpriteHandler - THIS METHOD CREATES OUR GPU AND SPRITE HANDLER (used for batch rendering textures) USING THE COLOR FORMAT AND SCREEN RESOLUTION OF OUR CHOICE. */ HRESULT DirectXGraphics::createDirectXDeviceAndSpriteHandler() { HRESULT result; GameText *text = game->getText(); // CREATE OUR GPU result = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, presentParameters.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, &presentParameters, &graphicsDevice); // IF GPU CREATION WAS SUCCESSFUL if (SUCCEEDED(result)) { text->writeDebugOutput("SUCCEEDED"); text->writeDebugOutput("\nD3DXCreateSprite(): "); // CREATE OUR SPRITE HANDLER result = D3DXCreateSprite(graphicsDevice, &spriteHandler); if (SUCCEEDED(result)) { text->writeDebugOutput("SUCCEEDED"); } else text->writeDebugOutput("FAILED"); this->initTextFont(20); } else text->writeDebugOutput("FAILED"); return result; }