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