author | unc0rr |
Fri, 25 Jan 2008 20:47:50 +0000 | |
changeset 753 | 40fc0deb388f |
parent 704 | 9b096d05004e |
child 754 | 94ac14829085 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
393 | 3 |
* Copyright (c) 2004-2007 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 |
|
351 | 21 |
uses uConsts, uTeams, SDLh, uFloat; |
4 | 22 |
{$INCLUDE options.inc} |
23 |
||
24 |
procedure StoreInit; |
|
25 |
procedure StoreLoad; |
|
26 |
procedure StoreRelease; |
|
689 | 27 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt; Surface: PSDL_Surface); |
371 | 28 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt; Surface: PSDL_Surface); |
29 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt; Surface: PSDL_Surface); |
|
30 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source, Surface: PSDL_Surface); |
|
31 |
procedure DrawLand (X, Y: LongInt; Surface: PSDL_Surface); |
|
32 |
procedure DXOutText(X, Y: LongInt; Font: THWFont; s: string; Surface: PSDL_Surface); |
|
33 |
procedure DrawCentered(X, Top: LongInt; Source, Surface: PSDL_Surface); |
|
690 | 34 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface); |
371 | 35 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Surface: PSDL_Surface); |
351 | 36 |
function RenderString(s: string; Color: Longword; font: THWFont): PSDL_Surface; |
4 | 37 |
procedure RenderHealth(var Hedgehog: THedgehog); |
38 |
procedure AddProgress; |
|
510 | 39 |
procedure FinishProgress; |
518 | 40 |
function LoadImage(const filename: string; hasAlpha, critical, setTransparent: boolean): PSDL_Surface; |
753 | 41 |
procedure SetupOpenGL; |
4 | 42 |
|
43 |
var PixelFormat: PSDL_PixelFormat; |
|
44 |
SDLPrimSurface: PSDL_Surface; |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
45 |
PauseSurface: PSDL_Surface; |
4 | 46 |
|
47 |
implementation |
|
753 | 48 |
uses uMisc, uConsole, uLand, uLocale, GL, GLU; |
4 | 49 |
|
690 | 50 |
var |
51 |
HHSurface: PSDL_Surface; |
|
4 | 52 |
|
53 |
procedure StoreInit; |
|
54 |
begin |
|
55 |
||
56 |
end; |
|
57 |
||
351 | 58 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
47 | 59 |
var r: TSDL_Rect; |
60 |
begin |
|
61 |
r:= rect^; |
|
83 | 62 |
if Clear then SDL_FillRect(Surface, @r, 0); |
351 | 63 |
r.y:= rect^.y + 1; |
64 |
r.h:= rect^.h - 2; |
|
47 | 65 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 66 |
r.x:= rect^.x + 1; |
67 |
r.w:= rect^.w - 2; |
|
68 |
r.y:= rect^.y; |
|
69 |
r.h:= rect^.h; |
|
47 | 70 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 71 |
r.x:= rect^.x + 2; |
72 |
r.y:= rect^.y + 1; |
|
73 |
r.w:= rect^.w - 4; |
|
74 |
r.h:= rect^.h - 2; |
|
47 | 75 |
SDL_FillRect(Surface, @r, FillColor); |
351 | 76 |
r.x:= rect^.x + 1; |
77 |
r.y:= rect^.y + 2; |
|
78 |
r.w:= rect^.w - 2; |
|
79 |
r.h:= rect^.h - 4; |
|
47 | 80 |
SDL_FillRect(Surface, @r, FillColor) |
81 |
end; |
|
82 |
||
371 | 83 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
351 | 84 |
var w, h: LongInt; |
4 | 85 |
tmpsurf: PSDL_Surface; |
86 |
clr: TSDL_Color; |
|
351 | 87 |
Result: TSDL_Rect; |
4 | 88 |
begin |
355 | 89 |
TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
4 | 90 |
Result.x:= X; |
91 |
Result.y:= Y; |
|
202 | 92 |
Result.w:= w + FontBorder * 2 + 4; |
93 |
Result.h:= h + FontBorder * 2; |
|
351 | 94 |
DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface, true); |
189 | 95 |
clr.r:= Color shr 16; |
96 |
clr.g:= (Color shr 8) and $FF; |
|
97 |
clr.b:= Color and $FF; |
|
355 | 98 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr.value); |
202 | 99 |
Result.x:= X + FontBorder + 2; |
100 |
Result.y:= Y + FontBorder; |
|
199 | 101 |
SDLTry(tmpsurf <> nil, true); |
4 | 102 |
SDL_UpperBlit(tmpsurf, nil, Surface, @Result); |
103 |
SDL_FreeSurface(tmpsurf); |
|
104 |
Result.x:= X; |
|
105 |
Result.y:= Y; |
|
202 | 106 |
Result.w:= w + FontBorder * 2 + 4; |
351 | 107 |
Result.h:= h + FontBorder * 2; |
108 |
WriteInRoundRect:= Result |
|
4 | 109 |
end; |
110 |
||
111 |
procedure StoreLoad; |
|
689 | 112 |
var ii: TSprite; |
4 | 113 |
fi: THWFont; |
114 |
s: string; |
|
115 |
tmpsurf: PSDL_Surface; |
|
116 |
||
117 |
procedure WriteNames(Font: THWFont); |
|
547 | 118 |
var t: LongInt; |
371 | 119 |
i: LongInt; |
47 | 120 |
r, rr: TSDL_Rect; |
371 | 121 |
drY: LongInt; |
4 | 122 |
begin |
123 |
r.x:= 0; |
|
690 | 124 |
r.y:= 0; |
70 | 125 |
drY:= cScreenHeight - 4; |
547 | 126 |
for t:= 0 to Pred(TeamsCount) do |
127 |
with TeamsArray[t]^ do |
|
4 | 128 |
begin |
549 | 129 |
NameTag:= RenderString(TeamName, Clan^.Color, Font); |
690 | 130 |
|
47 | 131 |
r.w:= cTeamHealthWidth + 5; |
547 | 132 |
r.h:= NameTag^.h; |
690 | 133 |
|
134 |
HealthSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, r.w, r.h, cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
|
135 |
TryDo(HealthSurf <> nil, errmsgCreateSurface, true); |
|
704 | 136 |
TryDo(SDL_SetColorKey(HealthSurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
690 | 137 |
|
138 |
DrawRoundRect(@r, cWhiteColor, cColorNearBlack, HealthSurf, true); |
|
47 | 139 |
rr:= r; |
140 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
|
690 | 141 |
DrawRoundRect(@rr, Clan^.AdjColor, Clan^.AdjColor, HealthSurf, false); |
142 |
||
49 | 143 |
dec(drY, r.h + 2); |
547 | 144 |
DrawHealthY:= drY; |
4 | 145 |
for i:= 0 to 7 do |
547 | 146 |
with Hedgehogs[i] do |
95 | 147 |
if Gear <> nil then |
549 | 148 |
NameTag:= RenderString(Name, Clan^.Color, fnt16); |
4 | 149 |
end; |
150 |
end; |
|
151 |
||
152 |
procedure MakeCrossHairs; |
|
547 | 153 |
var t: LongInt; |
4 | 154 |
tmpsurf: PSDL_Surface; |
155 |
s: string; |
|
156 |
begin |
|
53 | 157 |
s:= Pathz[ptGraphics] + '/' + cCHFileName; |
351 | 158 |
tmpsurf:= LoadImage(s, true, true, false); |
4 | 159 |
|
547 | 160 |
for t:= 0 to Pred(TeamsCount) do |
161 |
with TeamsArray[t]^ do |
|
4 | 162 |
begin |
547 | 163 |
CrosshairSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, tmpsurf^.w, tmpsurf^.h, cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
164 |
TryDo(CrosshairSurf <> nil, errmsgCreateSurface, true); |
|
549 | 165 |
SDL_FillRect(CrosshairSurf, nil, Clan^.AdjColor); |
547 | 166 |
SDL_UpperBlit(tmpsurf, nil, CrosshairSurf, nil); |
167 |
TryDo(SDL_SetColorKey(CrosshairSurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
|
4 | 168 |
end; |
351 | 169 |
|
4 | 170 |
SDL_FreeSurface(tmpsurf) |
171 |
end; |
|
172 |
||
173 |
procedure InitHealth; |
|
547 | 174 |
var i, t: LongInt; |
4 | 175 |
begin |
547 | 176 |
for t:= 0 to Pred(TeamsCount) do |
177 |
if TeamsArray[t] <> nil then |
|
178 |
with TeamsArray[t]^ do |
|
4 | 179 |
begin |
180 |
for i:= 0 to cMaxHHIndex do |
|
547 | 181 |
if Hedgehogs[i].Gear <> nil then |
182 |
RenderHealth(Hedgehogs[i]); |
|
4 | 183 |
end |
184 |
end; |
|
185 |
||
186 |
procedure LoadGraves; |
|
689 | 187 |
var t: LongInt; |
4 | 188 |
begin |
547 | 189 |
for t:= 0 to Pred(TeamsCount) do |
190 |
if TeamsArray[t] <> nil then |
|
191 |
with TeamsArray[t]^ do |
|
4 | 192 |
begin |
547 | 193 |
if GraveName = '' then GraveName:= 'Simple'; |
689 | 194 |
GraveSurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, false, true, true); |
4 | 195 |
end |
196 |
end; |
|
197 |
||
198 |
procedure GetSkyColor; |
|
107 | 199 |
var p: PByteArray; |
4 | 200 |
begin |
80 | 201 |
if SDL_MustLock(SpritesData[sprSky].Surface) then |
202 |
SDLTry(SDL_LockSurface(SpritesData[sprSky].Surface) >= 0, true); |
|
351 | 203 |
p:= SpritesData[sprSky].Surface^.pixels; |
204 |
case SpritesData[sprSky].Surface^.format^.BytesPerPixel of |
|
4 | 205 |
1: cSkyColor:= PByte(p)^; |
206 |
2: cSkyColor:= PWord(p)^; |
|
107 | 207 |
3: cSkyColor:= (p^[0]) or (p^[1] shl 8) or (p^[2] shl 16); |
4 | 208 |
4: cSkyColor:= PLongword(p)^; |
209 |
end; |
|
753 | 210 |
glClearColor((cSkyColor shr 16) / 255, ((cSkyColor shr 8) and $FF) / 255, (cSkyColor and $FF) / 255, 0); |
211 |
||
80 | 212 |
if SDL_MustLock(SpritesData[sprSky].Surface) then |
213 |
SDL_UnlockSurface(SpritesData[sprSky].Surface) |
|
4 | 214 |
end; |
215 |
||
216 |
procedure GetExplosionBorderColor; |
|
217 |
var f: textfile; |
|
371 | 218 |
c: LongInt; |
4 | 219 |
begin |
80 | 220 |
s:= Pathz[ptCurrTheme] + '/' + cThemeCFGFilename; |
4 | 221 |
WriteToConsole(msgLoading + s + ' '); |
351 | 222 |
Assign(f, s); |
4 | 223 |
{$I-} |
224 |
Reset(f); |
|
225 |
Readln(f, s); |
|
351 | 226 |
Close(f); |
4 | 227 |
{$I+} |
228 |
TryDo(IOResult = 0, msgFailed, true); |
|
229 |
WriteLnToConsole(msgOK); |
|
230 |
val(s, cExplosionBorderColor, c); |
|
495 | 231 |
TryDo(c = 0, 'Theme data corrupted', true); |
191
a03c2d037e24
Bots are in the same thread as game. Fixes FreePascal issues.
unc0rr
parents:
190
diff
changeset
|
232 |
AdjustColor(cExplosionBorderColor); |
4 | 233 |
end; |
234 |
||
235 |
begin |
|
236 |
for fi:= Low(THWFont) to High(THWFont) do |
|
237 |
with Fontz[fi] do |
|
238 |
begin |
|
53 | 239 |
s:= Pathz[ptFonts] + '/' + Name; |
200 | 240 |
WriteToConsole(msgLoading + s + '... '); |
355 | 241 |
Handle:= TTF_OpenFont(Str2PChar(s), Height); |
200 | 242 |
SDLTry(Handle <> nil, true); |
202 | 243 |
TTF_SetFontStyle(Handle, style); |
4 | 244 |
WriteLnToConsole(msgOK) |
245 |
end; |
|
246 |
AddProgress; |
|
53 | 247 |
|
105 | 248 |
WriteToConsole('LandSurface tuning... '); |
4 | 249 |
tmpsurf:= LandSurface; |
250 |
TryDo(tmpsurf <> nil, msgFailed, true); |
|
251 |
if cFullScreen then |
|
252 |
begin |
|
253 |
LandSurface:= SDL_DisplayFormat(tmpsurf); |
|
254 |
SDL_FreeSurface(tmpsurf); |
|
255 |
end else LandSurface:= tmpsurf; |
|
35 | 256 |
TryDo(SDL_SetColorKey(LandSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
4 | 257 |
WriteLnToConsole(msgOK); |
258 |
||
259 |
GetExplosionBorderColor; |
|
260 |
||
261 |
AddProgress; |
|
262 |
WriteNames(fnt16); |
|
70 | 263 |
MakeCrossHairs; |
4 | 264 |
LoadGraves; |
265 |
||
266 |
AddProgress; |
|
267 |
for ii:= Low(TSprite) to High(TSprite) do |
|
268 |
with SpritesData[ii] do |
|
80 | 269 |
begin |
270 |
if AltPath = ptNone then |
|
351 | 271 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, true, true) |
80 | 272 |
else begin |
351 | 273 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, false, true); |
80 | 274 |
if Surface = nil then |
351 | 275 |
Surface:= LoadImage(Pathz[AltPath] + '/' + FileName, hasAlpha, true, true) |
80 | 276 |
end; |
351 | 277 |
if Width = 0 then Width:= Surface^.w; |
278 |
if Height = 0 then Height:= Surface^.h |
|
80 | 279 |
end; |
280 |
||
281 |
GetSkyColor; |
|
4 | 282 |
|
283 |
AddProgress; |
|
567 | 284 |
|
285 |
HHSurface:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, true, true, true); |
|
4 | 286 |
|
287 |
InitHealth; |
|
288 |
||
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
289 |
PauseSurface:= RenderString(trmsg[sidPaused], $FFFF00, fntBig); |
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
290 |
|
4 | 291 |
{$IFDEF DUMP} |
292 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
293 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
294 |
{$ENDIF} |
|
295 |
end; |
|
296 |
||
371 | 297 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface); |
4 | 298 |
var rr: TSDL_Rect; |
299 |
begin |
|
300 |
rr.x:= X; |
|
301 |
rr.y:= Y; |
|
351 | 302 |
rr.w:= r^.w; |
303 |
rr.h:= r^.h; |
|
4 | 304 |
if SDL_UpperBlit(SourceSurface, r, DestSurface, @rr) < 0 then |
305 |
begin |
|
43 | 306 |
OutError('Blit: ' + SDL_GetError, true); |
4 | 307 |
exit |
308 |
end; |
|
309 |
end; |
|
310 |
||
689 | 311 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt; Surface: PSDL_Surface); |
4 | 312 |
begin |
313 |
r.y:= r.y + Height * Position; |
|
314 |
r.h:= Height; |
|
689 | 315 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface) |
4 | 316 |
end; |
317 |
||
371 | 318 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt; Surface: PSDL_Surface); |
4 | 319 |
begin |
198 | 320 |
DrawSurfSprite(X, Y, SpritesData[Sprite].Height, Frame, SpritesData[Sprite].Surface, Surface) |
4 | 321 |
end; |
322 |
||
371 | 323 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt; Surface: PSDL_Surface); |
43 | 324 |
var r: TSDL_Rect; |
325 |
begin |
|
326 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
327 |
r.w:= SpritesData[Sprite].Width; |
|
328 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
329 |
r.h:= SpritesData[Sprite].Height; |
|
330 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface) |
|
331 |
end; |
|
332 |
||
371 | 333 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source, Surface: PSDL_Surface); |
198 | 334 |
var r: TSDL_Rect; |
335 |
begin |
|
336 |
r.x:= 0; |
|
351 | 337 |
r.w:= Source^.w; |
198 | 338 |
r.y:= Frame * Height; |
339 |
r.h:= Height; |
|
340 |
DrawFromRect(X, Y, @r, Source, Surface) |
|
341 |
end; |
|
342 |
||
371 | 343 |
procedure DXOutText(X, Y: LongInt; Font: THWFont; s: string; Surface: PSDL_Surface); |
4 | 344 |
var clr: TSDL_Color; |
345 |
tmpsurf: PSDL_Surface; |
|
346 |
r: TSDL_Rect; |
|
347 |
begin |
|
348 |
r.x:= X; |
|
349 |
r.y:= Y; |
|
189 | 350 |
clr.r:= $FF; |
351 |
clr.g:= $FF; |
|
352 |
clr.b:= $FF; |
|
355 | 353 |
tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, Str2PChar(s), clr.value); |
208 | 354 |
if tmpsurf = nil then |
355 |
begin |
|
356 |
SetKB(1); |
|
357 |
exit |
|
358 |
end; |
|
4 | 359 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
360 |
SDL_FreeSurface(tmpsurf) |
|
361 |
end; |
|
362 |
||
371 | 363 |
procedure DrawLand(X, Y: LongInt; Surface: PSDL_Surface); |
4 | 364 |
const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024); |
365 |
begin |
|
753 | 366 |
glBindTexture(GL_TEXTURE_2D, LandTexture); |
367 |
glEnable(GL_TEXTURE_2D); |
|
368 |
||
369 |
glBegin(GL_QUADS); |
|
370 |
||
371 |
// top left |
|
372 |
glTexCoord2f(0, 0); |
|
373 |
glVertex2f(0, 0); |
|
374 |
||
375 |
// top right |
|
376 |
glTexCoord2f(1, 0); |
|
377 |
glVertex2f(1, 0); |
|
378 |
||
379 |
// bottom right |
|
380 |
glTexCoord2f(1, 1); |
|
381 |
glVertex2f(1, 1); |
|
382 |
||
383 |
// bottom left |
|
384 |
glTexCoord2f(0, 1); |
|
385 |
glVertex2f(0, 1); |
|
386 |
||
387 |
glEnd(); |
|
388 |
//DrawFromRect(X, Y, @r, LandSurface, Surface) |
|
4 | 389 |
end; |
390 |
||
371 | 391 |
procedure DrawCentered(X, Top: LongInt; Source, Surface: PSDL_Surface); |
95 | 392 |
var r: TSDL_Rect; |
393 |
begin |
|
351 | 394 |
r.x:= X - Source^.w div 2; |
95 | 395 |
r.y:= Top; |
351 | 396 |
r.w:= Source^.w; |
397 |
r.h:= Source^.h; |
|
95 | 398 |
SDL_UpperBlit(Source, nil, Surface, @r) |
4 | 399 |
end; |
400 |
||
371 | 401 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Surface: PSDL_Surface); |
4 | 402 |
var r: TSDL_Rect; |
403 |
begin |
|
404 |
r.x:= Step * 32; |
|
405 |
r.y:= Pos * 32; |
|
351 | 406 |
if Dir = -1 then r.x:= HHSurface^.w - 32 - r.x; |
4 | 407 |
r.w:= 32; |
408 |
r.h:= 32; |
|
409 |
DrawFromRect(X, Y, @r, HHSurface, Surface) |
|
410 |
end; |
|
411 |
||
412 |
procedure StoreRelease; |
|
413 |
var ii: TSprite; |
|
414 |
begin |
|
415 |
for ii:= Low(TSprite) to High(TSprite) do |
|
416 |
SDL_FreeSurface(SpritesData[ii].Surface); |
|
417 |
SDL_FreeSurface( HHSurface ); |
|
690 | 418 |
SDL_FreeSurface(LandSurface ) |
4 | 419 |
end; |
420 |
||
351 | 421 |
function RenderString(s: string; Color: Longword; font: THWFont): PSDL_Surface; |
432 | 422 |
var w, h: LongInt; |
351 | 423 |
Result: PSDL_Surface; |
95 | 424 |
begin |
355 | 425 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
202 | 426 |
Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
351 | 427 |
cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
107 | 428 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
95 | 429 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
351 | 430 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
431 |
RenderString:= Result |
|
95 | 432 |
end; |
433 |
||
4 | 434 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 435 |
var s: shortstring; |
4 | 436 |
begin |
351 | 437 |
str(Hedgehog.Gear^.Health, s); |
95 | 438 |
if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag); |
549 | 439 |
Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Clan^.Color, fnt16) |
4 | 440 |
end; |
441 |
||
518 | 442 |
function LoadImage(const filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface; |
30 | 443 |
var tmpsurf: PSDL_Surface; |
753 | 444 |
//Result: PSDL_Surface; |
355 | 445 |
s: shortstring; |
4 | 446 |
begin |
447 |
WriteToConsole(msgLoading + filename + '... '); |
|
355 | 448 |
s:= filename + '.' + cBitsStr + '.png'; |
449 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 450 |
|
74 | 451 |
if tmpsurf = nil then |
351 | 452 |
begin |
355 | 453 |
s:= filename + '.png'; |
454 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 455 |
end; |
80 | 456 |
|
457 |
if tmpsurf = nil then |
|
458 |
if critical then OutError(msgFailed, true) |
|
459 |
else begin |
|
460 |
WriteLnToConsole(msgFailed); |
|
351 | 461 |
exit(nil) |
80 | 462 |
end; |
351 | 463 |
|
198 | 464 |
if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
753 | 465 |
//if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
466 |
// else Result:= SDL_DisplayFormat(tmpsurf); |
|
620 | 467 |
{$IFDEF DEBUGFILE}WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') ');{$ENDIF} |
351 | 468 |
WriteLnToConsole(msgOK); |
753 | 469 |
LoadImage:= tmpsurf//Result |
470 |
end; |
|
471 |
||
472 |
procedure SetupOpenGL; |
|
473 |
var aspect: real; |
|
474 |
begin |
|
475 |
aspect:= cScreenWidth / cScreenHeight; |
|
476 |
||
477 |
glViewport(0, 0, cScreenWidth, cScreenHeight); |
|
478 |
||
479 |
//glMatrixMode(GL_PROJECTION); |
|
480 |
//glLoadIdentity(); |
|
481 |
||
482 |
//gluPerspective(60.0, aspect, 0.1, 100.0); |
|
483 |
||
484 |
glMatrixMode(GL_MODELVIEW) |
|
4 | 485 |
end; |
486 |
||
510 | 487 |
//////////////////////////////////////////////////////////////////////////////// |
488 |
var ProgrSurf: PSDL_Surface = nil; |
|
534 | 489 |
Step: integer = 0; |
510 | 490 |
|
491 |
procedure AddProgress; |
|
492 |
var r: TSDL_Rect; |
|
493 |
begin |
|
494 |
if Step = 0 then |
|
495 |
begin |
|
496 |
WriteToConsole(msgLoading + 'progress sprite: '); |
|
497 |
ProgrSurf:= LoadImage(Pathz[ptGraphics] + '/Progress', false, true, true); |
|
498 |
end; |
|
499 |
SDL_FillRect(SDLPrimSurface, nil, 0); |
|
500 |
r.x:= 0; |
|
501 |
r.w:= ProgrSurf^.w; |
|
502 |
r.h:= ProgrSurf^.w; |
|
503 |
r.y:= (Step mod (ProgrSurf^.h div ProgrSurf^.w)) * ProgrSurf^.w; |
|
504 |
DrawFromRect((cScreenWidth - ProgrSurf^.w) div 2, |
|
505 |
(cScreenHeight - ProgrSurf^.w) div 2, @r, ProgrSurf, SDLPrimSurface); |
|
506 |
SDL_Flip(SDLPrimSurface); |
|
507 |
inc(Step); |
|
508 |
end; |
|
509 |
||
510 |
procedure FinishProgress; |
|
511 |
begin |
|
512 |
WriteLnToConsole('Freeing progress surface... '); |
|
513 |
SDL_FreeSurface(ProgrSurf) |
|
514 |
end; |
|
515 |
||
4 | 516 |
end. |