author | nemo |
Tue, 24 Apr 2012 17:16:18 -0400 | |
changeset 6927 | ee000959d645 |
parent 6710 | 42504695122d |
child 6982 | 8d41d22a291d |
permissions | -rw-r--r-- |
4976 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
6700 | 3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
4976 | 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); |
6688 | 45 |
procedure DrawScreenWidget(widget: POnScreenWidget); |
4378 | 46 |
procedure Tint(r, g, b, a: Byte); inline; |
47 |
procedure Tint(c: Longword); inline; |
|
48 |
||
4385 | 49 |
|
4378 | 50 |
implementation |
51 |
uses uVariables; |
|
52 |
||
53 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
|
54 |
begin |
|
55 |
r.y:= r.y + Height * Position; |
|
56 |
r.h:= Height; |
|
57 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
|
58 |
end; |
|
59 |
||
60 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
|
61 |
begin |
|
62 |
DrawFromRect(X, Y, r^.w, r^.h, r, SourceTexture) |
|
63 |
end; |
|
64 |
||
65 |
procedure DrawFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
|
66 |
var rr: TSDL_Rect; |
|
67 |
_l, _r, _t, _b: real; |
|
68 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
|
69 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
70 |
if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
71 |
exit; |
4378 | 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 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
211 |
glRotatef(Angle, 0, 0, -1) |
4378 | 212 |
else |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
213 |
glRotatef(Angle, 0, 0, 1); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
214 |
if Dir < 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
215 |
glScalef(-1.0, 1.0, 1.0); |
4378 | 216 |
|
217 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
218 |
||
219 |
glPopMatrix |
|
220 |
end; |
|
221 |
||
222 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
|
223 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
224 |
begin |
|
5565 | 225 |
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
4378 | 226 |
if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then |
227 |
exit; |
|
228 |
if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then |
|
229 |
exit; |
|
230 |
||
231 |
glPushMatrix; |
|
232 |
glTranslatef(X, Y, 0); |
|
233 |
||
234 |
if Dir < 0 then |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
235 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
236 |
hw:= - hw; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
237 |
glRotatef(Angle, 0, 0, -1); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
238 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
239 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
240 |
glRotatef(Angle, 0, 0, 1); |
4378 | 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 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
264 |
if SpritesData[Sprite].imageHeight = 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
265 |
exit; |
4378 | 266 |
numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height; |
267 |
row:= Frame mod numFramesFirstCol; |
|
268 |
col:= Frame div numFramesFirstCol; |
|
269 |
DrawSprite2 (Sprite, X, Y, col, row); |
|
270 |
end; |
|
271 |
||
272 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
|
273 |
var r: TSDL_Rect; |
|
274 |
begin |
|
275 |
r.x:= 0; |
|
276 |
r.y:= 0; |
|
277 |
r.w:= SpritesData[Sprite].Width; |
|
278 |
r.h:= SpritesData[Sprite].Height; |
|
279 |
||
280 |
if (X < LeftX) then |
|
281 |
r.x:= LeftX - X; |
|
282 |
if (Y < TopY) then |
|
283 |
r.y:= TopY - Y; |
|
284 |
||
285 |
if (Y + SpritesData[Sprite].Height > BottomY) then |
|
286 |
r.h:= BottomY - Y + 1; |
|
287 |
if (X + SpritesData[Sprite].Width > RightX) then |
|
288 |
r.w:= RightX - X + 1; |
|
289 |
||
290 |
dec(r.h, r.y); |
|
291 |
dec(r.w, r.x); |
|
292 |
||
293 |
DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture) |
|
294 |
end; |
|
295 |
||
296 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
|
297 |
var r: TSDL_Rect; |
|
298 |
begin |
|
299 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
300 |
r.w:= SpritesData[Sprite].Width; |
|
301 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
302 |
r.h:= SpritesData[Sprite].Height; |
|
303 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
|
304 |
end; |
|
305 |
||
306 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
|
307 |
var scale: GLfloat; |
|
308 |
begin |
|
309 |
if (Source^.w + 20) > cScreenWidth then |
|
310 |
scale:= cScreenWidth / (Source^.w + 20) |
|
311 |
else |
|
312 |
scale:= 1.0; |
|
313 |
DrawTexture(X - round(Source^.w * scale) div 2, Top, Source, scale) |
|
314 |
end; |
|
315 |
||
316 |
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte); |
|
317 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
318 |
begin |
|
319 |
glDisable(GL_TEXTURE_2D); |
|
320 |
glEnable(GL_LINE_SMOOTH); |
|
321 |
||
322 |
glPushMatrix; |
|
323 |
glTranslatef(WorldDx, WorldDy, 0); |
|
324 |
glLineWidth(Width); |
|
325 |
||
326 |
Tint(r, g, b, a); |
|
327 |
VertexBuffer[0].X:= X0; |
|
328 |
VertexBuffer[0].Y:= Y0; |
|
329 |
VertexBuffer[1].X:= X1; |
|
330 |
VertexBuffer[1].Y:= Y1; |
|
331 |
||
332 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
333 |
glDrawArrays(GL_LINES, 0, Length(VertexBuffer)); |
|
334 |
Tint($FF, $FF, $FF, $FF); |
|
335 |
||
336 |
glPopMatrix; |
|
337 |
||
338 |
glEnable(GL_TEXTURE_2D); |
|
339 |
glDisable(GL_LINE_SMOOTH); |
|
340 |
end; |
|
341 |
||
342 |
procedure DrawFillRect(r: TSDL_Rect); |
|
343 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
344 |
begin |
|
5565 | 345 |
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
4378 | 346 |
if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) * cScaleFactor > cScreenWidth) then |
347 |
exit; |
|
348 |
if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) * cScaleFactor > cScreenHeight) then |
|
349 |
exit; |
|
350 |
||
351 |
glDisable(GL_TEXTURE_2D); |
|
352 |
||
353 |
Tint($00, $00, $00, $80); |
|
354 |
||
355 |
VertexBuffer[0].X:= r.x; |
|
356 |
VertexBuffer[0].Y:= r.y; |
|
357 |
VertexBuffer[1].X:= r.x + r.w; |
|
358 |
VertexBuffer[1].Y:= r.y; |
|
359 |
VertexBuffer[2].X:= r.x + r.w; |
|
360 |
VertexBuffer[2].Y:= r.y + r.h; |
|
361 |
VertexBuffer[3].X:= r.x; |
|
362 |
VertexBuffer[3].Y:= r.y + r.h; |
|
363 |
||
364 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
365 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
366 |
||
367 |
Tint($FF, $FF, $FF, $FF); |
|
368 |
glEnable(GL_TEXTURE_2D) |
|
369 |
end; |
|
370 |
||
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
|
371 |
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
|
372 |
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
|
373 |
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
|
374 |
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
|
375 |
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
|
376 |
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
|
377 |
|
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 |
procedure DrawCircle(X, Y, Radius, Width: LongInt); |
4378 | 379 |
var |
380 |
i: LongInt; |
|
5561
dfbe55237c64
Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents:
5559
diff
changeset
|
381 |
CircleVertex: array [0..59] of TVertex2f; |
4378 | 382 |
begin |
5561
dfbe55237c64
Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents:
5559
diff
changeset
|
383 |
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
|
384 |
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
|
385 |
CircleVertex[i].Y := Y + Radius*sin(i*pi/30); |
4378 | 386 |
end; |
387 |
glDisable(GL_TEXTURE_2D); |
|
388 |
glEnable(GL_LINE_SMOOTH); |
|
389 |
glPushMatrix; |
|
390 |
glLineWidth(Width); |
|
391 |
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
|
392 |
glDrawArrays(GL_LINE_LOOP, 0, 60); |
4378 | 393 |
glPopMatrix; |
394 |
glEnable(GL_TEXTURE_2D); |
|
395 |
glDisable(GL_LINE_SMOOTH); |
|
396 |
end; |
|
397 |
||
398 |
||
4385 | 399 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
400 |
const VertexBuffer: array [0..3] of TVertex2f = ( |
|
401 |
(x: -16; y: -16), |
|
402 |
(x: 16; y: -16), |
|
403 |
(x: 16; y: 16), |
|
404 |
(x: -16; y: 16)); |
|
405 |
var l, r, t, b: real; |
|
406 |
TextureBuffer: array [0..3] of TVertex2f; |
|
407 |
begin |
|
5565 | 408 |
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
4385 | 409 |
if (abs(X) > 32) and ((abs(X) - 16) * cScaleFactor > cScreenWidth) then |
410 |
exit; |
|
411 |
if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) * cScaleFactor > cScreenHeight) then |
|
412 |
exit; |
|
413 |
||
414 |
t:= Pos * 32 / HHTexture^.h; |
|
415 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
416 |
||
417 |
if Dir = -1 then |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
418 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
419 |
l:= (Step + 1) * 32 / HHTexture^.w; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
420 |
r:= Step * 32 / HHTexture^.w |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
421 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
422 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
423 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
424 |
l:= Step * 32 / HHTexture^.w; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
425 |
r:= (Step + 1) * 32 / HHTexture^.w |
4385 | 426 |
end; |
427 |
||
428 |
||
429 |
glPushMatrix(); |
|
430 |
glTranslatef(X, Y, 0); |
|
431 |
glRotatef(Angle, 0, 0, 1); |
|
432 |
||
433 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
|
434 |
||
435 |
TextureBuffer[0].X:= l; |
|
436 |
TextureBuffer[0].Y:= t; |
|
437 |
TextureBuffer[1].X:= r; |
|
438 |
TextureBuffer[1].Y:= t; |
|
439 |
TextureBuffer[2].X:= r; |
|
440 |
TextureBuffer[2].Y:= b; |
|
441 |
TextureBuffer[3].X:= l; |
|
442 |
TextureBuffer[3].Y:= b; |
|
443 |
||
444 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
445 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
446 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
447 |
||
448 |
glPopMatrix |
|
449 |
end; |
|
450 |
||
6688 | 451 |
procedure DrawScreenWidget(widget: POnScreenWidget); |
452 |
var alpha: byte = $FF; |
|
453 |
begin |
|
6689 | 454 |
{$IFDEF USE_TOUCH_INTERFACE} |
6688 | 455 |
with widget^ do |
456 |
begin |
|
457 |
if (fadeAnimStart <> 0) then |
|
458 |
begin |
|
459 |
if RealTicks > (fadeAnimStart + FADE_ANIM_TIME) then |
|
460 |
fadeAnimStart:= 0 |
|
461 |
else |
|
462 |
if show then |
|
463 |
alpha:= Byte(trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF)) |
|
464 |
else |
|
465 |
alpha:= Byte($FF - trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF)); |
|
466 |
end; |
|
467 |
||
468 |
with moveAnim do |
|
469 |
if animate then |
|
470 |
if RealTicks > (startTime + MOVE_ANIM_TIME) then |
|
471 |
begin |
|
472 |
startTime:= 0; |
|
6710
42504695122d
fixed the active region on widgets when they are animated, added active.x:= in uWorld too
Xeli
parents:
6700
diff
changeset
|
473 |
animate:= false; |
6695
32de8965c62c
refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents:
6689
diff
changeset
|
474 |
frame.x:= target.x; |
32de8965c62c
refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents:
6689
diff
changeset
|
475 |
frame.y:= target.y; |
6710
42504695122d
fixed the active region on widgets when they are animated, added active.x:= in uWorld too
Xeli
parents:
6700
diff
changeset
|
476 |
active.x:= active.x + (target.x - source.x); |
42504695122d
fixed the active region on widgets when they are animated, added active.x:= in uWorld too
Xeli
parents:
6700
diff
changeset
|
477 |
active.y:= active.y + (target.y - source.y); |
6688 | 478 |
end |
479 |
else |
|
480 |
begin |
|
6695
32de8965c62c
refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents:
6689
diff
changeset
|
481 |
frame.x:= source.x + Round((target.x - source.x) * ((RealTicks - startTime) / MOVE_ANIM_TIME)); |
32de8965c62c
refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents:
6689
diff
changeset
|
482 |
frame.y:= source.y + Round((target.y - source.y) * ((RealTicks - startTime) / MOVE_ANIM_TIME)); |
6688 | 483 |
end; |
484 |
||
485 |
if show or (fadeAnimStart <> 0) then |
|
486 |
begin |
|
487 |
Tint($FF, $FF, $FF, alpha); |
|
6695
32de8965c62c
refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents:
6689
diff
changeset
|
488 |
DrawTexture(frame.x, frame.y, spritesData[sprite].Texture, buttonScale); |
6688 | 489 |
Tint($FF, $FF, $FF, $FF); |
490 |
end; |
|
491 |
end; |
|
6689 | 492 |
{$ENDIF} |
6688 | 493 |
end; |
4385 | 494 |
|
4378 | 495 |
procedure Tint(r, g, b, a: Byte); inline; |
5559 | 496 |
const |
497 |
lastTint: Longword = 0; |
|
498 |
var |
|
499 |
nc, tw: Longword; |
|
4378 | 500 |
begin |
501 |
nc:= (a shl 24) or (b shl 16) or (g shl 8) or r; |
|
5559 | 502 |
|
4378 | 503 |
if nc = lastTint then |
504 |
exit; |
|
5559 | 505 |
|
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
506 |
if cGrayScale then |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
507 |
begin |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
508 |
tw:= round(r * RGB_LUMINANCE_RED + g * RGB_LUMINANCE_GREEN + b * RGB_LUMINANCE_BLUE); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
509 |
if tw > 255 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
510 |
tw:= 255; |
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
511 |
r:= tw; |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
512 |
g:= tw; |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
513 |
b:= tw |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
514 |
end; |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
515 |
|
4378 | 516 |
glColor4ub(r, g, b, a); |
517 |
lastTint:= nc; |
|
518 |
end; |
|
519 |
||
520 |
procedure Tint(c: Longword); inline; |
|
521 |
begin |
|
4452 | 522 |
Tint(((c shr 24) and $FF), ((c shr 16) and $FF), (c shr 8) and $FF, (c and $FF)) |
4378 | 523 |
end; |
524 |
||
525 |
end. |