author | koda |
Thu, 24 Dec 2009 13:38:20 +0000 | |
changeset 2670 | 1b327b7515ed |
parent 2669 | 4eec706e86b0 |
child 2671 | 7e0f88013fe8 |
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 |
||
2623 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uStore; |
22 |
interface |
|
2017 | 23 |
uses sysutils, uConsts, uTeams, SDLh, |
2152 | 24 |
{$IFDEF GLES11} |
1906 | 25 |
gles11, |
26 |
{$ELSE} |
|
2428 | 27 |
GL, GLext, |
1906 | 28 |
{$ENDIF} |
29 |
uFloat; |
|
4 | 30 |
|
31 |
procedure StoreInit; |
|
32 |
procedure StoreLoad; |
|
33 |
procedure StoreRelease; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
34 |
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
|
35 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
36 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
1939 | 37 |
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
|
38 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture); |
762 | 39 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
1251 | 40 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt); |
2597 | 41 |
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, Frames: LongInt; Angle: real); |
822 | 42 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
853 | 43 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
822 | 44 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
762 | 45 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
46 |
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
|
47 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1431 | 48 |
procedure DrawFillRect(r: TSDL_Rect); |
762 | 49 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
2017 | 50 |
function RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture; |
51 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
|
52 |
//procedure rotateSurface(Surface: PSDL_Surface); |
|
53 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL |
|
54 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer); |
|
4 | 55 |
procedure RenderHealth(var Hedgehog: THedgehog); |
56 |
procedure AddProgress; |
|
510 | 57 |
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
|
58 |
function LoadImage(const filename: string; imageFlags: Integer): PSDL_Surface; |
753 | 59 |
procedure SetupOpenGL; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
60 |
procedure SetScale(f: GLfloat); |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
61 |
|
4 | 62 |
|
1525 | 63 |
var PixelFormat: PSDL_PixelFormat = nil; |
64 |
SDLPrimSurface: PSDL_Surface = nil; |
|
1023 | 65 |
PauseTexture, |
2397
2ca4ca6b4bab
- Patch for "Syncronizing" message by Smaxx + some tweaks by me
unc0rr
parents:
2376
diff
changeset
|
66 |
SyncTexture, |
1023 | 67 |
ConfirmTexture: PTexture; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
68 |
cScaleFactor: GLfloat = 2.0; |
2428 | 69 |
SupportNPOTT: Boolean = false; |
4 | 70 |
|
71 |
implementation |
|
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
72 |
uses uMisc, uConsole, uLand, uLocale, uWorld; |
4 | 73 |
|
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
|
74 |
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
|
75 |
|
690 | 76 |
var |
761 | 77 |
HHTexture: PTexture; |
2153 | 78 |
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
|
79 |
cGPUVendor: TGPUVendor; |
4 | 80 |
|
81 |
procedure StoreInit; |
|
82 |
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
|
83 |
cGPUVendor:= gvUnknown; |
4 | 84 |
end; |
85 |
||
351 | 86 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
47 | 87 |
var r: TSDL_Rect; |
88 |
begin |
|
89 |
r:= rect^; |
|
83 | 90 |
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
|
91 |
|
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
92 |
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
|
93 |
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
|
94 |
|
351 | 95 |
r.y:= rect^.y + 1; |
96 |
r.h:= rect^.h - 2; |
|
47 | 97 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 98 |
r.x:= rect^.x + 1; |
99 |
r.w:= rect^.w - 2; |
|
100 |
r.y:= rect^.y; |
|
101 |
r.h:= rect^.h; |
|
47 | 102 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 103 |
r.x:= rect^.x + 2; |
104 |
r.y:= rect^.y + 1; |
|
105 |
r.w:= rect^.w - 4; |
|
106 |
r.h:= rect^.h - 2; |
|
47 | 107 |
SDL_FillRect(Surface, @r, FillColor); |
351 | 108 |
r.x:= rect^.x + 1; |
109 |
r.y:= rect^.y + 2; |
|
110 |
r.w:= rect^.w - 2; |
|
111 |
r.h:= rect^.h - 4; |
|
47 | 112 |
SDL_FillRect(Surface, @r, FillColor) |
113 |
end; |
|
114 |
||
371 | 115 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
351 | 116 |
var w, h: LongInt; |
4 | 117 |
tmpsurf: PSDL_Surface; |
118 |
clr: TSDL_Color; |
|
351 | 119 |
Result: TSDL_Rect; |
4 | 120 |
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
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
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
|
125 |
Result.h:= h + FontBorder * 2; |
2670 | 126 |
DrawRoundRect(@Result, cWhiteColor, endian(cNearBlackColorChannels.value), Surface, true); |
127 |
clr.r:= (Color shr 16) and $FF; |
|
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
|
128 |
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
|
129 |
clr.b:= Color and $FF; |
2665
50b4e544c163
complete transition of longword->sdl_color for TTF bindings
koda
parents:
2663
diff
changeset
|
130 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr); |
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
|
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 |
|
2666 | 168 |
DrawRoundRect(@r, cWhiteColor, cNearBlackColorChannels.value, texsurf, true); |
1185 | 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; |
|
4 | 267 |
begin |
2222 | 268 |
|
2669 | 269 |
AddProgress; |
270 |
||
4 | 271 |
for fi:= Low(THWFont) to High(THWFont) do |
1185 | 272 |
with Fontz[fi] do |
273 |
begin |
|
274 |
s:= Pathz[ptFonts] + '/' + Name; |
|
275 |
WriteToConsole(msgLoading + s + '... '); |
|
276 |
Handle:= TTF_OpenFont(Str2PChar(s), Height); |
|
277 |
SDLTry(Handle <> nil, true); |
|
278 |
TTF_SetFontStyle(Handle, style); |
|
279 |
WriteLnToConsole(msgOK) |
|
280 |
end; |
|
53 | 281 |
|
4 | 282 |
WriteNames(fnt16); |
70 | 283 |
MakeCrossHairs; |
4 | 284 |
LoadGraves; |
285 |
||
286 |
AddProgress; |
|
287 |
for ii:= Low(TSprite) to High(TSprite) do |
|
1185 | 288 |
with SpritesData[ii] do |
2145 | 289 |
// FIXME - add a sprite attribute |
2426 | 290 |
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
|
291 |
begin |
1185 | 292 |
if AltPath = ptNone then |
2426 | 293 |
if ii in [sprHorizontL, sprHorizontR, sprSkyL, sprSkyR] then // FIXME: hack |
294 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifLowRes) |
|
295 |
else |
|
296 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical or ifLowRes) |
|
1185 | 297 |
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
|
298 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
1185 | 299 |
if tmpsurf = nil then |
2610 | 300 |
tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent); |
1185 | 301 |
end; |
2426 | 302 |
|
303 |
if tmpsurf <> nil then |
|
2630 | 304 |
begin |
2610 | 305 |
if imageWidth = 0 then imageWidth:= tmpsurf^.w; |
306 |
if imageHeight = 0 then imageHeight:= tmpsurf^.h; |
|
2426 | 307 |
if Width = 0 then Width:= tmpsurf^.w; |
308 |
if Height = 0 then Height:= tmpsurf^.h; |
|
2452 | 309 |
if (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]) then |
2426 | 310 |
Texture:= Surface2Tex(tmpsurf, true) |
311 |
else |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
312 |
begin |
2426 | 313 |
Texture:= Surface2Tex(tmpsurf, false); |
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
314 |
if (ii = sprWater) and not cReducedQuality then // HACK: We should include some sprite attribute to define the texture wrap directions |
2630 | 315 |
begin |
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
316 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
317 |
end; |
2630 | 318 |
end; |
2426 | 319 |
if saveSurf then Surface:= tmpsurf else SDL_FreeSurface(tmpsurf) |
320 |
end |
|
321 |
else |
|
322 |
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
|
323 |
end; |
80 | 324 |
|
4 | 325 |
AddProgress; |
567 | 326 |
|
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
|
327 |
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
|
328 |
HHTexture:= Surface2Tex(tmpsurf, false); |
761 | 329 |
SDL_FreeSurface(tmpsurf); |
4 | 330 |
|
331 |
InitHealth; |
|
332 |
||
2623 | 333 |
PauseTexture:= RenderStringTex(trmsg[sidPaused], cYellowColor, fntBig); |
334 |
ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], cYellowColor, fntBig); |
|
335 |
SyncTexture:= RenderStringTex(trmsg[sidSync], cYellowColor, fntBig); |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
336 |
|
2601 | 337 |
AddProgress; |
338 |
||
2670 | 339 |
// name of weapons in ammo menu |
843 | 340 |
for ai:= Low(TAmmoType) to High(TAmmoType) do |
341 |
with Ammoz[ai] do |
|
342 |
begin |
|
2665
50b4e544c163
complete transition of longword->sdl_color for TTF bindings
koda
parents:
2663
diff
changeset
|
343 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(trAmmo[NameId]), cWhiteColorChannels); |
2670 | 344 |
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
|
345 |
NameTex:= Surface2Tex(tmpsurf, false); |
843 | 346 |
SDL_FreeSurface(tmpsurf) |
347 |
end; |
|
2376 | 348 |
|
2670 | 349 |
// number of weapons in ammo menu |
844 | 350 |
for i:= Low(CountTexz) to High(CountTexz) do |
351 |
begin |
|
2665
50b4e544c163
complete transition of longword->sdl_color for TTF bindings
koda
parents:
2663
diff
changeset
|
352 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels); |
2670 | 353 |
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
|
354 |
CountTexz[i]:= Surface2Tex(tmpsurf, false); |
844 | 355 |
SDL_FreeSurface(tmpsurf) |
356 |
end; |
|
357 |
||
4 | 358 |
{$IFDEF DUMP} |
2601 | 359 |
//not working anymore, where are LandSurface and StoreSurface defined? |
360 |
//SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
361 |
//SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
4 | 362 |
{$ENDIF} |
2222 | 363 |
AddProgress; |
2669 | 364 |
|
365 |
IMG_Quit(); |
|
4 | 366 |
end; |
367 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
368 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
4 | 369 |
var rr: TSDL_Rect; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
370 |
_l, _r, _t, _b: real; |
1916 | 371 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
4 | 372 |
begin |
2428 | 373 |
if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit; |
4 | 374 |
rr.x:= X; |
375 |
rr.y:= Y; |
|
351 | 376 |
rr.w:= r^.w; |
377 |
rr.h:= r^.h; |
|
755 | 378 |
|
1896 | 379 |
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx; |
380 |
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx; |
|
381 |
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry; |
|
382 |
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry; |
|
755 | 383 |
|
384 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
385 |
||
1916 | 386 |
VertexBuffer[0].X:= X; |
387 |
VertexBuffer[0].Y:= Y; |
|
388 |
VertexBuffer[1].X:= rr.w + X; |
|
389 |
VertexBuffer[1].Y:= Y; |
|
390 |
VertexBuffer[2].X:= rr.w + X; |
|
391 |
VertexBuffer[2].Y:= rr.h + Y; |
|
392 |
VertexBuffer[3].X:= X; |
|
393 |
VertexBuffer[3].Y:= rr.h + Y; |
|
755 | 394 |
|
1916 | 395 |
TextureBuffer[0].X:= _l; |
396 |
TextureBuffer[0].Y:= _t; |
|
397 |
TextureBuffer[1].X:= _r; |
|
398 |
TextureBuffer[1].Y:= _t; |
|
399 |
TextureBuffer[2].X:= _r; |
|
400 |
TextureBuffer[2].Y:= _b; |
|
401 |
TextureBuffer[3].X:= _l; |
|
402 |
TextureBuffer[3].Y:= _b; |
|
755 | 403 |
|
1916 | 404 |
glEnableClientState(GL_VERTEX_ARRAY); |
405 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
755 | 406 |
|
1916 | 407 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
408 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
409 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
410 |
||
411 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
412 |
glDisableClientState(GL_VERTEX_ARRAY) |
|
762 | 413 |
end; |
414 |
||
415 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
|
416 |
begin |
|
1904 | 417 |
glPushMatrix; |
418 |
glTranslatef(X, Y, 0); |
|
419 |
||
762 | 420 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
421 |
||
1904 | 422 |
glEnableClientState(GL_VERTEX_ARRAY); |
423 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
762 | 424 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
425 |
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
|
426 |
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
|
427 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); |
1904 | 428 |
|
429 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
430 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
431 |
||
432 |
glPopMatrix |
|
4 | 433 |
end; |
434 |
||
1251 | 435 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt); |
1242 | 436 |
var ft, fb: GLfloat; |
437 |
hw: LongInt; |
|
1916 | 438 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
1242 | 439 |
begin |
440 |
glPushMatrix; |
|
441 |
glTranslatef(X, Y, 0); |
|
2598 | 442 |
glScalef(Scale, Scale, 1.0); |
2597 | 443 |
|
444 |
if Dir < 0 then |
|
445 |
hw:= - 16 |
|
446 |
else |
|
447 |
hw:= 16; |
|
448 |
||
449 |
ft:= Frame / Frames * Texture^.ry; |
|
450 |
fb:= (Frame + 1) / Frames * Texture^.ry; |
|
451 |
||
452 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
453 |
||
454 |
VertexBuffer[0].X:= -hw; |
|
455 |
VertexBuffer[0].Y:= -16; |
|
456 |
VertexBuffer[1].X:= hw; |
|
457 |
VertexBuffer[1].Y:= -16; |
|
458 |
VertexBuffer[2].X:= hw; |
|
459 |
VertexBuffer[2].Y:= 16; |
|
460 |
VertexBuffer[3].X:= -hw; |
|
461 |
VertexBuffer[3].Y:= 16; |
|
462 |
||
463 |
TextureBuffer[0].X:= 0; |
|
464 |
TextureBuffer[0].Y:= ft; |
|
465 |
TextureBuffer[1].X:= Texture^.rx; |
|
466 |
TextureBuffer[1].Y:= ft; |
|
467 |
TextureBuffer[2].X:= Texture^.rx; |
|
468 |
TextureBuffer[2].Y:= fb; |
|
469 |
TextureBuffer[3].X:= 0; |
|
470 |
TextureBuffer[3].Y:= fb; |
|
471 |
||
472 |
glEnableClientState(GL_VERTEX_ARRAY); |
|
473 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
474 |
||
475 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
476 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
477 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
478 |
||
479 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
480 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
481 |
||
482 |
||
483 |
glPopMatrix |
|
484 |
end; |
|
485 |
||
486 |
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, Frames: LongInt; Angle: real); |
|
487 |
var ft, fb: GLfloat; |
|
488 |
hw: LongInt; |
|
489 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
|
490 |
begin |
|
491 |
glPushMatrix; |
|
492 |
glTranslatef(X, Y, 0); |
|
493 |
||
494 |
if Dir < 0 then |
|
495 |
glRotatef(Angle, 0, 0, -1) |
|
496 |
else |
|
497 |
glRotatef(Angle, 0, 0, 1); |
|
498 |
||
499 |
glTranslatef(Dir*OffsetX, OffsetY, 0); |
|
500 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
|
1242 | 501 |
|
502 |
if Dir < 0 then |
|
503 |
hw:= - 16 |
|
504 |
else |
|
505 |
hw:= 16; |
|
506 |
||
1896 | 507 |
ft:= Frame / Frames * Texture^.ry; |
508 |
fb:= (Frame + 1) / Frames * Texture^.ry; |
|
1242 | 509 |
|
510 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
511 |
||
1916 | 512 |
VertexBuffer[0].X:= -hw; |
513 |
VertexBuffer[0].Y:= -16; |
|
514 |
VertexBuffer[1].X:= hw; |
|
515 |
VertexBuffer[1].Y:= -16; |
|
516 |
VertexBuffer[2].X:= hw; |
|
517 |
VertexBuffer[2].Y:= 16; |
|
518 |
VertexBuffer[3].X:= -hw; |
|
519 |
VertexBuffer[3].Y:= 16; |
|
1242 | 520 |
|
1916 | 521 |
TextureBuffer[0].X:= 0; |
522 |
TextureBuffer[0].Y:= ft; |
|
523 |
TextureBuffer[1].X:= Texture^.rx; |
|
524 |
TextureBuffer[1].Y:= ft; |
|
525 |
TextureBuffer[2].X:= Texture^.rx; |
|
526 |
TextureBuffer[2].Y:= fb; |
|
527 |
TextureBuffer[3].X:= 0; |
|
528 |
TextureBuffer[3].Y:= fb; |
|
1242 | 529 |
|
1916 | 530 |
glEnableClientState(GL_VERTEX_ARRAY); |
531 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
1242 | 532 |
|
1916 | 533 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
534 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
535 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
536 |
||
537 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
538 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
539 |
||
1242 | 540 |
|
541 |
glPopMatrix |
|
542 |
end; |
|
543 |
||
822 | 544 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
775 | 545 |
begin |
777 | 546 |
DrawRotatedTex(SpritesData[Sprite].Texture, |
822 | 547 |
SpritesData[Sprite].Width, |
548 |
SpritesData[Sprite].Height, |
|
549 |
X, Y, Dir, Angle) |
|
777 | 550 |
end; |
551 |
||
853 | 552 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
806 | 553 |
begin |
554 |
glPushMatrix; |
|
809 | 555 |
glTranslatef(X, Y, 0); |
806 | 556 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
557 |
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
|
558 |
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
|
559 |
else |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
560 |
glRotatef(Angle, 0, 0, 1); |
853 | 561 |
if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
562 |
||
563 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
806 | 564 |
|
565 |
glPopMatrix |
|
566 |
end; |
|
567 |
||
822 | 568 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
1916 | 569 |
var VertexBuffer: array [0..3] of TVertex2f; |
777 | 570 |
begin |
775 | 571 |
glPushMatrix; |
572 |
glTranslatef(X, Y, 0); |
|
822 | 573 |
|
574 |
if Dir < 0 then |
|
575 |
begin |
|
576 |
hw:= - hw; |
|
577 |
glRotatef(Angle, 0, 0, -1); |
|
578 |
end else |
|
579 |
glRotatef(Angle, 0, 0, 1); |
|
580 |
||
775 | 581 |
|
777 | 582 |
glBindTexture(GL_TEXTURE_2D, Tex^.id); |
775 | 583 |
|
1916 | 584 |
VertexBuffer[0].X:= -hw; |
585 |
VertexBuffer[0].Y:= -hh; |
|
586 |
VertexBuffer[1].X:= hw; |
|
587 |
VertexBuffer[1].Y:= -hh; |
|
588 |
VertexBuffer[2].X:= hw; |
|
589 |
VertexBuffer[2].Y:= hh; |
|
590 |
VertexBuffer[3].X:= -hw; |
|
591 |
VertexBuffer[3].Y:= hh; |
|
775 | 592 |
|
1916 | 593 |
glEnableClientState(GL_VERTEX_ARRAY); |
594 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
775 | 595 |
|
1916 | 596 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
597 |
glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb); |
|
598 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
775 | 599 |
|
1916 | 600 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
601 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
775 | 602 |
|
603 |
glPopMatrix |
|
604 |
end; |
|
605 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
606 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
4 | 607 |
begin |
608 |
r.y:= r.y + Height * Position; |
|
609 |
r.h:= Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
610 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 611 |
end; |
612 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
613 |
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
|
614 |
var row, col, numFramesFirstCol: LongInt; |
4 | 615 |
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
|
616 |
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
|
617 |
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
|
618 |
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
|
619 |
DrawSprite2 (Sprite, X, Y, col, row); |
4 | 620 |
end; |
621 |
||
1939 | 622 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
623 |
var r: TSDL_Rect; |
|
624 |
begin |
|
625 |
r.x:= 0; |
|
626 |
r.y:= 0; |
|
627 |
r.w:= SpritesData[Sprite].Width; |
|
628 |
r.h:= SpritesData[Sprite].Height; |
|
629 |
||
630 |
if (X < LeftX) then |
|
631 |
r.x:= LeftX - X; |
|
632 |
if (Y < TopY) then |
|
633 |
r.y:= TopY - Y; |
|
634 |
||
635 |
if (Y + SpritesData[Sprite].Height > BottomY) then |
|
636 |
r.h:= BottomY - Y + 1; |
|
637 |
if (X + SpritesData[Sprite].Width > RightX) then |
|
638 |
r.w:= RightX - X + 1; |
|
639 |
||
640 |
dec(r.h, r.y); |
|
641 |
dec(r.w, r.x); |
|
2230
d6963f72d21a
once again, trying to restore windows compatibility from nemo's experiments
koda
parents:
2229
diff
changeset
|
642 |
|
1939 | 643 |
DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture) |
644 |
end; |
|
645 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
646 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
43 | 647 |
var r: TSDL_Rect; |
648 |
begin |
|
649 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
650 |
r.w:= SpritesData[Sprite].Width; |
|
651 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
652 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
653 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
43 | 654 |
end; |
655 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
656 |
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
|
657 |
var r: TSDL_Rect; |
198 | 658 |
begin |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
659 |
r.x:= 0; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
660 |
r.w:= Source^.w; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
661 |
r.y:= Frame * Height; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
662 |
r.h:= Height; |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
663 |
DrawFromRect(X, Y, @r, Source) |
198 | 664 |
end; |
665 |
||
762 | 666 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
95 | 667 |
begin |
2567 | 668 |
DrawTexture(X - Source^.w shr 1, Top, Source) |
4 | 669 |
end; |
670 |
||
1865
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1854
diff
changeset
|
671 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1916 | 672 |
const VertexBuffer: array [0..3] of TVertex2f = ( |
673 |
(x: -16; y: -16), |
|
674 |
(x: 16; y: -16), |
|
675 |
(x: 16; y: 16), |
|
676 |
(x: -16; y: 16)); |
|
761 | 677 |
var l, r, t, b: real; |
1916 | 678 |
TextureBuffer: array [0..3] of TVertex2f; |
4 | 679 |
begin |
761 | 680 |
|
681 |
t:= Pos * 32 / HHTexture^.h; |
|
682 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
683 |
||
684 |
if Dir = -1 then |
|
685 |
begin |
|
686 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
687 |
r:= Step * 32 / HHTexture^.w |
|
688 |
end else |
|
689 |
begin |
|
690 |
l:= Step * 32 / HHTexture^.w; |
|
691 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
692 |
end; |
|
693 |
||
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
694 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
695 |
glPushMatrix(); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
696 |
glTranslatef(X, Y, 0); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
697 |
glRotatef(Angle, 0, 0, 1); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
698 |
|
761 | 699 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
700 |
||
1916 | 701 |
TextureBuffer[0].X:= l; |
702 |
TextureBuffer[0].Y:= t; |
|
703 |
TextureBuffer[1].X:= r; |
|
704 |
TextureBuffer[1].Y:= t; |
|
705 |
TextureBuffer[2].X:= r; |
|
706 |
TextureBuffer[2].Y:= b; |
|
707 |
TextureBuffer[3].X:= l; |
|
708 |
TextureBuffer[3].Y:= b; |
|
761 | 709 |
|
1916 | 710 |
glEnableClientState(GL_VERTEX_ARRAY); |
711 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
761 | 712 |
|
1916 | 713 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
714 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
715 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
761 | 716 |
|
1916 | 717 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
718 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
761 | 719 |
|
1854 | 720 |
|
721 |
glColor4f(1,1,1,1); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
722 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
723 |
glPopMatrix |
4 | 724 |
end; |
725 |
||
1431 | 726 |
procedure DrawFillRect(r: TSDL_Rect); |
1916 | 727 |
var VertexBuffer: array [0..3] of TVertex2f; |
1431 | 728 |
begin |
729 |
glDisable(GL_TEXTURE_2D); |
|
730 |
||
731 |
glColor4ub(0, 0, 0, 127); |
|
732 |
||
1916 | 733 |
VertexBuffer[0].X:= r.x; |
734 |
VertexBuffer[0].Y:= r.y; |
|
735 |
VertexBuffer[1].X:= r.x + r.w; |
|
736 |
VertexBuffer[1].Y:= r.y; |
|
737 |
VertexBuffer[2].X:= r.x + r.w; |
|
738 |
VertexBuffer[2].Y:= r.y + r.h; |
|
739 |
VertexBuffer[3].X:= r.x; |
|
740 |
VertexBuffer[3].Y:= r.y + r.h; |
|
1431 | 741 |
|
1916 | 742 |
glEnableClientState(GL_VERTEX_ARRAY); |
743 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
744 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
745 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
1431 | 746 |
|
747 |
glColor4f(1, 1, 1, 1); |
|
748 |
glEnable(GL_TEXTURE_2D) |
|
749 |
end; |
|
750 |
||
4 | 751 |
procedure StoreRelease; |
752 |
var ii: TSprite; |
|
753 |
begin |
|
754 |
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
|
755 |
begin |
759 | 756 |
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
|
757 |
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
|
758 |
end; |
761 | 759 |
|
1806 | 760 |
FreeTexture(HHTexture) |
4 | 761 |
end; |
762 |
||
762 | 763 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
432 | 764 |
var w, h: LongInt; |
351 | 765 |
Result: PSDL_Surface; |
95 | 766 |
begin |
1989 | 767 |
if length(s) = 0 then s:= ' '; |
355 | 768 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
785 | 769 |
|
762 | 770 |
Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
771 |
32, RMask, GMask, BMask, AMask); |
|
785 | 772 |
|
107 | 773 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
785 | 774 |
|
95 | 775 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
785 | 776 |
|
762 | 777 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
785 | 778 |
|
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
|
779 |
RenderStringTex:= Surface2Tex(Result, false); |
785 | 780 |
|
762 | 781 |
SDL_FreeSurface(Result) |
95 | 782 |
end; |
783 |
||
2017 | 784 |
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
|
785 |
var textWidth, textHeight, x, y, w, h, i, j, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt; |
2017 | 786 |
Result, tmpsurf, rotatedEdge: PSDL_Surface; |
787 |
rect: TSDL_Rect; |
|
788 |
chars: TSysCharSet = [#9,' ','.',';',':','?','!',',']; |
|
789 |
substr: shortstring; |
|
790 |
edge, corner, tail: TSPrite; |
|
791 |
begin |
|
792 |
||
793 |
case SpeechType of |
|
2376 | 794 |
1: begin; |
795 |
edge:= sprSpeechEdge; |
|
2017 | 796 |
corner:= sprSpeechCorner; |
797 |
tail:= sprSpeechTail; |
|
798 |
end; |
|
2376 | 799 |
2: begin; |
2017 | 800 |
edge:= sprThoughtEdge; |
2376 | 801 |
corner:= sprThoughtCorner; |
2017 | 802 |
tail:= sprThoughtTail; |
803 |
end; |
|
2376 | 804 |
3: begin; |
2017 | 805 |
edge:= sprShoutEdge; |
806 |
corner:= sprShoutCorner; |
|
807 |
tail:= sprShoutTail; |
|
808 |
end; |
|
809 |
end; |
|
810 |
edgeHeight:= SpritesData[edge].Height; |
|
811 |
edgeWidth:= SpritesData[edge].Width; |
|
812 |
cornerWidth:= SpritesData[corner].Width; |
|
813 |
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
|
814 |
// This one screws up WrapText |
2022 | 815 |
//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
|
816 |
// 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
|
817 |
//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
|
818 |
|
2022 | 819 |
numLines:= 0; |
2017 | 820 |
|
821 |
if length(s) = 0 then s:= '...'; |
|
822 |
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
|
823 |
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
|
824 |
j:= 0; |
2017 | 825 |
if (length(s) > 20) then |
826 |
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
|
827 |
w:= 0; |
2017 | 828 |
i:= round(Sqrt(length(s)) * 2); |
829 |
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
|
830 |
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
|
831 |
// 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
|
832 |
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
|
833 |
begin |
2017 | 834 |
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
|
835 |
begin |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
836 |
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
|
837 |
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
|
838 |
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
|
839 |
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
|
840 |
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
|
841 |
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
|
842 |
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
|
843 |
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
|
844 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
845 |
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
|
846 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
847 |
end |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
848 |
else numLines := 1; |
2017 | 849 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
850 |
textWidth:=((w-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth; |
2022 | 851 |
textHeight:=(((numlines * h + 2)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth; |
2019 | 852 |
|
2022 | 853 |
textHeight:=max(textHeight,edgeWidth); |
2017 | 854 |
//textWidth:=max(textWidth,SpritesData[tail].Width); |
855 |
rect.x:= 0; |
|
856 |
rect.y:= 0; |
|
2022 | 857 |
rect.w:= textWidth + (cornerWidth * 2); |
858 |
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
|
859 |
//s:= inttostr(w) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h); |
2017 | 860 |
|
861 |
Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask); |
|
862 |
||
863 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
|
864 |
||
865 |
//////////////////////////////// CORNERS /////////////////////////////// |
|
866 |
copyToXY(SpritesData[corner].Surface, Result, 0, 0); /////////////////// NW |
|
867 |
||
868 |
flipSurface(SpritesData[corner].Surface, true); // store all 4 versions in memory to avoid repeated flips? |
|
869 |
x:= 0; |
|
870 |
y:= textHeight + cornerHeight -1; |
|
871 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// SW |
|
872 |
||
873 |
flipSurface(SpritesData[corner].Surface, false); |
|
874 |
x:= rect.w-cornerWidth-1; |
|
875 |
y:= textHeight + cornerHeight -1; |
|
876 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// SE |
|
877 |
||
878 |
flipSurface(SpritesData[corner].Surface, true); |
|
879 |
x:= rect.w-cornerWidth-1; |
|
880 |
y:= 0; |
|
881 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// NE |
|
882 |
flipSurface(SpritesData[corner].Surface, false); // restore original position |
|
883 |
//////////////////////////////// END CORNERS /////////////////////////////// |
|
884 |
||
885 |
//////////////////////////////// EDGES ////////////////////////////////////// |
|
886 |
x:= cornerWidth; |
|
887 |
y:= 0; |
|
888 |
while x < rect.w-cornerWidth-1 do |
|
889 |
begin |
|
890 |
copyToXY(SpritesData[edge].Surface, Result, x, y); ///////////////// top edge |
|
891 |
inc(x,edgeWidth); |
|
892 |
end; |
|
893 |
flipSurface(SpritesData[edge].Surface, true); |
|
894 |
x:= cornerWidth; |
|
895 |
y:= textHeight + cornerHeight*2 - edgeHeight-1; |
|
896 |
while x < rect.w-cornerWidth-1 do |
|
897 |
begin |
|
898 |
copyToXY(SpritesData[edge].Surface, Result, x, y); ///////////////// bottom edge |
|
899 |
inc(x,edgeWidth); |
|
900 |
end; |
|
901 |
flipSurface(SpritesData[edge].Surface, true); // restore original position |
|
902 |
||
903 |
rotatedEdge:= SDL_CreateRGBSurface(SDL_SWSURFACE, edgeHeight, edgeWidth, 32, RMask, GMask, BMask, AMask); |
|
904 |
x:= rect.w - edgeHeight - 1; |
|
905 |
y:= cornerHeight; |
|
906 |
//// initially was going to rotate in place, but the SDL spec claims width/height are read only |
|
907 |
copyRotatedSurface(SpritesData[edge].Surface,rotatedEdge); |
|
908 |
while y < textHeight + cornerHeight do |
|
909 |
begin |
|
910 |
copyToXY(rotatedEdge, Result, x, y); |
|
911 |
inc(y,edgeWidth); |
|
912 |
end; |
|
913 |
flipSurface(rotatedEdge, false); // restore original position |
|
914 |
x:= 0; |
|
915 |
y:= cornerHeight; |
|
916 |
while y < textHeight + cornerHeight do |
|
917 |
begin |
|
918 |
copyToXY(rotatedEdge, Result, x, y); |
|
919 |
inc(y,edgeWidth); |
|
920 |
end; |
|
921 |
//////////////////////////////// END EDGES ////////////////////////////////////// |
|
922 |
||
923 |
x:= cornerWidth; |
|
924 |
y:= textHeight + cornerHeight * 2 - edgeHeight - 1; |
|
925 |
copyToXY(SpritesData[tail].Surface, Result, x, y); |
|
926 |
||
927 |
rect.x:= edgeHeight; |
|
928 |
rect.y:= edgeHeight; |
|
929 |
rect.w:= rect.w - edgeHeight * 2; |
|
930 |
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
|
931 |
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
|
932 |
j:= rect.h; |
2017 | 933 |
SDL_FillRect(Result, @rect, cWhiteColor); |
934 |
||
935 |
pos:= 1; prevpos:= 0; line:= 0; |
|
936 |
while pos <= length(s) do |
|
937 |
begin |
|
938 |
if (s[pos] = #1) or (pos = length(s)) then |
|
939 |
begin |
|
940 |
if s[pos] <> #1 then inc(pos); |
|
941 |
while s[prevpos+1] = ' 'do inc(prevpos); |
|
942 |
substr:= copy(s, prevpos+1, pos-prevpos-1); |
|
943 |
if Length(substr) <> 0 then |
|
944 |
begin |
|
2666 | 945 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cNearBlackColorChannels); |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
946 |
rect.x:= edgeHeight + 1 + ((i - w) div 2); |
2022 | 947 |
// 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
|
948 |
rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h; |
2017 | 949 |
SDLTry(tmpsurf <> nil, true); |
950 |
SDL_UpperBlit(tmpsurf, nil, Result, @rect); |
|
951 |
SDL_FreeSurface(tmpsurf); |
|
952 |
inc(line); |
|
953 |
prevpos:= pos; |
|
954 |
end; |
|
955 |
end; |
|
956 |
inc(pos); |
|
957 |
end; |
|
958 |
||
959 |
//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
|
960 |
RenderSpeechBubbleTex:= Surface2Tex(Result, true); |
2017 | 961 |
|
962 |
SDL_FreeSurface(rotatedEdge); |
|
963 |
SDL_FreeSurface(Result) |
|
964 |
end; |
|
965 |
||
4 | 966 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 967 |
var s: shortstring; |
4 | 968 |
begin |
351 | 969 |
str(Hedgehog.Gear^.Health, s); |
762 | 970 |
if Hedgehog.HealthTagTex <> nil then FreeTexture(Hedgehog.HealthTagTex); |
971 |
Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
|
4 | 972 |
end; |
973 |
||
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
|
974 |
function LoadImage(const filename: string; imageFlags: Integer): PSDL_Surface; |
30 | 975 |
var tmpsurf: PSDL_Surface; |
355 | 976 |
s: shortstring; |
2630 | 977 |
{$IFDEF IPHONEOS} |
978 |
tmpP: PLongWordArray; |
|
979 |
tmpA, tmpR, tmpG, tmpB: LongWord; |
|
980 |
i: LongInt; |
|
981 |
{$ENDIF} |
|
4 | 982 |
begin |
2630 | 983 |
WriteToConsole(msgLoading + filename + '... '); |
2426 | 984 |
|
2630 | 985 |
s:= filename + '.png'; |
986 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
2254 | 987 |
|
2630 | 988 |
if (imageFlags and ifLowRes) <> 0 then |
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
|
989 |
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
|
990 |
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
|
991 |
if (tmpsurf <> nil) then |
2376 | 992 |
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
|
993 |
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
|
994 |
begin |
2426 | 995 |
SDL_FreeSurface(tmpsurf); |
2630 | 996 |
{$IFDEF DEBUGFILE} |
997 |
AddFileLog('...image too big, trying to load lowres version: ' + s + '...'); |
|
998 |
{$ENDIF} |
|
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
|
999 |
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
|
1000 |
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
|
1001 |
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
|
1002 |
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
|
1003 |
begin |
2630 | 1004 |
{$IFDEF DEBUGFILE} |
1005 |
AddFileLog('...image not found, trying to load lowres version: ' + s + '...'); |
|
1006 |
{$ENDIF} |
|
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
|
1007 |
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
|
1008 |
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
|
1009 |
end; |
2376 | 1010 |
|
2630 | 1011 |
if tmpsurf = nil then |
2153 | 1012 |
begin |
2630 | 1013 |
OutError(msgFailed, (imageFlags and ifCritical) <> 0); |
1014 |
exit(nil) |
|
2153 | 1015 |
end; |
1016 |
||
2630 | 1017 |
if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
2153 | 1018 |
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
|
1019 |
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
|
1020 |
OutError(msgFailedSize, (imageFlags and ifCritical) <> 0); |
2630 | 1021 |
// 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
|
1022 |
exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask)); |
2153 | 1023 |
end; |
351 | 1024 |
|
2630 | 1025 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
1026 |
||
2663 | 1027 |
{$IFDEF DONTUSE} // way too slow |
2630 | 1028 |
{* http://bugzilla.libsdl.org/show_bug.cgi?id=868 but patched library doesn't work on ipod, so implementing workaround here *} |
1029 |
if imageFlags and (ifAlpha or ifTransparent) > 0 then |
|
1030 |
begin |
|
1031 |
tmpP := tmpsurf^.pixels; |
|
1032 |
for i:= 0 to (tmpsurf^.pitch shr 2) * tmpsurf^.h - 1 do |
|
1033 |
begin |
|
1034 |
{$IFDEF ENDIAN_LITTLE} |
|
1035 |
tmpA:= tmpP^[i] shr 24 and $FF; |
|
1036 |
tmpR:= tmpP^[i] shr 16 and $FF; |
|
1037 |
tmpG:= tmpP^[i] shr 8 and $FF; |
|
1038 |
tmpB:= tmpP^[i] and $FF; |
|
1039 |
{$ELSE} |
|
1040 |
tmpA:= tmpP^[i] and $FF; |
|
1041 |
tmpR:= tmpP^[i] shr 8 and $FF; |
|
1042 |
tmpG:= tmpP^[i] shr 16 and $FF; |
|
1043 |
tmpB:= tmpP^[i] shr 24 and $FF; |
|
1044 |
{$ENDIF} |
|
1045 |
if tmpA <> 0 then |
|
1046 |
begin |
|
1047 |
tmpR:= round(tmpR * 255 / tmpA); |
|
1048 |
tmpG:= round(tmpG * 255 / tmpA); |
|
1049 |
tmpB:= round(tmpB * 255 / tmpA); |
|
1050 |
end; |
|
2575 | 1051 |
|
2630 | 1052 |
if tmpR > 255 then tmpR:= 255; |
1053 |
if tmpG > 255 then tmpG:= 255; |
|
1054 |
if tmpB > 255 then tmpB:= 255; |
|
2153 | 1055 |
|
2630 | 1056 |
{$IFDEF ENDIAN_LITTLE} |
1057 |
tmpP^[i]:= (tmpA shl 24) or (tmpR shl 16) or (tmpG shl 8) or tmpB; |
|
1058 |
{$ELSE} |
|
1059 |
tmpP^[i]:= (tmpA) or (tmpR shl 8) or (tmpG shl 16) or (tmpB shl 24); |
|
1060 |
{$ENDIF} |
|
1061 |
end; |
|
1062 |
(* for i:= 0 to (tmpsurf^.pitch shr 2) * tmpsurf^.h - 1 do |
|
1063 |
begin |
|
1064 |
tmpA:= tmpP^[i] shr 24 and $FF; |
|
1065 |
tmpR:= tmpP^[i] shr 16 and $FF; |
|
1066 |
tmpG:= tmpP^[i] shr 8 and $FF; |
|
1067 |
tmpB:= tmpP^[i] and $FF; |
|
1068 |
writeln(stdout, inttostr(tmpA) + ' | ' + inttostr(tmpR) + ' | ' + inttostr(tmpG)+ ' | ' + inttostr(tmpB)); |
|
1069 |
end; *) |
|
1070 |
end; |
|
1071 |
{$ENDIF} |
|
1072 |
||
1073 |
if (imageFlags and ifTransparent) <> 0 then |
|
1074 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
1075 |
||
1076 |
WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') '); |
|
1077 |
WriteLnToConsole(msgOK); |
|
1078 |
||
1079 |
LoadImage:= tmpsurf //Result |
|
753 | 1080 |
end; |
1081 |
||
2428 | 1082 |
function glLoadExtension(extension : string) : boolean; |
1083 |
begin |
|
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1084 |
{$IFDEF IPHONEOS} |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1085 |
glLoadExtension:= false; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1086 |
{$ELSE} |
2428 | 1087 |
glLoadExtension:= glext_LoadExtension(extension); |
2438 | 1088 |
{$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
|
1089 |
{$IFDEF DEBUGFILE} |
2428 | 1090 |
if not glLoadExtension then |
2575 | 1091 |
AddFileLog('OpenGL - "' + extension + '" failed to load') |
2428 | 1092 |
else |
2575 | 1093 |
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
|
1094 |
{$ENDIF} |
2428 | 1095 |
end; |
1096 |
||
753 | 1097 |
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
|
1098 |
var vendor: shortstring; |
753 | 1099 |
begin |
2153 | 1100 |
glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize); |
2565 | 1101 |
|
2630 | 1102 |
WriteLnToConsole('OpenGL - Renderer: ' + string(pchar(glGetString(GL_RENDERER)))); |
2153 | 1103 |
{$IFDEF DEBUGFILE} |
2575 | 1104 |
AddFileLog('OpenGL - Vendor: ' + string(pchar(glGetString(GL_VENDOR)))); |
1105 |
AddFileLog('OpenGL - Version: ' + string(pchar(glGetString(GL_VERSION)))); |
|
2153 | 1106 |
{$ENDIF} |
2630 | 1107 |
WriteLnToConsole('OpenGL - GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize)); |
2252 | 1108 |
|
2630 | 1109 |
if MaxTextureSize = 0 then |
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
|
1110 |
begin |
2633 | 1111 |
MaxTextureSize:= 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
|
1112 |
{$IFDEF DEBUGFILE} |
2633 | 1113 |
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
|
1114 |
{$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
|
1115 |
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
|
1116 |
|
2575 | 1117 |
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
|
1118 |
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
|
1119 |
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
|
1120 |
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
|
1121 |
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
|
1122 |
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
|
1123 |
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
|
1124 |
|
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
|
1125 |
|
2438 | 1126 |
{$IFNDEF IPHONEOS} |
2647 | 1127 |
//SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two'); |
2428 | 1128 |
{$ENDIF} |
1129 |
||
1130 |
// set view port to whole window |
|
1131 |
glViewport(0, 0, cScreenWidth, cScreenHeight); |
|
1132 |
||
1133 |
glMatrixMode(GL_MODELVIEW); |
|
1134 |
// prepare default translation/scaling |
|
1135 |
glLoadIdentity; |
|
1136 |
glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
|
2663 | 1137 |
//{$IFDEF IPHONEOS} |
1138 |
//glRotatef(90, 0, 0, 1); |
|
1139 |
//{$ENDIF} |
|
2428 | 1140 |
glTranslatef(0, -cScreenHeight / 2, 0); |
1141 |
||
1142 |
// enable alpha blending |
|
1143 |
glEnable(GL_BLEND); |
|
1144 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
4 | 1145 |
end; |
1146 |
||
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1147 |
procedure SetScale(f: GLfloat); |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1148 |
begin |
2438 | 1149 |
// leave immediately if scale factor did not change |
2428 | 1150 |
if f = cScaleFactor then exit; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1151 |
|
2428 | 1152 |
if f = 2.0 then // default scaling |
1153 |
glPopMatrix // "return" to default scaling |
|
1154 |
else // other scaling |
|
1155 |
begin |
|
1156 |
glPushMatrix; // save default scaling |
|
1157 |
glLoadIdentity; |
|
1158 |
glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0); |
|
2663 | 1159 |
//{$IFDEF IPHONEOS} |
1160 |
// glRotatef(90, 0, 0, 1); |
|
1161 |
//{$ENDIF} |
|
2428 | 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. |