author | unc0rr |
Sun, 28 Sep 2008 08:26:18 +0000 | |
changeset 1287 | 4a0cbcbe3521 |
parent 1251 | 1f545d9a10ca |
child 1294 | 50198e5c7f02 |
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); |
|
1251 | 33 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; 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 |
||
1251 | 360 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt); |
1242 | 361 |
var ft, fb: GLfloat; |
362 |
hw: LongInt; |
|
363 |
begin |
|
364 |
glPushMatrix; |
|
365 |
glTranslatef(X, Y, 0); |
|
1251 | 366 |
glScalef(Scale, Scale, 1.0); |
1242 | 367 |
|
368 |
if Dir < 0 then |
|
369 |
hw:= - 16 |
|
370 |
else |
|
371 |
hw:= 16; |
|
372 |
||
373 |
ft:= Frame / Frames; |
|
374 |
fb:= (Frame + 1) / Frames; |
|
375 |
||
376 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
377 |
||
378 |
glBegin(GL_QUADS); |
|
379 |
||
380 |
glTexCoord2f(0, ft); |
|
381 |
glVertex2i(-hw, -16); |
|
382 |
||
383 |
glTexCoord2f(1, ft); |
|
384 |
glVertex2i(hw, -16); |
|
385 |
||
386 |
glTexCoord2f(1, fb); |
|
387 |
glVertex2i(hw, 16); |
|
388 |
||
389 |
glTexCoord2f(0, fb); |
|
390 |
glVertex2i(-hw, 16); |
|
391 |
||
392 |
glEnd(); |
|
393 |
||
394 |
glPopMatrix |
|
395 |
end; |
|
396 |
||
822 | 397 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
775 | 398 |
begin |
777 | 399 |
DrawRotatedTex(SpritesData[Sprite].Texture, |
822 | 400 |
SpritesData[Sprite].Width, |
401 |
SpritesData[Sprite].Height, |
|
402 |
X, Y, Dir, Angle) |
|
777 | 403 |
end; |
404 |
||
853 | 405 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
806 | 406 |
begin |
407 |
glPushMatrix; |
|
809 | 408 |
glTranslatef(X, Y, 0); |
806 | 409 |
glRotatef(Angle, 0, 0, 1); |
410 |
||
853 | 411 |
if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
412 |
||
413 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
806 | 414 |
|
415 |
glPopMatrix |
|
416 |
end; |
|
417 |
||
822 | 418 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
777 | 419 |
begin |
775 | 420 |
glPushMatrix; |
421 |
glTranslatef(X, Y, 0); |
|
822 | 422 |
|
423 |
if Dir < 0 then |
|
424 |
begin |
|
425 |
hw:= - hw; |
|
426 |
glRotatef(Angle, 0, 0, -1); |
|
427 |
end else |
|
428 |
glRotatef(Angle, 0, 0, 1); |
|
429 |
||
775 | 430 |
|
777 | 431 |
glBindTexture(GL_TEXTURE_2D, Tex^.id); |
775 | 432 |
|
433 |
glBegin(GL_QUADS); |
|
434 |
||
435 |
glTexCoord2f(0, 0); |
|
436 |
glVertex2i(-hw, -hh); |
|
437 |
||
438 |
glTexCoord2f(1, 0); |
|
439 |
glVertex2i(hw, -hh); |
|
440 |
||
441 |
glTexCoord2f(1, 1); |
|
442 |
glVertex2i(hw, hh); |
|
443 |
||
444 |
glTexCoord2f(0, 1); |
|
445 |
glVertex2i(-hw, hh); |
|
446 |
||
447 |
glEnd(); |
|
448 |
||
449 |
glPopMatrix |
|
450 |
end; |
|
451 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
452 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
4 | 453 |
begin |
454 |
r.y:= r.y + Height * Position; |
|
455 |
r.h:= Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
456 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 457 |
end; |
458 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
459 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
755 | 460 |
var r: TSDL_Rect; |
4 | 461 |
begin |
755 | 462 |
r.x:= 0; |
463 |
r.w:= SpritesData[Sprite].Width; |
|
464 |
r.y:= Frame * SpritesData[Sprite].Height; |
|
465 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
466 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 467 |
end; |
468 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
469 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
43 | 470 |
var r: TSDL_Rect; |
471 |
begin |
|
472 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
473 |
r.w:= SpritesData[Sprite].Width; |
|
474 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
475 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
476 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
43 | 477 |
end; |
478 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
479 |
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
|
480 |
var r: TSDL_Rect; |
198 | 481 |
begin |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
482 |
r.x:= 0; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
483 |
r.w:= Source^.w; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
484 |
r.y:= Frame * Height; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
485 |
r.h:= Height; |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
486 |
DrawFromRect(X, Y, @r, Source) |
198 | 487 |
end; |
488 |
||
762 | 489 |
procedure DrawLand(X, Y: LongInt); |
4 | 490 |
begin |
762 | 491 |
DrawTexture(X, Y, LandTexture) |
4 | 492 |
end; |
493 |
||
762 | 494 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
95 | 495 |
begin |
762 | 496 |
DrawTexture(X - Source^.w div 2, Top, Source) |
4 | 497 |
end; |
498 |
||
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
499 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
761 | 500 |
var l, r, t, b: real; |
4 | 501 |
begin |
761 | 502 |
|
503 |
t:= Pos * 32 / HHTexture^.h; |
|
504 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
505 |
||
506 |
if Dir = -1 then |
|
507 |
begin |
|
508 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
509 |
r:= Step * 32 / HHTexture^.w |
|
510 |
end else |
|
511 |
begin |
|
512 |
l:= Step * 32 / HHTexture^.w; |
|
513 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
514 |
end; |
|
515 |
||
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
516 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
517 |
glPushMatrix(); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
518 |
glTranslatef(X, Y, 0); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
519 |
glRotatef(Angle, 0, 0, 1); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
520 |
|
761 | 521 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
522 |
||
523 |
glBegin(GL_QUADS); |
|
524 |
||
525 |
glTexCoord2f(l, t); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
526 |
glVertex2i(-16, -16); |
761 | 527 |
|
528 |
glTexCoord2f(r, t); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
529 |
glVertex2i(16, -16); |
761 | 530 |
|
531 |
glTexCoord2f(r, b); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
532 |
glVertex2i(16, 16); |
761 | 533 |
|
534 |
glTexCoord2f(l, b); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
535 |
glVertex2i(-16, 16); |
761 | 536 |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
537 |
glEnd(); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
538 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
539 |
glPopMatrix |
4 | 540 |
end; |
541 |
||
542 |
procedure StoreRelease; |
|
543 |
var ii: TSprite; |
|
544 |
begin |
|
545 |
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
|
546 |
begin |
759 | 547 |
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
|
548 |
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
|
549 |
end; |
761 | 550 |
|
551 |
FreeTexture(HHTexture); |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1120
diff
changeset
|
552 |
FreeTexture(LandTexture) |
4 | 553 |
end; |
554 |
||
762 | 555 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
432 | 556 |
var w, h: LongInt; |
351 | 557 |
Result: PSDL_Surface; |
95 | 558 |
begin |
355 | 559 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
785 | 560 |
|
762 | 561 |
Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
562 |
32, RMask, GMask, BMask, AMask); |
|
785 | 563 |
|
107 | 564 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
785 | 565 |
|
95 | 566 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
785 | 567 |
|
762 | 568 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
785 | 569 |
|
762 | 570 |
RenderStringTex:= Surface2Tex(Result); |
785 | 571 |
|
762 | 572 |
SDL_FreeSurface(Result) |
95 | 573 |
end; |
574 |
||
4 | 575 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 576 |
var s: shortstring; |
4 | 577 |
begin |
351 | 578 |
str(Hedgehog.Gear^.Health, s); |
762 | 579 |
if Hedgehog.HealthTagTex <> nil then FreeTexture(Hedgehog.HealthTagTex); |
580 |
Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
|
4 | 581 |
end; |
582 |
||
518 | 583 |
function LoadImage(const filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface; |
30 | 584 |
var tmpsurf: PSDL_Surface; |
753 | 585 |
//Result: PSDL_Surface; |
355 | 586 |
s: shortstring; |
4 | 587 |
begin |
588 |
WriteToConsole(msgLoading + filename + '... '); |
|
355 | 589 |
s:= filename + '.' + cBitsStr + '.png'; |
590 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 591 |
|
74 | 592 |
if tmpsurf = nil then |
351 | 593 |
begin |
355 | 594 |
s:= filename + '.png'; |
595 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 596 |
end; |
80 | 597 |
|
598 |
if tmpsurf = nil then |
|
599 |
if critical then OutError(msgFailed, true) |
|
600 |
else begin |
|
601 |
WriteLnToConsole(msgFailed); |
|
351 | 602 |
exit(nil) |
80 | 603 |
end; |
351 | 604 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
605 |
if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
753 | 606 |
//if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
607 |
// else Result:= SDL_DisplayFormat(tmpsurf); |
|
620 | 608 |
{$IFDEF DEBUGFILE}WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') ');{$ENDIF} |
351 | 609 |
WriteLnToConsole(msgOK); |
753 | 610 |
LoadImage:= tmpsurf//Result |
611 |
end; |
|
612 |
||
613 |
procedure SetupOpenGL; |
|
614 |
begin |
|
756 | 615 |
glLoadIdentity; |
753 | 616 |
glViewport(0, 0, cScreenWidth, cScreenHeight); |
754 | 617 |
glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
618 |
glTranslatef(-cScreenWidth / 2, -cScreenHeight / 2, 0); |
|
756 | 619 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
753 | 620 |
glMatrixMode(GL_MODELVIEW) |
4 | 621 |
end; |
622 |
||
510 | 623 |
//////////////////////////////////////////////////////////////////////////////// |
766 | 624 |
var ProgrTex: PTexture = nil; |
534 | 625 |
Step: integer = 0; |
510 | 626 |
|
627 |
procedure AddProgress; |
|
628 |
var r: TSDL_Rect; |
|
766 | 629 |
texsurf: PSDL_Surface; |
510 | 630 |
begin |
631 |
if Step = 0 then |
|
632 |
begin |
|
633 |
WriteToConsole(msgLoading + 'progress sprite: '); |
|
766 | 634 |
texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', false, true, true); |
635 |
ProgrTex:= Surface2Tex(texsurf); |
|
636 |
SDL_FreeSurface(texsurf) |
|
510 | 637 |
end; |
1045 | 638 |
|
766 | 639 |
glClear(GL_COLOR_BUFFER_BIT); |
775 | 640 |
glEnable(GL_TEXTURE_2D); |
510 | 641 |
r.x:= 0; |
766 | 642 |
r.w:= ProgrTex^.w; |
643 |
r.h:= ProgrTex^.w; |
|
644 |
r.y:= (Step mod (ProgrTex^.h div ProgrTex^.w)) * ProgrTex^.w; |
|
645 |
DrawFromRect((cScreenWidth - ProgrTex^.w) div 2, |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
646 |
(cScreenHeight - ProgrTex^.w) div 2, @r, ProgrTex); |
775 | 647 |
glDisable(GL_TEXTURE_2D); |
766 | 648 |
SDL_GL_SwapBuffers(); |
510 | 649 |
inc(Step); |
650 |
end; |
|
651 |
||
652 |
procedure FinishProgress; |
|
653 |
begin |
|
654 |
WriteLnToConsole('Freeing progress surface... '); |
|
766 | 655 |
FreeTexture(ProgrTex) |
510 | 656 |
end; |
657 |
||
4 | 658 |
end. |