void GameScene::DrawScene(const tt::GameContext& context) { auto pGfxService = MyServiceLocator::GetInstance()->GetService<IGraphicsService>(); pGfxService->PrepareShadowGeneration(); for(auto pObj : m_Objects) pObj->GenerateShadows(context); pGfxService->GetGraphicsDevice()->ResetRenderTarget(); pGfxService->PrepareDeferredShading(); for(auto pObj : m_Objects){ pObj->Draw(context); //pObj->DrawObject(context); } pGfxService->CompositeDeferredShading(context); //Render FPS m_pDefaultFont->DrawText(std::tstring(_T("FPS: ")) + to_tstring(context.FramesPerSecond) + _T("\nSPF: ") + to_tstring(context.GameTimer.GetElapsedSeconds() ), tt::Vector2(5,0), tt::Vector4(1,1,0,1) ); pGfxService->GetSpriteBatch()->Flush(context); auto particlesSprite = ParticleEmitterComponent::RenderDeferred(context); //pGfxService->GetSpriteBatch()->Draw(particlesSprite); //pGfxService->GetSpriteBatch()->Flush(context); if(!m_PostProEffects.empty() ){ auto postProSprite = pGfxService->RenderPostProcessing(context, m_PostProEffects); pGfxService->GetSpriteBatch()->Draw(postProSprite); pGfxService->GetSpriteBatch()->Flush(context); } }
void ErrorPopUpScreen::Draw(float totalTime, float elapsedTime) { UNREFERENCED_PARAMETER(totalTime); UNREFERENCED_PARAMETER(elapsedTime); auto screenManager = Manager(); auto spriteBatch = screenManager->GetSpriteBatch(); auto spriteFont = screenManager->GetSpriteFont(); auto blendStates = screenManager->GetCommonStates(); auto viewportBounds = screenManager->GetScreenBounds(); float viewportWidth = float(viewportBounds.right); float viewportHeight = float(viewportBounds.bottom); auto scaleMatrix = DX::GetScaleMatrixForWindow(screenManager->GetWindowBounds()); // calculate position and size of error message XMFLOAT2 errorMsgPosition = XMFLOAT2(0, viewportHeight / 2.0f); XMVECTORF32 errorMsgColor = Colors::Yellow; XMFLOAT2 origin = XMFLOAT2(0, spriteFont->GetLineSpacing() / 2.0f); XMVECTOR size = spriteFont->MeasureString(m_errorMessage.c_str()); errorMsgPosition.x = viewportWidth / 2.0f - XMVectorGetX(size) / 2.0f; // create a rectangle representing the screen dimensions of the error message background rectangle long rectangleWidth = long(std::min(std::max(XMVectorGetX(size) + 100.0f, 600.0f), viewportWidth)); long rectangleHeight = long(spriteFont->GetLineSpacing() * 6.0f); long rectangleLeft = long(viewportWidth / 2.0f) - (rectangleWidth / 2); long rectangleTop = long(errorMsgPosition.y + spriteFont->GetLineSpacing()) - (rectangleHeight / 2); RECT backgroundRectangle = { rectangleLeft, rectangleTop, rectangleLeft + rectangleWidth, rectangleTop + rectangleHeight }; spriteBatch->Begin(SpriteSortMode_Deferred, blendStates->NonPremultiplied(), nullptr, nullptr, nullptr, nullptr, scaleMatrix); // draw a background color for the rectangle spriteBatch->Draw(m_backgroundTexture->GetResourceViewTemporary(), backgroundRectangle, BackgroundColor); // draw error message in the middle of the screen spriteFont->DrawString(spriteBatch.get(), m_errorMessage.c_str(), errorMsgPosition, errorMsgColor, 0, origin); // draw continuation prompt winrt::hstring continuePrompt = L"Press (A) to Continue"; if (!InputState::IsAnyGamepadConnected()) { continuePrompt = L"Press Enter to Continue"; } errorMsgPosition.y += spriteFont->GetLineSpacing(); size = spriteFont->MeasureString(continuePrompt.c_str()); errorMsgPosition.x = viewportWidth / 2.0f - XMVectorGetX(size) / 2.0f; spriteFont->DrawString(spriteBatch.get(), continuePrompt.c_str(), errorMsgPosition, Colors::Yellow, 0, origin); spriteBatch->End(); }