author | unc0rr |
Sat, 13 Jun 2009 11:32:23 +0000 | |
changeset 2160 | c83e8608dfd7 |
parent 2154 | 3d2917be12c3 |
child 2161 | 0c8634241fa4 |
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 |
|
2017 | 21 |
uses sysutils, uConsts, uTeams, SDLh, |
2152 | 22 |
{$IFDEF GLES11} |
1906 | 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); |
1939 | 36 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
37 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture); |
762 | 38 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
1251 | 39 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt); |
822 | 40 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
853 | 41 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
822 | 42 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
762 | 43 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
44 |
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
|
45 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1431 | 46 |
procedure DrawFillRect(r: TSDL_Rect); |
762 | 47 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
2017 | 48 |
function RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture; |
49 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
|
50 |
//procedure rotateSurface(Surface: PSDL_Surface); |
|
51 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL |
|
52 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer); |
|
4 | 53 |
procedure RenderHealth(var Hedgehog: THedgehog); |
54 |
procedure AddProgress; |
|
510 | 55 |
procedure FinishProgress; |
518 | 56 |
function LoadImage(const filename: string; hasAlpha, critical, setTransparent: boolean): PSDL_Surface; |
753 | 57 |
procedure SetupOpenGL; |
4 | 58 |
|
1525 | 59 |
var PixelFormat: PSDL_PixelFormat = nil; |
60 |
SDLPrimSurface: PSDL_Surface = nil; |
|
1023 | 61 |
PauseTexture, |
62 |
ConfirmTexture: PTexture; |
|
4 | 63 |
|
64 |
implementation |
|
1906 | 65 |
uses uMisc, uConsole, uLand, uLocale; |
4 | 66 |
|
690 | 67 |
var |
761 | 68 |
HHTexture: PTexture; |
2153 | 69 |
MaxTextureSize: Integer; |
4 | 70 |
|
71 |
procedure StoreInit; |
|
72 |
begin |
|
73 |
||
74 |
end; |
|
75 |
||
351 | 76 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
47 | 77 |
var r: TSDL_Rect; |
78 |
begin |
|
79 |
r:= rect^; |
|
83 | 80 |
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
|
81 |
|
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
82 |
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
|
83 |
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
|
84 |
|
351 | 85 |
r.y:= rect^.y + 1; |
86 |
r.h:= rect^.h - 2; |
|
47 | 87 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 88 |
r.x:= rect^.x + 1; |
89 |
r.w:= rect^.w - 2; |
|
90 |
r.y:= rect^.y; |
|
91 |
r.h:= rect^.h; |
|
47 | 92 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 93 |
r.x:= rect^.x + 2; |
94 |
r.y:= rect^.y + 1; |
|
95 |
r.w:= rect^.w - 4; |
|
96 |
r.h:= rect^.h - 2; |
|
47 | 97 |
SDL_FillRect(Surface, @r, FillColor); |
351 | 98 |
r.x:= rect^.x + 1; |
99 |
r.y:= rect^.y + 2; |
|
100 |
r.w:= rect^.w - 2; |
|
101 |
r.h:= rect^.h - 4; |
|
47 | 102 |
SDL_FillRect(Surface, @r, FillColor) |
103 |
end; |
|
104 |
||
371 | 105 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
351 | 106 |
var w, h: LongInt; |
4 | 107 |
tmpsurf: PSDL_Surface; |
108 |
clr: TSDL_Color; |
|
351 | 109 |
Result: TSDL_Rect; |
4 | 110 |
begin |
355 | 111 |
TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
4 | 112 |
Result.x:= X; |
113 |
Result.y:= Y; |
|
202 | 114 |
Result.w:= w + FontBorder * 2 + 4; |
115 |
Result.h:= h + FontBorder * 2; |
|
351 | 116 |
DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface, true); |
189 | 117 |
clr.r:= Color shr 16; |
118 |
clr.g:= (Color shr 8) and $FF; |
|
119 |
clr.b:= Color and $FF; |
|
355 | 120 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr.value); |
202 | 121 |
Result.x:= X + FontBorder + 2; |
122 |
Result.y:= Y + FontBorder; |
|
199 | 123 |
SDLTry(tmpsurf <> nil, true); |
4 | 124 |
SDL_UpperBlit(tmpsurf, nil, Surface, @Result); |
125 |
SDL_FreeSurface(tmpsurf); |
|
126 |
Result.x:= X; |
|
127 |
Result.y:= Y; |
|
202 | 128 |
Result.w:= w + FontBorder * 2 + 4; |
351 | 129 |
Result.h:= h + FontBorder * 2; |
130 |
WriteInRoundRect:= Result |
|
4 | 131 |
end; |
132 |
||
133 |
procedure StoreLoad; |
|
844 | 134 |
var s: string; |
4 | 135 |
|
1185 | 136 |
procedure WriteNames(Font: THWFont); |
137 |
var t: LongInt; |
|
138 |
i: LongInt; |
|
139 |
r, rr: TSDL_Rect; |
|
140 |
drY: LongInt; |
|
141 |
texsurf: PSDL_Surface; |
|
142 |
begin |
|
143 |
r.x:= 0; |
|
144 |
r.y:= 0; |
|
145 |
drY:= - 4; |
|
146 |
for t:= 0 to Pred(TeamsCount) do |
|
147 |
with TeamsArray[t]^ do |
|
148 |
begin |
|
149 |
NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font); |
|
690 | 150 |
|
1185 | 151 |
r.w:= cTeamHealthWidth + 5; |
152 |
r.h:= NameTagTex^.h; |
|
690 | 153 |
|
1185 | 154 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
155 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
156 |
TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
690 | 157 |
|
1185 | 158 |
DrawRoundRect(@r, cWhiteColor, cColorNearBlack, texsurf, true); |
159 |
rr:= r; |
|
160 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
|
161 |
DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false); |
|
162 |
HealthTex:= Surface2Tex(texsurf); |
|
163 |
SDL_FreeSurface(texsurf); |
|
690 | 164 |
|
1185 | 165 |
dec(drY, r.h + 2); |
166 |
DrawHealthY:= drY; |
|
167 |
for i:= 0 to 7 do |
|
168 |
with Hedgehogs[i] do |
|
169 |
if Gear <> nil then |
|
1242 | 170 |
begin |
1185 | 171 |
NameTagTex:= RenderStringTex(Name, Clan^.Color, fnt16); |
1294
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
172 |
if Hat <> 'NoHat' then |
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
173 |
begin |
1698 | 174 |
texsurf:= LoadImage(Pathz[ptHats] + '/' + Hat, false, false, false); |
175 |
if texsurf <> nil then |
|
176 |
begin |
|
177 |
HatTex:= Surface2Tex(texsurf); |
|
178 |
SDL_FreeSurface(texsurf) |
|
179 |
end |
|
1294
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
180 |
end |
1242 | 181 |
end; |
1185 | 182 |
end; |
183 |
end; |
|
4 | 184 |
|
1185 | 185 |
procedure MakeCrossHairs; |
186 |
var t: LongInt; |
|
187 |
tmpsurf, texsurf: PSDL_Surface; |
|
188 |
Color, i: Longword; |
|
189 |
begin |
|
190 |
s:= Pathz[ptGraphics] + '/' + cCHFileName; |
|
191 |
tmpsurf:= LoadImage(s, true, true, false); |
|
4 | 192 |
|
1185 | 193 |
for t:= 0 to Pred(TeamsCount) do |
194 |
with TeamsArray[t]^ do |
|
195 |
begin |
|
196 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask); |
|
197 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
198 |
|
1185 | 199 |
Color:= Clan^.Color; |
200 |
Color:= SDL_MapRGB(texsurf^.format, Color shr 16, Color shr 8, Color and $FF); |
|
201 |
SDL_FillRect(texsurf, nil, Color); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
202 |
|
1185 | 203 |
SDL_UpperBlit(tmpsurf, nil, texsurf, nil); |
777 | 204 |
|
1185 | 205 |
TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Ooops', true); |
777 | 206 |
|
1185 | 207 |
if SDL_MustLock(texsurf) then |
208 |
SDLTry(SDL_LockSurface(texsurf) >= 0, true); |
|
777 | 209 |
|
1185 | 210 |
// make black pixel be alpha-transparent |
211 |
for i:= 0 to texsurf^.w * texsurf^.h - 1 do |
|
212 |
if PLongwordArray(texsurf^.pixels)^[i] = $FF000000 then PLongwordArray(texsurf^.pixels)^[i]:= 0; |
|
777 | 213 |
|
1185 | 214 |
if SDL_MustLock(texsurf) then |
215 |
SDL_UnlockSurface(texsurf); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
216 |
|
1185 | 217 |
CrosshairTex:= Surface2Tex(texsurf); |
218 |
SDL_FreeSurface(texsurf) |
|
219 |
end; |
|
351 | 220 |
|
1185 | 221 |
SDL_FreeSurface(tmpsurf) |
222 |
end; |
|
4 | 223 |
|
1185 | 224 |
procedure InitHealth; |
225 |
var i, t: LongInt; |
|
226 |
begin |
|
227 |
for t:= 0 to Pred(TeamsCount) do |
|
228 |
if TeamsArray[t] <> nil then |
|
229 |
with TeamsArray[t]^ do |
|
230 |
begin |
|
231 |
for i:= 0 to cMaxHHIndex do |
|
232 |
if Hedgehogs[i].Gear <> nil then |
|
233 |
RenderHealth(Hedgehogs[i]); |
|
234 |
end |
|
235 |
end; |
|
4 | 236 |
|
1185 | 237 |
procedure LoadGraves; |
238 |
var t: LongInt; |
|
239 |
texsurf: PSDL_Surface; |
|
240 |
begin |
|
241 |
for t:= 0 to Pred(TeamsCount) do |
|
242 |
if TeamsArray[t] <> nil then |
|
243 |
with TeamsArray[t]^ do |
|
244 |
begin |
|
245 |
if GraveName = '' then GraveName:= 'Simple'; |
|
246 |
texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, false, true, true); |
|
247 |
GraveTex:= Surface2Tex(texsurf); |
|
248 |
SDL_FreeSurface(texsurf) |
|
249 |
end |
|
250 |
end; |
|
4 | 251 |
|
844 | 252 |
var ii: TSprite; |
253 |
fi: THWFont; |
|
254 |
ai: TAmmoType; |
|
255 |
tmpsurf: PSDL_Surface; |
|
256 |
i: LongInt; |
|
4 | 257 |
begin |
258 |
for fi:= Low(THWFont) to High(THWFont) do |
|
1185 | 259 |
with Fontz[fi] do |
260 |
begin |
|
261 |
s:= Pathz[ptFonts] + '/' + Name; |
|
262 |
WriteToConsole(msgLoading + s + '... '); |
|
263 |
Handle:= TTF_OpenFont(Str2PChar(s), Height); |
|
264 |
SDLTry(Handle <> nil, true); |
|
265 |
TTF_SetFontStyle(Handle, style); |
|
266 |
WriteLnToConsole(msgOK) |
|
267 |
end; |
|
4 | 268 |
AddProgress; |
53 | 269 |
|
4 | 270 |
WriteNames(fnt16); |
70 | 271 |
MakeCrossHairs; |
4 | 272 |
LoadGraves; |
273 |
||
274 |
AddProgress; |
|
275 |
for ii:= Low(TSprite) to High(TSprite) do |
|
1185 | 276 |
with SpritesData[ii] do |
2145 | 277 |
// FIXME - add a sprite attribute |
278 |
if (not cReducedQuality) or |
|
1939 | 279 |
((ii <> sprSky) and (ii <> sprHorizont) and (ii <> sprFlake)) then |
1185 | 280 |
begin |
281 |
if AltPath = ptNone then |
|
282 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, true, true, true) |
|
283 |
else begin |
|
284 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, true, false, true); |
|
285 |
if tmpsurf = nil then |
|
286 |
tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, true, true, true) |
|
287 |
end; |
|
288 |
if Width = 0 then Width:= tmpsurf^.w; |
|
289 |
if Height = 0 then Height:= tmpsurf^.h; |
|
290 |
Texture:= Surface2Tex(tmpsurf); |
|
291 |
if saveSurf then Surface:= tmpsurf else SDL_FreeSurface(tmpsurf) |
|
292 |
end; |
|
80 | 293 |
|
4 | 294 |
AddProgress; |
567 | 295 |
|
761 | 296 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, true, true, true); |
297 |
HHTexture:= Surface2Tex(tmpsurf); |
|
298 |
SDL_FreeSurface(tmpsurf); |
|
4 | 299 |
|
300 |
InitHealth; |
|
301 |
||
762 | 302 |
PauseTexture:= RenderStringTex(trmsg[sidPaused], $FFFF00, fntBig); |
1023 | 303 |
ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], $FFFF00, fntBig); |
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
304 |
|
843 | 305 |
for ai:= Low(TAmmoType) to High(TAmmoType) do |
306 |
with Ammoz[ai] do |
|
307 |
begin |
|
308 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(trAmmo[NameId]), $FFFFFF); |
|
309 |
NameTex:= Surface2Tex(tmpsurf); |
|
310 |
SDL_FreeSurface(tmpsurf) |
|
311 |
end; |
|
312 |
||
844 | 313 |
for i:= Low(CountTexz) to High(CountTexz) do |
314 |
begin |
|
315 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), $FFFFFF); |
|
316 |
CountTexz[i]:= Surface2Tex(tmpsurf); |
|
317 |
SDL_FreeSurface(tmpsurf) |
|
318 |
end; |
|
319 |
||
4 | 320 |
{$IFDEF DUMP} |
321 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
322 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
323 |
{$ENDIF} |
|
324 |
end; |
|
325 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
326 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
4 | 327 |
var rr: TSDL_Rect; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
328 |
_l, _r, _t, _b: real; |
1916 | 329 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
4 | 330 |
begin |
759 | 331 |
if SourceTexture^.h = 0 then exit; |
4 | 332 |
rr.x:= X; |
333 |
rr.y:= Y; |
|
351 | 334 |
rr.w:= r^.w; |
335 |
rr.h:= r^.h; |
|
755 | 336 |
|
1896 | 337 |
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx; |
338 |
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx; |
|
339 |
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry; |
|
340 |
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry; |
|
755 | 341 |
|
342 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
343 |
||
1916 | 344 |
VertexBuffer[0].X:= X; |
345 |
VertexBuffer[0].Y:= Y; |
|
346 |
VertexBuffer[1].X:= rr.w + X; |
|
347 |
VertexBuffer[1].Y:= Y; |
|
348 |
VertexBuffer[2].X:= rr.w + X; |
|
349 |
VertexBuffer[2].Y:= rr.h + Y; |
|
350 |
VertexBuffer[3].X:= X; |
|
351 |
VertexBuffer[3].Y:= rr.h + Y; |
|
755 | 352 |
|
1916 | 353 |
TextureBuffer[0].X:= _l; |
354 |
TextureBuffer[0].Y:= _t; |
|
355 |
TextureBuffer[1].X:= _r; |
|
356 |
TextureBuffer[1].Y:= _t; |
|
357 |
TextureBuffer[2].X:= _r; |
|
358 |
TextureBuffer[2].Y:= _b; |
|
359 |
TextureBuffer[3].X:= _l; |
|
360 |
TextureBuffer[3].Y:= _b; |
|
755 | 361 |
|
1916 | 362 |
glEnableClientState(GL_VERTEX_ARRAY); |
363 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
755 | 364 |
|
1916 | 365 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
366 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
367 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
368 |
||
369 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
370 |
glDisableClientState(GL_VERTEX_ARRAY) |
|
762 | 371 |
end; |
372 |
||
373 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
|
374 |
begin |
|
1904 | 375 |
glPushMatrix; |
376 |
glTranslatef(X, Y, 0); |
|
377 |
||
762 | 378 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
379 |
||
1904 | 380 |
glEnableClientState(GL_VERTEX_ARRAY); |
381 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
762 | 382 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
383 |
glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
384 |
glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
385 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); |
1904 | 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; |
|
1916 | 396 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
1242 | 397 |
begin |
398 |
glPushMatrix; |
|
399 |
glTranslatef(X, Y, 0); |
|
1251 | 400 |
glScalef(Scale, Scale, 1.0); |
1242 | 401 |
|
402 |
if Dir < 0 then |
|
403 |
hw:= - 16 |
|
404 |
else |
|
405 |
hw:= 16; |
|
406 |
||
1896 | 407 |
ft:= Frame / Frames * Texture^.ry; |
408 |
fb:= (Frame + 1) / Frames * Texture^.ry; |
|
1242 | 409 |
|
410 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
411 |
||
1916 | 412 |
VertexBuffer[0].X:= -hw; |
413 |
VertexBuffer[0].Y:= -16; |
|
414 |
VertexBuffer[1].X:= hw; |
|
415 |
VertexBuffer[1].Y:= -16; |
|
416 |
VertexBuffer[2].X:= hw; |
|
417 |
VertexBuffer[2].Y:= 16; |
|
418 |
VertexBuffer[3].X:= -hw; |
|
419 |
VertexBuffer[3].Y:= 16; |
|
1242 | 420 |
|
1916 | 421 |
TextureBuffer[0].X:= 0; |
422 |
TextureBuffer[0].Y:= ft; |
|
423 |
TextureBuffer[1].X:= Texture^.rx; |
|
424 |
TextureBuffer[1].Y:= ft; |
|
425 |
TextureBuffer[2].X:= Texture^.rx; |
|
426 |
TextureBuffer[2].Y:= fb; |
|
427 |
TextureBuffer[3].X:= 0; |
|
428 |
TextureBuffer[3].Y:= fb; |
|
1242 | 429 |
|
1916 | 430 |
glEnableClientState(GL_VERTEX_ARRAY); |
431 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
1242 | 432 |
|
1916 | 433 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
434 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
435 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
436 |
||
437 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
438 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
439 |
||
1242 | 440 |
|
441 |
glPopMatrix |
|
442 |
end; |
|
443 |
||
822 | 444 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
775 | 445 |
begin |
777 | 446 |
DrawRotatedTex(SpritesData[Sprite].Texture, |
822 | 447 |
SpritesData[Sprite].Width, |
448 |
SpritesData[Sprite].Height, |
|
449 |
X, Y, Dir, Angle) |
|
777 | 450 |
end; |
451 |
||
853 | 452 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
806 | 453 |
begin |
454 |
glPushMatrix; |
|
809 | 455 |
glTranslatef(X, Y, 0); |
806 | 456 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
457 |
if Dir < 0 then |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
458 |
glRotatef(Angle, 0, 0, -1) |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
459 |
else |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
460 |
glRotatef(Angle, 0, 0, 1); |
853 | 461 |
if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
462 |
||
463 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
806 | 464 |
|
465 |
glPopMatrix |
|
466 |
end; |
|
467 |
||
822 | 468 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
1916 | 469 |
var VertexBuffer: array [0..3] of TVertex2f; |
777 | 470 |
begin |
775 | 471 |
glPushMatrix; |
472 |
glTranslatef(X, Y, 0); |
|
822 | 473 |
|
474 |
if Dir < 0 then |
|
475 |
begin |
|
476 |
hw:= - hw; |
|
477 |
glRotatef(Angle, 0, 0, -1); |
|
478 |
end else |
|
479 |
glRotatef(Angle, 0, 0, 1); |
|
480 |
||
775 | 481 |
|
777 | 482 |
glBindTexture(GL_TEXTURE_2D, Tex^.id); |
775 | 483 |
|
1916 | 484 |
VertexBuffer[0].X:= -hw; |
485 |
VertexBuffer[0].Y:= -hh; |
|
486 |
VertexBuffer[1].X:= hw; |
|
487 |
VertexBuffer[1].Y:= -hh; |
|
488 |
VertexBuffer[2].X:= hw; |
|
489 |
VertexBuffer[2].Y:= hh; |
|
490 |
VertexBuffer[3].X:= -hw; |
|
491 |
VertexBuffer[3].Y:= hh; |
|
775 | 492 |
|
1916 | 493 |
glEnableClientState(GL_VERTEX_ARRAY); |
494 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
775 | 495 |
|
1916 | 496 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
497 |
glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb); |
|
498 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
775 | 499 |
|
1916 | 500 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
501 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
775 | 502 |
|
503 |
glPopMatrix |
|
504 |
end; |
|
505 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
506 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
4 | 507 |
begin |
508 |
r.y:= r.y + Height * Position; |
|
509 |
r.h:= Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
510 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 511 |
end; |
512 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
513 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
755 | 514 |
var r: TSDL_Rect; |
4 | 515 |
begin |
755 | 516 |
r.x:= 0; |
517 |
r.w:= SpritesData[Sprite].Width; |
|
518 |
r.y:= Frame * SpritesData[Sprite].Height; |
|
519 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
520 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 521 |
end; |
522 |
||
1939 | 523 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
524 |
var r: TSDL_Rect; |
|
525 |
begin |
|
526 |
r.x:= 0; |
|
527 |
r.y:= 0; |
|
528 |
r.w:= SpritesData[Sprite].Width; |
|
529 |
r.h:= SpritesData[Sprite].Height; |
|
530 |
||
531 |
if (X < LeftX) then |
|
532 |
r.x:= LeftX - X; |
|
533 |
if (Y < TopY) then |
|
534 |
r.y:= TopY - Y; |
|
535 |
||
536 |
if (Y + SpritesData[Sprite].Height > BottomY) then |
|
537 |
r.h:= BottomY - Y + 1; |
|
538 |
if (X + SpritesData[Sprite].Width > RightX) then |
|
539 |
r.w:= RightX - X + 1; |
|
540 |
||
541 |
dec(r.h, r.y); |
|
542 |
dec(r.w, r.x); |
|
543 |
||
544 |
DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture) |
|
545 |
end; |
|
546 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
547 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
43 | 548 |
var r: TSDL_Rect; |
549 |
begin |
|
550 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
551 |
r.w:= SpritesData[Sprite].Width; |
|
552 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
553 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
554 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
43 | 555 |
end; |
556 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
557 |
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
|
558 |
var r: TSDL_Rect; |
198 | 559 |
begin |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
560 |
r.x:= 0; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
561 |
r.w:= Source^.w; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
562 |
r.y:= Frame * Height; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
563 |
r.h:= Height; |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
564 |
DrawFromRect(X, Y, @r, Source) |
198 | 565 |
end; |
566 |
||
762 | 567 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
95 | 568 |
begin |
762 | 569 |
DrawTexture(X - Source^.w div 2, Top, Source) |
4 | 570 |
end; |
571 |
||
1865
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1854
diff
changeset
|
572 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1916 | 573 |
const VertexBuffer: array [0..3] of TVertex2f = ( |
574 |
(x: -16; y: -16), |
|
575 |
(x: 16; y: -16), |
|
576 |
(x: 16; y: 16), |
|
577 |
(x: -16; y: 16)); |
|
761 | 578 |
var l, r, t, b: real; |
1916 | 579 |
TextureBuffer: array [0..3] of TVertex2f; |
4 | 580 |
begin |
761 | 581 |
|
582 |
t:= Pos * 32 / HHTexture^.h; |
|
583 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
584 |
||
585 |
if Dir = -1 then |
|
586 |
begin |
|
587 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
588 |
r:= Step * 32 / HHTexture^.w |
|
589 |
end else |
|
590 |
begin |
|
591 |
l:= Step * 32 / HHTexture^.w; |
|
592 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
593 |
end; |
|
594 |
||
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
595 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
596 |
glPushMatrix(); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
597 |
glTranslatef(X, Y, 0); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
598 |
glRotatef(Angle, 0, 0, 1); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
599 |
|
761 | 600 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
601 |
||
1916 | 602 |
TextureBuffer[0].X:= l; |
603 |
TextureBuffer[0].Y:= t; |
|
604 |
TextureBuffer[1].X:= r; |
|
605 |
TextureBuffer[1].Y:= t; |
|
606 |
TextureBuffer[2].X:= r; |
|
607 |
TextureBuffer[2].Y:= b; |
|
608 |
TextureBuffer[3].X:= l; |
|
609 |
TextureBuffer[3].Y:= b; |
|
761 | 610 |
|
1916 | 611 |
glEnableClientState(GL_VERTEX_ARRAY); |
612 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
761 | 613 |
|
1916 | 614 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
615 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
616 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
761 | 617 |
|
1916 | 618 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
619 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
761 | 620 |
|
1854 | 621 |
|
622 |
glColor4f(1,1,1,1); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
623 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
624 |
glPopMatrix |
4 | 625 |
end; |
626 |
||
1431 | 627 |
procedure DrawFillRect(r: TSDL_Rect); |
1916 | 628 |
var VertexBuffer: array [0..3] of TVertex2f; |
1431 | 629 |
begin |
630 |
glDisable(GL_TEXTURE_2D); |
|
631 |
||
632 |
glColor4ub(0, 0, 0, 127); |
|
633 |
||
1916 | 634 |
VertexBuffer[0].X:= r.x; |
635 |
VertexBuffer[0].Y:= r.y; |
|
636 |
VertexBuffer[1].X:= r.x + r.w; |
|
637 |
VertexBuffer[1].Y:= r.y; |
|
638 |
VertexBuffer[2].X:= r.x + r.w; |
|
639 |
VertexBuffer[2].Y:= r.y + r.h; |
|
640 |
VertexBuffer[3].X:= r.x; |
|
641 |
VertexBuffer[3].Y:= r.y + r.h; |
|
1431 | 642 |
|
1916 | 643 |
glEnableClientState(GL_VERTEX_ARRAY); |
644 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
645 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
646 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
1431 | 647 |
|
648 |
glColor4f(1, 1, 1, 1); |
|
649 |
glEnable(GL_TEXTURE_2D) |
|
650 |
end; |
|
651 |
||
4 | 652 |
procedure StoreRelease; |
653 |
var ii: TSprite; |
|
654 |
begin |
|
655 |
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
|
656 |
begin |
759 | 657 |
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
|
658 |
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
|
659 |
end; |
761 | 660 |
|
1806 | 661 |
FreeTexture(HHTexture) |
4 | 662 |
end; |
663 |
||
762 | 664 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
432 | 665 |
var w, h: LongInt; |
351 | 666 |
Result: PSDL_Surface; |
95 | 667 |
begin |
1989 | 668 |
if length(s) = 0 then s:= ' '; |
355 | 669 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
785 | 670 |
|
762 | 671 |
Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
672 |
32, RMask, GMask, BMask, AMask); |
|
785 | 673 |
|
107 | 674 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
785 | 675 |
|
95 | 676 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
785 | 677 |
|
762 | 678 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
785 | 679 |
|
762 | 680 |
RenderStringTex:= Surface2Tex(Result); |
785 | 681 |
|
762 | 682 |
SDL_FreeSurface(Result) |
95 | 683 |
end; |
684 |
||
2017 | 685 |
function RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture; |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
686 |
var textWidth, textHeight, x, y, w, h, i, j, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt; |
2017 | 687 |
Result, tmpsurf, rotatedEdge: PSDL_Surface; |
688 |
rect: TSDL_Rect; |
|
689 |
chars: TSysCharSet = [#9,' ','.',';',':','?','!',',']; |
|
690 |
substr: shortstring; |
|
691 |
edge, corner, tail: TSPrite; |
|
692 |
begin |
|
693 |
||
694 |
case SpeechType of |
|
695 |
1: begin; |
|
696 |
edge:= sprSpeechEdge; |
|
697 |
corner:= sprSpeechCorner; |
|
698 |
tail:= sprSpeechTail; |
|
699 |
end; |
|
700 |
2: begin; |
|
701 |
edge:= sprThoughtEdge; |
|
702 |
corner:= sprThoughtCorner; |
|
703 |
tail:= sprThoughtTail; |
|
704 |
end; |
|
705 |
3: begin; |
|
706 |
edge:= sprShoutEdge; |
|
707 |
corner:= sprShoutCorner; |
|
708 |
tail:= sprShoutTail; |
|
709 |
end; |
|
710 |
end; |
|
711 |
edgeHeight:= SpritesData[edge].Height; |
|
712 |
edgeWidth:= SpritesData[edge].Width; |
|
713 |
cornerWidth:= SpritesData[corner].Width; |
|
714 |
cornerHeight:= SpritesData[corner].Height; |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
715 |
// This one screws up WrapText |
2022 | 716 |
//s:= 'This is the song that never ends. ''cause it goes on and on my friends. Some people, started singing it not knowing what it was. And they''ll just go on singing it forever just because... This is the song that never ends...'; |
2154
3d2917be12c3
Change default output to stderr since /tmp doesn't exist under windows and is useless under iphoneos, add a couple of extra parameters
nemo
parents:
2153
diff
changeset
|
717 |
// This one does not |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
718 |
//s:= 'This is the song that never ends. cause it goes on and on my friends. Some people, started singing it not knowing what it was. And they will go on singing it forever just because... This is the song that never ends... '; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
719 |
|
2022 | 720 |
numLines:= 0; |
2017 | 721 |
|
722 |
if length(s) = 0 then s:= '...'; |
|
723 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
724 |
j:= 0; |
2017 | 725 |
if (length(s) > 20) then |
726 |
begin |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
727 |
w:= 0; |
2017 | 728 |
i:= round(Sqrt(length(s)) * 2); |
729 |
s:= WrapText(s, #1, chars, i); |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
730 |
pos:= 1; prevpos:= 0; line:= 0; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
731 |
// Find the longest line for the purposes of centring the text. Font dependant. |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
732 |
while pos <= length(s) do |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
733 |
begin |
2017 | 734 |
if (s[pos] = #1) or (pos = length(s)) then |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
735 |
begin |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
736 |
inc(numlines); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
737 |
if s[pos] <> #1 then inc(pos); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
738 |
while s[prevpos+1] = ' ' do inc(prevpos); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
739 |
substr:= copy(s, prevpos+1, pos-prevpos-1); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
740 |
i:= 0; j:= 0; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
741 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(substr), i, j); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
742 |
if i > w then w:= i; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
743 |
prevpos:= pos; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
744 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
745 |
inc(pos); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
746 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
747 |
end |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
748 |
else numLines := 1; |
2017 | 749 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
750 |
textWidth:=((w-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth; |
2022 | 751 |
textHeight:=(((numlines * h + 2)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth; |
2019 | 752 |
|
2022 | 753 |
textHeight:=max(textHeight,edgeWidth); |
2017 | 754 |
//textWidth:=max(textWidth,SpritesData[tail].Width); |
755 |
rect.x:= 0; |
|
756 |
rect.y:= 0; |
|
2022 | 757 |
rect.w:= textWidth + (cornerWidth * 2); |
758 |
rect.h:= textHeight + cornerHeight*2 - edgeHeight + SpritesData[tail].Height; |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
759 |
//s:= inttostr(w) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h); |
2017 | 760 |
|
761 |
Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask); |
|
762 |
||
763 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
|
764 |
||
765 |
//////////////////////////////// CORNERS /////////////////////////////// |
|
766 |
copyToXY(SpritesData[corner].Surface, Result, 0, 0); /////////////////// NW |
|
767 |
||
768 |
flipSurface(SpritesData[corner].Surface, true); // store all 4 versions in memory to avoid repeated flips? |
|
769 |
x:= 0; |
|
770 |
y:= textHeight + cornerHeight -1; |
|
771 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// SW |
|
772 |
||
773 |
flipSurface(SpritesData[corner].Surface, false); |
|
774 |
x:= rect.w-cornerWidth-1; |
|
775 |
y:= textHeight + cornerHeight -1; |
|
776 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// SE |
|
777 |
||
778 |
flipSurface(SpritesData[corner].Surface, true); |
|
779 |
x:= rect.w-cornerWidth-1; |
|
780 |
y:= 0; |
|
781 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// NE |
|
782 |
flipSurface(SpritesData[corner].Surface, false); // restore original position |
|
783 |
//////////////////////////////// END CORNERS /////////////////////////////// |
|
784 |
||
785 |
//////////////////////////////// EDGES ////////////////////////////////////// |
|
786 |
x:= cornerWidth; |
|
787 |
y:= 0; |
|
788 |
while x < rect.w-cornerWidth-1 do |
|
789 |
begin |
|
790 |
copyToXY(SpritesData[edge].Surface, Result, x, y); ///////////////// top edge |
|
791 |
inc(x,edgeWidth); |
|
792 |
end; |
|
793 |
flipSurface(SpritesData[edge].Surface, true); |
|
794 |
x:= cornerWidth; |
|
795 |
y:= textHeight + cornerHeight*2 - edgeHeight-1; |
|
796 |
while x < rect.w-cornerWidth-1 do |
|
797 |
begin |
|
798 |
copyToXY(SpritesData[edge].Surface, Result, x, y); ///////////////// bottom edge |
|
799 |
inc(x,edgeWidth); |
|
800 |
end; |
|
801 |
flipSurface(SpritesData[edge].Surface, true); // restore original position |
|
802 |
||
803 |
rotatedEdge:= SDL_CreateRGBSurface(SDL_SWSURFACE, edgeHeight, edgeWidth, 32, RMask, GMask, BMask, AMask); |
|
804 |
x:= rect.w - edgeHeight - 1; |
|
805 |
y:= cornerHeight; |
|
806 |
//// initially was going to rotate in place, but the SDL spec claims width/height are read only |
|
807 |
copyRotatedSurface(SpritesData[edge].Surface,rotatedEdge); |
|
808 |
while y < textHeight + cornerHeight do |
|
809 |
begin |
|
810 |
copyToXY(rotatedEdge, Result, x, y); |
|
811 |
inc(y,edgeWidth); |
|
812 |
end; |
|
813 |
flipSurface(rotatedEdge, false); // restore original position |
|
814 |
x:= 0; |
|
815 |
y:= cornerHeight; |
|
816 |
while y < textHeight + cornerHeight do |
|
817 |
begin |
|
818 |
copyToXY(rotatedEdge, Result, x, y); |
|
819 |
inc(y,edgeWidth); |
|
820 |
end; |
|
821 |
//////////////////////////////// END EDGES ////////////////////////////////////// |
|
822 |
||
823 |
x:= cornerWidth; |
|
824 |
y:= textHeight + cornerHeight * 2 - edgeHeight - 1; |
|
825 |
copyToXY(SpritesData[tail].Surface, Result, x, y); |
|
826 |
||
827 |
rect.x:= edgeHeight; |
|
828 |
rect.y:= edgeHeight; |
|
829 |
rect.w:= rect.w - edgeHeight * 2; |
|
830 |
rect.h:= textHeight + cornerHeight * 2 - edgeHeight * 2; |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
831 |
i:= rect.w; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
832 |
j:= rect.h; |
2017 | 833 |
SDL_FillRect(Result, @rect, cWhiteColor); |
834 |
||
835 |
pos:= 1; prevpos:= 0; line:= 0; |
|
836 |
while pos <= length(s) do |
|
837 |
begin |
|
838 |
if (s[pos] = #1) or (pos = length(s)) then |
|
839 |
begin |
|
840 |
if s[pos] <> #1 then inc(pos); |
|
841 |
while s[prevpos+1] = ' 'do inc(prevpos); |
|
842 |
substr:= copy(s, prevpos+1, pos-prevpos-1); |
|
843 |
if Length(substr) <> 0 then |
|
844 |
begin |
|
845 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cColorNearBlack); |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
846 |
rect.x:= edgeHeight + 1 + ((i - w) div 2); |
2022 | 847 |
// trying to more evenly position the text, vertically |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
848 |
rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h; |
2017 | 849 |
SDLTry(tmpsurf <> nil, true); |
850 |
SDL_UpperBlit(tmpsurf, nil, Result, @rect); |
|
851 |
SDL_FreeSurface(tmpsurf); |
|
852 |
inc(line); |
|
853 |
prevpos:= pos; |
|
854 |
end; |
|
855 |
end; |
|
856 |
inc(pos); |
|
857 |
end; |
|
858 |
||
859 |
//TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
860 |
RenderSpeechBubbleTex:= Surface2Tex(Result); |
|
861 |
||
862 |
SDL_FreeSurface(rotatedEdge); |
|
863 |
SDL_FreeSurface(Result) |
|
864 |
end; |
|
865 |
||
4 | 866 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 867 |
var s: shortstring; |
4 | 868 |
begin |
351 | 869 |
str(Hedgehog.Gear^.Health, s); |
762 | 870 |
if Hedgehog.HealthTagTex <> nil then FreeTexture(Hedgehog.HealthTagTex); |
871 |
Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
|
4 | 872 |
end; |
873 |
||
518 | 874 |
function LoadImage(const filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface; |
30 | 875 |
var tmpsurf: PSDL_Surface; |
753 | 876 |
//Result: PSDL_Surface; |
355 | 877 |
s: shortstring; |
4 | 878 |
begin |
879 |
WriteToConsole(msgLoading + filename + '... '); |
|
355 | 880 |
s:= filename + '.' + cBitsStr + '.png'; |
881 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 882 |
|
74 | 883 |
if tmpsurf = nil then |
351 | 884 |
begin |
355 | 885 |
s:= filename + '.png'; |
886 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 887 |
end; |
80 | 888 |
|
889 |
if tmpsurf = nil then |
|
2153 | 890 |
begin |
891 |
OutError(msgFailed, critical); |
|
892 |
exit(nil) |
|
893 |
end; |
|
894 |
||
895 |
if (tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize) then |
|
896 |
begin |
|
897 |
SDL_FreeSurface(tmpsurf); |
|
898 |
OutError(msgFailedSize, critical); |
|
899 |
exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask)) |
|
900 |
end; |
|
351 | 901 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
902 |
if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
753 | 903 |
//if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
904 |
// else Result:= SDL_DisplayFormat(tmpsurf); |
|
2153 | 905 |
WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') '); |
351 | 906 |
WriteLnToConsole(msgOK); |
2153 | 907 |
|
908 |
LoadImage:= tmpsurf //Result |
|
753 | 909 |
end; |
910 |
||
911 |
procedure SetupOpenGL; |
|
912 |
begin |
|
756 | 913 |
glLoadIdentity; |
753 | 914 |
glViewport(0, 0, cScreenWidth, cScreenHeight); |
754 | 915 |
glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
916 |
glTranslatef(-cScreenWidth / 2, -cScreenHeight / 2, 0); |
|
756 | 917 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2153 | 918 |
glMatrixMode(GL_MODELVIEW); |
919 |
||
920 |
glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize); |
|
921 |
{$IFDEF DEBUGFILE} |
|
922 |
AddFileLog('GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize)); |
|
923 |
{$ENDIF} |
|
4 | 924 |
end; |
925 |
||
510 | 926 |
//////////////////////////////////////////////////////////////////////////////// |
766 | 927 |
var ProgrTex: PTexture = nil; |
534 | 928 |
Step: integer = 0; |
510 | 929 |
|
930 |
procedure AddProgress; |
|
931 |
var r: TSDL_Rect; |
|
766 | 932 |
texsurf: PSDL_Surface; |
510 | 933 |
begin |
934 |
if Step = 0 then |
|
935 |
begin |
|
936 |
WriteToConsole(msgLoading + 'progress sprite: '); |
|
766 | 937 |
texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', false, true, true); |
938 |
ProgrTex:= Surface2Tex(texsurf); |
|
939 |
SDL_FreeSurface(texsurf) |
|
510 | 940 |
end; |
1045 | 941 |
|
766 | 942 |
glClear(GL_COLOR_BUFFER_BIT); |
775 | 943 |
glEnable(GL_TEXTURE_2D); |
510 | 944 |
r.x:= 0; |
766 | 945 |
r.w:= ProgrTex^.w; |
946 |
r.h:= ProgrTex^.w; |
|
947 |
r.y:= (Step mod (ProgrTex^.h div ProgrTex^.w)) * ProgrTex^.w; |
|
948 |
DrawFromRect((cScreenWidth - ProgrTex^.w) div 2, |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
949 |
(cScreenHeight - ProgrTex^.w) div 2, @r, ProgrTex); |
775 | 950 |
glDisable(GL_TEXTURE_2D); |
766 | 951 |
SDL_GL_SwapBuffers(); |
510 | 952 |
inc(Step); |
953 |
end; |
|
954 |
||
955 |
procedure FinishProgress; |
|
956 |
begin |
|
957 |
WriteLnToConsole('Freeing progress surface... '); |
|
766 | 958 |
FreeTexture(ProgrTex) |
510 | 959 |
end; |
960 |
||
2017 | 961 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
962 |
var y, x, i, j: LongInt; |
|
963 |
tmpPixel: Longword; |
|
964 |
pixels: PLongWordArray; |
|
965 |
begin |
|
966 |
TryDo(Surface^.format^.BytesPerPixel = 4, 'flipSurface failed, expecting 32 bit surface', true); |
|
967 |
pixels:= Surface^.pixels; |
|
968 |
if Vertical then |
|
969 |
for y := 0 to (Surface^.h div 2) - 1 do |
|
970 |
for x := 0 to Surface^.w - 1 do |
|
971 |
begin |
|
972 |
i:= y * Surface^.w + x; |
|
973 |
j:= (Surface^.h - y - 1) * Surface^.w + x; |
|
974 |
tmpPixel:= pixels^[i]; |
|
975 |
pixels^[i]:= pixels^[j]; |
|
976 |
pixels^[j]:= tmpPixel; |
|
977 |
end |
|
978 |
else |
|
979 |
for x := 0 to (Surface^.w div 2) - 1 do |
|
980 |
for y := 0 to Surface^.h -1 do |
|
981 |
begin |
|
982 |
i:= y*Surface^.w + x; |
|
983 |
j:= y*Surface^.w + (Surface^.w - x - 1); |
|
984 |
tmpPixel:= pixels^[i]; |
|
985 |
pixels^[i]:= pixels^[j]; |
|
986 |
pixels^[j]:= tmpPixel; |
|
987 |
end; |
|
988 |
end; |
|
989 |
||
990 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer); |
|
991 |
var srcX, srcY, i, j, maxDest: LongInt; |
|
992 |
srcPixels, destPixels: PLongWordArray; |
|
993 |
begin |
|
994 |
maxDest:= (dest^.pitch div 4) * dest^.h; |
|
995 |
srcPixels:= src^.pixels; |
|
996 |
destPixels:= dest^.pixels; |
|
997 |
||
998 |
for srcX:= 0 to src^.w - 1 do |
|
999 |
for srcY:= 0 to src^.h - 1 do |
|
1000 |
begin |
|
1001 |
i:= (destY + srcY) * (dest^.pitch div 4) + destX + srcX; |
|
1002 |
j:= srcY * (src^.pitch div 4) + srcX; |
|
1003 |
// basic skip of transparent pixels - cleverness would be to do true alpha |
|
1004 |
if (i < maxDest) and ($FF000000 and srcPixels^[j] <> 0) then destPixels^[i]:= srcPixels^[j]; |
|
1005 |
end; |
|
1006 |
end; |
|
1007 |
||
1008 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently |
|
1009 |
var y, x, i, j: LongInt; |
|
1010 |
srcPixels, destPixels: PLongWordArray; |
|
1011 |
begin |
|
1012 |
TryDo(src^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
1013 |
TryDo(dest^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
1014 |
||
1015 |
srcPixels:= src^.pixels; |
|
1016 |
destPixels:= dest^.pixels; |
|
1017 |
||
1018 |
j:= 0; |
|
1019 |
for x := 0 to src^.w - 1 do |
|
1020 |
for y := 0 to src^.h - 1 do |
|
1021 |
begin |
|
1022 |
i:= (src^.h - 1 - y) * (src^.pitch div 4) + x; |
|
1023 |
destPixels^[j]:= srcPixels^[i]; |
|
1024 |
inc(j) |
|
1025 |
end; |
|
1026 |
end; |
|
1027 |
||
4 | 1028 |
end. |