/* * Recompute viewport line-limits for forward/backward scrolling */ static void forward(RING * gbl, int n) { TRACE(("forward %d\n", n)); setup_view(gbl); while (n-- > 0) { if ((vue->last_file + 1) < gbl->numfiles) { vue->base_file = vue->last_file + 1; setup_view(gbl); } else break; } }
/* * Instructions on using this program: * * 'H' - hardware viewing and perspective transforms * 'O' - orthographic projection mode * 'P' - perspective projection mode * 'I' - reset to original setup * * In each mode, pressing the 'l', 'k', 'w' keys * makes the transformation in the 'forward' direction, * pressing 'h', 'j', 's' makes the transformation in the * 'reverse' direction. You are required to implement this * functionality. Look at the kbd() function to see how * the various functions are called. * */ void kbd(unsigned char key, int x, int y) { switch(key) { case 'q': /* quit */ case 27 : glutDestroyWindow(wd); exit (0); case 'I': /* reset */ cam = Camera(eye_pos0, gaze_dir0, top_dir0, zNear0, zFar0, fovy0); resetWorld(mode); setup_view(mode); transformWorld(mode); // TODO do the transform, including perspective transform in objects.cpp fprintf(stderr, "Reset!\n"); break; case 'H': mode = HARDWARE; init_viewcam(mode); reshape(screen_w, screen_h); fprintf(stderr, "Hardware transforms\n"); break; case 'O': mode = ORTHOGRAPHIC; init_viewcam(mode); reshape(screen_w, screen_h); fprintf(stderr, "Orthographic mode\n"); break; case 'P': mode = PERSPECTIVE; init_viewcam(mode); reshape(screen_w, screen_h); fprintf(stderr, "Perspective mode\n"); break; default: movecam(key, x, y); // TODO in transfomrs.cpp setup_view(mode); // TODO set up the viewing transformation in transforms.cpp transformWorld(mode); // TODO do the transform, including perspective transform in objects.cpp break; } glutPostRedisplay(); return; }
void downLINE(RING * gbl, unsigned n) { gbl->curfile += n; if (gbl->curfile >= gbl->numfiles) gbl->curfile = gbl->numfiles - 1; if (gbl->curfile > vue->last_file) { unsigned savebase = vue->base_file; while (gbl->curfile > vue->last_file && (vue->last_file + 1) < gbl->numfiles) { vue->base_file += 1; setup_view(gbl); } #if defined(HAVE_WSCRL) && defined(HAVE_WSETSCRREG) if (vue->base_file > savebase && setscrreg((int) vue->base_row + 1, (int) vue->last_row - 1) != ERR) { scrl((int) (vue->base_file - savebase)); setscrreg(0, LINES - 1); } #endif showFILES(gbl, FALSE); } else showC(gbl); }
void bgfx_chain_entry::submit(int view, render_primitive* prim, texture_manager& textures, uint16_t screen_count, uint16_t screen_width, uint16_t screen_height, float screen_scale_x, float screen_scale_y, float screen_offset_x, float screen_offset_y, uint32_t rotation_type, bool swap_xy, uint64_t blend, int32_t screen) { bgfx::setViewSeq(view, true); if (!setup_view(view, screen_width, screen_height, screen)) { return; } for (bgfx_input_pair* input : m_inputs) { input->bind(m_effect, screen); } bgfx::TransientVertexBuffer buffer; put_screen_buffer(prim, &buffer); bgfx::setVertexBuffer(&buffer); setup_auto_uniforms(prim, textures, screen_count, screen_width, screen_height, screen_scale_x, screen_scale_y, screen_offset_x, screen_offset_y, rotation_type, swap_xy, screen); for (bgfx_entry_uniform* uniform : m_uniforms) { if (uniform->name() != "s_tex") { uniform->bind(); } } m_effect->submit(view, blend); if (m_targets.target(screen, m_output) != nullptr) { m_targets.target(screen, m_output)->page_flip(); } }
/* * Move the cursor up/down the specified number of lines, scrolling * to a new screen if necessary. */ void upLINE(RING * gbl, unsigned n) { if (gbl->curfile < n) gbl->curfile = 0; else gbl->curfile -= n; if (gbl->curfile < vue->base_file) { unsigned savebase = vue->base_file; while (gbl->curfile < vue->base_file && vue->base_file > 0) { vue->base_file -= 1; setup_view(gbl); } #if defined(HAVE_WSCRL) && defined(HAVE_WSETSCRREG) if (vue->base_file < savebase && setscrreg((int) vue->base_row + 1, (int) vue->last_row - 1) != ERR) { scrl((int) (vue->base_file - savebase)); setscrreg(0, LINES - 1); } #endif showFILES(gbl, FALSE); } else { showC(gbl); } }
void init(void) { mode = MOVECAM; object = TORUS; sphere_radius = INITRAD; /* Initial camera location and orientation */ eye_pos0 = XVec4f(2.0, 3.0, 6.0, 1.0); gaze_dir0 = XVec4f(-2.0, -3.0, -6.1, 0.0); // c = (0,0,0); g = c - e top_dir0 = XVec4f(0.0, 1.0, 0.0, 0.0); zNear0 = -0.1; zFar0 = -25.0; fovy0 = 27.0; cam = Camera(eye_pos0, gaze_dir0, top_dir0, zNear0, zFar0, fovy0); glClearColor(0.0, 0.0, 0.0, 1.0); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glGetDoublev(GL_TEXTURE_MATRIX, cmodview); init_properties(); /* YOUR CODE HERE . . . * Initialize your lights: some needs to be positioned * before viewing transform, others after. */ //initialize eye light //glLightfv(lightname,param,value) glLightfv(EYELIGHT, GL_SPOT_DIRECTION, eyelight_position); glLightfv(EYELIGHT, GL_POSITION, eyelight_position); setup_view(); // in viewing.cpp glLightfv(SUNLIGHT, GL_POSITION, sunlight_position); glLightfv(OBJLIGHT, GL_POSITION, objlight_position); /* . . . AND/OR HERE */ //initialize sun light glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* YOUR CODE HERE - enable various other pieces of OpenGL state * 1. Depth test, so that OpenGL has a sense of depth (Cf. glEnable()) * 2. Automatic normalization of normals (Cf. glEnable()) * 3. Back face culling (Cf. glEnable()) * 4. Smooth shading of polygons (Cf. glShadeModel()) * 5. Filled rendering of polygons (Cf. glPolygonMode()) */ glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); glShadeModel(GL_SMOOTH); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glColor4f(0.0, 0.0, 1.0, 0.4); initWorld(); // TODO in objects.cpp return; }
static void backward(RING * gbl, int n) { TRACE(("backward %d\n", n)); setup_view(gbl); while (n-- > 0) { if (vue->base_file > 0) { unsigned delta = (vue->last_row - vue->base_row - 1); if (vue->base_file < delta) vue->base_file = 0; else vue->base_file -= delta; setup_view(gbl); } else break; } }
static void change_view() { /* Change the view */ setup_view( (float)disp_crnt_view_x, (float)disp_crnt_view_y, DFLT_VIEW_DIST, disp_crnt_zoom, 0 ) ; /* And redraw */ display_scene( disp_fill_mode, disp_patch_switch, disp_mesh_switch, disp_interaction_switch, 0 ) ; }
/* * Mouse behaviour: * drag left/right: pan * drag up/down: tilt */ void motion(int x, int y) { movecam(MOUSE_DRAG, (x - mouse_x), (y - mouse_y)); /* TODO in transforms.cpp */ setup_view(mode); // TODO set up the viewing transformation in transforms.cpp transformWorld(mode); // TODO do the transform, including perspective transform in objects.cpp mouse_x = x; mouse_y = y; glutPostRedisplay(); /* Refresh screen after changes */ return; }
/* * Display all files in the current viewport */ static void show_view(RING * gbl) { unsigned j; setup_view(gbl); for (j = vue->base_file; j <= vue->last_file; j++) show_line(vue, j); for (j = (unsigned) file2row(vue->last_file + 1); j < vue->last_row; j++) { move((int) j, 0); clrtoeol(); } }
/* Draw the world with the latest transformations */ void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glGetDoublev(GL_TEXTURE_MATRIX, cmodview); setup_view(); drawAxes(screen_w, screen_h, 1.0); // draw world axes in eye space glMultMatrixd(cmodview); drawWorld(screen_w, screen_h); /* Force display */ glutSwapBuffers(); return; }
void init_viewcam(transform_t mode) { eye_pos0 = XVec4f(0.0, 0.0, 1000, 1.0); // {100, 50, 250, 1.0}; gaze_dir0 = XVec4f(0.0, 0.0, -1.0, 0.0); // along -z-axis top_dir0 = XVec4f(0.0, 1.0, 0.0, 0.0); zNear0 = -300.0; // z-coordinate of the near plane, negative number zFar0 = -5000.0; // = infinity fovy0 = 105.0; cam = Camera(eye_pos0, gaze_dir0, top_dir0, zNear0, zFar0, fovy0); // last 2 args not used setup_view(mode); transformWorld(mode); // TODO do the transform, including perspective transform in objects.cpp return; }
int do_load_desktop (Desktop * d, char *filename) { int f; if ((f = open (filename, O_RDONLY)) >= 0) { int i, x = 40, y = 40; char *sign; sign = strread (f); if (strcmp (sign, "stereo\n - saved desktop\n\n")) { close (f); Cerrordialogue (CMain, 20, 20, " Load Desktop ", \ " This is not a desktop file "); free (sign); return 1; } free (sign); for (i = 0; i < d->num_views; i++) destroy_view (&(d->view[i])); clear (d, Desktop); read (f, d, sizeof (Desktop)); destroy ((void *) &d->cal_points); d->cal_points = Cmalloc (d->num_cal_points * sizeof (Vec)); read (f, d->cal_points, d->num_cal_points * sizeof (Vec)); d->cal_file = strread (f); d->temp_dir = strread (f); d->image_dir = strread (f); if (d->num_views) for (i = 0; i < d->num_views; i++) { char *v; v = strread (f); if (v) { setup_view (d, v, x += 20, y += 20, i); d->view[i].filename = v; } } draw_markers (d); close (f); return 0; } else { Cerrordialogue (CMain, 20, 20, " Load Desktop ", \ get_sys_error (" Error trying to save file. ")); } return 1; }
/* * Scroll, as needed, to put current-file in the window */ int to_file(RING * gbl) { int code; TRACE(("to_file %d in %s\n", gbl->curfile, gbl->new_wd)); setup_view(gbl); code = !FILE_VISIBLE(vue, gbl->curfile); while (gbl->curfile > vue->last_file) forward(gbl, 1); while (gbl->curfile < vue->base_file) backward(gbl, 1); TRACE(("...done to_file:%d\n", code)); return (code); }
/* * Mouse behaviour: * drag left/right: pan * drag up/down: tilt */ void motion(int x, int y) { if (mode == MOVECAM) { movecam(MOUSE_DRAG, (x - mouse_x), (y - mouse_y)); // in viewing.cpp setup_view(); // set up the viewing transformation in viewing.cpp /* YOUR CODE HERE . . . * Same as within movecam(). */ glMultMatrixd(cmodview); // play back all modeling transforms /* . . . AND/OR HERE */ mouse_x = x; mouse_y = y; glutPostRedisplay(); /* Refresh screen after changes */ } return; }
void create_romBrowser() { GtkWidget* menu; GtkWidget* submenu; GtkWidget* item; australia = gdk_pixbuf_new_from_file(get_iconpath("australia.png"), NULL); europe = gdk_pixbuf_new_from_file(get_iconpath("europe.png"), NULL); france = gdk_pixbuf_new_from_file(get_iconpath("france.png"), NULL); germany = gdk_pixbuf_new_from_file(get_iconpath("germany.png"), NULL); italy = gdk_pixbuf_new_from_file(get_iconpath("italy.png"), NULL); japan = gdk_pixbuf_new_from_file(get_iconpath("japan.png"), NULL); spain = gdk_pixbuf_new_from_file(get_iconpath("spain.png"), NULL); usa = gdk_pixbuf_new_from_file(get_iconpath("usa.png"), NULL); japanusa = gdk_pixbuf_new_from_file(get_iconpath("japanusa.png"), NULL); n64cart = gdk_pixbuf_new_from_file(get_iconpath("16x16/mupen64cart.png"), NULL); /* Setup rombrowser column names. g_MainWindow.column_names[column][0] is the translated column header. g_MainWindow.column_names[column][1] toggles visability in the config system. */ snprintf(g_MainWindow.column_names[0][0], 128, tr("Country")); snprintf(g_MainWindow.column_names[0][1], 128, "ColumnCountryVisible"); snprintf(g_MainWindow.column_names[1][0], 128, tr("Good Name")); snprintf(g_MainWindow.column_names[1][1], 128, "ColumnGoodNameVisible"); snprintf(g_MainWindow.column_names[2][0], 128, tr("Status")); snprintf(g_MainWindow.column_names[2][1], 128, "ColumnStatusVisible"); snprintf(g_MainWindow.column_names[3][0], 128, tr("User Comments")); snprintf(g_MainWindow.column_names[3][1], 128, "ColumnUserCommentsVisible"); snprintf(g_MainWindow.column_names[4][0], 128, tr("File Name")); snprintf(g_MainWindow.column_names[4][1], 128, "ColumnFileNameVisible"); snprintf(g_MainWindow.column_names[5][0], 128, tr("MD5 Hash")); snprintf(g_MainWindow.column_names[5][1], 128, "ColumnMD5HashVisible"); snprintf(g_MainWindow.column_names[6][0], 128, tr("CRC1")); snprintf(g_MainWindow.column_names[6][1], 128, "ColumnCRC1Visible"); snprintf(g_MainWindow.column_names[7][0], 128, tr("CRC2")); snprintf(g_MainWindow.column_names[7][1], 128, "ColumnCRC2Visible"); snprintf(g_MainWindow.column_names[8][0], 128, tr("Internal Name")); snprintf(g_MainWindow.column_names[8][1], 128, "ColumnInternalNameVisible"); snprintf(g_MainWindow.column_names[9][0], 128, tr("Save Types")); snprintf(g_MainWindow.column_names[9][1], 128, "ColumnSaveTypeVisible"); snprintf(g_MainWindow.column_names[10][0], 128, tr("Players")); snprintf(g_MainWindow.column_names[10][1], 128, "ColumnPlayersVisible"); snprintf(g_MainWindow.column_names[11][0], 128, tr("Size")); snprintf(g_MainWindow.column_names[11][1], 128, "ColumnSizeVisible"); snprintf(g_MainWindow.column_names[12][0], 128, tr("Compression")); snprintf(g_MainWindow.column_names[12][1], 128, "ColumnCompressionVisible"); snprintf(g_MainWindow.column_names[13][0], 128, tr("Image Type")); snprintf(g_MainWindow.column_names[13][1], 128, "ColumnImageTypeVisible"); snprintf(g_MainWindow.column_names[14][0], 128, tr("CIC Chip")); snprintf(g_MainWindow.column_names[14][1], 128, "ColumnCICChipVisible"); snprintf(g_MainWindow.column_names[15][0], 128, tr("Rumble")); snprintf(g_MainWindow.column_names[15][1], 128, "ColumnRumbleVisible"); /* Setup rombrowser tree views. */ g_MainWindow.romFullList = gtk_tree_view_new(); g_MainWindow.romDisplay = gtk_tree_view_new(); /* Multiple selections needed due to the way we clear the TreeViews. */ GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_MainWindow.romFullList)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_MainWindow.romDisplay)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); /* Initialize TreeViews - i.e. setup column info. models */ setup_view(g_MainWindow.romFullList); setup_view(g_MainWindow.romDisplay); g_MainWindow.romScrolledWindow = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(g_MainWindow.romScrolledWindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); /* Add the Display TreeView into our scrolled window. */ gtk_container_add(GTK_CONTAINER(g_MainWindow.romScrolledWindow), g_MainWindow.romDisplay); gtk_container_add(GTK_CONTAINER(g_MainWindow.toplevelVBox), g_MainWindow.romScrolledWindow); gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(g_MainWindow.romDisplay), TRUE); gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(g_MainWindow.romDisplay), TRUE); gtk_tree_view_set_reorderable(GTK_TREE_VIEW(g_MainWindow.romDisplay), FALSE); /* Open on double click. */ g_signal_connect(g_MainWindow.romDisplay, "row-activated", G_CALLBACK(callback_play_rom), NULL); /* Setup right-click menu. */ menu = gtk_menu_new(); g_MainWindow.playRomItem = gtk_image_menu_item_new_with_label(tr("Play Rom")); g_MainWindow.playRombrowserImage = gtk_image_new(); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(g_MainWindow.playRomItem), g_MainWindow.playRombrowserImage); g_signal_connect(g_MainWindow.playRomItem, "activate", G_CALLBACK(callback_play_rom), NULL); gtk_menu_shell_append(GTK_MENU_SHELL(menu), g_MainWindow.playRomItem); g_MainWindow.romPropertiesItem = gtk_image_menu_item_new_with_label(tr("Rom Properties")); g_MainWindow.propertiesRombrowserImage = gtk_image_new(); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(g_MainWindow.romPropertiesItem), g_MainWindow.propertiesRombrowserImage); g_signal_connect(g_MainWindow.romPropertiesItem, "activate", G_CALLBACK(callback_rom_properties), NULL); gtk_menu_shell_append(GTK_MENU_SHELL(menu), g_MainWindow.romPropertiesItem); gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new()); item = gtk_image_menu_item_new_with_label(tr("Refresh")); g_MainWindow.refreshRombrowserImage = gtk_image_new(); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), g_MainWindow.refreshRombrowserImage); g_signal_connect(item, "activate", G_CALLBACK(callback_call_rcs), NULL); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); item = gtk_menu_item_new_with_label(tr("Configure Rombrowser")); g_signal_connect(item, "activate", G_CALLBACK(callback_configure_rombrowser), NULL); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new()); submenu = gtk_image_menu_item_new_with_label(tr("Configure Columns")); gtk_menu_item_set_submenu(GTK_MENU_ITEM(submenu), g_MainWindow.romHeaderMenu); gtk_menu_shell_append(GTK_MENU_SHELL(menu), submenu); gtk_widget_show_all(menu); g_signal_connect(g_MainWindow.romDisplay, "button-press-event", G_CALLBACK(callback_rombrowser_context), (gpointer)menu); }
int main(int argc, char *argv[]) { long i; long total_rad_time, max_rad_time, min_rad_time; long total_refine_time, max_refine_time, min_refine_time; long total_wait_time, max_wait_time, min_wait_time; long total_vertex_time, max_vertex_time, min_vertex_time; /* Parse arguments */ parse_args(argc, argv) ; choices[2].init_value = model_selector ; /* Initialize graphic device */ if( batch_mode == 0 ) { g_init(argc, argv) ; setup_view( DFLT_VIEW_ROT_X, DFLT_VIEW_ROT_Y, DFLT_VIEW_DIST, DFLT_VIEW_ZOOM,0 ) ; } /* Initialize ANL macro */ MAIN_INITENV(,60000000) ; THREAD_INIT_FREE(); /* Allocate global shared memory and initialize */ global = (Global *) G_MALLOC(sizeof(Global)) ; if( global == 0 ) { printf( "Can't allocate memory\n" ) ; exit(1) ; } init_global(0) ; timing = (Timing **) G_MALLOC(n_processors * sizeof(Timing *)); for (i = 0; i < n_processors; i++) timing[i] = (Timing *) G_MALLOC(sizeof(Timing)); /* Initialize shared lock */ init_sharedlock(0) ; /* Initial random testing rays array for visibility test. */ init_visibility_module(0) ; /* POSSIBLE ENHANCEMENT: Here is where one might distribute the sobj_struct, task_struct, and vis_struct data structures across physically distributed memories as desired. One way to place data is as follows: long i; for (i=0;i<n_processors;i++) { Place all addresses x such that &(sobj_struct[i]) <= x < &(sobj_struct[i+1]) on node i Place all addresses x such that &(task_struct[i]) <= x < &(task_struct[i+1]) on node i Place all addresses x such that &(vis_struct[i]) <= x < &(vis_struct[i+1]) on node i } */ if( batch_mode ) { /* In batch mode, create child processes and start immediately */ /* Time stamp */ CLOCK( time_rad_start ); global->index = 0; for( i = 0 ; i < n_processors ; i++ ) { taskqueue_id[i] = assign_taskq(0) ; } /* And start processing */ CREATE(radiosity, n_processors); WAIT_FOR_END(n_processors); /* Time stamp */ CLOCK( time_rad_end ); /* Print out running time */ printf("TIMING STATISTICS MEASURED BY MAIN PROCESS:\n"); print_running_time(0); if (dostats) { printf("\n\n\nPER-PROCESS STATISTICS:\n"); printf("%8s%20s%20s%12s%12s\n","Proc","Total","Refine","Wait","Smooth"); printf("%8s%20s%20s%12s%12s\n\n","","Time","Time","Time","Time"); for (i = 0; i < n_processors; i++) printf("%8ld%20lu%20lu%12lu%12lu\n",i,timing[i]->rad_time, timing[i]->refine_time, timing[i]->wait_time, timing[i]->vertex_time); total_rad_time = timing[0]->rad_time; max_rad_time = timing[0]->rad_time; min_rad_time = timing[0]->rad_time; total_refine_time = timing[0]->refine_time; max_refine_time = timing[0]->refine_time; min_refine_time = timing[0]->refine_time; total_wait_time = timing[0]->wait_time; max_wait_time = timing[0]->wait_time; min_wait_time = timing[0]->wait_time; total_vertex_time = timing[0]->vertex_time; max_vertex_time = timing[0]->vertex_time; min_vertex_time = timing[0]->vertex_time; for (i = 1; i < n_processors; i++) { total_rad_time += timing[i]->rad_time; if (timing[i]->rad_time > max_rad_time) max_rad_time = timing[i]->rad_time; if (timing[i]->rad_time < min_rad_time) min_rad_time = timing[i]->rad_time; total_refine_time += timing[i]->refine_time; if (timing[i]->refine_time > max_refine_time) max_refine_time = timing[i]->refine_time; if (timing[i]->refine_time < min_refine_time) min_refine_time = timing[i]->refine_time; total_wait_time += timing[i]->wait_time; if (timing[i]->wait_time > max_wait_time) max_wait_time = timing[i]->wait_time; if (timing[i]->wait_time < min_wait_time) min_wait_time = timing[i]->wait_time; total_vertex_time += timing[i]->vertex_time; if (timing[i]->vertex_time > max_vertex_time) max_vertex_time = timing[i]->vertex_time; if (timing[i]->vertex_time < min_vertex_time) min_vertex_time = timing[i]->vertex_time; } printf("\n\n%8s%20lu%20lu%12lu%12lu\n","Max", max_rad_time, max_refine_time, max_wait_time, max_vertex_time); printf("\n%8s%20lu%20lu%12lu%12lu\n","Min", min_rad_time, min_refine_time, min_wait_time, min_vertex_time); printf("\n%8s%20lu%20lu%12lu%12lu\n","Avg", (long) (((double) total_rad_time) / ((double) (1.0 * n_processors))), (long) (((double) total_refine_time) / ((double) (1.0 * n_processors))), (long) (((double) total_wait_time) / ((double) (1.0 * n_processors))), (long) (((double) total_vertex_time) / ((double) (1.0 * n_processors)))); printf("\n\n"); } /* print_fork_time(0) ; */ print_statistics( stdout, 0 ) ; } else { /* In interactive mode, start workers, and the master starts notification loop */ /* Start notification loop */ g_start( expose_callback, N_SLIDERS, sliders, N_CHOICES, choices ) ; } MAIN_END; exit(0) ; }
int main(int argc, char *argv[]) { const char* chunkfile = "crater/crater.chu"; const char* texturefile = "crater/crater.jpg"; // Process command-line args. int file_arg_index = 0; for (int i = 1; i < argc; i++) { switch (argv[i][0]) { case '-': { switch (argv[i][1]) { case 0: default: printf("error: unknown switch '%s'\n\n", argv[i]); print_usage(); exit(1); break; case 'w': // window width. i++; if (i >= argc) { printf("error: -w switch must be followed by a window width (in pixels)\n\n"); print_usage(); exit(1); } window_width = atoi(argv[i]); // bounds checking here? break; case 'h': // window height. i++; if (i >= argc) { printf("error: -h switch must be followed by a window height (in pixels)\n\n"); print_usage(); exit(1); } window_height = atoi(argv[i]); // bounds checking here? break; case 'b': // bits per pixel i++; if (i >= argc) { printf("error: -b switch must be followed by the desired window bits per pixel\n\n"); print_usage(); exit(1); } bits_per_pixel = atoi(argv[i]); break; case 'f': // fullscreen flag. fullscreen = true; break; case 't': // background loader thread flag. i++; if (i >= argc) { printf("error: -t switch must be followed by 0 or 1\n\n"); print_usage(); exit(1); } s_use_loader_thread = atoi(argv[i]) ? true : false; case '2': // two-pass flag s_two_phase_render = true; break; } break; } default: { // file args. if (file_arg_index == 0) { chunkfile = argv[i]; file_arg_index++; } else if (file_arg_index == 1) { texturefile = argv[i]; file_arg_index++; } else { printf("error: too many args, starting with '%s'.\n\n", argv[i]); print_usage(); exit(1); } break; } } } // Print out program info. print_usage(); // Initialize the SDL subsystems we're using. if (SDL_Init(SDL_INIT_VIDEO /* | SDL_INIT_JOYSTICK | SDL_INIT_CDROM | SDL_INIT_AUDIO*/)) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); // Get current display info. const SDL_VideoInfo* info = NULL; info = SDL_GetVideoInfo(); if (!info) { fprintf(stderr, "SDL_GetVideoInfo() failed."); exit(1); } if (bits_per_pixel == 0) { // Take the default desktop depth. //bits_per_pixel = info->vfmt->BitsPerPixel; } int flags = SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0); int component_depth = 0; int z_depth = 32; if (bits_per_pixel > 0 && bits_per_pixel <= 16) { component_depth = 5; z_depth = 16; } else if (bits_per_pixel <= 32) { component_depth = 8; z_depth = 24; } else { component_depth = bits_per_pixel / 4; // Assume the user knows what they're trying to do. } SDL_GL_SetAttribute( SDL_GL_RED_SIZE, component_depth ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, component_depth ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, component_depth ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, z_depth ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // Set the video mode. if (SDL_SetVideoMode(window_width, window_height, bits_per_pixel, flags) == 0) { fprintf(stderr, "SDL_SetVideoMode() failed."); exit(1); } // Initialize the engine's opengl subsystem (loads extensions if possible). ogl::open(); printf("Window: %d x %d x %d\n", window_width, window_height, bits_per_pixel); // Load a texture or a texture-quadtree object. tqt* texture_quadtree = NULL; // Does it look like a .tqt file? if (tqt::is_tqt_file(texturefile)) { texture_quadtree = new tqt(texturefile); } if (texture_quadtree == NULL) { // // No texture quadtree; try to load the texture arg as an ordinary texture. // //SDL_Surface* texture = IMG_Load(texturefile); image::rgb* texture = image::read_jpeg(texturefile); if (texture) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, ogl::get_clamp_mode()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, ogl::get_clamp_mode()); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture->m_width, texture->m_height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->m_data); // Build mips. int level = 1; while (texture->m_width > 1 || texture->m_height > 1) { image::make_next_miplevel(texture); glTexImage2D(GL_TEXTURE_2D, level, GL_RGB, texture->m_width, texture->m_height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->m_data); level++; } // SDL_FreeSurface(texture); delete texture; glBindTexture(GL_TEXTURE_2D, 1); } } glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // GL_MODULATE // Sometimes (under Win32) for debugging it's better to not catch // exceptions. //#define CATCH_EXCEPTIONS #ifdef CATCH_EXCEPTIONS try #endif // CATCH_EXCEPTIONS { // Load our chunked model. tu_file* in = new tu_file(chunkfile, "rb"); if (in->get_error()) { printf("Can't open '%s'\n", chunkfile); exit(1); } lod_chunk_tree* model = new lod_chunk_tree(in, texture_quadtree); vec3 center, extent; model->get_bounding_box(¢er, &extent); // Initialize viewpoint: middle of the bounding box in // the x-z plane, top of the box plus a little in the y axis. viewer_pos = center; viewer_pos.y += extent.y + 10.f; // Enable vertex array, and just leave it on. glEnableClientState(GL_VERTEX_ARRAY); s_view.m_frame_number = 1; if (texture_quadtree == NULL) { // Set up automatic texture-coordinate generation. // Basically we're just stretching the current texture // over the entire model. float xsize = extent.get_x() * 2; float zsize = extent.get_z() * 2; glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); float p[4] = { 0, 0, 0, 0 }; p[0] = 1.0f / xsize; glTexGenfv(GL_S, GL_OBJECT_PLANE, p); p[0] = 0; glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); p[2] = 1.0f / zsize; glTexGenfv(GL_T, GL_OBJECT_PLANE, p); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); } // Main loop. Uint32 last_ticks = SDL_GetTicks(); for (;;) { Uint32 ticks = SDL_GetTicks(); int delta_ticks = ticks - last_ticks; float delta_t = delta_ticks / 1000.f; last_ticks = ticks; process_events(); if ( move_forward ) { // Drift the viewpoint forward. viewer_pos += viewer_dir * delta_t * (float) (1 << speed) * 0.50f; } model->set_use_loader_thread(s_use_loader_thread); model->set_parameters(max_pixel_error, max_texel_size, (float) window_width, horizontal_fov_degrees); if (enable_update) { model->update(viewer_pos); } clear(); float midz = farz; if (s_two_phase_render) { // Draw the far part of the terrain, then clear the z-buffer before // drawing the near part. Helps (a lot!) w/ z-buffer precision. midz = sqrt(nearz * farz); setup_view(midz * 0.9f, farz); // must overlap at the boundary; otherwise there can be cracks. frame_triangle_count += model->render(s_view, render_opt); glClear(GL_DEPTH_BUFFER_BIT); } setup_view(nearz, midz); frame_triangle_count += model->render(s_view, render_opt); SDL_GL_SwapBuffers(); s_view.m_frame_number++; // Performance counting. if (measure_performance) { frame_count ++; total_triangle_count += frame_triangle_count; performance_timer += delta_ticks; // See if one second has elapsed. if (performance_timer > 1000) { // Print out stats for the previous second. float fps = frame_count / (performance_timer / 1000.f); float tps = total_triangle_count / (performance_timer / 1000.f); printf("fps = %3.1f : tri/s = %3.2fM : tri/frame = %2.3fM\n", fps, tps / 1000000.f, frame_triangle_count / 1000000.f); total_triangle_count = 0; performance_timer = 0; frame_count = 0; } frame_triangle_count = 0; } } delete model; model = NULL; if (texture_quadtree) { delete texture_quadtree; texture_quadtree = NULL; } delete in; in = NULL; } #ifdef CATCH_EXCEPTIONS catch (const char* message) { printf("run-time exception: %s\n", message); exit(1); } catch (...) { printf("run-time exception: unknown type\n"); exit(1); } #endif // CATCH_EXCEPTIONS return 0; }
/* * Instructions on using this program: * * 'I' - reset to original * '0' - toggle drawing torus or sphere * 'L' - toggle lights on/off * '1' - toggle sun light on/off * '2' - toggle eye light on/off * '3' - toggle object light on/off * 'CTRL' - turns on ROTATION mode * 'ALT' - turns on TRANSLATION mode * 'M' - magnify sphere radius * 'm' - minify sphere radius * * In each mode, pressing the 'l', 'k', 'w' keys * makes the transformation in the 'forward' direction, * pressing 'h', 'j', 's' makes the transformation in the * 'reverse' direction. You are required to implement this * functionality. Look at the kbd() function to see how * the various functions are called. * */ void kbd(unsigned char key, int x, int y) { int mod=0; /* Get info about Alt, Ctrl, Shift modifier keys */ mod = glutGetModifiers(); if (mod & GLUT_ACTIVE_ALT) { mode = TRANSLATION; } else if (mod & GLUT_ACTIVE_CTRL) { key += 'a'-1; mode = ROTATION; } switch(key) { case 'q': /* quit */ case 27 : glutDestroyWindow(wd); exit (0); case 'I': /* reset */ sphere_radius = INITRAD; cam = Camera(eye_pos0, gaze_dir0, top_dir0, zNear0, zFar0, fovy0); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glGetDoublev(GL_TEXTURE_MATRIX, cmodview); setup_view(); // in viewing.cpp glLightfv(SUNLIGHT, GL_POSITION, sunlight_position); glLightfv(OBJLIGHT, GL_POSITION, objlight_position); fprintf(stderr, "Reset!\n"); break; case '0': object = (object == TORUS) ? SPHERE : TORUS; break; case '1': sunlight_on = 1 - sunlight_on; if (sunlight_on) { glEnable(SUNLIGHT); } else { glDisable(SUNLIGHT); } printf("\tsun light %s\n", sunlight_on ? "on" : "off"); break; case '2': eyelight_on = 1 - eyelight_on; if (eyelight_on) { glEnable(EYELIGHT); } else { glDisable(EYELIGHT); } printf("\teye light %s\n", eyelight_on ? "on" : "off"); break; case '3': objlight_on = 1 - objlight_on; if (objlight_on) { glEnable(OBJLIGHT); } else { glDisable(OBJLIGHT); } printf("\tobj light %s\n", objlight_on ? "on" : "off"); break; case 'M': sphere_radius *= MAGFAC; printf("Sphere radius magnified to %.3f\n", sphere_radius); break; case 'm': sphere_radius *= MINFAC; printf("Sphere radius minified to %.3f\n", sphere_radius); break; default: /* Setup the modelview matrix for modeling transform or * the camera coordinate system for viewing transform. */ switch (mode) { case ROTATION: rotate(key, x, y); // in modeling.cpp break; case TRANSLATION: translate(key, x, y); // in modeling.cpp break; case MOVECAM: movecam(key, x, y); // in viewing.cpp break; default: break; } break; } /* YOUR CODE HERE . . . * After transformations, you want to adjust some or all of your lights. * Again, you may need to reposition some lights after every transformation, * others only if the camera is moved, or some others may never need to be * moved at all. */ glLightfv(OBJLIGHT, GL_POSITION, objlight_position); if (mode == MOVECAM) { setup_view(); // in viewing.cpp /* . . . AND/OR HERE . . . */ glLightfv(SUNLIGHT, GL_POSITION, sunlight_position); glMultMatrixd(cmodview); // play back all modeling transforms } /* . . . AND/OR HERE */ if ((mod & GLUT_ACTIVE_ALT) | (mod & GLUT_ACTIVE_CTRL)) { mode = MOVECAM; } glutPostRedisplay(); return; }