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