graphic.c 5.91 KB
#define MAIN
#include "graphic.h"

int debug = TRUE;
int en_su_subpix = TRUE; /* enable setup subpixel adjustment */
int en_texture = TRUE; /* enable texture mapping */
int en_tf_bilinear = TRUE; /* enable texture filter bilinear */
int en_tc_persp = TRUE;	/* enable texture coordinate perspective */
int en_antialias = TRUE; /* enable antialiasing */
int en_coverage = TRUE; /* enable coverage */
int en_bf_cull = TRUE; /* enable backface cull */
int en_tc_lod = TRUE; /* texture coordinate level of detail */
int en_mipmap = TRUE; /* texture mipmap */
int en_movie_loop = FALSE; /* enable recording movie loops */
int en_tramtile = FALSE; /* enable tram tiling */
int en_lighting = FALSE; /* enable lighting */
int en_powmul = TRUE; /* enable multiplys to generate x**n power */
int en_zbuffer = TRUE; /* enable z buffering stuff */
int en_divot = TRUE; /* enable divot suppression */
int en_line = FALSE; /* enable line drawing */
int render_mode = RENDER_OPAQUE;

float line_width = 1;	/* line width */
int bf_cull_sign = 0;	/* backface cull on xor pleq sign, 0 or -1 */
int sc_xmin, sc_xmax, sc_ymin, sc_ymax; /* scissor box */

int CombineMode = DEFAULT_COMBINE;
struct Tex_color PrimitiveColor   = {255, 255, 255, 255};
struct Tex_color EnvironmentColor = {255, 255, 255, 255};

int drdx,drdy;
int dgdx,dgdy;
int dbdx,dbdy;
int dadx,dady;
int dzdx,dzdy;
int draw_color = 0xffffff;
int zoom = 1;
float del_rotx = 17;
int movie_count = 10;
char *movie;
char default_file[] = "quad.i";
char *inputfile = default_file;
float pow_val = 80.0;
float fog_val = 0.0;

void
  print_usage(char *prog_name)
{
  printf("Usage: %s [options]\n", prog_name);
  printf("Options: \n");
  printf("\t-l \tdisable bi-linear texture filter\n");
  printf("\t-t \tdisable texture\n");
  printf("\t-p \tdisable texture perspective\n");
  printf("\t-s \tdisable setup subpixel adjustment\n");
  printf("\t-a \tdisable anti-alias\n");
  printf("\t-c \tdisable coverage\n");
  printf("\t-Z \tdisable Z-buffer\n");
  printf("\t-D \tdisable divot suppression\n");
  printf("\t-b \tdisable back-face cull\n");
  printf("\t-d \tdisable texture coordinate LOD\n");
  printf("\t-m \tdisable texture mip-map\n");
  printf("\t-P \tdisable power multiplier\n");
  printf("\t-T \tenable Tmem tiling\n");
  printf("\t-? \tprint usage\n");
  printf("\n");
  printf("\t-i <delta rot x>\n");
  printf("\t-k <power val>\n");
  printf("\t-B <back face cull sign>\n");
  printf("\t-z <zoom scale>\n");
  printf("\t-f <input file>\n");
  printf("\t-F <fog value>\n");
  printf("\t-w <line width> enable line drawing\n");
  printf("\t-M <movie name>\tenable movie\n");
  printf("\t-C <movie frame count>\n");
}


