author | unc0rr |
Sun, 31 Aug 2008 18:36:26 +0000 | |
changeset 1244 | 87b3931c70e9 |
parent 1242 | 4aca5f7b2504 |
child 1251 | 1f545d9a10ca |
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 |
|
755 | 21 |
uses uConsts, uTeams, SDLh, uFloat, GL; |
4 | 22 |
{$INCLUDE options.inc} |
23 |
||
24 |
procedure StoreInit; |
|
25 |
procedure StoreLoad; |
|
26 |
procedure StoreRelease; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
27 |
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
|
28 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
29 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
30 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture); |
762 | 31 |
procedure DrawLand (X, Y: LongInt); |
32 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
|
1242 | 33 |
procedure DrawTextureF(Texture: PTexture; X, Y, Frame, Dir, Frames: LongInt); |
822 | 34 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
853 | 35 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
822 | 36 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
762 | 37 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
38 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
39 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
762 | 40 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
4 | 41 |
procedure RenderHealth(var Hedgehog: THedgehog); |
42 |
procedure AddProgress; |
|
510 | 43 |
procedure FinishProgress; |
518 | 44 |
function LoadImage(const filename: string; hasAlpha, critical, setTransparent: boolean): PSDL_Surface; |
753 | 45 |
procedure SetupOpenGL; |
4 | 46 |
|
47 |
var PixelFormat: PSDL_PixelFormat; |
|
48 |
SDLPrimSurface: PSDL_Surface; |
|
1023 | 49 |
PauseTexture, |
50 |
ConfirmTexture: PTexture; |
|
4 | 51 |
|
52 |
implementation |
|
755 | 53 |
uses uMisc, uConsole, uLand, uLocale, GLU; |
4 | 54 |
|
690 | 55 |
var |
761 | 56 |
HHTexture: PTexture; |
4 | 57 |
|
58 |
procedure StoreInit; |
|
59 |
begin |
|
60 |
||
61 |
end; |
|
62 |
||
351 | 63 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
47 | 64 |
var r: TSDL_Rect; |
65 |
begin |
|
66 |
r:= rect^; |
|
83 | 67 |
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
|
68 |
|
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
|
351 | 72 |
r.y:= rect^.y + 1; |
73 |
r.h:= rect^.h - 2; |
|
47 | 74 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 75 |
r.x:= rect^.x + 1; |
76 |
r.w:= rect^.w - 2; |
|
77 |
r.y:= rect^.y; |
|
78 |
r.h:= rect^.h; |
|
47 | 79 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 80 |
r.x:= rect^.x + 2; |
81 |
r.y:= rect^.y + 1; |
|
82 |
r.w:= rect^.w - 4; |
|
83 |
r.h:= rect^.h - 2; |
|
47 | 84 |
SDL_FillRect(Surface, @r, FillColor); |
351 | 85 |
r.x:= rect^.x + 1; |
86 |
r.y:= rect^.y + 2; |
|
87 |
r.w:= rect^.w - 2; |
|
88 |
r.h:= rect^.h - 4; |
|
47 | 89 |
SDL_FillRect(Surface, @r, FillColor) |
90 |
end; |
|
91 |
||
371 | 92 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
351 | 93 |
var w, h: LongInt; |
4 | 94 |
tmpsurf: PSDL_Surface; |
95 |
clr: TSDL_Color; |
|
351 | 96 |
Result: TSDL_Rect; |
4 | 97 |
begin |
355 | 98 |
TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
4 | 99 |
Result.x:= X; |
100 |
Result.y:= Y; |
|
202 | 101 |
Result.w:= w + FontBorder * 2 + 4; |
102 |
Result.h:= h + FontBorder * 2; |
|
351 | 103 |
DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface, true); |
189 | 104 |
clr.r:= Color shr 16; |
105 |
clr.g:= (Color shr 8) and $FF; |
|
106 |
clr.b:= Color and $FF; |
|
355 | 107 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr.value); |
202 | 108 |
Result.x:= X + FontBorder + 2; |
109 |
Result.y:= Y + FontBorder; |
|
199 | 110 |
SDLTry(tmpsurf <> nil, true); |
4 | 111 |
SDL_UpperBlit(tmpsurf, nil, Surface, @Result); |
112 |
SDL_FreeSurface(tmpsurf); |
|
113 |
Result.x:= X; |
|
114 |
Result.y:= Y; |
|
202 | 115 |
Result.w:= w + FontBorder * 2 + 4; |
351 | 116 |
Result.h:= h + FontBorder * 2; |
117 |
WriteInRoundRect:= Result |
|
4 | 118 |
end; |
119 |
||
120 |
procedure StoreLoad; |
|
844 | 121 |
var s: string; |
4 | 122 |
|
1185 | 123 |
procedure WriteNames(Font: THWFont); |
124 |
var t: LongInt; |
|
125 |
i: LongInt; |
|
126 |
r, rr: TSDL_Rect; |
|
127 |
drY: LongInt; |
|
128 |
texsurf: PSDL_Surface; |
|
129 |
begin |
|
130 |
r.x:= 0; |
|
131 |
r.y:= 0; |
|
132 |
drY:= - 4; |
|
133 |
for t:= 0 to Pred(TeamsCount) do |
|
134 |
with TeamsArray[t]^ do |
|
135 |
begin |
|
136 |
NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font); |
|
690 | 137 |
|
1185 | 138 |
r.w:= cTeamHealthWidth + 5; |
139 |
r.h:= NameTagTex^.h; |
|
690 | 140 |
|
1185 | 141 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
142 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
143 |
TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
690 | 144 |
|
1185 | 145 |
DrawRoundRect(@r, cWhiteColor, cColorNearBlack, texsurf, true); |
146 |
rr:= r; |
|
147 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
|
148 |
DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false); |
|
149 |
HealthTex:= Surface2Tex(texsurf); |
|
150 |
SDL_FreeSurface(texsurf); |
|
690 | 151 |
|
1185 | 152 |
dec(drY, r.h + 2); |
153 |
DrawHealthY:= drY; |
|
154 |
for i:= 0 to 7 do |
|
155 |
with Hedgehogs[i] do |
|
156 |
if Gear <> nil then |
|
1242 | 157 |
begin |
1185 | 158 |
NameTagTex:= RenderStringTex(Name, Clan^.Color, fnt16); |
1242 | 159 |
texsurf:= LoadImage(Pathz[ptHats] + '/' + Hat, false, true, false); |
160 |
HatTex:= Surface2Tex(texsurf); |
|
161 |
SDL_FreeSurface(texsurf) |
|
162 |
end; |
|
1185 | 163 |
end; |
164 |
end; |
|
4 | 165 |
|
1185 | 166 |
procedure MakeCrossHairs; |
167 |
var t: LongInt; |
|
168 |
tmpsurf, texsurf: PSDL_Surface; |
|
169 |
Color, i: Longword; |
|
170 |
begin |
|
171 |
s:= Pathz[ptGraphics] + '/' + cCHFileName; |
|
172 |
tmpsurf:= LoadImage(s, true, true, false); |
|
4 | 173 |
|
1185 | 174 |
for t:= 0 to Pred(TeamsCount) do |
175 |
with TeamsArray[t]^ do |
|
176 |
begin |
|
177 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask); |
|
178 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
179 |
|
1185 | 180 |
Color:= Clan^.Color; |
181 |
Color:= SDL_MapRGB(texsurf^.format, Color shr 16, Color shr 8, Color and $FF); |
|
182 |
SDL_FillRect(texsurf, nil, Color); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
183 |
|
1185 | 184 |
SDL_UpperBlit(tmpsurf, nil, texsurf, nil); |
777 | 185 |
|
1185 | 186 |
TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Ooops', true); |
777 | 187 |
|
1185 | 188 |
if SDL_MustLock(texsurf) then |
189 |
SDLTry(SDL_LockSurface(texsurf) >= 0, true); |
|
777 | 190 |
|
1185 | 191 |
// make black pixel be alpha-transparent |
192 |
for i:= 0 to texsurf^.w * texsurf^.h - 1 do |
|
193 |
if PLongwordArray(texsurf^.pixels)^[i] = $FF000000 then PLongwordArray(texsurf^.pixels)^[i]:= 0; |
|
777 | 194 |
|
1185 | 195 |
if SDL_MustLock(texsurf) then |
196 |
SDL_UnlockSurface(texsurf); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
197 |
|
1185 | 198 |
CrosshairTex:= Surface2Tex(texsurf); |
199 |
SDL_FreeSurface(texsurf) |
|
200 |
end; |
|
351 | 201 |
|
1185 | 202 |
SDL_FreeSurface(tmpsurf) |
203 |
end; |
|
4 | 204 |
|
1185 | 205 |
procedure InitHealth; |
206 |
var i, t: LongInt; |
|
207 |
begin |
|
208 |
for t:= 0 to Pred(TeamsCount) do |
|
209 |
if TeamsArray[t] <> nil then |
|
210 |
with TeamsArray[t]^ do |
|
211 |
begin |
|
212 |
for i:= 0 to cMaxHHIndex do |
|
213 |
if Hedgehogs[i].Gear <> nil then |
|
214 |
RenderHealth(Hedgehogs[i]); |
|
215 |
end |
|
216 |
end; |
|
4 | 217 |
|
1185 | 218 |
procedure LoadGraves; |
219 |
var t: LongInt; |
|
220 |
texsurf: PSDL_Surface; |
|
221 |
begin |
|
222 |
for t:= 0 to Pred(TeamsCount) do |
|
223 |
if TeamsArray[t] <> nil then |
|
224 |
with TeamsArray[t]^ do |
|
225 |
begin |
|
226 |
if GraveName = '' then GraveName:= 'Simple'; |
|
227 |
texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, false, true, true); |
|
228 |
GraveTex:= Surface2Tex(texsurf); |
|
229 |
SDL_FreeSurface(texsurf) |
|
230 |
end |
|
231 |
end; |
|
4 | 232 |
|
844 | 233 |
var ii: TSprite; |
234 |
fi: THWFont; |
|
235 |
ai: TAmmoType; |
|
236 |
tmpsurf: PSDL_Surface; |
|
237 |
i: LongInt; |
|
4 | 238 |
begin |
239 |
for fi:= Low(THWFont) to High(THWFont) do |
|
1185 | 240 |
with Fontz[fi] do |
241 |
begin |
|
242 |
s:= Pathz[ptFonts] + '/' + Name; |
|
243 |
WriteToConsole(msgLoading + s + '... '); |
|
244 |
Handle:= TTF_OpenFont(Str2PChar(s), Height); |
|
245 |
SDLTry(Handle <> nil, true); |
|
246 |
TTF_SetFontStyle(Handle, style); |
|
247 |
WriteLnToConsole(msgOK) |
|
248 |
end; |
|
4 | 249 |
AddProgress; |
53 | 250 |
|
4 | 251 |
AddProgress; |
252 |
WriteNames(fnt16); |
|
70 | 253 |
MakeCrossHairs; |
4 | 254 |
LoadGraves; |
255 |
||
256 |
AddProgress; |
|
257 |
for ii:= Low(TSprite) to High(TSprite) do |
|
1185 | 258 |
with SpritesData[ii] do |
259 |
begin |
|
260 |
if AltPath = ptNone then |
|
261 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, true, true, true) |
|
262 |
else begin |
|
263 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, true, false, true); |
|
264 |
if tmpsurf = nil then |
|
265 |
tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, true, true, true) |
|
266 |
end; |
|
267 |
if Width = 0 then Width:= tmpsurf^.w; |
|
268 |
if Height = 0 then Height:= tmpsurf^.h; |
|
269 |
Texture:= Surface2Tex(tmpsurf); |
|
270 |
if saveSurf then Surface:= tmpsurf else SDL_FreeSurface(tmpsurf) |
|
271 |
end; |
|
80 | 272 |
|
4 | 273 |
AddProgress; |
567 | 274 |
|
761 | 275 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, true, true, true); |
276 |
HHTexture:= Surface2Tex(tmpsurf); |
|
277 |
SDL_FreeSurface(tmpsurf); |
|
4 | 278 |
|
279 |
InitHealth; |
|
280 |
||
762 | 281 |
PauseTexture:= RenderStringTex(trmsg[sidPaused], $FFFF00, fntBig); |
1023 | 282 |
ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], $FFFF00, fntBig); |
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
283 |
|
843 | 284 |
for ai:= Low(TAmmoType) to High(TAmmoType) do |
285 |
with Ammoz[ai] do |
|
286 |
begin |
|
287 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(trAmmo[NameId]), $FFFFFF); |
|
288 |
NameTex:= Surface2Tex(tmpsurf); |
|
289 |
SDL_FreeSurface(tmpsurf) |
|
290 |
end; |
|
291 |
||
844 | 292 |
for i:= Low(CountTexz) to High(CountTexz) do |
293 |
begin |
|
294 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), $FFFFFF); |
|
295 |
CountTexz[i]:= Surface2Tex(tmpsurf); |
|
296 |
SDL_FreeSurface(tmpsurf) |
|
297 |
end; |
|
298 |
||
4 | 299 |
{$IFDEF DUMP} |
300 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
301 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
302 |
{$ENDIF} |
|
303 |
end; |
|
304 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
305 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
4 | 306 |
var rr: TSDL_Rect; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
307 |
_l, _r, _t, _b: real; |
4 | 308 |
begin |
759 | 309 |
if SourceTexture^.h = 0 then exit; |
4 | 310 |
rr.x:= X; |
311 |
rr.y:= Y; |
|
351 | 312 |
rr.w:= r^.w; |
313 |
rr.h:= r^.h; |
|
755 | 314 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
315 |
_l:= r^.x / SourceTexture^.w; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
316 |
_r:= (r^.x + r^.w) / SourceTexture^.w; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
317 |
_t:= r^.y / SourceTexture^.h; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
318 |
_b:= (r^.y + r^.h) / SourceTexture^.h; |
755 | 319 |
|
320 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
321 |
||
322 |
glBegin(GL_QUADS); |
|
323 |
||
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
324 |
glTexCoord2f(_l, _t); |
755 | 325 |
glVertex2i(X, Y); |
326 |
||
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
327 |
glTexCoord2f(_r, _t); |
755 | 328 |
glVertex2i(rr.w + X, Y); |
329 |
||
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
330 |
glTexCoord2f(_r, _b); |
755 | 331 |
glVertex2i(rr.w + X, rr.h + Y); |
332 |
||
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
333 |
glTexCoord2f(_l, _b); |
755 | 334 |
glVertex2i(X, rr.h + Y); |
335 |
||
762 | 336 |
glEnd() |
337 |
end; |
|
338 |
||
339 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
|
340 |
begin |
|
341 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
342 |
||
343 |
glBegin(GL_QUADS); |
|
344 |
||
345 |
glTexCoord2f(0, 0); |
|
346 |
glVertex2i(X, Y); |
|
347 |
||
348 |
glTexCoord2f(1, 0); |
|
349 |
glVertex2i(Texture^.w + X, Y); |
|
350 |
||
351 |
glTexCoord2f(1, 1); |
|
352 |
glVertex2i(Texture^.w + X, Texture^.h + Y); |
|
353 |
||
354 |
glTexCoord2f(0, 1); |
|
355 |
glVertex2i(X, Texture^.h + Y); |
|
356 |
||
357 |
glEnd() |
|
4 | 358 |
end; |
359 |
||
1242 | 360 |
procedure DrawTextureF(Texture: PTexture; X, Y, Frame, Dir, Frames: LongInt); |
361 |
var ft, fb: GLfloat; |
|
362 |
hw: LongInt; |
|
363 |
begin |
|
364 |
glPushMatrix; |
|
365 |
glTranslatef(X, Y, 0); |
|
366 |
||
367 |
if Dir < 0 then |
|
368 |
hw:= - 16 |
|
369 |
else |
|
370 |
hw:= 16; |
|
371 |
||
372 |
ft:= Frame / Frames; |
|
373 |
fb:= (Frame + 1) / Frames; |
|
374 |
||
375 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
376 |
||
377 |
glBegin(GL_QUADS); |
|
378 |
||
379 |
glTexCoord2f(0, ft); |
|
380 |
glVertex2i(-hw, -16); |
|
381 |
||
382 |
glTexCoord2f(1, ft); |
|
383 |
glVertex2i(hw, -16); |
|
384 |
||
385 |
glTexCoord2f(1, fb); |
|
386 |
glVertex2i(hw, 16); |
|
387 |
||
388 |
glTexCoord2f(0, fb); |
|
389 |
glVertex2i(-hw, 16); |
|
390 |
||
391 |
glEnd(); |
|
392 |
||
393 |
glPopMatrix |
|
394 |
end; |
|
395 |
||
822 | 396 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
775 | 397 |
begin |
777 | 398 |
DrawRotatedTex(SpritesData[Sprite].Texture, |
822 | 399 |
SpritesData[Sprite].Width, |
400 |
SpritesData[Sprite].Height, |
|
401 |
X, Y, Dir, Angle) |
|
777 | 402 |
end; |
403 |
||
853 | 404 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
806 | 405 |
begin |
406 |
glPushMatrix; |
|
809 | 407 |
glTranslatef(X, Y, 0); |
806 | 408 |
glRotatef(Angle, 0, 0, 1); |
409 |
||
853 | 410 |
if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
411 |
||
412 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
806 | 413 |
|
414 |
glPopMatrix |
|
415 |
end; |
|
416 |
||
822 | 417 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
777 | 418 |
begin |
775 | 419 |
glPushMatrix; |
420 |
glTranslatef(X, Y, 0); |
|
822 | 421 |
|
422 |
if Dir < 0 then |
|
423 |
begin |
|
424 |
hw:= - hw; |
|
425 |
glRotatef(Angle, 0, 0, -1); |
|
426 |
end else |
|
427 |
glRotatef(Angle, 0, 0, 1); |
|
428 |
||
775 | 429 |
|
777 | 430 |
glBindTexture(GL_TEXTURE_2D, Tex^.id); |
775 | 431 |
|
432 |
glBegin(GL_QUADS); |
|
433 |
||
434 |
glTexCoord2f(0, 0); |
|
435 |
glVertex2i(-hw, -hh); |
|
436 |
||
437 |
glTexCoord2f(1, 0); |
|
438 |
glVertex2i(hw, -hh); |
|
439 |
||
440 |
glTexCoord2f(1, 1); |
|
441 |
glVertex2i(hw, hh); |
|
442 |
||
443 |
glTexCoord2f(0, 1); |
|
444 |
glVertex2i(-hw, hh); |
|
445 |
||
446 |
glEnd(); |
|
447 |
||
448 |
glPopMatrix |
|
449 |
end; |
|
450 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
451 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
4 | 452 |
begin |
453 |
r.y:= r.y + Height * Position; |
|
454 |
r.h:= Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
455 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 456 |
end; |
457 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
458 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
755 | 459 |
var r: TSDL_Rect; |
4 | 460 |
begin |
755 | 461 |
r.x:= 0; |
462 |
r.w:= SpritesData[Sprite].Width; |
|
463 |
r.y:= Frame * SpritesData[Sprite].Height; |
|
464 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
465 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 466 |
end; |
467 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
468 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
43 | 469 |
var r: TSDL_Rect; |
470 |
begin |
|
471 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
472 |
r.w:= SpritesData[Sprite].Width; |
|
473 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
474 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
475 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
43 | 476 |
end; |
477 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
478 |
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
|
479 |
var r: TSDL_Rect; |
198 | 480 |
begin |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
481 |
r.x:= 0; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
482 |
r.w:= Source^.w; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
483 |
r.y:= Frame * Height; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
484 |
r.h:= Height; |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
485 |
DrawFromRect(X, Y, @r, Source) |
198 | 486 |
end; |
487 |
||
762 | 488 |
procedure DrawLand(X, Y: LongInt); |
4 | 489 |
begin |
762 | 490 |
DrawTexture(X, Y, LandTexture) |
4 | 491 |
end; |
492 |
||
762 | 493 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
95 | 494 |
begin |
762 | 495 |
DrawTexture(X - Source^.w div 2, Top, Source) |
4 | 496 |
end; |
497 |
||
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
498 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
761 | 499 |
var l, r, t, b: real; |
4 | 500 |
begin |
761 | 501 |
|
502 |
t:= Pos * 32 / HHTexture^.h; |
|
503 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
504 |
||
505 |
if Dir = -1 then |
|
506 |
begin |
|
507 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
508 |
r:= Step * 32 / HHTexture^.w |
|
509 |
end else |
|
510 |
begin |
|
511 |
l:= Step * 32 / HHTexture^.w; |
|
512 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
513 |
end; |
|
514 |
||
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
515 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
516 |
glPushMatrix(); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
517 |
glTranslatef(X, Y, 0); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
518 |
glRotatef(Angle, 0, 0, 1); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
519 |
|
761 | 520 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
521 |
||
522 |
glBegin(GL_QUADS); |
|
523 |
||
524 |
glTexCoord2f(l, t); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
525 |
glVertex2i(-16, -16); |
761 | 526 |
|
527 |
glTexCoord2f(r, t); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
528 |
glVertex2i(16, -16); |
761 | 529 |
|
530 |
glTexCoord2f(r, b); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
531 |
glVertex2i(16, 16); |
761 | 532 |
|
533 |
glTexCoord2f(l, b); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
534 |
glVertex2i(-16, 16); |
761 | 535 |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
536 |
glEnd(); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
537 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
538 |
glPopMatrix |
4 | 539 |
end; |
540 |
||
541 |
procedure StoreRelease; |
|
542 |
var ii: TSprite; |
|
543 |
begin |
|
544 |
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
|
545 |
begin |
759 | 546 |
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
|
547 |
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
|
548 |
end; |
761 | 549 |
|
550 |
FreeTexture(HHTexture); |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1120
diff
changeset
|
551 |
FreeTexture(LandTexture) |
4 | 552 |
end; |
553 |
||
762 | 554 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
432 | 555 |
var w, h: LongInt; |
351 | 556 |
Result: PSDL_Surface; |
95 | 557 |
begin |
355 | 558 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
785 | 559 |
|
762 | 560 |
Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
561 |
32, RMask, GMask, BMask, AMask); |
|
785 | 562 |
|
107 | 563 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
785 | 564 |
|
95 | 565 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
785 | 566 |
|
762 | 567 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
785 | 568 |
|
762 | 569 |
RenderStringTex:= Surface2Tex(Result); |
785 | 570 |
|
762 | 571 |
SDL_FreeSurface(Result) |
95 | 572 |
end; |
573 |
||
4 | 574 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 575 |
var s: shortstring; |
4 | 576 |
begin |
351 | 577 |
str(Hedgehog.Gear^.Health, s); |
762 | 578 |
if Hedgehog.HealthTagTex <> nil then FreeTexture(Hedgehog.HealthTagTex); |
579 |
Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
|
4 | 580 |
end; |
581 |
||
518 | 582 |
function LoadImage(const filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface; |
30 | 583 |
var tmpsurf: PSDL_Surface; |
753 | 584 |
//Result: PSDL_Surface; |
355 | 585 |
s: shortstring; |
4 | 586 |
begin |
587 |
WriteToConsole(msgLoading + filename + '... '); |
|
355 | 588 |
s:= filename + '.' + cBitsStr + '.png'; |
589 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 590 |
|
74 | 591 |
if tmpsurf = nil then |
351 | 592 |
begin |
355 | 593 |
s:= filename + '.png'; |
594 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 595 |
end; |
80 | 596 |
|
597 |
if tmpsurf = nil then |
|
598 |
if critical then OutError(msgFailed, true) |
|
599 |
else begin |
|
600 |
WriteLnToConsole(msgFailed); |
|
351 | 601 |
exit(nil) |
80 | 602 |
end; |
351 | 603 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
604 |
if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
753 | 605 |
//if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
606 |
// else Result:= SDL_DisplayFormat(tmpsurf); |
|
620 | 607 |
{$IFDEF DEBUGFILE}WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') ');{$ENDIF} |
351 | 608 |
WriteLnToConsole(msgOK); |
753 | 609 |
LoadImage:= tmpsurf//Result |
610 |
end; |
|
611 |
||
612 |
procedure SetupOpenGL; |
|
613 |
begin |
|
756 | 614 |
glLoadIdentity; |
753 | 615 |
glViewport(0, 0, cScreenWidth, cScreenHeight); |
754 | 616 |
glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
617 |
glTranslatef(-cScreenWidth / 2, -cScreenHeight / 2, 0); |
|
756 | 618 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
753 | 619 |
glMatrixMode(GL_MODELVIEW) |
4 | 620 |
end; |
621 |
||
510 | 622 |
//////////////////////////////////////////////////////////////////////////////// |
766 | 623 |
var ProgrTex: PTexture = nil; |
534 | 624 |
Step: integer = 0; |
510 | 625 |
|
626 |
procedure AddProgress; |
|
627 |
var r: TSDL_Rect; |
|
766 | 628 |
texsurf: PSDL_Surface; |
510 | 629 |
begin |
630 |
if Step = 0 then |
|
631 |
begin |
|
632 |
WriteToConsole(msgLoading + 'progress sprite: '); |
|
766 | 633 |
texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', false, true, true); |
634 |
ProgrTex:= Surface2Tex(texsurf); |
|
635 |
SDL_FreeSurface(texsurf) |
|
510 | 636 |
end; |
1045 | 637 |
|
766 | 638 |
glClear(GL_COLOR_BUFFER_BIT); |
775 | 639 |
glEnable(GL_TEXTURE_2D); |
510 | 640 |
r.x:= 0; |
766 | 641 |
r.w:= ProgrTex^.w; |
642 |
r.h:= ProgrTex^.w; |
|
643 |
r.y:= (Step mod (ProgrTex^.h div ProgrTex^.w)) * ProgrTex^.w; |
|
644 |
DrawFromRect((cScreenWidth - ProgrTex^.w) div 2, |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
645 |
(cScreenHeight - ProgrTex^.w) div 2, @r, ProgrTex); |
775 | 646 |
glDisable(GL_TEXTURE_2D); |
766 | 647 |
SDL_GL_SwapBuffers(); |
510 | 648 |
inc(Step); |
649 |
end; |
|
650 |
||
651 |
procedure FinishProgress; |
|
652 |
begin |
|
653 |
WriteLnToConsole('Freeing progress surface... '); |
|
766 | 654 |
FreeTexture(ProgrTex) |
510 | 655 |
end; |
656 |
||
4 | 657 |
end. |