void R2Image:: SetPixelRGB(int x, int y, const RNRgb& rgb) { // Set pixel color unsigned char *pixel = &(pixels[y*rowsize + x*ncomponents]); switch (ncomponents) { case 1: *(pixel++) = (unsigned char) (255 * rgb.Luminance()); break; case 2: *(pixel++) = (unsigned char) (255 * rgb.Luminance()); *(pixel++) = (unsigned char) 255; break; case 3: *(pixel++) = (unsigned char) (255 * rgb.R()); *(pixel++) = (unsigned char) (255 * rgb.G()); *(pixel++) = (unsigned char) (255 * rgb.B()); break; case 4: *(pixel++) = (unsigned char) (255 * rgb.R()); *(pixel++) = (unsigned char) (255 * rgb.G()); *(pixel++) = (unsigned char) (255 * rgb.B()); *(pixel++) = (unsigned char) 255; break; } }
void GLUTRedraw(void) { // Check scene if (!scene) return; // Set viewing transformation viewer->Camera().Load(); // Clear window RNRgb background = scene->Background(); glClearColor(background.R(), background.G(), background.B(), 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Load lights LoadLights(scene); // Draw camera if (show_camera) { glDisable(GL_LIGHTING); glColor3d(1.0, 1.0, 1.0); glLineWidth(5); DrawCamera(scene); glLineWidth(1); } // Draw lights if (show_lights) { glDisable(GL_LIGHTING); glColor3d(1.0, 1.0, 1.0); glLineWidth(5); DrawLights(scene); glLineWidth(1); } // Draw rays if (show_rays) { glDisable(GL_LIGHTING); glColor3d(0.0, 1.0, 0.0); glLineWidth(3); DrawRays(scene); glLineWidth(1); } // Draw rays if (show_photons) { glDisable(GL_LIGHTING); glColor3d(1.0, 1.0, 1.0); glLineWidth(1); DrawPhotonPaths(scene); glLineWidth(1); } // Draw rays if (show_global_samples) { glDisable(GL_LIGHTING); glColor3d(1.0, 1.0, 1.0); glLineWidth(1); DrawGlobalSamples(scene); glLineWidth(1); } // Draw rays if (show_caustic_samples) { glDisable(GL_LIGHTING); glColor3d(1.0, 1.0, 1.0); glLineWidth(1); DrawCausticSamples(scene); glLineWidth(1); } // Draw scene nodes if (show_shapes) { glEnable(GL_LIGHTING); R3null_material.Draw(); DrawShapes(scene, scene->Root()); R3null_material.Draw(); } // Draw bboxes if (show_bboxes) { glDisable(GL_LIGHTING); glColor3d(1.0, 0.0, 0.0); DrawBBoxes(scene, scene->Root()); } // Draw frame time if (show_frame_rate) { char buffer[128]; static RNTime last_time; double frame_time = last_time.Elapsed(); last_time.Read(); if ((frame_time > 0) && (frame_time < 10)) { glDisable(GL_LIGHTING); glColor3d(1.0, 1.0, 1.0); sprintf(buffer, "%.1f fps", 1.0 / frame_time); DrawText(R2Point(100, 100), buffer); } } // Capture screenshot image if (screenshot_image_name) { if (print_verbose) printf("Creating image %s\n", screenshot_image_name); R2Image image(GLUTwindow_width, GLUTwindow_height, 3); image.Capture(); image.Write(screenshot_image_name); screenshot_image_name = NULL; } // Swap buffers glutSwapBuffers(); }