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