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