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