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