graphic.c
5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#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