static void child() { int i; dup2(gfd[0], 0); close(gfd[1]); gbuf = (char *)ri_mem_alloc(gwidth * gheight * 4); gmask = (char *)ri_mem_alloc(gwidth * gheight); for (i = 0; i < gwidth * gheight; i++) { gbuf[4 * i + 3] = 0; gbuf[4 * i + 2] = 152; gbuf[4 * i + 1] = 127; gbuf[4 * i + 0] = 127; gmask[i] = 1; } setup_glut(); }
int main() { /* Initialize GLUT state - glut will take any command line arguments that pertain to it or X Window - look at its documentation at http://reality.sgi.com/mjk/spec3/spec3.html */ setup_glut(); init_gl(); // initialize score current_score = 0; session_high_score = 0; init_imagery(); set_camera(); init_visualizer_speech(); /* Start Event Processing Engine */ glutMainLoop(); return 0; }
int main(int argc, char** argv) { printf("Initializing image.\n"); initializeImage(512, 512); printf("Configuring scene.\n"); Scene scene = configureScene(); printf("Loading camera.\n"); Camera eye = *scene.getCamera(); printf("Beginning render.\n"); /* Status message: indicate rendering mode. */ #ifdef _TRACE_MODE_INT_ONLY_ printf("Rendering in intersection-only mode.\n"); #elif defined(_TRACE_MODE_NO_AA_) printf("Rendering in shading-only mode (No AA).\n"); #else printf("Rendering in full mode (Shading + AA).\n"); printf("Using %d samples for antialiasing.\n", N_SAMPLES); #endif /************ Reduced functionality modes (part a & b) *************/ #if defined(_TRACE_MODE_INT_ONLY_) || defined(_TRACE_MODE_NO_AA_) int percentile = 0; for(int iy = 0; iy < ny; iy++){ for(int ix = 0; ix < nx; ix++){ Ray ray = eye.getRay(ix, iy); Intersection* hit = scene.intersect(ray, 0.0, HUGE); if(hit) #if defined(_TRACE_MODE_INT_ONLY_) colorPixel(image, ix, iy, Color(1.0f, 1.0f, 1.0f), 1.0f, nx, ny); #else colorPixel(image, ix, iy, scene.shade(ray, *hit, BACKGROUND), 2.2f, nx, ny); #endif } /* Rough estimate of percent progress. */ if((1.0 * iy)/(ny-1) >= 0.10*percentile && percentile <= 10){ printf("%d%%\n", percentile++ * 10); } } #else /********** Shading and anti-aliasing. (Default) (part c) ***********/ int percentile = 0; int one_dim_steps = sqrt(N_SAMPLES); float stepsize = 1.0f/one_dim_steps; for(int iy = 0; iy < ny; iy++){ for(int ix = 0; ix < nx; ix++){ Color sampleSum = BACKGROUND; /* Stratified sampling within pixel, with additional random jitter. */ for(int sy = 0; sy < one_dim_steps; sy++){ for(int sx = 0; sx < one_dim_steps; sx++){ float x, y, jx, jy; // Generate random jitter in [0, 1.0] jx = (float)rand()/(float)RAND_MAX; jy = (float)rand()/(float)RAND_MAX; // Work with a fixed stepsize, but add additional random factor in [0, 1.0] (s_ + j_) x = ix - 0.5f + (sx + jx) * stepsize; // -0.5 moves from center point to left boundary y = iy - 0.5f + (sy + jy) * stepsize; // -0.5 moves from center point to top boundary // Generate eye ray from the stratified/random position within pixel Ray r = eye.getRay(x, y); // Add to sum of sampled colors on hit, with baseline value equal to BACKGROUND Intersection *hit = scene.intersect(r, 0.0f, HUGE); if(hit) sampleSum += scene.shade(r, *hit, BACKGROUND); } } // Finally, color the pixel at (ix, iy) by the average sampled color, with gamma correction. colorPixel(image, ix, iy, sampleSum * (1.0f / (one_dim_steps*one_dim_steps)), 2.2f, nx, ny); } /* Rough estimate of percent progress. */ if((1.0 * iy)/(ny-1) >= 0.10*percentile && percentile <= 10){ printf("%d%%\n", percentile++ * 10); } } #endif // Configure GLUT for rendering via OpenGL setup_glut(argc, argv); return EXIT_SUCCESS; }