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