-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
126 lines (98 loc) · 2.45 KB
/
main.cpp
File metadata and controls
126 lines (98 loc) · 2.45 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
//External includes
#include "SDL.h"
#undef main
//Standard includes
#include <iostream>
//Project includes
#include "Timer.h"
#include "Renderer.h"
#include "Scene.h"
using namespace dae;
void ShutDown(SDL_Window* pWindow)
{
SDL_DestroyWindow(pWindow);
SDL_Quit();
}
int main(int argc, char* args[])
{
//Unreferenced parameters
(void)argc;
(void)args;
//Create window + surfaces
SDL_Init(SDL_INIT_VIDEO);
constexpr uint32_t width = 640;
constexpr uint32_t height = 480;
//const auto pScene = new Scene_W1();
//const auto pScene = new Scene_W2();
//const auto pScene = new Scene_W3();
const auto pScene = new Scene_W4();
//const auto pScene = new Scene_W4_Bunny();
pScene->Initialize();
std::string title = "RayTracer - Xander Berten (2DAE09) - ";
title += pScene->GetSceneName();
SDL_Window* pWindow = SDL_CreateWindow(
title.c_str(),
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
width, height, 0);
if (!pWindow)
return 1;
//Initialize "framework"
const auto pTimer = new Timer();
const auto pRenderer = new Renderer(pWindow);
//Start loop
pTimer->Start();
// Start Benchmark
// pTimer->StartBenchmark();
float printTimer = 0.f;
bool isLooping = true;
bool takeScreenshot = false;
while (isLooping)
{
//--------- Get input events ---------
SDL_Event e;
while (SDL_PollEvent(&e))
{
switch (e.type)
{
case SDL_QUIT:
isLooping = false;
break;
case SDL_KEYUP:
if (e.key.keysym.scancode == SDL_SCANCODE_X) takeScreenshot = true;
if (e.key.keysym.scancode == SDL_SCANCODE_F2) pRenderer->ToggleShadows();
if (e.key.keysym.scancode == SDL_SCANCODE_F3) pRenderer->CycleLightingMode();
if (e.key.keysym.scancode == SDL_SCANCODE_F6) pTimer->StartBenchmark();
break;
}
}
//--------- Update ---------
pScene->Update(pTimer);
//--------- Render ---------
pRenderer->Render(pScene);
//--------- Timer ---------
pTimer->Update();
printTimer += pTimer->GetElapsed();
if (printTimer >= 1.f)
{
printTimer = 0.f;
std::cout << "dFPS: " << pTimer->GetdFPS() << std::endl;
}
//Save screenshot after full render
if (takeScreenshot)
{
if (!pRenderer->SaveBufferToImage())
std::cout << "Screenshot saved!" << std::endl;
else
std::cout << "Something went wrong. Screenshot not saved!" << std::endl;
takeScreenshot = false;
}
}
pTimer->Stop();
//Shutdown "framework"
delete pScene;
delete pRenderer;
delete pTimer;
ShutDown(pWindow);
return 0;
}