-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
67 lines (59 loc) · 1.7 KB
/
main.cpp
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
#include <iostream>
#include <fstream>
#include "GL\freeglut.h"
#include "cuda.h"
#include "math.h"
#include "lite_tracer.h"
#include "gpu_timer.h"
float buffer[image_size * 3];
void render()
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.05f, 0.0f, 0.06f, 1.0f);
glDrawPixels(width, height, GL_RGB, GL_FLOAT, buffer);
glFlush(); glutSwapBuffers();
}
void scene1()
{
add_cube(vec3(+1.6f, 0.9f, +0.6f), { 0.8f,0.8f,0.8f }, light_green, 0.3);
add_cube(vec3(+0.0f, 0.9f, +0.1f), { 1.1f,1.1f,1.1f }, basic_red, 0.7);
add_cube(vec3(-1.8f, 0.9f, +0.3f), { 0.8f,0.8f,0.8f }, light_red, 0.9);
add_cube(vec3(-0.65f, 1.9f, +1.9f), { 1.3f,1.1f,0.1f }, glass_ideal, 0.2);
}
void scene2()
{
add_cube(vec3(-0.6, 0.9f, +0.3f), { 3.5f,0.8f,0.8f }, basic_blue, 0.0);
add_cube(vec3(+1.0, 1.1f, -0.8f), { 2.5f,0.8f,0.8f }, mirror_50, 0.0);
add_cube(vec3(-0.6f, 1.3f, 1.2f), { 2.1f,1.8f,0.2f }, glass_ideal, 0.0);
add_cube(vec3(+0.1f, 1.6f, -0.2f), { 1.8f,1.8f,0.2f }, glass_ideal, 0.0);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(width, height);
glutInitWindowPosition(windowX, windowY);
glutCreateWindow("LiteGL3000");
glutDisplayFunc(render);
glLoadIdentity();
glOrtho(0, width, 0, height, 0, 1);
build_room(vec3(6, 5, 6));
scene2();
float accumulated_time = 0.0f;
for (int iter = 0;; iter++)
{
GpuTimer timer;
timer.Start();
path_tracing(iter, (float3*)buffer);
if ((iter + 1) % 30 == 0)
{
printf("Time elapsed = %g ms\n", accumulated_time);
printf("Average FPS = %g fps\n", iter / accumulated_time * 1000.f);
}
glutMainLoopEvent();
glutPostRedisplay();
timer.Stop();
accumulated_time += timer.Elapsed();
}
return 0;
}