d8facb5a29271e62b29bfb2cbf0a8fc45be21cdf
[dosdemo] / src / polyfill.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "polyfill.h"
4 #include "gfxutil.h"
5 #include "demo.h"
6
7 void (*fillfunc[])(struct pvertex*, int) = {
8         polyfill_wire,
9         0, 0, 0, 0
10 };
11
12 void polyfill(int mode, struct pvertex *verts, int nverts)
13 {
14 #ifndef NDEBUG
15         if(!fillfunc[mode]) {
16                 fprintf(stderr, "polyfill mode %d not implemented\n", mode);
17                 abort();
18         }
19 #endif
20
21         fillfunc[mode](verts, nverts);
22 }
23
24 void polyfill_wire(struct pvertex *verts, int nverts)
25 {
26         int i;
27         struct pvertex *v = verts;
28         unsigned short color = ((v->r << 8) & 0xf800) |
29                 ((v->g << 3) & 0x7e0) | ((v->b >> 3) & 0x1f);
30
31         for(i=0; i<nverts; i++) {
32                 int x0, y0, x1, y1;
33                 x0 = v->x >> 8;
34                 y0 = v->y >> 8;
35                 ++v;
36                 x1 = v->x >> 8;
37                 y1 = v->y >> 8;
38                 clip_line(&x0, &y0, &x1, &y1, 0, 0, fb_width, fb_height);
39                 draw_line(x0, y0, x1, y1, color);
40         }
41 }