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