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