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