void Rastr_Br struct rebro int Rastr mr int GLint height width size im

 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
void Rastr_Br(struct rebro *p, int n) {
Rastr(mr,N);
int i = 0, j = 0, x = 0, y = 0;
GLint height, width, size = 0;
//image = NULL;
for (i = 0; i < N - 1; i++) {
mr[i].bx = pt[i].x;
mr[i].by = pt[i].y;
mr[i].ex = pt[i + 1].x;
mr[i].ey = pt[i + 1].y;
}
mr[N - 1].bx = pt[N - 1].x;
mr[N - 1].by = pt[N - 1].y;
mr[N - 1].ex = pt[0].x;
mr[N - 1].ey = pt[0].y;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glRasterPos2f(0, 0);
width = GW;
height = GH;
size = width*height;
for (i = 0; i < N && s == N; i++) {
int flag;
int dx = abs(mr[i].ex - mr[i].bx);
int dy = abs(mr[i].ey - mr[i].by);
int s1 = (mr[i].ex - mr[i].bx < 0) ? -1 : 1;
int s2 = (mr[i].ey - mr[i].by < 0) ? -1 : 1;
if (dx < dy) {
int temp = dx;
dx = dy;
dy = temp;
flag = 1;
}
else flag = 0;
int L = 255;
int m = 2 * L*dy;
int w = 2*dx*L - m;
int e = m/2;
y = mr[i].by;
x = mr[i].bx;
for (j = 0; j < dx; j++) {
GLbyte* row = image + (width * 3) * y;
row[x * 3] = 0x00;
row[x * 3 + 1] = 0x00;
row[x * 3 + 2] = e / (2 * dx);
if ((flag == 1) != (s1*s2==-1)) row[x * 3 + 2] = L - e / (2 * dx);
if (e >= w) {
if (flag == 1) x += s1;
else y += s2;
e -= w;
}
else {
e += m;
}
if (flag == 1) y += s2;
else x += s1;
}
}
}