Avionics
Dropship Simulator
Screen.cpp
Go to the documentation of this file.
1 #include "Screen.h"
2 
3 void Screen::Initialize(Logger* prmLogger, WINDOW_OBJECT* prmpWindow, ID3DX10Font* prmFont)
4 {
5  logger = prmLogger;
6  pWindow = prmpWindow;
7  pFont = prmFont;
8 
9  viewport.TopLeftX = 0;
10  viewport.TopLeftY = 0;
11  viewport.Width = pWindow->Width;
12  viewport.Height = pWindow->Height;
13  viewport.MinDepth = 0.0f;
14  viewport.MaxDepth = 1.0f;
15 
16  // Create the projection matrix using the values in the viewport
17  D3DXMatrixOrthoOffCenterLH(&matProjection, 0, static_cast<float>(viewport.Width), 0, static_cast<float>(viewport.Height), 0.1f, 1);
18 
19  D3D10_RASTERIZER_DESC desc;
20  desc.FillMode = D3D10_FILL_SOLID; // D3D10_FILL_WIREFRAME
21  desc.CullMode = D3D10_CULL_NONE;
22  desc.FrontCounterClockwise = false;
23  desc.DepthBias = 0;
24  desc.DepthBiasClamp = 0.0f;
25  desc.SlopeScaledDepthBias = 0.0f;
26  desc.DepthClipEnable = false;
27  desc.ScissorEnable = false;
28  desc.MultisampleEnable = false;
29  desc.AntialiasedLineEnable = false;
30 
31  HRESULT hr;
32  V(prmpWindow->pDevice->pd3dDevice->CreateRasterizerState(&desc, &state));
33  prmpWindow->pDevice->pd3dDevice->RSSetState(state);
34 
35  if (flip)
36  {
37  D3DXMatrixScaling(&matView, 1, -1, 1);
38  D3DXMATRIX trans;
39  D3DXMatrixTranslation(&trans, 0, static_cast<float>(pWindow->Height), 0);
40  matView *= trans;
41  }
42  else
43  {
44  D3DXMatrixIdentity(&matView);
45  }
46 
47  initialized = true;
48 }
49 
51 
52 void Screen::Render(float fElapsed)
53 {
54  HRESULT hr;
55 
56  // set the render target
57  pWindow->pDevice->pd3dDevice->OMSetRenderTargets(1, &pWindow->pRenderTargetView, nullptr);
58 
59  // set the viewport
60  pWindow->pDevice->pd3dDevice->RSSetViewports(1, &viewport);
61 
62  // clear the target
63  float clearColor[4] = {0.0, 0.0, 0.0, 0.0};
64 
65  pWindow->pDevice->pd3dDevice->ClearRenderTargetView(pWindow->pRenderTargetView, clearColor);
66  //pWindow->pDevice->pd3dDevice->ClearDepthStencilView(pWindow->pDepthStencilView, D3D10_CLEAR_DEPTH, 1.0, 0);
67 
68  // Set the projection matrix
69  if (FAILED(hr = pWindow->pDevice->pSprite->SetProjectionTransform(&matProjection)))
70  {
71  logger->Log("Screen::Render SetProjectionTransform failed!", Logger::Fatal, hr);
72  }
73 
74  // Set the projection matrix
75  if (FAILED(hr = pWindow->pDevice->pSprite->SetViewTransform(&matView)))
76  {
77  logger->Log("Screen::Render SetViewTransform failed!", Logger::Fatal, hr);
78  }
79 
80  // start drawing the sprites
81  if (FAILED(hr = pWindow->pDevice->pSprite->Begin(D3DX10_SPRITE_SORT_DEPTH_BACK_TO_FRONT)))
82  {
83  logger->Log("Screen::Render Begin failed!", Logger::Fatal, hr);
84  }
85 
86  pages.at(currentPage).Render(fElapsed);
87 
88  WCHAR msg[99];
89  swprintf_s(msg, 99, L"Adapter %i Win %i Page %i", pWindow->AdapterOrdinal, pWindow->WindowOrdinal, currentPage);
90  pFont->DrawTextW(pWindow->pDevice->pSprite, msg, -1, nullptr, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f));
91 
93  if (FAILED(hr = pWindow->pDevice->pSprite->Flush()))
94  {
95  logger->Log("Screen::Render Flush failed!", Logger::Fatal, hr);
96  }
97 
99  if (FAILED(hr = pWindow->pDevice->pSprite->End()))
100  {
101  logger->Log("Screen::Render End failed!", Logger::Fatal, hr);
102  }
103 }
bool flip
Definition: Screen.h:25
Logger * logger
Definition: Screen.h:9
ID3DX10Sprite * pSprite
Definition: DeviceObject.h:9
void Initialize(Logger *, WINDOW_OBJECT *, ID3DX10Font *)
Definition: Screen.cpp:3
D3DXMATRIX matView
Definition: Screen.h:19
Definition: Logger.h:5
ID3D10RasterizerState * state
Definition: Screen.h:13
ID3D10Device * pd3dDevice
Definition: DeviceObject.h:8
void Render(float fElapsed)
Definition: Screen.cpp:52
D3D10_VIEWPORT viewport
Definition: Screen.h:10
D3DXMATRIX matProjection
Definition: Screen.h:18
std::vector< Page > pages
Definition: Screen.h:17
ID3DX10Font * pFont
Definition: Screen.h:12
ID3D10RenderTargetView * pRenderTargetView
Definition: WindowObject.h:16
DEVICE_OBJECT * pDevice
Definition: WindowObject.h:15
void Log(const char *msg, Level level=Info, int errorCode=0)
These have to be in this order.
Definition: Logger.cpp:16
bool initialized
Definition: Screen.h:20
UINT WindowOrdinal
Definition: WindowObject.h:9
int currentPage
Definition: Screen.h:16
WINDOW_OBJECT * pWindow
Definition: Screen.h:11
UINT AdapterOrdinal
Definition: WindowObject.h:8