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