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