📄 test_sphere.c
字号:
/********** **********//**** * can_event_proc(window, event, arg) * * Handles canvas events. * ****/staticvoidcan_event_proc(window, event, arg)Xv_Window window;Event *event;Notify_arg arg;{ int width, height; switch(event_action(event)) { case ACTION_MENU: if (event_is_down(event)) { menu_show(menu_main, window, event, NULL); } break; default: break; }}staticvoidresize_proc(canvas, w, h)Canvas canvas;int w, h;{ xgl_window_raster_resize(ras, w, h);}/********** **********//********** Routines to Handle Application Menu Selections **********//********** **********//**** * clear_proc() * * Calls Xgl to clear canvas (raster). * ****/staticvoidclear_proc(){ Xgl_hlhsr_mode hlhsr; Xgl_hlhsr_data hlhsr_data; Xgl_pt_f3d max_coords; xgl_object_get(cctx, XGL_3D_CTX_HLHSR_MODE, &hlhsr); if (hlhsr == XGL_HLHSR_ZBUFFER) { xgl_object_get(ras, XGL_DEV_MAXIMUM_COORDINATES, &max_coords); hlhsr_data.z_buffer.z_value = max_coords.z; xgl_object_set(cctx, XGL_3D_CTX_HLHSR_DATA, &hlhsr_data, 0); } xgl_context_new_frame(cctx);}/**** * redraw_proc() * * Calls Xgl to redraw canvas (raster). * ****/staticvoidredraw_proc(){ int i, eye, eye_z; Xgl_pt_f3d vpn; Xgl_geom_normal geom_normal; Xgl_boolean last = FALSE, clip_calc_done = FALSE; if (data_ok) { time_elapsed = 0.0;#ifdef TRI_PERF tri_pixel_count = 0;#endif xgl_context_new_frame(cctx); for (eye = num_spheres; eye > 0; eye--) { /* cycle thru many spheres */ eye_z = 1 << (eye + 1); p_eye_position_pt.z = -((float)eye_z);/* if ((eye > 2) && !clip_calc_done) */ { clip_calc_proc(); clip_calc_done = TRUE; } vpn.x = p_eye_look_at_pt.x - p_eye_position_pt.x; vpn.y = p_eye_look_at_pt.y - p_eye_position_pt.y; vpn.z = p_eye_look_at_pt.z - p_eye_position_pt.z; xgli_set_3d_view(&p_eye_position_pt, &vpn, &p_eye_up_vector, &p_eye_perspective, p_eye_view_mat); xgl_transform_write(view_trans, p_eye_view_mat); p_eye_new_view = FALSE; START_TIMER(&t_start); switch (fct_type) { case XGL_FACET_NONE: case XGL_FACET_COLOR: for (for_i = 0; for_i < num_pl; for_i++) { /* each octant has different geom normal */ if((for_i % 9) == 0) { if((for_i % 18) == 0) last = !last; if((for_i % 36) == 0) last = !last; if (last) geom_normal = XGL_GEOM_NORMAL_LAST_POINTS; else geom_normal = XGL_GEOM_NORMAL_FIRST_POINTS; xgl_object_set(cctx, XGL_3D_CTX_SURF_GEOM_NORMAL, geom_normal, 0); last = !last; } xgl_triangle_strip(cctx, &fct_list[for_i], &pl[for_i]); } break; case XGL_FACET_NORMAL: for (for_i = 0; for_i < num_pl; for_i++) { xgl_triangle_strip(cctx, &fct_list[for_i], &pl[for_i]); } break; case XGL_FACET_COLOR_NORMAL: for (for_i = 0; for_i < num_pl; for_i++) { xgl_triangle_strip(cctx, &fct_list[for_i], &pl[for_i]); } break; } for (i = 0; i < num_txt; i++) { xgl_stroke_text_3d(cctx, texts[i].str, &(texts[i].pos), texts[i].dir); } STOP_TIMER(&t_end); time_elapsed += ELAPSED_SECONDS(&t_start, &t_end); } time_display_proc(); }}/**** * quit_proc() * * Catches when "quit" is selected from the menu, and closes XGL * ****/staticNotify_valuequit_proc(frame, status) Frame frame;Destroy_status status;{ if (status == DESTROY_CHECKING) xgl_close(sys_state); return(notify_next_destroy_func(frame, status));}/**** * quit_on_signal() * * Catches keyboard interrupt (^C), and closes XGL nicely before exiting. * ****/staticvoidquit_on_signal(){ xgl_close(sys_state); exit(0);}/**** * front_no_shading_proc() * * Calls Xgl to change front surface shading type to none. * ****/staticvoidfront_no_shading_proc(){ /* use facet shading on front-facing facets */ xgl_object_set(cctx, XGL_3D_CTX_SURF_FRONT_ILLUMINATION, XGL_ILLUM_NONE, 0);}/**** * front_facet_shading_proc() * * Calls Xgl to change front surface shading type to facet. * ****/staticvoidfront_facet_shading_proc(){ /* use facet shading on front-facing facets */ xgl_object_set(cctx, XGL_3D_CTX_SURF_FRONT_ILLUMINATION, XGL_ILLUM_PER_FACET, 0);}/**** * front_gouraud_shading_proc() * * Calls Xgl to change front surface shading type to Gouraud. * ****/staticvoidfront_gouraud_shading_proc(){ /* use vertex shading on front-facing facets */ xgl_object_set(cctx, XGL_3D_CTX_SURF_FRONT_ILLUMINATION, XGL_ILLUM_PER_VERTEX, 0);}/**** * back_no_shading_proc() * * Calls Xgl to change back surface shading type to none. * ****/staticvoidback_no_shading_proc(){ /* use facet shading on back-facing facets */ xgl_object_set(cctx, XGL_3D_CTX_SURF_BACK_ILLUMINATION, XGL_ILLUM_NONE, 0);}/**** * back_facet_shading_proc() * * Calls Xgl to change back surface shading type to facet. * ****/staticvoidback_facet_shading_proc(){ /* use facet shading on back-facing facets */ xgl_object_set(cctx, XGL_3D_CTX_SURF_BACK_ILLUMINATION, XGL_ILLUM_PER_FACET, 0);}/**** * back_gouraud_shading_proc() * * Calls Xgl to change back surface shading type to Gouraud. * ****/staticvoidback_gouraud_shading_proc(){ /* use vertex shading on back-facing facets */ xgl_object_set(cctx, XGL_3D_CTX_SURF_BACK_ILLUMINATION, XGL_ILLUM_PER_VERTEX, 0);}/**** * edges_proc() * * Calls Xgl to turn edges on or off. * ****/staticvoidedges_proc(menu, menu_item) Menu menu; Menu_item menu_item;{ static char *on_or_off; on_or_off = (char *)menu_get(menu_item, MENU_STRING); switch (on_or_off[1]) { case 'n': /* edges on */ case 'N': xgl_object_set(cctx, XGL_CTX_SURF_EDGE_FLAG, TRUE, 0); break; case 'f': /* edges off */ case 'F': default: xgl_object_set(cctx, XGL_CTX_SURF_EDGE_FLAG, FALSE, 0); break; }}/**** * zbuff_proc() * * Calls Xgl to turn Z-buffering ON and OFF * ****/staticvoidzbuff_proc(menu, menu_item) Menu menu; Menu_item menu_item;{ static char *on_or_off; on_or_off = (char *)menu_get(menu_item, MENU_STRING); switch (on_or_off[1]) { case 'n': /* Zbuffer on */ case 'N': xgl_object_set(cctx, XGL_3D_CTX_HLHSR_MODE, XGL_HLHSR_ZBUFFER, XGL_CTX_NEW_FRAME_ACTION, XGL_CTX_NEW_FRAME_CLEAR | XGL_CTX_NEW_FRAME_HLHSR_ACTION, 0); break; case 'f': /* Zbuffer off */ case 'F': default: xgl_object_set(cctx, XGL_3D_CTX_HLHSR_MODE, XGL_HLHSR_NONE, XGL_CTX_NEW_FRAME_ACTION, XGL_CTX_NEW_FRAME_CLEAR, 0); break; }}/**** * face_proc() * * Calls Xgl to turn face culling off, front or back * ****/staticvoidface_proc(menu, menu_item) Menu menu; Menu_item menu_item;{ static char *on_or_off; static Xgl_surf_cull_mode mode; on_or_off = (char *)menu_get(menu_item, MENU_STRING); switch (on_or_off[0]) { case 'F': case 'f': mode = XGL_CULL_FRONT; break; case 'B': case 'b': mode = XGL_CULL_BACK; break; case 'O': case 'o': default: mode = XGL_CULL_OFF; break; } xgl_object_set(cctx, XGL_3D_CTX_SURF_FACE_CULL, mode, 0);}/**** * disting_proc() * * Calls Xgl to turn face distinguishing off or on * ****/staticvoiddisting_proc(menu, menu_item) Menu menu; Menu_item menu_item;{ static char *on_or_off; static Xgl_boolean mode; on_or_off = (char *)menu_get(menu_item, MENU_STRING); switch (on_or_off[0]) { case 'T': case 't': mode = TRUE; break; case 'F': case 'f': default: mode = FALSE; break; } xgl_object_set(cctx, XGL_3D_CTX_SURF_FACE_DISTINGUISH, mode, 0);}/**** * norm_flip_proc() * * Calls Xgl to turn normal flipping off or on * ****/staticvoidnorm_flip_proc(menu, menu_item) Menu menu; Menu_item menu_item;{ static char *on_or_off; static Xgl_boolean mode; on_or_off = (char *)menu_get(menu_item, MENU_STRING); switch (on_or_off[0]) { case 'T': case 't': mode = TRUE; break; case 'F': case 'f': default: mode = FALSE; break; } xgl_object_set(cctx, XGL_3D_CTX_SURF_NORMAL_FLIP, mode, 0);}/**** * num_spheres_proc() * * Changes number of spheres drawn. * ****/staticvoidnum_spheres_proc(menu, menu_item) Menu menu; Menu_item menu_item;{ static char *asc_num_spheres; /* get number of spheres from menu */ asc_num_spheres = (char *)menu_get(menu_item, MENU_STRING); /* convert to integer and store in global */ num_spheres = atoi(asc_num_spheres);}time_display_proc(){ int i, tri_count = 0; float x; for (i = 0; i < num_pl; i++) tri_count += pl[i].num_pts - 2; x = (float)num_spheres * (float)tri_count; sprintf(tris_count_str, "Count: %10.1f", x); sprintf(timestr, "Time: %9.3f sec", time_elapsed); sprintf(tris_per_sec, "Tris/Sec: %10.1f", (float)(x / time_elapsed));#ifdef TRI_PERF sprintf(tri_area, "Av Tri Area: %10.1f", (float)tri_pixel_count/x);#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -