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