author | unc0rr |
Sun, 22 Mar 2009 14:32:22 +0000 | |
changeset 1906 | 644f93d8f148 |
parent 1904 | 20348675b015 |
child 1908 | 5be17e24751a |
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); |
|
1904 | 351 |
var VertexBuffer, TextureBuffer: array [0..5] of TVertex2f; |
762 | 352 |
begin |
1904 | 353 |
glPushMatrix; |
354 |
glTranslatef(X, Y, 0); |
|
355 |
||
762 | 356 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
357 |
||
1904 | 358 |
VertexBuffer[0].X:= 0; |
359 |
VertexBuffer[0].Y:= 0; |
|
360 |
VertexBuffer[1].X:= Texture^.w; |
|
361 |
VertexBuffer[1].Y:= 0; |
|
362 |
VertexBuffer[2].X:= Texture^.w; |
|
363 |
VertexBuffer[2].Y:= Texture^.h; |
|
364 |
VertexBuffer[3].X:= 0; |
|
365 |
VertexBuffer[3].Y:= Texture^.h; |
|
366 |
VertexBuffer[4]:= VertexBuffer[0]; |
|
367 |
VertexBuffer[5]:= VertexBuffer[2]; |
|
762 | 368 |
|
1904 | 369 |
TextureBuffer[0].X:= 0; |
370 |
TextureBuffer[0].Y:= 0; |
|
371 |
TextureBuffer[1].X:= Texture^.rx; |
|
372 |
TextureBuffer[1].Y:= 0; |
|
373 |
TextureBuffer[2].X:= Texture^.rx; |
|
374 |
TextureBuffer[2].Y:= Texture^.ry; |
|
375 |
TextureBuffer[3].X:= 0; |
|
376 |
TextureBuffer[3].Y:= Texture^.ry; |
|
377 |
TextureBuffer[4]:= TextureBuffer[0]; |
|
378 |
TextureBuffer[5]:= TextureBuffer[2]; |
|
762 | 379 |
|
1904 | 380 |
glEnableClientState(GL_VERTEX_ARRAY); |
381 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
762 | 382 |
|
1904 | 383 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
384 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
385 |
glDrawArrays(GL_TRIANGLES, 0, Length(VertexBuffer)); |
|
386 |
||
387 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
388 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
389 |
||
390 |
glPopMatrix |
|
4 | 391 |
end; |
392 |
||
1251 | 393 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt); |
1242 | 394 |
var ft, fb: GLfloat; |
395 |
hw: LongInt; |
|
396 |
begin |
|
397 |
glPushMatrix; |
|
398 |
glTranslatef(X, Y, 0); |
|
1251 | 399 |
glScalef(Scale, Scale, 1.0); |
1242 | 400 |
|
401 |
if Dir < 0 then |
|
402 |
hw:= - 16 |
|
403 |
else |
|
404 |
hw:= 16; |
|
405 |
||
1896 | 406 |
ft:= Frame / Frames * Texture^.ry; |
407 |
fb:= (Frame + 1) / Frames * Texture^.ry; |
|
1242 | 408 |
|
409 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
410 |
||
411 |
glBegin(GL_QUADS); |
|
412 |
||
413 |
glTexCoord2f(0, ft); |
|
414 |
glVertex2i(-hw, -16); |
|
415 |
||
1896 | 416 |
glTexCoord2f(Texture^.rx, ft); |
1242 | 417 |
glVertex2i(hw, -16); |
418 |
||
1896 | 419 |
glTexCoord2f(Texture^.rx, fb); |
1242 | 420 |
glVertex2i(hw, 16); |
421 |
||
422 |
glTexCoord2f(0, fb); |
|
423 |
glVertex2i(-hw, 16); |
|
424 |
||
425 |
glEnd(); |
|
426 |
||
427 |
glPopMatrix |
|
428 |
end; |
|
429 |
||
822 | 430 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
775 | 431 |
begin |
777 | 432 |
DrawRotatedTex(SpritesData[Sprite].Texture, |
822 | 433 |
SpritesData[Sprite].Width, |
434 |
SpritesData[Sprite].Height, |
|
435 |
X, Y, Dir, Angle) |
|
777 | 436 |
end; |
437 |
||
853 | 438 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
806 | 439 |
begin |
440 |
glPushMatrix; |
|
809 | 441 |
glTranslatef(X, Y, 0); |
806 | 442 |
glRotatef(Angle, 0, 0, 1); |
443 |
||
853 | 444 |
if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
445 |
||
446 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
806 | 447 |
|
448 |
glPopMatrix |
|
449 |
end; |
|
450 |
||
822 | 451 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
777 | 452 |
begin |
775 | 453 |
glPushMatrix; |
454 |
glTranslatef(X, Y, 0); |
|
822 | 455 |
|
456 |
if Dir < 0 then |
|
457 |
begin |
|
458 |
hw:= - hw; |
|
459 |
glRotatef(Angle, 0, 0, -1); |
|
460 |
end else |
|
461 |
glRotatef(Angle, 0, 0, 1); |
|
462 |
||
775 | 463 |
|
777 | 464 |
glBindTexture(GL_TEXTURE_2D, Tex^.id); |
775 | 465 |
|
466 |
glBegin(GL_QUADS); |
|
467 |
||
468 |
glTexCoord2f(0, 0); |
|
469 |
glVertex2i(-hw, -hh); |
|
470 |
||
1896 | 471 |
glTexCoord2f(Tex^.rx, 0); |
775 | 472 |
glVertex2i(hw, -hh); |
473 |
||
1896 | 474 |
glTexCoord2f(Tex^.rx, Tex^.ry); |
775 | 475 |
glVertex2i(hw, hh); |
476 |
||
1896 | 477 |
glTexCoord2f(0, Tex^.ry); |
775 | 478 |
glVertex2i(-hw, hh); |
479 |
||
480 |
glEnd(); |
|
481 |
||
482 |
glPopMatrix |
|
483 |
end; |
|
484 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
485 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
4 | 486 |
begin |
487 |
r.y:= r.y + Height * Position; |
|
488 |
r.h:= Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
489 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 490 |
end; |
491 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
492 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
755 | 493 |
var r: TSDL_Rect; |
4 | 494 |
begin |
755 | 495 |
r.x:= 0; |
496 |
r.w:= SpritesData[Sprite].Width; |
|
497 |
r.y:= Frame * SpritesData[Sprite].Height; |
|
498 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
499 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 500 |
end; |
501 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
502 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
43 | 503 |
var r: TSDL_Rect; |
504 |
begin |
|
505 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
506 |
r.w:= SpritesData[Sprite].Width; |
|
507 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
508 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
509 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
43 | 510 |
end; |
511 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
512 |
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
|
513 |
var r: TSDL_Rect; |
198 | 514 |
begin |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
515 |
r.x:= 0; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
516 |
r.w:= Source^.w; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
517 |
r.y:= Frame * Height; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
518 |
r.h:= Height; |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
519 |
DrawFromRect(X, Y, @r, Source) |
198 | 520 |
end; |
521 |
||
762 | 522 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
95 | 523 |
begin |
762 | 524 |
DrawTexture(X - Source^.w div 2, Top, Source) |
4 | 525 |
end; |
526 |
||
1865
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1854
diff
changeset
|
527 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
761 | 528 |
var l, r, t, b: real; |
4 | 529 |
begin |
761 | 530 |
|
531 |
t:= Pos * 32 / HHTexture^.h; |
|
532 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
533 |
||
534 |
if Dir = -1 then |
|
535 |
begin |
|
536 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
537 |
r:= Step * 32 / HHTexture^.w |
|
538 |
end else |
|
539 |
begin |
|
540 |
l:= Step * 32 / HHTexture^.w; |
|
541 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
542 |
end; |
|
543 |
||
821
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 |
glPushMatrix(); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
546 |
glTranslatef(X, Y, 0); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
547 |
glRotatef(Angle, 0, 0, 1); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
548 |
|
761 | 549 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
550 |
||
551 |
glBegin(GL_QUADS); |
|
552 |
||
553 |
glTexCoord2f(l, t); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
554 |
glVertex2i(-16, -16); |
761 | 555 |
|
556 |
glTexCoord2f(r, t); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
557 |
glVertex2i(16, -16); |
761 | 558 |
|
559 |
glTexCoord2f(r, b); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
560 |
glVertex2i(16, 16); |
761 | 561 |
|
562 |
glTexCoord2f(l, b); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
563 |
glVertex2i(-16, 16); |
761 | 564 |
|
1854 | 565 |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
566 |
glEnd(); |
1854 | 567 |
glColor4f(1,1,1,1); |
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
568 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
569 |
glPopMatrix |
4 | 570 |
end; |
571 |
||
1431 | 572 |
procedure DrawFillRect(r: TSDL_Rect); |
573 |
begin |
|
574 |
glDisable(GL_TEXTURE_2D); |
|
575 |
||
576 |
glColor4ub(0, 0, 0, 127); |
|
577 |
||
578 |
glBegin(GL_QUADS); |
|
579 |
||
580 |
glVertex2i(r.x , r.y ); |
|
581 |
glVertex2i(r.x + r.w , r.y ); |
|
582 |
glVertex2i(r.x + r.w , r.y + r.h); |
|
583 |
glVertex2i(r.x , r.y + r.h); |
|
584 |
||
585 |
glEnd(); |
|
586 |
||
587 |
glColor4f(1, 1, 1, 1); |
|
588 |
glEnable(GL_TEXTURE_2D) |
|
589 |
end; |
|
590 |
||
4 | 591 |
procedure StoreRelease; |
592 |
var ii: TSprite; |
|
593 |
begin |
|
594 |
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
|
595 |
begin |
759 | 596 |
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
|
597 |
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
|
598 |
end; |
761 | 599 |
|
1806 | 600 |
FreeTexture(HHTexture) |
4 | 601 |
end; |
602 |
||
762 | 603 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
432 | 604 |
var w, h: LongInt; |
351 | 605 |
Result: PSDL_Surface; |
95 | 606 |
begin |
355 | 607 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
785 | 608 |
|
762 | 609 |
Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
610 |
32, RMask, GMask, BMask, AMask); |
|
785 | 611 |
|
107 | 612 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
785 | 613 |
|
95 | 614 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
785 | 615 |
|
762 | 616 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
785 | 617 |
|
762 | 618 |
RenderStringTex:= Surface2Tex(Result); |
785 | 619 |
|
762 | 620 |
SDL_FreeSurface(Result) |
95 | 621 |
end; |
622 |
||
4 | 623 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 624 |
var s: shortstring; |
4 | 625 |
begin |
351 | 626 |
str(Hedgehog.Gear^.Health, s); |
762 | 627 |
if Hedgehog.HealthTagTex <> nil then FreeTexture(Hedgehog.HealthTagTex); |
628 |
Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
|
4 | 629 |
end; |
630 |
||
518 | 631 |
function LoadImage(const filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface; |
30 | 632 |
var tmpsurf: PSDL_Surface; |
753 | 633 |
//Result: PSDL_Surface; |
355 | 634 |
s: shortstring; |
4 | 635 |
begin |
636 |
WriteToConsole(msgLoading + filename + '... '); |
|
355 | 637 |
s:= filename + '.' + cBitsStr + '.png'; |
638 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 639 |
|
74 | 640 |
if tmpsurf = nil then |
351 | 641 |
begin |
355 | 642 |
s:= filename + '.png'; |
643 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 644 |
end; |
80 | 645 |
|
646 |
if tmpsurf = nil then |
|
647 |
if critical then OutError(msgFailed, true) |
|
648 |
else begin |
|
649 |
WriteLnToConsole(msgFailed); |
|
351 | 650 |
exit(nil) |
80 | 651 |
end; |
351 | 652 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
653 |
if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
753 | 654 |
//if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
655 |
// else Result:= SDL_DisplayFormat(tmpsurf); |
|
620 | 656 |
{$IFDEF DEBUGFILE}WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') ');{$ENDIF} |
351 | 657 |
WriteLnToConsole(msgOK); |
753 | 658 |
LoadImage:= tmpsurf//Result |
659 |
end; |
|
660 |
||
661 |
procedure SetupOpenGL; |
|
662 |
begin |
|
756 | 663 |
glLoadIdentity; |
753 | 664 |
glViewport(0, 0, cScreenWidth, cScreenHeight); |
754 | 665 |
glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
666 |
glTranslatef(-cScreenWidth / 2, -cScreenHeight / 2, 0); |
|
756 | 667 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
753 | 668 |
glMatrixMode(GL_MODELVIEW) |
4 | 669 |
end; |
670 |
||
510 | 671 |
//////////////////////////////////////////////////////////////////////////////// |
766 | 672 |
var ProgrTex: PTexture = nil; |
534 | 673 |
Step: integer = 0; |
510 | 674 |
|
675 |
procedure AddProgress; |
|
676 |
var r: TSDL_Rect; |
|
766 | 677 |
texsurf: PSDL_Surface; |
510 | 678 |
begin |
679 |
if Step = 0 then |
|
680 |
begin |
|
681 |
WriteToConsole(msgLoading + 'progress sprite: '); |
|
766 | 682 |
texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', false, true, true); |
683 |
ProgrTex:= Surface2Tex(texsurf); |
|
684 |
SDL_FreeSurface(texsurf) |
|
510 | 685 |
end; |
1045 | 686 |
|
766 | 687 |
glClear(GL_COLOR_BUFFER_BIT); |
775 | 688 |
glEnable(GL_TEXTURE_2D); |
510 | 689 |
r.x:= 0; |
766 | 690 |
r.w:= ProgrTex^.w; |
691 |
r.h:= ProgrTex^.w; |
|
692 |
r.y:= (Step mod (ProgrTex^.h div ProgrTex^.w)) * ProgrTex^.w; |
|
693 |
DrawFromRect((cScreenWidth - ProgrTex^.w) div 2, |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
694 |
(cScreenHeight - ProgrTex^.w) div 2, @r, ProgrTex); |
775 | 695 |
glDisable(GL_TEXTURE_2D); |
766 | 696 |
SDL_GL_SwapBuffers(); |
510 | 697 |
inc(Step); |
698 |
end; |
|
699 |
||
700 |
procedure FinishProgress; |
|
701 |
begin |
|
702 |
WriteLnToConsole('Freeing progress surface... '); |
|
766 | 703 |
FreeTexture(ProgrTex) |
510 | 704 |
end; |
705 |
||
4 | 706 |
end. |