author | sheepluva |
Tue, 10 Jun 2014 08:47:03 +0200 | |
changeset 10266 | a90a55ec5b98 |
parent 10255 | fdc342ebdc31 |
child 10275 | 6c91047f59b6 |
permissions | -rw-r--r-- |
4976 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
9998 | 3 |
* Copyright (c) 2004-2014 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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
10040
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4976 | 17 |
*) |
18 |
||
4378 | 19 |
{$INCLUDE "options.inc"} |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
20 |
{$IF GLunit = GL}{$DEFINE GLunit:=GL,GLext}{$ENDIF} |
4976 | 21 |
|
4378 | 22 |
unit uRender; |
23 |
||
24 |
interface |
|
25 |
||
10015 | 26 |
uses SDLh, uTypes, GLunit, uConsts, uStore{$IFDEF GL2}, uMatrix{$ENDIF}; |
4378 | 27 |
|
6999 | 28 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
29 |
procedure DrawSprite (Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
|
8560 | 30 |
procedure DrawSpriteFromRect (Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); inline; |
6999 | 31 |
procedure DrawSpriteClipped (Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
32 |
procedure DrawSpriteRotated (Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
|
33 |
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
|
34 |
|
6999 | 35 |
procedure DrawTexture (X, Y: LongInt; Texture: PTexture); inline; |
36 |
procedure DrawTexture (X, Y: LongInt; Texture: PTexture; Scale: GLfloat); |
|
10020
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
37 |
procedure DrawTexture2 (X, Y: LongInt; Texture: PTexture; Scale, Overlap: GLfloat); |
8560 | 38 |
procedure DrawTextureFromRect (X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline; |
39 |
procedure DrawTextureFromRect (X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline; |
|
40 |
procedure DrawTextureFromRectDir(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture; Dir: LongInt); |
|
6999 | 41 |
procedure DrawTextureCentered (X, Top: LongInt; Source: PTexture); |
42 |
procedure DrawTextureF (Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt); |
|
43 |
procedure DrawTextureRotated (Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
|
44 |
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
|
45 |
|
6999 | 46 |
procedure DrawCircle (X, Y, Radius, Width: LongInt); |
47 |
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
|
48 |
|
9557 | 49 |
procedure DrawLine (X0, Y0, X1, Y1, Width: Single; color: LongWord); inline; |
6999 | 50 |
procedure DrawLine (X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte); |
51 |
procedure DrawFillRect (r: TSDL_Rect); |
|
52 |
procedure DrawHedgehog (X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
|
53 |
procedure DrawScreenWidget (widget: POnScreenWidget); |
|
54 |
||
10255
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
55 |
procedure openglTint (r, g, b, a: Byte); inline; |
6999 | 56 |
procedure Tint (r, g, b, a: Byte); inline; |
57 |
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
|
58 |
procedure untint(); inline; |
8dcb25112d96
- Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents:
9557
diff
changeset
|
59 |
procedure setTintAdd (f: boolean); inline; |
4378 | 60 |
|
10266 | 61 |
function isAreaOffscreen(X, Y, Width, Height: LongInt): boolean; inline; |
62 |
||
63 |
// 0 => not offscreen, <0 => left/top of screen >0 => right/below of screen |
|
64 |
function isDxAreaOffscreen(X, Width: LongInt): LongInt; inline; |
|
65 |
function isDyAreaOffscreen(Y, Height: LongInt): LongInt; inline; |
|
66 |
||
4378 | 67 |
implementation |
68 |
uses uVariables; |
|
69 |
||
8145
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
7069
diff
changeset
|
70 |
{$IFDEF USE_TOUCH_INTERFACE} |
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
7069
diff
changeset
|
71 |
const |
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
7069
diff
changeset
|
72 |
FADE_ANIM_TIME = 500; |
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
7069
diff
changeset
|
73 |
MOVE_ANIM_TIME = 500; |
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
7069
diff
changeset
|
74 |
{$ENDIF} |
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
7069
diff
changeset
|
75 |
|
7028 | 76 |
var LastTint: LongWord = 0; |
77 |
||
10266 | 78 |
function isAreaOffscreen(X, Y, Width, Height: LongInt): boolean; inline; |
79 |
begin |
|
80 |
isAreaOffscreen:= (isDxAreaOffscreen(X, Width) <> 0) or (isDyAreaOffscreen(Y, Height) <> 0); |
|
81 |
end; |
|
82 |
||
83 |
function isDxAreaOffscreen(X, Width: LongInt): LongInt; inline; |
|
84 |
begin |
|
85 |
if X > ViewRightX then exit(1); |
|
86 |
if X + Width < ViewLeftX then exit(-1); |
|
87 |
isDxAreaOffscreen:= 0; |
|
88 |
end; |
|
89 |
||
90 |
function isDyAreaOffscreen(Y, Height: LongInt): LongInt; inline; |
|
91 |
begin |
|
92 |
if Y > ViewBottomY then exit(1); |
|
93 |
if Y + Height < ViewTopY then exit(-1); |
|
94 |
isDyAreaOffscreen:= 0; |
|
95 |
end; |
|
96 |
||
8560 | 97 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); inline; |
4378 | 98 |
begin |
99 |
r.y:= r.y + Height * Position; |
|
100 |
r.h:= Height; |
|
6999 | 101 |
DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4378 | 102 |
end; |
103 |
||
8560 | 104 |
procedure DrawTextureFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline; |
4378 | 105 |
begin |
8560 | 106 |
DrawTextureFromRectDir(X, Y, r^.w, r^.h, r, SourceTexture, 1) |
107 |
end; |
|
8833 | 108 |
|
8560 | 109 |
procedure DrawTextureFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline; |
110 |
begin |
|
111 |
DrawTextureFromRectDir(X, Y, W, H, r, SourceTexture, 1) |
|
4378 | 112 |
end; |
113 |
||
8560 | 114 |
procedure DrawTextureFromRectDir(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture; Dir: LongInt); |
4378 | 115 |
var rr: TSDL_Rect; |
116 |
_l, _r, _t, _b: real; |
|
117 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
|
118 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
119 |
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
|
120 |
exit; |
4378 | 121 |
|
5565 | 122 |
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
4378 | 123 |
if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then |
124 |
exit; |
|
125 |
if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) > cScreenHeight / cScaleFactor) then |
|
126 |
exit; |
|
127 |
||
128 |
rr.x:= X; |
|
129 |
rr.y:= Y; |
|
130 |
rr.w:= W; |
|
131 |
rr.h:= H; |
|
132 |
||
133 |
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx; |
|
134 |
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx; |
|
135 |
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry; |
|
136 |
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry; |
|
137 |
||
138 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
139 |
||
8560 | 140 |
if Dir < 0 then |
141 |
begin |
|
142 |
VertexBuffer[0].X:= X + rr.w/2; |
|
143 |
VertexBuffer[0].Y:= Y; |
|
144 |
VertexBuffer[1].X:= X - rr.w/2; |
|
145 |
VertexBuffer[1].Y:= Y; |
|
146 |
VertexBuffer[2].X:= X - rr.w/2; |
|
147 |
VertexBuffer[2].Y:= rr.h + Y; |
|
148 |
VertexBuffer[3].X:= X + rr.w/2; |
|
149 |
VertexBuffer[3].Y:= rr.h + Y; |
|
150 |
end |
|
151 |
else |
|
152 |
begin |
|
153 |
VertexBuffer[0].X:= X; |
|
154 |
VertexBuffer[0].Y:= Y; |
|
155 |
VertexBuffer[1].X:= rr.w + X; |
|
156 |
VertexBuffer[1].Y:= Y; |
|
157 |
VertexBuffer[2].X:= rr.w + X; |
|
158 |
VertexBuffer[2].Y:= rr.h + Y; |
|
159 |
VertexBuffer[3].X:= X; |
|
160 |
VertexBuffer[3].Y:= rr.h + Y; |
|
161 |
end; |
|
4378 | 162 |
|
163 |
TextureBuffer[0].X:= _l; |
|
164 |
TextureBuffer[0].Y:= _t; |
|
165 |
TextureBuffer[1].X:= _r; |
|
166 |
TextureBuffer[1].Y:= _t; |
|
167 |
TextureBuffer[2].X:= _r; |
|
168 |
TextureBuffer[2].Y:= _b; |
|
169 |
TextureBuffer[3].X:= _l; |
|
170 |
TextureBuffer[3].Y:= _b; |
|
171 |
||
172 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
173 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
174 |
glDrawArrays(GL_TRIANGLE_FAN, 0, High(VertexBuffer) - Low(VertexBuffer) + 1); |
4378 | 175 |
end; |
176 |
||
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
177 |
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
|
178 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
179 |
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
|
180 |
end; |
4378 | 181 |
|
182 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat); |
|
183 |
begin |
|
184 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
185 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
186 |
hglPushMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
187 |
hglTranslatef(X, Y, 0); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
188 |
hglScalef(Scale, Scale, 1); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
189 |
{$ELSE} |
4378 | 190 |
glPushMatrix; |
191 |
glTranslatef(X, Y, 0); |
|
192 |
glScalef(Scale, Scale, 1); |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
193 |
{$ENDIF} |
4378 | 194 |
|
195 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
196 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
197 |
SetVertexPointer(@Texture^.vb, Length(Texture^.vb)); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
198 |
SetTexCoordPointer(@Texture^.tb, Length(Texture^.vb)); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
199 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
200 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
201 |
UpdateModelviewProjection; |
4378 | 202 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
203 |
hglPopMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
204 |
{$ELSE} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
205 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
206 |
glPopMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
207 |
{$ENDIF} |
4378 | 208 |
|
209 |
end; |
|
210 |
||
10020
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
211 |
{ this contains tweaks in order to avoid land tile borders in blurry land mode } |
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
212 |
procedure DrawTexture2(X, Y: LongInt; Texture: PTexture; Scale, Overlap: GLfloat); |
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
213 |
var |
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
214 |
TextureBuffer: array [0..3] of TVertex2f; |
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
215 |
begin |
10266 | 216 |
{$IFDEF GL2} |
217 |
hglPushMatrix; |
|
218 |
hglTranslatef(X, Y, 0); |
|
219 |
hglScalef(Scale, Scale, 1); |
|
220 |
{$ELSE} |
|
221 |
glPushMatrix; |
|
10020
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
222 |
glTranslatef(X, Y, 0); |
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
223 |
glScalef(Scale, Scale, 1); |
10266 | 224 |
{$ENDIF} |
10020
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
225 |
|
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
226 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
227 |
|
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
228 |
TextureBuffer[0].X:= Texture^.tb[0].X + Overlap; |
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
229 |
TextureBuffer[0].Y:= Texture^.tb[0].Y + Overlap; |
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
230 |
TextureBuffer[1].X:= Texture^.tb[1].X - Overlap; |
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
231 |
TextureBuffer[1].Y:= Texture^.tb[1].Y + Overlap; |
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
232 |
TextureBuffer[2].X:= Texture^.tb[2].X - Overlap; |
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
233 |
TextureBuffer[2].Y:= Texture^.tb[2].Y - Overlap; |
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
234 |
TextureBuffer[3].X:= Texture^.tb[3].X + Overlap; |
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
235 |
TextureBuffer[3].Y:= Texture^.tb[3].Y - Overlap; |
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
236 |
|
10266 | 237 |
SetVertexPointer(@Texture^.vb, Length(Texture^.vb)); |
238 |
SetTexCoordPointer(@TextureBuffer, Length(Texture^.vb)); |
|
239 |
||
240 |
{$IFDEF GL2} |
|
241 |
UpdateModelviewProjection; |
|
10020
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
242 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); |
10266 | 243 |
hglPopMatrix; |
244 |
{$ELSE} |
|
245 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); |
|
246 |
glPopMatrix; |
|
247 |
{$ENDIF} |
|
10020
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
248 |
end; |
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
249 |
|
4378 | 250 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt); |
251 |
begin |
|
6999 | 252 |
DrawTextureRotatedF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0) |
4378 | 253 |
end; |
254 |
||
6999 | 255 |
procedure DrawTextureRotatedF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
4378 | 256 |
var ft, fb, fl, fr: GLfloat; |
257 |
hw, nx, ny: LongInt; |
|
258 |
VertexBuffer, TextureBuffer: 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) > W) and ((abs(X + dir * OffsetX) - W / 2) * cScaleFactor > cScreenWidth) then |
262 |
exit; |
|
263 |
if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then |
|
264 |
exit; |
|
265 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
266 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
267 |
hglPushMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
268 |
hglTranslatef(X, Y, 0); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
269 |
{$ELSE} |
4378 | 270 |
glPushMatrix; |
271 |
glTranslatef(X, Y, 0); |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
272 |
{$ENDIF} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
273 |
|
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
|
274 |
if Dir = 0 then Dir:= 1; |
4378 | 275 |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
276 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
277 |
hglRotatef(Angle, 0, 0, Dir); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
278 |
hglTranslatef(Dir*OffsetX, OffsetY, 0); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
279 |
hglScalef(Scale, Scale, 1); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
280 |
{$ELSE} |
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
|
281 |
glRotatef(Angle, 0, 0, Dir); |
4378 | 282 |
glTranslatef(Dir*OffsetX, OffsetY, 0); |
283 |
glScalef(Scale, Scale, 1); |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
284 |
{$ENDIF} |
4378 | 285 |
|
286 |
// Any reason for this call? And why only in t direction, not s? |
|
287 |
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
|
288 |
||
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
|
289 |
hw:= w div (2 div Dir); |
4378 | 290 |
|
291 |
nx:= round(Texture^.w / w); // number of horizontal frames |
|
292 |
ny:= round(Texture^.h / h); // number of vertical frames |
|
293 |
||
294 |
ft:= (Frame mod ny) * Texture^.ry / ny; |
|
295 |
fb:= ((Frame mod ny) + 1) * Texture^.ry / ny; |
|
296 |
fl:= (Frame div ny) * Texture^.rx / nx; |
|
297 |
fr:= ((Frame div ny) + 1) * Texture^.rx / nx; |
|
298 |
||
299 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
300 |
||
301 |
VertexBuffer[0].X:= -hw; |
|
302 |
VertexBuffer[0].Y:= w / -2; |
|
303 |
VertexBuffer[1].X:= hw; |
|
304 |
VertexBuffer[1].Y:= w / -2; |
|
305 |
VertexBuffer[2].X:= hw; |
|
306 |
VertexBuffer[2].Y:= w / 2; |
|
307 |
VertexBuffer[3].X:= -hw; |
|
308 |
VertexBuffer[3].Y:= w / 2; |
|
309 |
||
310 |
TextureBuffer[0].X:= fl; |
|
311 |
TextureBuffer[0].Y:= ft; |
|
312 |
TextureBuffer[1].X:= fr; |
|
313 |
TextureBuffer[1].Y:= ft; |
|
314 |
TextureBuffer[2].X:= fr; |
|
315 |
TextureBuffer[2].Y:= fb; |
|
316 |
TextureBuffer[3].X:= fl; |
|
317 |
TextureBuffer[3].Y:= fb; |
|
318 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
319 |
SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer)); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
320 |
SetTexCoordPointer(@TextureBuffer[0], Length(VertexBuffer)); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
321 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
322 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
323 |
UpdateModelviewProjection; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
324 |
{$ENDIF} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
325 |
|
4378 | 326 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
327 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
328 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
329 |
hglPopMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
330 |
{$ELSE} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
331 |
glPopMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
332 |
{$ENDIF} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
333 |
|
4378 | 334 |
end; |
335 |
||
6999 | 336 |
procedure DrawSpriteRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
4378 | 337 |
begin |
6999 | 338 |
DrawTextureRotated(SpritesData[Sprite].Texture, |
4378 | 339 |
SpritesData[Sprite].Width, |
340 |
SpritesData[Sprite].Height, |
|
341 |
X, Y, Dir, Angle) |
|
342 |
end; |
|
343 |
||
6999 | 344 |
procedure DrawSpriteRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
4378 | 345 |
begin |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
346 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
347 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
348 |
hglPushMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
349 |
hglTranslatef(X, Y, 0); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
350 |
{$ELSE} |
4378 | 351 |
glPushMatrix; |
352 |
glTranslatef(X, Y, 0); |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
353 |
{$ENDIF} |
4378 | 354 |
|
355 |
if Dir < 0 then |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
356 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
357 |
hglRotatef(Angle, 0, 0, -1) |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
358 |
{$ELSE} |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
359 |
glRotatef(Angle, 0, 0, -1) |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
360 |
{$ENDIF} |
4378 | 361 |
else |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
362 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
363 |
hglRotatef(Angle, 0, 0, 1); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
364 |
{$ELSE} |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
365 |
glRotatef(Angle, 0, 0, 1); |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
366 |
{$ENDIF} |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
367 |
if Dir < 0 then |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
368 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
369 |
hglScalef(-1.0, 1.0, 1.0); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
370 |
{$ELSE} |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
371 |
glScalef(-1.0, 1.0, 1.0); |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
372 |
{$ENDIF} |
4378 | 373 |
|
374 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
375 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
376 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
377 |
hglPopMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
378 |
{$ELSE} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
379 |
glPopMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
380 |
{$ENDIF} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
381 |
|
4378 | 382 |
end; |
383 |
||
6999 | 384 |
procedure DrawTextureRotated(Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
4378 | 385 |
var VertexBuffer: array [0..3] of TVertex2f; |
386 |
begin |
|
5565 | 387 |
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
4378 | 388 |
if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then |
389 |
exit; |
|
390 |
if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then |
|
391 |
exit; |
|
392 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
393 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
394 |
hglPushMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
395 |
hglTranslatef(X, Y, 0); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
396 |
{$ELSE} |
4378 | 397 |
glPushMatrix; |
398 |
glTranslatef(X, Y, 0); |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
399 |
{$ENDIF} |
4378 | 400 |
|
401 |
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
|
402 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
403 |
hw:= - hw; |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
404 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
405 |
hglRotatef(Angle, 0, 0, -1); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
406 |
{$ELSE} |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
407 |
glRotatef(Angle, 0, 0, -1); |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
408 |
{$ENDIF} |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
409 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
410 |
else |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
411 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
412 |
hglRotatef(Angle, 0, 0, 1); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
413 |
{$ELSE} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
414 |
glRotatef(Angle, 0, 0, 1); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
415 |
{$ENDIF} |
4378 | 416 |
|
6999 | 417 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
4378 | 418 |
|
419 |
VertexBuffer[0].X:= -hw; |
|
420 |
VertexBuffer[0].Y:= -hh; |
|
421 |
VertexBuffer[1].X:= hw; |
|
422 |
VertexBuffer[1].Y:= -hh; |
|
423 |
VertexBuffer[2].X:= hw; |
|
424 |
VertexBuffer[2].Y:= hh; |
|
425 |
VertexBuffer[3].X:= -hw; |
|
426 |
VertexBuffer[3].Y:= hh; |
|
427 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
428 |
SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer)); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
429 |
SetTexCoordPointer(@Texture^.tb, Length(VertexBuffer)); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
430 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
431 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
432 |
UpdateModelviewProjection; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
433 |
{$ENDIF} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
434 |
|
4378 | 435 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
436 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
437 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
438 |
hglPopMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
439 |
{$ELSE} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
440 |
glPopMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
441 |
{$ENDIF} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
442 |
|
4378 | 443 |
end; |
444 |
||
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
445 |
procedure DrawSprite(Sprite: TSprite; X, Y, Frame: LongInt); |
4378 | 446 |
var row, col, numFramesFirstCol: LongInt; |
447 |
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
|
448 |
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
|
449 |
exit; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
450 |
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
|
451 |
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
|
452 |
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
|
453 |
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
|
454 |
end; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
455 |
|
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
456 |
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
|
457 |
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
|
458 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
459 |
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
|
460 |
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
|
461 |
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
|
462 |
r.h:= SpritesData[Sprite].Height; |
6999 | 463 |
DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4378 | 464 |
end; |
465 |
||
466 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
|
467 |
var r: TSDL_Rect; |
|
468 |
begin |
|
469 |
r.x:= 0; |
|
470 |
r.y:= 0; |
|
471 |
r.w:= SpritesData[Sprite].Width; |
|
472 |
r.h:= SpritesData[Sprite].Height; |
|
473 |
||
474 |
if (X < LeftX) then |
|
475 |
r.x:= LeftX - X; |
|
476 |
if (Y < TopY) then |
|
477 |
r.y:= TopY - Y; |
|
478 |
||
479 |
if (Y + SpritesData[Sprite].Height > BottomY) then |
|
480 |
r.h:= BottomY - Y + 1; |
|
481 |
if (X + SpritesData[Sprite].Width > RightX) then |
|
482 |
r.w:= RightX - X + 1; |
|
483 |
||
10015 | 484 |
if (r.h < r.y) or (r.w < r.x) then |
9792
59cde1e53ca5
This seems to be enough to fix the bug with sprGirder rendered in stripe
unc0rr
parents:
9666
diff
changeset
|
485 |
exit; |
59cde1e53ca5
This seems to be enough to fix the bug with sprGirder rendered in stripe
unc0rr
parents:
9666
diff
changeset
|
486 |
|
4378 | 487 |
dec(r.h, r.y); |
488 |
dec(r.w, r.x); |
|
489 |
||
6999 | 490 |
DrawTextureFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture) |
4378 | 491 |
end; |
492 |
||
6999 | 493 |
procedure DrawTextureCentered(X, Top: LongInt; Source: PTexture); |
4378 | 494 |
var scale: GLfloat; |
495 |
begin |
|
496 |
if (Source^.w + 20) > cScreenWidth then |
|
497 |
scale:= cScreenWidth / (Source^.w + 20) |
|
498 |
else |
|
499 |
scale:= 1.0; |
|
500 |
DrawTexture(X - round(Source^.w * scale) div 2, Top, Source, scale) |
|
501 |
end; |
|
502 |
||
9557 | 503 |
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; color: LongWord); inline; |
504 |
begin |
|
505 |
DrawLine(X0, Y0, X1, Y1, Width, (color shr 24) and $FF, (color shr 16) and $FF, (color shr 8) and $FF, color and $FF) |
|
506 |
end; |
|
507 |
||
4378 | 508 |
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte); |
8626 | 509 |
var VertexBuffer: array [0..1] of TVertex2f; |
4378 | 510 |
begin |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
511 |
glEnable(GL_LINE_SMOOTH); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
512 |
{$IFNDEF GL2} |
4378 | 513 |
glDisable(GL_TEXTURE_2D); |
514 |
||
515 |
glPushMatrix; |
|
516 |
glTranslatef(WorldDx, WorldDy, 0); |
|
517 |
glLineWidth(Width); |
|
518 |
||
519 |
Tint(r, g, b, a); |
|
520 |
VertexBuffer[0].X:= X0; |
|
521 |
VertexBuffer[0].Y:= Y0; |
|
522 |
VertexBuffer[1].X:= X1; |
|
523 |
VertexBuffer[1].Y:= Y1; |
|
524 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
525 |
SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer)); |
4378 | 526 |
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
|
527 |
untint; |
10015 | 528 |
|
4378 | 529 |
glPopMatrix; |
8330 | 530 |
|
4378 | 531 |
glEnable(GL_TEXTURE_2D); |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
532 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
533 |
{$ELSE} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
534 |
EnableTexture(False); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
535 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
536 |
hglPushMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
537 |
hglTranslatef(WorldDx, WorldDy, 0); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
538 |
glLineWidth(Width); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
539 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
540 |
UpdateModelviewProjection; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
541 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
542 |
Tint(r, g, b, a); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
543 |
VertexBuffer[0].X:= X0; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
544 |
VertexBuffer[0].Y:= Y0; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
545 |
VertexBuffer[1].X:= X1; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
546 |
VertexBuffer[1].Y:= Y1; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
547 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
548 |
SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer)); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
549 |
glDrawArrays(GL_LINES, 0, Length(VertexBuffer)); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
550 |
Tint($FF, $FF, $FF, $FF); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
551 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
552 |
hglPopMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
553 |
EnableTexture(True); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
554 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
555 |
{$ENDIF} |
4378 | 556 |
glDisable(GL_LINE_SMOOTH); |
557 |
end; |
|
558 |
||
559 |
procedure DrawFillRect(r: TSDL_Rect); |
|
560 |
var VertexBuffer: array [0..3] of TVertex2f; |
|
561 |
begin |
|
5565 | 562 |
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
563 |
|
4378 | 564 |
if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) * cScaleFactor > cScreenWidth) then |
565 |
exit; |
|
566 |
if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) * cScaleFactor > cScreenHeight) then |
|
567 |
exit; |
|
568 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
569 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
570 |
EnableTexture(False); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
571 |
{$ELSE} |
4378 | 572 |
glDisable(GL_TEXTURE_2D); |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
573 |
{$ENDIF} |
4378 | 574 |
|
575 |
Tint($00, $00, $00, $80); |
|
576 |
||
577 |
VertexBuffer[0].X:= r.x; |
|
578 |
VertexBuffer[0].Y:= r.y; |
|
579 |
VertexBuffer[1].X:= r.x + r.w; |
|
580 |
VertexBuffer[1].Y:= r.y; |
|
581 |
VertexBuffer[2].X:= r.x + r.w; |
|
582 |
VertexBuffer[2].Y:= r.y + r.h; |
|
583 |
VertexBuffer[3].X:= r.x; |
|
584 |
VertexBuffer[3].Y:= r.y + r.h; |
|
585 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
586 |
SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer)); |
4378 | 587 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
588 |
||
9666
8dcb25112d96
- Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents:
9557
diff
changeset
|
589 |
untint; |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
590 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
591 |
EnableTexture(True); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
592 |
{$ELSE} |
4378 | 593 |
glEnable(GL_TEXTURE_2D) |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
594 |
{$ENDIF} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
595 |
|
4378 | 596 |
end; |
597 |
||
8330 | 598 |
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
|
599 |
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
|
600 |
Tint(r, g, b, a); |
10015 | 601 |
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
|
602 |
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
|
603 |
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
|
604 |
|
8330 | 605 |
procedure DrawCircle(X, Y, Radius, Width: LongInt); |
4378 | 606 |
var |
607 |
i: LongInt; |
|
5561
dfbe55237c64
Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents:
5559
diff
changeset
|
608 |
CircleVertex: array [0..59] of TVertex2f; |
4378 | 609 |
begin |
5561
dfbe55237c64
Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents:
5559
diff
changeset
|
610 |
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
|
611 |
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
|
612 |
CircleVertex[i].Y := Y + Radius*sin(i*pi/30); |
4378 | 613 |
end; |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
614 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
615 |
{$IFNDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
616 |
|
4378 | 617 |
glDisable(GL_TEXTURE_2D); |
618 |
glEnable(GL_LINE_SMOOTH); |
|
619 |
glPushMatrix; |
|
620 |
glLineWidth(Width); |
|
621 |
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
|
622 |
glDrawArrays(GL_LINE_LOOP, 0, 60); |
4378 | 623 |
glPopMatrix; |
624 |
glEnable(GL_TEXTURE_2D); |
|
625 |
glDisable(GL_LINE_SMOOTH); |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
626 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
627 |
{$ELSE} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
628 |
EnableTexture(False); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
629 |
glEnable(GL_LINE_SMOOTH); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
630 |
hglPushMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
631 |
glLineWidth(Width); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
632 |
SetVertexPointer(@CircleVertex[0], 60); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
633 |
glDrawArrays(GL_LINE_LOOP, 0, 60); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
634 |
hglPopMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
635 |
EnableTexture(True); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
636 |
glDisable(GL_LINE_SMOOTH); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
637 |
{$ENDIF} |
4378 | 638 |
end; |
639 |
||
640 |
||
4385 | 641 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
642 |
const VertexBuffer: array [0..3] of TVertex2f = ( |
|
7069 | 643 |
(X: -16; Y: -16), |
644 |
(X: 16; Y: -16), |
|
645 |
(X: 16; Y: 16), |
|
646 |
(X: -16; Y: 16)); |
|
4385 | 647 |
var l, r, t, b: real; |
648 |
TextureBuffer: array [0..3] of TVertex2f; |
|
649 |
begin |
|
5565 | 650 |
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
4385 | 651 |
if (abs(X) > 32) and ((abs(X) - 16) * cScaleFactor > cScreenWidth) then |
652 |
exit; |
|
653 |
if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) * cScaleFactor > cScreenHeight) then |
|
654 |
exit; |
|
655 |
||
656 |
t:= Pos * 32 / HHTexture^.h; |
|
657 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
658 |
||
659 |
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
|
660 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
661 |
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
|
662 |
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
|
663 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
664 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
665 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6394
diff
changeset
|
666 |
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
|
667 |
r:= (Step + 1) * 32 / HHTexture^.w |
4385 | 668 |
end; |
669 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
670 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
671 |
hglPushMatrix(); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
672 |
hglTranslatef(X, Y, 0); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
673 |
hglRotatef(Angle, 0, 0, 1); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
674 |
{$ELSE} |
4385 | 675 |
glPushMatrix(); |
676 |
glTranslatef(X, Y, 0); |
|
677 |
glRotatef(Angle, 0, 0, 1); |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
678 |
{$ENDIF} |
4385 | 679 |
|
680 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
|
681 |
||
682 |
TextureBuffer[0].X:= l; |
|
683 |
TextureBuffer[0].Y:= t; |
|
684 |
TextureBuffer[1].X:= r; |
|
685 |
TextureBuffer[1].Y:= t; |
|
686 |
TextureBuffer[2].X:= r; |
|
687 |
TextureBuffer[2].Y:= b; |
|
688 |
TextureBuffer[3].X:= l; |
|
689 |
TextureBuffer[3].Y:= b; |
|
690 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
691 |
SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer)); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
692 |
SetTexCoordPointer(@TextureBuffer[0], Length(VertexBuffer)); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
693 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
694 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
695 |
UpdateModelviewProjection; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
696 |
{$ENDIF} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
697 |
|
4385 | 698 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
699 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
700 |
{$IFDEF GL2} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
701 |
hglPopMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
702 |
{$ELSE} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
703 |
glPopMatrix; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
704 |
{$ENDIF} |
4385 | 705 |
end; |
706 |
||
6688 | 707 |
procedure DrawScreenWidget(widget: POnScreenWidget); |
6992 | 708 |
{$IFDEF USE_TOUCH_INTERFACE} |
6688 | 709 |
var alpha: byte = $FF; |
710 |
begin |
|
711 |
with widget^ do |
|
712 |
begin |
|
713 |
if (fadeAnimStart <> 0) then |
|
714 |
begin |
|
715 |
if RealTicks > (fadeAnimStart + FADE_ANIM_TIME) then |
|
716 |
fadeAnimStart:= 0 |
|
717 |
else |
|
8330 | 718 |
if show then |
6688 | 719 |
alpha:= Byte(trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF)) |
8330 | 720 |
else |
6688 | 721 |
alpha:= Byte($FF - trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF)); |
722 |
end; |
|
723 |
||
724 |
with moveAnim do |
|
725 |
if animate then |
|
726 |
if RealTicks > (startTime + MOVE_ANIM_TIME) then |
|
727 |
begin |
|
728 |
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
|
729 |
animate:= false; |
6695
32de8965c62c
refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents:
6689
diff
changeset
|
730 |
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
|
731 |
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
|
732 |
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
|
733 |
active.y:= active.y + (target.y - source.y); |
6688 | 734 |
end |
735 |
else |
|
736 |
begin |
|
6695
32de8965c62c
refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents:
6689
diff
changeset
|
737 |
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
|
738 |
frame.y:= source.y + Round((target.y - source.y) * ((RealTicks - startTime) / MOVE_ANIM_TIME)); |
6688 | 739 |
end; |
740 |
||
741 |
if show or (fadeAnimStart <> 0) then |
|
742 |
begin |
|
743 |
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
|
744 |
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
|
745 |
untint; |
6688 | 746 |
end; |
747 |
end; |
|
6992 | 748 |
{$ELSE} |
749 |
begin |
|
750 |
widget:= widget; // avoid hint |
|
6689 | 751 |
{$ENDIF} |
6688 | 752 |
end; |
4385 | 753 |
|
10255
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
754 |
procedure openglTint(r, g, b, a: Byte); inline; |
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
755 |
{$IFDEF GL2} |
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
756 |
const |
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
757 |
scale:Real = 1.0/255.0; |
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
758 |
{$ENDIF} |
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
759 |
begin |
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
760 |
{$IFDEF GL2} |
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
761 |
glUniform4f(uMainTintLocation, r*scale, g*scale, b*scale, a*scale); |
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
762 |
{$ELSE} |
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
763 |
glColor4ub(r, g, b, a); |
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
764 |
{$ENDIF} |
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
765 |
end; |
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
766 |
|
4378 | 767 |
procedure Tint(r, g, b, a: Byte); inline; |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
768 |
var |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7069
diff
changeset
|
769 |
nc, tw: Longword; |
4378 | 770 |
begin |
9557 | 771 |
nc:= (r shl 24) or (g shl 16) or (b shl 8) or a; |
5559 | 772 |
|
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
773 |
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
|
774 |
exit; |
5559 | 775 |
|
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
776 |
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
|
777 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
778 |
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
|
779 |
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
|
780 |
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
|
781 |
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
|
782 |
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
|
783 |
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
|
784 |
end; |
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5235
diff
changeset
|
785 |
|
10255
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
786 |
openglTint(r, g, b, a); |
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
787 |
lastTint:= nc; |
4378 | 788 |
end; |
789 |
||
790 |
procedure Tint(c: Longword); inline; |
|
791 |
begin |
|
9557 | 792 |
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
|
793 |
Tint(((c shr 24) and $FF), ((c shr 16) and $FF), (c shr 8) and $FF, (c and $FF)) |
4378 | 794 |
end; |
795 |
||
9666
8dcb25112d96
- Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents:
9557
diff
changeset
|
796 |
procedure untint(); inline; |
8dcb25112d96
- Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents:
9557
diff
changeset
|
797 |
begin |
10255
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
798 |
if cWhiteColor = lastTint then exit; |
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
799 |
openglTint($FF, $FF, $FF, $FF); |
fdc342ebdc31
tweak untint a little (especially in connection with GrayScale)
sheepluva
parents:
10108
diff
changeset
|
800 |
lastTint:= cWhiteColor; |
9666
8dcb25112d96
- Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents:
9557
diff
changeset
|
801 |
end; |
8dcb25112d96
- Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents:
9557
diff
changeset
|
802 |
|
8dcb25112d96
- Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents:
9557
diff
changeset
|
803 |
procedure setTintAdd(f: boolean); inline; |
8dcb25112d96
- Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents:
9557
diff
changeset
|
804 |
begin |
8dcb25112d96
- Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents:
9557
diff
changeset
|
805 |
if f then |
8dcb25112d96
- Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents:
9557
diff
changeset
|
806 |
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
|
807 |
else |
8dcb25112d96
- Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents:
9557
diff
changeset
|
808 |
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
|
809 |
end; |
8dcb25112d96
- Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents:
9557
diff
changeset
|
810 |
|
4378 | 811 |
end. |