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