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