From 0ef8e84c082a80354b502b169b6c79fccffa4405 Mon Sep 17 00:00:00 2001 From: Morten Hustveit Date: Tue, 2 Dec 2014 14:22:11 -0500 Subject: Make a headless entry point for benchmarking purposes --- main_glut.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 main_glut.c (limited to 'main_glut.c') diff --git a/main_glut.c b/main_glut.c new file mode 100644 index 0000000..cf22a73 --- /dev/null +++ b/main_glut.c @@ -0,0 +1,75 @@ +#include +#include +#include + +#include "ray.h" + +static int threaded; + +static int +init(int argc, char **argv, int w, int h) { + glutInit(&argc, argv); + + glutInitWindowPosition(0, 0); + glutInitWindowSize(w, h); + glutInitDisplayMode(GLUT_RGB); + glutCreateWindow(argv[0]); + + glDepthMask(0); + glDisable(GL_DEPTH_TEST); + glDisable(GL_BLEND); + + return 0; +} + +static void +display(void) { + static int count = 0; + ++count; + if(count > 10000) + exit(0); + float time = (float)glutGet(GLUT_ELAPSED_TIME) / 1000; + + unsigned char* buffer = calloc(4, WIDTH * HEIGHT); + trace_scene(time, buffer, threaded); + glDrawPixels(WIDTH, HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE, buffer); + free(buffer); + + glutSwapBuffers(); +} + +static void +reshape(int w, int h) { + glViewport(0, 0, w, h); +} + +static void +keyboard(unsigned char key, int x, int y) { + switch(key) { + case 27: + exit(EXIT_SUCCESS); + break; + case 't': + if(threaded) + threaded = 0; + else + threaded = 1; + break; + } +} + + +int +main(int argc, char **argv) { + if (init(argc, argv, WIDTH, HEIGHT)) + return EXIT_FAILURE; + + glutDisplayFunc(display); + glutIdleFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + + glutMainLoop(); + + return EXIT_SUCCESS; +} -- cgit v1.2.3 From 1d257b2051c94988318706a1070794fc2262bd6b Mon Sep 17 00:00:00 2001 From: Morten Hustveit Date: Tue, 2 Dec 2014 21:40:41 -0500 Subject: main_glut.c: Clear window and center animation --- main_glut.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'main_glut.c') diff --git a/main_glut.c b/main_glut.c index cf22a73..92e3fdb 100644 --- a/main_glut.c +++ b/main_glut.c @@ -5,6 +5,7 @@ #include "ray.h" static int threaded; +static int viewport_width, viewport_height; static int init(int argc, char **argv, int w, int h) { @@ -32,6 +33,8 @@ display(void) { unsigned char* buffer = calloc(4, WIDTH * HEIGHT); trace_scene(time, buffer, threaded); + glClear(GL_COLOR_BUFFER_BIT); + glRasterPos2d(-(double)WIDTH / viewport_width, -(double)HEIGHT / viewport_height); glDrawPixels(WIDTH, HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE, buffer); free(buffer); @@ -40,6 +43,8 @@ display(void) { static void reshape(int w, int h) { + viewport_width = w; + viewport_height = h; glViewport(0, 0, w, h); } -- cgit v1.2.3 From 128778e557dd665db36f2ac5fe3d21af22d32c50 Mon Sep 17 00:00:00 2001 From: Morten Hustveit Date: Tue, 2 Dec 2014 21:53:51 -0500 Subject: main_glut.c: Enable double buffering This prevents screen flickering during screen updates. --- main_glut.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main_glut.c') diff --git a/main_glut.c b/main_glut.c index 92e3fdb..ed4eee5 100644 --- a/main_glut.c +++ b/main_glut.c @@ -13,7 +13,7 @@ init(int argc, char **argv, int w, int h) { glutInitWindowPosition(0, 0); glutInitWindowSize(w, h); - glutInitDisplayMode(GLUT_RGB); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutCreateWindow(argv[0]); glDepthMask(0); -- cgit v1.2.3 From 10e4a4eb02b50a5751e496d6661a0587a86f11b5 Mon Sep 17 00:00:00 2001 From: Morten Hustveit Date: Tue, 2 Dec 2014 21:54:15 -0500 Subject: main_glut.c: Enable threading by default --- main_glut.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'main_glut.c') diff --git a/main_glut.c b/main_glut.c index ed4eee5..1717898 100644 --- a/main_glut.c +++ b/main_glut.c @@ -4,7 +4,7 @@ #include "ray.h" -static int threaded; +static int threaded = 1; static int viewport_width, viewport_height; static int @@ -54,11 +54,9 @@ keyboard(unsigned char key, int x, int y) { case 27: exit(EXIT_SUCCESS); break; + case 't': - if(threaded) - threaded = 0; - else - threaded = 1; + threaded = !threaded; break; } } -- cgit v1.2.3 From dbab279df7ffcf5dd55128a1bc44ea52d7584859 Mon Sep 17 00:00:00 2001 From: Morten Hustveit Date: Fri, 12 Dec 2014 15:32:34 -0800 Subject: main_glut.c: Restrict raster position to inside of target window --- main_glut.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'main_glut.c') diff --git a/main_glut.c b/main_glut.c index 1717898..272b17e 100644 --- a/main_glut.c +++ b/main_glut.c @@ -34,7 +34,11 @@ display(void) { unsigned char* buffer = calloc(4, WIDTH * HEIGHT); trace_scene(time, buffer, threaded); glClear(GL_COLOR_BUFFER_BIT); - glRasterPos2d(-(double)WIDTH / viewport_width, -(double)HEIGHT / viewport_height); + auto raster_x = -(double)WIDTH / viewport_width; + auto raster_y = -(double)HEIGHT / viewport_height; + if (raster_x < -1.0) raster_x = -1.0; + if (raster_y < -1.0) raster_y = -1.0; + glRasterPos2d(raster_x, raster_y); glDrawPixels(WIDTH, HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE, buffer); free(buffer); -- cgit v1.2.3 From eefec7a70c96e20e3920fb2adea6c4da77c26170 Mon Sep 17 00:00:00 2001 From: Morten Hustveit Date: Fri, 12 Dec 2014 15:41:38 -0800 Subject: Render to window dimensions --- main_glut.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'main_glut.c') diff --git a/main_glut.c b/main_glut.c index 272b17e..e24ab5e 100644 --- a/main_glut.c +++ b/main_glut.c @@ -31,15 +31,11 @@ display(void) { exit(0); float time = (float)glutGet(GLUT_ELAPSED_TIME) / 1000; - unsigned char* buffer = calloc(4, WIDTH * HEIGHT); - trace_scene(time, buffer, threaded); + unsigned char* buffer = calloc(viewport_width * viewport_height, 4); + trace_scene(time, viewport_width, viewport_height, buffer, threaded); glClear(GL_COLOR_BUFFER_BIT); - auto raster_x = -(double)WIDTH / viewport_width; - auto raster_y = -(double)HEIGHT / viewport_height; - if (raster_x < -1.0) raster_x = -1.0; - if (raster_y < -1.0) raster_y = -1.0; - glRasterPos2d(raster_x, raster_y); - glDrawPixels(WIDTH, HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE, buffer); + glRasterPos2d(-1.0, -1.0); + glDrawPixels(viewport_width, viewport_height, GL_BGRA, GL_UNSIGNED_BYTE, buffer); free(buffer); glutSwapBuffers(); @@ -68,7 +64,7 @@ keyboard(unsigned char key, int x, int y) { int main(int argc, char **argv) { - if (init(argc, argv, WIDTH, HEIGHT)) + if (init(argc, argv, 800, 600)) return EXIT_FAILURE; glutDisplayFunc(display); -- cgit v1.2.3