main( argc, argv)
int argc; char *argv[];
{
  char *prog_name = argv[0];

if(argc == 1)
{
  print_usage(prog_name);
  exit(0);
}

while (--argc) {
	if ((*++argv)[0] == '-') {
	switch ((*argv)[1]) {
	case 'i':       argc--; argv++;
			sscanf( *argv, "%f", &del_rotx); break;
	case 'k':	argc--; argv++;
	                sscanf(*argv, "%f", &pow_val);
                        break;
	case 'l':	en_tf_bilinear = FALSE; break;
	case 't':	en_texture = FALSE; 
			CombineMode = DISABLE_TEXTURE;
			break;
	case 'p':	en_tc_persp = FALSE; break;
	case 's':	en_su_subpix = FALSE; break;
	case 'a':	en_antialias = FALSE; break;
	case 'c':	en_coverage = FALSE; break;
	case 'Z':       en_zbuffer = FALSE; break;
	case 'D':	en_divot = FALSE; break;
	case 'b':	en_bf_cull = FALSE; break;
	case 'd':	en_tc_lod = FALSE; break;
	case 'm':	en_mipmap = FALSE; break;
	case 'w':	en_line = TRUE;
			argc--; argv++;
			sscanf( *argv, "%f", &line_width);	
			break;
	case 'P':	en_powmul = FALSE; break;
	case 'B':	argc--; argv++;
			sscanf( *argv, "%d", &bf_cull_sign);	
			if (bf_cull_sign < 0) bf_cull_sign = -1;
				else bf_cull_sign = 0; break;
	case 'z':	argc--; argv++;
			sscanf( *argv, "%d", &zoom);	
			break;
	case 'f':	argc--; argv++;
			inputfile = *argv;
			break;
	case 'F':	argc--; argv++;
	                sscanf(*argv, "%f", &fog_val);
                        break;
	case 'T':	en_tramtile = TRUE; break;
	case 'M':       argc--, argv++;
			movie = *argv;
			en_movie_loop = TRUE;
			break;
	case 'C':	argc--; argv++;
			sscanf( *argv, "%d", &movie_count);	
			break;
	case '?':	print_usage(prog_name);
			exit(0);
	}}}
	if (!en_tramtile || !en_tc_lod) en_mipmap = FALSE;

	open_file(inputfile);

	while (1)
		proccmds();
}
/*------------------------------------------*/
get_draw_color( color)
int *color;
{
*color = draw_color;
return( 1);
}
/*------------------------------------------*/
#ifdef 0
/* this hardwired texture now captured to file six.t */
struct Image *create_texture( op, x, y)
int op, x, y;
{
struct Image *im;
ubyte *py, *px;
int ix, iy, fx, fy;
int bgc = 0;
int fgc = 0xffffff;
int alp, alpy;
float pax, pay, dax, day;

	im = (struct Image *)malloc( sizeof(struct Image));
	im->xsize = x;
	im->ysize = y;
	im->lsize = x * 4;
	im->base = (ubyte *)malloc( im->ysize * im->lsize);

	if (en_antialias) bgc = 0x404040;
	fx = x / 8;
	fy = y / 8;
	py = im->base;
	pay = 0;
	day = (float)256/im->ysize;
	dax = (float)256/im->xsize;
for (iy=0; iy<im->ysize; iy++) {
	px = py - 4;
	py += im->lsize;
	pax = 0;
	alpy = (int)pay;
	pay += day;
for (ix=0; ix<im->xsize; ix++) {
	alp = (int)pax;
	pax += dax;
	alp = (alpy < alp) ? alpy : alp;
alp = 255 - (int)(pax * pay * (float)1.0/256);
	px += 4;
	*(int *)px = bgc | (alp << 24);
	if (iy < fy || iy > (fy * 7 )) continue;
	if (ix < fx || ix > (fx * 7 )) continue;
	if (iy > (fy * 2) && iy < (fy * 4) && ix > (fx * 2))
		continue;
	if (iy > (fy * 5) && iy < (fy * 6) &&
		ix > (fx * 2) && ix < (fx * 6)) continue;
	*(int *)px = fgc | (alp << 24);
	}
	}
return( im);
}

/*---------------------------------*/
show_image( im, x, y)
struct Image *im;
int x, y;
{
int ix, iy;
ubyte *px, *py;
int color;

	py = im->base;
for (iy=0; iy<im->ysize; iy++) {
	px = py;
	py += im->lsize;
for (ix=0; ix<im->xsize; ix++) {
	color = *(int *)px;
	put_pixel( ix+x, iy+y, color);
	px += 4;
	}
	}
}
/*---------------------------------*/
#endif