author | unc0rr |
Mon, 26 Jan 2009 15:53:43 +0000 | |
changeset 1760 | 55a1edd97911 |
parent 1698 | 993c42413387 |
child 1805 | dd9fb4b13fd8 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
19 |
unit uStore; |
|
20 |
interface |
|
755 | 21 |
uses uConsts, uTeams, SDLh, uFloat, GL; |
4 | 22 |
{$INCLUDE options.inc} |
23 |
||
24 |
procedure StoreInit; |
|
25 |
procedure StoreLoad; |
|
26 |
procedure StoreRelease; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
27 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
28 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
29 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
30 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture); |
762 | 31 |
procedure DrawLand (X, Y: LongInt); |
32 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
|
1251 | 33 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt); |
822 | 34 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
853 | 35 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
822 | 36 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
762 | 37 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
38 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
39 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1431 | 40 |
procedure DrawFillRect(r: TSDL_Rect); |
762 | 41 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
4 | 42 |
procedure RenderHealth(var Hedgehog: THedgehog); |
43 |
procedure AddProgress; |
|
510 | 44 |
procedure FinishProgress; |
518 | 45 |
function LoadImage(const filename: string; hasAlpha, critical, setTransparent: boolean): PSDL_Surface; |
753 | 46 |
procedure SetupOpenGL; |
4 | 47 |
|
1525 | 48 |
var PixelFormat: PSDL_PixelFormat = nil; |
49 |
SDLPrimSurface: PSDL_Surface = nil; |
|
1023 | 50 |
PauseTexture, |
51 |
ConfirmTexture: PTexture; |
|
4 | 52 |
|
53 |
implementation |
|
755 | 54 |
uses uMisc, uConsole, uLand, uLocale, GLU; |
4 | 55 |
|
690 | 56 |
var |
761 | 57 |
HHTexture: PTexture; |
4 | 58 |
|
59 |
procedure StoreInit; |
|
60 |
begin |
|
61 |
||
62 |
end; |
|
63 |
||
351 | 64 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
47 | 65 |
var r: TSDL_Rect; |
66 |
begin |
|
67 |
r:= rect^; |
|
83 | 68 |
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
|
69 |
|
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
70 |
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
|
71 |
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
|
72 |
|
351 | 73 |
r.y:= rect^.y + 1; |
74 |
r.h:= rect^.h - 2; |
|
47 | 75 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 76 |
r.x:= rect^.x + 1; |
77 |
r.w:= rect^.w - 2; |
|
78 |
r.y:= rect^.y; |
|
79 |
r.h:= rect^.h; |
|
47 | 80 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 81 |
r.x:= rect^.x + 2; |
82 |
r.y:= rect^.y + 1; |
|
83 |
r.w:= rect^.w - 4; |
|
84 |
r.h:= rect^.h - 2; |
|
47 | 85 |
SDL_FillRect(Surface, @r, FillColor); |
351 | 86 |
r.x:= rect^.x + 1; |
87 |
r.y:= rect^.y + 2; |
|
88 |
r.w:= rect^.w - 2; |
|
89 |
r.h:= rect^.h - 4; |
|
47 | 90 |
SDL_FillRect(Surface, @r, FillColor) |
91 |
end; |
|
92 |
||
371 | 93 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
351 | 94 |
var w, h: LongInt; |
4 | 95 |
tmpsurf: PSDL_Surface; |
96 |
clr: TSDL_Color; |
|
351 | 97 |
Result: TSDL_Rect; |
4 | 98 |
begin |
355 | 99 |
TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
4 | 100 |
Result.x:= X; |
101 |
Result.y:= Y; |
|
202 | 102 |
Result.w:= w + FontBorder * 2 + 4; |
103 |
Result.h:= h + FontBorder * 2; |
|
351 | 104 |
DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface, true); |
189 | 105 |
clr.r:= Color shr 16; |
106 |
clr.g:= (Color shr 8) and $FF; |
|
107 |
clr.b:= Color and $FF; |
|
355 | 108 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr.value); |
202 | 109 |
Result.x:= X + FontBorder + 2; |
110 |
Result.y:= Y + FontBorder; |
|
199 | 111 |
SDLTry(tmpsurf <> nil, true); |
4 | 112 |
SDL_UpperBlit(tmpsurf, nil, Surface, @Result); |
113 |
SDL_FreeSurface(tmpsurf); |
|
114 |
Result.x:= X; |
|
115 |
Result.y:= Y; |
|
202 | 116 |
Result.w:= w + FontBorder * 2 + 4; |
351 | 117 |
Result.h:= h + FontBorder * 2; |
118 |
WriteInRoundRect:= Result |
|
4 | 119 |
end; |
120 |
||
121 |
procedure StoreLoad; |
|
844 | 122 |
var s: string; |
4 | 123 |
|
1185 | 124 |
procedure WriteNames(Font: THWFont); |
125 |
var t: LongInt; |
|
126 |
i: LongInt; |
|
127 |
r, rr: TSDL_Rect; |
|
128 |
drY: LongInt; |
|
129 |
texsurf: PSDL_Surface; |
|
130 |
begin |
|
131 |
r.x:= 0; |
|
132 |
r.y:= 0; |
|
133 |
drY:= - 4; |
|
134 |
for t:= 0 to Pred(TeamsCount) do |
|
135 |
with TeamsArray[t]^ do |
|
136 |
begin |
|
137 |
NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font); |
|
690 | 138 |
|
1185 | 139 |
r.w:= cTeamHealthWidth + 5; |
140 |
r.h:= NameTagTex^.h; |
|
690 | 141 |
|
1185 | 142 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
143 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
144 |
TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
690 | 145 |
|
1185 | 146 |
DrawRoundRect(@r, cWhiteColor, cColorNearBlack, texsurf, true); |
147 |
rr:= r; |
|
148 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
|
149 |
DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false); |
|
150 |
HealthTex:= Surface2Tex(texsurf); |
|
151 |
SDL_FreeSurface(texsurf); |
|
690 | 152 |
|
1185 | 153 |
dec(drY, r.h + 2); |
154 |
DrawHealthY:= drY; |
|
155 |
for i:= 0 to 7 do |
|
156 |
with Hedgehogs[i] do |
|
157 |
if Gear <> nil then |
|
1242 | 158 |
begin |
1185 | 159 |
NameTagTex:= RenderStringTex(Name, Clan^.Color, fnt16); |
1294
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
160 |
if Hat <> 'NoHat' then |
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
161 |
begin |
1698 | 162 |
texsurf:= LoadImage(Pathz[ptHats] + '/' + Hat, false, false, false); |
163 |
if texsurf <> nil then |
|
164 |
begin |
|
165 |
HatTex:= Surface2Tex(texsurf); |
|
166 |
SDL_FreeSurface(texsurf) |
|
167 |
end |
|
1294
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
168 |
end |
1242 | 169 |
end; |
1185 | 170 |
end; |
171 |
end; |
|
4 | 172 |
|
1185 | 173 |
procedure MakeCrossHairs; |
174 |
var t: LongInt; |
|
175 |
tmpsurf, texsurf: PSDL_Surface; |
|
176 |
Color, i: Longword; |
|
177 |
begin |
|
178 |
s:= Pathz[ptGraphics] + '/' + cCHFileName; |
|
179 |
tmpsurf:= LoadImage(s, true, true, false); |
|
4 | 180 |
|
1185 | 181 |
for t:= 0 to Pred(TeamsCount) do |
182 |
with TeamsArray[t]^ do |
|
183 |
begin |
|
184 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask); |
|
185 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
186 |
|
1185 | 187 |
Color:= Clan^.Color; |
188 |
Color:= SDL_MapRGB(texsurf^.format, Color shr 16, Color shr 8, Color and $FF); |
|
189 |
SDL_FillRect(texsurf, nil, Color); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
190 |
|
1185 | 191 |
SDL_UpperBlit(tmpsurf, nil, texsurf, nil); |
777 | 192 |
|
1185 | 193 |
TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Ooops', true); |
777 | 194 |
|
1185 | 195 |
if SDL_MustLock(texsurf) then |
196 |
SDLTry(SDL_LockSurface(texsurf) >= 0, true); |
|
777 | 197 |
|
1185 | 198 |
// make black pixel be alpha-transparent |
199 |
for i:= 0 to texsurf^.w * texsurf^.h - 1 do |
|
200 |
if PLongwordArray(texsurf^.pixels)^[i] = $FF000000 then PLongwordArray(texsurf^.pixels)^[i]:= 0; |
|
777 | 201 |
|
1185 | 202 |
if SDL_MustLock(texsurf) then |
203 |
SDL_UnlockSurface(texsurf); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
204 |
|
1185 | 205 |
CrosshairTex:= Surface2Tex(texsurf); |
206 |
SDL_FreeSurface(texsurf) |
|
207 |
end; |
|
351 | 208 |
|
1185 | 209 |
SDL_FreeSurface(tmpsurf) |
210 |
end; |
|
4 | 211 |
|
1185 | 212 |
procedure InitHealth; |
213 |
var i, t: LongInt; |
|
214 |
begin |
|
215 |
for t:= 0 to Pred(TeamsCount) do |
|
216 |
if TeamsArray[t] <> nil then |
|
217 |
with TeamsArray[t]^ do |
|
218 |
begin |
|
219 |
for i:= 0 to cMaxHHIndex do |
|
220 |
if Hedgehogs[i].Gear <> nil then |
|
221 |
RenderHealth(Hedgehogs[i]); |
|
222 |
end |
|
223 |
end; |
|
4 | 224 |
|
1185 | 225 |
procedure LoadGraves; |
226 |
var t: LongInt; |
|
227 |
texsurf: PSDL_Surface; |
|
228 |
begin |
|
229 |
for t:= 0 to Pred(TeamsCount) do |
|
230 |
if TeamsArray[t] <> nil then |
|
231 |
with TeamsArray[t]^ do |
|
232 |
begin |
|
233 |
if GraveName = '' then GraveName:= 'Simple'; |
|
234 |
texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, false, true, true); |
|
235 |
GraveTex:= Surface2Tex(texsurf); |
|
236 |
SDL_FreeSurface(texsurf) |
|
237 |
end |
|
238 |
end; |
|
4 | 239 |
|
844 | 240 |
var ii: TSprite; |
241 |
fi: THWFont; |
|
242 |
ai: TAmmoType; |
|
243 |
tmpsurf: PSDL_Surface; |
|
244 |
i: LongInt; |
|
4 | 245 |
begin |
246 |
for fi:= Low(THWFont) to High(THWFont) do |
|
1185 | 247 |
with Fontz[fi] do |
248 |
begin |
|
249 |
s:= Pathz[ptFonts] + '/' + Name; |
|
250 |
WriteToConsole(msgLoading + s + '... '); |
|
251 |
Handle:= TTF_OpenFont(Str2PChar(s), Height); |
|
252 |
SDLTry(Handle <> nil, true); |
|
253 |
TTF_SetFontStyle(Handle, style); |
|
254 |
WriteLnToConsole(msgOK) |
|
255 |
end; |
|
4 | 256 |
AddProgress; |
53 | 257 |
|
4 | 258 |
WriteNames(fnt16); |
70 | 259 |
MakeCrossHairs; |
4 | 260 |
LoadGraves; |
261 |
||
262 |
AddProgress; |
|
263 |
for ii:= Low(TSprite) to High(TSprite) do |
|
1185 | 264 |
with SpritesData[ii] do |
265 |
begin |
|
266 |
if AltPath = ptNone then |
|
267 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, true, true, true) |
|
268 |
else begin |
|
269 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, true, false, true); |
|
270 |
if tmpsurf = nil then |
|
271 |
tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, true, true, true) |
|
272 |
end; |
|
273 |
if Width = 0 then Width:= tmpsurf^.w; |
|
274 |
if Height = 0 then Height:= tmpsurf^.h; |
|
275 |
Texture:= Surface2Tex(tmpsurf); |
|
276 |
if saveSurf then Surface:= tmpsurf else SDL_FreeSurface(tmpsurf) |
|
277 |
end; |
|
80 | 278 |
|
4 | 279 |
AddProgress; |
567 | 280 |
|
761 | 281 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, true, true, true); |
282 |
HHTexture:= Surface2Tex(tmpsurf); |
|
283 |
SDL_FreeSurface(tmpsurf); |
|
4 | 284 |
|
285 |
InitHealth; |
|
286 |
||
762 | 287 |
PauseTexture:= RenderStringTex(trmsg[sidPaused], $FFFF00, fntBig); |
1023 | 288 |
ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], $FFFF00, fntBig); |
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
289 |
|
843 | 290 |
for ai:= Low(TAmmoType) to High(TAmmoType) do |
291 |
with Ammoz[ai] do |
|
292 |
begin |
|
293 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(trAmmo[NameId]), $FFFFFF); |
|
294 |
NameTex:= Surface2Tex(tmpsurf); |
|
295 |
SDL_FreeSurface(tmpsurf) |
|
296 |
end; |
|
297 |
||
844 | 298 |
for i:= Low(CountTexz) to High(CountTexz) do |
299 |
begin |
|
300 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), $FFFFFF); |
|
301 |
CountTexz[i]:= Surface2Tex(tmpsurf); |
|
302 |
SDL_FreeSurface(tmpsurf) |
|
303 |
end; |
|
304 |
||
4 | 305 |
{$IFDEF DUMP} |
306 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
307 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
308 |
{$ENDIF} |
|
309 |
end; |
|
310 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
311 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
4 | 312 |
var rr: TSDL_Rect; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
313 |
_l, _r, _t, _b: real; |
4 | 314 |
begin |
759 | 315 |
if SourceTexture^.h = 0 then exit; |
4 | 316 |
rr.x:= X; |
317 |
rr.y:= Y; |
|
351 | 318 |
rr.w:= r^.w; |
319 |
rr.h:= r^.h; |
|
755 | 320 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
321 |
_l:= r^.x / SourceTexture^.w; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
322 |
_r:= (r^.x + r^.w) / SourceTexture^.w; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
323 |
_t:= r^.y / SourceTexture^.h; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
324 |
_b:= (r^.y + r^.h) / SourceTexture^.h; |
755 | 325 |
|
326 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
327 |
||
328 |
glBegin(GL_QUADS); |
|
329 |
||
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
330 |
glTexCoord2f(_l, _t); |
755 | 331 |
glVertex2i(X, Y); |
332 |
||
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
333 |
glTexCoord2f(_r, _t); |
755 | 334 |
glVertex2i(rr.w + X, Y); |
335 |
||
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
336 |
glTexCoord2f(_r, _b); |
755 | 337 |
glVertex2i(rr.w + X, rr.h + Y); |
338 |
||
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
339 |
glTexCoord2f(_l, _b); |
755 | 340 |
glVertex2i(X, rr.h + Y); |
341 |
||
762 | 342 |
glEnd() |
343 |
end; |
|
344 |
||
345 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
|
346 |
begin |
|
347 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
348 |
||
349 |
glBegin(GL_QUADS); |
|
350 |
||
351 |
glTexCoord2f(0, 0); |
|
352 |
glVertex2i(X, Y); |
|
353 |
||
354 |
glTexCoord2f(1, 0); |
|
355 |
glVertex2i(Texture^.w + X, Y); |
|
356 |
||
357 |
glTexCoord2f(1, 1); |
|
358 |
glVertex2i(Texture^.w + X, Texture^.h + Y); |
|
359 |
||
360 |
glTexCoord2f(0, 1); |
|
361 |
glVertex2i(X, Texture^.h + Y); |
|
362 |
||
363 |
glEnd() |
|
4 | 364 |
end; |
365 |
||
1251 | 366 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt); |
1242 | 367 |
var ft, fb: GLfloat; |
368 |
hw: LongInt; |
|
369 |
begin |
|
370 |
glPushMatrix; |
|
371 |
glTranslatef(X, Y, 0); |
|
1251 | 372 |
glScalef(Scale, Scale, 1.0); |
1242 | 373 |
|
374 |
if Dir < 0 then |
|
375 |
hw:= - 16 |
|
376 |
else |
|
377 |
hw:= 16; |
|
378 |
||
379 |
ft:= Frame / Frames; |
|
380 |
fb:= (Frame + 1) / Frames; |
|
381 |
||
382 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
383 |
||
384 |
glBegin(GL_QUADS); |
|
385 |
||
386 |
glTexCoord2f(0, ft); |
|
387 |
glVertex2i(-hw, -16); |
|
388 |
||
389 |
glTexCoord2f(1, ft); |
|
390 |
glVertex2i(hw, -16); |
|
391 |
||
392 |
glTexCoord2f(1, fb); |
|
393 |
glVertex2i(hw, 16); |
|
394 |
||
395 |
glTexCoord2f(0, fb); |
|
396 |
glVertex2i(-hw, 16); |
|
397 |
||
398 |
glEnd(); |
|
399 |
||
400 |
glPopMatrix |
|
401 |
end; |
|
402 |
||
822 | 403 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
775 | 404 |
begin |
777 | 405 |
DrawRotatedTex(SpritesData[Sprite].Texture, |
822 | 406 |
SpritesData[Sprite].Width, |
407 |
SpritesData[Sprite].Height, |
|
408 |
X, Y, Dir, Angle) |
|
777 | 409 |
end; |
410 |
||
853 | 411 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
806 | 412 |
begin |
413 |
glPushMatrix; |
|
809 | 414 |
glTranslatef(X, Y, 0); |
806 | 415 |
glRotatef(Angle, 0, 0, 1); |
416 |
||
853 | 417 |
if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
418 |
||
419 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
806 | 420 |
|
421 |
glPopMatrix |
|
422 |
end; |
|
423 |
||
822 | 424 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
777 | 425 |
begin |
775 | 426 |
glPushMatrix; |
427 |
glTranslatef(X, Y, 0); |
|
822 | 428 |
|
429 |
if Dir < 0 then |
|
430 |
begin |
|
431 |
hw:= - hw; |
|
432 |
glRotatef(Angle, 0, 0, -1); |
|
433 |
end else |
|
434 |
glRotatef(Angle, 0, 0, 1); |
|
435 |
||
775 | 436 |
|
777 | 437 |
glBindTexture(GL_TEXTURE_2D, Tex^.id); |
775 | 438 |
|
439 |
glBegin(GL_QUADS); |
|
440 |
||
441 |
glTexCoord2f(0, 0); |
|
442 |
glVertex2i(-hw, -hh); |
|
443 |
||
444 |
glTexCoord2f(1, 0); |
|
445 |
glVertex2i(hw, -hh); |
|
446 |
||
447 |
glTexCoord2f(1, 1); |
|
448 |
glVertex2i(hw, hh); |
|
449 |
||
450 |
glTexCoord2f(0, 1); |
|
451 |
glVertex2i(-hw, hh); |
|
452 |
||
453 |
glEnd(); |
|
454 |
||
455 |
glPopMatrix |
|
456 |
end; |
|
457 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
458 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
4 | 459 |
begin |
460 |
r.y:= r.y + Height * Position; |
|
461 |
r.h:= Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
462 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 463 |
end; |
464 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
465 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
755 | 466 |
var r: TSDL_Rect; |
4 | 467 |
begin |
755 | 468 |
r.x:= 0; |
469 |
r.w:= SpritesData[Sprite].Width; |
|
470 |
r.y:= Frame * SpritesData[Sprite].Height; |
|
471 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
472 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 473 |
end; |
474 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
475 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
43 | 476 |
var r: TSDL_Rect; |
477 |
begin |
|
478 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
479 |
r.w:= SpritesData[Sprite].Width; |
|
480 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
481 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
482 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
43 | 483 |
end; |
484 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
485 |
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
|
486 |
var r: TSDL_Rect; |
198 | 487 |
begin |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
488 |
r.x:= 0; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
489 |
r.w:= Source^.w; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
490 |
r.y:= Frame * Height; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
491 |
r.h:= Height; |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
492 |
DrawFromRect(X, Y, @r, Source) |
198 | 493 |
end; |
494 |
||
762 | 495 |
procedure DrawLand(X, Y: LongInt); |
4 | 496 |
begin |
762 | 497 |
DrawTexture(X, Y, LandTexture) |
4 | 498 |
end; |
499 |
||
762 | 500 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
95 | 501 |
begin |
762 | 502 |
DrawTexture(X - Source^.w div 2, Top, Source) |
4 | 503 |
end; |
504 |
||
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
505 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
761 | 506 |
var l, r, t, b: real; |
4 | 507 |
begin |
761 | 508 |
|
509 |
t:= Pos * 32 / HHTexture^.h; |
|
510 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
511 |
||
512 |
if Dir = -1 then |
|
513 |
begin |
|
514 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
515 |
r:= Step * 32 / HHTexture^.w |
|
516 |
end else |
|
517 |
begin |
|
518 |
l:= Step * 32 / HHTexture^.w; |
|
519 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
520 |
end; |
|
521 |
||
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
522 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
523 |
glPushMatrix(); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
524 |
glTranslatef(X, Y, 0); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
525 |
glRotatef(Angle, 0, 0, 1); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
526 |
|
761 | 527 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
528 |
||
529 |
glBegin(GL_QUADS); |
|
530 |
||
531 |
glTexCoord2f(l, 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, t); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
535 |
glVertex2i(16, -16); |
761 | 536 |
|
537 |
glTexCoord2f(r, b); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
538 |
glVertex2i(16, 16); |
761 | 539 |
|
540 |
glTexCoord2f(l, b); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
541 |
glVertex2i(-16, 16); |
761 | 542 |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
543 |
glEnd(); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
544 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
545 |
glPopMatrix |
4 | 546 |
end; |
547 |
||
1431 | 548 |
procedure DrawFillRect(r: TSDL_Rect); |
549 |
begin |
|
550 |
glDisable(GL_TEXTURE_2D); |
|
551 |
||
552 |
glColor4ub(0, 0, 0, 127); |
|
553 |
||
554 |
glBegin(GL_QUADS); |
|
555 |
||
556 |
glVertex2i(r.x , r.y ); |
|
557 |
glVertex2i(r.x + r.w , r.y ); |
|
558 |
glVertex2i(r.x + r.w , r.y + r.h); |
|
559 |
glVertex2i(r.x , r.y + r.h); |
|
560 |
||
561 |
glEnd(); |
|
562 |
||
563 |
glColor4f(1, 1, 1, 1); |
|
564 |
glEnable(GL_TEXTURE_2D) |
|
565 |
end; |
|
566 |
||
4 | 567 |
procedure StoreRelease; |
568 |
var ii: TSprite; |
|
569 |
begin |
|
570 |
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
|
571 |
begin |
759 | 572 |
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
|
573 |
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
|
574 |
end; |
761 | 575 |
|
576 |
FreeTexture(HHTexture); |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1120
diff
changeset
|
577 |
FreeTexture(LandTexture) |
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. |