nuclear@54: #include nuclear@54: #include nuclear@54: #include "rt.h" nuclear@54: #include "ogl.h" nuclear@54: nuclear@54: #define MIN(a, b) ((a) < (b) ? (a) : (b)) nuclear@54: static void dbg_set_gl_material(Material *mat) nuclear@54: { nuclear@54: static Material def_mat = {{0.7, 0.7, 0.7, 1}, {0, 0, 0, 0}, 0, 0, 0}; nuclear@54: nuclear@54: if(!mat) mat = &def_mat; nuclear@54: nuclear@54: glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat->kd); nuclear@54: glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat->ks); nuclear@54: glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, MIN(mat->spow, 128.0f)); nuclear@54: } nuclear@54: nuclear@54: void dbg_render_gl(Scene *scn, bool show_tree, bool show_obj) nuclear@54: { nuclear@54: const RendInfo *rinf = get_render_info(); nuclear@54: const Face *faces = scn->get_face_buffer(); nuclear@54: nuclear@54: glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT | GL_LIGHTING_BIT); nuclear@54: nuclear@54: for(int i=0; iget_num_lights(); i++) { nuclear@54: float lpos[4]; nuclear@54: nuclear@54: memcpy(lpos, scn->lights[i].pos, sizeof lpos); nuclear@54: lpos[3] = 1.0; nuclear@54: nuclear@54: glLightfv(GL_LIGHT0 + i, GL_POSITION, lpos); nuclear@54: glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, scn->lights[i].color); nuclear@54: glEnable(GL_LIGHT0 + i); nuclear@54: } nuclear@54: nuclear@54: glDisable(GL_TEXTURE_2D); nuclear@54: glEnable(GL_DEPTH_TEST); nuclear@54: glEnable(GL_LIGHTING); nuclear@54: nuclear@54: glMatrixMode(GL_PROJECTION); nuclear@54: glPushMatrix(); nuclear@54: glLoadIdentity(); nuclear@54: gluPerspective(45.0, (float)rinf->xsz / (float)rinf->ysz, 0.5, 1000.0); nuclear@54: nuclear@54: if(show_obj) { nuclear@54: Material *materials = scn->get_materials(); nuclear@54: nuclear@54: int num_faces = scn->get_num_faces(); nuclear@54: int cur_mat = -1; nuclear@54: nuclear@54: for(int i=0; idraw_kdtree(); nuclear@54: } nuclear@54: nuclear@54: glPopMatrix(); nuclear@54: glPopAttrib(); nuclear@54: nuclear@54: assert(glGetError() == GL_NO_ERROR); nuclear@54: }