medit2c.c
18 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
/*
* Convert medit format files to C code for use by morphfaces program
*
* (c) 1995 Silicon Graphics
*
* Author: Bill Mark, August 1995
*
*
* Arrays and variables output into C program:
* 'code' Segment
* tricnt = # of triangles (for each image)
* trilist[3*tricnt] = indicies to verts for triangle ([t]...[t+2] = tri)
* vface1[tricnt*3*4] = (x,y,s,t) of verts for image #1
* ([v]=x,[v+1]=y,[v+2]=s,[v+3]=t).
* In the generated code it's actually an array
* Vtx vface1[tricnt*3].
* vface2[tricnt*3*4] = same for image #2
* tcoords1[tricnt][4] = sl,sh,tl,th for texture block loaded with tri.
* [0] = lows, [1] = lowt, [2] = highs, [3] = hight
* tcoords2[tricnt][4] = same for image #2
* tindex1[tricnt*3] = [t+0] = start index in texture[] for block
* [t+1] = width of the block
* [t+2] = height of the block
* tindex2[tricnt*3] = same for image #2
*
* 'static' Segment
* texture[] = array containing all texture block data
*
*/
#include <stdio.h>
/* Can increase these if too small -- sets triangle and vertex array sizes */
#define VMAX 600
#define TMAX 400
/* Maximum texture width and height */
/* These can't necessarily be changed without causing problems */
#define MAXTW 32
#define MAXTH 32
/*
* stmaxmin -- utility routine for buildit
*/
void stmaxmin(int v0, int v1, int v2, int *verts, int offset,
int *stmin, int *stmax) {
*stmin = verts[v0*4+offset];
*stmax = verts[v0*4+offset];
if (verts[v1*4+offset] > *stmax) {
*stmax = verts[v1*4+offset];
}
if (verts[v1*4+offset] < *stmin) {
*stmin = verts[v1*4+offset];
}
if (verts[v2*4+offset] > *stmax) {
*stmax = verts[v2*4+offset];
}
if (verts[v2*4+offset] < *stmin) {
*stmin = verts[v2*4+offset];
}
} /* stmaxmin */
/*
* buildit -- build arrays that will be later written to C output files
* mf = factor by which to multiply x and y coordinates
* Coordinates are centered around zero, then multiplied by mf
* The original coordinates were texel coordinates.
*/
void buildit(int *tris, int tricnt, int *verts,
char *i1, char *i2, int w, int h,
unsigned int texture[],
int *tasize, /* # of elements in texture[] */
int tindex1[], int tindex2[],
int tcoords1[][4], int tcoords2[][4],
int trilist[], int vface1[], int vface2[],
int mf) {
int t;
int v0, v1, v2;
int smin, smax, tmin, tmax;
int i,j;
int r,g,b;
int twidth, theight;
*tasize = 0; /* Reset to zero */
for (t=0; t<tricnt; t++) {
/* Vert indicies */
v0 = tris[t*3];
v1 = tris[t*3+1];
v2 = tris[t*3+2];
/* We don't share verts in the output, so each triangle gets three */
trilist[t*3+0] = t*3+0; /* v0 */
trilist[t*3+1] = t*3+1; /* v1 */
trilist[t*3+2] = t*3+2; /* v2 */
/*
* Put in vertex info (vface1, vface2)
*/
vface1[t*12+0+0] = (verts[v0*4+0]-w/2)*mf; /* v0, x, f1 */
vface1[t*12+0+1] = (h-1-verts[v0*4+1]-h/2)*mf; /* v0, y, f1 */
vface2[t*12+0+0] = (verts[v0*4+2]-w/2)*mf; /* v0, x, f2 */
vface2[t*12+0+1] = (h-1-verts[v0*4+3]-h/2)*mf; /* v0, y, f2 */
vface1[t*12+0+2] = verts[v0*4+0]; /* v0, s, f1 */
vface1[t*12+0+3] = verts[v0*4+1]; /* v0, t, f1 */
vface2[t*12+0+2] = verts[v0*4+2]; /* v0, s, f2 */
vface2[t*12+0+3] = verts[v0*4+3]; /* v0, t, f2 */
vface1[t*12+4+0] = (verts[v1*4+0]-w/2)*mf; /* v1, x, f1 */
vface1[t*12+4+1] = (h-1-verts[v1*4+1]-h/2)*mf; /* v1, y, f1 */
vface2[t*12+4+0] = (verts[v1*4+2]-w/2)*mf; /* v1, x, f2 */
vface2[t*12+4+1] = (h-1-verts[v1*4+3]-h/2)*mf; /* v1, y, f2 */
vface1[t*12+4+2] = verts[v1*4+0]; /* v1, s, f1 */
vface1[t*12+4+3] = verts[v1*4+1]; /* v1, t, f1 */
vface2[t*12+4+2] = verts[v1*4+2]; /* v1, s, f2 */
vface2[t*12+4+3] = verts[v1*4+3]; /* v1, t, f2 */
vface1[t*12+8+0] = (verts[v2*4+0]-w/2)*mf; /* v2, x, f1 */
vface1[t*12+8+1] = (h-1-verts[v2*4+1]-h/2)*mf; /* v2, y, f1 */
vface2[t*12+8+0] = (verts[v2*4+2]-w/2)*mf; /* v2, x, f2 */
vface2[t*12+8+1] = (h-1-verts[v2*4+3]-h/2)*mf; /* v2, y, f2 */
vface1[t*12+8+2] = verts[v2*4+0]; /* v2, s, f1 */
vface1[t*12+8+3] = verts[v2*4+1]; /* v2, t, f1 */
vface2[t*12+8+2] = verts[v2*4+2]; /* v2, s, f2 */
vface2[t*12+8+3] = verts[v2*4+3]; /* v2, t, f2 */
/*
* Image #1: Compute texture block location, and check size
*/
stmaxmin(v0, v1, v2, verts, 0, &smin, &smax);
stmaxmin(v0, v1, v2, verts, 1, &tmin, &tmax);
if ((smax - smin >= MAXTW) || (tmax - tmin) >= MAXTH) {
fprintf(stderr, "Triangle #%i, face #1 exceeds max texture size\n", t);
fprintf(stderr, "-> smax = %i, smin = %i, tmax = %i, tmin = %i\n",
smax,smin,tmax,tmin);
fprintf(stderr, "-> v0 = %i, v1 = %i, v2 = %i\n", v0, v1, v2);
exit(1);
}
/*
* Image #1: Texture coordinates for texture block
*/
twidth = smax-smin+1;
twidth = ((twidth+3)>>2) << 2; /* round up to nearest /4 */
smax = smin + twidth - 1;
theight = tmax-tmin+1;
tcoords1[t][0] = smin;
tcoords1[t][1] = tmin;
tcoords1[t][2] = smax;
tcoords1[t][3] = tmax;
/* Fill -- Do not swizzle here */
for (i=0; i<=(smax-smin); i++) {
for (j=0; j<=(tmax-tmin); j++) {
r = i1[((tmin+j)*w+smin+i)*3+0] & 0xff;
g = i1[((tmin+j)*w+smin+i)*3+1] & 0xff;
b = i1[((tmin+j)*w+smin+i)*3+2] & 0xff;
texture[(*tasize)+j*twidth+i] =
(r << 24) | (g << 16) | (b << 8) | 0xff;
}
}
tindex1[t*3+0] = *tasize;
tindex1[t*3+1] = twidth;
tindex1[t*3+2] = theight;
*tasize += theight*twidth;
/*
* Image #2: Compute texture block location, and check size
*/
stmaxmin(v0, v1, v2, verts, 2, &smin, &smax);
stmaxmin(v0, v1, v2, verts, 3, &tmin, &tmax);
if ((smax - smin >= MAXTW) || (tmax - tmin) >= MAXTH) {
fprintf(stderr, "Triangle #%i, face #2 exceeds max texture size\n", t);
fprintf(stderr, "-> smin = %i, smax = %i, tmin = %i, tmax = %i\n",
smin, smax, tmin, tmax);
fprintf(stderr, "-> v0 = %i, v1 = %i, v2 = %i\n",
v0, v1, v2);
exit(1);
}
/*
* Image #2: Texture coordinates for texture block
*/
twidth = smax-smin+1;
twidth = ((twidth+3)>>2) << 2; /* round up to nearest / 4*/
smax = smin + twidth - 1;
theight = tmax-tmin+1;
tcoords2[t][0] = smin;
tcoords2[t][1] = tmin;
tcoords2[t][2] = smax;
tcoords2[t][3] = tmax;
/* Fill -- Do not swizzle here */
for (i=0; i<=(smax-smin); i++) {
for (j=0; j<=(tmax-tmin); j++) {
r = i2[((tmin+j)*w+smin+i)*3+0] & 0xff;
g = i2[((tmin+j)*w+smin+i)*3+1] & 0xff;
b = i2[((tmin+j)*w+smin+i)*3+2] & 0xff;
texture[(*tasize)+j*twidth+i] =
(r << 24) | (g << 16) | (b << 8) | 0xff;
}
}
tindex2[t*3+0] = *tasize;
tindex2[t*3+1] = twidth;
tindex2[t*3+2] = theight;
*tasize += theight*twidth;
} /* for t */
} /* buildit */
/*
* writeit -- write the two C output files
*
* sfile = filename of 'static' segment C code
* cfile = filename of 'code' segment C code
* tricnt = # of entries in triangle array
* texture, tindex1, tindex2,
* tcoords1, tcoords2, trilist, vface1, vface2
* = arrays for C code
* tasize = size of texture[] array
* tris = original triangle verts; printed in comments
*/
void writeit(char *sfile, char *cfile,
int tricnt,
unsigned int texture[], int tasize, int tindex1[], int tindex2[],
int tcoords1[][4], int tcoords2[][4],
int trilist[], int vface1[], int vface2[],
int tris[]) {
int t, i;
FILE *fs;
FILE *fc;
/* open static output file */
fs = fopen(sfile, "w");
if (fs == NULL) {
fprintf(stderr, "Error opening sfile '%s' for output\n", sfile);
exit(1);
}
/*
* Write texture
*/
fprintf(fs, "/* Generated by medit2c ('static' segment) */\n"
"static u64 padder; /* Enforce alignment */\n"
"unsigned int texture[%i] = {\n ", tasize);
for (i=0; i<tasize; i++) {
fprintf(fs, "0x%x,", texture[i]);
if (i % 16 == 0) fprintf(fs, "\n ");
}
fprintf(fs, "\n};\n");
/*
* Close 'static' output file
*/
fclose(fs);
/*
* open 'code' output file
*/
fc = fopen(cfile, "w");
if (fc == NULL) {
fprintf(stderr, "Error opening cfile '%s' for output\n", cfile);
exit(1);
}
/*
* Write tricnt
*/
fprintf(fc, "/* generated by medit2c ('code' segment) */\n");
fprintf(fc, "int tricnt = %i;\n", tricnt);
/*
* Write trilist
*/
fprintf(fc, "int trilist[%i] = {\n", tricnt*3);
for (t = 0; t<tricnt; t++) {
fprintf(fc, " %i, %i, %i,\n",
trilist[t*3+0], trilist[t*3+1], trilist[t*3+2]);
} /* for t */
fprintf(fc, "\n};\n\n");
/*
* Write vface1
*/
fprintf(fc, "Vtx vface1[%i] = {\n", tricnt*3);
for (t = 0; t<tricnt; t++) {
fprintf(fc, " /* Verts for face #1, triangle #%i */\n", t);
fprintf(fc, " {%i,%i,0,0,%i,%i,0,0,0,0}, /* Orig vert #%i */\n",
vface1[t*12+0], vface1[t*12+1], vface1[t*12+2], vface1[t*12+3],
tris[t*3+0]);
fprintf(fc, " {%i,%i,0,0,%i,%i,0,0,0,0}, /* Orig vert #%i */\n",
vface1[t*12+4], vface1[t*12+5], vface1[t*12+6], vface1[t*12+7],
tris[t*3+1]);
fprintf(fc, " {%i,%i,0,0,%i,%i,0,0,0,0}, /* Orig vert #%i */\n",
vface1[t*12+8], vface1[t*12+9], vface1[t*12+10], vface1[t*12+11],
tris[t*3+2]);
} /* for t */
fprintf(fc, "\n};\n\n");
/*
* Write vface2
*/
fprintf(fc, "Vtx vface2[%i] = {\n", tricnt*3);
for (t=0; t<tricnt; t++) {
fprintf(fc, " /* Verts for face #2, triangle #%i */\n", t);
fprintf(fc, " {%i,%i,0,0,%i,%i,0,0,0,0}, /* Orig vert #%i */\n",
vface2[t*12+0], vface2[t*12+1], vface2[t*12+2], vface2[t*12+3],
tris[t*3+0]);
fprintf(fc, " {%i,%i,0,0,%i,%i,0,0,0,0}, /* Orig vert #%i */\n",
vface2[t*12+4], vface2[t*12+5], vface2[t*12+6], vface2[t*12+7],
tris[t*3+1]);
fprintf(fc, " {%i,%i,0,0,%i,%i,0,0,0,0}, /* Orig vert #%i */\n",
vface2[t*12+8], vface2[t*12+9], vface2[t*12+10], vface2[t*12+11],
tris[t*3+2]);
} /* for t */
fprintf(fc, "\n};\n\n");
/*
* Write tcoords1
*/
fprintf(fc, "int tcoords1[%i][4] = {\n", tricnt);
for (t=0; t<tricnt; t++) {
fprintf(fc, " {%i,%i,%i,%i}, /* Triangle #%i, Face #1 */\n",
tcoords1[t][0], tcoords1[t][1], tcoords1[t][2], tcoords1[t][3], t);
} /* for t */
fprintf(fc, "};\n\n");
/*
* Write tcoords2
*/
fprintf(fc, "int tcoords2[%i][4] = {\n", tricnt);
for (t=0; t<tricnt; t++) {
fprintf(fc, " {%i,%i,%i,%i}, /* Triangle #%i, Face #2 */\n",
tcoords2[t][0], tcoords2[t][1], tcoords2[t][2], tcoords2[t][3], t);
} /* for t */
fprintf(fc, "};\n\n");
/*
* Write tindex1
*/
fprintf(fc, "int tindex1[%i] = {\n", tricnt*3);
for (t = 0; t<tricnt; t++) {
fprintf(fc, " %i, %i, %i,\n",
tindex1[t*3+0], tindex1[t*3+1], tindex1[t*3+2]);
} /* for t */
fprintf(fc, "\n};\n\n");
/*
* Write tindex2
*/
fprintf(fc, "int tindex2[%i] = {\n", tricnt*3);
for (t = 0; t<tricnt; t++) {
fprintf(fc, " %i, %i, %i,\n",
tindex2[t*3+0], tindex2[t*3+1], tindex2[t*3+2]);
} /* for t */
fprintf(fc, "\n};\n\n");
/*
* Close 'code' file
*/
fclose(fc);
} /* writeit */
/*
* Read in a ppm file
*
* IN: filename = file to read it from
* OUT: width, height = width and height of image
* image = pointer to the image in memory
*/
void readppm(char *filename, int *width, int *height, char **image) {
FILE *f;
char buf[512];
int i;
/*
* Open the file
*/
f = fopen(filename, "r");
if (f == NULL) {
fprintf(stderr, "Error opening .ppm file '%s'\n", filename);
exit(1);
}
/*
* read in the ppm file header, currently only supports binary format,
* and assumes one and only one comment line.
*/
fgets(buf, 512, f); /* P6 */
while (1) {
fgets(buf, 512, f); /* # ..., or W H */
if (buf[0] != '#') break;
}
sscanf(buf," %i %i ",width,height);
fprintf(stderr, "Reading '%s', w=%i, h=%i\n", filename, *width, *height);
fgets(buf, 512, f); /* 256 */
/* now actually read in the texture data */
*image = (unsigned char *)calloc(*width**height,3);
fread(*image, 3, *width**height, f);
fclose(f);
} /* readppm */
/*
* rdvertfile -- Read in vertex file, set up verts[].
*/
void rdvertfile(char *vertfn, int *vertcnt, int *verts, int vmax,
int w, int h) {
FILE *f;
char buf[256];
int x1, y1, x2, y2;
f = fopen(vertfn, "r");
if (f == NULL) {
fprintf(stderr, "Error opening vertfile, '%s'\n", vertfn);
exit(1);
}
*vertcnt = 0;
while (fgets(buf, 256, f) != NULL) {
if (*vertcnt >= vmax) {
fprintf(stderr, "Exceeded vmax (%i)\n", *vertcnt); exit(1);}
sscanf(buf, " %i %i %i %i ", &x1, &y1, &x2, &y2);
if ((x1 < 0) || (x1 >= w) ||
(y1 < 0) || (y1 >= h) ||
(x2 < 0) || (x2 >= w) ||
(y2 < 0) || (y2 >= h)) {
fprintf(stderr, "Vertex #%i out of range\n", (*vertcnt)+1);
exit(1);
}
verts[*vertcnt*4+0] = x1;
verts[*vertcnt*4+1] = y1;
verts[*vertcnt*4+2] = x2;
verts[*vertcnt*4+3] = y2;
(*vertcnt)++;
}
fclose(f);
} /* rdvertfile */
/*
* rdtrifile -- Read in triangle file, set up tris[]
*/
void rdtrifile(char *trifn, int *tricnt, int *tris, int tmax,
int vertcnt) {
FILE *f;
char buf[256];
int v1, v2, v3;
f = fopen(trifn, "r");
if (f == NULL) {
fprintf(stderr, "Error opening trifile, '%s'\n", trifn);
exit(1);
}
*tricnt = 0;
while (fgets(buf, 256, f) != NULL) {
if (*tricnt >= tmax) {fprintf(stderr, "Exceeded tmax\n"); exit(1);}
sscanf(buf, " %i %i %i ", &v1, &v2, &v3);
if ((v1 < 0) || (v1 >= vertcnt) ||
(v2 < 0) || (v2 >= vertcnt) ||
(v3 < 0) || (v3 >= vertcnt)) {
fprintf(stderr, "Triangle %i uses out of range vertex\n", (*tricnt)+1);
exit(1);
}
tris[*tricnt*3+0] = v1;
tris[*tricnt*3+1] = v2;
tris[*tricnt*3+2] = v3;
(*tricnt)++;
}
fclose(f);
} /* rdtrifile */
/*
* parseoptions -- Parse command line options
* vfile = vertex input file (from medit)
* tfile = triangle input file (from medit)
* ifile = image #1 input file
* jfile = image #2 input file
* sfile = 'static' segment C code output file
* cfile = 'code' segment C code output file
*
*/
void parseoptions(int argc, char *argv[],
char **vfile, char **tfile, char **ifile, char **jfile,
char **sfile, char **cfile,
int *mf) {
extern char *optarg;
extern int optind;
int c;
*vfile = NULL;
*tfile = NULL;
*ifile = NULL;
*jfile = NULL;
*sfile = NULL;
*cfile = NULL;
*mf = 1; /* default */
while ((c = getopt(argc, argv, "hm:v:t:i:j:s:c:")) != EOF) {
switch (c) {
case 'h': /* help */
case '?':
default:
fprintf(stderr,
"usage: %s [-h] [-m mf] -v fn -t fn -i fn -j fn -s fn -c fn\n"
" -h = help\n"
" -m mf = set scale factor for x,y coords (def = 1)\n"
" -v fn = vertex input file from medit\n"
" -t fn = triangle input file from medit\n"
" -i fn = image input file #1 (.ppm format)\n"
" -j fn = image input file #2 (.ppm format)\n"
" -s fn = 'static' segment C code output file\n"
" -c fn = 'code' segment C code output file\n",
argv[0]);
exit(2);
case 'm':
*mf = atoi(optarg);
break;
case 'v':
*vfile = optarg;
break;
case 't':
*tfile = optarg;
break;
case 'i':
*ifile = optarg;
break;
case 'j':
*jfile = optarg;
break;
case 's':
*sfile = optarg;
break;
case 'c':
*cfile = optarg;
break;
} /* switch */
} /* while */
/*
* Check that all files were specified
*/
if ((*vfile == NULL) ||
(*tfile == NULL) ||
(*ifile == NULL) ||
(*jfile == NULL) ||
(*sfile == NULL) ||
(*cfile == NULL)
) {
fprintf(stderr, "** Need all 6 files specified, use -h for help\n");
exit(1);
}
} /* parseoptions */
/*
* main
*/
int main(int argc, char *argv[]) {
char *vfile; /* vertex input file */
char *tfile; /* triangle input file */
char *ifile; /* image #1 input file */
char *jfile; /* image #2 input file */
char *sfile; /* 'static' segment C code output file */
char *cfile; /* 'code' segment C code output file */
int mf; /* scale factor for x and y */
char *i1; /* image #1 */
char *i2; /* image #2 */
int w, h; /* image width and height */
int w2, h2; /* temp for chking 2nd image */
void *texture;
void *tindex1;
void *tindex2;
void *tcoords1;
void *tcoords2;
void *trilist;
void *vface1;
void *vface2;
int tricnt, vertcnt;
int tris[TMAX*3];
int verts[VMAX*4];
int tasize; /* # of elements in texture[] array */
/*
* parse options and parameters
*/
parseoptions(argc, argv, &vfile, &tfile, &ifile, &jfile,
&sfile, &cfile, &mf);
/*
* read input files
*/
readppm(ifile, &w, &h, &i1);
readppm(jfile, &w2, &h2, &i2);
if ((w != w2) || (h != h2)) {
fprintf(stderr, "Sizes of ifile and jfile must match.\n");
exit(1);
}
rdvertfile(vfile, &vertcnt, verts, VMAX, w, h);
printf("Read %i verticies\n", vertcnt);
rdtrifile(tfile, &tricnt, tris, TMAX, vertcnt);
printf("Read %i triangles\n", tricnt);
/*
* create arrays that will be written to C files later
*/
texture = (void *) malloc(sizeof(int)*tricnt*(32*32)*2); /* max possible */
tindex1 = (void *) malloc(sizeof(int)*tricnt*3);
tindex2 = (void *) malloc(sizeof(int)*tricnt*3);
tcoords1 = (void *) malloc(sizeof(int)*tricnt*4);
tcoords2 = (void *) malloc(sizeof(int)*tricnt*4);
trilist = (void *) malloc(sizeof(int)*tricnt*3);
vface1 = (void *) malloc(sizeof(int)*tricnt*3*4);
vface2 = (void *) malloc(sizeof(int)*tricnt*3*4);
/*
* Fill the arrays
*/
buildit(tris, tricnt, verts, i1, i2, w, h,
texture, &tasize, tindex1, tindex2,
tcoords1, tcoords2, trilist, vface1, vface2,
mf);
/*
* Write the output files
*/
writeit(sfile, cfile, tricnt,
texture, tasize, tindex1, tindex2,
tcoords1, tcoords2, trilist, vface1, vface2,
tris);
} /* main */