author | nemo |
Mon, 12 Sep 2011 16:38:54 -0400 | |
changeset 5881 | 099464aab4b6 |
parent 5565 | 1a326ba319c9 |
child 6318 | ca12368acc16 |
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 |
||
162 |
if Dir < 0 then |
|
163 |
hw:= w div -2 |
|
164 |
else |
|
165 |
hw:= w div 2; |
|
166 |
||
167 |
nx:= round(Texture^.w / w); // number of horizontal frames |
|
168 |
ny:= round(Texture^.h / h); // number of vertical frames |
|
169 |
||
170 |
ft:= (Frame mod ny) * Texture^.ry / ny; |
|
171 |
fb:= ((Frame mod ny) + 1) * Texture^.ry / ny; |
|
172 |
fl:= (Frame div ny) * Texture^.rx / nx; |
|
173 |
fr:= ((Frame div ny) + 1) * Texture^.rx / nx; |
|
174 |
||
175 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
176 |
||
177 |
VertexBuffer[0].X:= -hw; |
|
178 |
VertexBuffer[0].Y:= w / -2; |
|
179 |
VertexBuffer[1].X:= hw; |
|
180 |
VertexBuffer[1].Y:= w / -2; |
|
181 |
VertexBuffer[2].X:= hw; |
|
182 |
VertexBuffer[2].Y:= w / 2; |
|
183 |
VertexBuffer[3].X:= -hw; |
|
184 |
VertexBuffer[3].Y:= w / 2; |
|
185 |
||
186 |
TextureBuffer[0].X:= fl; |
|
187 |
TextureBuffer[0].Y:= ft; |
|
188 |
TextureBuffer[1].X:= fr; |
|
189 |
TextureBuffer[1].Y:= ft; |
|
190 |
TextureBuffer[2].X:= fr; |
|
191 |
TextureBuffer[2].Y:= fb; |
|
192 |
TextureBuffer[3].X:= fl; |
|
193 |
TextureBuffer[3].Y:= fb; |
|
194 |
||
195 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
196 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
197 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
198 |
||
199 |
glPopMatrix |
|
200 |
end; |
|
201 |
||
202 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
|
203 |
begin |
|
204 |
DrawRotatedTex(SpritesData[Sprite].Texture, |
|
205 |
SpritesData[Sprite].Width, |
|
206 |
SpritesData[Sprite].Height, |
|
207 |
X, Y, Dir, Angle) |
|
208 |
end; |
|
209 |
||
210 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
|
211 |
begin |
|
212 |
glPushMatrix; |
|
213 |
glTranslatef(X, Y, 0); |
|
214 |
||
215 |
if Dir < 0 then |
|
216 |
glRotatef(Angle, 0, 0, -1) |
|
217 |
else |
|
218 |
glRotatef(Angle, 0, 0, 1); |
|
219 |
if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
|
220 |
||
221 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
222 |
||
223 |
glPopMatrix |
|
224 |
end; |
|
225 |
||
226 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
|
227 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
228 |
begin |
|
5565 | 229 |
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
4378 | 230 |
if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then |
231 |
exit; |
|
232 |
if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then |
|
233 |
exit; |
|
234 |
||
235 |
glPushMatrix; |
|
236 |
glTranslatef(X, Y, 0); |
|
237 |
||
238 |
if Dir < 0 then |
|
239 |
begin |
|
240 |
hw:= - hw; |
|
241 |
glRotatef(Angle, 0, 0, -1); |
|
242 |
end else |
|
243 |
glRotatef(Angle, 0, 0, 1); |
|
244 |
||
245 |
||
246 |
glBindTexture(GL_TEXTURE_2D, Tex^.id); |
|
247 |
||
248 |
VertexBuffer[0].X:= -hw; |
|
249 |
VertexBuffer[0].Y:= -hh; |
|
250 |
VertexBuffer[1].X:= hw; |
|
251 |
VertexBuffer[1].Y:= -hh; |
|
252 |
VertexBuffer[2].X:= hw; |
|
253 |
VertexBuffer[2].Y:= hh; |
|
254 |
VertexBuffer[3].X:= -hw; |
|
255 |
VertexBuffer[3].Y:= hh; |
|
256 |
||
257 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
258 |
glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb); |
|
259 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
260 |
||
261 |
glPopMatrix |
|
262 |
end; |
|
263 |
||
264 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
|
265 |
var row, col, numFramesFirstCol: LongInt; |
|
266 |
begin |
|
5235
e30b06ffea3a
Skip droplets if plain splash is enabled, add a sanity check just in case.
nemo
parents:
4976
diff
changeset
|
267 |
if SpritesData[Sprite].imageHeight = 0 then exit; |
4378 | 268 |
numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height; |
269 |
row:= Frame mod numFramesFirstCol; |
|
270 |
col:= Frame div numFramesFirstCol; |
|
271 |
DrawSprite2 (Sprite, X, Y, col, row); |
|
272 |
end; |
|
273 |
||
274 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
|
275 |
var r: TSDL_Rect; |
|
276 |
begin |
|
277 |
r.x:= 0; |
|
278 |
r.y:= 0; |
|
279 |
r.w:= SpritesData[Sprite].Width; |
|
280 |
r.h:= SpritesData[Sprite].Height; |
|
281 |
||
282 |
if (X < LeftX) then |
|
283 |
r.x:= LeftX - X; |
|
284 |
if (Y < TopY) then |
|
285 |
r.y:= TopY - Y; |
|
286 |
||
287 |
if (Y + SpritesData[Sprite].Height > BottomY) then |
|
288 |
r.h:= BottomY - Y + 1; |
|
289 |
if (X + SpritesData[Sprite].Width > RightX) then |
|
290 |
r.w:= RightX - X + 1; |
|
291 |
||
292 |
dec(r.h, r.y); |
|
293 |
dec(r.w, r.x); |
|
294 |
||
295 |
DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture) |
|
296 |
end; |
|
297 |
||
298 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
|
299 |
var r: TSDL_Rect; |
|
300 |
begin |
|
301 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
302 |
r.w:= SpritesData[Sprite].Width; |
|
303 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
304 |
r.h:= SpritesData[Sprite].Height; |
|
305 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
|
306 |
end; |
|
307 |
||
308 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
|
309 |
var scale: GLfloat; |
|
310 |
begin |
|
311 |
if (Source^.w + 20) > cScreenWidth then |
|
312 |
scale:= cScreenWidth / (Source^.w + 20) |
|
313 |
else |
|
314 |
scale:= 1.0; |
|
315 |
DrawTexture(X - round(Source^.w * scale) div 2, Top, Source, scale) |
|
316 |
end; |
|
317 |
||
318 |
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte); |
|
319 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
320 |
begin |
|
321 |
glDisable(GL_TEXTURE_2D); |
|
322 |
glEnable(GL_LINE_SMOOTH); |
|
323 |
||
324 |
glPushMatrix; |
|
325 |
glTranslatef(WorldDx, WorldDy, 0); |
|
326 |
glLineWidth(Width); |
|
327 |
||
328 |
Tint(r, g, b, a); |
|
329 |
VertexBuffer[0].X:= X0; |
|
330 |
VertexBuffer[0].Y:= Y0; |
|
331 |
VertexBuffer[1].X:= X1; |
|
332 |
VertexBuffer[1].Y:= Y1; |
|
333 |
||
334 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
335 |
glDrawArrays(GL_LINES, 0, Length(VertexBuffer)); |
|
336 |
Tint($FF, $FF, $FF, $FF); |
|
337 |
||
338 |
glPopMatrix; |
|
339 |
||
340 |
glEnable(GL_TEXTURE_2D); |
|
341 |
glDisable(GL_LINE_SMOOTH); |
|
342 |
end; |
|
343 |
||
344 |
procedure DrawFillRect(r: TSDL_Rect); |
|
345 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
346 |
begin |
|
5565 | 347 |
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
4378 | 348 |
if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) * cScaleFactor > cScreenWidth) then |
349 |
exit; |
|
350 |
if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) * cScaleFactor > cScreenHeight) then |
|
351 |
exit; |
|
352 |
||
353 |
glDisable(GL_TEXTURE_2D); |
|
354 |
||
355 |
Tint($00, $00, $00, $80); |
|
356 |
||
357 |
VertexBuffer[0].X:= r.x; |
|
358 |
VertexBuffer[0].Y:= r.y; |
|
359 |
VertexBuffer[1].X:= r.x + r.w; |
|
360 |
VertexBuffer[1].Y:= r.y; |
|
361 |
VertexBuffer[2].X:= r.x + r.w; |
|
362 |
VertexBuffer[2].Y:= r.y + r.h; |
|
363 |
VertexBuffer[3].X:= r.x; |
|
364 |
VertexBuffer[3].Y:= r.y + r.h; |
|
365 |
||
366 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
367 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
368 |
||
369 |
Tint($FF, $FF, $FF, $FF); |
|
370 |
glEnable(GL_TEXTURE_2D) |
|
371 |
end; |
|
372 |
||
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
|
373 |
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
|
374 |
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
|
375 |
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
|
376 |
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
|
377 |
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
|
378 |
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
|
379 |
|
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 |
procedure DrawCircle(X, Y, Radius, Width: LongInt); |
4378 | 381 |
var |
382 |
i: LongInt; |
|
5561
dfbe55237c64
Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents:
5559
diff
changeset
|
383 |
CircleVertex: array [0..59] of TVertex2f; |
4378 | 384 |
begin |
5561
dfbe55237c64
Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents:
5559
diff
changeset
|
385 |
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
|
386 |
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
|
387 |
CircleVertex[i].Y := Y + Radius*sin(i*pi/30); |
4378 | 388 |
end; |
389 |
glDisable(GL_TEXTURE_2D); |
|
390 |
glEnable(GL_LINE_SMOOTH); |
|
391 |
glPushMatrix; |
|
392 |
glLineWidth(Width); |
|
393 |
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
|
394 |
glDrawArrays(GL_LINE_LOOP, 0, 60); |
4378 | 395 |
glPopMatrix; |
396 |
glEnable(GL_TEXTURE_2D); |
|
397 |
glDisable(GL_LINE_SMOOTH); |
|
398 |
end; |
|
399 |
||
400 |
||
4385 | 401 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
402 |
const VertexBuffer: array [0..3] of TVertex2f = ( |
|
403 |
(x: -16; y: -16), |
|
404 |
(x: 16; y: -16), |
|
405 |
(x: 16; y: 16), |
|
406 |
(x: -16; y: 16)); |
|
407 |
var l, r, t, b: real; |
|
408 |
TextureBuffer: array [0..3] of TVertex2f; |
|
409 |
begin |
|
5565 | 410 |
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
4385 | 411 |
if (abs(X) > 32) and ((abs(X) - 16) * cScaleFactor > cScreenWidth) then |
412 |
exit; |
|
413 |
if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) * cScaleFactor > cScreenHeight) then |
|
414 |
exit; |
|
415 |
||
416 |
t:= Pos * 32 / HHTexture^.h; |
|
417 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
418 |
||
419 |
if Dir = -1 then |
|
420 |
begin |
|
421 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
422 |
r:= Step * 32 / HHTexture^.w |
|
423 |
end else |
|
424 |
begin |
|
425 |
l:= Step * 32 / HHTexture^.w; |
|
426 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
427 |
end; |
|
428 |
||
429 |
||
430 |
glPushMatrix(); |
|
431 |
glTranslatef(X, Y, 0); |
|
432 |
glRotatef(Angle, 0, 0, 1); |
|
433 |
||
434 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
|
435 |
||
436 |
TextureBuffer[0].X:= l; |
|
437 |
TextureBuffer[0].Y:= t; |
|
438 |
TextureBuffer[1].X:= r; |
|
439 |
TextureBuffer[1].Y:= t; |
|
440 |
TextureBuffer[2].X:= r; |
|
441 |
TextureBuffer[2].Y:= b; |
|
442 |
TextureBuffer[3].X:= l; |
|
443 |
TextureBuffer[3].Y:= b; |
|
444 |
||
445 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
446 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
447 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
448 |
||
449 |
glPopMatrix |
|
450 |
end; |
|
451 |
||
452 |
||
4378 | 453 |
procedure Tint(r, g, b, a: Byte); inline; |
5559 | 454 |
const |
455 |
lastTint: Longword = 0; |
|
456 |
var |
|
457 |
nc, tw: Longword; |
|
4378 | 458 |
begin |
459 |
nc:= (a shl 24) or (b shl 16) or (g shl 8) or r; |
|
5559 | 460 |
|
4378 | 461 |
if nc = lastTint then |
462 |
exit; |
|
5559 | 463 |
|
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
464 |
if cGrayScale then |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
465 |
begin |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
466 |
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
|
467 |
if tw > 255 then tw:= 255; |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
468 |
r:= tw; |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
469 |
g:= tw; |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
470 |
b:= tw |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
471 |
end; |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
472 |
|
4378 | 473 |
glColor4ub(r, g, b, a); |
474 |
lastTint:= nc; |
|
475 |
end; |
|
476 |
||
477 |
procedure Tint(c: Longword); inline; |
|
478 |
begin |
|
4452 | 479 |
Tint(((c shr 24) and $FF), ((c shr 16) and $FF), (c shr 8) and $FF, (c and $FF)) |
4378 | 480 |
end; |
481 |
||
482 |
end. |