author | nemo |
Fri, 20 Nov 2009 22:02:49 +0000 | |
changeset 2632 | 0c1d3c12ded9 |
parent 2630 | 079ef82eac75 |
child 2633 | 9eb131794a6e |
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 |
||
2623 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uStore; |
22 |
interface |
|
2017 | 23 |
uses sysutils, uConsts, uTeams, SDLh, |
2152 | 24 |
{$IFDEF GLES11} |
1906 | 25 |
gles11, |
26 |
{$ELSE} |
|
2428 | 27 |
GL, GLext, |
1906 | 28 |
{$ENDIF} |
29 |
uFloat; |
|
4 | 30 |
|
31 |
procedure StoreInit; |
|
32 |
procedure StoreLoad; |
|
33 |
procedure StoreRelease; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
34 |
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
|
35 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
36 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
1939 | 37 |
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
|
38 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture); |
762 | 39 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
1251 | 40 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt); |
2597 | 41 |
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, Frames: LongInt; Angle: real); |
822 | 42 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
853 | 43 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
822 | 44 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
762 | 45 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
46 |
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
|
47 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1431 | 48 |
procedure DrawFillRect(r: TSDL_Rect); |
762 | 49 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
2017 | 50 |
function RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture; |
51 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
|
52 |
//procedure rotateSurface(Surface: PSDL_Surface); |
|
53 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL |
|
54 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer); |
|
4 | 55 |
procedure RenderHealth(var Hedgehog: THedgehog); |
56 |
procedure AddProgress; |
|
510 | 57 |
procedure FinishProgress; |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
58 |
function LoadImage(const filename: string; imageFlags: Integer): PSDL_Surface; |
753 | 59 |
procedure SetupOpenGL; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
60 |
procedure SetScale(f: GLfloat); |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
61 |
|
4 | 62 |
|
1525 | 63 |
var PixelFormat: PSDL_PixelFormat = nil; |
64 |
SDLPrimSurface: PSDL_Surface = nil; |
|
1023 | 65 |
PauseTexture, |
2397
2ca4ca6b4bab
- Patch for "Syncronizing" message by Smaxx + some tweaks by me
unc0rr
parents:
2376
diff
changeset
|
66 |
SyncTexture, |
1023 | 67 |
ConfirmTexture: PTexture; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
68 |
cScaleFactor: GLfloat = 2.0; |
2428 | 69 |
SupportNPOTT: Boolean = false; |
4 | 70 |
|
71 |
implementation |
|
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
72 |
uses uMisc, uConsole, uLand, uLocale, uWorld; |
4 | 73 |
|
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
74 |
type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel); |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
75 |
|
690 | 76 |
var |
761 | 77 |
HHTexture: PTexture; |
2153 | 78 |
MaxTextureSize: Integer; |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
79 |
cGPUVendor: TGPUVendor; |
4 | 80 |
|
81 |
procedure StoreInit; |
|
82 |
begin |
|
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
83 |
cGPUVendor:= gvUnknown; |
4 | 84 |
end; |
85 |
||
351 | 86 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
47 | 87 |
var r: TSDL_Rect; |
88 |
begin |
|
89 |
r:= rect^; |
|
83 | 90 |
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
|
91 |
|
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
92 |
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
|
93 |
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
|
94 |
|
351 | 95 |
r.y:= rect^.y + 1; |
96 |
r.h:= rect^.h - 2; |
|
47 | 97 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 98 |
r.x:= rect^.x + 1; |
99 |
r.w:= rect^.w - 2; |
|
100 |
r.y:= rect^.y; |
|
101 |
r.h:= rect^.h; |
|
47 | 102 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 103 |
r.x:= rect^.x + 2; |
104 |
r.y:= rect^.y + 1; |
|
105 |
r.w:= rect^.w - 4; |
|
106 |
r.h:= rect^.h - 2; |
|
47 | 107 |
SDL_FillRect(Surface, @r, FillColor); |
351 | 108 |
r.x:= rect^.x + 1; |
109 |
r.y:= rect^.y + 2; |
|
110 |
r.w:= rect^.w - 2; |
|
111 |
r.h:= rect^.h - 4; |
|
47 | 112 |
SDL_FillRect(Surface, @r, FillColor) |
113 |
end; |
|
114 |
||
371 | 115 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
351 | 116 |
var w, h: LongInt; |
4 | 117 |
tmpsurf: PSDL_Surface; |
118 |
clr: TSDL_Color; |
|
351 | 119 |
Result: TSDL_Rect; |
4 | 120 |
begin |
2620
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
121 |
TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
122 |
Result.x:= X; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
123 |
Result.y:= Y; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
124 |
Result.w:= w + FontBorder * 2 + 4; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
125 |
Result.h:= h + FontBorder * 2; |
2623 | 126 |
DrawRoundRect(@Result, cWhiteColor, cNearBlackColor, Surface, true); |
2620
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
127 |
clr.r:= Color shr 16; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
128 |
clr.g:= (Color shr 8) and $FF; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
129 |
clr.b:= Color and $FF; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
130 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr.value); |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
131 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
132 |
Result.x:= X + FontBorder + 2; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
133 |
Result.y:= Y + FontBorder; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
134 |
SDLTry(tmpsurf <> nil, true); |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
135 |
SDL_UpperBlit(tmpsurf, nil, Surface, @Result); |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
136 |
SDL_FreeSurface(tmpsurf); |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
137 |
Result.x:= X; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
138 |
Result.y:= Y; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
139 |
Result.w:= w + FontBorder * 2 + 4; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
140 |
Result.h:= h + FontBorder * 2; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
141 |
WriteInRoundRect:= Result |
4 | 142 |
end; |
143 |
||
144 |
procedure StoreLoad; |
|
844 | 145 |
var s: string; |
4 | 146 |
|
1185 | 147 |
procedure WriteNames(Font: THWFont); |
148 |
var t: LongInt; |
|
149 |
i: LongInt; |
|
150 |
r, rr: TSDL_Rect; |
|
151 |
drY: LongInt; |
|
152 |
texsurf: PSDL_Surface; |
|
153 |
begin |
|
154 |
r.x:= 0; |
|
155 |
r.y:= 0; |
|
156 |
drY:= - 4; |
|
157 |
for t:= 0 to Pred(TeamsCount) do |
|
158 |
with TeamsArray[t]^ do |
|
159 |
begin |
|
160 |
NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font); |
|
690 | 161 |
|
1185 | 162 |
r.w:= cTeamHealthWidth + 5; |
163 |
r.h:= NameTagTex^.h; |
|
690 | 164 |
|
1185 | 165 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
166 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
167 |
TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
690 | 168 |
|
2623 | 169 |
DrawRoundRect(@r, cWhiteColor, cNearBlackColor, texsurf, true); |
1185 | 170 |
rr:= r; |
171 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
|
172 |
DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false); |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
173 |
HealthTex:= Surface2Tex(texsurf, false); |
1185 | 174 |
SDL_FreeSurface(texsurf); |
690 | 175 |
|
1185 | 176 |
dec(drY, r.h + 2); |
177 |
DrawHealthY:= drY; |
|
178 |
for i:= 0 to 7 do |
|
179 |
with Hedgehogs[i] do |
|
180 |
if Gear <> nil then |
|
1242 | 181 |
begin |
1185 | 182 |
NameTagTex:= RenderStringTex(Name, Clan^.Color, fnt16); |
1294
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
183 |
if Hat <> 'NoHat' then |
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
184 |
begin |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
185 |
texsurf:= LoadImage(Pathz[ptHats] + '/' + Hat, ifNone); |
1698 | 186 |
if texsurf <> nil then |
187 |
begin |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
188 |
HatTex:= Surface2Tex(texsurf, true); |
1698 | 189 |
SDL_FreeSurface(texsurf) |
190 |
end |
|
1294
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
191 |
end |
1242 | 192 |
end; |
1185 | 193 |
end; |
194 |
end; |
|
4 | 195 |
|
1185 | 196 |
procedure MakeCrossHairs; |
197 |
var t: LongInt; |
|
198 |
tmpsurf, texsurf: PSDL_Surface; |
|
199 |
Color, i: Longword; |
|
200 |
begin |
|
201 |
s:= Pathz[ptGraphics] + '/' + cCHFileName; |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
202 |
tmpsurf:= LoadImage(s, ifAlpha or ifCritical); |
4 | 203 |
|
1185 | 204 |
for t:= 0 to Pred(TeamsCount) do |
205 |
with TeamsArray[t]^ do |
|
206 |
begin |
|
207 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask); |
|
208 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
209 |
|
1185 | 210 |
Color:= Clan^.Color; |
211 |
Color:= SDL_MapRGB(texsurf^.format, Color shr 16, Color shr 8, Color and $FF); |
|
212 |
SDL_FillRect(texsurf, nil, Color); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
213 |
|
1185 | 214 |
SDL_UpperBlit(tmpsurf, nil, texsurf, nil); |
777 | 215 |
|
1185 | 216 |
TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Ooops', true); |
777 | 217 |
|
1185 | 218 |
if SDL_MustLock(texsurf) then |
219 |
SDLTry(SDL_LockSurface(texsurf) >= 0, true); |
|
777 | 220 |
|
1185 | 221 |
// make black pixel be alpha-transparent |
222 |
for i:= 0 to texsurf^.w * texsurf^.h - 1 do |
|
2592 | 223 |
if PLongwordArray(texsurf^.pixels)^[i] = AMask then PLongwordArray(texsurf^.pixels)^[i]:= 0; |
777 | 224 |
|
1185 | 225 |
if SDL_MustLock(texsurf) then |
226 |
SDL_UnlockSurface(texsurf); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
227 |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
228 |
CrosshairTex:= Surface2Tex(texsurf, false); |
1185 | 229 |
SDL_FreeSurface(texsurf) |
230 |
end; |
|
351 | 231 |
|
1185 | 232 |
SDL_FreeSurface(tmpsurf) |
233 |
end; |
|
4 | 234 |
|
1185 | 235 |
procedure InitHealth; |
236 |
var i, t: LongInt; |
|
237 |
begin |
|
238 |
for t:= 0 to Pred(TeamsCount) do |
|
239 |
if TeamsArray[t] <> nil then |
|
240 |
with TeamsArray[t]^ do |
|
241 |
begin |
|
242 |
for i:= 0 to cMaxHHIndex do |
|
243 |
if Hedgehogs[i].Gear <> nil then |
|
244 |
RenderHealth(Hedgehogs[i]); |
|
245 |
end |
|
246 |
end; |
|
4 | 247 |
|
1185 | 248 |
procedure LoadGraves; |
249 |
var t: LongInt; |
|
250 |
texsurf: PSDL_Surface; |
|
251 |
begin |
|
252 |
for t:= 0 to Pred(TeamsCount) do |
|
253 |
if TeamsArray[t] <> nil then |
|
254 |
with TeamsArray[t]^ do |
|
255 |
begin |
|
256 |
if GraveName = '' then GraveName:= 'Simple'; |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
257 |
texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifCritical or ifTransparent); |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
258 |
GraveTex:= Surface2Tex(texsurf, false); |
1185 | 259 |
SDL_FreeSurface(texsurf) |
260 |
end |
|
261 |
end; |
|
4 | 262 |
|
844 | 263 |
var ii: TSprite; |
264 |
fi: THWFont; |
|
265 |
ai: TAmmoType; |
|
266 |
tmpsurf: PSDL_Surface; |
|
267 |
i: LongInt; |
|
4 | 268 |
begin |
2222 | 269 |
|
4 | 270 |
for fi:= Low(THWFont) to High(THWFont) do |
1185 | 271 |
with Fontz[fi] do |
272 |
begin |
|
273 |
s:= Pathz[ptFonts] + '/' + Name; |
|
274 |
WriteToConsole(msgLoading + s + '... '); |
|
275 |
Handle:= TTF_OpenFont(Str2PChar(s), Height); |
|
276 |
SDLTry(Handle <> nil, true); |
|
277 |
TTF_SetFontStyle(Handle, style); |
|
278 |
WriteLnToConsole(msgOK) |
|
279 |
end; |
|
53 | 280 |
|
4 | 281 |
WriteNames(fnt16); |
70 | 282 |
MakeCrossHairs; |
4 | 283 |
LoadGraves; |
284 |
||
285 |
AddProgress; |
|
286 |
for ii:= Low(TSprite) to High(TSprite) do |
|
1185 | 287 |
with SpritesData[ii] do |
2145 | 288 |
// FIXME - add a sprite attribute |
2426 | 289 |
if (not cReducedQuality) or (not (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR, sprFlake])) then // FIXME: hack |
2229
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
290 |
begin |
1185 | 291 |
if AltPath = ptNone then |
2426 | 292 |
if ii in [sprHorizontL, sprHorizontR, sprSkyL, sprSkyR] then // FIXME: hack |
293 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifLowRes) |
|
294 |
else |
|
295 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical or ifLowRes) |
|
1185 | 296 |
else begin |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
297 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
1185 | 298 |
if tmpsurf = nil then |
2610 | 299 |
tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent); |
1185 | 300 |
end; |
2426 | 301 |
|
302 |
if tmpsurf <> nil then |
|
2630 | 303 |
begin |
2610 | 304 |
if imageWidth = 0 then imageWidth:= tmpsurf^.w; |
305 |
if imageHeight = 0 then imageHeight:= tmpsurf^.h; |
|
2426 | 306 |
if Width = 0 then Width:= tmpsurf^.w; |
307 |
if Height = 0 then Height:= tmpsurf^.h; |
|
2452 | 308 |
if (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]) then |
2426 | 309 |
Texture:= Surface2Tex(tmpsurf, true) |
310 |
else |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
311 |
begin |
2426 | 312 |
Texture:= Surface2Tex(tmpsurf, false); |
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
313 |
if (ii = sprWater) and not cReducedQuality then // HACK: We should include some sprite attribute to define the texture wrap directions |
2630 | 314 |
begin |
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
315 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
316 |
end; |
2630 | 317 |
end; |
2426 | 318 |
if saveSurf then Surface:= tmpsurf else SDL_FreeSurface(tmpsurf) |
319 |
end |
|
320 |
else |
|
321 |
Surface:= nil |
|
2229
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
322 |
end; |
80 | 323 |
|
4 | 324 |
AddProgress; |
567 | 325 |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
326 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent); |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
327 |
HHTexture:= Surface2Tex(tmpsurf, false); |
761 | 328 |
SDL_FreeSurface(tmpsurf); |
4 | 329 |
|
330 |
InitHealth; |
|
331 |
||
2623 | 332 |
PauseTexture:= RenderStringTex(trmsg[sidPaused], cYellowColor, fntBig); |
333 |
ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], cYellowColor, fntBig); |
|
334 |
SyncTexture:= RenderStringTex(trmsg[sidSync], cYellowColor, fntBig); |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
335 |
|
2601 | 336 |
AddProgress; |
337 |
||
843 | 338 |
for ai:= Low(TAmmoType) to High(TAmmoType) do |
339 |
with Ammoz[ai] do |
|
340 |
begin |
|
2619 | 341 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(trAmmo[NameId]), cWhiteColor); |
342 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
343 |
NameTex:= Surface2Tex(tmpsurf, false); |
843 | 344 |
SDL_FreeSurface(tmpsurf) |
345 |
end; |
|
2376 | 346 |
|
844 | 347 |
for i:= Low(CountTexz) to High(CountTexz) do |
348 |
begin |
|
2619 | 349 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColor); |
350 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
351 |
CountTexz[i]:= Surface2Tex(tmpsurf, false); |
844 | 352 |
SDL_FreeSurface(tmpsurf) |
353 |
end; |
|
354 |
||
4 | 355 |
{$IFDEF DUMP} |
2601 | 356 |
//not working anymore, where are LandSurface and StoreSurface defined? |
357 |
//SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
358 |
//SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
4 | 359 |
{$ENDIF} |
2222 | 360 |
AddProgress; |
4 | 361 |
end; |
362 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
363 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
4 | 364 |
var rr: TSDL_Rect; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
365 |
_l, _r, _t, _b: real; |
1916 | 366 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
4 | 367 |
begin |
2428 | 368 |
if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit; |
4 | 369 |
rr.x:= X; |
370 |
rr.y:= Y; |
|
351 | 371 |
rr.w:= r^.w; |
372 |
rr.h:= r^.h; |
|
755 | 373 |
|
1896 | 374 |
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx; |
375 |
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx; |
|
376 |
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry; |
|
377 |
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry; |
|
755 | 378 |
|
379 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
380 |
||
1916 | 381 |
VertexBuffer[0].X:= X; |
382 |
VertexBuffer[0].Y:= Y; |
|
383 |
VertexBuffer[1].X:= rr.w + X; |
|
384 |
VertexBuffer[1].Y:= Y; |
|
385 |
VertexBuffer[2].X:= rr.w + X; |
|
386 |
VertexBuffer[2].Y:= rr.h + Y; |
|
387 |
VertexBuffer[3].X:= X; |
|
388 |
VertexBuffer[3].Y:= rr.h + Y; |
|
755 | 389 |
|
1916 | 390 |
TextureBuffer[0].X:= _l; |
391 |
TextureBuffer[0].Y:= _t; |
|
392 |
TextureBuffer[1].X:= _r; |
|
393 |
TextureBuffer[1].Y:= _t; |
|
394 |
TextureBuffer[2].X:= _r; |
|
395 |
TextureBuffer[2].Y:= _b; |
|
396 |
TextureBuffer[3].X:= _l; |
|
397 |
TextureBuffer[3].Y:= _b; |
|
755 | 398 |
|
1916 | 399 |
glEnableClientState(GL_VERTEX_ARRAY); |
400 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
755 | 401 |
|
1916 | 402 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
403 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
404 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
405 |
||
406 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
407 |
glDisableClientState(GL_VERTEX_ARRAY) |
|
762 | 408 |
end; |
409 |
||
410 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
|
411 |
begin |
|
1904 | 412 |
glPushMatrix; |
413 |
glTranslatef(X, Y, 0); |
|
414 |
||
762 | 415 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
416 |
||
1904 | 417 |
glEnableClientState(GL_VERTEX_ARRAY); |
418 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
762 | 419 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
420 |
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
|
421 |
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
|
422 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); |
1904 | 423 |
|
424 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
425 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
426 |
||
427 |
glPopMatrix |
|
4 | 428 |
end; |
429 |
||
1251 | 430 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt); |
1242 | 431 |
var ft, fb: GLfloat; |
432 |
hw: LongInt; |
|
1916 | 433 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
1242 | 434 |
begin |
435 |
glPushMatrix; |
|
436 |
glTranslatef(X, Y, 0); |
|
2598 | 437 |
glScalef(Scale, Scale, 1.0); |
2597 | 438 |
|
439 |
if Dir < 0 then |
|
440 |
hw:= - 16 |
|
441 |
else |
|
442 |
hw:= 16; |
|
443 |
||
444 |
ft:= Frame / Frames * Texture^.ry; |
|
445 |
fb:= (Frame + 1) / Frames * Texture^.ry; |
|
446 |
||
447 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
448 |
||
449 |
VertexBuffer[0].X:= -hw; |
|
450 |
VertexBuffer[0].Y:= -16; |
|
451 |
VertexBuffer[1].X:= hw; |
|
452 |
VertexBuffer[1].Y:= -16; |
|
453 |
VertexBuffer[2].X:= hw; |
|
454 |
VertexBuffer[2].Y:= 16; |
|
455 |
VertexBuffer[3].X:= -hw; |
|
456 |
VertexBuffer[3].Y:= 16; |
|
457 |
||
458 |
TextureBuffer[0].X:= 0; |
|
459 |
TextureBuffer[0].Y:= ft; |
|
460 |
TextureBuffer[1].X:= Texture^.rx; |
|
461 |
TextureBuffer[1].Y:= ft; |
|
462 |
TextureBuffer[2].X:= Texture^.rx; |
|
463 |
TextureBuffer[2].Y:= fb; |
|
464 |
TextureBuffer[3].X:= 0; |
|
465 |
TextureBuffer[3].Y:= fb; |
|
466 |
||
467 |
glEnableClientState(GL_VERTEX_ARRAY); |
|
468 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
469 |
||
470 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
471 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
472 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
473 |
||
474 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
475 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
476 |
||
477 |
||
478 |
glPopMatrix |
|
479 |
end; |
|
480 |
||
481 |
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, Frames: LongInt; Angle: real); |
|
482 |
var ft, fb: GLfloat; |
|
483 |
hw: LongInt; |
|
484 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
|
485 |
begin |
|
486 |
glPushMatrix; |
|
487 |
glTranslatef(X, Y, 0); |
|
488 |
||
489 |
if Dir < 0 then |
|
490 |
glRotatef(Angle, 0, 0, -1) |
|
491 |
else |
|
492 |
glRotatef(Angle, 0, 0, 1); |
|
493 |
||
494 |
glTranslatef(Dir*OffsetX, OffsetY, 0); |
|
495 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
|
1242 | 496 |
|
497 |
if Dir < 0 then |
|
498 |
hw:= - 16 |
|
499 |
else |
|
500 |
hw:= 16; |
|
501 |
||
1896 | 502 |
ft:= Frame / Frames * Texture^.ry; |
503 |
fb:= (Frame + 1) / Frames * Texture^.ry; |
|
1242 | 504 |
|
505 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
506 |
||
1916 | 507 |
VertexBuffer[0].X:= -hw; |
508 |
VertexBuffer[0].Y:= -16; |
|
509 |
VertexBuffer[1].X:= hw; |
|
510 |
VertexBuffer[1].Y:= -16; |
|
511 |
VertexBuffer[2].X:= hw; |
|
512 |
VertexBuffer[2].Y:= 16; |
|
513 |
VertexBuffer[3].X:= -hw; |
|
514 |
VertexBuffer[3].Y:= 16; |
|
1242 | 515 |
|
1916 | 516 |
TextureBuffer[0].X:= 0; |
517 |
TextureBuffer[0].Y:= ft; |
|
518 |
TextureBuffer[1].X:= Texture^.rx; |
|
519 |
TextureBuffer[1].Y:= ft; |
|
520 |
TextureBuffer[2].X:= Texture^.rx; |
|
521 |
TextureBuffer[2].Y:= fb; |
|
522 |
TextureBuffer[3].X:= 0; |
|
523 |
TextureBuffer[3].Y:= fb; |
|
1242 | 524 |
|
1916 | 525 |
glEnableClientState(GL_VERTEX_ARRAY); |
526 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
1242 | 527 |
|
1916 | 528 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
529 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
530 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
531 |
||
532 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
533 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
534 |
||
1242 | 535 |
|
536 |
glPopMatrix |
|
537 |
end; |
|
538 |
||
822 | 539 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
775 | 540 |
begin |
777 | 541 |
DrawRotatedTex(SpritesData[Sprite].Texture, |
822 | 542 |
SpritesData[Sprite].Width, |
543 |
SpritesData[Sprite].Height, |
|
544 |
X, Y, Dir, Angle) |
|
777 | 545 |
end; |
546 |
||
853 | 547 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
806 | 548 |
begin |
549 |
glPushMatrix; |
|
809 | 550 |
glTranslatef(X, Y, 0); |
806 | 551 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
552 |
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
|
553 |
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
|
554 |
else |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
555 |
glRotatef(Angle, 0, 0, 1); |
853 | 556 |
if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
557 |
||
558 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
806 | 559 |
|
560 |
glPopMatrix |
|
561 |
end; |
|
562 |
||
822 | 563 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
1916 | 564 |
var VertexBuffer: array [0..3] of TVertex2f; |
777 | 565 |
begin |
775 | 566 |
glPushMatrix; |
567 |
glTranslatef(X, Y, 0); |
|
822 | 568 |
|
569 |
if Dir < 0 then |
|
570 |
begin |
|
571 |
hw:= - hw; |
|
572 |
glRotatef(Angle, 0, 0, -1); |
|
573 |
end else |
|
574 |
glRotatef(Angle, 0, 0, 1); |
|
575 |
||
775 | 576 |
|
777 | 577 |
glBindTexture(GL_TEXTURE_2D, Tex^.id); |
775 | 578 |
|
1916 | 579 |
VertexBuffer[0].X:= -hw; |
580 |
VertexBuffer[0].Y:= -hh; |
|
581 |
VertexBuffer[1].X:= hw; |
|
582 |
VertexBuffer[1].Y:= -hh; |
|
583 |
VertexBuffer[2].X:= hw; |
|
584 |
VertexBuffer[2].Y:= hh; |
|
585 |
VertexBuffer[3].X:= -hw; |
|
586 |
VertexBuffer[3].Y:= hh; |
|
775 | 587 |
|
1916 | 588 |
glEnableClientState(GL_VERTEX_ARRAY); |
589 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
775 | 590 |
|
1916 | 591 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
592 |
glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb); |
|
593 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
775 | 594 |
|
1916 | 595 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
596 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
775 | 597 |
|
598 |
glPopMatrix |
|
599 |
end; |
|
600 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
601 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
4 | 602 |
begin |
603 |
r.y:= r.y + Height * Position; |
|
604 |
r.h:= Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
605 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 606 |
end; |
607 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
608 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
2229
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
609 |
var row, col, numFramesFirstCol: LongInt; |
4 | 610 |
begin |
2229
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
611 |
numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height; |
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
612 |
row:= Frame mod numFramesFirstCol; |
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
613 |
col:= Frame div numFramesFirstCol; |
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
614 |
DrawSprite2 (Sprite, X, Y, col, row); |
4 | 615 |
end; |
616 |
||
1939 | 617 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
618 |
var r: TSDL_Rect; |
|
619 |
begin |
|
620 |
r.x:= 0; |
|
621 |
r.y:= 0; |
|
622 |
r.w:= SpritesData[Sprite].Width; |
|
623 |
r.h:= SpritesData[Sprite].Height; |
|
624 |
||
625 |
if (X < LeftX) then |
|
626 |
r.x:= LeftX - X; |
|
627 |
if (Y < TopY) then |
|
628 |
r.y:= TopY - Y; |
|
629 |
||
630 |
if (Y + SpritesData[Sprite].Height > BottomY) then |
|
631 |
r.h:= BottomY - Y + 1; |
|
632 |
if (X + SpritesData[Sprite].Width > RightX) then |
|
633 |
r.w:= RightX - X + 1; |
|
634 |
||
635 |
dec(r.h, r.y); |
|
636 |
dec(r.w, r.x); |
|
2230
d6963f72d21a
once again, trying to restore windows compatibility from nemo's experiments
koda
parents:
2229
diff
changeset
|
637 |
|
1939 | 638 |
DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture) |
639 |
end; |
|
640 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
641 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
43 | 642 |
var r: TSDL_Rect; |
643 |
begin |
|
644 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
645 |
r.w:= SpritesData[Sprite].Width; |
|
646 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
647 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
648 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
43 | 649 |
end; |
650 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
651 |
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
|
652 |
var r: TSDL_Rect; |
198 | 653 |
begin |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
654 |
r.x:= 0; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
655 |
r.w:= Source^.w; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
656 |
r.y:= Frame * Height; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
657 |
r.h:= Height; |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
658 |
DrawFromRect(X, Y, @r, Source) |
198 | 659 |
end; |
660 |
||
762 | 661 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
95 | 662 |
begin |
2567 | 663 |
DrawTexture(X - Source^.w shr 1, Top, Source) |
4 | 664 |
end; |
665 |
||
1865
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1854
diff
changeset
|
666 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1916 | 667 |
const VertexBuffer: array [0..3] of TVertex2f = ( |
668 |
(x: -16; y: -16), |
|
669 |
(x: 16; y: -16), |
|
670 |
(x: 16; y: 16), |
|
671 |
(x: -16; y: 16)); |
|
761 | 672 |
var l, r, t, b: real; |
1916 | 673 |
TextureBuffer: array [0..3] of TVertex2f; |
4 | 674 |
begin |
761 | 675 |
|
676 |
t:= Pos * 32 / HHTexture^.h; |
|
677 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
678 |
||
679 |
if Dir = -1 then |
|
680 |
begin |
|
681 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
682 |
r:= Step * 32 / HHTexture^.w |
|
683 |
end else |
|
684 |
begin |
|
685 |
l:= Step * 32 / HHTexture^.w; |
|
686 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
687 |
end; |
|
688 |
||
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
689 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
690 |
glPushMatrix(); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
691 |
glTranslatef(X, Y, 0); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
692 |
glRotatef(Angle, 0, 0, 1); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
693 |
|
761 | 694 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
695 |
||
1916 | 696 |
TextureBuffer[0].X:= l; |
697 |
TextureBuffer[0].Y:= t; |
|
698 |
TextureBuffer[1].X:= r; |
|
699 |
TextureBuffer[1].Y:= t; |
|
700 |
TextureBuffer[2].X:= r; |
|
701 |
TextureBuffer[2].Y:= b; |
|
702 |
TextureBuffer[3].X:= l; |
|
703 |
TextureBuffer[3].Y:= b; |
|
761 | 704 |
|
1916 | 705 |
glEnableClientState(GL_VERTEX_ARRAY); |
706 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
761 | 707 |
|
1916 | 708 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
709 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
710 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
761 | 711 |
|
1916 | 712 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
713 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
761 | 714 |
|
1854 | 715 |
|
716 |
glColor4f(1,1,1,1); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
717 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
718 |
glPopMatrix |
4 | 719 |
end; |
720 |
||
1431 | 721 |
procedure DrawFillRect(r: TSDL_Rect); |
1916 | 722 |
var VertexBuffer: array [0..3] of TVertex2f; |
1431 | 723 |
begin |
724 |
glDisable(GL_TEXTURE_2D); |
|
725 |
||
726 |
glColor4ub(0, 0, 0, 127); |
|
727 |
||
1916 | 728 |
VertexBuffer[0].X:= r.x; |
729 |
VertexBuffer[0].Y:= r.y; |
|
730 |
VertexBuffer[1].X:= r.x + r.w; |
|
731 |
VertexBuffer[1].Y:= r.y; |
|
732 |
VertexBuffer[2].X:= r.x + r.w; |
|
733 |
VertexBuffer[2].Y:= r.y + r.h; |
|
734 |
VertexBuffer[3].X:= r.x; |
|
735 |
VertexBuffer[3].Y:= r.y + r.h; |
|
1431 | 736 |
|
1916 | 737 |
glEnableClientState(GL_VERTEX_ARRAY); |
738 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
739 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
740 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
1431 | 741 |
|
742 |
glColor4f(1, 1, 1, 1); |
|
743 |
glEnable(GL_TEXTURE_2D) |
|
744 |
end; |
|
745 |
||
4 | 746 |
procedure StoreRelease; |
747 |
var ii: TSprite; |
|
748 |
begin |
|
749 |
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
|
750 |
begin |
759 | 751 |
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
|
752 |
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
|
753 |
end; |
761 | 754 |
|
1806 | 755 |
FreeTexture(HHTexture) |
4 | 756 |
end; |
757 |
||
762 | 758 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
432 | 759 |
var w, h: LongInt; |
351 | 760 |
Result: PSDL_Surface; |
95 | 761 |
begin |
1989 | 762 |
if length(s) = 0 then s:= ' '; |
355 | 763 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
785 | 764 |
|
762 | 765 |
Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
766 |
32, RMask, GMask, BMask, AMask); |
|
785 | 767 |
|
107 | 768 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
785 | 769 |
|
95 | 770 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
785 | 771 |
|
762 | 772 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
785 | 773 |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
774 |
RenderStringTex:= Surface2Tex(Result, false); |
785 | 775 |
|
762 | 776 |
SDL_FreeSurface(Result) |
95 | 777 |
end; |
778 |
||
2017 | 779 |
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
|
780 |
var textWidth, textHeight, x, y, w, h, i, j, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt; |
2017 | 781 |
Result, tmpsurf, rotatedEdge: PSDL_Surface; |
782 |
rect: TSDL_Rect; |
|
783 |
chars: TSysCharSet = [#9,' ','.',';',':','?','!',',']; |
|
784 |
substr: shortstring; |
|
785 |
edge, corner, tail: TSPrite; |
|
786 |
begin |
|
787 |
||
788 |
case SpeechType of |
|
2376 | 789 |
1: begin; |
790 |
edge:= sprSpeechEdge; |
|
2017 | 791 |
corner:= sprSpeechCorner; |
792 |
tail:= sprSpeechTail; |
|
793 |
end; |
|
2376 | 794 |
2: begin; |
2017 | 795 |
edge:= sprThoughtEdge; |
2376 | 796 |
corner:= sprThoughtCorner; |
2017 | 797 |
tail:= sprThoughtTail; |
798 |
end; |
|
2376 | 799 |
3: begin; |
2017 | 800 |
edge:= sprShoutEdge; |
801 |
corner:= sprShoutCorner; |
|
802 |
tail:= sprShoutTail; |
|
803 |
end; |
|
804 |
end; |
|
805 |
edgeHeight:= SpritesData[edge].Height; |
|
806 |
edgeWidth:= SpritesData[edge].Width; |
|
807 |
cornerWidth:= SpritesData[corner].Width; |
|
808 |
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
|
809 |
// This one screws up WrapText |
2022 | 810 |
//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
|
811 |
// 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
|
812 |
//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
|
813 |
|
2022 | 814 |
numLines:= 0; |
2017 | 815 |
|
816 |
if length(s) = 0 then s:= '...'; |
|
817 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
|
2332
351abbbb12f3
Lower bound on speech text width for proper rendering
nemo
parents:
2292
diff
changeset
|
818 |
if w<8 then w:= 8; |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
819 |
j:= 0; |
2017 | 820 |
if (length(s) > 20) then |
821 |
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
|
822 |
w:= 0; |
2017 | 823 |
i:= round(Sqrt(length(s)) * 2); |
824 |
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
|
825 |
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
|
826 |
// 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
|
827 |
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
|
828 |
begin |
2017 | 829 |
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
|
830 |
begin |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
831 |
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
|
832 |
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
|
833 |
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
|
834 |
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
|
835 |
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
|
836 |
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
|
837 |
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
|
838 |
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
|
839 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
840 |
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
|
841 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
842 |
end |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
843 |
else numLines := 1; |
2017 | 844 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
845 |
textWidth:=((w-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth; |
2022 | 846 |
textHeight:=(((numlines * h + 2)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth; |
2019 | 847 |
|
2022 | 848 |
textHeight:=max(textHeight,edgeWidth); |
2017 | 849 |
//textWidth:=max(textWidth,SpritesData[tail].Width); |
850 |
rect.x:= 0; |
|
851 |
rect.y:= 0; |
|
2022 | 852 |
rect.w:= textWidth + (cornerWidth * 2); |
853 |
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
|
854 |
//s:= inttostr(w) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h); |
2017 | 855 |
|
856 |
Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask); |
|
857 |
||
858 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
|
859 |
||
860 |
//////////////////////////////// CORNERS /////////////////////////////// |
|
861 |
copyToXY(SpritesData[corner].Surface, Result, 0, 0); /////////////////// NW |
|
862 |
||
863 |
flipSurface(SpritesData[corner].Surface, true); // store all 4 versions in memory to avoid repeated flips? |
|
864 |
x:= 0; |
|
865 |
y:= textHeight + cornerHeight -1; |
|
866 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// SW |
|
867 |
||
868 |
flipSurface(SpritesData[corner].Surface, false); |
|
869 |
x:= rect.w-cornerWidth-1; |
|
870 |
y:= textHeight + cornerHeight -1; |
|
871 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// SE |
|
872 |
||
873 |
flipSurface(SpritesData[corner].Surface, true); |
|
874 |
x:= rect.w-cornerWidth-1; |
|
875 |
y:= 0; |
|
876 |
copyToXY(SpritesData[corner].Surface, Result, x, y); /////////////////// NE |
|
877 |
flipSurface(SpritesData[corner].Surface, false); // restore original position |
|
878 |
//////////////////////////////// END CORNERS /////////////////////////////// |
|
879 |
||
880 |
//////////////////////////////// EDGES ////////////////////////////////////// |
|
881 |
x:= cornerWidth; |
|
882 |
y:= 0; |
|
883 |
while x < rect.w-cornerWidth-1 do |
|
884 |
begin |
|
885 |
copyToXY(SpritesData[edge].Surface, Result, x, y); ///////////////// top edge |
|
886 |
inc(x,edgeWidth); |
|
887 |
end; |
|
888 |
flipSurface(SpritesData[edge].Surface, true); |
|
889 |
x:= cornerWidth; |
|
890 |
y:= textHeight + cornerHeight*2 - edgeHeight-1; |
|
891 |
while x < rect.w-cornerWidth-1 do |
|
892 |
begin |
|
893 |
copyToXY(SpritesData[edge].Surface, Result, x, y); ///////////////// bottom edge |
|
894 |
inc(x,edgeWidth); |
|
895 |
end; |
|
896 |
flipSurface(SpritesData[edge].Surface, true); // restore original position |
|
897 |
||
898 |
rotatedEdge:= SDL_CreateRGBSurface(SDL_SWSURFACE, edgeHeight, edgeWidth, 32, RMask, GMask, BMask, AMask); |
|
899 |
x:= rect.w - edgeHeight - 1; |
|
900 |
y:= cornerHeight; |
|
901 |
//// initially was going to rotate in place, but the SDL spec claims width/height are read only |
|
902 |
copyRotatedSurface(SpritesData[edge].Surface,rotatedEdge); |
|
903 |
while y < textHeight + cornerHeight do |
|
904 |
begin |
|
905 |
copyToXY(rotatedEdge, Result, x, y); |
|
906 |
inc(y,edgeWidth); |
|
907 |
end; |
|
908 |
flipSurface(rotatedEdge, false); // restore original position |
|
909 |
x:= 0; |
|
910 |
y:= cornerHeight; |
|
911 |
while y < textHeight + cornerHeight do |
|
912 |
begin |
|
913 |
copyToXY(rotatedEdge, Result, x, y); |
|
914 |
inc(y,edgeWidth); |
|
915 |
end; |
|
916 |
//////////////////////////////// END EDGES ////////////////////////////////////// |
|
917 |
||
918 |
x:= cornerWidth; |
|
919 |
y:= textHeight + cornerHeight * 2 - edgeHeight - 1; |
|
920 |
copyToXY(SpritesData[tail].Surface, Result, x, y); |
|
921 |
||
922 |
rect.x:= edgeHeight; |
|
923 |
rect.y:= edgeHeight; |
|
924 |
rect.w:= rect.w - edgeHeight * 2; |
|
925 |
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
|
926 |
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
|
927 |
j:= rect.h; |
2017 | 928 |
SDL_FillRect(Result, @rect, cWhiteColor); |
929 |
||
930 |
pos:= 1; prevpos:= 0; line:= 0; |
|
931 |
while pos <= length(s) do |
|
932 |
begin |
|
933 |
if (s[pos] = #1) or (pos = length(s)) then |
|
934 |
begin |
|
935 |
if s[pos] <> #1 then inc(pos); |
|
936 |
while s[prevpos+1] = ' 'do inc(prevpos); |
|
937 |
substr:= copy(s, prevpos+1, pos-prevpos-1); |
|
938 |
if Length(substr) <> 0 then |
|
939 |
begin |
|
2624 | 940 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), |
941 |
{$IFDEF ENDIAN_LITTLE} |
|
942 |
cNearBlackColor |
|
943 |
{$ELSE} |
|
944 |
$100000FF |
|
945 |
{$ENDIF} |
|
946 |
); // do not remove me |
|
2619 | 947 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
948 |
rect.x:= edgeHeight + 1 + ((i - w) div 2); |
2022 | 949 |
// 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
|
950 |
rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h; |
2017 | 951 |
SDLTry(tmpsurf <> nil, true); |
952 |
SDL_UpperBlit(tmpsurf, nil, Result, @rect); |
|
953 |
SDL_FreeSurface(tmpsurf); |
|
954 |
inc(line); |
|
955 |
prevpos:= pos; |
|
956 |
end; |
|
957 |
end; |
|
958 |
inc(pos); |
|
959 |
end; |
|
960 |
||
961 |
//TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
962 |
RenderSpeechBubbleTex:= Surface2Tex(Result, true); |
2017 | 963 |
|
964 |
SDL_FreeSurface(rotatedEdge); |
|
965 |
SDL_FreeSurface(Result) |
|
966 |
end; |
|
967 |
||
4 | 968 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 969 |
var s: shortstring; |
4 | 970 |
begin |
351 | 971 |
str(Hedgehog.Gear^.Health, s); |
762 | 972 |
if Hedgehog.HealthTagTex <> nil then FreeTexture(Hedgehog.HealthTagTex); |
973 |
Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
|
4 | 974 |
end; |
975 |
||
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
976 |
function LoadImage(const filename: string; imageFlags: Integer): PSDL_Surface; |
30 | 977 |
var tmpsurf: PSDL_Surface; |
355 | 978 |
s: shortstring; |
2630 | 979 |
{$IFDEF IPHONEOS} |
980 |
tmpP: PLongWordArray; |
|
981 |
tmpA, tmpR, tmpG, tmpB: LongWord; |
|
982 |
i: LongInt; |
|
983 |
{$ENDIF} |
|
4 | 984 |
begin |
2630 | 985 |
WriteToConsole(msgLoading + filename + '... '); |
2426 | 986 |
|
2630 | 987 |
s:= filename + '.png'; |
988 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
2254 | 989 |
|
2630 | 990 |
if (imageFlags and ifLowRes) <> 0 then |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
991 |
begin |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
992 |
s:= filename + '-lowres.png'; |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
993 |
if (tmpsurf <> nil) then |
2376 | 994 |
begin |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
995 |
if ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
996 |
begin |
2426 | 997 |
SDL_FreeSurface(tmpsurf); |
2630 | 998 |
{$IFDEF DEBUGFILE} |
999 |
AddFileLog('...image too big, trying to load lowres version: ' + s + '...'); |
|
1000 |
{$ENDIF} |
|
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1001 |
tmpsurf:= IMG_Load(Str2PChar(s)) |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1002 |
end; |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1003 |
end |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1004 |
else |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1005 |
begin |
2630 | 1006 |
{$IFDEF DEBUGFILE} |
1007 |
AddFileLog('...image not found, trying to load lowres version: ' + s + '...'); |
|
1008 |
{$ENDIF} |
|
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1009 |
tmpsurf:= IMG_Load(Str2PChar(s)) |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1010 |
end; |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1011 |
end; |
2376 | 1012 |
|
2630 | 1013 |
if tmpsurf = nil then |
2153 | 1014 |
begin |
2630 | 1015 |
OutError(msgFailed, (imageFlags and ifCritical) <> 0); |
1016 |
exit(nil) |
|
2153 | 1017 |
end; |
1018 |
||
2630 | 1019 |
if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
2153 | 1020 |
begin |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1021 |
SDL_FreeSurface(tmpsurf); |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1022 |
OutError(msgFailedSize, (imageFlags and ifCritical) <> 0); |
2630 | 1023 |
// dummy surface to replace non-critical textures that failed to load due to their size |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1024 |
exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask)); |
2153 | 1025 |
end; |
351 | 1026 |
|
2630 | 1027 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
1028 |
||
1029 |
{$IFDEF IPHONEOS} |
|
1030 |
{* http://bugzilla.libsdl.org/show_bug.cgi?id=868 but patched library doesn't work on ipod, so implementing workaround here *} |
|
1031 |
if imageFlags and (ifAlpha or ifTransparent) > 0 then |
|
1032 |
begin |
|
1033 |
tmpP := tmpsurf^.pixels; |
|
1034 |
for i:= 0 to (tmpsurf^.pitch shr 2) * tmpsurf^.h - 1 do |
|
1035 |
begin |
|
1036 |
{$IFDEF ENDIAN_LITTLE} |
|
1037 |
tmpA:= tmpP^[i] shr 24 and $FF; |
|
1038 |
tmpR:= tmpP^[i] shr 16 and $FF; |
|
1039 |
tmpG:= tmpP^[i] shr 8 and $FF; |
|
1040 |
tmpB:= tmpP^[i] and $FF; |
|
1041 |
{$ELSE} |
|
1042 |
tmpA:= tmpP^[i] and $FF; |
|
1043 |
tmpR:= tmpP^[i] shr 8 and $FF; |
|
1044 |
tmpG:= tmpP^[i] shr 16 and $FF; |
|
1045 |
tmpB:= tmpP^[i] shr 24 and $FF; |
|
1046 |
{$ENDIF} |
|
1047 |
if tmpA <> 0 then |
|
1048 |
begin |
|
1049 |
tmpR:= round(tmpR * 255 / tmpA); |
|
1050 |
tmpG:= round(tmpG * 255 / tmpA); |
|
1051 |
tmpB:= round(tmpB * 255 / tmpA); |
|
1052 |
end; |
|
2575 | 1053 |
|
2630 | 1054 |
if tmpR > 255 then tmpR:= 255; |
1055 |
if tmpG > 255 then tmpG:= 255; |
|
1056 |
if tmpB > 255 then tmpB:= 255; |
|
2153 | 1057 |
|
2630 | 1058 |
{$IFDEF ENDIAN_LITTLE} |
1059 |
tmpP^[i]:= (tmpA shl 24) or (tmpR shl 16) or (tmpG shl 8) or tmpB; |
|
1060 |
{$ELSE} |
|
1061 |
tmpP^[i]:= (tmpA) or (tmpR shl 8) or (tmpG shl 16) or (tmpB shl 24); |
|
1062 |
{$ENDIF} |
|
1063 |
end; |
|
1064 |
(* for i:= 0 to (tmpsurf^.pitch shr 2) * tmpsurf^.h - 1 do |
|
1065 |
begin |
|
1066 |
tmpA:= tmpP^[i] shr 24 and $FF; |
|
1067 |
tmpR:= tmpP^[i] shr 16 and $FF; |
|
1068 |
tmpG:= tmpP^[i] shr 8 and $FF; |
|
1069 |
tmpB:= tmpP^[i] and $FF; |
|
1070 |
writeln(stdout, inttostr(tmpA) + ' | ' + inttostr(tmpR) + ' | ' + inttostr(tmpG)+ ' | ' + inttostr(tmpB)); |
|
1071 |
end; *) |
|
1072 |
end; |
|
1073 |
{$ENDIF} |
|
1074 |
||
1075 |
if (imageFlags and ifTransparent) <> 0 then |
|
1076 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
1077 |
||
1078 |
WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') '); |
|
1079 |
WriteLnToConsole(msgOK); |
|
1080 |
||
1081 |
LoadImage:= tmpsurf //Result |
|
753 | 1082 |
end; |
1083 |
||
2428 | 1084 |
function glLoadExtension(extension : string) : boolean; |
1085 |
begin |
|
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1086 |
{$IFDEF IPHONEOS} |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1087 |
glLoadExtension:= false; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1088 |
{$ELSE} |
2428 | 1089 |
glLoadExtension:= glext_LoadExtension(extension); |
2438 | 1090 |
{$ENDIF} |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1091 |
{$IFDEF DEBUGFILE} |
2428 | 1092 |
if not glLoadExtension then |
2575 | 1093 |
AddFileLog('OpenGL - "' + extension + '" failed to load') |
2428 | 1094 |
else |
2575 | 1095 |
AddFileLog('OpenGL - "' + extension + '" loaded'); |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1096 |
{$ENDIF} |
2428 | 1097 |
end; |
1098 |
||
753 | 1099 |
procedure SetupOpenGL; |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1100 |
var vendor: shortstring; |
753 | 1101 |
begin |
2153 | 1102 |
glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize); |
2565 | 1103 |
|
2630 | 1104 |
WriteLnToConsole('OpenGL - Renderer: ' + string(pchar(glGetString(GL_RENDERER)))); |
2153 | 1105 |
{$IFDEF DEBUGFILE} |
2575 | 1106 |
AddFileLog('OpenGL - Vendor: ' + string(pchar(glGetString(GL_VENDOR)))); |
1107 |
AddFileLog('OpenGL - Version: ' + string(pchar(glGetString(GL_VERSION)))); |
|
2153 | 1108 |
{$ENDIF} |
2630 | 1109 |
WriteLnToConsole('OpenGL - GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize)); |
2252 | 1110 |
|
2630 | 1111 |
if MaxTextureSize = 0 then |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1112 |
begin |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1113 |
MaxTextureSize:= 1024; |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1114 |
{$IFDEF DEBUGFILE} |
2575 | 1115 |
AddFileLog('OpenGL Warning - driver didn''t provide any valid max texture size; assuming 1024'); |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1116 |
{$ENDIF} |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1117 |
end; |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1118 |
|
2575 | 1119 |
vendor:= LowerCase(string(pchar(glGetString(GL_VENDOR)))); |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1120 |
if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1121 |
cGPUVendor:= gvNVIDIA |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1122 |
else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1123 |
cGPUVendor:= gvATI |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1124 |
else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1125 |
cGPUVendor:= gvIntel; |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1126 |
|
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1127 |
|
2438 | 1128 |
{$IFNDEF IPHONEOS} |
2603 | 1129 |
// since ATI seems to be unable to provide proper texture filtering/quality, |
1130 |
// do not even try to load the extension on ATI cards |
|
1131 |
||
1132 |
{$IFDEF DARWIN} |
|
1133 |
if true then |
|
1134 |
{$ELSE} |
|
1135 |
if cGPUVendor <> gvATI then |
|
1136 |
{$ENDIF} |
|
1137 |
SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two') |
|
1138 |
{$IFDEF DEBUGFILE} |
|
1139 |
else |
|
1140 |
AddFileLog('OpenGL: Skipped extension GL_ARB_texture_non_power_of_two due to ATI card') |
|
1141 |
{$ENDIF} |
|
1142 |
; // do not touch this line! :) |
|
2428 | 1143 |
{$ENDIF} |
1144 |
||
1145 |
// set view port to whole window |
|
1146 |
glViewport(0, 0, cScreenWidth, cScreenHeight); |
|
1147 |
||
1148 |
glMatrixMode(GL_MODELVIEW); |
|
1149 |
// prepare default translation/scaling |
|
1150 |
glLoadIdentity; |
|
1151 |
glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
|
1152 |
glTranslatef(0, -cScreenHeight / 2, 0); |
|
1153 |
||
1154 |
// enable alpha blending |
|
1155 |
glEnable(GL_BLEND); |
|
1156 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
4 | 1157 |
end; |
1158 |
||
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1159 |
procedure SetScale(f: GLfloat); |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1160 |
begin |
2438 | 1161 |
// leave immediately if scale factor did not change |
2428 | 1162 |
if f = cScaleFactor then exit; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1163 |
|
2428 | 1164 |
if f = 2.0 then // default scaling |
1165 |
glPopMatrix // "return" to default scaling |
|
1166 |
else // other scaling |
|
1167 |
begin |
|
1168 |
glPushMatrix; // save default scaling |
|
1169 |
glLoadIdentity; |
|
1170 |
glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0); |
|
1171 |
glTranslatef(0, -cScreenHeight / 2, 0); |
|
1172 |
end; |
|
2258 | 1173 |
|
2428 | 1174 |
cScaleFactor:= f; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1175 |
end; |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1176 |
|
510 | 1177 |
//////////////////////////////////////////////////////////////////////////////// |
766 | 1178 |
var ProgrTex: PTexture = nil; |
534 | 1179 |
Step: integer = 0; |
2222 | 1180 |
squaresize : LongInt; |
1181 |
numsquares : integer; |
|
2284 | 1182 |
|
510 | 1183 |
procedure AddProgress; |
1184 |
var r: TSDL_Rect; |
|
766 | 1185 |
texsurf: PSDL_Surface; |
510 | 1186 |
begin |
1187 |
if Step = 0 then |
|
1188 |
begin |
|
1189 |
WriteToConsole(msgLoading + 'progress sprite: '); |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
1190 |
texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent); |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
1191 |
ProgrTex:= Surface2Tex(texsurf, false); |
2222 | 1192 |
SDL_FreeSurface(texsurf); |
1193 |
squaresize:= ProgrTex^.w shr 1; |
|
1194 |
numsquares:= ProgrTex^.h div squaresize; |
|
510 | 1195 |
end; |
1045 | 1196 |
|
2284 | 1197 |
TryDo(ProgrTex <> nil, 'ProgrTex = nil!', true); |
1198 |
||
766 | 1199 |
glClear(GL_COLOR_BUFFER_BIT); |
775 | 1200 |
glEnable(GL_TEXTURE_2D); |
2222 | 1201 |
if Step < numsquares then r.x:= 0 |
1202 |
else r.x:= squaresize; |
|
1203 |
r.y:= (Step mod numsquares) * squaresize; |
|
1204 |
r.w:= squaresize; |
|
1205 |
r.h:= squaresize; |
|
1206 |
DrawFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex); |
|
775 | 1207 |
glDisable(GL_TEXTURE_2D); |
766 | 1208 |
SDL_GL_SwapBuffers(); |
510 | 1209 |
inc(Step); |
1210 |
end; |
|
1211 |
||
2222 | 1212 |
|
510 | 1213 |
procedure FinishProgress; |
1214 |
begin |
|
1215 |
WriteLnToConsole('Freeing progress surface... '); |
|
2284 | 1216 |
FreeTexture(ProgrTex); |
1217 |
ProgrTex:= nil |
|
510 | 1218 |
end; |
1219 |
||
2017 | 1220 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
1221 |
var y, x, i, j: LongInt; |
|
1222 |
tmpPixel: Longword; |
|
1223 |
pixels: PLongWordArray; |
|
1224 |
begin |
|
1225 |
TryDo(Surface^.format^.BytesPerPixel = 4, 'flipSurface failed, expecting 32 bit surface', true); |
|
1226 |
pixels:= Surface^.pixels; |
|
1227 |
if Vertical then |
|
1228 |
for y := 0 to (Surface^.h div 2) - 1 do |
|
1229 |
for x := 0 to Surface^.w - 1 do |
|
1230 |
begin |
|
1231 |
i:= y * Surface^.w + x; |
|
1232 |
j:= (Surface^.h - y - 1) * Surface^.w + x; |
|
1233 |
tmpPixel:= pixels^[i]; |
|
1234 |
pixels^[i]:= pixels^[j]; |
|
1235 |
pixels^[j]:= tmpPixel; |
|
1236 |
end |
|
1237 |
else |
|
1238 |
for x := 0 to (Surface^.w div 2) - 1 do |
|
1239 |
for y := 0 to Surface^.h -1 do |
|
1240 |
begin |
|
1241 |
i:= y*Surface^.w + x; |
|
1242 |
j:= y*Surface^.w + (Surface^.w - x - 1); |
|
1243 |
tmpPixel:= pixels^[i]; |
|
1244 |
pixels^[i]:= pixels^[j]; |
|
1245 |
pixels^[j]:= tmpPixel; |
|
1246 |
end; |
|
1247 |
end; |
|
1248 |
||
1249 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer); |
|
1250 |
var srcX, srcY, i, j, maxDest: LongInt; |
|
1251 |
srcPixels, destPixels: PLongWordArray; |
|
1252 |
begin |
|
1253 |
maxDest:= (dest^.pitch div 4) * dest^.h; |
|
1254 |
srcPixels:= src^.pixels; |
|
1255 |
destPixels:= dest^.pixels; |
|
1256 |
||
1257 |
for srcX:= 0 to src^.w - 1 do |
|
1258 |
for srcY:= 0 to src^.h - 1 do |
|
1259 |
begin |
|
1260 |
i:= (destY + srcY) * (dest^.pitch div 4) + destX + srcX; |
|
1261 |
j:= srcY * (src^.pitch div 4) + srcX; |
|
1262 |
// basic skip of transparent pixels - cleverness would be to do true alpha |
|
2592 | 1263 |
if (i < maxDest) and (AMask and srcPixels^[j] <> 0) then destPixels^[i]:= srcPixels^[j]; |
2017 | 1264 |
end; |
1265 |
end; |
|
1266 |
||
1267 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently |
|
1268 |
var y, x, i, j: LongInt; |
|
1269 |
srcPixels, destPixels: PLongWordArray; |
|
1270 |
begin |
|
1271 |
TryDo(src^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
1272 |
TryDo(dest^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
1273 |
||
1274 |
srcPixels:= src^.pixels; |
|
1275 |
destPixels:= dest^.pixels; |
|
1276 |
||
1277 |
j:= 0; |
|
1278 |
for x := 0 to src^.w - 1 do |
|
1279 |
for y := 0 to src^.h - 1 do |
|
1280 |
begin |
|
1281 |
i:= (src^.h - 1 - y) * (src^.pitch div 4) + x; |
|
1282 |
destPixels^[j]:= srcPixels^[i]; |
|
1283 |
inc(j) |
|
1284 |
end; |
|
1285 |
end; |
|
1286 |
||
4 | 1287 |
end. |