author | koda |
Thu, 17 Mar 2011 23:53:33 +0100 | |
changeset 5019 | e38d1720a0ff |
parent 4976 | 088d40d8aba2 |
child 5235 | e30b06ffea3a |
permissions | -rw-r--r-- |
4976 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
18 |
||
4378 | 19 |
{$INCLUDE "options.inc"} |
4976 | 20 |
|
4378 | 21 |
unit uRender; |
22 |
||
23 |
interface |
|
24 |
||
25 |
uses SDLh, uTypes, GLunit; |
|
26 |
||
27 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
|
28 |
procedure DrawFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
|
29 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
|
30 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
|
31 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
|
32 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
|
33 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat = 1.0); |
|
34 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt); |
|
35 |
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
|
36 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
|
37 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
|
38 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
|
39 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
|
40 |
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte); |
|
41 |
procedure DrawFillRect(r: TSDL_Rect); |
|
4420
6be946bcd17a
Add a visual gear for drawing circles. Intent is to allow specifying areas on map for lua scripts (such as to indicate a location to go to). Could also be used to, say, circle a hog in CTF. Also add a "Critical" flag for visual gears so a gear flagges as such will always be created.
nemo
parents:
4385
diff
changeset
|
42 |
procedure DrawCircle(X, Y, Radius, Width: LongInt; r, g, b, a: Byte); |
4451
1c342980b4aa
trying to get tint to behave more as I expect. need to ask Smaxx what he intended here, to avoid too many pointless colour calls
nemo
parents:
4420
diff
changeset
|
43 |
procedure DrawCircle(X, Y, Radius, Width: LongInt); |
4385 | 44 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
4378 | 45 |
procedure Tint(r, g, b, a: Byte); inline; |
46 |
procedure Tint(c: Longword); inline; |
|
47 |
||
4385 | 48 |
var |
49 |
HHTexture: PTexture; |
|
50 |
||
4378 | 51 |
implementation |
52 |
uses uVariables; |
|
53 |
var |
|
54 |
lastTint: Longword; |
|
55 |
||
56 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
|
57 |
begin |
|
58 |
r.y:= r.y + Height * Position; |
|
59 |
r.h:= Height; |
|
60 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
|
61 |
end; |
|
62 |
||
63 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
|
64 |
begin |
|
65 |
DrawFromRect(X, Y, r^.w, r^.h, r, SourceTexture) |
|
66 |
end; |
|
67 |
||
68 |
procedure DrawFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
|
69 |
var rr: TSDL_Rect; |
|
70 |
_l, _r, _t, _b: real; |
|
71 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
|
72 |
begin |
|
73 |
if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit; |
|
74 |
||
75 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
76 |
if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then |
|
77 |
exit; |
|
78 |
if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) > cScreenHeight / cScaleFactor) then |
|
79 |
exit; |
|
80 |
||
81 |
rr.x:= X; |
|
82 |
rr.y:= Y; |
|
83 |
rr.w:= W; |
|
84 |
rr.h:= H; |
|
85 |
||
86 |
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx; |
|
87 |
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx; |
|
88 |
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry; |
|
89 |
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry; |
|
90 |
||
91 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
92 |
||
93 |
VertexBuffer[0].X:= X; |
|
94 |
VertexBuffer[0].Y:= Y; |
|
95 |
VertexBuffer[1].X:= rr.w + X; |
|
96 |
VertexBuffer[1].Y:= Y; |
|
97 |
VertexBuffer[2].X:= rr.w + X; |
|
98 |
VertexBuffer[2].Y:= rr.h + Y; |
|
99 |
VertexBuffer[3].X:= X; |
|
100 |
VertexBuffer[3].Y:= rr.h + Y; |
|
101 |
||
102 |
TextureBuffer[0].X:= _l; |
|
103 |
TextureBuffer[0].Y:= _t; |
|
104 |
TextureBuffer[1].X:= _r; |
|
105 |
TextureBuffer[1].Y:= _t; |
|
106 |
TextureBuffer[2].X:= _r; |
|
107 |
TextureBuffer[2].Y:= _b; |
|
108 |
TextureBuffer[3].X:= _l; |
|
109 |
TextureBuffer[3].Y:= _b; |
|
110 |
||
111 |
||
112 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
113 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
114 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
115 |
end; |
|
116 |
||
117 |
||
118 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat); |
|
119 |
begin |
|
120 |
||
121 |
glPushMatrix; |
|
122 |
glTranslatef(X, Y, 0); |
|
123 |
glScalef(Scale, Scale, 1); |
|
124 |
||
125 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
126 |
||
127 |
glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb); |
|
128 |
glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb); |
|
129 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); |
|
130 |
||
131 |
glPopMatrix |
|
132 |
end; |
|
133 |
||
134 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt); |
|
135 |
begin |
|
136 |
DrawRotatedTextureF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0) |
|
137 |
end; |
|
138 |
||
139 |
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
|
140 |
var ft, fb, fl, fr: GLfloat; |
|
141 |
hw, nx, ny: LongInt; |
|
142 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
|
143 |
begin |
|
144 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
145 |
if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * cScaleFactor > cScreenWidth) then |
|
146 |
exit; |
|
147 |
if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then |
|
148 |
exit; |
|
149 |
||
150 |
glPushMatrix; |
|
151 |
glTranslatef(X, Y, 0); |
|
152 |
||
153 |
if Dir < 0 then |
|
154 |
glRotatef(Angle, 0, 0, -1) |
|
155 |
else |
|
156 |
glRotatef(Angle, 0, 0, 1); |
|
157 |
||
158 |
glTranslatef(Dir*OffsetX, OffsetY, 0); |
|
159 |
glScalef(Scale, Scale, 1); |
|
160 |
||
161 |
// Any reason for this call? And why only in t direction, not s? |
|
162 |
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
|
163 |
||
164 |
if Dir < 0 then |
|
165 |
hw:= w div -2 |
|
166 |
else |
|
167 |
hw:= w div 2; |
|
168 |
||
169 |
nx:= round(Texture^.w / w); // number of horizontal frames |
|
170 |
ny:= round(Texture^.h / h); // number of vertical frames |
|
171 |
||
172 |
ft:= (Frame mod ny) * Texture^.ry / ny; |
|
173 |
fb:= ((Frame mod ny) + 1) * Texture^.ry / ny; |
|
174 |
fl:= (Frame div ny) * Texture^.rx / nx; |
|
175 |
fr:= ((Frame div ny) + 1) * Texture^.rx / nx; |
|
176 |
||
177 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
178 |
||
179 |
VertexBuffer[0].X:= -hw; |
|
180 |
VertexBuffer[0].Y:= w / -2; |
|
181 |
VertexBuffer[1].X:= hw; |
|
182 |
VertexBuffer[1].Y:= w / -2; |
|
183 |
VertexBuffer[2].X:= hw; |
|
184 |
VertexBuffer[2].Y:= w / 2; |
|
185 |
VertexBuffer[3].X:= -hw; |
|
186 |
VertexBuffer[3].Y:= w / 2; |
|
187 |
||
188 |
TextureBuffer[0].X:= fl; |
|
189 |
TextureBuffer[0].Y:= ft; |
|
190 |
TextureBuffer[1].X:= fr; |
|
191 |
TextureBuffer[1].Y:= ft; |
|
192 |
TextureBuffer[2].X:= fr; |
|
193 |
TextureBuffer[2].Y:= fb; |
|
194 |
TextureBuffer[3].X:= fl; |
|
195 |
TextureBuffer[3].Y:= fb; |
|
196 |
||
197 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
198 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
199 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
200 |
||
201 |
glPopMatrix |
|
202 |
end; |
|
203 |
||
204 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
|
205 |
begin |
|
206 |
DrawRotatedTex(SpritesData[Sprite].Texture, |
|
207 |
SpritesData[Sprite].Width, |
|
208 |
SpritesData[Sprite].Height, |
|
209 |
X, Y, Dir, Angle) |
|
210 |
end; |
|
211 |
||
212 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
|
213 |
begin |
|
214 |
glPushMatrix; |
|
215 |
glTranslatef(X, Y, 0); |
|
216 |
||
217 |
if Dir < 0 then |
|
218 |
glRotatef(Angle, 0, 0, -1) |
|
219 |
else |
|
220 |
glRotatef(Angle, 0, 0, 1); |
|
221 |
if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
|
222 |
||
223 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
224 |
||
225 |
glPopMatrix |
|
226 |
end; |
|
227 |
||
228 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
|
229 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
230 |
begin |
|
231 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
232 |
if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then |
|
233 |
exit; |
|
234 |
if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then |
|
235 |
exit; |
|
236 |
||
237 |
glPushMatrix; |
|
238 |
glTranslatef(X, Y, 0); |
|
239 |
||
240 |
if Dir < 0 then |
|
241 |
begin |
|
242 |
hw:= - hw; |
|
243 |
glRotatef(Angle, 0, 0, -1); |
|
244 |
end else |
|
245 |
glRotatef(Angle, 0, 0, 1); |
|
246 |
||
247 |
||
248 |
glBindTexture(GL_TEXTURE_2D, Tex^.id); |
|
249 |
||
250 |
VertexBuffer[0].X:= -hw; |
|
251 |
VertexBuffer[0].Y:= -hh; |
|
252 |
VertexBuffer[1].X:= hw; |
|
253 |
VertexBuffer[1].Y:= -hh; |
|
254 |
VertexBuffer[2].X:= hw; |
|
255 |
VertexBuffer[2].Y:= hh; |
|
256 |
VertexBuffer[3].X:= -hw; |
|
257 |
VertexBuffer[3].Y:= hh; |
|
258 |
||
259 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
260 |
glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb); |
|
261 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
262 |
||
263 |
glPopMatrix |
|
264 |
end; |
|
265 |
||
266 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
|
267 |
var row, col, numFramesFirstCol: LongInt; |
|
268 |
begin |
|
269 |
numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height; |
|
270 |
row:= Frame mod numFramesFirstCol; |
|
271 |
col:= Frame div numFramesFirstCol; |
|
272 |
DrawSprite2 (Sprite, X, Y, col, row); |
|
273 |
end; |
|
274 |
||
275 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
|
276 |
var r: TSDL_Rect; |
|
277 |
begin |
|
278 |
r.x:= 0; |
|
279 |
r.y:= 0; |
|
280 |
r.w:= SpritesData[Sprite].Width; |
|
281 |
r.h:= SpritesData[Sprite].Height; |
|
282 |
||
283 |
if (X < LeftX) then |
|
284 |
r.x:= LeftX - X; |
|
285 |
if (Y < TopY) then |
|
286 |
r.y:= TopY - Y; |
|
287 |
||
288 |
if (Y + SpritesData[Sprite].Height > BottomY) then |
|
289 |
r.h:= BottomY - Y + 1; |
|
290 |
if (X + SpritesData[Sprite].Width > RightX) then |
|
291 |
r.w:= RightX - X + 1; |
|
292 |
||
293 |
dec(r.h, r.y); |
|
294 |
dec(r.w, r.x); |
|
295 |
||
296 |
DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture) |
|
297 |
end; |
|
298 |
||
299 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
|
300 |
var r: TSDL_Rect; |
|
301 |
begin |
|
302 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
303 |
r.w:= SpritesData[Sprite].Width; |
|
304 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
305 |
r.h:= SpritesData[Sprite].Height; |
|
306 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
|
307 |
end; |
|
308 |
||
309 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
|
310 |
var scale: GLfloat; |
|
311 |
begin |
|
312 |
if (Source^.w + 20) > cScreenWidth then |
|
313 |
scale:= cScreenWidth / (Source^.w + 20) |
|
314 |
else |
|
315 |
scale:= 1.0; |
|
316 |
DrawTexture(X - round(Source^.w * scale) div 2, Top, Source, scale) |
|
317 |
end; |
|
318 |
||
319 |
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte); |
|
320 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
321 |
begin |
|
322 |
glDisable(GL_TEXTURE_2D); |
|
323 |
glEnable(GL_LINE_SMOOTH); |
|
324 |
||
325 |
glPushMatrix; |
|
326 |
glTranslatef(WorldDx, WorldDy, 0); |
|
327 |
glLineWidth(Width); |
|
328 |
||
329 |
Tint(r, g, b, a); |
|
330 |
VertexBuffer[0].X:= X0; |
|
331 |
VertexBuffer[0].Y:= Y0; |
|
332 |
VertexBuffer[1].X:= X1; |
|
333 |
VertexBuffer[1].Y:= Y1; |
|
334 |
||
335 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
336 |
glDrawArrays(GL_LINES, 0, Length(VertexBuffer)); |
|
337 |
Tint($FF, $FF, $FF, $FF); |
|
338 |
||
339 |
glPopMatrix; |
|
340 |
||
341 |
glEnable(GL_TEXTURE_2D); |
|
342 |
glDisable(GL_LINE_SMOOTH); |
|
343 |
end; |
|
344 |
||
345 |
procedure DrawFillRect(r: TSDL_Rect); |
|
346 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
347 |
begin |
|
348 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
349 |
if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) * cScaleFactor > cScreenWidth) then |
|
350 |
exit; |
|
351 |
if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) * cScaleFactor > cScreenHeight) then |
|
352 |
exit; |
|
353 |
||
354 |
glDisable(GL_TEXTURE_2D); |
|
355 |
||
356 |
Tint($00, $00, $00, $80); |
|
357 |
||
358 |
VertexBuffer[0].X:= r.x; |
|
359 |
VertexBuffer[0].Y:= r.y; |
|
360 |
VertexBuffer[1].X:= r.x + r.w; |
|
361 |
VertexBuffer[1].Y:= r.y; |
|
362 |
VertexBuffer[2].X:= r.x + r.w; |
|
363 |
VertexBuffer[2].Y:= r.y + r.h; |
|
364 |
VertexBuffer[3].X:= r.x; |
|
365 |
VertexBuffer[3].Y:= r.y + r.h; |
|
366 |
||
367 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
368 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
369 |
||
370 |
Tint($FF, $FF, $FF, $FF); |
|
371 |
glEnable(GL_TEXTURE_2D) |
|
372 |
end; |
|
373 |
||
4420
6be946bcd17a
Add a visual gear for drawing circles. Intent is to allow specifying areas on map for lua scripts (such as to indicate a location to go to). Could also be used to, say, circle a hog in CTF. Also add a "Critical" flag for visual gears so a gear flagges as such will always be created.
nemo
parents:
4385
diff
changeset
|
374 |
procedure DrawCircle(X, Y, Radius, Width: LongInt; r, g, b, a: Byte); |
4451
1c342980b4aa
trying to get tint to behave more as I expect. need to ask Smaxx what he intended here, to avoid too many pointless colour calls
nemo
parents:
4420
diff
changeset
|
375 |
begin |
1c342980b4aa
trying to get tint to behave more as I expect. need to ask Smaxx what he intended here, to avoid too many pointless colour calls
nemo
parents:
4420
diff
changeset
|
376 |
Tint(r, g, b, a); |
1c342980b4aa
trying to get tint to behave more as I expect. need to ask Smaxx what he intended here, to avoid too many pointless colour calls
nemo
parents:
4420
diff
changeset
|
377 |
DrawCircle(X, Y, Radius, Width); |
1c342980b4aa
trying to get tint to behave more as I expect. need to ask Smaxx what he intended here, to avoid too many pointless colour calls
nemo
parents:
4420
diff
changeset
|
378 |
Tint($FF, $FF, $FF, $FF); |
1c342980b4aa
trying to get tint to behave more as I expect. need to ask Smaxx what he intended here, to avoid too many pointless colour calls
nemo
parents:
4420
diff
changeset
|
379 |
end; |
1c342980b4aa
trying to get tint to behave more as I expect. need to ask Smaxx what he intended here, to avoid too many pointless colour calls
nemo
parents:
4420
diff
changeset
|
380 |
|
1c342980b4aa
trying to get tint to behave more as I expect. need to ask Smaxx what he intended here, to avoid too many pointless colour calls
nemo
parents:
4420
diff
changeset
|
381 |
procedure DrawCircle(X, Y, Radius, Width: LongInt); |
4378 | 382 |
var |
383 |
i: LongInt; |
|
384 |
CircleVertex: array [0..359] of TVertex2f; |
|
385 |
begin |
|
386 |
for i := 0 to 359 do begin |
|
387 |
CircleVertex[i].X := X + Radius*cos(i*pi/180); |
|
388 |
CircleVertex[i].Y := Y + Radius*sin(i*pi/180); |
|
389 |
end; |
|
390 |
glDisable(GL_TEXTURE_2D); |
|
391 |
glEnable(GL_LINE_SMOOTH); |
|
392 |
glPushMatrix; |
|
393 |
glLineWidth(Width); |
|
394 |
glVertexPointer(2, GL_FLOAT, 0, @CircleVertex[0]); |
|
395 |
glDrawArrays(GL_LINE_LOOP, 0, 360); |
|
396 |
glPopMatrix; |
|
397 |
glEnable(GL_TEXTURE_2D); |
|
398 |
glDisable(GL_LINE_SMOOTH); |
|
399 |
end; |
|
400 |
||
401 |
||
4385 | 402 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
403 |
const VertexBuffer: array [0..3] of TVertex2f = ( |
|
404 |
(x: -16; y: -16), |
|
405 |
(x: 16; y: -16), |
|
406 |
(x: 16; y: 16), |
|
407 |
(x: -16; y: 16)); |
|
408 |
var l, r, t, b: real; |
|
409 |
TextureBuffer: array [0..3] of TVertex2f; |
|
410 |
begin |
|
411 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
412 |
if (abs(X) > 32) and ((abs(X) - 16) * cScaleFactor > cScreenWidth) then |
|
413 |
exit; |
|
414 |
if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) * cScaleFactor > cScreenHeight) then |
|
415 |
exit; |
|
416 |
||
417 |
t:= Pos * 32 / HHTexture^.h; |
|
418 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
419 |
||
420 |
if Dir = -1 then |
|
421 |
begin |
|
422 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
423 |
r:= Step * 32 / HHTexture^.w |
|
424 |
end else |
|
425 |
begin |
|
426 |
l:= Step * 32 / HHTexture^.w; |
|
427 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
428 |
end; |
|
429 |
||
430 |
||
431 |
glPushMatrix(); |
|
432 |
glTranslatef(X, Y, 0); |
|
433 |
glRotatef(Angle, 0, 0, 1); |
|
434 |
||
435 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
|
436 |
||
437 |
TextureBuffer[0].X:= l; |
|
438 |
TextureBuffer[0].Y:= t; |
|
439 |
TextureBuffer[1].X:= r; |
|
440 |
TextureBuffer[1].Y:= t; |
|
441 |
TextureBuffer[2].X:= r; |
|
442 |
TextureBuffer[2].Y:= b; |
|
443 |
TextureBuffer[3].X:= l; |
|
444 |
TextureBuffer[3].Y:= b; |
|
445 |
||
446 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
447 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
448 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
449 |
||
450 |
glPopMatrix |
|
451 |
end; |
|
452 |
||
453 |
||
4378 | 454 |
procedure Tint(r, g, b, a: Byte); inline; |
455 |
var nc: Longword; |
|
456 |
begin |
|
457 |
nc:= (a shl 24) or (b shl 16) or (g shl 8) or r; |
|
458 |
if nc = lastTint then |
|
459 |
exit; |
|
460 |
glColor4ub(r, g, b, a); |
|
461 |
lastTint:= nc; |
|
462 |
end; |
|
463 |
||
464 |
procedure Tint(c: Longword); inline; |
|
465 |
begin |
|
4452 | 466 |
Tint(((c shr 24) and $FF), ((c shr 16) and $FF), (c shr 8) and $FF, (c and $FF)) |
4378 | 467 |
end; |
468 |
||
469 |
end. |