author | unc0rr |
Sun, 15 Mar 2009 14:47:59 +0000 | |
changeset 1894 | ba54441631da |
parent 1865 | ebc6dfca60d4 |
child 1896 | fdacad5d0acc |
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); |
1865
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1854
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 |
||
1865
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1854
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 |
|
1854 | 537 |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
538 |
glEnd(); |
1854 | 539 |
glColor4f(1,1,1,1); |
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
540 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
541 |
glPopMatrix |
4 | 542 |
end; |
543 |
||
1431 | 544 |
procedure DrawFillRect(r: TSDL_Rect); |
545 |
begin |
|
546 |
glDisable(GL_TEXTURE_2D); |
|
547 |
||
548 |
glColor4ub(0, 0, 0, 127); |
|
549 |
||
550 |
glBegin(GL_QUADS); |
|
551 |
||
552 |
glVertex2i(r.x , r.y ); |
|
553 |
glVertex2i(r.x + r.w , r.y ); |
|
554 |
glVertex2i(r.x + r.w , r.y + r.h); |
|
555 |
glVertex2i(r.x , r.y + r.h); |
|
556 |
||
557 |
glEnd(); |
|
558 |
||
559 |
glColor4f(1, 1, 1, 1); |
|
560 |
glEnable(GL_TEXTURE_2D) |
|
561 |
end; |
|
562 |
||
4 | 563 |
procedure StoreRelease; |
564 |
var ii: TSprite; |
|
565 |
begin |
|
566 |
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
|
567 |
begin |
759 | 568 |
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
|
569 |
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
|
570 |
end; |
761 | 571 |
|
1806 | 572 |
FreeTexture(HHTexture) |
4 | 573 |
end; |
574 |
||
762 | 575 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
432 | 576 |
var w, h: LongInt; |
351 | 577 |
Result: PSDL_Surface; |
95 | 578 |
begin |
355 | 579 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
785 | 580 |
|
762 | 581 |
Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
582 |
32, RMask, GMask, BMask, AMask); |
|
785 | 583 |
|
107 | 584 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
785 | 585 |
|
95 | 586 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
785 | 587 |
|
762 | 588 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
785 | 589 |
|
762 | 590 |
RenderStringTex:= Surface2Tex(Result); |
785 | 591 |
|
762 | 592 |
SDL_FreeSurface(Result) |
95 | 593 |
end; |
594 |
||
4 | 595 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 596 |
var s: shortstring; |
4 | 597 |
begin |
351 | 598 |
str(Hedgehog.Gear^.Health, s); |
762 | 599 |
if Hedgehog.HealthTagTex <> nil then FreeTexture(Hedgehog.HealthTagTex); |
600 |
Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
|
4 | 601 |
end; |
602 |
||
518 | 603 |
function LoadImage(const filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface; |
30 | 604 |
var tmpsurf: PSDL_Surface; |
753 | 605 |
//Result: PSDL_Surface; |
355 | 606 |
s: shortstring; |
4 | 607 |
begin |
608 |
WriteToConsole(msgLoading + filename + '... '); |
|
355 | 609 |
s:= filename + '.' + cBitsStr + '.png'; |
610 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 611 |
|
74 | 612 |
if tmpsurf = nil then |
351 | 613 |
begin |
355 | 614 |
s:= filename + '.png'; |
615 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 616 |
end; |
80 | 617 |
|
618 |
if tmpsurf = nil then |
|
619 |
if critical then OutError(msgFailed, true) |
|
620 |
else begin |
|
621 |
WriteLnToConsole(msgFailed); |
|
351 | 622 |
exit(nil) |
80 | 623 |
end; |
351 | 624 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
625 |
if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
753 | 626 |
//if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
627 |
// else Result:= SDL_DisplayFormat(tmpsurf); |
|
620 | 628 |
{$IFDEF DEBUGFILE}WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') ');{$ENDIF} |
351 | 629 |
WriteLnToConsole(msgOK); |
753 | 630 |
LoadImage:= tmpsurf//Result |
631 |
end; |
|
632 |
||
633 |
procedure SetupOpenGL; |
|
634 |
begin |
|
756 | 635 |
glLoadIdentity; |
753 | 636 |
glViewport(0, 0, cScreenWidth, cScreenHeight); |
754 | 637 |
glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
638 |
glTranslatef(-cScreenWidth / 2, -cScreenHeight / 2, 0); |
|
756 | 639 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
753 | 640 |
glMatrixMode(GL_MODELVIEW) |
4 | 641 |
end; |
642 |
||
510 | 643 |
//////////////////////////////////////////////////////////////////////////////// |
766 | 644 |
var ProgrTex: PTexture = nil; |
534 | 645 |
Step: integer = 0; |
510 | 646 |
|
647 |
procedure AddProgress; |
|
648 |
var r: TSDL_Rect; |
|
766 | 649 |
texsurf: PSDL_Surface; |
510 | 650 |
begin |
651 |
if Step = 0 then |
|
652 |
begin |
|
653 |
WriteToConsole(msgLoading + 'progress sprite: '); |
|
766 | 654 |
texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', false, true, true); |
655 |
ProgrTex:= Surface2Tex(texsurf); |
|
656 |
SDL_FreeSurface(texsurf) |
|
510 | 657 |
end; |
1045 | 658 |
|
766 | 659 |
glClear(GL_COLOR_BUFFER_BIT); |
775 | 660 |
glEnable(GL_TEXTURE_2D); |
510 | 661 |
r.x:= 0; |
766 | 662 |
r.w:= ProgrTex^.w; |
663 |
r.h:= ProgrTex^.w; |
|
664 |
r.y:= (Step mod (ProgrTex^.h div ProgrTex^.w)) * ProgrTex^.w; |
|
665 |
DrawFromRect((cScreenWidth - ProgrTex^.w) div 2, |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
666 |
(cScreenHeight - ProgrTex^.w) div 2, @r, ProgrTex); |
775 | 667 |
glDisable(GL_TEXTURE_2D); |
766 | 668 |
SDL_GL_SwapBuffers(); |
510 | 669 |
inc(Step); |
670 |
end; |
|
671 |
||
672 |
procedure FinishProgress; |
|
673 |
begin |
|
674 |
WriteLnToConsole('Freeing progress surface... '); |
|
766 | 675 |
FreeTexture(ProgrTex) |
510 | 676 |
end; |
677 |
||
4 | 678 |
end. |