author | nemo |
Fri, 20 Jul 2012 21:15:38 -0400 | |
changeset 7412 | 9e5aa3c8dc62 |
parent 7069 | bcf9d8e64e92 |
child 7080 | dbf43c07a507 |
child 8026 | 4a4f21070479 |
child 8145 | 6408c0ba4ba1 |
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 |
|
6999 | 27 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
28 |
procedure DrawSprite (Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
|
29 |
procedure DrawSpriteFromRect (Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
|
30 |
procedure DrawSpriteClipped (Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
|
31 |
procedure DrawSpriteRotated (Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
|
32 |
procedure DrawSpriteRotatedF (Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
|
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
33 |
|
6999 | 34 |
procedure DrawTexture (X, Y: LongInt; Texture: PTexture); inline; |
35 |
procedure DrawTexture (X, Y: LongInt; Texture: PTexture; Scale: GLfloat); |
|
36 |
procedure DrawTextureFromRect (X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
|
37 |
procedure DrawTextureFromRect (X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
|
38 |
procedure DrawTextureCentered (X, Top: LongInt; Source: PTexture); |
|
39 |
procedure DrawTextureF (Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt); |
|
40 |
procedure DrawTextureRotated (Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
|
41 |
procedure DrawTextureRotatedF (Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
|
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
42 |
|
6999 | 43 |
procedure DrawCircle (X, Y, Radius, Width: LongInt); |
44 |
procedure DrawCircle (X, Y, Radius, Width: LongInt; r, g, b, a: Byte); |
|
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
45 |
|
6999 | 46 |
procedure DrawLine (X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte); |
47 |
procedure DrawFillRect (r: TSDL_Rect); |
|
48 |
procedure DrawHedgehog (X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
|
49 |
procedure DrawScreenWidget (widget: POnScreenWidget); |
|
50 |
||
51 |
procedure Tint (r, g, b, a: Byte); inline; |
|
52 |
procedure Tint (c: Longword); inline; |
|
4378 | 53 |
|
4385 | 54 |
|
4378 | 55 |
implementation |
56 |
uses uVariables; |
|
57 |
||
7028 | 58 |
var LastTint: LongWord = 0; |
59 |
||
4378 | 60 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
61 |
begin |
|
62 |
r.y:= r.y + Height * Position; |
|
63 |
r.h:= Height; |
|
6999 | 64 |
DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4378 | 65 |
end; |
66 |
||
6999 | 67 |
procedure DrawTextureFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
4378 | 68 |
begin |
6999 | 69 |
DrawTextureFromRect(X, Y, r^.w, r^.h, r, SourceTexture) |
4378 | 70 |
end; |
71 |
||
6999 | 72 |
procedure DrawTextureFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
4378 | 73 |
var rr: TSDL_Rect; |
74 |
_l, _r, _t, _b: real; |
|
75 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
|
76 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
77 |
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
|
78 |
exit; |
4378 | 79 |
|
5565 | 80 |
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
4378 | 81 |
if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then |
82 |
exit; |
|
83 |
if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) > cScreenHeight / cScaleFactor) then |
|
84 |
exit; |
|
85 |
||
86 |
rr.x:= X; |
|
87 |
rr.y:= Y; |
|
88 |
rr.w:= W; |
|
89 |
rr.h:= H; |
|
90 |
||
91 |
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx; |
|
92 |
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx; |
|
93 |
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry; |
|
94 |
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry; |
|
95 |
||
96 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
97 |
||
98 |
VertexBuffer[0].X:= X; |
|
99 |
VertexBuffer[0].Y:= Y; |
|
100 |
VertexBuffer[1].X:= rr.w + X; |
|
101 |
VertexBuffer[1].Y:= Y; |
|
102 |
VertexBuffer[2].X:= rr.w + X; |
|
103 |
VertexBuffer[2].Y:= rr.h + Y; |
|
104 |
VertexBuffer[3].X:= X; |
|
105 |
VertexBuffer[3].Y:= rr.h + Y; |
|
106 |
||
107 |
TextureBuffer[0].X:= _l; |
|
108 |
TextureBuffer[0].Y:= _t; |
|
109 |
TextureBuffer[1].X:= _r; |
|
110 |
TextureBuffer[1].Y:= _t; |
|
111 |
TextureBuffer[2].X:= _r; |
|
112 |
TextureBuffer[2].Y:= _b; |
|
113 |
TextureBuffer[3].X:= _l; |
|
114 |
TextureBuffer[3].Y:= _b; |
|
115 |
||
116 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
117 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
118 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
119 |
end; |
|
120 |
||
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
121 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); inline; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
122 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
123 |
DrawTexture(X, Y, Texture, 1.0); |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
124 |
end; |
4378 | 125 |
|
126 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat); |
|
127 |
begin |
|
128 |
||
129 |
glPushMatrix; |
|
130 |
glTranslatef(X, Y, 0); |
|
131 |
glScalef(Scale, Scale, 1); |
|
132 |
||
133 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
134 |
||
135 |
glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb); |
|
136 |
glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb); |
|
137 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); |
|
138 |
||
139 |
glPopMatrix |
|
140 |
end; |
|
141 |
||
142 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt); |
|
143 |
begin |
|
6999 | 144 |
DrawTextureRotatedF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0) |
4378 | 145 |
end; |
146 |
||
6999 | 147 |
procedure DrawTextureRotatedF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
4378 | 148 |
var ft, fb, fl, fr: GLfloat; |
149 |
hw, nx, ny: LongInt; |
|
150 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
|
151 |
begin |
|
5565 | 152 |
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
4378 | 153 |
if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * cScaleFactor > cScreenWidth) then |
154 |
exit; |
|
155 |
if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then |
|
156 |
exit; |
|
157 |
||
158 |
glPushMatrix; |
|
159 |
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
|
160 |
if Dir = 0 then Dir:= 1; |
4378 | 161 |
|
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
|
162 |
glRotatef(Angle, 0, 0, Dir); |
4378 | 163 |
|
164 |
glTranslatef(Dir*OffsetX, OffsetY, 0); |
|
165 |
glScalef(Scale, Scale, 1); |
|
166 |
||
167 |
// Any reason for this call? And why only in t direction, not s? |
|
168 |
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
|
169 |
||
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
|
170 |
hw:= w div (2 div Dir); |
4378 | 171 |
|
172 |
nx:= round(Texture^.w / w); // number of horizontal frames |
|
173 |
ny:= round(Texture^.h / h); // number of vertical frames |
|
174 |
||
175 |
ft:= (Frame mod ny) * Texture^.ry / ny; |
|
176 |
fb:= ((Frame mod ny) + 1) * Texture^.ry / ny; |
|
177 |
fl:= (Frame div ny) * Texture^.rx / nx; |
|
178 |
fr:= ((Frame div ny) + 1) * Texture^.rx / nx; |
|
179 |
||
180 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
181 |
||
182 |
VertexBuffer[0].X:= -hw; |
|
183 |
VertexBuffer[0].Y:= w / -2; |
|
184 |
VertexBuffer[1].X:= hw; |
|
185 |
VertexBuffer[1].Y:= w / -2; |
|
186 |
VertexBuffer[2].X:= hw; |
|
187 |
VertexBuffer[2].Y:= w / 2; |
|
188 |
VertexBuffer[3].X:= -hw; |
|
189 |
VertexBuffer[3].Y:= w / 2; |
|
190 |
||
191 |
TextureBuffer[0].X:= fl; |
|
192 |
TextureBuffer[0].Y:= ft; |
|
193 |
TextureBuffer[1].X:= fr; |
|
194 |
TextureBuffer[1].Y:= ft; |
|
195 |
TextureBuffer[2].X:= fr; |
|
196 |
TextureBuffer[2].Y:= fb; |
|
197 |
TextureBuffer[3].X:= fl; |
|
198 |
TextureBuffer[3].Y:= fb; |
|
199 |
||
200 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
201 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
202 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
203 |
||
204 |
glPopMatrix |
|
205 |
end; |
|
206 |
||
6999 | 207 |
procedure DrawSpriteRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
4378 | 208 |
begin |
6999 | 209 |
DrawTextureRotated(SpritesData[Sprite].Texture, |
4378 | 210 |
SpritesData[Sprite].Width, |
211 |
SpritesData[Sprite].Height, |
|
212 |
X, Y, Dir, Angle) |
|
213 |
end; |
|
214 |
||
6999 | 215 |
procedure DrawSpriteRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
4378 | 216 |
begin |
217 |
glPushMatrix; |
|
218 |
glTranslatef(X, Y, 0); |
|
219 |
||
220 |
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
|
221 |
glRotatef(Angle, 0, 0, -1) |
4378 | 222 |
else |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
223 |
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
|
224 |
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
|
225 |
glScalef(-1.0, 1.0, 1.0); |
4378 | 226 |
|
227 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
228 |
||
229 |
glPopMatrix |
|
230 |
end; |
|
231 |
||
6999 | 232 |
procedure DrawTextureRotated(Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
4378 | 233 |
var VertexBuffer: array [0..3] of TVertex2f; |
234 |
begin |
|
5565 | 235 |
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
4378 | 236 |
if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then |
237 |
exit; |
|
238 |
if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then |
|
239 |
exit; |
|
240 |
||
241 |
glPushMatrix; |
|
242 |
glTranslatef(X, Y, 0); |
|
243 |
||
244 |
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
|
245 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
246 |
hw:= - hw; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
247 |
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
|
248 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
249 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
250 |
glRotatef(Angle, 0, 0, 1); |
4378 | 251 |
|
252 |
||
6999 | 253 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
4378 | 254 |
|
255 |
VertexBuffer[0].X:= -hw; |
|
256 |
VertexBuffer[0].Y:= -hh; |
|
257 |
VertexBuffer[1].X:= hw; |
|
258 |
VertexBuffer[1].Y:= -hh; |
|
259 |
VertexBuffer[2].X:= hw; |
|
260 |
VertexBuffer[2].Y:= hh; |
|
261 |
VertexBuffer[3].X:= -hw; |
|
262 |
VertexBuffer[3].Y:= hh; |
|
263 |
||
264 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
6999 | 265 |
glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb); |
4378 | 266 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
267 |
||
268 |
glPopMatrix |
|
269 |
end; |
|
270 |
||
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
271 |
procedure DrawSprite(Sprite: TSprite; X, Y, Frame: LongInt); |
4378 | 272 |
var row, col, numFramesFirstCol: LongInt; |
273 |
begin |
|
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
274 |
if SpritesData[Sprite].imageHeight = 0 then |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
275 |
exit; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
276 |
numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
277 |
row:= Frame mod numFramesFirstCol; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
278 |
col:= Frame div numFramesFirstCol; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
279 |
DrawSprite(Sprite, X, Y, col, row); |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
280 |
end; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
281 |
|
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
282 |
procedure DrawSprite(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
283 |
var r: TSDL_Rect; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
284 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
285 |
r.x:= FrameX * SpritesData[Sprite].Width; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
286 |
r.w:= SpritesData[Sprite].Width; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
287 |
r.y:= FrameY * SpritesData[Sprite].Height; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
288 |
r.h:= SpritesData[Sprite].Height; |
6999 | 289 |
DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4378 | 290 |
end; |
291 |
||
292 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
|
293 |
var r: TSDL_Rect; |
|
294 |
begin |
|
295 |
r.x:= 0; |
|
296 |
r.y:= 0; |
|
297 |
r.w:= SpritesData[Sprite].Width; |
|
298 |
r.h:= SpritesData[Sprite].Height; |
|
299 |
||
300 |
if (X < LeftX) then |
|
301 |
r.x:= LeftX - X; |
|
302 |
if (Y < TopY) then |
|
303 |
r.y:= TopY - Y; |
|
304 |
||
305 |
if (Y + SpritesData[Sprite].Height > BottomY) then |
|
306 |
r.h:= BottomY - Y + 1; |
|
307 |
if (X + SpritesData[Sprite].Width > RightX) then |
|
308 |
r.w:= RightX - X + 1; |
|
309 |
||
310 |
dec(r.h, r.y); |
|
311 |
dec(r.w, r.x); |
|
312 |
||
6999 | 313 |
DrawTextureFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture) |
4378 | 314 |
end; |
315 |
||
6999 | 316 |
procedure DrawTextureCentered(X, Top: LongInt; Source: PTexture); |
4378 | 317 |
var scale: GLfloat; |
318 |
begin |
|
319 |
if (Source^.w + 20) > cScreenWidth then |
|
320 |
scale:= cScreenWidth / (Source^.w + 20) |
|
321 |
else |
|
322 |
scale:= 1.0; |
|
323 |
DrawTexture(X - round(Source^.w * scale) div 2, Top, Source, scale) |
|
324 |
end; |
|
325 |
||
326 |
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte); |
|
327 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
328 |
begin |
|
329 |
glDisable(GL_TEXTURE_2D); |
|
330 |
glEnable(GL_LINE_SMOOTH); |
|
331 |
||
332 |
glPushMatrix; |
|
333 |
glTranslatef(WorldDx, WorldDy, 0); |
|
334 |
glLineWidth(Width); |
|
335 |
||
336 |
Tint(r, g, b, a); |
|
337 |
VertexBuffer[0].X:= X0; |
|
338 |
VertexBuffer[0].Y:= Y0; |
|
339 |
VertexBuffer[1].X:= X1; |
|
340 |
VertexBuffer[1].Y:= Y1; |
|
341 |
||
342 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
343 |
glDrawArrays(GL_LINES, 0, Length(VertexBuffer)); |
|
344 |
Tint($FF, $FF, $FF, $FF); |
|
345 |
||
346 |
glPopMatrix; |
|
347 |
||
348 |
glEnable(GL_TEXTURE_2D); |
|
349 |
glDisable(GL_LINE_SMOOTH); |
|
350 |
end; |
|
351 |
||
352 |
procedure DrawFillRect(r: TSDL_Rect); |
|
353 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
354 |
begin |
|
5565 | 355 |
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
4378 | 356 |
if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) * cScaleFactor > cScreenWidth) then |
357 |
exit; |
|
358 |
if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) * cScaleFactor > cScreenHeight) then |
|
359 |
exit; |
|
360 |
||
361 |
glDisable(GL_TEXTURE_2D); |
|
362 |
||
363 |
Tint($00, $00, $00, $80); |
|
364 |
||
365 |
VertexBuffer[0].X:= r.x; |
|
366 |
VertexBuffer[0].Y:= r.y; |
|
367 |
VertexBuffer[1].X:= r.x + r.w; |
|
368 |
VertexBuffer[1].Y:= r.y; |
|
369 |
VertexBuffer[2].X:= r.x + r.w; |
|
370 |
VertexBuffer[2].Y:= r.y + r.h; |
|
371 |
VertexBuffer[3].X:= r.x; |
|
372 |
VertexBuffer[3].Y:= r.y + r.h; |
|
373 |
||
374 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
375 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
376 |
||
377 |
Tint($FF, $FF, $FF, $FF); |
|
378 |
glEnable(GL_TEXTURE_2D) |
|
379 |
end; |
|
380 |
||
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
|
381 |
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
|
382 |
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
|
383 |
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
|
384 |
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
|
385 |
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
|
386 |
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
|
387 |
|
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
|
388 |
procedure DrawCircle(X, Y, Radius, Width: LongInt); |
4378 | 389 |
var |
390 |
i: LongInt; |
|
5561
dfbe55237c64
Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents:
5559
diff
changeset
|
391 |
CircleVertex: array [0..59] of TVertex2f; |
4378 | 392 |
begin |
5561
dfbe55237c64
Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents:
5559
diff
changeset
|
393 |
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
|
394 |
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
|
395 |
CircleVertex[i].Y := Y + Radius*sin(i*pi/30); |
4378 | 396 |
end; |
397 |
glDisable(GL_TEXTURE_2D); |
|
398 |
glEnable(GL_LINE_SMOOTH); |
|
399 |
glPushMatrix; |
|
400 |
glLineWidth(Width); |
|
401 |
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
|
402 |
glDrawArrays(GL_LINE_LOOP, 0, 60); |
4378 | 403 |
glPopMatrix; |
404 |
glEnable(GL_TEXTURE_2D); |
|
405 |
glDisable(GL_LINE_SMOOTH); |
|
406 |
end; |
|
407 |
||
408 |
||
4385 | 409 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
410 |
const VertexBuffer: array [0..3] of TVertex2f = ( |
|
7069 | 411 |
(X: -16; Y: -16), |
412 |
(X: 16; Y: -16), |
|
413 |
(X: 16; Y: 16), |
|
414 |
(X: -16; Y: 16)); |
|
4385 | 415 |
var l, r, t, b: real; |
416 |
TextureBuffer: array [0..3] of TVertex2f; |
|
417 |
begin |
|
5565 | 418 |
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
4385 | 419 |
if (abs(X) > 32) and ((abs(X) - 16) * cScaleFactor > cScreenWidth) then |
420 |
exit; |
|
421 |
if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) * cScaleFactor > cScreenHeight) then |
|
422 |
exit; |
|
423 |
||
424 |
t:= Pos * 32 / HHTexture^.h; |
|
425 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
426 |
||
427 |
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
|
428 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
429 |
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
|
430 |
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
|
431 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
432 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
433 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
434 |
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
|
435 |
r:= (Step + 1) * 32 / HHTexture^.w |
4385 | 436 |
end; |
437 |
||
438 |
||
439 |
glPushMatrix(); |
|
440 |
glTranslatef(X, Y, 0); |
|
441 |
glRotatef(Angle, 0, 0, 1); |
|
442 |
||
443 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
|
444 |
||
445 |
TextureBuffer[0].X:= l; |
|
446 |
TextureBuffer[0].Y:= t; |
|
447 |
TextureBuffer[1].X:= r; |
|
448 |
TextureBuffer[1].Y:= t; |
|
449 |
TextureBuffer[2].X:= r; |
|
450 |
TextureBuffer[2].Y:= b; |
|
451 |
TextureBuffer[3].X:= l; |
|
452 |
TextureBuffer[3].Y:= b; |
|
453 |
||
454 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
455 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
456 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
457 |
||
458 |
glPopMatrix |
|
459 |
end; |
|
460 |
||
6688 | 461 |
procedure DrawScreenWidget(widget: POnScreenWidget); |
6992 | 462 |
{$IFDEF USE_TOUCH_INTERFACE} |
6688 | 463 |
var alpha: byte = $FF; |
464 |
begin |
|
465 |
with widget^ do |
|
466 |
begin |
|
467 |
if (fadeAnimStart <> 0) then |
|
468 |
begin |
|
469 |
if RealTicks > (fadeAnimStart + FADE_ANIM_TIME) then |
|
470 |
fadeAnimStart:= 0 |
|
471 |
else |
|
472 |
if show then |
|
473 |
alpha:= Byte(trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF)) |
|
474 |
else |
|
475 |
alpha:= Byte($FF - trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF)); |
|
476 |
end; |
|
477 |
||
478 |
with moveAnim do |
|
479 |
if animate then |
|
480 |
if RealTicks > (startTime + MOVE_ANIM_TIME) then |
|
481 |
begin |
|
482 |
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
|
483 |
animate:= false; |
6695
32de8965c62c
refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents:
6689
diff
changeset
|
484 |
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
|
485 |
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
|
486 |
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
|
487 |
active.y:= active.y + (target.y - source.y); |
6688 | 488 |
end |
489 |
else |
|
490 |
begin |
|
6695
32de8965c62c
refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents:
6689
diff
changeset
|
491 |
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
|
492 |
frame.y:= source.y + Round((target.y - source.y) * ((RealTicks - startTime) / MOVE_ANIM_TIME)); |
6688 | 493 |
end; |
494 |
||
495 |
if show or (fadeAnimStart <> 0) then |
|
496 |
begin |
|
497 |
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
|
498 |
DrawTexture(frame.x, frame.y, spritesData[sprite].Texture, buttonScale); |
6688 | 499 |
Tint($FF, $FF, $FF, $FF); |
500 |
end; |
|
501 |
end; |
|
6992 | 502 |
{$ELSE} |
503 |
begin |
|
504 |
widget:= widget; // avoid hint |
|
6689 | 505 |
{$ENDIF} |
6688 | 506 |
end; |
4385 | 507 |
|
4378 | 508 |
procedure Tint(r, g, b, a: Byte); inline; |
6982 | 509 |
var nc, tw: Longword; |
4378 | 510 |
begin |
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
511 |
nc:= (a shl 24) or (b shl 16) or (g shl 8) or r; |
5559 | 512 |
|
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
513 |
if nc = lastTint then |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
514 |
exit; |
5559 | 515 |
|
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
516 |
if GrayScale then |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
517 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
518 |
tw:= round(r * RGB_LUMINANCE_RED + g * RGB_LUMINANCE_GREEN + b * RGB_LUMINANCE_BLUE); |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
519 |
if tw > 255 then |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
520 |
tw:= 255; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
521 |
r:= tw; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
522 |
g:= tw; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
523 |
b:= tw |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
524 |
end; |
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
525 |
|
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
526 |
glColor4ub(r, g, b, a); |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
527 |
lastTint:= nc; |
4378 | 528 |
end; |
529 |
||
530 |
procedure Tint(c: Longword); inline; |
|
531 |
begin |
|
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
532 |
Tint(((c shr 24) and $FF), ((c shr 16) and $FF), (c shr 8) and $FF, (c and $FF)) |
4378 | 533 |
end; |
534 |
||
535 |
end. |