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