-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathex10.c
64 lines (48 loc) · 1.46 KB
/
ex10.c
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
/*=========================================================================
GFX EXAMPLE CODE - #10
"shaded triangle"
Copyright (C) 2004 Rafael de Oliveira Jannone
This example's source code is Public Domain.
WARNING: The author makes no guarantees and holds no responsibility for
any damage, injury or loss that may result from the use of this source
code. USE IT AT YOUR OWN RISK.
Contact the author:
by e-mail : rafael AT jannone DOT org
homepage : http://jannone.org/gfxlib
ICQ UIN : 10115284
=========================================================================*/
#include <stdlib.h>
#include "line.h"
int low[MODE2_HEIGHT];
int high[MODE2_HEIGHT];
u_char *buf;
main() {
int c, l;
u_char i;
surface_t surf;
buf = (u_char*)malloc(MODE2_MAX);
surf.data.ram = buf;
set_color(15, 1, 1);
set_mode(mode_2);
fill(MODE2_ATTR, 0x31, MODE2_MAX);
c = 0;
// paint polygon
for (;;) {
memset(buf, MODE2_MAX, 0); // yeah... crap
memset(low, MODE2_HEIGHT << 1, 64); // yeah... crap
memset(high, MODE2_HEIGHT << 1, 0); // yeah... crap
// calculate polygon
calculate_side(128 + c, c + 20, 40, 180 - c, low, high);
calculate_side(128 + c, c + 20, 255 - c, 96, low, high);
calculate_side(255 - c, 96, 40, 180 - c, low, high);
c = (c + 4) & 63;
i = (c + 15) >> 4;
for (l = 20; l < 180; l++) {
surface_hline(&surf, low[l], l, high[l], DITHER(i, l));
}
vwrite(surf.data.ram, 0, MODE2_MAX);
if (get_trigger(0))
break;
}
set_mode(mode_0);
}