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