author | nemo |
Sat, 14 Nov 2009 05:26:26 +0000 | |
changeset 2620 | 796269129c47 |
parent 2619 | bc2786a00fb8 |
child 2623 | 9332f744bbdf |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 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 |
|
4 | 8 |
* |
183 | 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. |
|
4 | 13 |
* |
183 | 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 |
|
4 | 17 |
*) |
18 |
||
19 |
unit uStore; |
|
20 |
interface |
|
2599 | 21 |
{$INCLUDE "options.inc"} |
2017 | 22 |
uses sysutils, uConsts, uTeams, SDLh, |
2152 | 23 |
{$IFDEF GLES11} |
1906 | 24 |
gles11, |
25 |
{$ELSE} |
|
2428 | 26 |
GL, GLext, |
1906 | 27 |
{$ENDIF} |
28 |
uFloat; |
|
4 | 29 |
|
30 |
procedure StoreInit; |
|
31 |
procedure StoreLoad; |
|
32 |
procedure StoreRelease; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
33 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
34 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
35 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
1939 | 36 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
37 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture); |
762 | 38 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
1251 | 39 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt); |
2597 | 40 |
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, Frames: LongInt; Angle: real); |
822 | 41 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
853 | 42 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
822 | 43 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
762 | 44 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
45 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
1865
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1854
diff
changeset
|
46 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1431 | 47 |
procedure DrawFillRect(r: TSDL_Rect); |
762 | 48 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
2017 | 49 |
function RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture; |
50 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
|
51 |
//procedure rotateSurface(Surface: PSDL_Surface); |
|
52 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL |
|
53 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer); |
|
4 | 54 |
procedure RenderHealth(var Hedgehog: THedgehog); |
55 |
procedure AddProgress; |
|
510 | 56 |
procedure FinishProgress; |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
57 |
function LoadImage(const filename: string; imageFlags: Integer): PSDL_Surface; |
753 | 58 |
procedure SetupOpenGL; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
59 |
procedure SetScale(f: GLfloat); |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
60 |
|
4 | 61 |
|
1525 | 62 |
var PixelFormat: PSDL_PixelFormat = nil; |
63 |
SDLPrimSurface: PSDL_Surface = nil; |
|
1023 | 64 |
PauseTexture, |
2397
2ca4ca6b4bab
- Patch for "Syncronizing" message by Smaxx + some tweaks by me
unc0rr
parents:
2376
diff
changeset
|
65 |
SyncTexture, |
1023 | 66 |
ConfirmTexture: PTexture; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
67 |
cScaleFactor: GLfloat = 2.0; |
2428 | 68 |
SupportNPOTT: Boolean = false; |
4 | 69 |
|
70 |
implementation |
|
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
71 |
uses uMisc, uConsole, uLand, uLocale, uWorld; |
4 | 72 |
|
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
73 |
type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel); |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
74 |
|
690 | 75 |
var |
761 | 76 |
HHTexture: PTexture; |
2153 | 77 |
MaxTextureSize: Integer; |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
78 |
cGPUVendor: TGPUVendor; |
4 | 79 |
|
80 |
procedure StoreInit; |
|
81 |
begin |
|
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
82 |
cGPUVendor:= gvUnknown; |
4 | 83 |
end; |
84 |
||
351 | 85 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
47 | 86 |
var r: TSDL_Rect; |
87 |
begin |
|
88 |
r:= rect^; |
|
83 | 89 |
if Clear then SDL_FillRect(Surface, @r, 0); |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
90 |
|
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
91 |
BorderColor:= SDL_MapRGB(Surface^.format, BorderColor shr 16, BorderColor shr 8, BorderColor and $FF); |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
92 |
FillColor:= SDL_MapRGB(Surface^.format, FillColor shr 16, FillColor shr 8, FillColor and $FF); |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
93 |
|
351 | 94 |
r.y:= rect^.y + 1; |
95 |
r.h:= rect^.h - 2; |
|
47 | 96 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 97 |
r.x:= rect^.x + 1; |
98 |
r.w:= rect^.w - 2; |
|
99 |
r.y:= rect^.y; |
|
100 |
r.h:= rect^.h; |
|
47 | 101 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 102 |
r.x:= rect^.x + 2; |
103 |
r.y:= rect^.y + 1; |
|
104 |
r.w:= rect^.w - 4; |
|
105 |
r.h:= rect^.h - 2; |
|
47 | 106 |
SDL_FillRect(Surface, @r, FillColor); |
351 | 107 |
r.x:= rect^.x + 1; |
108 |
r.y:= rect^.y + 2; |
|
109 |
r.w:= rect^.w - 2; |
|
110 |
r.h:= rect^.h - 4; |
|
47 | 111 |
SDL_FillRect(Surface, @r, FillColor) |
112 |
end; |
|
113 |
||
371 | 114 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
351 | 115 |
var w, h: LongInt; |
4 | 116 |
tmpsurf: PSDL_Surface; |
117 |
clr: TSDL_Color; |
|
351 | 118 |
Result: TSDL_Rect; |
4 | 119 |
begin |
2620
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
120 |
TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
121 |
Result.x:= X; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
122 |
Result.y:= Y; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
123 |
Result.w:= w + FontBorder * 2 + 4; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
124 |
Result.h:= h + FontBorder * 2; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
125 |
DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface, true); |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
126 |
clr.r:= Color shr 16; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
127 |
clr.g:= (Color shr 8) and $FF; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
128 |
clr.b:= Color and $FF; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
129 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr.value); |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
130 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
131 |
Result.x:= X + FontBorder + 2; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
132 |
Result.y:= Y + FontBorder; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
133 |
SDLTry(tmpsurf <> nil, true); |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
134 |
SDL_UpperBlit(tmpsurf, nil, Surface, @Result); |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
135 |
SDL_FreeSurface(tmpsurf); |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
136 |
Result.x:= X; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
137 |
Result.y:= Y; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
138 |
Result.w:= w + FontBorder * 2 + 4; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
139 |
Result.h:= h + FontBorder * 2; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
140 |
WriteInRoundRect:= Result |
4 | 141 |
end; |
142 |
||
143 |
procedure StoreLoad; |
|
844 | 144 |
var s: string; |
4 | 145 |
|
1185 | 146 |
procedure WriteNames(Font: THWFont); |
147 |
var t: LongInt; |
|
148 |
i: LongInt; |
|
149 |
r, rr: TSDL_Rect; |
|
150 |
drY: LongInt; |
|
151 |
texsurf: PSDL_Surface; |
|
152 |
begin |
|
153 |
r.x:= 0; |
|
154 |
r.y:= 0; |
|
155 |
drY:= - 4; |
|
156 |
for t:= 0 to Pred(TeamsCount) do |
|
157 |
with TeamsArray[t]^ do |
|
158 |
begin |
|
159 |
NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font); |
|
690 | 160 |
|
1185 | 161 |
r.w:= cTeamHealthWidth + 5; |
162 |
r.h:= NameTagTex^.h; |
|
690 | 163 |
|
1185 | 164 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
165 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
166 |
TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
690 | 167 |
|
1185 | 168 |
DrawRoundRect(@r, cWhiteColor, cColorNearBlack, texsurf, true); |
169 |
rr:= r; |
|
170 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
|
171 |
DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false); |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
172 |
HealthTex:= Surface2Tex(texsurf, false); |
1185 | 173 |
SDL_FreeSurface(texsurf); |
690 | 174 |
|
1185 | 175 |
dec(drY, r.h + 2); |
176 |
DrawHealthY:= drY; |
|
177 |
for i:= 0 to 7 do |
|
178 |
with Hedgehogs[i] do |
|
179 |
if Gear <> nil then |
|
1242 | 180 |
begin |
1185 | 181 |
NameTagTex:= RenderStringTex(Name, Clan^.Color, fnt16); |
1294
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
182 |
if Hat <> 'NoHat' then |
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
183 |
begin |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
184 |
texsurf:= LoadImage(Pathz[ptHats] + '/' + Hat, ifNone); |
1698 | 185 |
if texsurf <> nil then |
186 |
begin |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
187 |
HatTex:= Surface2Tex(texsurf, true); |
1698 | 188 |
SDL_FreeSurface(texsurf) |
189 |
end |
|
1294
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
190 |
end |
1242 | 191 |
end; |
1185 | 192 |
end; |
193 |
end; |
|
4 | 194 |
|
1185 | 195 |
procedure MakeCrossHairs; |
196 |
var t: LongInt; |
|
197 |
tmpsurf, texsurf: PSDL_Surface; |
|
198 |
Color, i: Longword; |
|
199 |
begin |
|
200 |
s:= Pathz[ptGraphics] + '/' + cCHFileName; |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
201 |
tmpsurf:= LoadImage(s, ifAlpha or ifCritical); |
4 | 202 |
|
1185 | 203 |
for t:= 0 to Pred(TeamsCount) do |
204 |
with TeamsArray[t]^ do |
|
205 |
begin |
|
206 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask); |
|
207 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
208 |
|
1185 | 209 |
Color:= Clan^.Color; |
210 |
Color:= SDL_MapRGB(texsurf^.format, Color shr 16, Color shr 8, Color and $FF); |
|
211 |
SDL_FillRect(texsurf, nil, Color); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
212 |
|
1185 | 213 |
SDL_UpperBlit(tmpsurf, nil, texsurf, nil); |
777 | 214 |
|
1185 | 215 |
TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Ooops', true); |
777 | 216 |
|
1185 | 217 |
if SDL_MustLock(texsurf) then |
218 |
SDLTry(SDL_LockSurface(texsurf) >= 0, true); |
|
777 | 219 |
|
1185 | 220 |
// make black pixel be alpha-transparent |
221 |
for i:= 0 to texsurf^.w * texsurf^.h - 1 do |
|
2592 | 222 |
if PLongwordArray(texsurf^.pixels)^[i] = AMask then PLongwordArray(texsurf^.pixels)^[i]:= 0; |
777 | 223 |
|
1185 | 224 |
if SDL_MustLock(texsurf) then |
225 |
SDL_UnlockSurface(texsurf); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
226 |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
227 |
CrosshairTex:= Surface2Tex(texsurf, false); |
1185 | 228 |
SDL_FreeSurface(texsurf) |
229 |
end; |
|
351 | 230 |
|
1185 | 231 |
SDL_FreeSurface(tmpsurf) |
232 |
end; |
|
4 | 233 |
|
1185 | 234 |
procedure InitHealth; |
235 |
var i, t: LongInt; |
|
236 |
begin |
|
237 |
for t:= 0 to Pred(TeamsCount) do |
|
238 |
if TeamsArray[t] <> nil then |
|
239 |
with TeamsArray[t]^ do |
|
240 |
begin |
|
241 |
for i:= 0 to cMaxHHIndex do |
|
242 |
if Hedgehogs[i].Gear <> nil then |
|
243 |
RenderHealth(Hedgehogs[i]); |
|
244 |
end |
|
245 |
end; |
|
4 | 246 |
|
1185 | 247 |
procedure LoadGraves; |
248 |
var t: LongInt; |
|
249 |
texsurf: PSDL_Surface; |
|
250 |
begin |
|
251 |
for t:= 0 to Pred(TeamsCount) do |
|
252 |
if TeamsArray[t] <> nil then |
|
253 |
with TeamsArray[t]^ do |
|
254 |
begin |
|
255 |
if GraveName = '' then GraveName:= 'Simple'; |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
256 |
texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifCritical or ifTransparent); |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
257 |
GraveTex:= Surface2Tex(texsurf, false); |
1185 | 258 |
SDL_FreeSurface(texsurf) |
259 |
end |
|
260 |
end; |
|
4 | 261 |
|
844 | 262 |
var ii: TSprite; |
263 |
fi: THWFont; |
|
264 |
ai: TAmmoType; |
|
265 |
tmpsurf: PSDL_Surface; |
|
266 |
i: LongInt; |
|
2615 | 267 |
{$IFDEF IPHONEOS} |
2593 | 268 |
tmpP: PLongWordArray; |
269 |
tmpA, tmpR, tmpG, tmpB: LongWord; |
|
270 |
{$ENDIF} |
|
4 | 271 |
begin |
2222 | 272 |
|
4 | 273 |
for fi:= Low(THWFont) to High(THWFont) do |
1185 | 274 |
with Fontz[fi] do |
275 |
begin |
|
276 |
s:= Pathz[ptFonts] + '/' + Name; |
|
277 |
WriteToConsole(msgLoading + s + '... '); |
|
278 |
Handle:= TTF_OpenFont(Str2PChar(s), Height); |
|
279 |
SDLTry(Handle <> nil, true); |
|
280 |
TTF_SetFontStyle(Handle, style); |
|
281 |
WriteLnToConsole(msgOK) |
|
282 |
end; |
|
53 | 283 |
|
4 | 284 |
WriteNames(fnt16); |
70 | 285 |
MakeCrossHairs; |
4 | 286 |
LoadGraves; |
287 |
||
288 |
AddProgress; |
|
289 |
for ii:= Low(TSprite) to High(TSprite) do |
|
1185 | 290 |
with SpritesData[ii] do |
2145 | 291 |
// FIXME - add a sprite attribute |
2426 | 292 |
if (not cReducedQuality) or (not (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR, sprFlake])) then // FIXME: hack |
2229
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
293 |
begin |
1185 | 294 |
if AltPath = ptNone then |
2426 | 295 |
if ii in [sprHorizontL, sprHorizontR, sprSkyL, sprSkyR] then // FIXME: hack |
296 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifLowRes) |
|
297 |
else |
|
298 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical or ifLowRes) |
|
1185 | 299 |
else begin |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
300 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
1185 | 301 |
if tmpsurf = nil then |
2610 | 302 |
tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent); |
1185 | 303 |
end; |
2426 | 304 |
|
305 |
if tmpsurf <> nil then |
|
306 |
begin |
|
2615 | 307 |
{$IFDEF IPHONEOS} |
308 |
{* http://bugzilla.libsdl.org/show_bug.cgi?id=868 but patched library doesn't work on ipod, so implementing workaround here *} |
|
309 |
if (ifAlpha or ifTransparent) > 0 then |
|
2610 | 310 |
begin |
2615 | 311 |
tmpP := tmpsurf^.pixels; |
312 |
for i:= 0 to (tmpsurf^.pitch shr 2) * tmpsurf^.h - 1 do |
|
313 |
begin |
|
2610 | 314 |
{$IFDEF ENDIAN_LITTLE} |
2615 | 315 |
tmpA:= tmpP^[i] shr 24 and $FF; |
316 |
tmpR:= tmpP^[i] shr 16 and $FF; |
|
317 |
tmpG:= tmpP^[i] shr 8 and $FF; |
|
318 |
tmpB:= tmpP^[i] and $FF; |
|
2610 | 319 |
{$ELSE} |
2615 | 320 |
tmpA:= tmpP^[i] and $FF; |
321 |
tmpR:= tmpP^[i] shr 8 and $FF; |
|
322 |
tmpG:= tmpP^[i] shr 16 and $FF; |
|
323 |
tmpB:= tmpP^[i] shr 24 and $FF; |
|
2610 | 324 |
{$ENDIF} |
2615 | 325 |
if tmpA <> 0 then |
326 |
begin |
|
327 |
tmpR:= round(tmpR * 255 / tmpA); |
|
328 |
tmpG:= round(tmpG * 255 / tmpA); |
|
329 |
tmpB:= round(tmpB * 255 / tmpA); |
|
330 |
end; |
|
2593 | 331 |
|
2615 | 332 |
if tmpR > 255 then tmpR:= 255; |
333 |
if tmpG > 255 then tmpG:= 255; |
|
334 |
if tmpB > 255 then tmpB:= 255; |
|
2593 | 335 |
|
2610 | 336 |
{$IFDEF ENDIAN_LITTLE} |
2615 | 337 |
tmpP^[i]:= (tmpA shl 24) or (tmpR shl 16) or (tmpG shl 8) or tmpB; |
2610 | 338 |
{$ELSE} |
2615 | 339 |
tmpP^[i]:= (tmpA) or (tmpR shl 8) or (tmpG shl 16) or (tmpB shl 24); |
2610 | 340 |
{$ENDIF} |
2615 | 341 |
end; |
2610 | 342 |
end; |
2593 | 343 |
{$ENDIF} |
344 |
||
2610 | 345 |
if imageWidth = 0 then imageWidth:= tmpsurf^.w; |
346 |
if imageHeight = 0 then imageHeight:= tmpsurf^.h; |
|
2426 | 347 |
if Width = 0 then Width:= tmpsurf^.w; |
348 |
if Height = 0 then Height:= tmpsurf^.h; |
|
2452 | 349 |
if (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]) then |
2426 | 350 |
Texture:= Surface2Tex(tmpsurf, true) |
351 |
else |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
352 |
begin |
2426 | 353 |
Texture:= Surface2Tex(tmpsurf, false); |
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
354 |
if (ii = sprWater) and not cReducedQuality then // HACK: We should include some sprite attribute to define the texture wrap directions |
2610 | 355 |
begin |
2612 | 356 |
(* REMOVE ME WHEN BUG ABOVE IS FIXED |
2610 | 357 |
tmpP := tmpsurf^.pixels; |
358 |
for i:= 0 to (tmpsurf^.pitch shr 2) * tmpsurf^.h - 1 do |
|
359 |
begin |
|
360 |
tmpA:= tmpP^[i] shr 24 and $FF; |
|
361 |
tmpR:= tmpP^[i] shr 16 and $FF; |
|
362 |
tmpG:= tmpP^[i] shr 8 and $FF; |
|
363 |
tmpB:= tmpP^[i] and $FF; |
|
364 |
||
365 |
writeln(stdout, inttostr(tmpA) + ' | ' + inttostr(tmpR) + ' | ' + inttostr(tmpG)+ ' | ' + inttostr(tmpB)); |
|
366 |
end; |
|
367 |
*) |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
368 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
2610 | 369 |
end; |
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
370 |
end; |
2426 | 371 |
if saveSurf then Surface:= tmpsurf else SDL_FreeSurface(tmpsurf) |
372 |
end |
|
373 |
else |
|
374 |
Surface:= nil |
|
2229
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
375 |
end; |
80 | 376 |
|
4 | 377 |
AddProgress; |
567 | 378 |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
379 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent); |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
380 |
HHTexture:= Surface2Tex(tmpsurf, false); |
761 | 381 |
SDL_FreeSurface(tmpsurf); |
4 | 382 |
|
383 |
InitHealth; |
|
384 |
||
762 | 385 |
PauseTexture:= RenderStringTex(trmsg[sidPaused], $FFFF00, fntBig); |
1023 | 386 |
ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], $FFFF00, fntBig); |
2397
2ca4ca6b4bab
- Patch for "Syncronizing" message by Smaxx + some tweaks by me
unc0rr
parents:
2376
diff
changeset
|
387 |
SyncTexture:= RenderStringTex(trmsg[sidSync], $FFFF00, fntBig); |
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
388 |
|
2601 | 389 |
AddProgress; |
390 |
||
843 | 391 |
for ai:= Low(TAmmoType) to High(TAmmoType) do |
392 |
with Ammoz[ai] do |
|
393 |
begin |
|
2619 | 394 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(trAmmo[NameId]), cWhiteColor); |
395 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
396 |
NameTex:= Surface2Tex(tmpsurf, false); |
843 | 397 |
SDL_FreeSurface(tmpsurf) |
398 |
end; |
|
2376 | 399 |
|
844 | 400 |
for i:= Low(CountTexz) to High(CountTexz) do |
401 |
begin |
|
2619 | 402 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColor); |
403 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
404 |
CountTexz[i]:= Surface2Tex(tmpsurf, false); |
844 | 405 |
SDL_FreeSurface(tmpsurf) |
406 |
end; |
|
407 |
||
4 | 408 |
{$IFDEF DUMP} |
2601 | 409 |
//not working anymore, where are LandSurface and StoreSurface defined? |
410 |
//SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
411 |
//SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
4 | 412 |
{$ENDIF} |
2222 | 413 |
AddProgress; |
4 | 414 |
end; |
415 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
416 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
4 | 417 |
var rr: TSDL_Rect; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
418 |
_l, _r, _t, _b: real; |
1916 | 419 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
4 | 420 |
begin |
2428 | 421 |
if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit; |
4 | 422 |
rr.x:= X; |
423 |
rr.y:= Y; |
|
351 | 424 |
rr.w:= r^.w; |
425 |
rr.h:= r^.h; |
|
755 | 426 |
|
1896 | 427 |
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx; |
428 |
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx; |
|
429 |
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry; |
|
430 |
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry; |
|
755 | 431 |
|
432 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
433 |
||
1916 | 434 |
VertexBuffer[0].X:= X; |
435 |
VertexBuffer[0].Y:= Y; |
|
436 |
VertexBuffer[1].X:= rr.w + X; |
|
437 |
VertexBuffer[1].Y:= Y; |
|
438 |
VertexBuffer[2].X:= rr.w + X; |
|
439 |
VertexBuffer[2].Y:= rr.h + Y; |
|
440 |
VertexBuffer[3].X:= X; |
|
441 |
VertexBuffer[3].Y:= rr.h + Y; |
|
755 | 442 |
|
1916 | 443 |
TextureBuffer[0].X:= _l; |
444 |
TextureBuffer[0].Y:= _t; |
|
445 |
TextureBuffer[1].X:= _r; |
|
446 |
TextureBuffer[1].Y:= _t; |
|
447 |
TextureBuffer[2].X:= _r; |
|
448 |
TextureBuffer[2].Y:= _b; |
|
449 |
TextureBuffer[3].X:= _l; |
|
450 |
TextureBuffer[3].Y:= _b; |
|
755 | 451 |
|
1916 | 452 |
glEnableClientState(GL_VERTEX_ARRAY); |
453 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
755 | 454 |
|
1916 | 455 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
456 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
457 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
458 |
||
459 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
460 |
glDisableClientState(GL_VERTEX_ARRAY) |
|
762 | 461 |
end; |
462 |
||
463 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
|
464 |
begin |
|
1904 | 465 |
glPushMatrix; |
466 |
glTranslatef(X, Y, 0); |
|
467 |
||
762 | 468 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
469 |
||
1904 | 470 |
glEnableClientState(GL_VERTEX_ARRAY); |
471 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
762 | 472 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
473 |
glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
474 |
glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
475 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); |
1904 | 476 |
|
477 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
478 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
479 |
||
480 |
glPopMatrix |
|
4 | 481 |
end; |
482 |
||
1251 | 483 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt); |
1242 | 484 |
var ft, fb: GLfloat; |
485 |
hw: LongInt; |
|
1916 | 486 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
1242 | 487 |
begin |
488 |
glPushMatrix; |
|
489 |
glTranslatef(X, Y, 0); |
|
2598 | 490 |
glScalef(Scale, Scale, 1.0); |
2597 | 491 |
|
492 |
if Dir < 0 then |
|
493 |
hw:= - 16 |
|
494 |
else |
|
495 |
hw:= 16; |
|
496 |
||
497 |
ft:= Frame / Frames * Texture^.ry; |
|
498 |
fb:= (Frame + 1) / Frames * Texture^.ry; |
|
499 |
||
500 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
501 |
||
502 |
VertexBuffer[0].X:= -hw; |
|
503 |
VertexBuffer[0].Y:= -16; |
|
504 |
VertexBuffer[1].X:= hw; |
|
505 |
VertexBuffer[1].Y:= -16; |
|
506 |
VertexBuffer[2].X:= hw; |
|
507 |
VertexBuffer[2].Y:= 16; |
|
508 |
VertexBuffer[3].X:= -hw; |
|
509 |
VertexBuffer[3].Y:= 16; |
|
510 |
||
511 |
TextureBuffer[0].X:= 0; |
|
512 |
TextureBuffer[0].Y:= ft; |
|
513 |
TextureBuffer[1].X:= Texture^.rx; |
|
514 |
TextureBuffer[1].Y:= ft; |
|
515 |
TextureBuffer[2].X:= Texture^.rx; |
|
516 |
TextureBuffer[2].Y:= fb; |
|
517 |
TextureBuffer[3].X:= 0; |
|
518 |
TextureBuffer[3].Y:= fb; |
|
519 |
||
520 |
glEnableClientState(GL_VERTEX_ARRAY); |
|
521 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
522 |
||
523 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
524 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
525 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
526 |
||
527 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
528 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
529 |
||
530 |
||
531 |
glPopMatrix |
|
532 |
end; |
|
533 |
||
534 |
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, Frames: LongInt; Angle: real); |
|
535 |
var ft, fb: GLfloat; |
|
536 |
hw: LongInt; |
|
537 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
|
538 |
begin |
|
539 |
glPushMatrix; |
|
540 |
glTranslatef(X, Y, 0); |
|
541 |
||
542 |
if Dir < 0 then |
|
543 |
glRotatef(Angle, 0, 0, -1) |
|
544 |
else |
|
545 |
glRotatef(Angle, 0, 0, 1); |
|
546 |
||
547 |
glTranslatef(Dir*OffsetX, OffsetY, 0); |
|
548 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
|
1242 | 549 |
|
550 |
if Dir < 0 then |
|
551 |
hw:= - 16 |
|
552 |
else |
|
553 |
hw:= 16; |
|
554 |
||
1896 | 555 |
ft:= Frame / Frames * Texture^.ry; |
556 |
fb:= (Frame + 1) / Frames * Texture^.ry; |
|
1242 | 557 |
|
558 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
559 |
||
1916 | 560 |
VertexBuffer[0].X:= -hw; |
561 |
VertexBuffer[0].Y:= -16; |
|
562 |
VertexBuffer[1].X:= hw; |
|
563 |
VertexBuffer[1].Y:= -16; |
|
564 |
VertexBuffer[2].X:= hw; |
|
565 |
VertexBuffer[2].Y:= 16; |
|
566 |
VertexBuffer[3].X:= -hw; |
|
567 |
VertexBuffer[3].Y:= 16; |
|
1242 | 568 |
|
1916 | 569 |
TextureBuffer[0].X:= 0; |
570 |
TextureBuffer[0].Y:= ft; |
|
571 |
TextureBuffer[1].X:= Texture^.rx; |
|
572 |
TextureBuffer[1].Y:= ft; |
|
573 |
TextureBuffer[2].X:= Texture^.rx; |
|
574 |
TextureBuffer[2].Y:= fb; |
|
575 |
TextureBuffer[3].X:= 0; |
|
576 |
TextureBuffer[3].Y:= fb; |
|
1242 | 577 |
|
1916 | 578 |
glEnableClientState(GL_VERTEX_ARRAY); |
579 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
1242 | 580 |
|
1916 | 581 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
582 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
583 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
584 |
||
585 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
586 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
587 |
||
1242 | 588 |
|
589 |
glPopMatrix |
|
590 |
end; |
|
591 |
||
822 | 592 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
775 | 593 |
begin |
777 | 594 |
DrawRotatedTex(SpritesData[Sprite].Texture, |
822 | 595 |
SpritesData[Sprite].Width, |
596 |
SpritesData[Sprite].Height, |
|
597 |
X, Y, Dir, Angle) |
|
777 | 598 |
end; |
599 |
||
853 | 600 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
806 | 601 |
begin |
602 |
glPushMatrix; |
|
809 | 603 |
glTranslatef(X, Y, 0); |
806 | 604 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
605 |
if Dir < 0 then |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
606 |
glRotatef(Angle, 0, 0, -1) |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
607 |
else |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
608 |
glRotatef(Angle, 0, 0, 1); |
853 | 609 |
if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
610 |
||
611 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
806 | 612 |
|
613 |
glPopMatrix |
|
614 |
end; |
|
615 |
||
822 | 616 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
1916 | 617 |
var VertexBuffer: array [0..3] of TVertex2f; |
777 | 618 |
begin |
775 | 619 |
glPushMatrix; |
620 |
glTranslatef(X, Y, 0); |
|
822 | 621 |
|
622 |
if Dir < 0 then |
|
623 |
begin |
|
624 |
hw:= - hw; |
|
625 |
glRotatef(Angle, 0, 0, -1); |
|
626 |
end else |
|
627 |
glRotatef(Angle, 0, 0, 1); |
|
628 |
||
775 | 629 |
|
777 | 630 |
glBindTexture(GL_TEXTURE_2D, Tex^.id); |
775 | 631 |
|
1916 | 632 |
VertexBuffer[0].X:= -hw; |
633 |
VertexBuffer[0].Y:= -hh; |
|
634 |
VertexBuffer[1].X:= hw; |
|
635 |
VertexBuffer[1].Y:= -hh; |
|
636 |
VertexBuffer[2].X:= hw; |
|
637 |
VertexBuffer[2].Y:= hh; |
|
638 |
VertexBuffer[3].X:= -hw; |
|
639 |
VertexBuffer[3].Y:= hh; |
|
775 | 640 |
|
1916 | 641 |
glEnableClientState(GL_VERTEX_ARRAY); |
642 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
775 | 643 |
|
1916 | 644 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
645 |
glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb); |
|
646 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
775 | 647 |
|
1916 | 648 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
649 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
775 | 650 |
|
651 |
glPopMatrix |
|
652 |
end; |
|
653 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
654 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
4 | 655 |
begin |
656 |
r.y:= r.y + Height * Position; |
|
657 |
r.h:= Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
658 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 659 |
end; |
660 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
661 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
2229
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
662 |
var row, col, numFramesFirstCol: LongInt; |
4 | 663 |
begin |
2229
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
664 |
numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height; |
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
665 |
row:= Frame mod numFramesFirstCol; |
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
666 |
col:= Frame div numFramesFirstCol; |
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
667 |
DrawSprite2 (Sprite, X, Y, col, row); |
4 | 668 |
end; |
669 |
||
1939 | 670 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
671 |
var r: TSDL_Rect; |
|
672 |
begin |
|
673 |
r.x:= 0; |
|
674 |
r.y:= 0; |
|
675 |
r.w:= SpritesData[Sprite].Width; |
|
676 |
r.h:= SpritesData[Sprite].Height; |
|
677 |
||
678 |
if (X < LeftX) then |
|
679 |
r.x:= LeftX - X; |
|
680 |
if (Y < TopY) then |
|
681 |
r.y:= TopY - Y; |
|
682 |
||
683 |
if (Y + SpritesData[Sprite].Height > BottomY) then |
|
684 |
r.h:= BottomY - Y + 1; |
|
685 |
if (X + SpritesData[Sprite].Width > RightX) then |
|
686 |
r.w:= RightX - X + 1; |
|
687 |
||
688 |
dec(r.h, r.y); |
|
689 |
dec(r.w, r.x); |
|
2230
d6963f72d21a
once again, trying to restore windows compatibility from nemo's experiments
koda
parents:
2229
diff
changeset
|
690 |
|
1939 | 691 |
DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture) |
692 |
end; |
|
693 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
694 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
43 | 695 |
var r: TSDL_Rect; |
696 |
begin |
|
697 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
698 |
r.w:= SpritesData[Sprite].Width; |
|
699 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
700 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
701 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
43 | 702 |
end; |
703 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
704 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture); |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
705 |
var r: TSDL_Rect; |
198 | 706 |
begin |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
707 |
r.x:= 0; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
708 |
r.w:= Source^.w; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
709 |
r.y:= Frame * Height; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
710 |
r.h:= Height; |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
711 |
DrawFromRect(X, Y, @r, Source) |
198 | 712 |
end; |
713 |
||
762 | 714 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
95 | 715 |
begin |
2567 | 716 |
DrawTexture(X - Source^.w shr 1, Top, Source) |
4 | 717 |
end; |
718 |
||
1865
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1854
diff
changeset
|
719 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1916 | 720 |
const VertexBuffer: array [0..3] of TVertex2f = ( |
721 |
(x: -16; y: -16), |
|
722 |
(x: 16; y: -16), |
|
723 |
(x: 16; y: 16), |
|
724 |
(x: -16; y: 16)); |
|
761 | 725 |
var l, r, t, b: real; |
1916 | 726 |
TextureBuffer: array [0..3] of TVertex2f; |
4 | 727 |
begin |
761 | 728 |
|
729 |
t:= Pos * 32 / HHTexture^.h; |
|
730 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
731 |
||
732 |
if Dir = -1 then |
|
733 |
begin |
|
734 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
735 |
r:= Step * 32 / HHTexture^.w |
|
736 |
end else |
|
737 |
begin |
|
738 |
l:= Step * 32 / HHTexture^.w; |
|
739 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
740 |
end; |
|
741 |
||
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
742 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
743 |
glPushMatrix(); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
744 |
glTranslatef(X, Y, 0); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
745 |
glRotatef(Angle, 0, 0, 1); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
746 |
|
761 | 747 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
748 |
||
1916 | 749 |
TextureBuffer[0].X:= l; |
750 |
TextureBuffer[0].Y:= t; |
|
751 |
TextureBuffer[1].X:= r; |
|
752 |
TextureBuffer[1].Y:= t; |
|
753 |
TextureBuffer[2].X:= r; |
|
754 |
TextureBuffer[2].Y:= b; |
|
755 |
TextureBuffer[3].X:= l; |
|
756 |
TextureBuffer[3].Y:= b; |
|
761 | 757 |
|
1916 | 758 |
glEnableClientState(GL_VERTEX_ARRAY); |
759 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
761 | 760 |
|
1916 | 761 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
762 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
763 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
761 | 764 |
|
1916 | 765 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
766 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
761 | 767 |
|
1854 | 768 |
|
769 |
glColor4f(1,1,1,1); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
770 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
771 |
glPopMatrix |
4 | 772 |
end; |
773 |
||
1431 | 774 |
procedure DrawFillRect(r: TSDL_Rect); |
1916 | 775 |
var VertexBuffer: array [0..3] of TVertex2f; |
1431 | 776 |
begin |
777 |
glDisable(GL_TEXTURE_2D); |
|
778 |
||
779 |
glColor4ub(0, 0, 0, 127); |
|
780 |
||
1916 | 781 |
VertexBuffer[0].X:= r.x; |
782 |
VertexBuffer[0].Y:= r.y; |
|
783 |
VertexBuffer[1].X:= r.x + r.w; |
|
784 |
VertexBuffer[1].Y:= r.y; |
|
785 |
VertexBuffer[2].X:= r.x + r.w; |
|
786 |
VertexBuffer[2].Y:= r.y + r.h; |
|
787 |
VertexBuffer[3].X:= r.x; |
|
788 |
VertexBuffer[3].Y:= r.y + r.h; |
|
1431 | 789 |
|
1916 | 790 |
glEnableClientState(GL_VERTEX_ARRAY); |
791 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
792 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
793 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
1431 | 794 |
|
795 |
glColor4f(1, 1, 1, 1); |
|
796 |
glEnable(GL_TEXTURE_2D) |
|
797 |
end; |
|
798 |
||
4 | 799 |
procedure StoreRelease; |
800 |
var ii: TSprite; |
|
801 |
begin |
|
802 |
for ii:= Low(TSprite) to High(TSprite) do |
|
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
803 |
begin |
759 | 804 |
FreeTexture(SpritesData[ii].Texture); |
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
805 |
if SpritesData[ii].Surface <> nil then SDL_FreeSurface(SpritesData[ii].Surface) |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
806 |
end; |
761 | 807 |
|
1806 | 808 |
FreeTexture(HHTexture) |
4 | 809 |
end; |
810 |
||
762 | 811 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
432 | 812 |
var w, h: LongInt; |
351 | 813 |
Result: PSDL_Surface; |
95 | 814 |
begin |
1989 | 815 |
if length(s) = 0 then s:= ' '; |
355 | 816 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
785 | 817 |
|
762 | 818 |
Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
819 |
32, RMask, GMask, BMask, AMask); |
|
785 | 820 |
|
107 | 821 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
785 | 822 |
|
95 | 823 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
785 | 824 |
|
762 | 825 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
785 | 826 |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
827 |
RenderStringTex:= Surface2Tex(Result, false); |
785 | 828 |
|
762 | 829 |
SDL_FreeSurface(Result) |
95 | 830 |
end; |
831 |
||
2017 | 832 |
function RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture; |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
833 |
var textWidth, textHeight, x, y, w, h, i, j, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt; |
2017 | 834 |
Result, tmpsurf, rotatedEdge: PSDL_Surface; |
835 |
rect: TSDL_Rect; |
|
836 |
chars: TSysCharSet = [#9,' ','.',';',':','?','!',',']; |
|
837 |
substr: shortstring; |
|
838 |
edge, corner, tail: TSPrite; |
|
839 |
begin |
|
840 |
||
841 |
case SpeechType of |
|
2376 | 842 |
1: begin; |
843 |
edge:= sprSpeechEdge; |
|
2017 | 844 |
corner:= sprSpeechCorner; |
845 |
tail:= sprSpeechTail; |
|
846 |
end; |
|
2376 | 847 |
2: begin; |
2017 | 848 |
edge:= sprThoughtEdge; |
2376 | 849 |
corner:= sprThoughtCorner; |
2017 | 850 |
tail:= sprThoughtTail; |
851 |
end; |
|
2376 | 852 |
3: begin; |
2017 | 853 |
edge:= sprShoutEdge; |
854 |
corner:= sprShoutCorner; |
|
855 |
tail:= sprShoutTail; |
|
856 |
end; |
|
857 |
end; |
|
858 |
edgeHeight:= SpritesData[edge].Height; |
|
859 |
edgeWidth:= SpritesData[edge].Width; |
|
860 |
cornerWidth:= SpritesData[corner].Width; |
|
861 |
cornerHeight:= SpritesData[corner].Height; |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
862 |
// This one screws up WrapText |
2022 | 863 |
//s:= 'This is the song that never ends. ''cause it goes on and on my friends. Some people, started singing it not knowing what it was. And they''ll just go on singing it forever just because... This is the song that never ends...'; |
2154
3d2917be12c3
Change default output to stderr since /tmp doesn't exist under windows and is useless under iphoneos, add a couple of extra parameters
nemo
parents:
2153
diff
changeset
|
864 |
// This one does not |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
865 |
//s:= 'This is the song that never ends. cause it goes on and on my friends. Some people, started singing it not knowing what it was. And they will go on singing it forever just because... This is the song that never ends... '; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
866 |
|
2022 | 867 |
numLines:= 0; |
2017 | 868 |
|
869 |
if length(s) = 0 then s:= '...'; |
|
870 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
|
2332
351abbbb12f3
Lower bound on speech text width for proper rendering
nemo
parents:
2292
diff
changeset
|
871 |
if w<8 then w:= 8; |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
872 |
j:= 0; |
2017 | 873 |
if (length(s) > 20) then |
874 |
begin |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
875 |
w:= 0; |
2017 | 876 |
i:= round(Sqrt(length(s)) * 2); |
877 |
s:= WrapText(s, #1, chars, i); |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
878 |
pos:= 1; prevpos:= 0; line:= 0; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
879 |
// Find the longest line for the purposes of centring the text. Font dependant. |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
880 |
while pos <= length(s) do |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
881 |
begin |
2017 | 882 |
if (s[pos] = #1) or (pos = length(s)) then |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
883 |
begin |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
884 |
inc(numlines); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
885 |
if s[pos] <> #1 then inc(pos); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
886 |
while s[prevpos+1] = ' ' do inc(prevpos); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
887 |
substr:= copy(s, prevpos+1, pos-prevpos-1); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
888 |
i:= 0; j:= 0; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
889 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(substr), i, j); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
890 |
if i > w then w:= i; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
891 |
prevpos:= pos; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
892 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
893 |
inc(pos); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
894 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
895 |
end |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
896 |
else numLines := 1; |
2017 | 897 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
898 |
textWidth:=((w-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth; |
2022 | 899 |
textHeight:=(((numlines * h + 2)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth; |
2019 | 900 |
|
2022 | 901 |
textHeight:=max(textHeight,edgeWidth); |
2017 | 902 |
//textWidth:=max(textWidth,SpritesData[tail].Width); |
903 |
rect.x:= 0; |
|
904 |
rect.y:= 0; |
|
2022 | 905 |
rect.w:= textWidth + (cornerWidth * 2); |
906 |
rect.h:= textHeight + cornerHeight*2 - edgeHeight + SpritesData[tail].Height; |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
907 |
//s:= inttostr(w) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h); |
2017 | 908 |
|
909 |
Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask); |
|
910 |
||
911 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
|
912 |
||
913 |
//////////////////////////////// CORNERS /////////////////////////////// |
|
914 |
copyToXY(SpritesData[corner].Surface, Result, 0, 0); /////////////////// NW |
|
915 |
||
916 |
flipSurface(SpritesData[corner].Surface, true); // store all 4 versions in memory to avoid repeated flips? |
|
917 |
x:= 0; |
|
918 |
y:= textHeight + cornerHeight -1; |
|
919 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// SW |
|
920 |
||
921 |
flipSurface(SpritesData[corner].Surface, false); |
|
922 |
x:= rect.w-cornerWidth-1; |
|
923 |
y:= textHeight + cornerHeight -1; |
|
924 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// SE |
|
925 |
||
926 |
flipSurface(SpritesData[corner].Surface, true); |
|
927 |
x:= rect.w-cornerWidth-1; |
|
928 |
y:= 0; |
|
929 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// NE |
|
930 |
flipSurface(SpritesData[corner].Surface, false); // restore original position |
|
931 |
//////////////////////////////// END CORNERS /////////////////////////////// |
|
932 |
||
933 |
//////////////////////////////// EDGES ////////////////////////////////////// |
|
934 |
x:= cornerWidth; |
|
935 |
y:= 0; |
|
936 |
while x < rect.w-cornerWidth-1 do |
|
937 |
begin |
|
938 |
copyToXY(SpritesData[edge].Surface, Result, x, y); ///////////////// top edge |
|
939 |
inc(x,edgeWidth); |
|
940 |
end; |
|
941 |
flipSurface(SpritesData[edge].Surface, true); |
|
942 |
x:= cornerWidth; |
|
943 |
y:= textHeight + cornerHeight*2 - edgeHeight-1; |
|
944 |
while x < rect.w-cornerWidth-1 do |
|
945 |
begin |
|
946 |
copyToXY(SpritesData[edge].Surface, Result, x, y); ///////////////// bottom edge |
|
947 |
inc(x,edgeWidth); |
|
948 |
end; |
|
949 |
flipSurface(SpritesData[edge].Surface, true); // restore original position |
|
950 |
||
951 |
rotatedEdge:= SDL_CreateRGBSurface(SDL_SWSURFACE, edgeHeight, edgeWidth, 32, RMask, GMask, BMask, AMask); |
|
952 |
x:= rect.w - edgeHeight - 1; |
|
953 |
y:= cornerHeight; |
|
954 |
//// initially was going to rotate in place, but the SDL spec claims width/height are read only |
|
955 |
copyRotatedSurface(SpritesData[edge].Surface,rotatedEdge); |
|
956 |
while y < textHeight + cornerHeight do |
|
957 |
begin |
|
958 |
copyToXY(rotatedEdge, Result, x, y); |
|
959 |
inc(y,edgeWidth); |
|
960 |
end; |
|
961 |
flipSurface(rotatedEdge, false); // restore original position |
|
962 |
x:= 0; |
|
963 |
y:= cornerHeight; |
|
964 |
while y < textHeight + cornerHeight do |
|
965 |
begin |
|
966 |
copyToXY(rotatedEdge, Result, x, y); |
|
967 |
inc(y,edgeWidth); |
|
968 |
end; |
|
969 |
//////////////////////////////// END EDGES ////////////////////////////////////// |
|
970 |
||
971 |
x:= cornerWidth; |
|
972 |
y:= textHeight + cornerHeight * 2 - edgeHeight - 1; |
|
973 |
copyToXY(SpritesData[tail].Surface, Result, x, y); |
|
974 |
||
975 |
rect.x:= edgeHeight; |
|
976 |
rect.y:= edgeHeight; |
|
977 |
rect.w:= rect.w - edgeHeight * 2; |
|
978 |
rect.h:= textHeight + cornerHeight * 2 - edgeHeight * 2; |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
979 |
i:= rect.w; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
980 |
j:= rect.h; |
2017 | 981 |
SDL_FillRect(Result, @rect, cWhiteColor); |
982 |
||
983 |
pos:= 1; prevpos:= 0; line:= 0; |
|
984 |
while pos <= length(s) do |
|
985 |
begin |
|
986 |
if (s[pos] = #1) or (pos = length(s)) then |
|
987 |
begin |
|
988 |
if s[pos] <> #1 then inc(pos); |
|
989 |
while s[prevpos+1] = ' 'do inc(prevpos); |
|
990 |
substr:= copy(s, prevpos+1, pos-prevpos-1); |
|
991 |
if Length(substr) <> 0 then |
|
992 |
begin |
|
993 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cColorNearBlack); |
|
2619 | 994 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
995 |
rect.x:= edgeHeight + 1 + ((i - w) div 2); |
2022 | 996 |
// trying to more evenly position the text, vertically |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
997 |
rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h; |
2017 | 998 |
SDLTry(tmpsurf <> nil, true); |
999 |
SDL_UpperBlit(tmpsurf, nil, Result, @rect); |
|
1000 |
SDL_FreeSurface(tmpsurf); |
|
1001 |
inc(line); |
|
1002 |
prevpos:= pos; |
|
1003 |
end; |
|
1004 |
end; |
|
1005 |
inc(pos); |
|
1006 |
end; |
|
1007 |
||
1008 |
//TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
1009 |
RenderSpeechBubbleTex:= Surface2Tex(Result, true); |
2017 | 1010 |
|
1011 |
SDL_FreeSurface(rotatedEdge); |
|
1012 |
SDL_FreeSurface(Result) |
|
1013 |
end; |
|
1014 |
||
4 | 1015 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 1016 |
var s: shortstring; |
4 | 1017 |
begin |
351 | 1018 |
str(Hedgehog.Gear^.Health, s); |
762 | 1019 |
if Hedgehog.HealthTagTex <> nil then FreeTexture(Hedgehog.HealthTagTex); |
1020 |
Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
|
4 | 1021 |
end; |
1022 |
||
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
1023 |
function LoadImage(const filename: string; imageFlags: Integer): PSDL_Surface; |
30 | 1024 |
var tmpsurf: PSDL_Surface; |
355 | 1025 |
s: shortstring; |
4 | 1026 |
begin |
1027 |
WriteToConsole(msgLoading + filename + '... '); |
|
2426 | 1028 |
|
1029 |
s:= filename + '.png'; |
|
355 | 1030 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
2254 | 1031 |
|
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1032 |
if ((imageFlags and ifLowRes) <> 0) then |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1033 |
begin |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1034 |
s:= filename + '-lowres.png'; |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1035 |
if (tmpsurf <> nil) then |
2376 | 1036 |
begin |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1037 |
if ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1038 |
begin |
2426 | 1039 |
SDL_FreeSurface(tmpsurf); |
2600 | 1040 |
WriteLnToConsole('Image too big, trying to load lowres version: ' + s); |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1041 |
tmpsurf:= IMG_Load(Str2PChar(s)) |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1042 |
end; |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1043 |
end |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1044 |
else |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1045 |
begin |
2600 | 1046 |
WriteLnToConsole('Image not found, trying to load lowres version: ' + s); |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1047 |
tmpsurf:= IMG_Load(Str2PChar(s)) |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1048 |
end; |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1049 |
end; |
2376 | 1050 |
|
80 | 1051 |
if tmpsurf = nil then |
2153 | 1052 |
begin |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
1053 |
OutError(msgFailed, (imageFlags and ifCritical) <> 0); |
2153 | 1054 |
exit(nil) |
1055 |
end; |
|
1056 |
||
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
1057 |
if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
2153 | 1058 |
begin |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1059 |
SDL_FreeSurface(tmpsurf); |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1060 |
OutError(msgFailedSize, (imageFlags and ifCritical) <> 0); |
2248
26e11cb27c61
real fix for iphone color (reverting previous commit)
koda
parents:
2244
diff
changeset
|
1061 |
//dummy surface to replace non-critical textures that failed to load due to their size |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1062 |
exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask)); |
2153 | 1063 |
end; |
351 | 1064 |
|
2619 | 1065 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
2575 | 1066 |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
1067 |
if (imageFlags and ifTransparent) <> 0 then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
2248
26e11cb27c61
real fix for iphone color (reverting previous commit)
koda
parents:
2244
diff
changeset
|
1068 |
//if (imageFlags and ifAlpha) <> 0 then Result:= SDL_DisplayFormatAlpha(tmpsurf) else Result:= SDL_DisplayFormat(tmpsurf); |
2153 | 1069 |
WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') '); |
351 | 1070 |
WriteLnToConsole(msgOK); |
2153 | 1071 |
|
1072 |
LoadImage:= tmpsurf //Result |
|
753 | 1073 |
end; |
1074 |
||
2428 | 1075 |
function glLoadExtension(extension : string) : boolean; |
1076 |
begin |
|
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1077 |
{$IFDEF IPHONEOS} |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1078 |
glLoadExtension:= false; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1079 |
{$ELSE} |
2428 | 1080 |
glLoadExtension:= glext_LoadExtension(extension); |
2438 | 1081 |
{$ENDIF} |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1082 |
{$IFDEF DEBUGFILE} |
2428 | 1083 |
if not glLoadExtension then |
2575 | 1084 |
AddFileLog('OpenGL - "' + extension + '" failed to load') |
2428 | 1085 |
else |
2575 | 1086 |
AddFileLog('OpenGL - "' + extension + '" loaded'); |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1087 |
{$ENDIF} |
2428 | 1088 |
end; |
1089 |
||
753 | 1090 |
procedure SetupOpenGL; |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1091 |
var vendor: shortstring; |
753 | 1092 |
begin |
2153 | 1093 |
glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize); |
2565 | 1094 |
|
2153 | 1095 |
{$IFDEF DEBUGFILE} |
2575 | 1096 |
AddFileLog('OpenGL - Renderer: ' + string(pchar(glGetString(GL_RENDERER)))); |
1097 |
AddFileLog('OpenGL - Vendor: ' + string(pchar(glGetString(GL_VENDOR)))); |
|
1098 |
AddFileLog('OpenGL - Version: ' + string(pchar(glGetString(GL_VERSION)))); |
|
1099 |
AddFileLog('OpenGL - GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize)); |
|
2153 | 1100 |
{$ENDIF} |
2252 | 1101 |
|
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1102 |
if MaxTextureSize = 0 then |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1103 |
begin |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1104 |
MaxTextureSize:= 1024; |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1105 |
{$IFDEF DEBUGFILE} |
2575 | 1106 |
AddFileLog('OpenGL Warning - driver didn''t provide any valid max texture size; assuming 1024'); |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1107 |
{$ENDIF} |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1108 |
end; |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1109 |
|
2575 | 1110 |
vendor:= LowerCase(string(pchar(glGetString(GL_VENDOR)))); |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1111 |
if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1112 |
cGPUVendor:= gvNVIDIA |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1113 |
else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1114 |
cGPUVendor:= gvATI |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1115 |
else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1116 |
cGPUVendor:= gvIntel; |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1117 |
|
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1118 |
|
2438 | 1119 |
{$IFNDEF IPHONEOS} |
2603 | 1120 |
// since ATI seems to be unable to provide proper texture filtering/quality, |
1121 |
// do not even try to load the extension on ATI cards |
|
1122 |
||
1123 |
{$IFDEF DARWIN} |
|
1124 |
if true then |
|
1125 |
{$ELSE} |
|
1126 |
if cGPUVendor <> gvATI then |
|
1127 |
{$ENDIF} |
|
1128 |
SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two') |
|
1129 |
{$IFDEF DEBUGFILE} |
|
1130 |
else |
|
1131 |
AddFileLog('OpenGL: Skipped extension GL_ARB_texture_non_power_of_two due to ATI card') |
|
1132 |
{$ENDIF} |
|
1133 |
; // do not touch this line! :) |
|
2428 | 1134 |
{$ENDIF} |
1135 |
||
1136 |
// set view port to whole window |
|
1137 |
glViewport(0, 0, cScreenWidth, cScreenHeight); |
|
1138 |
||
1139 |
glMatrixMode(GL_MODELVIEW); |
|
1140 |
// prepare default translation/scaling |
|
1141 |
glLoadIdentity; |
|
1142 |
glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
|
1143 |
glTranslatef(0, -cScreenHeight / 2, 0); |
|
1144 |
||
1145 |
// enable alpha blending |
|
1146 |
glEnable(GL_BLEND); |
|
1147 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
4 | 1148 |
end; |
1149 |
||
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1150 |
procedure SetScale(f: GLfloat); |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1151 |
begin |
2438 | 1152 |
// leave immediately if scale factor did not change |
2428 | 1153 |
if f = cScaleFactor then exit; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1154 |
|
2428 | 1155 |
if f = 2.0 then // default scaling |
1156 |
glPopMatrix // "return" to default scaling |
|
1157 |
else // other scaling |
|
1158 |
begin |
|
1159 |
glPushMatrix; // save default scaling |
|
1160 |
glLoadIdentity; |
|
1161 |
glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0); |
|
1162 |
glTranslatef(0, -cScreenHeight / 2, 0); |
|
1163 |
end; |
|
2258 | 1164 |
|
2428 | 1165 |
cScaleFactor:= f; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1166 |
end; |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1167 |
|
510 | 1168 |
//////////////////////////////////////////////////////////////////////////////// |
766 | 1169 |
var ProgrTex: PTexture = nil; |
534 | 1170 |
Step: integer = 0; |
2222 | 1171 |
squaresize : LongInt; |
1172 |
numsquares : integer; |
|
2284 | 1173 |
|
510 | 1174 |
procedure AddProgress; |
1175 |
var r: TSDL_Rect; |
|
766 | 1176 |
texsurf: PSDL_Surface; |
510 | 1177 |
begin |
1178 |
if Step = 0 then |
|
1179 |
begin |
|
1180 |
WriteToConsole(msgLoading + 'progress sprite: '); |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
1181 |
texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent); |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
1182 |
ProgrTex:= Surface2Tex(texsurf, false); |
2222 | 1183 |
SDL_FreeSurface(texsurf); |
1184 |
squaresize:= ProgrTex^.w shr 1; |
|
1185 |
numsquares:= ProgrTex^.h div squaresize; |
|
510 | 1186 |
end; |
1045 | 1187 |
|
2284 | 1188 |
TryDo(ProgrTex <> nil, 'ProgrTex = nil!', true); |
1189 |
||
766 | 1190 |
glClear(GL_COLOR_BUFFER_BIT); |
775 | 1191 |
glEnable(GL_TEXTURE_2D); |
2222 | 1192 |
if Step < numsquares then r.x:= 0 |
1193 |
else r.x:= squaresize; |
|
1194 |
r.y:= (Step mod numsquares) * squaresize; |
|
1195 |
r.w:= squaresize; |
|
1196 |
r.h:= squaresize; |
|
1197 |
DrawFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex); |
|
775 | 1198 |
glDisable(GL_TEXTURE_2D); |
766 | 1199 |
SDL_GL_SwapBuffers(); |
510 | 1200 |
inc(Step); |
1201 |
end; |
|
1202 |
||
2222 | 1203 |
|
510 | 1204 |
procedure FinishProgress; |
1205 |
begin |
|
1206 |
WriteLnToConsole('Freeing progress surface... '); |
|
2284 | 1207 |
FreeTexture(ProgrTex); |
1208 |
ProgrTex:= nil |
|
510 | 1209 |
end; |
1210 |
||
2017 | 1211 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
1212 |
var y, x, i, j: LongInt; |
|
1213 |
tmpPixel: Longword; |
|
1214 |
pixels: PLongWordArray; |
|
1215 |
begin |
|
1216 |
TryDo(Surface^.format^.BytesPerPixel = 4, 'flipSurface failed, expecting 32 bit surface', true); |
|
1217 |
pixels:= Surface^.pixels; |
|
1218 |
if Vertical then |
|
1219 |
for y := 0 to (Surface^.h div 2) - 1 do |
|
1220 |
for x := 0 to Surface^.w - 1 do |
|
1221 |
begin |
|
1222 |
i:= y * Surface^.w + x; |
|
1223 |
j:= (Surface^.h - y - 1) * Surface^.w + x; |
|
1224 |
tmpPixel:= pixels^[i]; |
|
1225 |
pixels^[i]:= pixels^[j]; |
|
1226 |
pixels^[j]:= tmpPixel; |
|
1227 |
end |
|
1228 |
else |
|
1229 |
for x := 0 to (Surface^.w div 2) - 1 do |
|
1230 |
for y := 0 to Surface^.h -1 do |
|
1231 |
begin |
|
1232 |
i:= y*Surface^.w + x; |
|
1233 |
j:= y*Surface^.w + (Surface^.w - x - 1); |
|
1234 |
tmpPixel:= pixels^[i]; |
|
1235 |
pixels^[i]:= pixels^[j]; |
|
1236 |
pixels^[j]:= tmpPixel; |
|
1237 |
end; |
|
1238 |
end; |
|
1239 |
||
1240 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer); |
|
1241 |
var srcX, srcY, i, j, maxDest: LongInt; |
|
1242 |
srcPixels, destPixels: PLongWordArray; |
|
1243 |
begin |
|
1244 |
maxDest:= (dest^.pitch div 4) * dest^.h; |
|
1245 |
srcPixels:= src^.pixels; |
|
1246 |
destPixels:= dest^.pixels; |
|
1247 |
||
1248 |
for srcX:= 0 to src^.w - 1 do |
|
1249 |
for srcY:= 0 to src^.h - 1 do |
|
1250 |
begin |
|
1251 |
i:= (destY + srcY) * (dest^.pitch div 4) + destX + srcX; |
|
1252 |
j:= srcY * (src^.pitch div 4) + srcX; |
|
1253 |
// basic skip of transparent pixels - cleverness would be to do true alpha |
|
2592 | 1254 |
if (i < maxDest) and (AMask and srcPixels^[j] <> 0) then destPixels^[i]:= srcPixels^[j]; |
2017 | 1255 |
end; |
1256 |
end; |
|
1257 |
||
1258 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently |
|
1259 |
var y, x, i, j: LongInt; |
|
1260 |
srcPixels, destPixels: PLongWordArray; |
|
1261 |
begin |
|
1262 |
TryDo(src^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
1263 |
TryDo(dest^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
1264 |
||
1265 |
srcPixels:= src^.pixels; |
|
1266 |
destPixels:= dest^.pixels; |
|
1267 |
||
1268 |
j:= 0; |
|
1269 |
for x := 0 to src^.w - 1 do |
|
1270 |
for y := 0 to src^.h - 1 do |
|
1271 |
begin |
|
1272 |
i:= (src^.h - 1 - y) * (src^.pitch div 4) + x; |
|
1273 |
destPixels^[j]:= srcPixels^[i]; |
|
1274 |
inc(j) |
|
1275 |
end; |
|
1276 |
end; |
|
1277 |
||
4 | 1278 |
end. |