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