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