-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
127 lines (118 loc) · 3.47 KB
/
main.cpp
File metadata and controls
127 lines (118 loc) · 3.47 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
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
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "./core/core_pack.h"
#include "./core/integrator_pack.h"
#include "./utils/Config.h"
#include "./core/Camera.h"
static WNDCLASS wc;
static HWND wnd;
static char bitmapbuffer[sizeof( BITMAPINFO ) + 16];
static BITMAPINFO* bh;
HDC window_hdc;
unsigned int * buffer = 0;
int SCRWIDTH;
int SCRHEIGHT;
Camera * cam = 0;
void DrawWindow();
static LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
int result = 0, keycode = 0;
switch (message)
{
case WM_PAINT:
if (!buffer) break;
StretchDIBits( window_hdc, 0, 0, SCRWIDTH, SCRHEIGHT, 0, 0, SCRWIDTH, SCRHEIGHT, buffer, bh, DIB_RGB_COLORS, SRCCOPY );
ValidateRect( wnd, NULL );
break;
case WM_MOUSEMOVE:
if (cam)
cam->mouseTo(float(LOWORD(lParam))/SCRWIDTH, float(HIWORD(lParam))/SCRHEIGHT);
break;
case WM_KEYDOWN:
switch(wParam & 0xFF){
case 27: break;//esc
default:
if (cam)
cam->parseKey(wParam & 0xFF);
return 0;
};
case WM_CLOSE:
ReleaseDC( wnd, window_hdc );
DestroyWindow( wnd );
//SystemParametersInfo( SPI_SETSCREENSAVEACTIVE, 1, 0, 0 );
ExitProcess( 0 );
break;
default:
result = DefWindowProc(hWnd,message,wParam,lParam);
}
return result;
}
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
RECT rect;
int cc;
LogDefault = new Logger();
Config config("config.txt");
SCRWIDTH=config.getIntByName("width");
SCRHEIGHT=config.getIntByName("height");
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = wc.cbWndExtra = 0;
wc.hInstance = 0;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(0,IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = L"RT";
if (!RegisterClass(&wc)) return FALSE;
rect.left = rect.top = 0;
rect.right = SCRWIDTH, rect.bottom = SCRHEIGHT;
AdjustWindowRect( &rect, WS_POPUP|WS_SYSMENU|WS_CAPTION, 0 );
rect.right -= rect.left, rect.bottom -= rect.top;
wnd = CreateWindowEx( 0, L"RT", L"RayTracer v0.2", WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME,
CW_USEDEFAULT, CW_USEDEFAULT, rect.right, rect.bottom, 0, 0, 0, 0 );
ShowWindow(wnd,SW_NORMAL);
for ( cc = 0; cc < sizeof( BITMAPINFOHEADER ) + 16; cc++ ) bitmapbuffer[cc] = 0;
bh = (BITMAPINFO *)&bitmapbuffer;
bh->bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
bh->bmiHeader.biPlanes = 1;
bh->bmiHeader.biBitCount = 32;
bh->bmiHeader.biCompression = BI_BITFIELDS;
bh->bmiHeader.biWidth = SCRWIDTH, bh->bmiHeader.biHeight = -SCRHEIGHT;
((unsigned long*)bh->bmiColors)[0] = 255 << 16;
((unsigned long*)bh->bmiColors)[1] = 255 << 8;
((unsigned long*)bh->bmiColors)[2] = 255;
window_hdc = GetDC(wnd);
//SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, 0, 0);
buffer = new unsigned int[SCRWIDTH * SCRHEIGHT];
Engine engine(
//new DebugRayCaster(config, DebugRayCaster::getNorm),
//new KdDebugRayCaster(config),
new RayCaster(config),
config);
cam = engine.getScene()->getCamera();
//prepare output
DrawWindow();
while (1)
{
engine.trace(buffer);
DrawWindow();
}
return 1;
}
void DrawWindow()
{
MSG message;
HACCEL haccel = 0;
InvalidateRect( wnd,NULL,TRUE );
SendMessage( wnd, WM_PAINT, 0, 0 );
while (PeekMessage( &message, wnd, 0, 0, PM_REMOVE ))
{
if (TranslateAccelerator( wnd, haccel, &message ) == 0)
{
TranslateMessage( &message );
DispatchMessage( &message );
}
}
Sleep( 0 );
}