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