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