author | nemo |
Mon, 15 Jun 2009 21:03:57 +0000 | |
changeset 2167 | 4e9ad395c1d1 |
parent 2161 | 0c8634241fa4 |
child 2171 | 8208946331ba |
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; |
518 | 56 |
function LoadImage(const filename: string; hasAlpha, critical, setTransparent: boolean): 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 |
1698 | 177 |
texsurf:= LoadImage(Pathz[ptHats] + '/' + Hat, false, false, false); |
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; |
|
194 |
tmpsurf:= LoadImage(s, true, true, false); |
|
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'; |
|
249 |
texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, false, true, true); |
|
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 |
261 |
for fi:= Low(THWFont) to High(THWFont) do |
|
1185 | 262 |
with Fontz[fi] do |
263 |
begin |
|
264 |
s:= Pathz[ptFonts] + '/' + Name; |
|
265 |
WriteToConsole(msgLoading + s + '... '); |
|
266 |
Handle:= TTF_OpenFont(Str2PChar(s), Height); |
|
267 |
SDLTry(Handle <> nil, true); |
|
268 |
TTF_SetFontStyle(Handle, style); |
|
269 |
WriteLnToConsole(msgOK) |
|
270 |
end; |
|
4 | 271 |
AddProgress; |
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 |
|
285 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, true, true, true) |
|
286 |
else begin |
|
287 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, true, false, true); |
|
288 |
if tmpsurf = nil then |
|
289 |
tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, true, true, true) |
|
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 |
|
761 | 299 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, true, true, true); |
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; |
|
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} |
|
327 |
end; |
|
328 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
329 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
4 | 330 |
var rr: TSDL_Rect; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
331 |
_l, _r, _t, _b: real; |
1916 | 332 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
4 | 333 |
begin |
759 | 334 |
if SourceTexture^.h = 0 then exit; |
4 | 335 |
rr.x:= X; |
336 |
rr.y:= Y; |
|
351 | 337 |
rr.w:= r^.w; |
338 |
rr.h:= r^.h; |
|
755 | 339 |
|
1896 | 340 |
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx; |
341 |
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx; |
|
342 |
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry; |
|
343 |
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry; |
|
755 | 344 |
|
345 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
346 |
||
1916 | 347 |
VertexBuffer[0].X:= X; |
348 |
VertexBuffer[0].Y:= Y; |
|
349 |
VertexBuffer[1].X:= rr.w + X; |
|
350 |
VertexBuffer[1].Y:= Y; |
|
351 |
VertexBuffer[2].X:= rr.w + X; |
|
352 |
VertexBuffer[2].Y:= rr.h + Y; |
|
353 |
VertexBuffer[3].X:= X; |
|
354 |
VertexBuffer[3].Y:= rr.h + Y; |
|
755 | 355 |
|
1916 | 356 |
TextureBuffer[0].X:= _l; |
357 |
TextureBuffer[0].Y:= _t; |
|
358 |
TextureBuffer[1].X:= _r; |
|
359 |
TextureBuffer[1].Y:= _t; |
|
360 |
TextureBuffer[2].X:= _r; |
|
361 |
TextureBuffer[2].Y:= _b; |
|
362 |
TextureBuffer[3].X:= _l; |
|
363 |
TextureBuffer[3].Y:= _b; |
|
755 | 364 |
|
1916 | 365 |
glEnableClientState(GL_VERTEX_ARRAY); |
366 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
755 | 367 |
|
1916 | 368 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
369 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
370 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
371 |
||
372 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
373 |
glDisableClientState(GL_VERTEX_ARRAY) |
|
762 | 374 |
end; |
375 |
||
376 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
|
377 |
begin |
|
1904 | 378 |
glPushMatrix; |
379 |
glTranslatef(X, Y, 0); |
|
380 |
||
762 | 381 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
382 |
||
1904 | 383 |
glEnableClientState(GL_VERTEX_ARRAY); |
384 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
762 | 385 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
386 |
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
|
387 |
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
|
388 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); |
1904 | 389 |
|
390 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
391 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
392 |
||
393 |
glPopMatrix |
|
4 | 394 |
end; |
395 |
||
1251 | 396 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt); |
1242 | 397 |
var ft, fb: GLfloat; |
398 |
hw: LongInt; |
|
1916 | 399 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
1242 | 400 |
begin |
401 |
glPushMatrix; |
|
402 |
glTranslatef(X, Y, 0); |
|
1251 | 403 |
glScalef(Scale, Scale, 1.0); |
1242 | 404 |
|
405 |
if Dir < 0 then |
|
406 |
hw:= - 16 |
|
407 |
else |
|
408 |
hw:= 16; |
|
409 |
||
1896 | 410 |
ft:= Frame / Frames * Texture^.ry; |
411 |
fb:= (Frame + 1) / Frames * Texture^.ry; |
|
1242 | 412 |
|
413 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
414 |
||
1916 | 415 |
VertexBuffer[0].X:= -hw; |
416 |
VertexBuffer[0].Y:= -16; |
|
417 |
VertexBuffer[1].X:= hw; |
|
418 |
VertexBuffer[1].Y:= -16; |
|
419 |
VertexBuffer[2].X:= hw; |
|
420 |
VertexBuffer[2].Y:= 16; |
|
421 |
VertexBuffer[3].X:= -hw; |
|
422 |
VertexBuffer[3].Y:= 16; |
|
1242 | 423 |
|
1916 | 424 |
TextureBuffer[0].X:= 0; |
425 |
TextureBuffer[0].Y:= ft; |
|
426 |
TextureBuffer[1].X:= Texture^.rx; |
|
427 |
TextureBuffer[1].Y:= ft; |
|
428 |
TextureBuffer[2].X:= Texture^.rx; |
|
429 |
TextureBuffer[2].Y:= fb; |
|
430 |
TextureBuffer[3].X:= 0; |
|
431 |
TextureBuffer[3].Y:= fb; |
|
1242 | 432 |
|
1916 | 433 |
glEnableClientState(GL_VERTEX_ARRAY); |
434 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
1242 | 435 |
|
1916 | 436 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
437 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
438 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
439 |
||
440 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
441 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
442 |
||
1242 | 443 |
|
444 |
glPopMatrix |
|
445 |
end; |
|
446 |
||
822 | 447 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
775 | 448 |
begin |
777 | 449 |
DrawRotatedTex(SpritesData[Sprite].Texture, |
822 | 450 |
SpritesData[Sprite].Width, |
451 |
SpritesData[Sprite].Height, |
|
452 |
X, Y, Dir, Angle) |
|
777 | 453 |
end; |
454 |
||
853 | 455 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
806 | 456 |
begin |
457 |
glPushMatrix; |
|
809 | 458 |
glTranslatef(X, Y, 0); |
806 | 459 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
460 |
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
|
461 |
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
|
462 |
else |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
463 |
glRotatef(Angle, 0, 0, 1); |
853 | 464 |
if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
465 |
||
466 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
806 | 467 |
|
468 |
glPopMatrix |
|
469 |
end; |
|
470 |
||
822 | 471 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
1916 | 472 |
var VertexBuffer: array [0..3] of TVertex2f; |
777 | 473 |
begin |
775 | 474 |
glPushMatrix; |
475 |
glTranslatef(X, Y, 0); |
|
822 | 476 |
|
477 |
if Dir < 0 then |
|
478 |
begin |
|
479 |
hw:= - hw; |
|
480 |
glRotatef(Angle, 0, 0, -1); |
|
481 |
end else |
|
482 |
glRotatef(Angle, 0, 0, 1); |
|
483 |
||
775 | 484 |
|
777 | 485 |
glBindTexture(GL_TEXTURE_2D, Tex^.id); |
775 | 486 |
|
1916 | 487 |
VertexBuffer[0].X:= -hw; |
488 |
VertexBuffer[0].Y:= -hh; |
|
489 |
VertexBuffer[1].X:= hw; |
|
490 |
VertexBuffer[1].Y:= -hh; |
|
491 |
VertexBuffer[2].X:= hw; |
|
492 |
VertexBuffer[2].Y:= hh; |
|
493 |
VertexBuffer[3].X:= -hw; |
|
494 |
VertexBuffer[3].Y:= hh; |
|
775 | 495 |
|
1916 | 496 |
glEnableClientState(GL_VERTEX_ARRAY); |
497 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
775 | 498 |
|
1916 | 499 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
500 |
glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb); |
|
501 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
775 | 502 |
|
1916 | 503 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
504 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
775 | 505 |
|
506 |
glPopMatrix |
|
507 |
end; |
|
508 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
509 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
4 | 510 |
begin |
511 |
r.y:= r.y + Height * Position; |
|
512 |
r.h:= Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
513 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 514 |
end; |
515 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
516 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
755 | 517 |
var r: TSDL_Rect; |
4 | 518 |
begin |
755 | 519 |
r.x:= 0; |
520 |
r.w:= SpritesData[Sprite].Width; |
|
521 |
r.y:= Frame * SpritesData[Sprite].Height; |
|
522 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
523 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 524 |
end; |
525 |
||
1939 | 526 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
527 |
var r: TSDL_Rect; |
|
528 |
begin |
|
529 |
r.x:= 0; |
|
530 |
r.y:= 0; |
|
531 |
r.w:= SpritesData[Sprite].Width; |
|
532 |
r.h:= SpritesData[Sprite].Height; |
|
533 |
||
534 |
if (X < LeftX) then |
|
535 |
r.x:= LeftX - X; |
|
536 |
if (Y < TopY) then |
|
537 |
r.y:= TopY - Y; |
|
538 |
||
539 |
if (Y + SpritesData[Sprite].Height > BottomY) then |
|
540 |
r.h:= BottomY - Y + 1; |
|
541 |
if (X + SpritesData[Sprite].Width > RightX) then |
|
542 |
r.w:= RightX - X + 1; |
|
543 |
||
544 |
dec(r.h, r.y); |
|
545 |
dec(r.w, r.x); |
|
546 |
||
547 |
DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture) |
|
548 |
end; |
|
549 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
550 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
43 | 551 |
var r: TSDL_Rect; |
552 |
begin |
|
553 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
554 |
r.w:= SpritesData[Sprite].Width; |
|
555 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
556 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
557 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
43 | 558 |
end; |
559 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
560 |
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
|
561 |
var r: TSDL_Rect; |
198 | 562 |
begin |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
563 |
r.x:= 0; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
564 |
r.w:= Source^.w; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
565 |
r.y:= Frame * Height; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
566 |
r.h:= Height; |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
567 |
DrawFromRect(X, Y, @r, Source) |
198 | 568 |
end; |
569 |
||
762 | 570 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
95 | 571 |
begin |
762 | 572 |
DrawTexture(X - Source^.w div 2, Top, Source) |
4 | 573 |
end; |
574 |
||
1865
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1854
diff
changeset
|
575 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1916 | 576 |
const VertexBuffer: array [0..3] of TVertex2f = ( |
577 |
(x: -16; y: -16), |
|
578 |
(x: 16; y: -16), |
|
579 |
(x: 16; y: 16), |
|
580 |
(x: -16; y: 16)); |
|
761 | 581 |
var l, r, t, b: real; |
1916 | 582 |
TextureBuffer: array [0..3] of TVertex2f; |
4 | 583 |
begin |
761 | 584 |
|
585 |
t:= Pos * 32 / HHTexture^.h; |
|
586 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
587 |
||
588 |
if Dir = -1 then |
|
589 |
begin |
|
590 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
591 |
r:= Step * 32 / HHTexture^.w |
|
592 |
end else |
|
593 |
begin |
|
594 |
l:= Step * 32 / HHTexture^.w; |
|
595 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
596 |
end; |
|
597 |
||
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
598 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
599 |
glPushMatrix(); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
600 |
glTranslatef(X, Y, 0); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
601 |
glRotatef(Angle, 0, 0, 1); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
602 |
|
761 | 603 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
604 |
||
1916 | 605 |
TextureBuffer[0].X:= l; |
606 |
TextureBuffer[0].Y:= t; |
|
607 |
TextureBuffer[1].X:= r; |
|
608 |
TextureBuffer[1].Y:= t; |
|
609 |
TextureBuffer[2].X:= r; |
|
610 |
TextureBuffer[2].Y:= b; |
|
611 |
TextureBuffer[3].X:= l; |
|
612 |
TextureBuffer[3].Y:= b; |
|
761 | 613 |
|
1916 | 614 |
glEnableClientState(GL_VERTEX_ARRAY); |
615 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
761 | 616 |
|
1916 | 617 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
618 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
619 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
761 | 620 |
|
1916 | 621 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
622 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
761 | 623 |
|
1854 | 624 |
|
625 |
glColor4f(1,1,1,1); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
626 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
627 |
glPopMatrix |
4 | 628 |
end; |
629 |
||
1431 | 630 |
procedure DrawFillRect(r: TSDL_Rect); |
1916 | 631 |
var VertexBuffer: array [0..3] of TVertex2f; |
1431 | 632 |
begin |
633 |
glDisable(GL_TEXTURE_2D); |
|
634 |
||
635 |
glColor4ub(0, 0, 0, 127); |
|
636 |
||
1916 | 637 |
VertexBuffer[0].X:= r.x; |
638 |
VertexBuffer[0].Y:= r.y; |
|
639 |
VertexBuffer[1].X:= r.x + r.w; |
|
640 |
VertexBuffer[1].Y:= r.y; |
|
641 |
VertexBuffer[2].X:= r.x + r.w; |
|
642 |
VertexBuffer[2].Y:= r.y + r.h; |
|
643 |
VertexBuffer[3].X:= r.x; |
|
644 |
VertexBuffer[3].Y:= r.y + r.h; |
|
1431 | 645 |
|
1916 | 646 |
glEnableClientState(GL_VERTEX_ARRAY); |
647 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
648 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
649 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
1431 | 650 |
|
651 |
glColor4f(1, 1, 1, 1); |
|
652 |
glEnable(GL_TEXTURE_2D) |
|
653 |
end; |
|
654 |
||
4 | 655 |
procedure StoreRelease; |
656 |
var ii: TSprite; |
|
657 |
begin |
|
658 |
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
|
659 |
begin |
759 | 660 |
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
|
661 |
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
|
662 |
end; |
761 | 663 |
|
1806 | 664 |
FreeTexture(HHTexture) |
4 | 665 |
end; |
666 |
||
762 | 667 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
432 | 668 |
var w, h: LongInt; |
351 | 669 |
Result: PSDL_Surface; |
95 | 670 |
begin |
1989 | 671 |
if length(s) = 0 then s:= ' '; |
355 | 672 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
785 | 673 |
|
762 | 674 |
Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
675 |
32, RMask, GMask, BMask, AMask); |
|
785 | 676 |
|
107 | 677 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
785 | 678 |
|
95 | 679 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
785 | 680 |
|
762 | 681 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
785 | 682 |
|
762 | 683 |
RenderStringTex:= Surface2Tex(Result); |
785 | 684 |
|
762 | 685 |
SDL_FreeSurface(Result) |
95 | 686 |
end; |
687 |
||
2017 | 688 |
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
|
689 |
var textWidth, textHeight, x, y, w, h, i, j, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt; |
2017 | 690 |
Result, tmpsurf, rotatedEdge: PSDL_Surface; |
691 |
rect: TSDL_Rect; |
|
692 |
chars: TSysCharSet = [#9,' ','.',';',':','?','!',',']; |
|
693 |
substr: shortstring; |
|
694 |
edge, corner, tail: TSPrite; |
|
695 |
begin |
|
696 |
||
697 |
case SpeechType of |
|
698 |
1: begin; |
|
699 |
edge:= sprSpeechEdge; |
|
700 |
corner:= sprSpeechCorner; |
|
701 |
tail:= sprSpeechTail; |
|
702 |
end; |
|
703 |
2: begin; |
|
704 |
edge:= sprThoughtEdge; |
|
705 |
corner:= sprThoughtCorner; |
|
706 |
tail:= sprThoughtTail; |
|
707 |
end; |
|
708 |
3: begin; |
|
709 |
edge:= sprShoutEdge; |
|
710 |
corner:= sprShoutCorner; |
|
711 |
tail:= sprShoutTail; |
|
712 |
end; |
|
713 |
end; |
|
714 |
edgeHeight:= SpritesData[edge].Height; |
|
715 |
edgeWidth:= SpritesData[edge].Width; |
|
716 |
cornerWidth:= SpritesData[corner].Width; |
|
717 |
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
|
718 |
// This one screws up WrapText |
2022 | 719 |
//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
|
720 |
// 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
|
721 |
//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
|
722 |
|
2022 | 723 |
numLines:= 0; |
2017 | 724 |
|
725 |
if length(s) = 0 then s:= '...'; |
|
726 |
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
|
727 |
j:= 0; |
2017 | 728 |
if (length(s) > 20) then |
729 |
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
|
730 |
w:= 0; |
2017 | 731 |
i:= round(Sqrt(length(s)) * 2); |
732 |
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
|
733 |
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
|
734 |
// 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
|
735 |
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
|
736 |
begin |
2017 | 737 |
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
|
738 |
begin |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
739 |
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
|
740 |
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
|
741 |
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
|
742 |
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
|
743 |
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
|
744 |
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
|
745 |
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
|
746 |
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
|
747 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
748 |
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
|
749 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
750 |
end |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
751 |
else numLines := 1; |
2017 | 752 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
753 |
textWidth:=((w-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth; |
2022 | 754 |
textHeight:=(((numlines * h + 2)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth; |
2019 | 755 |
|
2022 | 756 |
textHeight:=max(textHeight,edgeWidth); |
2017 | 757 |
//textWidth:=max(textWidth,SpritesData[tail].Width); |
758 |
rect.x:= 0; |
|
759 |
rect.y:= 0; |
|
2022 | 760 |
rect.w:= textWidth + (cornerWidth * 2); |
761 |
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
|
762 |
//s:= inttostr(w) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h); |
2017 | 763 |
|
764 |
Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask); |
|
765 |
||
766 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
|
767 |
||
768 |
//////////////////////////////// CORNERS /////////////////////////////// |
|
769 |
copyToXY(SpritesData[corner].Surface, Result, 0, 0); /////////////////// NW |
|
770 |
||
771 |
flipSurface(SpritesData[corner].Surface, true); // store all 4 versions in memory to avoid repeated flips? |
|
772 |
x:= 0; |
|
773 |
y:= textHeight + cornerHeight -1; |
|
774 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// SW |
|
775 |
||
776 |
flipSurface(SpritesData[corner].Surface, false); |
|
777 |
x:= rect.w-cornerWidth-1; |
|
778 |
y:= textHeight + cornerHeight -1; |
|
779 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// SE |
|
780 |
||
781 |
flipSurface(SpritesData[corner].Surface, true); |
|
782 |
x:= rect.w-cornerWidth-1; |
|
783 |
y:= 0; |
|
784 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// NE |
|
785 |
flipSurface(SpritesData[corner].Surface, false); // restore original position |
|
786 |
//////////////////////////////// END CORNERS /////////////////////////////// |
|
787 |
||
788 |
//////////////////////////////// EDGES ////////////////////////////////////// |
|
789 |
x:= cornerWidth; |
|
790 |
y:= 0; |
|
791 |
while x < rect.w-cornerWidth-1 do |
|
792 |
begin |
|
793 |
copyToXY(SpritesData[edge].Surface, Result, x, y); ///////////////// top edge |
|
794 |
inc(x,edgeWidth); |
|
795 |
end; |
|
796 |
flipSurface(SpritesData[edge].Surface, true); |
|
797 |
x:= cornerWidth; |
|
798 |
y:= textHeight + cornerHeight*2 - edgeHeight-1; |
|
799 |
while x < rect.w-cornerWidth-1 do |
|
800 |
begin |
|
801 |
copyToXY(SpritesData[edge].Surface, Result, x, y); ///////////////// bottom edge |
|
802 |
inc(x,edgeWidth); |
|
803 |
end; |
|
804 |
flipSurface(SpritesData[edge].Surface, true); // restore original position |
|
805 |
||
806 |
rotatedEdge:= SDL_CreateRGBSurface(SDL_SWSURFACE, edgeHeight, edgeWidth, 32, RMask, GMask, BMask, AMask); |
|
807 |
x:= rect.w - edgeHeight - 1; |
|
808 |
y:= cornerHeight; |
|
809 |
//// initially was going to rotate in place, but the SDL spec claims width/height are read only |
|
810 |
copyRotatedSurface(SpritesData[edge].Surface,rotatedEdge); |
|
811 |
while y < textHeight + cornerHeight do |
|
812 |
begin |
|
813 |
copyToXY(rotatedEdge, Result, x, y); |
|
814 |
inc(y,edgeWidth); |
|
815 |
end; |
|
816 |
flipSurface(rotatedEdge, false); // restore original position |
|
817 |
x:= 0; |
|
818 |
y:= cornerHeight; |
|
819 |
while y < textHeight + cornerHeight do |
|
820 |
begin |
|
821 |
copyToXY(rotatedEdge, Result, x, y); |
|
822 |
inc(y,edgeWidth); |
|
823 |
end; |
|
824 |
//////////////////////////////// END EDGES ////////////////////////////////////// |
|
825 |
||
826 |
x:= cornerWidth; |
|
827 |
y:= textHeight + cornerHeight * 2 - edgeHeight - 1; |
|
828 |
copyToXY(SpritesData[tail].Surface, Result, x, y); |
|
829 |
||
830 |
rect.x:= edgeHeight; |
|
831 |
rect.y:= edgeHeight; |
|
832 |
rect.w:= rect.w - edgeHeight * 2; |
|
833 |
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
|
834 |
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
|
835 |
j:= rect.h; |
2017 | 836 |
SDL_FillRect(Result, @rect, cWhiteColor); |
837 |
||
838 |
pos:= 1; prevpos:= 0; line:= 0; |
|
839 |
while pos <= length(s) do |
|
840 |
begin |
|
841 |
if (s[pos] = #1) or (pos = length(s)) then |
|
842 |
begin |
|
843 |
if s[pos] <> #1 then inc(pos); |
|
844 |
while s[prevpos+1] = ' 'do inc(prevpos); |
|
845 |
substr:= copy(s, prevpos+1, pos-prevpos-1); |
|
846 |
if Length(substr) <> 0 then |
|
847 |
begin |
|
848 |
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
|
849 |
rect.x:= edgeHeight + 1 + ((i - w) div 2); |
2022 | 850 |
// 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
|
851 |
rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h; |
2017 | 852 |
SDLTry(tmpsurf <> nil, true); |
853 |
SDL_UpperBlit(tmpsurf, nil, Result, @rect); |
|
854 |
SDL_FreeSurface(tmpsurf); |
|
855 |
inc(line); |
|
856 |
prevpos:= pos; |
|
857 |
end; |
|
858 |
end; |
|
859 |
inc(pos); |
|
860 |
end; |
|
861 |
||
862 |
//TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
863 |
RenderSpeechBubbleTex:= Surface2Tex(Result); |
|
864 |
||
865 |
SDL_FreeSurface(rotatedEdge); |
|
866 |
SDL_FreeSurface(Result) |
|
867 |
end; |
|
868 |
||
4 | 869 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 870 |
var s: shortstring; |
4 | 871 |
begin |
351 | 872 |
str(Hedgehog.Gear^.Health, s); |
762 | 873 |
if Hedgehog.HealthTagTex <> nil then FreeTexture(Hedgehog.HealthTagTex); |
874 |
Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
|
4 | 875 |
end; |
876 |
||
518 | 877 |
function LoadImage(const filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface; |
30 | 878 |
var tmpsurf: PSDL_Surface; |
753 | 879 |
//Result: PSDL_Surface; |
355 | 880 |
s: shortstring; |
4 | 881 |
begin |
882 |
WriteToConsole(msgLoading + filename + '... '); |
|
355 | 883 |
s:= filename + '.' + cBitsStr + '.png'; |
884 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 885 |
|
74 | 886 |
if tmpsurf = nil then |
351 | 887 |
begin |
355 | 888 |
s:= filename + '.png'; |
889 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 890 |
end; |
80 | 891 |
|
892 |
if tmpsurf = nil then |
|
2153 | 893 |
begin |
894 |
OutError(msgFailed, critical); |
|
895 |
exit(nil) |
|
896 |
end; |
|
897 |
||
898 |
if (tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize) then |
|
899 |
begin |
|
900 |
SDL_FreeSurface(tmpsurf); |
|
901 |
OutError(msgFailedSize, critical); |
|
902 |
exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask)) |
|
903 |
end; |
|
351 | 904 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
905 |
if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
753 | 906 |
//if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
907 |
// else Result:= SDL_DisplayFormat(tmpsurf); |
|
2153 | 908 |
WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') '); |
351 | 909 |
WriteLnToConsole(msgOK); |
2153 | 910 |
|
911 |
LoadImage:= tmpsurf //Result |
|
753 | 912 |
end; |
913 |
||
914 |
procedure SetupOpenGL; |
|
915 |
begin |
|
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
916 |
SetScale(2.0); |
756 | 917 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2153 | 918 |
glMatrixMode(GL_MODELVIEW); |
919 |
||
920 |
glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize); |
|
921 |
{$IFDEF DEBUGFILE} |
|
922 |
AddFileLog('GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize)); |
|
923 |
{$ENDIF} |
|
4 | 924 |
end; |
925 |
||
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
926 |
procedure SetScale(f: GLfloat); |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
927 |
begin |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
928 |
cScaleFactor:= f; |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
929 |
cWaterSprCount:= 1 + round(cScreenWidth * 2 / cScaleFactor / SpritesData[sprWater].Width); |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
930 |
|
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
931 |
glLoadIdentity; |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
932 |
glViewport(0, 0, cScreenWidth, cScreenHeight); |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
933 |
glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0); |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
934 |
//glTranslatef(-cScreenWidth / 2, -cScreenHeight / 2, 0); |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
935 |
glTranslatef(0, -cScreenHeight / 2, 0); |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
936 |
end; |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
937 |
|
510 | 938 |
//////////////////////////////////////////////////////////////////////////////// |
766 | 939 |
var ProgrTex: PTexture = nil; |
534 | 940 |
Step: integer = 0; |
510 | 941 |
|
942 |
procedure AddProgress; |
|
943 |
var r: TSDL_Rect; |
|
766 | 944 |
texsurf: PSDL_Surface; |
510 | 945 |
begin |
946 |
if Step = 0 then |
|
947 |
begin |
|
948 |
WriteToConsole(msgLoading + 'progress sprite: '); |
|
766 | 949 |
texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', false, true, true); |
950 |
ProgrTex:= Surface2Tex(texsurf); |
|
951 |
SDL_FreeSurface(texsurf) |
|
510 | 952 |
end; |
1045 | 953 |
|
766 | 954 |
glClear(GL_COLOR_BUFFER_BIT); |
775 | 955 |
glEnable(GL_TEXTURE_2D); |
510 | 956 |
r.x:= 0; |
766 | 957 |
r.w:= ProgrTex^.w; |
958 |
r.h:= ProgrTex^.w; |
|
959 |
r.y:= (Step mod (ProgrTex^.h div ProgrTex^.w)) * ProgrTex^.w; |
|
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
960 |
DrawFromRect( -ProgrTex^.w div 2, |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
961 |
(cScreenHeight - ProgrTex^.w) div 2, @r, ProgrTex); |
775 | 962 |
glDisable(GL_TEXTURE_2D); |
766 | 963 |
SDL_GL_SwapBuffers(); |
510 | 964 |
inc(Step); |
965 |
end; |
|
966 |
||
967 |
procedure FinishProgress; |
|
968 |
begin |
|
969 |
WriteLnToConsole('Freeing progress surface... '); |
|
766 | 970 |
FreeTexture(ProgrTex) |
510 | 971 |
end; |
972 |
||
2017 | 973 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
974 |
var y, x, i, j: LongInt; |
|
975 |
tmpPixel: Longword; |
|
976 |
pixels: PLongWordArray; |
|
977 |
begin |
|
978 |
TryDo(Surface^.format^.BytesPerPixel = 4, 'flipSurface failed, expecting 32 bit surface', true); |
|
979 |
pixels:= Surface^.pixels; |
|
980 |
if Vertical then |
|
981 |
for y := 0 to (Surface^.h div 2) - 1 do |
|
982 |
for x := 0 to Surface^.w - 1 do |
|
983 |
begin |
|
984 |
i:= y * Surface^.w + x; |
|
985 |
j:= (Surface^.h - y - 1) * Surface^.w + x; |
|
986 |
tmpPixel:= pixels^[i]; |
|
987 |
pixels^[i]:= pixels^[j]; |
|
988 |
pixels^[j]:= tmpPixel; |
|
989 |
end |
|
990 |
else |
|
991 |
for x := 0 to (Surface^.w div 2) - 1 do |
|
992 |
for y := 0 to Surface^.h -1 do |
|
993 |
begin |
|
994 |
i:= y*Surface^.w + x; |
|
995 |
j:= y*Surface^.w + (Surface^.w - x - 1); |
|
996 |
tmpPixel:= pixels^[i]; |
|
997 |
pixels^[i]:= pixels^[j]; |
|
998 |
pixels^[j]:= tmpPixel; |
|
999 |
end; |
|
1000 |
end; |
|
1001 |
||
1002 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer); |
|
1003 |
var srcX, srcY, i, j, maxDest: LongInt; |
|
1004 |
srcPixels, destPixels: PLongWordArray; |
|
1005 |
begin |
|
1006 |
maxDest:= (dest^.pitch div 4) * dest^.h; |
|
1007 |
srcPixels:= src^.pixels; |
|
1008 |
destPixels:= dest^.pixels; |
|
1009 |
||
1010 |
for srcX:= 0 to src^.w - 1 do |
|
1011 |
for srcY:= 0 to src^.h - 1 do |
|
1012 |
begin |
|
1013 |
i:= (destY + srcY) * (dest^.pitch div 4) + destX + srcX; |
|
1014 |
j:= srcY * (src^.pitch div 4) + srcX; |
|
1015 |
// basic skip of transparent pixels - cleverness would be to do true alpha |
|
1016 |
if (i < maxDest) and ($FF000000 and srcPixels^[j] <> 0) then destPixels^[i]:= srcPixels^[j]; |
|
1017 |
end; |
|
1018 |
end; |
|
1019 |
||
1020 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently |
|
1021 |
var y, x, i, j: LongInt; |
|
1022 |
srcPixels, destPixels: PLongWordArray; |
|
1023 |
begin |
|
1024 |
TryDo(src^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
1025 |
TryDo(dest^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
1026 |
||
1027 |
srcPixels:= src^.pixels; |
|
1028 |
destPixels:= dest^.pixels; |
|
1029 |
||
1030 |
j:= 0; |
|
1031 |
for x := 0 to src^.w - 1 do |
|
1032 |
for y := 0 to src^.h - 1 do |
|
1033 |
begin |
|
1034 |
i:= (src^.h - 1 - y) * (src^.pitch div 4) + x; |
|
1035 |
destPixels^[j]:= srcPixels^[i]; |
|
1036 |
inc(j) |
|
1037 |
end; |
|
1038 |
end; |
|
1039 |
||
4 | 1040 |
end. |