1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
#include "BuggedProgram.h"
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
// Set up window
InitializeWindow();
SetUpDirectX();
// Message loop
MSG msg = { };
while (WM_QUIT != msg.message)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Render();
}
return (int) msg.wParam;
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_SIZE:
{
winWidth = LOWORD(lParam);
winHeight = HIWORD(lParam);
if (pSwapChain)
{
pD3DDevice->OMSetRenderTargets(0, 0, 0);
pRenderTargetView->Release();
pSwapChain->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0);
ID3D10Texture2D* pBuffer;
pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (void**) &pBuffer);
pD3DDevice->CreateRenderTargetView(pBuffer, NULL, &pRenderTargetView);
pBuffer->Release();
pD3DDevice->OMSetRenderTargets(1, &pRenderTargetView, NULL);
// Set the viewport
D3D10_VIEWPORT viewPort;
viewPort.Width = winWidth;
viewPort.Height = winHeight;
viewPort.MinDepth = 0.0f;
viewPort.MaxDepth = 1.0f;
viewPort.TopLeftX = 0;
viewPort.TopLeftY = 0;
pD3DDevice->RSSetViewports(1, &viewPort);
// Set projection matrix
D3DXMatrixOrthoOffCenterLH(
&matProjection,
(float)viewPort.TopLeftX,
(float)viewPort.Width,
(float)viewPort.TopLeftY,
(float)viewPort.Height,
0.1f,
10);
Sprite::spriteObject->SetProjectionTransform(&matProjection);
}
} break;
//case WM_KEYDOWN:
// {
// } break;
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
void InitializeWindow()
{
// Window class
WNDCLASS wc = {};
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = L"WindowClass";
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
RegisterClass(&wc);
// Create window
windowHandle = CreateWindowEx(
0,
L"WindowClass",
L"Bugged program",
WS_OVERLAPPEDWINDOW,
0, 0,
winWidth, winHeight,
NULL,
NULL,
hInstance,
NULL);
// Show window
ShowWindow(windowHandle, SW_SHOWMAXIMIZED);
}
void SetUpDirectX()
{
// Swap chain
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Width = winWidth;
swapChainDesc.BufferDesc.Height = winHeight;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.OutputWindow = windowHandle;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.Windowed = true;
// Create device and swap chain
D3D10CreateDeviceAndSwapChain(
NULL,
D3D10_DRIVER_TYPE_HARDWARE,
NULL,
0,
D3D10_SDK_VERSION,
&swapChainDesc,
&pSwapChain,
&pD3DDevice);
// Set the render target
ID3D10Texture2D *pBackBuffer;
pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer);
pD3DDevice->CreateRenderTargetView(pBackBuffer, NULL, &pRenderTargetView);
pBackBuffer->Release();
pD3DDevice->OMSetRenderTargets(1, &pRenderTargetView, NULL);
// Set the viewport
D3D10_VIEWPORT viewPort;
viewPort.Width = winWidth;
viewPort.Height = winHeight;
viewPort.MinDepth = 0.0f;
viewPort.MaxDepth = 1.0f;
viewPort.TopLeftX = 0;
viewPort.TopLeftY = 0;
pD3DDevice->RSSetViewports(1, &viewPort);
// Set projection matrix
D3DXMatrixOrthoOffCenterLH(
&matProjection,
(float)viewPort.TopLeftX,
(float)viewPort.Width,
(float)viewPort.TopLeftY,
(float)viewPort.Height,
0.1f,
10);
}
void Render()
{
// Lots of Manchester United logos rollin'
static int xPos = 0;
for (int x = 0 - (winWidth / 15); x < winWidth; x += winWidth / 15)
for (int y = 0; y < winHeight; y += winHeight / 15)
Sprite(L"ManULogo.png", x + xPos, y, winWidth / 15, winHeight / 15);
++xPos;
if (xPos > winWidth / 15)
xPos = 0;
// Render sprites
if (pD3DDevice && Sprite::spriteObject)
{
pD3DDevice->ClearRenderTargetView(pRenderTargetView, D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f));
Sprite::spriteObject->Begin(D3DX10_SPRITE_SORT_TEXTURE);
Sprite::spriteObject->DrawSpritesImmediate(Sprite::spritePool, Sprite::numActiveSprites, 0, 0);
Sprite::spriteObject->End();
pSwapChain->Present(0, 0);
Sprite::numActiveSprites = 0;
}
}
| |