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