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