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
|
#ifndef render_h
#define render_h
#include "rect.h"
struct Map;
typedef struct {
int x, y;
int dx, dy;
int sx, sy;
int e;
} Line;
void init_line(
Line* l,
const int* f,
const int* t
);
void init_lerp(
Line* l,
int a, int b,
int x, int y
);
void step_line(Line* l);
typedef struct {
unsigned char r, g, b, a;
} Colour;
Colour make_colour(unsigned rgb, unsigned char a);
Colour make_red(void);
Colour make_green(void);
Colour make_blue(void);
Colour make_cyan(void);
Colour make_pink(void);
Colour make_yellow(void);
Colour make_aliceblue(void);
Colour make_white(void);
Colour make_black(void);
Colour blend(Colour dst, Colour src);
Colour blend_mod(Colour dst, Colour src, Colour mod);
Colour col_mul(Colour a, Colour b);
Colour col_scl(Colour a, unsigned char s);
Colour col_add(Colour a, Colour b);
typedef struct {
Colour* p;
int w, h;
} Bitmap;
typedef struct Texture {
int w, h;
} Texture;
typedef struct {
unsigned short p, n, t;
} Mesh_Vert;
typedef struct Mesh {
int vc, pc, nc, tc;
int* p, * n, * t;
Mesh_Vert* verts;
} Mesh;
typedef struct Renderer {
Colour* t;
int* d;
int asp, n;
int vp[2];
int clip[4];
} Renderer;
int tri_os(
const Renderer* r,
const int* v0,
const int* v1,
const int* v2
);
int point_os(
const Renderer* r,
int x,
int y
);
Colour sample_tex(const Texture* t, int u, int v);
void ren_begin(Renderer* r, Colour* t, int* d, int w, int h);
void ren_end(Renderer* r);
void ren_clear(Renderer* r);
void ren_clearc(Renderer* r, Colour c);
void ren_cleard(Renderer* r, int depth);
void ren_clip(Renderer* r, const Rect* c);
void ren_clipr(Renderer* r);
void ren_point(Renderer* r, Colour c, int x, int y);
void ren_rect(Renderer* r, Colour c, const Rect*);
void ren_char(
Renderer* r,
Colour c,
int x,
int y,
char ch
);
void ren_chars(
Renderer* r,
Colour c,
int x,
int y,
char ch
);
void ren_text(
Renderer* r,
Colour c,
int x,
int y,
const char* t
);
void ren_texts(
Renderer* r,
Colour c,
int x,
int y,
const char* t
);
void ren_line(
Renderer* r,
Colour c,
const int* s,
const int* e
);
void ren_texture(
Renderer* r,
const Rect* re,
const Texture* t
);
/* Vertex format:
* x y z u v r g b
* All fixed point values with 9 bits of precision.
*/
void ren_tri(
Renderer* r,
const int* v0,
const int* v1,
const int* v2,
const Texture* tex
); /* Unsafe for 3D. Clips against the r->clip */
void ren_tri3(
Renderer* r,
const int* v0,
const int* v1,
const int* v2,
const Texture* tex
); /* Does perspective calculation and clips against the near. */
void ren_mesh(
Renderer* r,
const Mesh* mesh,
const Texture* tex
);
void ren_map(
Renderer* r,
const struct Map* map,
const int* pos,
const int* dir,
const int* left
);
#endif
|