author | nemo |
Tue, 28 Jun 2011 21:48:28 -0400 | |
changeset 5352 | 7f57d0c7816a |
parent 5235 | e30b06ffea3a |
child 5441 | 39962b855540 |
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 |
|
5235
e30b06ffea3a
Skip droplets if plain splash is enabled, add a sanity check just in case.
nemo
parents:
4976
diff
changeset
|
269 |
if SpritesData[Sprite].imageHeight = 0 then exit; |
4378 | 270 |
numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height; |
271 |
row:= Frame mod numFramesFirstCol; |
|
272 |
col:= Frame div numFramesFirstCol; |
|
273 |
DrawSprite2 (Sprite, X, Y, col, row); |
|
274 |
end; |
|
275 |
||
276 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
|
277 |
var r: TSDL_Rect; |
|
278 |
begin |
|
279 |
r.x:= 0; |
|
280 |
r.y:= 0; |
|
281 |
r.w:= SpritesData[Sprite].Width; |
|
282 |
r.h:= SpritesData[Sprite].Height; |
|
283 |
||
284 |
if (X < LeftX) then |
|
285 |
r.x:= LeftX - X; |
|
286 |
if (Y < TopY) then |
|
287 |
r.y:= TopY - Y; |
|
288 |
||
289 |
if (Y + SpritesData[Sprite].Height > BottomY) then |
|
290 |
r.h:= BottomY - Y + 1; |
|
291 |
if (X + SpritesData[Sprite].Width > RightX) then |
|
292 |
r.w:= RightX - X + 1; |
|
293 |
||
294 |
dec(r.h, r.y); |
|
295 |
dec(r.w, r.x); |
|
296 |
||
297 |
DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture) |
|
298 |
end; |
|
299 |
||
300 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
|
301 |
var r: TSDL_Rect; |
|
302 |
begin |
|
303 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
304 |
r.w:= SpritesData[Sprite].Width; |
|
305 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
306 |
r.h:= SpritesData[Sprite].Height; |
|
307 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
|
308 |
end; |
|
309 |
||
310 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
|
311 |
var scale: GLfloat; |
|
312 |
begin |
|
313 |
if (Source^.w + 20) > cScreenWidth then |
|
314 |
scale:= cScreenWidth / (Source^.w + 20) |
|
315 |
else |
|
316 |
scale:= 1.0; |
|
317 |
DrawTexture(X - round(Source^.w * scale) div 2, Top, Source, scale) |
|
318 |
end; |
|
319 |
||
320 |
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte); |
|
321 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
322 |
begin |
|
323 |
glDisable(GL_TEXTURE_2D); |
|
324 |
glEnable(GL_LINE_SMOOTH); |
|
325 |
||
326 |
glPushMatrix; |
|
327 |
glTranslatef(WorldDx, WorldDy, 0); |
|
328 |
glLineWidth(Width); |
|
329 |
||
330 |
Tint(r, g, b, a); |
|
331 |
VertexBuffer[0].X:= X0; |
|
332 |
VertexBuffer[0].Y:= Y0; |
|
333 |
VertexBuffer[1].X:= X1; |
|
334 |
VertexBuffer[1].Y:= Y1; |
|
335 |
||
336 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
337 |
glDrawArrays(GL_LINES, 0, Length(VertexBuffer)); |
|
338 |
Tint($FF, $FF, $FF, $FF); |
|
339 |
||
340 |
glPopMatrix; |
|
341 |
||
342 |
glEnable(GL_TEXTURE_2D); |
|
343 |
glDisable(GL_LINE_SMOOTH); |
|
344 |
end; |
|
345 |
||
346 |
procedure DrawFillRect(r: TSDL_Rect); |
|
347 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
348 |
begin |
|
349 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
350 |
if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) * cScaleFactor > cScreenWidth) then |
|
351 |
exit; |
|
352 |
if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) * cScaleFactor > cScreenHeight) then |
|
353 |
exit; |
|
354 |
||
355 |
glDisable(GL_TEXTURE_2D); |
|
356 |
||
357 |
Tint($00, $00, $00, $80); |
|
358 |
||
359 |
VertexBuffer[0].X:= r.x; |
|
360 |
VertexBuffer[0].Y:= r.y; |
|
361 |
VertexBuffer[1].X:= r.x + r.w; |
|
362 |
VertexBuffer[1].Y:= r.y; |
|
363 |
VertexBuffer[2].X:= r.x + r.w; |
|
364 |
VertexBuffer[2].Y:= r.y + r.h; |
|
365 |
VertexBuffer[3].X:= r.x; |
|
366 |
VertexBuffer[3].Y:= r.y + r.h; |
|
367 |
||
368 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
369 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
370 |
||
371 |
Tint($FF, $FF, $FF, $FF); |
|
372 |
glEnable(GL_TEXTURE_2D) |
|
373 |
end; |
|
374 |
||
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
|
375 |
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
|
376 |
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
|
377 |
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
|
378 |
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
|
379 |
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
|
380 |
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
|
381 |
|
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
|
382 |
procedure DrawCircle(X, Y, Radius, Width: LongInt); |
4378 | 383 |
var |
384 |
i: LongInt; |
|
385 |
CircleVertex: array [0..359] of TVertex2f; |
|
386 |
begin |
|
387 |
for i := 0 to 359 do begin |
|
388 |
CircleVertex[i].X := X + Radius*cos(i*pi/180); |
|
389 |
CircleVertex[i].Y := Y + Radius*sin(i*pi/180); |
|
390 |
end; |
|
391 |
glDisable(GL_TEXTURE_2D); |
|
392 |
glEnable(GL_LINE_SMOOTH); |
|
393 |
glPushMatrix; |
|
394 |
glLineWidth(Width); |
|
395 |
glVertexPointer(2, GL_FLOAT, 0, @CircleVertex[0]); |
|
396 |
glDrawArrays(GL_LINE_LOOP, 0, 360); |
|
397 |
glPopMatrix; |
|
398 |
glEnable(GL_TEXTURE_2D); |
|
399 |
glDisable(GL_LINE_SMOOTH); |
|
400 |
end; |
|
401 |
||
402 |
||
4385 | 403 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
404 |
const VertexBuffer: array [0..3] of TVertex2f = ( |
|
405 |
(x: -16; y: -16), |
|
406 |
(x: 16; y: -16), |
|
407 |
(x: 16; y: 16), |
|
408 |
(x: -16; y: 16)); |
|
409 |
var l, r, t, b: real; |
|
410 |
TextureBuffer: array [0..3] of TVertex2f; |
|
411 |
begin |
|
412 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
413 |
if (abs(X) > 32) and ((abs(X) - 16) * cScaleFactor > cScreenWidth) then |
|
414 |
exit; |
|
415 |
if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) * cScaleFactor > cScreenHeight) then |
|
416 |
exit; |
|
417 |
||
418 |
t:= Pos * 32 / HHTexture^.h; |
|
419 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
420 |
||
421 |
if Dir = -1 then |
|
422 |
begin |
|
423 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
424 |
r:= Step * 32 / HHTexture^.w |
|
425 |
end else |
|
426 |
begin |
|
427 |
l:= Step * 32 / HHTexture^.w; |
|
428 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
429 |
end; |
|
430 |
||
431 |
||
432 |
glPushMatrix(); |
|
433 |
glTranslatef(X, Y, 0); |
|
434 |
glRotatef(Angle, 0, 0, 1); |
|
435 |
||
436 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
|
437 |
||
438 |
TextureBuffer[0].X:= l; |
|
439 |
TextureBuffer[0].Y:= t; |
|
440 |
TextureBuffer[1].X:= r; |
|
441 |
TextureBuffer[1].Y:= t; |
|
442 |
TextureBuffer[2].X:= r; |
|
443 |
TextureBuffer[2].Y:= b; |
|
444 |
TextureBuffer[3].X:= l; |
|
445 |
TextureBuffer[3].Y:= b; |
|
446 |
||
447 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
448 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
449 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
450 |
||
451 |
glPopMatrix |
|
452 |
end; |
|
453 |
||
454 |
||
4378 | 455 |
procedure Tint(r, g, b, a: Byte); inline; |
456 |
var nc: Longword; |
|
457 |
begin |
|
458 |
nc:= (a shl 24) or (b shl 16) or (g shl 8) or r; |
|
459 |
if nc = lastTint then |
|
460 |
exit; |
|
461 |
glColor4ub(r, g, b, a); |
|
462 |
lastTint:= nc; |
|
463 |
end; |
|
464 |
||
465 |
procedure Tint(c: Longword); inline; |
|
466 |
begin |
|
4452 | 467 |
Tint(((c shr 24) and $FF), ((c shr 16) and $FF), (c shr 8) and $FF, (c and $FF)) |
4378 | 468 |
end; |
469 |
||
470 |
end. |