author | unc0rr |
Sun, 30 Jan 2011 20:43:18 +0300 | |
branch | server_refactor |
changeset 4620 | 6122a43d3424 |
parent 4452 | 258945553b18 |
child 4976 | 088d40d8aba2 |
permissions | -rw-r--r-- |
4378 | 1 |
{$INCLUDE "options.inc"} |
2 |
unit uRender; |
|
3 |
||
4 |
interface |
|
5 |
||
6 |
uses SDLh, uTypes, GLunit; |
|
7 |
||
8 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
|
9 |
procedure DrawFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
|
10 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
|
11 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
|
12 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
|
13 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
|
14 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat = 1.0); |
|
15 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt); |
|
16 |
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
|
17 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
|
18 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
|
19 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
|
20 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
|
21 |
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte); |
|
22 |
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
|
23 |
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
|
24 |
procedure DrawCircle(X, Y, Radius, Width: LongInt); |
4385 | 25 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
4378 | 26 |
procedure Tint(r, g, b, a: Byte); inline; |
27 |
procedure Tint(c: Longword); inline; |
|
28 |
||
4385 | 29 |
var |
30 |
HHTexture: PTexture; |
|
31 |
||
4378 | 32 |
implementation |
33 |
uses uVariables; |
|
34 |
var |
|
35 |
lastTint: Longword; |
|
36 |
||
37 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
|
38 |
begin |
|
39 |
r.y:= r.y + Height * Position; |
|
40 |
r.h:= Height; |
|
41 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
|
42 |
end; |
|
43 |
||
44 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
|
45 |
begin |
|
46 |
DrawFromRect(X, Y, r^.w, r^.h, r, SourceTexture) |
|
47 |
end; |
|
48 |
||
49 |
procedure DrawFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
|
50 |
var rr: TSDL_Rect; |
|
51 |
_l, _r, _t, _b: real; |
|
52 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
|
53 |
begin |
|
54 |
if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit; |
|
55 |
||
56 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
57 |
if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then |
|
58 |
exit; |
|
59 |
if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) > cScreenHeight / cScaleFactor) then |
|
60 |
exit; |
|
61 |
||
62 |
rr.x:= X; |
|
63 |
rr.y:= Y; |
|
64 |
rr.w:= W; |
|
65 |
rr.h:= H; |
|
66 |
||
67 |
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx; |
|
68 |
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx; |
|
69 |
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry; |
|
70 |
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry; |
|
71 |
||
72 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
73 |
||
74 |
VertexBuffer[0].X:= X; |
|
75 |
VertexBuffer[0].Y:= Y; |
|
76 |
VertexBuffer[1].X:= rr.w + X; |
|
77 |
VertexBuffer[1].Y:= Y; |
|
78 |
VertexBuffer[2].X:= rr.w + X; |
|
79 |
VertexBuffer[2].Y:= rr.h + Y; |
|
80 |
VertexBuffer[3].X:= X; |
|
81 |
VertexBuffer[3].Y:= rr.h + Y; |
|
82 |
||
83 |
TextureBuffer[0].X:= _l; |
|
84 |
TextureBuffer[0].Y:= _t; |
|
85 |
TextureBuffer[1].X:= _r; |
|
86 |
TextureBuffer[1].Y:= _t; |
|
87 |
TextureBuffer[2].X:= _r; |
|
88 |
TextureBuffer[2].Y:= _b; |
|
89 |
TextureBuffer[3].X:= _l; |
|
90 |
TextureBuffer[3].Y:= _b; |
|
91 |
||
92 |
||
93 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
94 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
95 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
96 |
end; |
|
97 |
||
98 |
||
99 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat); |
|
100 |
begin |
|
101 |
||
102 |
glPushMatrix; |
|
103 |
glTranslatef(X, Y, 0); |
|
104 |
glScalef(Scale, Scale, 1); |
|
105 |
||
106 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
107 |
||
108 |
glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb); |
|
109 |
glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb); |
|
110 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); |
|
111 |
||
112 |
glPopMatrix |
|
113 |
end; |
|
114 |
||
115 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt); |
|
116 |
begin |
|
117 |
DrawRotatedTextureF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0) |
|
118 |
end; |
|
119 |
||
120 |
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
|
121 |
var ft, fb, fl, fr: GLfloat; |
|
122 |
hw, nx, ny: LongInt; |
|
123 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
|
124 |
begin |
|
125 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
126 |
if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * cScaleFactor > cScreenWidth) then |
|
127 |
exit; |
|
128 |
if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then |
|
129 |
exit; |
|
130 |
||
131 |
glPushMatrix; |
|
132 |
glTranslatef(X, Y, 0); |
|
133 |
||
134 |
if Dir < 0 then |
|
135 |
glRotatef(Angle, 0, 0, -1) |
|
136 |
else |
|
137 |
glRotatef(Angle, 0, 0, 1); |
|
138 |
||
139 |
glTranslatef(Dir*OffsetX, OffsetY, 0); |
|
140 |
glScalef(Scale, Scale, 1); |
|
141 |
||
142 |
// Any reason for this call? And why only in t direction, not s? |
|
143 |
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
|
144 |
||
145 |
if Dir < 0 then |
|
146 |
hw:= w div -2 |
|
147 |
else |
|
148 |
hw:= w div 2; |
|
149 |
||
150 |
nx:= round(Texture^.w / w); // number of horizontal frames |
|
151 |
ny:= round(Texture^.h / h); // number of vertical frames |
|
152 |
||
153 |
ft:= (Frame mod ny) * Texture^.ry / ny; |
|
154 |
fb:= ((Frame mod ny) + 1) * Texture^.ry / ny; |
|
155 |
fl:= (Frame div ny) * Texture^.rx / nx; |
|
156 |
fr:= ((Frame div ny) + 1) * Texture^.rx / nx; |
|
157 |
||
158 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
159 |
||
160 |
VertexBuffer[0].X:= -hw; |
|
161 |
VertexBuffer[0].Y:= w / -2; |
|
162 |
VertexBuffer[1].X:= hw; |
|
163 |
VertexBuffer[1].Y:= w / -2; |
|
164 |
VertexBuffer[2].X:= hw; |
|
165 |
VertexBuffer[2].Y:= w / 2; |
|
166 |
VertexBuffer[3].X:= -hw; |
|
167 |
VertexBuffer[3].Y:= w / 2; |
|
168 |
||
169 |
TextureBuffer[0].X:= fl; |
|
170 |
TextureBuffer[0].Y:= ft; |
|
171 |
TextureBuffer[1].X:= fr; |
|
172 |
TextureBuffer[1].Y:= ft; |
|
173 |
TextureBuffer[2].X:= fr; |
|
174 |
TextureBuffer[2].Y:= fb; |
|
175 |
TextureBuffer[3].X:= fl; |
|
176 |
TextureBuffer[3].Y:= fb; |
|
177 |
||
178 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
179 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
180 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
181 |
||
182 |
glPopMatrix |
|
183 |
end; |
|
184 |
||
185 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
|
186 |
begin |
|
187 |
DrawRotatedTex(SpritesData[Sprite].Texture, |
|
188 |
SpritesData[Sprite].Width, |
|
189 |
SpritesData[Sprite].Height, |
|
190 |
X, Y, Dir, Angle) |
|
191 |
end; |
|
192 |
||
193 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
|
194 |
begin |
|
195 |
glPushMatrix; |
|
196 |
glTranslatef(X, Y, 0); |
|
197 |
||
198 |
if Dir < 0 then |
|
199 |
glRotatef(Angle, 0, 0, -1) |
|
200 |
else |
|
201 |
glRotatef(Angle, 0, 0, 1); |
|
202 |
if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
|
203 |
||
204 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
205 |
||
206 |
glPopMatrix |
|
207 |
end; |
|
208 |
||
209 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
|
210 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
211 |
begin |
|
212 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
213 |
if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then |
|
214 |
exit; |
|
215 |
if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then |
|
216 |
exit; |
|
217 |
||
218 |
glPushMatrix; |
|
219 |
glTranslatef(X, Y, 0); |
|
220 |
||
221 |
if Dir < 0 then |
|
222 |
begin |
|
223 |
hw:= - hw; |
|
224 |
glRotatef(Angle, 0, 0, -1); |
|
225 |
end else |
|
226 |
glRotatef(Angle, 0, 0, 1); |
|
227 |
||
228 |
||
229 |
glBindTexture(GL_TEXTURE_2D, Tex^.id); |
|
230 |
||
231 |
VertexBuffer[0].X:= -hw; |
|
232 |
VertexBuffer[0].Y:= -hh; |
|
233 |
VertexBuffer[1].X:= hw; |
|
234 |
VertexBuffer[1].Y:= -hh; |
|
235 |
VertexBuffer[2].X:= hw; |
|
236 |
VertexBuffer[2].Y:= hh; |
|
237 |
VertexBuffer[3].X:= -hw; |
|
238 |
VertexBuffer[3].Y:= hh; |
|
239 |
||
240 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
241 |
glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb); |
|
242 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
243 |
||
244 |
glPopMatrix |
|
245 |
end; |
|
246 |
||
247 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
|
248 |
var row, col, numFramesFirstCol: LongInt; |
|
249 |
begin |
|
250 |
numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height; |
|
251 |
row:= Frame mod numFramesFirstCol; |
|
252 |
col:= Frame div numFramesFirstCol; |
|
253 |
DrawSprite2 (Sprite, X, Y, col, row); |
|
254 |
end; |
|
255 |
||
256 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
|
257 |
var r: TSDL_Rect; |
|
258 |
begin |
|
259 |
r.x:= 0; |
|
260 |
r.y:= 0; |
|
261 |
r.w:= SpritesData[Sprite].Width; |
|
262 |
r.h:= SpritesData[Sprite].Height; |
|
263 |
||
264 |
if (X < LeftX) then |
|
265 |
r.x:= LeftX - X; |
|
266 |
if (Y < TopY) then |
|
267 |
r.y:= TopY - Y; |
|
268 |
||
269 |
if (Y + SpritesData[Sprite].Height > BottomY) then |
|
270 |
r.h:= BottomY - Y + 1; |
|
271 |
if (X + SpritesData[Sprite].Width > RightX) then |
|
272 |
r.w:= RightX - X + 1; |
|
273 |
||
274 |
dec(r.h, r.y); |
|
275 |
dec(r.w, r.x); |
|
276 |
||
277 |
DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture) |
|
278 |
end; |
|
279 |
||
280 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
|
281 |
var r: TSDL_Rect; |
|
282 |
begin |
|
283 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
284 |
r.w:= SpritesData[Sprite].Width; |
|
285 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
286 |
r.h:= SpritesData[Sprite].Height; |
|
287 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
|
288 |
end; |
|
289 |
||
290 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
|
291 |
var scale: GLfloat; |
|
292 |
begin |
|
293 |
if (Source^.w + 20) > cScreenWidth then |
|
294 |
scale:= cScreenWidth / (Source^.w + 20) |
|
295 |
else |
|
296 |
scale:= 1.0; |
|
297 |
DrawTexture(X - round(Source^.w * scale) div 2, Top, Source, scale) |
|
298 |
end; |
|
299 |
||
300 |
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte); |
|
301 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
302 |
begin |
|
303 |
glDisable(GL_TEXTURE_2D); |
|
304 |
glEnable(GL_LINE_SMOOTH); |
|
305 |
||
306 |
glPushMatrix; |
|
307 |
glTranslatef(WorldDx, WorldDy, 0); |
|
308 |
glLineWidth(Width); |
|
309 |
||
310 |
Tint(r, g, b, a); |
|
311 |
VertexBuffer[0].X:= X0; |
|
312 |
VertexBuffer[0].Y:= Y0; |
|
313 |
VertexBuffer[1].X:= X1; |
|
314 |
VertexBuffer[1].Y:= Y1; |
|
315 |
||
316 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
317 |
glDrawArrays(GL_LINES, 0, Length(VertexBuffer)); |
|
318 |
Tint($FF, $FF, $FF, $FF); |
|
319 |
||
320 |
glPopMatrix; |
|
321 |
||
322 |
glEnable(GL_TEXTURE_2D); |
|
323 |
glDisable(GL_LINE_SMOOTH); |
|
324 |
end; |
|
325 |
||
326 |
procedure DrawFillRect(r: TSDL_Rect); |
|
327 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
328 |
begin |
|
329 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
330 |
if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) * cScaleFactor > cScreenWidth) then |
|
331 |
exit; |
|
332 |
if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) * cScaleFactor > cScreenHeight) then |
|
333 |
exit; |
|
334 |
||
335 |
glDisable(GL_TEXTURE_2D); |
|
336 |
||
337 |
Tint($00, $00, $00, $80); |
|
338 |
||
339 |
VertexBuffer[0].X:= r.x; |
|
340 |
VertexBuffer[0].Y:= r.y; |
|
341 |
VertexBuffer[1].X:= r.x + r.w; |
|
342 |
VertexBuffer[1].Y:= r.y; |
|
343 |
VertexBuffer[2].X:= r.x + r.w; |
|
344 |
VertexBuffer[2].Y:= r.y + r.h; |
|
345 |
VertexBuffer[3].X:= r.x; |
|
346 |
VertexBuffer[3].Y:= r.y + r.h; |
|
347 |
||
348 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
349 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
350 |
||
351 |
Tint($FF, $FF, $FF, $FF); |
|
352 |
glEnable(GL_TEXTURE_2D) |
|
353 |
end; |
|
354 |
||
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
|
355 |
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
|
356 |
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
|
357 |
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
|
358 |
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
|
359 |
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
|
360 |
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
|
361 |
|
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
|
362 |
procedure DrawCircle(X, Y, Radius, Width: LongInt); |
4378 | 363 |
var |
364 |
i: LongInt; |
|
365 |
CircleVertex: array [0..359] of TVertex2f; |
|
366 |
begin |
|
367 |
for i := 0 to 359 do begin |
|
368 |
CircleVertex[i].X := X + Radius*cos(i*pi/180); |
|
369 |
CircleVertex[i].Y := Y + Radius*sin(i*pi/180); |
|
370 |
end; |
|
371 |
glDisable(GL_TEXTURE_2D); |
|
372 |
glEnable(GL_LINE_SMOOTH); |
|
373 |
glPushMatrix; |
|
374 |
glLineWidth(Width); |
|
375 |
glVertexPointer(2, GL_FLOAT, 0, @CircleVertex[0]); |
|
376 |
glDrawArrays(GL_LINE_LOOP, 0, 360); |
|
377 |
glPopMatrix; |
|
378 |
glEnable(GL_TEXTURE_2D); |
|
379 |
glDisable(GL_LINE_SMOOTH); |
|
380 |
end; |
|
381 |
||
382 |
||
4385 | 383 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
384 |
const VertexBuffer: array [0..3] of TVertex2f = ( |
|
385 |
(x: -16; y: -16), |
|
386 |
(x: 16; y: -16), |
|
387 |
(x: 16; y: 16), |
|
388 |
(x: -16; y: 16)); |
|
389 |
var l, r, t, b: real; |
|
390 |
TextureBuffer: array [0..3] of TVertex2f; |
|
391 |
begin |
|
392 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
393 |
if (abs(X) > 32) and ((abs(X) - 16) * cScaleFactor > cScreenWidth) then |
|
394 |
exit; |
|
395 |
if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) * cScaleFactor > cScreenHeight) then |
|
396 |
exit; |
|
397 |
||
398 |
t:= Pos * 32 / HHTexture^.h; |
|
399 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
400 |
||
401 |
if Dir = -1 then |
|
402 |
begin |
|
403 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
404 |
r:= Step * 32 / HHTexture^.w |
|
405 |
end else |
|
406 |
begin |
|
407 |
l:= Step * 32 / HHTexture^.w; |
|
408 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
409 |
end; |
|
410 |
||
411 |
||
412 |
glPushMatrix(); |
|
413 |
glTranslatef(X, Y, 0); |
|
414 |
glRotatef(Angle, 0, 0, 1); |
|
415 |
||
416 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
|
417 |
||
418 |
TextureBuffer[0].X:= l; |
|
419 |
TextureBuffer[0].Y:= t; |
|
420 |
TextureBuffer[1].X:= r; |
|
421 |
TextureBuffer[1].Y:= t; |
|
422 |
TextureBuffer[2].X:= r; |
|
423 |
TextureBuffer[2].Y:= b; |
|
424 |
TextureBuffer[3].X:= l; |
|
425 |
TextureBuffer[3].Y:= b; |
|
426 |
||
427 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
428 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
429 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
430 |
||
431 |
glPopMatrix |
|
432 |
end; |
|
433 |
||
434 |
||
4378 | 435 |
procedure Tint(r, g, b, a: Byte); inline; |
436 |
var nc: Longword; |
|
437 |
begin |
|
438 |
nc:= (a shl 24) or (b shl 16) or (g shl 8) or r; |
|
439 |
if nc = lastTint then |
|
440 |
exit; |
|
441 |
glColor4ub(r, g, b, a); |
|
442 |
lastTint:= nc; |
|
443 |
end; |
|
444 |
||
445 |
procedure Tint(c: Longword); inline; |
|
446 |
begin |
|
4452 | 447 |
Tint(((c shr 24) and $FF), ((c shr 16) and $FF), (c shr 8) and $FF, (c and $FF)) |
4378 | 448 |
end; |
449 |
||
450 |
end. |