int main( int argc, char **argv )
{
	//printf("%d\n",win_width);
	//printf("%d\n",win_height);
	// Parse the arguments
	if (argc < 2) {
		printf("Missing arguments ... use:\n");
		return -1;
	}

	set_up_chess();
	step_max = atoi(argv[1]); // maximum level of recursions

	// Optional arguments
	for(int i = 2; i < argc; i++)
	{
		if (strcmp(argv[i], "+s") == 0)	shadow_on = 1;
		else if (strcmp(argv[i], "+l")==0) reflect_on = 1;
		else if (strcmp(argv[i], "+c")==0) board_on = 1;
		else if (strcmp(argv[i], "+r")==0) refract_on = 1;
		else if (strcmp(argv[i], "+p")==0) antialias_on = 1;
		else if (strcmp(argv[i], "+f")==0) diffuse_reflection_on = 1;
	}
	if(board_on) {
		pl.height = -3;
		pl.reflectance = 0.4;
		pl.mat_ambient = vec3(0, 0, 0);
		pl.mat_diffuse1 = vec3(4, 4, 4);
		pl.mat_diffuse2 = vec3(0.0, 0.0, 0.0);
		pl.mat_specular = vec3(1.0, 1.0, 1.0);
		pl.shineness = 10;
		
	}

	//
	// ray trace the scene now
	//
	// we have used so many global variables and this function is
	// happy to carry no parameters
	//
	printf("Rendering scene using my fantastic ray tracer ...\n");
	ray_trace();
	printf("ray tracing ended\n");

	// we want to make sure that intensity values are normalized
	histogram_normalization();

	// Show the result in glut via texture mapping
	glutInit( &argc, argv );
	glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
	glutInitWindowSize( WIN_WIDTH, WIN_HEIGHT );
	glutCreateWindow( "Ray tracing" );
	glewInit();
	init();

	glutDisplayFunc( display );
	glutKeyboardFunc( keyboard );
	glutMainLoop();
	return 0;
}
Esempio n. 2
0
/** Display callback; render the scene.
 */
void handle_display() {
    // The ray itself.
    ray3_t ray ;
    ray.base = eye ;

    color_t color ;

#ifndef NDEBUG
    clock_t start_time, end_time ;
    start_time = clock() ;
#endif
    for (int x=0; x<win_width; ++x) {
        for (int y=0; y<win_height; ++y) {
            win2world(x, y, &ray.dir) ;
            debug_c((x==400 && y==300),
                "view ray = {(%f, %f, %f), (%f, %f, %f)}.\n",
                eye.x, eye.y, eye.z, 
                ray.dir.x, ray.dir.y, ray.dir.z) ;
            color = ray_trace(ray, 1.0 + EPSILON, FLT_MAX, 5) ;
            *(fb+fb_offset(y, x, 0)) = color.red ;
            *(fb+fb_offset(y, x, 1)) = color.green ;
            *(fb+fb_offset(y, x, 2)) = color.blue ;
        }
    }
#ifndef NDEBUG
    end_time = clock() ;
    debug("handle_display(): frame calculation time = %f sec.",
            ((double)(end_time-start_time))/CLOCKS_PER_SEC) ;
#endif

    glWindowPos2s(0, 0) ;
    glDrawPixels(win_width, win_height, GL_RGB, GL_FLOAT, fb) ;
    glFlush() ;
    glutSwapBuffers() ;
}
void run(int w_start, int w_end, int h_start, int h_end, int *status, double *y, double *z)
{
    for (int h = h_start; h <= h_end; h++) {
        for (int w = w_start; w <= w_end; w++) {
            int k = h * C_RESOLUTION_WIDTH + w;
            ray_trace(w, h, status + k, y + k, z + k);
        }
    }
}