-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (66 loc) · 1.9 KB
/
main.cpp
File metadata and controls
80 lines (66 loc) · 1.9 KB
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
#include "stdafx.h"
#include "MyWindow.h"
#include "D3DSetup.h"
#include "MyShaders.h"
#include "MyScene.h"
// include the Direct3D Library files
#pragma comment (lib, "d3d11.lib")
#pragma comment (lib, "D3dcompiler.lib")
// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_KEYDOWN:
switch (wParam)
{
case VK_ESCAPE:
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc (hWnd, message, wParam, lParam);
}
// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
/*
int tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
tmpDbgFlag |= _CRTDBG_ALLOC_MEM_DF;
tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF;
tmpDbgFlag |= _CRTDBG_CHECK_CRT_DF;
tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF;
tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF;
_CrtSetDbgFlag(tmpDbgFlag);
*/
MyWindow window(hInstance);
D3DSetup d3d(window.hWnd);
MyShaders shaders(d3d.dev, d3d.devcon);
MyScene scene;
ShowWindow(window.hWnd, nCmdShow);
// deep blue
float backgroundColor[] = {0.0f, 0.2f, 0.4f, 1.0f};
MSG msg;
int frame = 1;
while(TRUE)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if(msg.message == WM_QUIT)
break;
}
// clear the back buffer to a deep blue
d3d.devcon->ClearRenderTargetView(d3d.backbuffer, backgroundColor);
scene.update(d3d.dev, d3d.devcon, frame);
scene.render(d3d.devcon);
// switch the back buffer and the front buffer, aka show what we just rendered
d3d.swapchain->Present(1, 0);
++frame;
}
return msg.wParam;
}