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