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