-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
45 lines (36 loc) · 1.22 KB
/
main.cpp
File metadata and controls
45 lines (36 loc) · 1.22 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
#include <iostream>
#include <chrono>
#include "SceneLoader.hpp"
int main(int argc, char *argv[])
{
std::cout << std::endl;
std::cout << "*********************************" << std::endl;
std::cout << "*** Kevin's Awesome Raytracer ***" << std::endl;
std::cout << "*********************************" << std::endl;
std::cout << std::endl;
if (argc < 2)
{
std::cerr << "[ERROR] Please a path your scene file (.json)" << std::endl;
std::cout << std::endl;
exit(0);
}
std::string path = argv[1];
auto [scene, camera, image] = SceneLoader::Load(path);
std::string outpath = "image.png";
if (argc > 2)
{
outpath = argv[2];
}
std::cout << "Rendering " << image->width << "x" << image->height << " pixels..." << std::endl;
auto begin = std::chrono::high_resolution_clock::now();
camera->render(*image, *scene);
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
std::cout << "Done." << std::endl;
std::printf("Total time: %.3f seconds.\n", elapsed.count() * 1e-9);
std::cout << "Writing file: " << outpath << std::endl;
image->writeFile(outpath);
delete scene;
delete camera;
delete image;
}