DEADSOFTWARE

82ecc94dec561dde831d1e8bc1b8097478982c96
[d2df-sdl.git] / src / game / g_holmes.inc
1 (* Copyright (C) DooM 2D:Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 // ////////////////////////////////////////////////////////////////////////// //
17 // cursor (hi, Death Track!)
18 const curTexWidth = 32;
19 const curTexHeight = 32;
20 const curWidth = 17;
21 const curHeight = 23;
23 const cursorImg: array[0..curWidth*curHeight-1] of Byte = (
24 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
25 3,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
26 3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
27 3,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,
28 3,3,4,2,2,0,0,0,0,0,0,0,0,0,0,0,0,
29 3,3,4,4,2,2,0,0,0,0,0,0,0,0,0,0,0,
30 3,3,4,4,4,2,2,0,0,0,0,0,0,0,0,0,0,
31 3,3,4,4,4,4,2,2,0,0,0,0,0,0,0,0,0,
32 3,3,4,4,4,5,6,2,2,0,0,0,0,0,0,0,0,
33 3,3,4,4,5,6,7,5,2,2,0,0,0,0,0,0,0,
34 3,3,4,5,6,7,5,4,5,2,2,0,0,0,0,0,0,
35 3,3,5,6,7,5,4,5,6,7,2,2,0,0,0,0,0,
36 3,3,6,7,5,4,5,6,7,7,7,2,2,0,0,0,0,
37 3,3,7,5,4,5,6,7,7,7,7,7,2,2,0,0,0,
38 3,3,5,4,5,6,8,8,8,8,8,8,8,8,2,0,0,
39 3,3,4,5,6,3,8,8,8,8,8,8,8,8,8,0,0,
40 3,3,5,6,3,3,0,0,0,0,0,0,0,0,0,0,0,
41 3,3,6,3,3,0,0,0,0,0,0,0,0,0,0,0,0,
42 3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,
43 3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
44 3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
45 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
46 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
47 );
48 const cursorPal: array[0..9*4-1] of Byte = (
49 0, 0, 0, 0,
50 0, 0, 0,163,
51 85,255,255,255,
52 85, 85,255,255,
53 255, 85, 85,255,
54 170, 0,170,255,
55 85, 85, 85,255,
56 0, 0, 0,255,
57 0, 0,170,255
58 );
61 var
62 curtexid: GLuint = 0;
64 procedure createCursorTexture ();
65 var
66 tex, tpp: PByte;
67 c: Integer;
68 x, y: Integer;
69 begin
70 if (curtexid <> 0) then exit; //begin glDeleteTextures(1, @curtexid); curtexid := 0; end;
72 GetMem(tex, curTexWidth*curTexHeight*4);
73 FillChar(tex^, curTexWidth*curTexHeight*4, 0);
75 // draw shadow
76 for y := 0 to curHeight-1 do
77 begin
78 for x := 0 to curWidth-1 do
79 begin
80 if (cursorImg[y*curWidth+x] <> 0) then
81 begin
82 c := 1*4;
83 tpp := tex+((y+1)*(curTexWidth*4)+(x+3)*4);
84 tpp^ := cursorPal[c+0]; Inc(tpp);
85 tpp^ := cursorPal[c+1]; Inc(tpp);
86 tpp^ := cursorPal[c+2]; Inc(tpp);
87 tpp^ := cursorPal[c+3]; Inc(tpp);
88 tpp^ := cursorPal[c+0]; Inc(tpp);
89 tpp^ := cursorPal[c+1]; Inc(tpp);
90 tpp^ := cursorPal[c+2]; Inc(tpp);
91 tpp^ := cursorPal[c+3]; Inc(tpp);
92 end;
93 end;
94 end;
96 // draw cursor
97 for y := 0 to curHeight-1 do
98 begin
99 for x := 0 to curWidth-1 do
100 begin
101 c := cursorImg[y*curWidth+x]*4;
102 if (c <> 0) then
103 begin
104 tpp := tex+(y*(curTexWidth*4)+x*4);
105 tpp^ := cursorPal[c+0]; Inc(tpp);
106 tpp^ := cursorPal[c+1]; Inc(tpp);
107 tpp^ := cursorPal[c+2]; Inc(tpp);
108 tpp^ := cursorPal[c+3]; Inc(tpp);
109 end;
110 end;
111 end;
113 glGenTextures(1, @curtexid);
114 if (curtexid = 0) then raise Exception.Create('can''t create Holmes texture');
116 glBindTexture(GL_TEXTURE_2D, curtexid);
117 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
118 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
119 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
120 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
122 //GLfloat[4] bclr = 0.0;
123 //glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, bclr.ptr);
125 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, curTexWidth, curTexHeight, 0, GL_RGBA{gltt}, GL_UNSIGNED_BYTE, tex);
126 glFlush();
128 //FreeMem(tex);
129 end;
132 procedure drawCursor ();
133 begin
134 if (curtexid = 0) then createCursorTexture() else glBindTexture(GL_TEXTURE_2D, curtexid);
135 // blend it
136 glEnable(GL_BLEND);
137 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
138 glEnable(GL_TEXTURE_2D);
139 // color and opacity
140 glColor4f(1, 1, 1, 0.9);
141 //Dec(msX, 2);
142 glBegin(GL_QUADS);
143 glTexCoord2f(0.0, 0.0); glVertex2i(msX, msY); // top-left
144 glTexCoord2f(1.0, 0.0); glVertex2i(msX+curTexWidth, msY); // top-right
145 glTexCoord2f(1.0, 1.0); glVertex2i(msX+curTexWidth, msY+curTexHeight); // bottom-right
146 glTexCoord2f(0.0, 1.0); glVertex2i(msX, msY+curTexHeight); // bottom-left
147 glEnd();
148 //Inc(msX, 2);
149 glDisable(GL_BLEND);
150 glDisable(GL_TEXTURE_2D);
151 glColor4f(1, 1, 1, 1);
152 glBindTexture(GL_TEXTURE_2D, 0);
153 end;
156 // ////////////////////////////////////////////////////////////////////////// //
157 type
158 TScissorSave = record
159 public
160 wassc: Boolean;
161 scxywh: packed array[0..3] of GLint;
163 public
164 procedure save (enableScissoring: Boolean);
165 procedure restore ();
166 end;
168 procedure TScissorSave.save (enableScissoring: Boolean);
169 begin
170 wassc := (glIsEnabled(GL_SCISSOR_TEST) <> 0);
171 if wassc then glGetIntegerv(GL_SCISSOR_BOX, @scxywh[0]) else glGetIntegerv(GL_VIEWPORT, @scxywh[0]);
172 //conwritefln('(%d,%d)-(%d,%d)', [scxywh[0], scxywh[1], scxywh[2], scxywh[3]]);
173 if enableScissoring then glEnable(GL_SCISSOR_TEST);
174 end;
177 procedure TScissorSave.restore ();
178 begin
179 glScissor(scxywh[0], scxywh[1], scxywh[2], scxywh[3]);
180 if wassc then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST);
181 end;
184 // ////////////////////////////////////////////////////////////////////////// //
185 // fonts
186 const kgiFont6: array[0..256*8-1] of Byte = (
187 $00,$00,$00,$00,$00,$00,$00,$00,$3c,$42,$a5,$81,$a5,$99,$42,$3c,$3c,$7e,$db,$ff,$ff,$db,$66,$3c,$6c,$fe,
188 $fe,$fe,$7c,$38,$10,$00,$10,$38,$7c,$fe,$7c,$38,$10,$00,$10,$38,$54,$fe,$54,$10,$38,$00,$10,$38,$7c,$fe,
189 $fe,$10,$38,$00,$00,$00,$00,$30,$30,$00,$00,$00,$ff,$ff,$ff,$e7,$e7,$ff,$ff,$ff,$38,$44,$82,$82,$82,$44,
190 $38,$00,$c7,$bb,$7d,$7d,$7d,$bb,$c7,$ff,$0f,$03,$05,$79,$88,$88,$88,$70,$38,$44,$44,$44,$38,$10,$7c,$10,
191 $30,$28,$24,$24,$28,$20,$e0,$c0,$3c,$24,$3c,$24,$24,$e4,$dc,$18,$10,$54,$38,$ee,$38,$54,$10,$00,$10,$10,
192 $10,$7c,$10,$10,$10,$10,$10,$10,$10,$ff,$00,$00,$00,$00,$00,$00,$00,$ff,$10,$10,$10,$10,$10,$10,$10,$f0,
193 $10,$10,$10,$10,$10,$10,$10,$1f,$10,$10,$10,$10,$10,$10,$10,$ff,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,
194 $10,$10,$00,$00,$00,$ff,$00,$00,$00,$00,$00,$00,$00,$1f,$10,$10,$10,$10,$00,$00,$00,$f0,$10,$10,$10,$10,
195 $10,$10,$10,$1f,$00,$00,$00,$00,$10,$10,$10,$f0,$00,$00,$00,$00,$81,$42,$24,$18,$18,$24,$42,$81,$01,$02,
196 $04,$08,$10,$20,$40,$80,$80,$40,$20,$10,$08,$04,$02,$01,$00,$10,$10,$ff,$10,$10,$00,$00,$00,$00,$00,$00,
197 $00,$00,$00,$00,$20,$20,$20,$20,$00,$00,$20,$00,$50,$50,$50,$00,$00,$00,$00,$00,$50,$50,$f8,$50,$f8,$50,
198 $50,$00,$20,$78,$a0,$70,$28,$f0,$20,$00,$c0,$c8,$10,$20,$40,$98,$18,$00,$40,$a0,$40,$a8,$90,$98,$60,$00,
199 $10,$20,$40,$00,$00,$00,$00,$00,$10,$20,$40,$40,$40,$20,$10,$00,$40,$20,$10,$10,$10,$20,$40,$00,$88,$50,
200 $20,$f8,$20,$50,$88,$00,$00,$20,$20,$f8,$20,$20,$00,$00,$00,$00,$00,$00,$00,$20,$20,$40,$00,$00,$00,$78,
201 $00,$00,$00,$00,$00,$00,$00,$00,$00,$60,$60,$00,$00,$00,$08,$10,$20,$40,$80,$00,$70,$88,$98,$a8,$c8,$88,
202 $70,$00,$20,$60,$a0,$20,$20,$20,$f8,$00,$70,$88,$08,$10,$60,$80,$f8,$00,$70,$88,$08,$30,$08,$88,$70,$00,
203 $10,$30,$50,$90,$f8,$10,$10,$00,$f8,$80,$e0,$10,$08,$10,$e0,$00,$30,$40,$80,$f0,$88,$88,$70,$00,$f8,$88,
204 $10,$20,$20,$20,$20,$00,$70,$88,$88,$70,$88,$88,$70,$00,$70,$88,$88,$78,$08,$10,$60,$00,$00,$00,$20,$00,
205 $00,$20,$00,$00,$00,$00,$20,$00,$00,$20,$20,$40,$18,$30,$60,$c0,$60,$30,$18,$00,$00,$00,$f8,$00,$f8,$00,
206 $00,$00,$c0,$60,$30,$18,$30,$60,$c0,$00,$70,$88,$08,$10,$20,$00,$20,$00,$70,$88,$08,$68,$a8,$a8,$70,$00,
207 $20,$50,$88,$88,$f8,$88,$88,$00,$f0,$48,$48,$70,$48,$48,$f0,$00,$30,$48,$80,$80,$80,$48,$30,$00,$e0,$50,
208 $48,$48,$48,$50,$e0,$00,$f8,$80,$80,$f0,$80,$80,$f8,$00,$f8,$80,$80,$f0,$80,$80,$80,$00,$70,$88,$80,$b8,
209 $88,$88,$70,$00,$88,$88,$88,$f8,$88,$88,$88,$00,$70,$20,$20,$20,$20,$20,$70,$00,$38,$10,$10,$10,$90,$90,
210 $60,$00,$88,$90,$a0,$c0,$a0,$90,$88,$00,$80,$80,$80,$80,$80,$80,$f8,$00,$88,$d8,$a8,$a8,$88,$88,$88,$00,
211 $88,$c8,$c8,$a8,$98,$98,$88,$00,$70,$88,$88,$88,$88,$88,$70,$00,$f0,$88,$88,$f0,$80,$80,$80,$00,$70,$88,
212 $88,$88,$a8,$90,$68,$00,$f0,$88,$88,$f0,$a0,$90,$88,$00,$70,$88,$80,$70,$08,$88,$70,$00,$f8,$20,$20,$20,
213 $20,$20,$20,$00,$88,$88,$88,$88,$88,$88,$70,$00,$88,$88,$88,$88,$50,$50,$20,$00,$88,$88,$88,$a8,$a8,$d8,
214 $88,$00,$88,$88,$50,$20,$50,$88,$88,$00,$88,$88,$88,$70,$20,$20,$20,$00,$f8,$08,$10,$20,$40,$80,$f8,$00,
215 $70,$40,$40,$40,$40,$40,$70,$00,$00,$00,$80,$40,$20,$10,$08,$00,$70,$10,$10,$10,$10,$10,$70,$00,$20,$50,
216 $88,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$f8,$00,$40,$20,$10,$00,$00,$00,$00,$00,$00,$00,$70,$08,
217 $78,$88,$78,$00,$80,$80,$b0,$c8,$88,$c8,$b0,$00,$00,$00,$70,$88,$80,$88,$70,$00,$08,$08,$68,$98,$88,$98,
218 $68,$00,$00,$00,$70,$88,$f8,$80,$70,$00,$10,$28,$20,$f8,$20,$20,$20,$00,$00,$00,$68,$98,$98,$68,$08,$70,
219 $80,$80,$f0,$88,$88,$88,$88,$00,$20,$00,$60,$20,$20,$20,$70,$00,$10,$00,$30,$10,$10,$10,$90,$60,$40,$40,
220 $48,$50,$60,$50,$48,$00,$60,$20,$20,$20,$20,$20,$70,$00,$00,$00,$d0,$a8,$a8,$a8,$a8,$00,$00,$00,$b0,$c8,
221 $88,$88,$88,$00,$00,$00,$70,$88,$88,$88,$70,$00,$00,$00,$b0,$c8,$c8,$b0,$80,$80,$00,$00,$68,$98,$98,$68,
222 $08,$08,$00,$00,$b0,$c8,$80,$80,$80,$00,$00,$00,$78,$80,$f0,$08,$f0,$00,$40,$40,$f0,$40,$40,$48,$30,$00,
223 $00,$00,$90,$90,$90,$90,$68,$00,$00,$00,$88,$88,$88,$50,$20,$00,$00,$00,$88,$a8,$a8,$a8,$50,$00,$00,$00,
224 $88,$50,$20,$50,$88,$00,$00,$00,$88,$88,$98,$68,$08,$70,$00,$00,$f8,$10,$20,$40,$f8,$00,$18,$20,$20,$40,
225 $20,$20,$18,$00,$20,$20,$20,$00,$20,$20,$20,$00,$c0,$20,$20,$10,$20,$20,$c0,$00,$40,$a8,$10,$00,$00,$00,
226 $00,$00,$00,$00,$20,$50,$f8,$00,$00,$00,$00,$00,$00,$00,$00,$00,$ff,$ff,$f0,$f0,$f0,$f0,$0f,$0f,$0f,$0f,
227 $00,$00,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$00,$00,$00,$00,$00,$00,$00,$00,$00,$3c,$3c,$00,$00,$00,$ff,$ff,
228 $ff,$ff,$ff,$ff,$00,$00,$c0,$c0,$c0,$c0,$c0,$c0,$c0,$c0,$0f,$0f,$0f,$0f,$f0,$f0,$f0,$f0,$fc,$fc,$fc,$fc,
229 $fc,$fc,$fc,$fc,$03,$03,$03,$03,$03,$03,$03,$03,$3f,$3f,$3f,$3f,$3f,$3f,$3f,$3f,$11,$22,$44,$88,$11,$22,
230 $44,$88,$88,$44,$22,$11,$88,$44,$22,$11,$fe,$7c,$38,$10,$00,$00,$00,$00,$00,$00,$00,$00,$10,$38,$7c,$fe,
231 $80,$c0,$e0,$f0,$e0,$c0,$80,$00,$01,$03,$07,$0f,$07,$03,$01,$00,$ff,$7e,$3c,$18,$18,$3c,$7e,$ff,$81,$c3,
232 $e7,$ff,$ff,$e7,$c3,$81,$f0,$f0,$f0,$f0,$00,$00,$00,$00,$00,$00,$00,$00,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,
233 $00,$00,$00,$00,$00,$00,$00,$00,$f0,$f0,$f0,$f0,$33,$33,$cc,$cc,$33,$33,$cc,$cc,$00,$20,$20,$50,$50,$88,
234 $f8,$00,$20,$20,$70,$20,$70,$20,$20,$00,$00,$00,$00,$50,$88,$a8,$50,$00,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,
235 $00,$00,$00,$00,$ff,$ff,$ff,$ff,$f0,$f0,$f0,$f0,$f0,$f0,$f0,$f0,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$ff,$ff,
236 $ff,$ff,$00,$00,$00,$00,$00,$00,$68,$90,$90,$90,$68,$00,$30,$48,$48,$70,$48,$48,$70,$c0,$f8,$88,$80,$80,
237 $80,$80,$80,$00,$00,$50,$70,$88,$f8,$80,$70,$00,$00,$00,$78,$80,$f0,$80,$78,$00,$00,$00,$78,$90,$90,$90,
238 $60,$00,$20,$00,$60,$20,$20,$20,$70,$00,$50,$00,$70,$20,$20,$20,$70,$00,$f8,$20,$70,$a8,$a8,$70,$20,$f8,
239 $20,$50,$88,$f8,$88,$50,$20,$00,$70,$88,$88,$88,$50,$50,$d8,$00,$30,$40,$40,$20,$50,$50,$50,$20,$00,$00,
240 $00,$50,$a8,$a8,$50,$00,$08,$70,$a8,$a8,$a8,$70,$80,$00,$38,$40,$80,$f8,$80,$40,$38,$00,$70,$88,$88,$88,
241 $88,$88,$88,$00,$00,$f8,$00,$f8,$00,$f8,$00,$00,$20,$20,$f8,$20,$20,$00,$f8,$00,$c0,$30,$08,$30,$c0,$00,
242 $f8,$00,$50,$f8,$80,$f0,$80,$80,$f8,$00,$78,$80,$80,$f0,$80,$80,$78,$00,$20,$20,$20,$20,$20,$20,$a0,$40,
243 $70,$20,$20,$20,$20,$20,$70,$00,$50,$70,$20,$20,$20,$20,$70,$00,$00,$18,$24,$24,$18,$00,$00,$00,$00,$30,
244 $78,$78,$30,$00,$00,$00,$00,$00,$00,$00,$30,$00,$00,$00,$3e,$20,$20,$20,$a0,$60,$20,$00,$a0,$50,$50,$50,
245 $00,$00,$00,$00,$40,$a0,$20,$40,$e0,$00,$00,$00,$00,$38,$38,$38,$38,$38,$38,$00,$3c,$42,$99,$a1,$a1,$99,
246 $42,$3c,$00,$00,$90,$a8,$e8,$a8,$90,$00,$00,$00,$60,$10,$70,$90,$68,$00,$00,$00,$f0,$80,$f0,$88,$f0,$00,
247 $00,$00,$90,$90,$90,$f8,$08,$00,$00,$00,$30,$50,$50,$70,$88,$00,$00,$00,$70,$88,$f8,$80,$70,$00,$00,$20,
248 $70,$a8,$a8,$70,$20,$00,$00,$00,$78,$48,$40,$40,$40,$00,$00,$00,$88,$50,$20,$50,$88,$00,$00,$00,$88,$98,
249 $a8,$c8,$88,$00,$00,$50,$20,$00,$98,$a8,$c8,$00,$00,$00,$90,$a0,$c0,$a0,$90,$00,$00,$00,$38,$28,$28,$48,
250 $88,$00,$00,$00,$88,$d8,$a8,$88,$88,$00,$00,$00,$88,$88,$f8,$88,$88,$00,$00,$00,$70,$88,$88,$88,$70,$00,
251 $00,$00,$78,$48,$48,$48,$48,$00,$00,$00,$78,$88,$78,$28,$48,$00,$00,$00,$f0,$88,$f0,$80,$80,$00,$00,$00,
252 $78,$80,$80,$80,$78,$00,$00,$00,$f8,$20,$20,$20,$20,$00,$00,$00,$88,$50,$20,$40,$80,$00,$00,$00,$a8,$70,
253 $20,$70,$a8,$00,$00,$00,$f0,$48,$70,$48,$f0,$00,$00,$00,$40,$40,$70,$48,$70,$00,$00,$00,$88,$88,$c8,$a8,
254 $c8,$00,$00,$00,$f0,$08,$70,$08,$f0,$00,$00,$00,$a8,$a8,$a8,$a8,$f8,$00,$00,$00,$70,$88,$38,$88,$70,$00,
255 $00,$00,$a8,$a8,$a8,$f8,$08,$00,$00,$00,$48,$48,$78,$08,$08,$00,$00,$00,$c0,$40,$70,$48,$70,$00,$90,$a8,
256 $a8,$e8,$a8,$a8,$90,$00,$20,$50,$88,$88,$f8,$88,$88,$00,$f8,$88,$80,$f0,$88,$88,$f0,$00,$90,$90,$90,$90,
257 $90,$f8,$08,$00,$38,$28,$28,$48,$48,$f8,$88,$00,$f8,$80,$80,$f0,$80,$80,$f8,$00,$20,$70,$a8,$a8,$a8,$70,
258 $20,$00,$f8,$88,$88,$80,$80,$80,$80,$00,$88,$88,$50,$20,$50,$88,$88,$00,$88,$88,$98,$a8,$c8,$88,$88,$00,
259 $50,$20,$88,$98,$a8,$c8,$88,$00,$88,$90,$a0,$c0,$a0,$90,$88,$00,$18,$28,$48,$48,$48,$48,$88,$00,$88,$d8,
260 $a8,$a8,$88,$88,$88,$00,$88,$88,$88,$f8,$88,$88,$88,$00,$70,$88,$88,$88,$88,$88,$70,$00,$f8,$88,$88,$88,
261 $88,$88,$88,$00,$78,$88,$88,$78,$28,$48,$88,$00,$f0,$88,$88,$f0,$80,$80,$80,$00,$70,$88,$80,$80,$80,$88,
262 $70,$00,$f8,$20,$20,$20,$20,$20,$20,$00,$88,$88,$88,$50,$20,$40,$80,$00,$a8,$a8,$70,$20,$70,$a8,$a8,$00,
263 $f0,$48,$48,$70,$48,$48,$f0,$00,$80,$80,$80,$f0,$88,$88,$f0,$00,$88,$88,$88,$c8,$a8,$a8,$c8,$00,$f0,$08,
264 $08,$30,$08,$08,$f0,$00,$a8,$a8,$a8,$a8,$a8,$a8,$f8,$00,$70,$88,$08,$78,$08,$88,$70,$00,$a8,$a8,$a8,$a8,
265 $a8,$f8,$08,$00,$88,$88,$88,$88,$78,$08,$08,$00,$c0,$40,$40,$70,$48,$48,$70,$00
266 );
268 const kgiFont8: array[0..256*8-1] of Byte = (
269 $00,$00,$00,$00,$00,$00,$00,$00,$7e,$81,$a5,$81,$bd,$99,$81,$7e,$7e,$ff,$db,$ff,$c3,$e7,$ff,$7e,$6c,$fe,
270 $fe,$fe,$7c,$38,$10,$00,$10,$38,$7c,$fe,$7c,$38,$10,$00,$38,$7c,$38,$fe,$fe,$d6,$10,$38,$10,$10,$38,$7c,
271 $fe,$7c,$10,$38,$00,$00,$18,$3c,$3c,$18,$00,$00,$ff,$ff,$e7,$c3,$c3,$e7,$ff,$ff,$00,$3c,$66,$42,$42,$66,
272 $3c,$00,$ff,$c3,$99,$bd,$bd,$99,$c3,$ff,$0f,$07,$0f,$7d,$cc,$cc,$cc,$78,$3c,$66,$66,$66,$3c,$18,$7e,$18,
273 $3f,$33,$3f,$30,$30,$70,$f0,$e0,$7f,$63,$7f,$63,$63,$67,$e6,$c0,$99,$5a,$3c,$e7,$e7,$3c,$5a,$99,$80,$e0,
274 $f8,$fe,$f8,$e0,$80,$00,$02,$0e,$3e,$fe,$3e,$0e,$02,$00,$18,$3c,$7e,$18,$18,$7e,$3c,$18,$66,$66,$66,$66,
275 $66,$00,$66,$00,$7f,$db,$db,$7b,$1b,$1b,$1b,$00,$7e,$c3,$78,$cc,$cc,$78,$8c,$f8,$00,$00,$00,$00,$7e,$7e,
276 $7e,$00,$18,$3c,$7e,$18,$7e,$3c,$18,$ff,$18,$3c,$7e,$18,$18,$18,$18,$00,$18,$18,$18,$18,$7e,$3c,$18,$00,
277 $00,$18,$0c,$fe,$0c,$18,$00,$00,$00,$30,$60,$fe,$60,$30,$00,$00,$00,$00,$c0,$c0,$c0,$fe,$00,$00,$00,$24,
278 $66,$ff,$66,$24,$00,$00,$00,$18,$3c,$7e,$ff,$ff,$00,$00,$00,$ff,$ff,$7e,$3c,$18,$00,$00,$00,$00,$00,$00,
279 $00,$00,$00,$00,$30,$78,$78,$30,$30,$00,$30,$00,$6c,$6c,$6c,$00,$00,$00,$00,$00,$6c,$6c,$fe,$6c,$fe,$6c,
280 $6c,$00,$30,$7c,$c0,$78,$0c,$f8,$30,$00,$00,$c6,$cc,$18,$30,$66,$c6,$00,$38,$6c,$38,$76,$dc,$cc,$76,$00,
281 $60,$60,$c0,$00,$00,$00,$00,$00,$18,$30,$60,$60,$60,$30,$18,$00,$60,$30,$18,$18,$18,$30,$60,$00,$00,$66,
282 $3c,$ff,$3c,$66,$00,$00,$00,$30,$30,$fc,$30,$30,$00,$00,$00,$00,$00,$00,$00,$70,$30,$60,$00,$00,$00,$fc,
283 $00,$00,$00,$00,$00,$00,$00,$00,$00,$30,$30,$00,$06,$0c,$18,$30,$60,$c0,$80,$00,$78,$cc,$dc,$fc,$ec,$cc,
284 $78,$00,$30,$f0,$30,$30,$30,$30,$fc,$00,$78,$cc,$0c,$38,$60,$cc,$fc,$00,$78,$cc,$0c,$38,$0c,$cc,$78,$00,
285 $1c,$3c,$6c,$cc,$fe,$0c,$0c,$00,$fc,$c0,$f8,$0c,$0c,$cc,$78,$00,$38,$60,$c0,$f8,$cc,$cc,$78,$00,$fc,$cc,
286 $0c,$18,$30,$60,$60,$00,$78,$cc,$cc,$78,$cc,$cc,$78,$00,$78,$cc,$cc,$7c,$0c,$18,$70,$00,$00,$00,$30,$30,
287 $00,$30,$30,$00,$00,$00,$30,$30,$00,$70,$30,$60,$18,$30,$60,$c0,$60,$30,$18,$00,$00,$00,$fc,$00,$fc,$00,
288 $00,$00,$60,$30,$18,$0c,$18,$30,$60,$00,$78,$cc,$0c,$18,$30,$00,$30,$00,$7c,$c6,$de,$de,$de,$c0,$78,$00,
289 $30,$78,$cc,$cc,$fc,$cc,$cc,$00,$fc,$66,$66,$7c,$66,$66,$fc,$00,$3c,$66,$c0,$c0,$c0,$66,$3c,$00,$fc,$6c,
290 $66,$66,$66,$6c,$fc,$00,$fe,$62,$68,$78,$68,$62,$fe,$00,$fe,$62,$68,$78,$68,$60,$f0,$00,$3c,$66,$c0,$c0,
291 $ce,$66,$3e,$00,$cc,$cc,$cc,$fc,$cc,$cc,$cc,$00,$78,$30,$30,$30,$30,$30,$78,$00,$1e,$0c,$0c,$0c,$cc,$cc,
292 $78,$00,$e6,$66,$6c,$78,$6c,$66,$e6,$00,$f0,$60,$60,$60,$62,$66,$fe,$00,$c6,$ee,$fe,$d6,$c6,$c6,$c6,$00,
293 $c6,$e6,$f6,$de,$ce,$c6,$c6,$00,$38,$6c,$c6,$c6,$c6,$6c,$38,$00,$fc,$66,$66,$7c,$60,$60,$f0,$00,$78,$cc,
294 $cc,$cc,$dc,$78,$1c,$00,$fc,$66,$66,$7c,$78,$6c,$e6,$00,$78,$cc,$e0,$38,$1c,$cc,$78,$00,$fc,$b4,$30,$30,
295 $30,$30,$78,$00,$cc,$cc,$cc,$cc,$cc,$cc,$fc,$00,$cc,$cc,$cc,$cc,$cc,$78,$30,$00,$c6,$c6,$c6,$d6,$fe,$ee,
296 $c6,$00,$c6,$c6,$6c,$38,$6c,$c6,$c6,$00,$cc,$cc,$cc,$78,$30,$30,$78,$00,$fe,$cc,$98,$30,$62,$c6,$fe,$00,
297 $78,$60,$60,$60,$60,$60,$78,$00,$c0,$60,$30,$18,$0c,$06,$02,$00,$78,$18,$18,$18,$18,$18,$78,$00,$10,$38,
298 $6c,$c6,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$ff,$30,$30,$18,$00,$00,$00,$00,$00,$00,$00,$78,$0c,
299 $7c,$cc,$76,$00,$e0,$60,$7c,$66,$66,$66,$bc,$00,$00,$00,$78,$cc,$c0,$cc,$78,$00,$1c,$0c,$0c,$7c,$cc,$cc,
300 $76,$00,$00,$00,$78,$cc,$fc,$c0,$78,$00,$38,$6c,$60,$f0,$60,$60,$f0,$00,$00,$00,$76,$cc,$cc,$7c,$0c,$f8,
301 $e0,$60,$6c,$76,$66,$66,$e6,$00,$30,$00,$70,$30,$30,$30,$78,$00,$18,$00,$78,$18,$18,$18,$d8,$70,$e0,$60,
302 $66,$6c,$78,$6c,$e6,$00,$70,$30,$30,$30,$30,$30,$78,$00,$00,$00,$ec,$fe,$d6,$c6,$c6,$00,$00,$00,$f8,$cc,
303 $cc,$cc,$cc,$00,$00,$00,$78,$cc,$cc,$cc,$78,$00,$00,$00,$dc,$66,$66,$7c,$60,$f0,$00,$00,$76,$cc,$cc,$7c,
304 $0c,$1e,$00,$00,$d8,$6c,$6c,$60,$f0,$00,$00,$00,$7c,$c0,$78,$0c,$f8,$00,$10,$30,$7c,$30,$30,$34,$18,$00,
305 $00,$00,$cc,$cc,$cc,$cc,$76,$00,$00,$00,$cc,$cc,$cc,$78,$30,$00,$00,$00,$c6,$c6,$d6,$fe,$6c,$00,$00,$00,
306 $c6,$6c,$38,$6c,$c6,$00,$00,$00,$cc,$cc,$cc,$7c,$0c,$f8,$00,$00,$fc,$98,$30,$64,$fc,$00,$1c,$30,$30,$e0,
307 $30,$30,$1c,$00,$18,$18,$18,$00,$18,$18,$18,$00,$e0,$30,$30,$1c,$30,$30,$e0,$00,$76,$dc,$00,$00,$00,$00,
308 $00,$00,$10,$38,$6c,$c6,$c6,$c6,$fe,$00,$78,$cc,$c0,$cc,$78,$18,$0c,$78,$00,$cc,$00,$cc,$cc,$cc,$7e,$00,
309 $1c,$00,$78,$cc,$fc,$c0,$78,$00,$7e,$c3,$3c,$06,$3e,$66,$3f,$00,$cc,$00,$78,$0c,$7c,$cc,$7e,$00,$e0,$00,
310 $78,$0c,$7c,$cc,$7e,$00,$30,$30,$78,$0c,$7c,$cc,$7e,$00,$00,$00,$7c,$c0,$c0,$7c,$06,$3c,$7e,$c3,$3c,$66,
311 $7e,$60,$3c,$00,$cc,$00,$78,$cc,$fc,$c0,$78,$00,$e0,$00,$78,$cc,$fc,$c0,$78,$00,$cc,$00,$70,$30,$30,$30,
312 $78,$00,$7c,$c6,$38,$18,$18,$18,$3c,$00,$e0,$00,$70,$30,$30,$30,$78,$00,$cc,$30,$78,$cc,$cc,$fc,$cc,$00,
313 $30,$30,$00,$78,$cc,$fc,$cc,$00,$1c,$00,$fc,$60,$78,$60,$fc,$00,$00,$00,$7f,$0c,$7f,$cc,$7f,$00,$3e,$6c,
314 $cc,$fe,$cc,$cc,$ce,$00,$78,$cc,$00,$78,$cc,$cc,$78,$00,$00,$cc,$00,$78,$cc,$cc,$78,$00,$00,$e0,$00,$78,
315 $cc,$cc,$78,$00,$78,$cc,$00,$cc,$cc,$cc,$7e,$00,$00,$e0,$00,$cc,$cc,$cc,$7e,$00,$00,$cc,$00,$cc,$cc,$fc,
316 $0c,$f8,$c6,$38,$7c,$c6,$c6,$7c,$38,$00,$cc,$00,$cc,$cc,$cc,$cc,$78,$00,$18,$18,$7e,$c0,$c0,$7e,$18,$18,
317 $38,$6c,$64,$f0,$60,$e6,$fc,$00,$cc,$cc,$78,$fc,$30,$fc,$30,$00,$f0,$d8,$d8,$f4,$cc,$de,$cc,$0e,$0e,$1b,
318 $18,$7e,$18,$18,$d8,$70,$1c,$00,$78,$0c,$7c,$cc,$7e,$00,$38,$00,$70,$30,$30,$30,$78,$00,$00,$1c,$00,$78,
319 $cc,$cc,$78,$00,$00,$1c,$00,$cc,$cc,$cc,$7e,$00,$00,$f8,$00,$f8,$cc,$cc,$cc,$00,$fc,$00,$cc,$ec,$fc,$dc,
320 $cc,$00,$3c,$6c,$6c,$3e,$00,$7e,$00,$00,$3c,$66,$66,$3c,$00,$7e,$00,$00,$30,$00,$30,$60,$c0,$cc,$78,$00,
321 $00,$00,$00,$fc,$c0,$c0,$00,$00,$00,$00,$00,$fc,$0c,$0c,$00,$00,$c6,$cc,$d8,$3e,$63,$ce,$98,$1f,$c6,$cc,
322 $d8,$f3,$67,$cf,$9f,$03,$00,$18,$00,$18,$18,$3c,$3c,$18,$00,$33,$66,$cc,$66,$33,$00,$00,$00,$cc,$66,$33,
323 $66,$cc,$00,$00,$22,$88,$22,$88,$22,$88,$22,$88,$55,$aa,$55,$aa,$55,$aa,$55,$aa,$dc,$76,$dc,$76,$dc,$76,
324 $dc,$76,$18,$18,$18,$18,$18,$18,$18,$18,$18,$18,$18,$18,$f8,$18,$18,$18,$18,$18,$f8,$18,$f8,$18,$18,$18,
325 $36,$36,$36,$36,$f6,$36,$36,$36,$00,$00,$00,$00,$fe,$36,$36,$36,$00,$00,$f8,$18,$f8,$18,$18,$18,$36,$36,
326 $f6,$06,$f6,$36,$36,$36,$36,$36,$36,$36,$36,$36,$36,$36,$00,$00,$fe,$06,$f6,$36,$36,$36,$36,$36,$f6,$06,
327 $fe,$00,$00,$00,$36,$36,$36,$36,$fe,$00,$00,$00,$18,$18,$f8,$18,$f8,$00,$00,$00,$00,$00,$00,$00,$f8,$18,
328 $18,$18,$18,$18,$18,$18,$1f,$00,$00,$00,$18,$18,$18,$18,$ff,$00,$00,$00,$00,$00,$00,$00,$ff,$18,$18,$18,
329 $18,$18,$18,$18,$1f,$18,$18,$18,$00,$00,$00,$00,$ff,$00,$00,$00,$18,$18,$18,$18,$ff,$18,$18,$18,$18,$18,
330 $1f,$18,$1f,$18,$18,$18,$36,$36,$36,$36,$37,$36,$36,$36,$36,$36,$37,$30,$3f,$00,$00,$00,$00,$00,$3f,$30,
331 $37,$36,$36,$36,$36,$36,$f7,$00,$ff,$00,$00,$00,$00,$00,$ff,$00,$f7,$36,$36,$36,$36,$36,$37,$30,$37,$36,
332 $36,$36,$00,$00,$ff,$00,$ff,$00,$00,$00,$36,$36,$f7,$00,$f7,$36,$36,$36,$18,$18,$ff,$00,$ff,$00,$00,$00,
333 $36,$36,$36,$36,$ff,$00,$00,$00,$00,$00,$ff,$00,$ff,$18,$18,$18,$00,$00,$00,$00,$ff,$36,$36,$36,$36,$36,
334 $36,$36,$3f,$00,$00,$00,$18,$18,$1f,$18,$1f,$00,$00,$00,$00,$00,$1f,$18,$1f,$18,$18,$18,$00,$00,$00,$00,
335 $3f,$36,$36,$36,$36,$36,$36,$36,$f7,$36,$36,$36,$18,$18,$ff,$00,$ff,$18,$18,$18,$18,$18,$18,$18,$f8,$00,
336 $00,$00,$00,$00,$00,$00,$1f,$18,$18,$18,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$00,$00,$00,$00,$ff,$ff,$ff,$ff,
337 $f0,$f0,$f0,$f0,$f0,$f0,$f0,$f0,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$ff,$ff,$ff,$ff,$00,$00,$00,$00,$00,$00,
338 $76,$dc,$c8,$dc,$76,$00,$00,$78,$cc,$f8,$cc,$f8,$c0,$c0,$00,$fe,$c6,$c0,$c0,$c0,$c0,$00,$00,$fe,$6c,$6c,
339 $6c,$6c,$6c,$00,$fe,$66,$30,$18,$30,$66,$fe,$00,$00,$00,$7e,$cc,$cc,$cc,$78,$00,$00,$66,$66,$66,$66,$7c,
340 $60,$c0,$00,$76,$dc,$18,$18,$18,$18,$00,$fc,$30,$78,$cc,$cc,$78,$30,$fc,$38,$6c,$c6,$fe,$c6,$6c,$38,$00,
341 $38,$6c,$c6,$c6,$6c,$6c,$ee,$00,$1c,$30,$18,$7c,$cc,$cc,$78,$00,$00,$00,$7e,$db,$db,$7e,$00,$00,$06,$0c,
342 $7e,$db,$db,$7e,$60,$c0,$3c,$60,$c0,$fc,$c0,$60,$3c,$00,$78,$cc,$cc,$cc,$cc,$cc,$cc,$00,$00,$fc,$00,$fc,
343 $00,$fc,$00,$00,$30,$30,$fc,$30,$30,$00,$fc,$00,$60,$30,$18,$30,$60,$00,$fc,$00,$18,$30,$60,$30,$18,$00,
344 $fc,$00,$0e,$1b,$1b,$18,$18,$18,$18,$18,$18,$18,$18,$18,$18,$d8,$d8,$70,$30,$30,$00,$fc,$00,$30,$30,$00,
345 $00,$72,$9c,$00,$72,$9c,$00,$00,$38,$6c,$6c,$38,$00,$00,$00,$00,$00,$00,$00,$18,$18,$00,$00,$00,$00,$00,
346 $00,$00,$18,$00,$00,$00,$0f,$0c,$0c,$0c,$ec,$6c,$3c,$1c,$78,$6c,$6c,$6c,$6c,$00,$00,$00,$78,$0c,$38,$60,
347 $7c,$00,$00,$00,$00,$00,$3c,$3c,$3c,$3c,$00,$00,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
348 );
350 const kgiFont6PropWidth: array[0..256-1] of Byte = (
351 $08,$08,$08,$07,$07,$07,$07,$04,$08,$07,$08,$08,$06,$06,$06,$07,
352 $06,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,
353 $85,$21,$13,$05,$05,$05,$05,$13,$13,$13,$05,$05,$12,$14,$12,$05,
354 $05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$21,$12,$05,$05,$05,$05,
355 $05,$05,$05,$05,$05,$05,$05,$05,$05,$13,$05,$05,$05,$05,$05,$05,
356 $05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$13,$05,$13,$05,$05,
357 $13,$05,$05,$05,$05,$05,$05,$05,$05,$13,$04,$14,$13,$05,$05,$05,
358 $05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$14,$21,$04,$05,$08,
359 $08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$04,
360 $44,$08,$08,$08,$08,$08,$08,$08,$05,$04,$05,$08,$08,$08,$08,$08,
361 $05,$05,$05,$05,$05,$05,$13,$13,$05,$05,$05,$04,$05,$05,$05,$05,
362 $05,$05,$05,$05,$05,$03,$04,$04,$06,$05,$04,$07,$04,$03,$05,$08,
363 $05,$05,$05,$05,$05,$05,$05,$14,$05,$05,$05,$04,$05,$05,$05,$05,
364 $14,$05,$05,$05,$05,$05,$05,$05,$14,$05,$05,$05,$05,$05,$14,$05,
365 $05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,
366 $05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05
367 );
369 const kgiFont8PropWidth: array[0..256-1] of Byte = (
370 $08,$08,$08,$07,$07,$07,$07,$06,$08,$07,$08,$08,$07,$08,$08,$08,
371 $07,$07,$07,$07,$08,$08,$07,$08,$07,$07,$07,$07,$07,$08,$08,$08,
372 $85,$14,$15,$07,$06,$07,$07,$03,$14,$14,$08,$06,$13,$06,$22,$07,
373 $05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$22,$13,$05,$06,$15,$06,
374 $07,$06,$07,$07,$07,$07,$07,$07,$06,$14,$07,$07,$07,$07,$07,$07,
375 $07,$06,$07,$06,$06,$06,$06,$07,$07,$06,$07,$14,$07,$14,$07,$08,
376 $23,$07,$07,$06,$07,$06,$06,$07,$07,$14,$05,$07,$14,$07,$06,$06,
377 $07,$07,$06,$06,$15,$07,$06,$07,$07,$06,$06,$06,$32,$06,$07,$07,
378 $06,$07,$06,$08,$07,$07,$07,$07,$08,$06,$06,$06,$07,$05,$06,$06,
379 $06,$08,$07,$06,$06,$06,$07,$07,$06,$07,$06,$07,$07,$06,$07,$08,
380 $07,$05,$06,$07,$06,$06,$16,$16,$06,$06,$06,$08,$08,$06,$08,$08,
381 $08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,
382 $38,$08,$08,$38,$08,$08,$38,$28,$28,$28,$08,$08,$28,$08,$08,$08,
383 $08,$08,$08,$28,$38,$38,$28,$08,$08,$08,$38,$08,$08,$08,$48,$08,
384 $07,$06,$07,$07,$07,$07,$07,$07,$06,$07,$07,$06,$08,$08,$06,$06,
385 $06,$06,$06,$06,$35,$05,$06,$07,$15,$32,$32,$08,$15,$15,$24,$08
386 );
389 function createFontTexture (constref font: array of Byte; constref fontwdt: array of Byte; prop: Boolean): GLuint;
390 const
391 Width = 16*8;
392 Height = 16*8;
393 var
394 tex, tpp: PByte;
395 b: Byte;
396 cc: Integer;
397 x, y, dx, dy: Integer;
398 begin
399 GetMem(tex, Width*Height*4);
401 for cc := 0 to 255 do
402 begin
403 x := (cc mod 16)*8;
404 y := (cc div 16)*8;
405 for dy := 0 to 7 do
406 begin
407 b := font[cc*8+dy];
408 if prop then b := b shl (fontwdt[cc] shr 4);
409 tpp := tex+((y+dy)*(Width*4))+x*4;
410 for dx := 0 to 7 do
411 begin
412 if ((b and $80) <> 0) then
413 begin
414 tpp^ := 255; Inc(tpp);
415 tpp^ := 255; Inc(tpp);
416 tpp^ := 255; Inc(tpp);
417 tpp^ := 255; Inc(tpp);
418 end
419 else
420 begin
421 tpp^ := 0; Inc(tpp);
422 tpp^ := 0; Inc(tpp);
423 tpp^ := 0; Inc(tpp);
424 tpp^ := 0; Inc(tpp);
425 end;
426 b := (b and $7f) shl 1;
427 end;
428 end;
429 end;
431 glGenTextures(1, @result);
432 if (result = 0) then raise Exception.Create('can''t create Holmes font texture');
434 glBindTexture(GL_TEXTURE_2D, result);
435 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
436 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
437 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
438 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
440 //GLfloat[4] bclr = 0.0;
441 //glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, bclr.ptr);
443 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA{gltt}, GL_UNSIGNED_BYTE, tex);
444 glFlush();
446 //FreeMem(tex);
447 end;
450 var
451 font6texid: GLuint = 0;
452 font8texid: GLuint = 0;
453 prfont6texid: GLuint = 0;
454 prfont8texid: GLuint = 0;
456 procedure createFonts ();
457 begin
458 if (font6texid = 0) then font6texid := createFontTexture(kgiFont6, kgiFont6PropWidth, false);
459 if (font8texid = 0) then font8texid := createFontTexture(kgiFont8, kgiFont8PropWidth, false);
460 if (prfont6texid = 0) then prfont6texid := createFontTexture(kgiFont6, kgiFont6PropWidth, true);
461 if (prfont8texid = 0) then prfont8texid := createFontTexture(kgiFont8, kgiFont8PropWidth, true);
462 end;
465 // ////////////////////////////////////////////////////////////////////////// //
466 procedure normRGBA (var r, g, b, a: Integer); inline;
467 begin
468 if (a < 0) then a := 0 else if (a > 255) then a := 255;
469 if (r < 0) then r := 0 else if (r > 255) then r := 255;
470 if (g < 0) then g := 0 else if (g > 255) then g := 255;
471 if (b < 0) then b := 0 else if (b > 255) then b := 255;
472 end;
474 // returns `false` if the color is transparent
475 function setupGLColor (r, g, b, a: Integer): Boolean;
476 begin
477 normRGBA(r, g, b, a);
478 if (a < 255) then
479 begin
480 if (a = 0) then begin result := false; exit; end;
481 glEnable(GL_BLEND);
482 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
483 end
484 else
485 begin
486 glDisable(GL_BLEND);
487 end;
488 glColor4ub(Byte(r), Byte(g), Byte(b), Byte(a));
489 result := true;
490 end;
492 function isScaled (): Boolean;
493 var
494 mt: packed array [0..15] of Double;
495 begin
496 glGetDoublev(GL_MODELVIEW_MATRIX, @mt[0]);
497 result := (mt[0] <> 1.0) or (mt[1*4+1] <> 1.0);
498 end;
501 // ////////////////////////////////////////////////////////////////////////// //
502 function textWidth6 (const s: AnsiString): Integer;
503 var
504 f: Integer;
505 begin
506 result := 0;
507 for f := 1 to Length(s) do Inc(result, Integer(kgiFont6PropWidth[Integer(s[f])] and $0f)+1);
508 if (result > 0) then Dec(result); // don't count last empty pixel
509 end;
512 function textWidth8 (const s: AnsiString): Integer;
513 var
514 f: Integer;
515 begin
516 result := 0;
517 for f := 1 to Length(s) do Inc(result, Integer(kgiFont8PropWidth[Integer(s[f])] and $0f)+1);
518 if (result > 0) then Dec(result); // don't count last empty pixel
519 end;
522 // return width (including last empty pixel)
523 function drawTextInternal (wdt, x, y: Integer; const s: AnsiString; r, g, b: Integer; a: Integer; tid: GLuint; constref fontwdt: array of Byte; prop: Boolean): Integer;
524 var
525 f, c: Integer;
526 tx, ty: Integer;
527 begin
528 result := 0;
529 if (Length(s) = 0) then exit;
530 if not setupGLColor(r, g, b, a) then exit;
531 glEnable(GL_ALPHA_TEST);
532 glAlphaFunc(GL_NOTEQUAL, 0.0);
533 glEnable(GL_TEXTURE_2D);
534 // color and opacity
535 glBindTexture(GL_TEXTURE_2D, tid);
537 for f := 1 to Length(s) do
538 begin
539 c := Integer(s[f]) and $ff;
540 tx := (c mod 16)*8;
541 ty := (c div 16)*8;
542 glBegin(GL_QUADS);
543 glTexCoord2f((tx+0)/128.0, (ty+0)/128.0); glVertex2i(x+0, y+0); // top-left
544 glTexCoord2f((tx+8)/128.0, (ty+0)/128.0); glVertex2i(x+8, y+0); // top-right
545 glTexCoord2f((tx+8)/128.0, (ty+8)/128.0); glVertex2i(x+8, y+8); // bottom-right
546 glTexCoord2f((tx+0)/128.0, (ty+8)/128.0); glVertex2i(x+0, y+8); // bottom-left
547 glEnd();
548 if prop then
549 begin
550 x += Integer(fontwdt[c] and $0f)+1;
551 result += Integer(fontwdt[c] and $0f)+1;
552 end
553 else
554 begin
555 x += wdt;
556 result += wdt;
557 end;
558 end;
560 glDisable(GL_ALPHA_TEST);
561 glDisable(GL_BLEND);
562 glDisable(GL_TEXTURE_2D);
563 glColor4f(1, 1, 1, 1);
564 glBindTexture(GL_TEXTURE_2D, 0);
565 end;
568 // ////////////////////////////////////////////////////////////////////////// //
569 procedure drawHLine (x, y, len: Integer; r, g, b: Integer; a: Integer=255);
570 begin
571 if (len < 1) then exit;
572 if not setupGLColor(r, g, b, a) then exit;
573 glDisable(GL_TEXTURE_2D);
574 if (not isScaled) then
575 begin
576 glBegin(GL_LINES);
577 glVertex2f(x+0.375, y+0.375);
578 glVertex2f(x+len+0.375, y+0.375);
579 glEnd();
580 end
581 else
582 begin
583 glBegin(GL_QUADS);
584 glVertex2i(x, y);
585 glVertex2i(x+len, y);
586 glVertex2i(x+len, y+1);
587 glVertex2i(x, y+1);
588 glEnd();
589 end;
590 end;
593 procedure drawVLine (x, y, len: Integer; r, g, b: Integer; a: Integer=255);
594 begin
595 if (len < 1) then exit;
596 if not setupGLColor(r, g, b, a) then exit;
597 glDisable(GL_TEXTURE_2D);
598 if (not isScaled) then
599 begin
600 glBegin(GL_LINES);
601 glVertex2f(x+0.375, y+0.375);
602 glVertex2f(x+0.375, y+len+0.375);
603 glEnd();
604 end
605 else
606 begin
607 glBegin(GL_QUADS);
608 glVertex2i(x, y);
609 glVertex2i(x, y+len);
610 glVertex2i(x+1, y+len);
611 glVertex2i(x+1, y);
612 glEnd();
613 end;
614 end;
617 procedure drawLine (x1, y1, x2, y2: Integer; r, g, b: Integer; a: Integer=255);
618 begin
619 if not setupGLColor(r, g, b, a) then exit;
621 glDisable(GL_TEXTURE_2D);
623 glLineWidth(1);
624 glPointSize(1);
626 glBegin(GL_LINES);
627 glVertex2f(x1+0.37, y1+0.37);
628 glVertex2f(x2+0.37, y2+0.37);
629 glEnd();
631 if (x1 <> x2) or (y1 <> y2) then
632 begin
633 glBegin(GL_POINTS);
634 glVertex2f(x2+0.37, y2+0.37);
635 glEnd();
636 end;
638 glColor4f(1, 1, 1, 1);
639 glDisable(GL_BLEND);
640 end;
643 procedure drawRect (x, y, w, h: Integer; r, g, b: Integer; a: Integer=255);
644 begin
645 if (w < 0) or (h < 0) then exit;
646 if not setupGLColor(r, g, b, a) then exit;
647 glDisable(GL_TEXTURE_2D);
648 glLineWidth(1);
649 glDisable(GL_LINE_SMOOTH);
650 glDisable(GL_POLYGON_SMOOTH);
651 if (w = 1) and (h = 1) then
652 begin
653 glBegin(GL_POINTS);
654 glVertex2f(x+0.37, y+0.37);
655 glEnd();
656 end
657 else
658 begin
659 glBegin(GL_LINES);
660 glVertex2i(x, y); glVertex2i(x+w, y); // top
661 glVertex2i(x, y+h-1); glVertex2i(x+w, y+h-1); // bottom
662 glVertex2f(x+0.37, y+1); glVertex2f(x+0.37, y+h-1); // left
663 glVertex2f(x+w-1+0.37, y+1); glVertex2f(x+w-1+0.37, y+h-1); // right
664 glEnd();
665 end;
666 //glRect(x, y, x+w, y+h);
667 glColor4f(1, 1, 1, 1);
668 glDisable(GL_BLEND);
669 end;
672 procedure drawRectUI (x, y, w, h: Integer; r, g, b: Integer; a: Integer=255);
673 procedure hline (x, y, len: Integer);
674 begin
675 if (len < 1) then exit;
676 glBegin(GL_QUADS);
677 glVertex2i(x, y);
678 glVertex2i(x+len, y);
679 glVertex2i(x+len, y+1);
680 glVertex2i(x, y+1);
681 glEnd();
682 end;
684 procedure vline (x, y, len: Integer);
685 begin
686 if (len < 1) then exit;
687 glBegin(GL_QUADS);
688 glVertex2i(x, y);
689 glVertex2i(x, y+len);
690 glVertex2i(x+1, y+len);
691 glVertex2i(x+1, y);
692 glEnd();
693 end;
695 var
696 scaled: Boolean;
697 begin
698 if (w < 0) or (h < 0) then exit;
699 if not setupGLColor(r, g, b, a) then exit;
700 glDisable(GL_TEXTURE_2D);
701 glLineWidth(1);
702 glDisable(GL_LINE_SMOOTH);
703 glDisable(GL_POLYGON_SMOOTH);
704 scaled := isScaled();
705 if (w = 1) and (h = 1) then
706 begin
707 glBegin(GL_POINTS);
708 if scaled then glVertex2i(x, y) else glVertex2f(x+0.375, y+0.375);
709 glEnd();
710 end
711 else
712 begin
713 if not scaled then
714 begin
715 glBegin(GL_LINES);
716 glVertex2i(x, y); glVertex2i(x+w, y); // top
717 glVertex2i(x, y+h-1); glVertex2i(x+w, y+h-1); // bottom
718 glVertex2f(x+0.375, y+1); glVertex2f(x+0.375, y+h-1); // left
719 glVertex2f(x+w-1+0.375, y+1); glVertex2f(x+w-1+0.375, y+h-1); // right
720 glEnd();
721 end
722 else
723 begin
724 hline(x, y, w);
725 hline(x, y+h-1, w);
726 vline(x, y+1, h-2);
727 vline(x+w-1, y+1, h-2);
728 end;
729 end;
730 //glRect(x, y, x+w, y+h);
731 glColor4f(1, 1, 1, 1);
732 glDisable(GL_BLEND);
733 end;
736 procedure darkenRect (x, y, w, h: Integer; a: Integer);
737 begin
738 if (w < 0) or (h < 0) then exit;
739 if (a < 0) then a := 0;
740 if (a >= 255) then exit;
741 glEnable(GL_BLEND);
742 glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
743 glDisable(GL_LINE_SMOOTH);
744 glDisable(GL_POLYGON_SMOOTH);
745 glDisable(GL_TEXTURE_2D);
746 glColor4ub(0, 0, 0, Byte(a));
747 glBegin(GL_QUADS);
748 glVertex2i(x, y);
749 glVertex2i(x+w, y);
750 glVertex2i(x+w, y+h);
751 glVertex2i(x, y+h);
752 glEnd();
753 //glRect(x, y, x+w, y+h);
754 glColor4f(1, 1, 1, 1);
755 glDisable(GL_BLEND);
756 //glBlendEquation(GL_FUNC_ADD);
757 end;
760 procedure fillRect (x, y, w, h: Integer; r, g, b: Integer; a: Integer=255);
761 begin
762 if (w < 0) or (h < 0) then exit;
763 if not setupGLColor(r, g, b, a) then exit;
764 glDisable(GL_LINE_SMOOTH);
765 glDisable(GL_POLYGON_SMOOTH);
766 glDisable(GL_TEXTURE_2D);
767 glBegin(GL_QUADS);
768 glVertex2f(x, y);
769 glVertex2f(x+w, y);
770 glVertex2f(x+w, y+h);
771 glVertex2f(x, y+h);
772 glEnd();
773 glColor4f(1, 1, 1, 1);
774 glDisable(GL_BLEND);
775 end;
778 // ////////////////////////////////////////////////////////////////////////// //
779 function drawText6 (x, y: Integer; const s: AnsiString; r, g, b: Integer; a: Integer=255): Integer;
780 begin
781 if (font6texid = 0) then createFonts();
782 drawTextInternal(6, x, y, s, r, g, b, a, font6texid, kgiFont6PropWidth, false);
783 result := Length(s)*6;
784 end;
786 function drawText8 (x, y: Integer; const s: AnsiString; r, g, b: Integer; a: Integer=255): Integer;
787 begin
788 if (font8texid = 0) then createFonts();
789 drawTextInternal(8, x, y, s, r, g, b, a, font8texid, kgiFont8PropWidth, false);
790 result := Length(s)*8;
791 end;
793 function drawText6Prop (x, y: Integer; const s: AnsiString; r, g, b: Integer; a: Integer=255): Integer;
794 begin
795 if (prfont6texid = 0) then createFonts();
796 result := drawTextInternal(6, x, y, s, r, g, b, a, prfont6texid, kgiFont6PropWidth, true);
797 end;
799 function drawText8Prop (x, y: Integer; const s: AnsiString; r, g, b: Integer; a: Integer=255): Integer;
800 begin
801 if (prfont8texid = 0) then createFonts();
802 result := drawTextInternal(8, x, y, s, r, g, b, a, prfont8texid, kgiFont8PropWidth, true);
803 end;
806 // ////////////////////////////////////////////////////////////////////////// //
807 // x-centered at `x`
808 function drawText6XC (x, y: Integer; const s: AnsiString; r, g, b: Integer; a: Integer=255): Integer;
809 begin
810 if (font6texid = 0) then createFonts();
811 x -= Length(s)*6 div 2;
812 drawTextInternal(6, x, y, s, r, g, b, a, font6texid, kgiFont6PropWidth, false);
813 result := Length(s)*6;
814 end;
816 function drawText8XC (x, y: Integer; const s: AnsiString; r, g, b: Integer; a: Integer=255): Integer;
817 begin
818 if (font8texid = 0) then createFonts();
819 x -= Length(s)*8 div 2;
820 drawTextInternal(8, x, y, s, r, g, b, a, font8texid, kgiFont8PropWidth, false);
821 result := Length(s)*8;
822 end;
824 function drawText6PropXC (x, y: Integer; const s: AnsiString; r, g, b: Integer; a: Integer=255): Integer;
825 begin
826 if (prfont6texid = 0) then createFonts();
827 x -= textWidth6(s) div 2;
828 result := drawTextInternal(6, x, y, s, r, g, b, a, prfont6texid, kgiFont6PropWidth, true);
829 end;
831 function drawText8PropXC (x, y: Integer; const s: AnsiString; r, g, b: Integer; a: Integer=255): Integer;
832 begin
833 if (prfont8texid = 0) then createFonts();
834 x -= textWidth8(s) div 2;
835 result := drawTextInternal(8, x, y, s, r, g, b, a, prfont8texid, kgiFont8PropWidth, true);
836 end;
839 // ////////////////////////////////////////////////////////////////////////// //
840 function monsTypeToString (mt: Byte): AnsiString;
841 begin
842 case mt of
843 MONSTER_NONE: begin result := 'none'; exit; end;
844 MONSTER_DEMON: begin result := 'demon'; exit; end;
845 MONSTER_IMP: begin result := 'imp'; exit; end;
846 MONSTER_ZOMBY: begin result := 'zombie'; exit; end;
847 MONSTER_SERG: begin result := 'serg'; exit; end;
848 MONSTER_CYBER: begin result := 'cyber'; exit; end;
849 MONSTER_CGUN: begin result := 'cgun'; exit; end;
850 MONSTER_BARON: begin result := 'baron'; exit; end;
851 MONSTER_KNIGHT: begin result := 'knight'; exit; end;
852 MONSTER_CACO: begin result := 'caco'; exit; end;
853 MONSTER_SOUL: begin result := 'soul'; exit; end;
854 MONSTER_PAIN: begin result := 'pain'; exit; end;
855 MONSTER_SPIDER: begin result := 'spider'; exit; end;
856 MONSTER_BSP: begin result := 'bsp'; exit; end;
857 MONSTER_MANCUB: begin result := 'mancubus'; exit; end;
858 MONSTER_SKEL: begin result := 'skel'; exit; end;
859 MONSTER_VILE: begin result := 'vile'; exit; end;
860 MONSTER_FISH: begin result := 'fish'; exit; end;
861 MONSTER_BARREL: begin result := 'barrel'; exit; end;
862 MONSTER_ROBO: begin result := 'robo'; exit; end;
863 MONSTER_MAN: begin result := 'man'; exit; end;
864 end;
865 result := 'unknown';
866 end;
869 function monsBehToString (bt: Byte): AnsiString;
870 begin
871 case bt of
872 BH_NORMAL: begin result := 'normal'; exit; end;
873 BH_KILLER: begin result := 'killer'; exit; end;
874 BH_MANIAC: begin result := 'maniac'; exit; end;
875 BH_INSANE: begin result := 'insane'; exit; end;
876 BH_CANNIBAL: begin result := 'cannibal'; exit; end;
877 BH_GOOD: begin result := 'good'; exit; end;
878 end;
879 result := 'unknown';
880 end;
883 function monsStateToString (st: Byte): AnsiString;
884 begin
885 case st of
886 MONSTATE_SLEEP: begin result := 'sleep'; exit; end;
887 MONSTATE_GO: begin result := 'go'; exit; end;
888 MONSTATE_RUN: begin result := 'run'; exit; end;
889 MONSTATE_CLIMB: begin result := 'climb'; exit; end;
890 MONSTATE_DIE: begin result := 'die'; exit; end;
891 MONSTATE_DEAD: begin result := 'dead'; exit; end;
892 MONSTATE_ATTACK: begin result := 'attack'; exit; end;
893 MONSTATE_SHOOT: begin result := 'shoot'; exit; end;
894 MONSTATE_PAIN: begin result := 'pain'; exit; end;
895 MONSTATE_WAIT: begin result := 'wait'; exit; end;
896 MONSTATE_REVIVE: begin result := 'revive'; exit; end;
897 MONSTATE_RUNOUT: begin result := 'runout'; exit; end;
898 end;
899 result := 'unknown';
900 end;