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