author | nemo |
Mon, 12 Oct 2009 19:40:01 +0000 | |
changeset 2435 | 7afc9edac4cf |
parent 2428 | 6800f8aa0184 |
child 2438 | 6df2e58b6ab2 |
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 |
|
2017 | 21 |
uses sysutils, uConsts, uTeams, SDLh, |
2152 | 22 |
{$IFDEF GLES11} |
1906 | 23 |
gles11, |
24 |
{$ELSE} |
|
2428 | 25 |
GL, GLext, |
1906 | 26 |
{$ENDIF} |
27 |
uFloat; |
|
4 | 28 |
{$INCLUDE options.inc} |
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); |
822 | 40 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
853 | 41 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
822 | 42 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
762 | 43 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
44 |
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
|
45 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1431 | 46 |
procedure DrawFillRect(r: TSDL_Rect); |
762 | 47 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
2017 | 48 |
function RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture; |
49 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
|
50 |
//procedure rotateSurface(Surface: PSDL_Surface); |
|
51 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL |
|
52 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer); |
|
4 | 53 |
procedure RenderHealth(var Hedgehog: THedgehog); |
54 |
procedure AddProgress; |
|
510 | 55 |
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
|
56 |
function LoadImage(const filename: string; imageFlags: Integer): PSDL_Surface; |
753 | 57 |
procedure SetupOpenGL; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
58 |
procedure SetScale(f: GLfloat); |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
59 |
|
4 | 60 |
|
1525 | 61 |
var PixelFormat: PSDL_PixelFormat = nil; |
62 |
SDLPrimSurface: PSDL_Surface = nil; |
|
1023 | 63 |
PauseTexture, |
2397
2ca4ca6b4bab
- Patch for "Syncronizing" message by Smaxx + some tweaks by me
unc0rr
parents:
2376
diff
changeset
|
64 |
SyncTexture, |
1023 | 65 |
ConfirmTexture: PTexture; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
66 |
cScaleFactor: GLfloat = 2.0; |
2428 | 67 |
SupportNPOTT: Boolean = false; |
4 | 68 |
|
69 |
implementation |
|
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
70 |
uses uMisc, uConsole, uLand, uLocale, uWorld; |
4 | 71 |
|
690 | 72 |
var |
761 | 73 |
HHTexture: PTexture; |
2153 | 74 |
MaxTextureSize: Integer; |
4 | 75 |
|
76 |
procedure StoreInit; |
|
77 |
begin |
|
78 |
||
79 |
end; |
|
80 |
||
351 | 81 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
47 | 82 |
var r: TSDL_Rect; |
83 |
begin |
|
84 |
r:= rect^; |
|
83 | 85 |
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
|
86 |
|
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
87 |
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
|
88 |
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
|
89 |
|
351 | 90 |
r.y:= rect^.y + 1; |
91 |
r.h:= rect^.h - 2; |
|
47 | 92 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 93 |
r.x:= rect^.x + 1; |
94 |
r.w:= rect^.w - 2; |
|
95 |
r.y:= rect^.y; |
|
96 |
r.h:= rect^.h; |
|
47 | 97 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 98 |
r.x:= rect^.x + 2; |
99 |
r.y:= rect^.y + 1; |
|
100 |
r.w:= rect^.w - 4; |
|
101 |
r.h:= rect^.h - 2; |
|
47 | 102 |
SDL_FillRect(Surface, @r, FillColor); |
351 | 103 |
r.x:= rect^.x + 1; |
104 |
r.y:= rect^.y + 2; |
|
105 |
r.w:= rect^.w - 2; |
|
106 |
r.h:= rect^.h - 4; |
|
47 | 107 |
SDL_FillRect(Surface, @r, FillColor) |
108 |
end; |
|
109 |
||
371 | 110 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
351 | 111 |
var w, h: LongInt; |
4 | 112 |
tmpsurf: PSDL_Surface; |
113 |
clr: TSDL_Color; |
|
351 | 114 |
Result: TSDL_Rect; |
4 | 115 |
begin |
355 | 116 |
TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
4 | 117 |
Result.x:= X; |
118 |
Result.y:= Y; |
|
202 | 119 |
Result.w:= w + FontBorder * 2 + 4; |
120 |
Result.h:= h + FontBorder * 2; |
|
351 | 121 |
DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface, true); |
189 | 122 |
clr.r:= Color shr 16; |
123 |
clr.g:= (Color shr 8) and $FF; |
|
124 |
clr.b:= Color and $FF; |
|
355 | 125 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr.value); |
202 | 126 |
Result.x:= X + FontBorder + 2; |
127 |
Result.y:= Y + FontBorder; |
|
199 | 128 |
SDLTry(tmpsurf <> nil, true); |
4 | 129 |
SDL_UpperBlit(tmpsurf, nil, Surface, @Result); |
130 |
SDL_FreeSurface(tmpsurf); |
|
131 |
Result.x:= X; |
|
132 |
Result.y:= Y; |
|
202 | 133 |
Result.w:= w + FontBorder * 2 + 4; |
351 | 134 |
Result.h:= h + FontBorder * 2; |
135 |
WriteInRoundRect:= Result |
|
4 | 136 |
end; |
137 |
||
138 |
procedure StoreLoad; |
|
844 | 139 |
var s: string; |
4 | 140 |
|
1185 | 141 |
procedure WriteNames(Font: THWFont); |
142 |
var t: LongInt; |
|
143 |
i: LongInt; |
|
144 |
r, rr: TSDL_Rect; |
|
145 |
drY: LongInt; |
|
146 |
texsurf: PSDL_Surface; |
|
147 |
begin |
|
148 |
r.x:= 0; |
|
149 |
r.y:= 0; |
|
150 |
drY:= - 4; |
|
151 |
for t:= 0 to Pred(TeamsCount) do |
|
152 |
with TeamsArray[t]^ do |
|
153 |
begin |
|
154 |
NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font); |
|
690 | 155 |
|
1185 | 156 |
r.w:= cTeamHealthWidth + 5; |
157 |
r.h:= NameTagTex^.h; |
|
690 | 158 |
|
1185 | 159 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
160 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
161 |
TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
690 | 162 |
|
1185 | 163 |
DrawRoundRect(@r, cWhiteColor, cColorNearBlack, texsurf, true); |
164 |
rr:= r; |
|
165 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
|
166 |
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
|
167 |
HealthTex:= Surface2Tex(texsurf, false); |
1185 | 168 |
SDL_FreeSurface(texsurf); |
690 | 169 |
|
1185 | 170 |
dec(drY, r.h + 2); |
171 |
DrawHealthY:= drY; |
|
172 |
for i:= 0 to 7 do |
|
173 |
with Hedgehogs[i] do |
|
174 |
if Gear <> nil then |
|
1242 | 175 |
begin |
1185 | 176 |
NameTagTex:= RenderStringTex(Name, Clan^.Color, fnt16); |
1294
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
177 |
if Hat <> 'NoHat' then |
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
178 |
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
|
179 |
texsurf:= LoadImage(Pathz[ptHats] + '/' + Hat, ifNone); |
1698 | 180 |
if texsurf <> nil then |
181 |
begin |
|
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
|
182 |
HatTex:= Surface2Tex(texsurf, false); |
1698 | 183 |
SDL_FreeSurface(texsurf) |
184 |
end |
|
1294
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
185 |
end |
1242 | 186 |
end; |
1185 | 187 |
end; |
188 |
end; |
|
4 | 189 |
|
1185 | 190 |
procedure MakeCrossHairs; |
191 |
var t: LongInt; |
|
192 |
tmpsurf, texsurf: PSDL_Surface; |
|
193 |
Color, i: Longword; |
|
194 |
begin |
|
195 |
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
|
196 |
tmpsurf:= LoadImage(s, ifAlpha or ifCritical); |
4 | 197 |
|
1185 | 198 |
for t:= 0 to Pred(TeamsCount) do |
199 |
with TeamsArray[t]^ do |
|
200 |
begin |
|
201 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask); |
|
202 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
203 |
|
1185 | 204 |
Color:= Clan^.Color; |
205 |
Color:= SDL_MapRGB(texsurf^.format, Color shr 16, Color shr 8, Color and $FF); |
|
206 |
SDL_FillRect(texsurf, nil, Color); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
207 |
|
1185 | 208 |
SDL_UpperBlit(tmpsurf, nil, texsurf, nil); |
777 | 209 |
|
1185 | 210 |
TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Ooops', true); |
777 | 211 |
|
1185 | 212 |
if SDL_MustLock(texsurf) then |
213 |
SDLTry(SDL_LockSurface(texsurf) >= 0, true); |
|
777 | 214 |
|
1185 | 215 |
// make black pixel be alpha-transparent |
216 |
for i:= 0 to texsurf^.w * texsurf^.h - 1 do |
|
217 |
if PLongwordArray(texsurf^.pixels)^[i] = $FF000000 then PLongwordArray(texsurf^.pixels)^[i]:= 0; |
|
777 | 218 |
|
1185 | 219 |
if SDL_MustLock(texsurf) then |
220 |
SDL_UnlockSurface(texsurf); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
221 |
|
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
|
222 |
CrosshairTex:= Surface2Tex(texsurf, false); |
1185 | 223 |
SDL_FreeSurface(texsurf) |
224 |
end; |
|
351 | 225 |
|
1185 | 226 |
SDL_FreeSurface(tmpsurf) |
227 |
end; |
|
4 | 228 |
|
1185 | 229 |
procedure InitHealth; |
230 |
var i, t: LongInt; |
|
231 |
begin |
|
232 |
for t:= 0 to Pred(TeamsCount) do |
|
233 |
if TeamsArray[t] <> nil then |
|
234 |
with TeamsArray[t]^ do |
|
235 |
begin |
|
236 |
for i:= 0 to cMaxHHIndex do |
|
237 |
if Hedgehogs[i].Gear <> nil then |
|
238 |
RenderHealth(Hedgehogs[i]); |
|
239 |
end |
|
240 |
end; |
|
4 | 241 |
|
1185 | 242 |
procedure LoadGraves; |
243 |
var t: LongInt; |
|
244 |
texsurf: PSDL_Surface; |
|
245 |
begin |
|
246 |
for t:= 0 to Pred(TeamsCount) do |
|
247 |
if TeamsArray[t] <> nil then |
|
248 |
with TeamsArray[t]^ do |
|
249 |
begin |
|
250 |
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
|
251 |
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
|
252 |
GraveTex:= Surface2Tex(texsurf, false); |
1185 | 253 |
SDL_FreeSurface(texsurf) |
254 |
end |
|
255 |
end; |
|
4 | 256 |
|
844 | 257 |
var ii: TSprite; |
258 |
fi: THWFont; |
|
259 |
ai: TAmmoType; |
|
260 |
tmpsurf: PSDL_Surface; |
|
261 |
i: LongInt; |
|
4 | 262 |
begin |
2222 | 263 |
|
4 | 264 |
for fi:= Low(THWFont) to High(THWFont) do |
1185 | 265 |
with Fontz[fi] do |
266 |
begin |
|
267 |
s:= Pathz[ptFonts] + '/' + Name; |
|
268 |
WriteToConsole(msgLoading + s + '... '); |
|
269 |
Handle:= TTF_OpenFont(Str2PChar(s), Height); |
|
270 |
SDLTry(Handle <> nil, true); |
|
271 |
TTF_SetFontStyle(Handle, style); |
|
272 |
WriteLnToConsole(msgOK) |
|
273 |
end; |
|
53 | 274 |
|
4 | 275 |
WriteNames(fnt16); |
70 | 276 |
MakeCrossHairs; |
4 | 277 |
LoadGraves; |
278 |
||
279 |
AddProgress; |
|
280 |
for ii:= Low(TSprite) to High(TSprite) do |
|
1185 | 281 |
with SpritesData[ii] do |
2145 | 282 |
// FIXME - add a sprite attribute |
2426 | 283 |
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
|
284 |
begin |
1185 | 285 |
if AltPath = ptNone then |
2426 | 286 |
if ii in [sprHorizontL, sprHorizontR, sprSkyL, sprSkyR] then // FIXME: hack |
287 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifLowRes) |
|
288 |
else |
|
289 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical or ifLowRes) |
|
1185 | 290 |
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
|
291 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
1185 | 292 |
if tmpsurf = nil then |
2426 | 293 |
tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent); |
1185 | 294 |
end; |
2426 | 295 |
|
296 |
if tmpsurf <> nil then |
|
297 |
begin |
|
298 |
if imageWidth = 0 then imageWidth := tmpsurf^.w; |
|
299 |
if imageHeight = 0 then imageHeight := tmpsurf^.h; |
|
300 |
if Width = 0 then Width:= tmpsurf^.w; |
|
301 |
if Height = 0 then Height:= tmpsurf^.h; |
|
302 |
if (ii = sprSky) then |
|
303 |
Texture:= Surface2Tex(tmpsurf, true) |
|
304 |
else |
|
305 |
Texture:= Surface2Tex(tmpsurf, false); |
|
306 |
if saveSurf then Surface:= tmpsurf else SDL_FreeSurface(tmpsurf) |
|
307 |
end |
|
308 |
else |
|
309 |
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
|
310 |
end; |
80 | 311 |
|
4 | 312 |
AddProgress; |
567 | 313 |
|
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
|
314 |
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
|
315 |
HHTexture:= Surface2Tex(tmpsurf, false); |
761 | 316 |
SDL_FreeSurface(tmpsurf); |
4 | 317 |
|
318 |
InitHealth; |
|
319 |
||
762 | 320 |
PauseTexture:= RenderStringTex(trmsg[sidPaused], $FFFF00, fntBig); |
1023 | 321 |
ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], $FFFF00, fntBig); |
2397
2ca4ca6b4bab
- Patch for "Syncronizing" message by Smaxx + some tweaks by me
unc0rr
parents:
2376
diff
changeset
|
322 |
SyncTexture:= RenderStringTex(trmsg[sidSync], $FFFF00, fntBig); |
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
323 |
|
843 | 324 |
for ai:= Low(TAmmoType) to High(TAmmoType) do |
325 |
with Ammoz[ai] do |
|
326 |
begin |
|
327 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(trAmmo[NameId]), $FFFFFF); |
|
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 |
NameTex:= Surface2Tex(tmpsurf, false); |
843 | 329 |
SDL_FreeSurface(tmpsurf) |
330 |
end; |
|
2376 | 331 |
|
844 | 332 |
for i:= Low(CountTexz) to High(CountTexz) do |
333 |
begin |
|
334 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), $FFFFFF); |
|
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
|
335 |
CountTexz[i]:= Surface2Tex(tmpsurf, false); |
844 | 336 |
SDL_FreeSurface(tmpsurf) |
337 |
end; |
|
338 |
||
4 | 339 |
{$IFDEF DUMP} |
340 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
341 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
342 |
{$ENDIF} |
|
2222 | 343 |
AddProgress; |
4 | 344 |
end; |
345 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
346 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
4 | 347 |
var rr: TSDL_Rect; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
348 |
_l, _r, _t, _b: real; |
1916 | 349 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
4 | 350 |
begin |
2428 | 351 |
if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit; |
4 | 352 |
rr.x:= X; |
353 |
rr.y:= Y; |
|
351 | 354 |
rr.w:= r^.w; |
355 |
rr.h:= r^.h; |
|
755 | 356 |
|
1896 | 357 |
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx; |
358 |
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx; |
|
359 |
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry; |
|
360 |
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry; |
|
755 | 361 |
|
362 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
363 |
||
1916 | 364 |
VertexBuffer[0].X:= X; |
365 |
VertexBuffer[0].Y:= Y; |
|
366 |
VertexBuffer[1].X:= rr.w + X; |
|
367 |
VertexBuffer[1].Y:= Y; |
|
368 |
VertexBuffer[2].X:= rr.w + X; |
|
369 |
VertexBuffer[2].Y:= rr.h + Y; |
|
370 |
VertexBuffer[3].X:= X; |
|
371 |
VertexBuffer[3].Y:= rr.h + Y; |
|
755 | 372 |
|
1916 | 373 |
TextureBuffer[0].X:= _l; |
374 |
TextureBuffer[0].Y:= _t; |
|
375 |
TextureBuffer[1].X:= _r; |
|
376 |
TextureBuffer[1].Y:= _t; |
|
377 |
TextureBuffer[2].X:= _r; |
|
378 |
TextureBuffer[2].Y:= _b; |
|
379 |
TextureBuffer[3].X:= _l; |
|
380 |
TextureBuffer[3].Y:= _b; |
|
755 | 381 |
|
1916 | 382 |
glEnableClientState(GL_VERTEX_ARRAY); |
383 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
755 | 384 |
|
1916 | 385 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
386 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
387 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
388 |
||
389 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
390 |
glDisableClientState(GL_VERTEX_ARRAY) |
|
762 | 391 |
end; |
392 |
||
393 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
|
394 |
begin |
|
1904 | 395 |
glPushMatrix; |
396 |
glTranslatef(X, Y, 0); |
|
397 |
||
762 | 398 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
399 |
||
1904 | 400 |
glEnableClientState(GL_VERTEX_ARRAY); |
401 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
762 | 402 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
403 |
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
|
404 |
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
|
405 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); |
1904 | 406 |
|
407 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
408 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
409 |
||
410 |
glPopMatrix |
|
4 | 411 |
end; |
412 |
||
1251 | 413 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt); |
1242 | 414 |
var ft, fb: GLfloat; |
415 |
hw: LongInt; |
|
1916 | 416 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
1242 | 417 |
begin |
418 |
glPushMatrix; |
|
419 |
glTranslatef(X, Y, 0); |
|
1251 | 420 |
glScalef(Scale, Scale, 1.0); |
1242 | 421 |
|
422 |
if Dir < 0 then |
|
423 |
hw:= - 16 |
|
424 |
else |
|
425 |
hw:= 16; |
|
426 |
||
1896 | 427 |
ft:= Frame / Frames * Texture^.ry; |
428 |
fb:= (Frame + 1) / Frames * Texture^.ry; |
|
1242 | 429 |
|
430 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
431 |
||
1916 | 432 |
VertexBuffer[0].X:= -hw; |
433 |
VertexBuffer[0].Y:= -16; |
|
434 |
VertexBuffer[1].X:= hw; |
|
435 |
VertexBuffer[1].Y:= -16; |
|
436 |
VertexBuffer[2].X:= hw; |
|
437 |
VertexBuffer[2].Y:= 16; |
|
438 |
VertexBuffer[3].X:= -hw; |
|
439 |
VertexBuffer[3].Y:= 16; |
|
1242 | 440 |
|
1916 | 441 |
TextureBuffer[0].X:= 0; |
442 |
TextureBuffer[0].Y:= ft; |
|
443 |
TextureBuffer[1].X:= Texture^.rx; |
|
444 |
TextureBuffer[1].Y:= ft; |
|
445 |
TextureBuffer[2].X:= Texture^.rx; |
|
446 |
TextureBuffer[2].Y:= fb; |
|
447 |
TextureBuffer[3].X:= 0; |
|
448 |
TextureBuffer[3].Y:= fb; |
|
1242 | 449 |
|
1916 | 450 |
glEnableClientState(GL_VERTEX_ARRAY); |
451 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
1242 | 452 |
|
1916 | 453 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
454 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
455 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
456 |
||
457 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
458 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
459 |
||
1242 | 460 |
|
461 |
glPopMatrix |
|
462 |
end; |
|
463 |
||
822 | 464 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
775 | 465 |
begin |
777 | 466 |
DrawRotatedTex(SpritesData[Sprite].Texture, |
822 | 467 |
SpritesData[Sprite].Width, |
468 |
SpritesData[Sprite].Height, |
|
469 |
X, Y, Dir, Angle) |
|
777 | 470 |
end; |
471 |
||
853 | 472 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
806 | 473 |
begin |
474 |
glPushMatrix; |
|
809 | 475 |
glTranslatef(X, Y, 0); |
806 | 476 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
477 |
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
|
478 |
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
|
479 |
else |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
480 |
glRotatef(Angle, 0, 0, 1); |
853 | 481 |
if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
482 |
||
483 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
806 | 484 |
|
485 |
glPopMatrix |
|
486 |
end; |
|
487 |
||
822 | 488 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
1916 | 489 |
var VertexBuffer: array [0..3] of TVertex2f; |
777 | 490 |
begin |
775 | 491 |
glPushMatrix; |
492 |
glTranslatef(X, Y, 0); |
|
822 | 493 |
|
494 |
if Dir < 0 then |
|
495 |
begin |
|
496 |
hw:= - hw; |
|
497 |
glRotatef(Angle, 0, 0, -1); |
|
498 |
end else |
|
499 |
glRotatef(Angle, 0, 0, 1); |
|
500 |
||
775 | 501 |
|
777 | 502 |
glBindTexture(GL_TEXTURE_2D, Tex^.id); |
775 | 503 |
|
1916 | 504 |
VertexBuffer[0].X:= -hw; |
505 |
VertexBuffer[0].Y:= -hh; |
|
506 |
VertexBuffer[1].X:= hw; |
|
507 |
VertexBuffer[1].Y:= -hh; |
|
508 |
VertexBuffer[2].X:= hw; |
|
509 |
VertexBuffer[2].Y:= hh; |
|
510 |
VertexBuffer[3].X:= -hw; |
|
511 |
VertexBuffer[3].Y:= hh; |
|
775 | 512 |
|
1916 | 513 |
glEnableClientState(GL_VERTEX_ARRAY); |
514 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
775 | 515 |
|
1916 | 516 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
517 |
glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb); |
|
518 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
775 | 519 |
|
1916 | 520 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
521 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
775 | 522 |
|
523 |
glPopMatrix |
|
524 |
end; |
|
525 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
526 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
4 | 527 |
begin |
528 |
r.y:= r.y + Height * Position; |
|
529 |
r.h:= Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
530 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 531 |
end; |
532 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
533 |
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
|
534 |
var row, col, numFramesFirstCol: LongInt; |
4 | 535 |
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
|
536 |
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
|
537 |
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
|
538 |
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
|
539 |
DrawSprite2 (Sprite, X, Y, col, row); |
4 | 540 |
end; |
541 |
||
1939 | 542 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
543 |
var r: TSDL_Rect; |
|
544 |
begin |
|
545 |
r.x:= 0; |
|
546 |
r.y:= 0; |
|
547 |
r.w:= SpritesData[Sprite].Width; |
|
548 |
r.h:= SpritesData[Sprite].Height; |
|
549 |
||
550 |
if (X < LeftX) then |
|
551 |
r.x:= LeftX - X; |
|
552 |
if (Y < TopY) then |
|
553 |
r.y:= TopY - Y; |
|
554 |
||
555 |
if (Y + SpritesData[Sprite].Height > BottomY) then |
|
556 |
r.h:= BottomY - Y + 1; |
|
557 |
if (X + SpritesData[Sprite].Width > RightX) then |
|
558 |
r.w:= RightX - X + 1; |
|
559 |
||
560 |
dec(r.h, r.y); |
|
561 |
dec(r.w, r.x); |
|
2230
d6963f72d21a
once again, trying to restore windows compatibility from nemo's experiments
koda
parents:
2229
diff
changeset
|
562 |
|
1939 | 563 |
DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture) |
564 |
end; |
|
565 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
566 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
43 | 567 |
var r: TSDL_Rect; |
568 |
begin |
|
569 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
570 |
r.w:= SpritesData[Sprite].Width; |
|
571 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
572 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
573 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
43 | 574 |
end; |
575 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
576 |
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
|
577 |
var r: TSDL_Rect; |
198 | 578 |
begin |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
579 |
r.x:= 0; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
580 |
r.w:= Source^.w; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
581 |
r.y:= Frame * Height; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
582 |
r.h:= Height; |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
583 |
DrawFromRect(X, Y, @r, Source) |
198 | 584 |
end; |
585 |
||
762 | 586 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
95 | 587 |
begin |
762 | 588 |
DrawTexture(X - Source^.w div 2, Top, Source) |
4 | 589 |
end; |
590 |
||
1865
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1854
diff
changeset
|
591 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1916 | 592 |
const VertexBuffer: array [0..3] of TVertex2f = ( |
593 |
(x: -16; y: -16), |
|
594 |
(x: 16; y: -16), |
|
595 |
(x: 16; y: 16), |
|
596 |
(x: -16; y: 16)); |
|
761 | 597 |
var l, r, t, b: real; |
1916 | 598 |
TextureBuffer: array [0..3] of TVertex2f; |
4 | 599 |
begin |
761 | 600 |
|
601 |
t:= Pos * 32 / HHTexture^.h; |
|
602 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
603 |
||
604 |
if Dir = -1 then |
|
605 |
begin |
|
606 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
607 |
r:= Step * 32 / HHTexture^.w |
|
608 |
end else |
|
609 |
begin |
|
610 |
l:= Step * 32 / HHTexture^.w; |
|
611 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
612 |
end; |
|
613 |
||
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
614 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
615 |
glPushMatrix(); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
616 |
glTranslatef(X, Y, 0); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
617 |
glRotatef(Angle, 0, 0, 1); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
618 |
|
761 | 619 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
620 |
||
1916 | 621 |
TextureBuffer[0].X:= l; |
622 |
TextureBuffer[0].Y:= t; |
|
623 |
TextureBuffer[1].X:= r; |
|
624 |
TextureBuffer[1].Y:= t; |
|
625 |
TextureBuffer[2].X:= r; |
|
626 |
TextureBuffer[2].Y:= b; |
|
627 |
TextureBuffer[3].X:= l; |
|
628 |
TextureBuffer[3].Y:= b; |
|
761 | 629 |
|
1916 | 630 |
glEnableClientState(GL_VERTEX_ARRAY); |
631 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
761 | 632 |
|
1916 | 633 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
634 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
635 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
761 | 636 |
|
1916 | 637 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
638 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
761 | 639 |
|
1854 | 640 |
|
641 |
glColor4f(1,1,1,1); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
642 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
643 |
glPopMatrix |
4 | 644 |
end; |
645 |
||
1431 | 646 |
procedure DrawFillRect(r: TSDL_Rect); |
1916 | 647 |
var VertexBuffer: array [0..3] of TVertex2f; |
1431 | 648 |
begin |
649 |
glDisable(GL_TEXTURE_2D); |
|
650 |
||
651 |
glColor4ub(0, 0, 0, 127); |
|
652 |
||
1916 | 653 |
VertexBuffer[0].X:= r.x; |
654 |
VertexBuffer[0].Y:= r.y; |
|
655 |
VertexBuffer[1].X:= r.x + r.w; |
|
656 |
VertexBuffer[1].Y:= r.y; |
|
657 |
VertexBuffer[2].X:= r.x + r.w; |
|
658 |
VertexBuffer[2].Y:= r.y + r.h; |
|
659 |
VertexBuffer[3].X:= r.x; |
|
660 |
VertexBuffer[3].Y:= r.y + r.h; |
|
1431 | 661 |
|
1916 | 662 |
glEnableClientState(GL_VERTEX_ARRAY); |
663 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
664 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
665 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
1431 | 666 |
|
667 |
glColor4f(1, 1, 1, 1); |
|
668 |
glEnable(GL_TEXTURE_2D) |
|
669 |
end; |
|
670 |
||
4 | 671 |
procedure StoreRelease; |
672 |
var ii: TSprite; |
|
673 |
begin |
|
674 |
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
|
675 |
begin |
759 | 676 |
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
|
677 |
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
|
678 |
end; |
761 | 679 |
|
1806 | 680 |
FreeTexture(HHTexture) |
4 | 681 |
end; |
682 |
||
762 | 683 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
432 | 684 |
var w, h: LongInt; |
351 | 685 |
Result: PSDL_Surface; |
95 | 686 |
begin |
1989 | 687 |
if length(s) = 0 then s:= ' '; |
355 | 688 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
785 | 689 |
|
762 | 690 |
Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
691 |
32, RMask, GMask, BMask, AMask); |
|
785 | 692 |
|
107 | 693 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
785 | 694 |
|
95 | 695 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
785 | 696 |
|
762 | 697 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
785 | 698 |
|
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
|
699 |
RenderStringTex:= Surface2Tex(Result, false); |
785 | 700 |
|
762 | 701 |
SDL_FreeSurface(Result) |
95 | 702 |
end; |
703 |
||
2017 | 704 |
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
|
705 |
var textWidth, textHeight, x, y, w, h, i, j, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt; |
2017 | 706 |
Result, tmpsurf, rotatedEdge: PSDL_Surface; |
707 |
rect: TSDL_Rect; |
|
708 |
chars: TSysCharSet = [#9,' ','.',';',':','?','!',',']; |
|
709 |
substr: shortstring; |
|
710 |
edge, corner, tail: TSPrite; |
|
711 |
begin |
|
712 |
||
713 |
case SpeechType of |
|
2376 | 714 |
1: begin; |
715 |
edge:= sprSpeechEdge; |
|
2017 | 716 |
corner:= sprSpeechCorner; |
717 |
tail:= sprSpeechTail; |
|
718 |
end; |
|
2376 | 719 |
2: begin; |
2017 | 720 |
edge:= sprThoughtEdge; |
2376 | 721 |
corner:= sprThoughtCorner; |
2017 | 722 |
tail:= sprThoughtTail; |
723 |
end; |
|
2376 | 724 |
3: begin; |
2017 | 725 |
edge:= sprShoutEdge; |
726 |
corner:= sprShoutCorner; |
|
727 |
tail:= sprShoutTail; |
|
728 |
end; |
|
729 |
end; |
|
730 |
edgeHeight:= SpritesData[edge].Height; |
|
731 |
edgeWidth:= SpritesData[edge].Width; |
|
732 |
cornerWidth:= SpritesData[corner].Width; |
|
733 |
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
|
734 |
// This one screws up WrapText |
2022 | 735 |
//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
|
736 |
// 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
|
737 |
//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
|
738 |
|
2022 | 739 |
numLines:= 0; |
2017 | 740 |
|
741 |
if length(s) = 0 then s:= '...'; |
|
742 |
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
|
743 |
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
|
744 |
j:= 0; |
2017 | 745 |
if (length(s) > 20) then |
746 |
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
|
747 |
w:= 0; |
2017 | 748 |
i:= round(Sqrt(length(s)) * 2); |
749 |
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
|
750 |
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
|
751 |
// 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
|
752 |
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
|
753 |
begin |
2017 | 754 |
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
|
755 |
begin |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
756 |
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
|
757 |
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
|
758 |
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
|
759 |
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
|
760 |
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
|
761 |
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
|
762 |
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
|
763 |
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
|
764 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
765 |
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
|
766 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
767 |
end |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
768 |
else numLines := 1; |
2017 | 769 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
770 |
textWidth:=((w-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth; |
2022 | 771 |
textHeight:=(((numlines * h + 2)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth; |
2019 | 772 |
|
2022 | 773 |
textHeight:=max(textHeight,edgeWidth); |
2017 | 774 |
//textWidth:=max(textWidth,SpritesData[tail].Width); |
775 |
rect.x:= 0; |
|
776 |
rect.y:= 0; |
|
2022 | 777 |
rect.w:= textWidth + (cornerWidth * 2); |
778 |
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
|
779 |
//s:= inttostr(w) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h); |
2017 | 780 |
|
781 |
Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask); |
|
782 |
||
783 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
|
784 |
||
785 |
//////////////////////////////// CORNERS /////////////////////////////// |
|
786 |
copyToXY(SpritesData[corner].Surface, Result, 0, 0); /////////////////// NW |
|
787 |
||
788 |
flipSurface(SpritesData[corner].Surface, true); // store all 4 versions in memory to avoid repeated flips? |
|
789 |
x:= 0; |
|
790 |
y:= textHeight + cornerHeight -1; |
|
791 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// SW |
|
792 |
||
793 |
flipSurface(SpritesData[corner].Surface, false); |
|
794 |
x:= rect.w-cornerWidth-1; |
|
795 |
y:= textHeight + cornerHeight -1; |
|
796 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// SE |
|
797 |
||
798 |
flipSurface(SpritesData[corner].Surface, true); |
|
799 |
x:= rect.w-cornerWidth-1; |
|
800 |
y:= 0; |
|
801 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// NE |
|
802 |
flipSurface(SpritesData[corner].Surface, false); // restore original position |
|
803 |
//////////////////////////////// END CORNERS /////////////////////////////// |
|
804 |
||
805 |
//////////////////////////////// EDGES ////////////////////////////////////// |
|
806 |
x:= cornerWidth; |
|
807 |
y:= 0; |
|
808 |
while x < rect.w-cornerWidth-1 do |
|
809 |
begin |
|
810 |
copyToXY(SpritesData[edge].Surface, Result, x, y); ///////////////// top edge |
|
811 |
inc(x,edgeWidth); |
|
812 |
end; |
|
813 |
flipSurface(SpritesData[edge].Surface, true); |
|
814 |
x:= cornerWidth; |
|
815 |
y:= textHeight + cornerHeight*2 - edgeHeight-1; |
|
816 |
while x < rect.w-cornerWidth-1 do |
|
817 |
begin |
|
818 |
copyToXY(SpritesData[edge].Surface, Result, x, y); ///////////////// bottom edge |
|
819 |
inc(x,edgeWidth); |
|
820 |
end; |
|
821 |
flipSurface(SpritesData[edge].Surface, true); // restore original position |
|
822 |
||
823 |
rotatedEdge:= SDL_CreateRGBSurface(SDL_SWSURFACE, edgeHeight, edgeWidth, 32, RMask, GMask, BMask, AMask); |
|
824 |
x:= rect.w - edgeHeight - 1; |
|
825 |
y:= cornerHeight; |
|
826 |
//// initially was going to rotate in place, but the SDL spec claims width/height are read only |
|
827 |
copyRotatedSurface(SpritesData[edge].Surface,rotatedEdge); |
|
828 |
while y < textHeight + cornerHeight do |
|
829 |
begin |
|
830 |
copyToXY(rotatedEdge, Result, x, y); |
|
831 |
inc(y,edgeWidth); |
|
832 |
end; |
|
833 |
flipSurface(rotatedEdge, false); // restore original position |
|
834 |
x:= 0; |
|
835 |
y:= cornerHeight; |
|
836 |
while y < textHeight + cornerHeight do |
|
837 |
begin |
|
838 |
copyToXY(rotatedEdge, Result, x, y); |
|
839 |
inc(y,edgeWidth); |
|
840 |
end; |
|
841 |
//////////////////////////////// END EDGES ////////////////////////////////////// |
|
842 |
||
843 |
x:= cornerWidth; |
|
844 |
y:= textHeight + cornerHeight * 2 - edgeHeight - 1; |
|
845 |
copyToXY(SpritesData[tail].Surface, Result, x, y); |
|
846 |
||
847 |
rect.x:= edgeHeight; |
|
848 |
rect.y:= edgeHeight; |
|
849 |
rect.w:= rect.w - edgeHeight * 2; |
|
850 |
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
|
851 |
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
|
852 |
j:= rect.h; |
2017 | 853 |
SDL_FillRect(Result, @rect, cWhiteColor); |
854 |
||
855 |
pos:= 1; prevpos:= 0; line:= 0; |
|
856 |
while pos <= length(s) do |
|
857 |
begin |
|
858 |
if (s[pos] = #1) or (pos = length(s)) then |
|
859 |
begin |
|
860 |
if s[pos] <> #1 then inc(pos); |
|
861 |
while s[prevpos+1] = ' 'do inc(prevpos); |
|
862 |
substr:= copy(s, prevpos+1, pos-prevpos-1); |
|
863 |
if Length(substr) <> 0 then |
|
864 |
begin |
|
865 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cColorNearBlack); |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
866 |
rect.x:= edgeHeight + 1 + ((i - w) div 2); |
2022 | 867 |
// 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
|
868 |
rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h; |
2017 | 869 |
SDLTry(tmpsurf <> nil, true); |
870 |
SDL_UpperBlit(tmpsurf, nil, Result, @rect); |
|
871 |
SDL_FreeSurface(tmpsurf); |
|
872 |
inc(line); |
|
873 |
prevpos:= pos; |
|
874 |
end; |
|
875 |
end; |
|
876 |
inc(pos); |
|
877 |
end; |
|
878 |
||
879 |
//TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
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
|
880 |
RenderSpeechBubbleTex:= Surface2Tex(Result, false); |
2017 | 881 |
|
882 |
SDL_FreeSurface(rotatedEdge); |
|
883 |
SDL_FreeSurface(Result) |
|
884 |
end; |
|
885 |
||
4 | 886 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 887 |
var s: shortstring; |
4 | 888 |
begin |
351 | 889 |
str(Hedgehog.Gear^.Health, s); |
762 | 890 |
if Hedgehog.HealthTagTex <> nil then FreeTexture(Hedgehog.HealthTagTex); |
891 |
Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
|
4 | 892 |
end; |
893 |
||
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
|
894 |
function LoadImage(const filename: string; imageFlags: Integer): PSDL_Surface; |
30 | 895 |
var tmpsurf: PSDL_Surface; |
355 | 896 |
s: shortstring; |
2248
26e11cb27c61
real fix for iphone color (reverting previous commit)
koda
parents:
2244
diff
changeset
|
897 |
{$IFDEF IPHONEOS} |
26e11cb27c61
real fix for iphone color (reverting previous commit)
koda
parents:
2244
diff
changeset
|
898 |
convertedSurf: PSDL_Surface; |
26e11cb27c61
real fix for iphone color (reverting previous commit)
koda
parents:
2244
diff
changeset
|
899 |
const TestFormat: TSDL_PixelFormat = ( |
2376 | 900 |
palette: nil; |
2248
26e11cb27c61
real fix for iphone color (reverting previous commit)
koda
parents:
2244
diff
changeset
|
901 |
BitsPerPixel : 32; |
26e11cb27c61
real fix for iphone color (reverting previous commit)
koda
parents:
2244
diff
changeset
|
902 |
BytesPerPixel: 4; |
2376 | 903 |
Rloss : 0; |
904 |
Gloss : 0; |
|
905 |
Bloss : 0; |
|
906 |
Aloss : 0; |
|
907 |
Rshift: 0; |
|
908 |
Gshift: 8; |
|
909 |
Bshift: 16; |
|
910 |
Ashift: 24; |
|
911 |
RMask : $000000FF; |
|
912 |
GMask : $0000FF00; |
|
913 |
BMask : $00FF0000; |
|
914 |
AMask : $FF000000; |
|
2248
26e11cb27c61
real fix for iphone color (reverting previous commit)
koda
parents:
2244
diff
changeset
|
915 |
colorkey: 0; |
2376 | 916 |
alpha : 255); |
2248
26e11cb27c61
real fix for iphone color (reverting previous commit)
koda
parents:
2244
diff
changeset
|
917 |
{$ENDIF} |
4 | 918 |
begin |
919 |
WriteToConsole(msgLoading + filename + '... '); |
|
2426 | 920 |
|
921 |
s:= filename + '.png'; |
|
355 | 922 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
2254 | 923 |
|
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
|
924 |
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
|
925 |
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
|
926 |
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
|
927 |
if (tmpsurf <> nil) then |
2376 | 928 |
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
|
929 |
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
|
930 |
begin |
2426 | 931 |
SDL_FreeSurface(tmpsurf); |
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
|
932 |
WriteLnToConsole('Image too big, trying to load lowres version: ' + 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
|
933 |
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
|
934 |
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
|
935 |
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
|
936 |
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
|
937 |
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
|
938 |
WriteLnToConsole('Image not found, trying to load lowres version: ' + 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
|
939 |
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
|
940 |
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
|
941 |
end; |
2376 | 942 |
|
80 | 943 |
if tmpsurf = nil then |
2153 | 944 |
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
|
945 |
OutError(msgFailed, (imageFlags and ifCritical) <> 0); |
2153 | 946 |
exit(nil) |
947 |
end; |
|
948 |
||
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
|
949 |
if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
2153 | 950 |
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
|
951 |
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
|
952 |
OutError(msgFailedSize, (imageFlags and ifCritical) <> 0); |
2248
26e11cb27c61
real fix for iphone color (reverting previous commit)
koda
parents:
2244
diff
changeset
|
953 |
//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
|
954 |
exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask)); |
2153 | 955 |
end; |
351 | 956 |
|
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
|
957 |
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
|
958 |
//if (imageFlags and ifAlpha) <> 0 then Result:= SDL_DisplayFormatAlpha(tmpsurf) else Result:= SDL_DisplayFormat(tmpsurf); |
2153 | 959 |
WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') '); |
351 | 960 |
WriteLnToConsole(msgOK); |
2153 | 961 |
|
2248
26e11cb27c61
real fix for iphone color (reverting previous commit)
koda
parents:
2244
diff
changeset
|
962 |
{$IFDEF IPHONEOS} |
26e11cb27c61
real fix for iphone color (reverting previous commit)
koda
parents:
2244
diff
changeset
|
963 |
//for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7 |
26e11cb27c61
real fix for iphone color (reverting previous commit)
koda
parents:
2244
diff
changeset
|
964 |
convertedSurf:= SDL_ConvertSurface(tmpsurf, @TestFormat, SDL_SWSURFACE); |
26e11cb27c61
real fix for iphone color (reverting previous commit)
koda
parents:
2244
diff
changeset
|
965 |
tmpsurf:= convertedSurf; |
26e11cb27c61
real fix for iphone color (reverting previous commit)
koda
parents:
2244
diff
changeset
|
966 |
{$ENDIF} |
26e11cb27c61
real fix for iphone color (reverting previous commit)
koda
parents:
2244
diff
changeset
|
967 |
|
2153 | 968 |
LoadImage:= tmpsurf //Result |
753 | 969 |
end; |
970 |
||
2428 | 971 |
function glLoadExtension(extension : string) : boolean; |
972 |
begin |
|
973 |
glLoadExtension:= glext_LoadExtension(extension); |
|
974 |
if not glLoadExtension then |
|
975 |
WriteLnToConsole('OpenGL: "' + extension + '" failed to load') |
|
976 |
else |
|
977 |
WriteLnToConsole('OpenGL: "' + extension + '" loaded'); |
|
978 |
end; |
|
979 |
||
753 | 980 |
procedure SetupOpenGL; |
981 |
begin |
|
2153 | 982 |
glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize); |
983 |
{$IFDEF DEBUGFILE} |
|
984 |
AddFileLog('GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize)); |
|
985 |
{$ENDIF} |
|
2252 | 986 |
|
2428 | 987 |
{$IFNDEF GLES11} |
988 |
SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two'); |
|
989 |
{$ENDIF} |
|
990 |
||
991 |
// set view port to whole window |
|
992 |
glViewport(0, 0, cScreenWidth, cScreenHeight); |
|
993 |
||
994 |
glMatrixMode(GL_MODELVIEW); |
|
995 |
// prepare default translation/scaling |
|
996 |
glLoadIdentity; |
|
997 |
glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
|
998 |
glTranslatef(0, -cScreenHeight / 2, 0); |
|
999 |
||
1000 |
// enable alpha blending |
|
1001 |
glEnable(GL_BLEND); |
|
1002 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
4 | 1003 |
end; |
1004 |
||
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1005 |
procedure SetScale(f: GLfloat); |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1006 |
begin |
2428 | 1007 |
// leave immediately if scale factor didn't change |
1008 |
if f = cScaleFactor then exit; |
|
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1009 |
|
2428 | 1010 |
if f = 2.0 then // default scaling |
1011 |
glPopMatrix // "return" to default scaling |
|
1012 |
else // other scaling |
|
1013 |
begin |
|
1014 |
glPushMatrix; // save default scaling |
|
1015 |
glLoadIdentity; |
|
1016 |
glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0); |
|
1017 |
glTranslatef(0, -cScreenHeight / 2, 0); |
|
1018 |
end; |
|
2258 | 1019 |
|
2428 | 1020 |
cScaleFactor:= f; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1021 |
end; |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1022 |
|
510 | 1023 |
//////////////////////////////////////////////////////////////////////////////// |
766 | 1024 |
var ProgrTex: PTexture = nil; |
534 | 1025 |
Step: integer = 0; |
2222 | 1026 |
squaresize : LongInt; |
1027 |
numsquares : integer; |
|
2284 | 1028 |
|
510 | 1029 |
procedure AddProgress; |
1030 |
var r: TSDL_Rect; |
|
766 | 1031 |
texsurf: PSDL_Surface; |
510 | 1032 |
begin |
1033 |
if Step = 0 then |
|
1034 |
begin |
|
1035 |
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
|
1036 |
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
|
1037 |
ProgrTex:= Surface2Tex(texsurf, false); |
2222 | 1038 |
SDL_FreeSurface(texsurf); |
1039 |
squaresize:= ProgrTex^.w shr 1; |
|
1040 |
numsquares:= ProgrTex^.h div squaresize; |
|
510 | 1041 |
end; |
1045 | 1042 |
|
2284 | 1043 |
TryDo(ProgrTex <> nil, 'ProgrTex = nil!', true); |
1044 |
||
766 | 1045 |
glClear(GL_COLOR_BUFFER_BIT); |
775 | 1046 |
glEnable(GL_TEXTURE_2D); |
2222 | 1047 |
if Step < numsquares then r.x:= 0 |
1048 |
else r.x:= squaresize; |
|
1049 |
r.y:= (Step mod numsquares) * squaresize; |
|
1050 |
r.w:= squaresize; |
|
1051 |
r.h:= squaresize; |
|
1052 |
DrawFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex); |
|
775 | 1053 |
glDisable(GL_TEXTURE_2D); |
766 | 1054 |
SDL_GL_SwapBuffers(); |
510 | 1055 |
inc(Step); |
1056 |
end; |
|
1057 |
||
2222 | 1058 |
|
510 | 1059 |
procedure FinishProgress; |
1060 |
begin |
|
1061 |
WriteLnToConsole('Freeing progress surface... '); |
|
2284 | 1062 |
FreeTexture(ProgrTex); |
1063 |
ProgrTex:= nil |
|
510 | 1064 |
end; |
1065 |
||
2017 | 1066 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
1067 |
var y, x, i, j: LongInt; |
|
1068 |
tmpPixel: Longword; |
|
1069 |
pixels: PLongWordArray; |
|
1070 |
begin |
|
1071 |
TryDo(Surface^.format^.BytesPerPixel = 4, 'flipSurface failed, expecting 32 bit surface', true); |
|
1072 |
pixels:= Surface^.pixels; |
|
1073 |
if Vertical then |
|
1074 |
for y := 0 to (Surface^.h div 2) - 1 do |
|
1075 |
for x := 0 to Surface^.w - 1 do |
|
1076 |
begin |
|
1077 |
i:= y * Surface^.w + x; |
|
1078 |
j:= (Surface^.h - y - 1) * Surface^.w + x; |
|
1079 |
tmpPixel:= pixels^[i]; |
|
1080 |
pixels^[i]:= pixels^[j]; |
|
1081 |
pixels^[j]:= tmpPixel; |
|
1082 |
end |
|
1083 |
else |
|
1084 |
for x := 0 to (Surface^.w div 2) - 1 do |
|
1085 |
for y := 0 to Surface^.h -1 do |
|
1086 |
begin |
|
1087 |
i:= y*Surface^.w + x; |
|
1088 |
j:= y*Surface^.w + (Surface^.w - x - 1); |
|
1089 |
tmpPixel:= pixels^[i]; |
|
1090 |
pixels^[i]:= pixels^[j]; |
|
1091 |
pixels^[j]:= tmpPixel; |
|
1092 |
end; |
|
1093 |
end; |
|
1094 |
||
1095 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer); |
|
1096 |
var srcX, srcY, i, j, maxDest: LongInt; |
|
1097 |
srcPixels, destPixels: PLongWordArray; |
|
1098 |
begin |
|
1099 |
maxDest:= (dest^.pitch div 4) * dest^.h; |
|
1100 |
srcPixels:= src^.pixels; |
|
1101 |
destPixels:= dest^.pixels; |
|
1102 |
||
1103 |
for srcX:= 0 to src^.w - 1 do |
|
1104 |
for srcY:= 0 to src^.h - 1 do |
|
1105 |
begin |
|
1106 |
i:= (destY + srcY) * (dest^.pitch div 4) + destX + srcX; |
|
1107 |
j:= srcY * (src^.pitch div 4) + srcX; |
|
1108 |
// basic skip of transparent pixels - cleverness would be to do true alpha |
|
1109 |
if (i < maxDest) and ($FF000000 and srcPixels^[j] <> 0) then destPixels^[i]:= srcPixels^[j]; |
|
1110 |
end; |
|
1111 |
end; |
|
1112 |
||
1113 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently |
|
1114 |
var y, x, i, j: LongInt; |
|
1115 |
srcPixels, destPixels: PLongWordArray; |
|
1116 |
begin |
|
1117 |
TryDo(src^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
1118 |
TryDo(dest^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
1119 |
||
1120 |
srcPixels:= src^.pixels; |
|
1121 |
destPixels:= dest^.pixels; |
|
1122 |
||
1123 |
j:= 0; |
|
1124 |
for x := 0 to src^.w - 1 do |
|
1125 |
for y := 0 to src^.h - 1 do |
|
1126 |
begin |
|
1127 |
i:= (src^.h - 1 - y) * (src^.pitch div 4) + x; |
|
1128 |
destPixels^[j]:= srcPixels^[i]; |
|
1129 |
inc(j) |
|
1130 |
end; |
|
1131 |
end; |
|
1132 |
||
4 | 1133 |
end. |