clray
diff src/clray.cc @ 13:407935b73af3
bollocks
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 04 Aug 2010 04:51:06 +0100 |
parents | 85fd61f374d9 |
children | 754faf15ba36 |
line diff
1.1 --- a/src/clray.cc Tue Aug 03 13:06:59 2010 +0100 1.2 +++ b/src/clray.cc Wed Aug 04 04:51:06 2010 +0100 1.3 @@ -9,6 +9,7 @@ 1.4 #endif 1.5 #include "rt.h" 1.6 #include "matrix.h" 1.7 +#include "mesh.h" 1.8 1.9 void cleanup(); 1.10 void disp(); 1.11 @@ -24,12 +25,33 @@ 1.12 static float cam_theta, cam_phi = 25.0; 1.13 static float cam_dist = 10.0; 1.14 1.15 -static bool dbg_glrender; 1.16 +static bool dbg_glrender = true; 1.17 + 1.18 +static Scene scn; 1.19 1.20 int main(int argc, char **argv) 1.21 { 1.22 glutInitWindowSize(800, 600); 1.23 glutInit(&argc, argv); 1.24 + 1.25 + int loaded = 0; 1.26 + for(int i=1; i<argc; i++) { 1.27 + if(!scn.load(argv[i])) { 1.28 + fprintf(stderr, "failed to load scene: %s\n", argv[i]); 1.29 + return false; 1.30 + } 1.31 + loaded++; 1.32 + } 1.33 + 1.34 + if(!loaded) { 1.35 + fprintf(stderr, "you must specify a scene file to load\n"); 1.36 + return false; 1.37 + } 1.38 + if(!scn.get_num_faces()) { 1.39 + fprintf(stderr, "didn't load any polygons\n"); 1.40 + return false; 1.41 + } 1.42 + 1.43 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); 1.44 glutCreateWindow("OpenCL Raytracer"); 1.45 1.46 @@ -42,7 +64,7 @@ 1.47 glutMouseFunc(mouse); 1.48 glutMotionFunc(motion); 1.49 1.50 - if(!init_renderer(xsz, ysz)) { 1.51 + if(!init_renderer(xsz, ysz, &scn)) { 1.52 return 1; 1.53 } 1.54 atexit(cleanup); 1.55 @@ -92,16 +114,18 @@ 1.56 set_xform(mat.m, inv_trans.m); 1.57 glPopMatrix(); 1.58 1.59 - if(!render()) { 1.60 - exit(1); 1.61 + if(!dbg_glrender) { 1.62 + if(!render()) { 1.63 + exit(1); 1.64 + } 1.65 + need_update = false; 1.66 } 1.67 - need_update = false; 1.68 } 1.69 1.70 if(dbg_glrender) { 1.71 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1.72 glLoadMatrixf(inv_mat.m); 1.73 - dbg_render_gl(); 1.74 + dbg_render_gl(&scn); 1.75 } else { 1.76 glEnable(GL_TEXTURE_2D); 1.77