⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_sphere.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
#ifndef lintstatic char sccsid[] = "@(#)test_sphere.c 1.1 92/07/30 Copyr 1989, 1990 Sun Micro";#endif#include <stdio.h>#include <math.h>#include <signal.h>#include <sys/time.h>#include <xgl/xgl.h>#include "WS_macros.h"#include "XGL.icon"/**** *	Sun Microsystems, Inc. *	Graphics Products Division * *	Date:		July 14, 1989 *	Revised:	September 7, 1989 * *  *	Module Name:	test_sphere.c * *	Synopsis:	Test program for Xgl triangle strips.  Some of *			code borrowed from program test_3d.c.  This program  *			uses the triangle strip data file (.tri suffix) * *			NOTE: The format of triangle strip data files is *			      slightly different than the format of polygonal *			      data files (i.e. the ".pg" format). * ****//* * routines included */		/* setup routines */static	void		xgl_init();static	void		create_menus();		/* data handling routines */static	void		get_data();static	void		render_point_type_proc();static	void		render_facet_type_proc();static	void		clip_calc_proc();		/* event handlers */static	void		can_event_proc();		/* menu selection handlers */static	void		clear_proc();static	void		redraw_proc();static	void		front_no_shading_proc();static	void		front_facet_shading_proc();static	void		front_gouraud_shading_proc();static	void		back_no_shading_proc();static	void		back_facet_shading_proc();static	void		back_gouraud_shading_proc();static	void		edges_proc();static	void		face_proc();static	void		disting_proc();static	void		norm_flip_proc();static	void		zbuff_proc();static	void		num_spheres_proc();static  Notify_value    quit_proc();static	void		quit_on_signal();/* * macros used for timing */#define START_TIMER(x)	(void)gettimeofday(x, (struct timezone *) 0)#define STOP_TIMER(x)	(void)gettimeofday(x, (struct timezone *) 0)#define ELAPSED_SECONDS(x,y) ( ((y)->tv_sec - (x)->tv_sec) + \			       ((y)->tv_usec - (x)->tv_usec)*1e-6)/* * global variables */typedef struct {  char		*str;  Xgl_pt_f3d	pos;  Xgl_pt_f3d	dir[2];} text_info;static	Xgl_facet_type			fct_type = XGL_FACET_NORMAL;static	Xgl_boolean			p_eye_new_view;static	Xgl_matrix_f3d			p_eye_view_mat;static	Xgl_pt_f3d			p_eye_perspective;static	Xgl_pt_f3d			p_eye_position_pt;static	Xgl_pt_f3d			p_eye_look_at_pt;static	Xgl_pt_f3d			p_eye_up_vector;static	Menu				menu_main;static	Menu				menu_front_shading;static	Menu				menu_back_shading;static	Menu				menu_edges;static	Menu				menu_zbuff;static	Menu				menu_face;static	Menu				menu_disting;static	Menu				menu_norm_flip;static	Menu				menu_spheres;static	Xgl_ras				ras;static	Xgl_3d_ctx			cctx;static	Xgl_trans			view_trans;static	Xgl_light			light[4];static	Xgl_boolean			light_switch[4];static	Xgl_pt_f3d			light_dir;	/* lighting vector */static	Xgl_pt_list			*pl;static	Xgl_sgn32			*p_ind, *f_ind;static  Xgl_bbox			*l_bbox;static 	Xgl_pt_flag_f3d			*pts;static 	Xgl_pt_normal_flag_f3d		*pts_n;static 	Xgl_pt_color_normal_flag_f3d	*pts_nc;static	Xgl_color_normal_facet		*fct_nc;static	Xgl_usgn32			num_pl;static  Xgl_bbox			pl_bbox, *bbox_pl;static	Xgl_boolean			data_ok;static	Xgl_usgn32			num_txt;static	text_info			*texts;static	Xgl_sgn32			txt_index, box_index, pts_index,					pl_index, fct_index;static	Xgl_sgn32			for_i;static	Xgl_color_facet			*fcts_color;static	Xgl_normal_facet		*fcts_normal;static	Xgl_facet_list			*fct_list;static	Xgl_bounds_f3d			vdc;static	Xgl_bounds_f3d			bound;static	Xgl_sgn32			num_spheres;static	float				bgnd_r, bgnd_g, bgnd_b;#ifdef	TRI_PERF	Xgl_sgn32			tri_row_count,					tri_pixel_count;static  char				tri_area[256];#endifstatic	char				timestr[256];static  char				tris_per_sec[256];static  char				tris_count_str[256];static	struct timeval    		t_start, t_end;static	double              		time_elapsed = 0.0;static  Xgl_sys_state    		sys_state;static	Frame				frame;/**** * * main * ****/main(argc, argv)    int			argc;    char		*argv[];{				/* output file */    static char		*default_file_name = "sphere_i.tri";    static char		*file_name;    FILE		*file_pt, *fopen();    int			i;    int			status;    Canvas		canvas;				/* defaults */    file_name = default_file_name;	/* data file */    vdc.xmin  = bound.xmin = -1.0;	/* vdc window bounds */    vdc.xmax  = bound.xmax =  1.0;    vdc.ymin  = bound.ymin = -1.0;    vdc.ymax  = bound.ymax =  1.0;    num_spheres = 1;			/* # of spheres to render */    bgnd_r = 0.0;			/* background color components */    bgnd_g = 0.0;    bgnd_b = 0.6;/*  bgnd_r = 0.21; */			/* patrick's favorites *//*  bgnd_g = 0.31; *//*  bgnd_b = 0.24; */    light_dir.x = 1.0;    light_dir.y = -1.0;    light_dir.z = 1.0;				/* initialize */    texts	= (text_info *)0;    pts		= (Xgl_pt_flag_f3d *)0;    pts_n	= (Xgl_pt_normal_flag_f3d *)0;    pl		= (Xgl_pt_list *)0;    fct_list	= (Xgl_facet_list *)0;    p_ind	= (int *)0;    f_ind	= (int *)0;    l_bbox	= (Xgl_bbox *)0;    pts_nc	= (Xgl_pt_color_normal_flag_f3d *)0;    fct_nc	= (Xgl_color_normal_facet *)0;				/* read command line args */    for (i = 1; i < argc; i++) {	if (*argv[i] != '-') {	    printf ("ERROR: All arguments must start with -\n");	    printf ("Use  %s -h  for help\n", argv[0]);	    exit (0);	}	switch (argv[i][1])	{	    case 'b':		/* clip bounds */	    case 'B':		bound.xmin = atof(argv[++i]);		bound.xmax = atof(argv[++i]);		bound.ymin = atof(argv[++i]);		bound.ymax = atof(argv[++i]);		break;	    case 'c':		/* canvas background color */	    case 'C':		bgnd_r = atof(argv[++i]);		bgnd_g = atof(argv[++i]);		bgnd_b = atof(argv[++i]);		break;	    case 'f':		/* output filename */	    case 'F':		file_name = argv[++i];		break;	    case 'l':		/* light vector */	    case 'L':		light_dir.x = atof(argv[++i]);		light_dir.y = atof(argv[++i]);		light_dir.z = atof(argv[++i]);		break;	    case 'n':		/* number of spheres to render */	    case 'N':		num_spheres = atof(argv[++i]);		break;	    case 'v':		/* vdc window */	    case 'V':		vdc.xmin = atof(argv[++i]);		vdc.xmax = atof(argv[++i]);		vdc.ymin = atof(argv[++i]);		vdc.ymax = atof(argv[++i]);		break;	    case 'h':		/* help */	    case 'H':	    case '?':		printf ("\ntest_sphere: Xgl test program for triangle strips\n");		printf ("Invoke with : %s [args]\n\n", argv[0]);		printf ("\t[args] allowed:\n");		printf ("\t   -f file              where file = input filename\n");		printf ("\t                        default: images/sphere_i.tri\n");		printf ("\t   -b xmin xmax ymin ymax\n");		printf ("\t                        where xmin, etc. = clip bounds\n");		printf ("\t                        default: -1 1 -1 1\n");		printf ("\t   -c r g b             where r,g,b = background color\n");		printf ("\t                        default: 0.21 0.31 0.24\n");		printf ("\t   -l x y z             where x, y, z = light vector\n");		printf ("\t                        default: 1 -1 1\n");		printf ("\t   -n num               where num = number of spheres\n");		printf ("\t                        default: 1 sphere rendered\n");		printf ("\t   -v xmin xmax ymin ymax\n");		printf ("\t                        where xmin, etc. = vdc bounds\n");		printf ("\t                        default: -1 1 -1 1\n");		printf ("\t   -h                   prints this message\n\n");		exit(0);	    default:		/* bad argument */		printf ("WARNING: Unknown command line argument used.\n");		printf ("         \"-%c\"  is unknown.  Continuing execution.\n", argv[i][1]);		i++;		break;	}    }    (void)xv_init(XV_INIT_ARGS, argc, argv, 0);    xgl_icon = icon_create(ICON_IMAGE, &icon_pixrect, 0);    frame = xv_create(NULL,  FRAME, 		WIN_DYNAMIC_VISUAL, TRUE,		FRAME_ICON,	xgl_icon,		FRAME_LABEL,  "Xgl Spheres",		WIN_WIDTH, 	600, 		WIN_HEIGHT, 	500, 		WIN_SHOW, TRUE,		0);    (void) notify_interpose_destroy_func(frame, quit_proc);    sprintf(tris_count_str, "Count: %10.1f", 0.);    sprintf(timestr, "Time: %9.3f sec", time_elapsed);    strcpy(tris_per_sec, "Tris/Sec: NA");#ifdef	TRI_PERF    strcpy(tri_area, "Av Tri Area: NA");#endif    canvas = xv_create(frame, CANVAS, 		WIN_DYNAMIC_VISUAL, TRUE,		OPENWIN_AUTO_CLEAR, FALSE, 		CANVAS_RETAINED, FALSE, 		CANVAS_FIXED_IMAGE, FALSE,		0);    create_menus();    xgl_init(canvas);    get_data(file_name);    xv_main_loop(frame);} /* end of main() *//**********                                                **********//**********                  Setup Routines                **********//**********                                                **********//**** * xgl_init(canvas) * * Sets up color maps, creates raster, context, etc. * ****/staticvoidxgl_init(canvas)    Canvas		canvas;{       Xgl_cmap		cmap;    Xgl_color_list	clist;    Xgl_color		colors[128];    Xgl_color		color0, color63, color95, color96;    Xgl_sgn32		i;    Xgl_segment		segments[3];    sys_state = xgl_open(XGL_SYS_ST_ERROR_DETECTION, TRUE, 0);    (void) signal(SIGINT, quit_on_signal);    /* create color list */    clist.start_index = 0;    clist.length = 128;    colors[0].rgb.r = bgnd_r;	/* canvas background */    colors[0].rgb.g = bgnd_g;    colors[0].rgb.b = bgnd_b;    for (i = 1; i < 64; i++) {	/* front-facing facet ramp */        colors[i].rgb.r = colors[i].rgb.g = colors[i].rgb.b = ((float) i)/63.0;    }    for (i = 64; i < 96; i++) {	/* back-facing facet ramp */        colors[i].rgb.r = ((float)(i - 64))/32.;        colors[i].rgb.g = 0.0;        colors[i].rgb.b = 0.0;    }    colors[96].rgb.r = 0;   colors[96].rgb.g = 1.0; colors[96].rgb.b = 0;    colors[97].rgb.r = 0;   colors[97].rgb.g = 0;   colors[97].rgb.b = 1.0;    colors[98].rgb.r = 1.0; colors[98].rgb.g = 1.0; colors[98].rgb.b = 0;    colors[99].rgb.r = 1.0; colors[99].rgb.g = 0;   colors[99].rgb.b = 1.0;    for (i = 100; i < 128; i++) {        colors[i].rgb.r = 0.0;        colors[i].rgb.b = 0.0;        colors[i].rgb.g = ((float)(i - 100))/28.0;    }    colors[127].rgb.r = colors[127].rgb.g = colors[127].rgb.b = 0;    clist.colors = colors;    segments[0].offset = 1;    segments[0].length = 63;    segments[1].offset = 64;    segments[1].length = 32;    segments[2].offset = 100;    segments[2].length = 27;    INIT_X11_WG(frame, canvas, can_event_proc, redraw_proc, resize_proc)    ras = xgl_window_raster_device_create(XGL_WIN_X, &xgl_x_win, 0);    cmap = xgl_color_map_create(0);    xgl_object_set(cmap, XGL_CMAP_COLOR_TABLE_SIZE, 128,			XGL_CMAP_COLOR_TABLE, &clist, 			XGL_CMAP_RAMP_NUM, 3,			XGL_CMAP_RAMP_LIST, segments,			0);    xgl_object_set(ras, XGL_RAS_COLOR_MAP, cmap, 0);    cctx = xgl_3d_context_create(XGL_CTX_DEVICE, ras, 				XGL_CTX_VDC_MAP, XGL_VDC_MAP_ALL,                                 XGL_CTX_MARKER_DESCRIPTION, xgl_marker_dot,				XGL_CTX_SFONT_CHAR_HEIGHT, 0.1,				XGL_3D_CTX_SURF_FRONT_AMBIENT, 0.1, 				XGL_3D_CTX_SURF_BACK_AMBIENT, 0.1, 				XGL_3D_CTX_SURF_FRONT_DIFFUSE, 0.8, 				XGL_3D_CTX_SURF_BACK_DIFFUSE, 0.8, 				XGL_CTX_DEFERRAL_MODE, XGL_DEFER_ASAP,				0);    xgl_object_get(cctx, XGL_CTX_VIEW_TRANS, &view_trans);    color0.index = 0;    color63.index = 63;    color95.index = 95;    color96.index = 96;    xgl_object_set(cctx, XGL_CTX_LINE_COLOR, &color96,                         XGL_CTX_EDGE_COLOR, &color96,                         XGL_CTX_MARKER_COLOR, &color96,                         XGL_CTX_SFONT_TEXT_COLOR, &color96,                         XGL_CTX_LINE_ALT_COLOR, &color0,                         XGL_CTX_EDGE_ALT_COLOR, &color0,                         XGL_CTX_SURF_FRONT_COLOR, &color63,                         XGL_3D_CTX_SURF_BACK_COLOR, &color95,			 XGL_3D_CTX_SURF_FACE_DISTINGUISH, TRUE,                         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);    light_switch[0] = light_switch[1] = TRUE;    xgl_object_set(cctx, XGL_3D_CTX_LIGHT_NUM, 2, 			XGL_3D_CTX_LIGHT_SWITCHES, light_switch,			0);    xgl_object_get(cctx, XGL_3D_CTX_LIGHTS, light);    xgl_object_set(light[0], XGL_LIGHT_TYPE, XGL_LIGHT_AMBIENT, 			0);    xgl_object_set(light[1], XGL_LIGHT_TYPE, XGL_LIGHT_DIRECTIONAL,			XGL_LIGHT_DIRECTION, &light_dir,			0);    data_ok = FALSE;    fct_type = XGL_FACET_NORMAL;    p_eye_new_view = FALSE;}/**** * create_menus() * * Creates application menu and sub-menus. * ****/staticvoidcreate_menus(){					/* front_shading sub-menu */    menu_front_shading = xv_create(XV_NULL,MENU_COMMAND_MENU, 			MENU_ITEM,			MENU_STRING,	"No Shading",			MENU_NOTIFY_PROC, front_no_shading_proc,			0,			MENU_ITEM,			MENU_STRING,	"Facet Shading",			MENU_NOTIFY_PROC, front_facet_shading_proc,			0,			MENU_ITEM,			MENU_STRING,	"Vertex (Gouraud) Shading",			MENU_NOTIFY_PROC, front_gouraud_shading_proc,			0, 0);					/* bac_shading sub-menu */    menu_back_shading = xv_create(XV_NULL,MENU_COMMAND_MENU, 			MENU_ITEM,			MENU_STRING,	"No Shading",			MENU_NOTIFY_PROC, back_no_shading_proc,			0,			MENU_ITEM,			MENU_STRING,	"Facet Shading",			MENU_NOTIFY_PROC, back_facet_shading_proc,			0,			MENU_ITEM,			MENU_STRING,	"Vertex (Gouraud) Shading",			MENU_NOTIFY_PROC, back_gouraud_shading_proc,			0, 0);					/* edge-type sub-menu */    menu_edges = xv_create(XV_NULL,MENU_COMMAND_MENU, 			MENU_ITEM,			MENU_STRING,	"On",			MENU_NOTIFY_PROC, edges_proc,			0,			MENU_ITEM,			MENU_STRING,	"Off",			MENU_NOTIFY_PROC, edges_proc,			0, 0);    menu_zbuff = xv_create(XV_NULL,MENU_COMMAND_MENU, 			MENU_ITEM,			MENU_STRING,	"On",			MENU_NOTIFY_PROC, zbuff_proc,			0,			MENU_ITEM,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -