diff options
author | Morten Hustveit <morten.hustveit@gmail.com> | 2014-12-02 14:22:11 -0500 |
---|---|---|
committer | Morten Hustveit <morten.hustveit@gmail.com> | 2014-12-02 14:22:11 -0500 |
commit | 0ef8e84c082a80354b502b169b6c79fccffa4405 (patch) | |
tree | c62b361bdc570598f7e8035963f8520bfd764702 /main_glut.c | |
parent | 706da965d3c7892ef09b83bdf6120f104faa2ede (diff) |
Make a headless entry point for benchmarking purposes
Diffstat (limited to 'main_glut.c')
-rw-r--r-- | main_glut.c | 75 |
1 files changed, 75 insertions, 0 deletions
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 <GL/gl.h> +#include <GL/glu.h> +#include <GL/glut.h> + +#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; +} |