173 end; |
173 end; |
174 |
174 |
175 procedure StoreLoad; |
175 procedure StoreLoad; |
176 var s: shortstring; |
176 var s: shortstring; |
177 |
177 |
178 procedure WriteNames(Font: THWFont); |
178 procedure WriteNames(Font: THWFont); |
179 var t: LongInt; |
179 var t: LongInt; |
180 i: LongInt; |
180 i: LongInt; |
181 r, rr: TSDL_Rect; |
181 r, rr: TSDL_Rect; |
182 drY: LongInt; |
182 drY: LongInt; |
183 texsurf, flagsurf, iconsurf: PSDL_Surface; |
183 texsurf, flagsurf, iconsurf: PSDL_Surface; |
184 begin |
184 begin |
185 r.x:= 0; |
185 r.x:= 0; |
186 r.y:= 0; |
186 r.y:= 0; |
187 drY:= - 4; |
187 drY:= - 4; |
188 for t:= 0 to Pred(TeamsCount) do |
188 for t:= 0 to Pred(TeamsCount) do |
189 with TeamsArray[t]^ do |
189 with TeamsArray[t]^ do |
190 begin |
190 begin |
191 NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font); |
191 NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font); |
192 |
192 |
193 r.w:= cTeamHealthWidth + 5; |
193 r.w:= cTeamHealthWidth + 5; |
194 r.h:= NameTagTex^.h; |
194 r.h:= NameTagTex^.h; |
195 |
195 |
196 texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
196 texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
197 TryDo(texsurf <> nil, errmsgCreateSurface, true); |
197 TryDo(texsurf <> nil, errmsgCreateSurface, true); |
198 TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
198 TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
199 |
199 |
200 DrawRoundRect(@r, cWhiteColor, cNearBlackColorChannels.value, texsurf, true); |
200 DrawRoundRect(@r, cWhiteColor, cNearBlackColorChannels.value, texsurf, true); |
201 rr:= r; |
201 rr:= r; |
202 inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
202 inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
203 DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false); |
203 DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false); |
204 HealthTex:= Surface2Tex(texsurf, false); |
204 HealthTex:= Surface2Tex(texsurf, false); |
205 SDL_FreeSurface(texsurf); |
205 SDL_FreeSurface(texsurf); |
206 |
206 |
207 r.x:= 0; |
207 r.x:= 0; |
208 r.y:= 0; |
208 r.y:= 0; |
209 r.w:= 32; |
209 r.w:= 32; |
210 r.h:= 32; |
210 r.h:= 32; |
211 texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
211 texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
212 TryDo(texsurf <> nil, errmsgCreateSurface, true); |
212 TryDo(texsurf <> nil, errmsgCreateSurface, true); |
213 TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
213 TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
214 |
214 |
215 r.w:= 26; |
215 r.w:= 26; |
216 r.h:= 19; |
216 r.h:= 19; |
217 |
217 |
218 DrawRoundRect(@r, cWhiteColor, cNearBlackColor, texsurf, true); |
218 DrawRoundRect(@r, cWhiteColor, cNearBlackColor, texsurf, true); |
219 |
219 |
220 // overwrite flag for cpu teams and keep players from using it |
220 // overwrite flag for cpu teams and keep players from using it |
221 if (Hedgehogs[0].Gear <> nil) and (Hedgehogs[0].BotLevel > 0) then |
221 if (Hedgehogs[0].Gear <> nil) and (Hedgehogs[0].BotLevel > 0) then |
222 Flag:= 'cpu' |
222 Flag:= 'cpu' |
223 else if Flag = 'cpu' then |
223 else if Flag = 'cpu' then |
224 Flag:= 'hedgewars'; |
224 Flag:= 'hedgewars'; |
225 |
225 |
226 flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone); |
226 flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone); |
227 if flagsurf = nil then |
227 if flagsurf = nil then |
228 flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone); |
228 flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone); |
229 TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true); |
229 TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true); |
230 copyToXY(flagsurf, texsurf, 2, 2); |
230 copyToXY(flagsurf, texsurf, 2, 2); |
231 SDL_FreeSurface(flagsurf); |
231 SDL_FreeSurface(flagsurf); |
232 |
232 |
233 // restore black border pixels inside the flag |
233 // restore black border pixels inside the flag |
234 PLongwordArray(texsurf^.pixels)^[32 * 2 + 2]:= cNearBlackColor; |
234 PLongwordArray(texsurf^.pixels)^[32 * 2 + 2]:= cNearBlackColor; |
235 PLongwordArray(texsurf^.pixels)^[32 * 2 + 23]:= cNearBlackColor; |
235 PLongwordArray(texsurf^.pixels)^[32 * 2 + 23]:= cNearBlackColor; |
236 PLongwordArray(texsurf^.pixels)^[32 * 16 + 2]:= cNearBlackColor; |
236 PLongwordArray(texsurf^.pixels)^[32 * 16 + 2]:= cNearBlackColor; |
237 PLongwordArray(texsurf^.pixels)^[32 * 16 + 23]:= cNearBlackColor; |
237 PLongwordArray(texsurf^.pixels)^[32 * 16 + 23]:= cNearBlackColor; |
238 |
238 |
239 FlagTex:= Surface2Tex(texsurf, false); |
239 FlagTex:= Surface2Tex(texsurf, false); |
240 |
240 |
241 dec(drY, r.h + 2); |
241 dec(drY, r.h + 2); |
242 DrawHealthY:= drY; |
242 DrawHealthY:= drY; |
243 for i:= 0 to 7 do |
243 for i:= 0 to 7 do |
244 with Hedgehogs[i] do |
244 with Hedgehogs[i] do |
245 if Gear <> nil then |
245 if Gear <> nil then |
246 begin |
246 begin |
247 NameTagTex:= RenderStringTex(Name, Clan^.Color, CheckCJKFont(Name,fnt16)); |
247 NameTagTex:= RenderStringTex(Name, Clan^.Color, CheckCJKFont(Name,fnt16)); |
248 if Hat <> 'NoHat' then |
248 if Hat <> 'NoHat' then |
249 begin |
249 begin |
250 texsurf:= nil; |
250 texsurf:= nil; |
251 if (Length(Hat) > 39) and (Copy(Hat,1,8) = 'Reserved') and (Copy(Hat,9,32) = PlayerHash) then |
251 if (Length(Hat) > 39) and (Copy(Hat,1,8) = 'Reserved') and (Copy(Hat,9,32) = PlayerHash) then |
252 texsurf:= LoadImage(Pathz[ptHats] + '/Reserved/' + Copy(Hat,9,Length(s)-8), ifNone) |
252 texsurf:= LoadImage(Pathz[ptHats] + '/Reserved/' + Copy(Hat,9,Length(s)-8), ifNone) |
253 else |
253 else |
254 texsurf:= LoadImage(Pathz[ptHats] + '/' + Hat, ifNone); |
254 texsurf:= LoadImage(Pathz[ptHats] + '/' + Hat, ifNone); |
255 if texsurf <> nil then |
255 if texsurf <> nil then |
256 begin |
256 begin |
257 HatTex:= Surface2Tex(texsurf, true); |
257 HatTex:= Surface2Tex(texsurf, true); |
258 SDL_FreeSurface(texsurf) |
258 SDL_FreeSurface(texsurf) |
259 end |
259 end |
260 end |
260 end |
261 end; |
261 end; |
262 end; |
262 end; |
263 MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical); |
263 MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical); |
264 iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask); |
264 iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask); |
265 if iconsurf <> nil then |
265 if iconsurf <> nil then |
266 begin |
266 begin |
267 r.x:= 0; |
267 r.x:= 0; |
268 r.y:= 0; |
268 r.y:= 0; |
269 r.w:= 28; |
269 r.w:= 28; |
270 r.h:= 28; |
270 r.h:= 28; |
271 DrawRoundRect(@r, cWhiteColor, cNearBlackColor, iconsurf, true); |
271 DrawRoundRect(@r, cWhiteColor, cNearBlackColor, iconsurf, true); |
272 ropeIconTex:= Surface2Tex(iconsurf, false); |
272 ropeIconTex:= Surface2Tex(iconsurf, false); |
273 SDL_FreeSurface(iconsurf) |
273 SDL_FreeSurface(iconsurf) |
274 end; |
274 end; |
275 end; |
275 end; |
276 |
276 |
277 procedure MakeCrossHairs; |
277 procedure MakeCrossHairs; |
278 var t: LongInt; |
278 var t: LongInt; |
279 tmpsurf, texsurf: PSDL_Surface; |
279 tmpsurf, texsurf: PSDL_Surface; |
280 Color, i: Longword; |
280 Color, i: Longword; |
281 begin |
281 begin |
282 s:= Pathz[ptGraphics] + '/' + cCHFileName; |
282 s:= Pathz[ptGraphics] + '/' + cCHFileName; |
283 tmpsurf:= LoadImage(s, ifAlpha or ifCritical); |
283 tmpsurf:= LoadImage(s, ifAlpha or ifCritical); |
284 |
284 |
285 for t:= 0 to Pred(TeamsCount) do |
285 for t:= 0 to Pred(TeamsCount) do |
286 with TeamsArray[t]^ do |
286 with TeamsArray[t]^ do |
287 begin |
287 begin |
288 texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask); |
288 texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask); |
289 TryDo(texsurf <> nil, errmsgCreateSurface, true); |
289 TryDo(texsurf <> nil, errmsgCreateSurface, true); |
290 |
290 |
291 Color:= Clan^.Color; |
291 Color:= Clan^.Color; |
292 Color:= SDL_MapRGB(texsurf^.format, Color shr 16, Color shr 8, Color and $FF); |
292 Color:= SDL_MapRGB(texsurf^.format, Color shr 16, Color shr 8, Color and $FF); |
293 SDL_FillRect(texsurf, nil, Color); |
293 SDL_FillRect(texsurf, nil, Color); |
294 |
294 |
295 SDL_UpperBlit(tmpsurf, nil, texsurf, nil); |
295 SDL_UpperBlit(tmpsurf, nil, texsurf, nil); |
296 |
296 |
297 TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Ooops', true); |
297 TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Ooops', true); |
298 |
298 |
299 if SDL_MustLock(texsurf) then |
299 if SDL_MustLock(texsurf) then |
300 SDLTry(SDL_LockSurface(texsurf) >= 0, true); |
300 SDLTry(SDL_LockSurface(texsurf) >= 0, true); |
301 |
301 |
302 // make black pixel be alpha-transparent |
302 // make black pixel be alpha-transparent |
303 for i:= 0 to texsurf^.w * texsurf^.h - 1 do |
303 for i:= 0 to texsurf^.w * texsurf^.h - 1 do |
304 if PLongwordArray(texsurf^.pixels)^[i] = AMask then PLongwordArray(texsurf^.pixels)^[i]:= 0; |
304 if PLongwordArray(texsurf^.pixels)^[i] = AMask then PLongwordArray(texsurf^.pixels)^[i]:= 0; |
305 |
305 |
306 if SDL_MustLock(texsurf) then |
306 if SDL_MustLock(texsurf) then |
307 SDL_UnlockSurface(texsurf); |
307 SDL_UnlockSurface(texsurf); |
308 |
308 |
309 CrosshairTex:= Surface2Tex(texsurf, false); |
309 CrosshairTex:= Surface2Tex(texsurf, false); |
310 SDL_FreeSurface(texsurf) |
310 SDL_FreeSurface(texsurf) |
311 end; |
311 end; |
312 |
312 |
313 SDL_FreeSurface(tmpsurf) |
313 SDL_FreeSurface(tmpsurf) |
314 end; |
314 end; |
315 |
315 |
316 procedure InitHealth; |
316 procedure InitHealth; |
317 var i, t: LongInt; |
317 var i, t: LongInt; |
318 begin |
318 begin |
319 for t:= 0 to Pred(TeamsCount) do |
319 for t:= 0 to Pred(TeamsCount) do |
320 if TeamsArray[t] <> nil then |
320 if TeamsArray[t] <> nil then |
321 with TeamsArray[t]^ do |
321 with TeamsArray[t]^ do |
322 begin |
322 begin |
323 for i:= 0 to cMaxHHIndex do |
323 for i:= 0 to cMaxHHIndex do |
324 if Hedgehogs[i].Gear <> nil then |
324 if Hedgehogs[i].Gear <> nil then |
325 RenderHealth(Hedgehogs[i]); |
325 RenderHealth(Hedgehogs[i]); |
326 end |
326 end |
327 end; |
327 end; |
328 |
328 |
329 procedure LoadGraves; |
329 procedure LoadGraves; |
330 var t: LongInt; |
330 var t: LongInt; |
331 texsurf: PSDL_Surface; |
331 texsurf: PSDL_Surface; |
332 begin |
332 begin |
333 for t:= 0 to Pred(TeamsCount) do |
333 for t:= 0 to Pred(TeamsCount) do |
334 if TeamsArray[t] <> nil then |
334 if TeamsArray[t] <> nil then |
335 with TeamsArray[t]^ do |
335 with TeamsArray[t]^ do |
336 begin |
336 begin |
337 if GraveName = '' then GraveName:= 'Simple'; |
337 if GraveName = '' then GraveName:= 'Simple'; |
338 texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifCritical or ifTransparent); |
338 texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifCritical or ifTransparent); |
339 GraveTex:= Surface2Tex(texsurf, false); |
339 GraveTex:= Surface2Tex(texsurf, false); |
340 SDL_FreeSurface(texsurf) |
340 SDL_FreeSurface(texsurf) |
341 end |
341 end |
342 end; |
342 end; |
343 |
343 |
344 var ii: TSprite; |
344 var ii: TSprite; |
345 fi: THWFont; |
345 fi: THWFont; |
346 ai: TAmmoType; |
346 ai: TAmmoType; |
347 tmpsurf: PSDL_Surface; |
347 tmpsurf: PSDL_Surface; |
348 i: LongInt; |
348 i: LongInt; |
349 begin |
349 begin |
350 |
350 |
351 for fi:= Low(THWFont) to High(THWFont) do |
351 for fi:= Low(THWFont) to High(THWFont) do |
352 with Fontz[fi] do |
352 with Fontz[fi] do |
353 begin |
353 begin |
354 s:= Pathz[ptFonts] + '/' + Name; |
354 s:= Pathz[ptFonts] + '/' + Name; |
355 WriteToConsole(msgLoading + s + '... '); |
355 WriteToConsole(msgLoading + s + '... '); |
356 Handle:= TTF_OpenFont(Str2PChar(s), Height); |
356 Handle:= TTF_OpenFont(Str2PChar(s), Height); |
357 SDLTry(Handle <> nil, true); |
357 SDLTry(Handle <> nil, true); |
358 TTF_SetFontStyle(Handle, style); |
358 TTF_SetFontStyle(Handle, style); |
359 WriteLnToConsole(msgOK) |
359 WriteLnToConsole(msgOK) |
360 end; |
360 end; |
361 |
361 |
362 WriteNames(fnt16); |
362 WriteNames(fnt16); |
363 MakeCrossHairs; |
363 MakeCrossHairs; |
364 LoadGraves; |
364 LoadGraves; |
365 |
365 |
366 AddProgress; |
366 AddProgress; |
367 for ii:= Low(TSprite) to High(TSprite) do |
367 for ii:= Low(TSprite) to High(TSprite) do |
368 with SpritesData[ii] do |
368 with SpritesData[ii] do |
369 // FIXME - add a sprite attribute |
369 // FIXME - add a sprite attribute |
370 if (not cReducedQuality) or (not (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR, sprFlake])) then // FIXME: hack |
370 if (not cReducedQuality) or (not (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR, sprFlake])) then // FIXME: hack |
371 begin |
371 begin |
372 if AltPath = ptNone then |
372 if AltPath = ptNone then |
373 if ii in [sprHorizontL, sprHorizontR, sprSkyL, sprSkyR] then // FIXME: hack |
373 if ii in [sprHorizontL, sprHorizontR, sprSkyL, sprSkyR] then // FIXME: hack |
374 tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifLowRes) |
374 tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifLowRes) |
375 else |
375 else |
376 tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical or ifLowRes) |
376 tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical or ifLowRes) |
377 else begin |
377 else begin |
378 tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
378 tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
379 if tmpsurf = nil then |
379 if tmpsurf = nil then |
380 tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent); |
380 tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent); |
381 end; |
381 end; |
382 |
382 |
383 if tmpsurf <> nil then |
383 if tmpsurf <> nil then |
384 begin |
384 begin |
385 if imageWidth = 0 then imageWidth:= tmpsurf^.w; |
385 if imageWidth = 0 then imageWidth:= tmpsurf^.w; |
386 if imageHeight = 0 then imageHeight:= tmpsurf^.h; |
386 if imageHeight = 0 then imageHeight:= tmpsurf^.h; |
387 if Width = 0 then Width:= tmpsurf^.w; |
387 if Width = 0 then Width:= tmpsurf^.w; |
388 if Height = 0 then Height:= tmpsurf^.h; |
388 if Height = 0 then Height:= tmpsurf^.h; |
389 if (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]) then |
389 if (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]) then |
390 Texture:= Surface2Tex(tmpsurf, true) |
390 Texture:= Surface2Tex(tmpsurf, true) |
391 else |
391 else |
392 begin |
392 begin |
393 Texture:= Surface2Tex(tmpsurf, false); |
393 Texture:= Surface2Tex(tmpsurf, false); |
394 if (ii = sprWater) and not cReducedQuality then // HACK: We should include some sprite attribute to define the texture wrap directions |
394 if (ii = sprWater) and not cReducedQuality then // HACK: We should include some sprite attribute to define the texture wrap directions |
395 begin |
395 begin |
396 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
396 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
397 end; |
397 end; |
398 end; |
398 end; |
399 if saveSurf then Surface:= tmpsurf else SDL_FreeSurface(tmpsurf) |
399 if saveSurf then Surface:= tmpsurf else SDL_FreeSurface(tmpsurf) |
400 end |
400 end |
401 else |
401 else |
402 Surface:= nil |
402 Surface:= nil |
403 end; |
403 end; |
404 |
404 |
405 AddProgress; |
405 AddProgress; |
406 |
406 |
407 tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent); |
407 tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent); |
408 HHTexture:= Surface2Tex(tmpsurf, false); |
408 HHTexture:= Surface2Tex(tmpsurf, false); |
1030 end; |
1030 end; |
1031 |
1031 |
1032 procedure RenderHealth(var Hedgehog: THedgehog); |
1032 procedure RenderHealth(var Hedgehog: THedgehog); |
1033 var s: shortstring; |
1033 var s: shortstring; |
1034 begin |
1034 begin |
1035 str(Hedgehog.Gear^.Health, s); |
1035 str(Hedgehog.Gear^.Health, s); |
1036 if Hedgehog.HealthTagTex <> nil then |
1036 if Hedgehog.HealthTagTex <> nil then |
1037 FreeTexture(Hedgehog.HealthTagTex); |
1037 FreeTexture(Hedgehog.HealthTagTex); |
1038 Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
1038 Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
1039 end; |
1039 end; |
1040 |
1040 |
1041 function LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface; |
1041 function LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface; |
1042 var tmpsurf: PSDL_Surface; |
1042 var tmpsurf: PSDL_Surface; |
1043 s: shortstring; |
1043 s: shortstring; |
1044 begin |
1044 begin |
1045 WriteToConsole(msgLoading + filename + ' [flags: ' + inttostr(imageFlags) + ']... '); |
1045 WriteToConsole(msgLoading + filename + ' [flags: ' + inttostr(imageFlags) + ']... '); |
1046 |
1046 |
1047 s:= filename + '.png'; |
1047 s:= filename + '.png'; |
1048 tmpsurf:= IMG_Load(Str2PChar(s)); |
1048 tmpsurf:= IMG_Load(Str2PChar(s)); |
1049 |
1049 |
1050 if (imageFlags and ifLowRes) <> 0 then |
1050 if (imageFlags and ifLowRes) <> 0 then |
1051 begin |
1051 begin |
1052 s:= filename + '-lowres.png'; |
1052 s:= filename + '-lowres.png'; |
1053 if (tmpsurf <> nil) then |
1053 if (tmpsurf <> nil) then |
1054 begin |
1054 begin |
1055 if ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
1055 if ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
1056 begin |
1056 begin |
1057 SDL_FreeSurface(tmpsurf); |
1057 SDL_FreeSurface(tmpsurf); |
1058 {$IFDEF DEBUGFILE} |
1058 {$IFDEF DEBUGFILE} |
1059 AddFileLog('...image too big, trying to load lowres version: ' + s + '...'); |
1059 AddFileLog('...image too big, trying to load lowres version: ' + s + '...'); |
1060 {$ENDIF} |
1060 {$ENDIF} |
1061 tmpsurf:= IMG_Load(Str2PChar(s)) |
1061 tmpsurf:= IMG_Load(Str2PChar(s)) |
1062 end; |
1062 end; |
1063 end |
1063 end |
1064 else |
1064 else |
1065 begin |
1065 begin |
1066 {$IFDEF DEBUGFILE} |
1066 {$IFDEF DEBUGFILE} |
1067 AddFileLog('...image not found, trying to load lowres version: ' + s + '...'); |
1067 AddFileLog('...image not found, trying to load lowres version: ' + s + '...'); |
1068 {$ENDIF} |
1068 {$ENDIF} |
1069 tmpsurf:= IMG_Load(Str2PChar(s)) |
1069 tmpsurf:= IMG_Load(Str2PChar(s)) |
1070 end; |
1070 end; |
1071 end; |
1071 end; |
1072 |
1072 |
1073 if tmpsurf = nil then |
1073 if tmpsurf = nil then |
1074 begin |
1074 begin |
1075 OutError(msgFailed, (imageFlags and ifCritical) <> 0); |
1075 OutError(msgFailed, (imageFlags and ifCritical) <> 0); |
1076 exit(nil) |
1076 exit(nil) |
1077 end; |
1077 end; |
1078 |
1078 |
1079 if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
1079 if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
1080 begin |
1080 begin |
1081 SDL_FreeSurface(tmpsurf); |
1081 SDL_FreeSurface(tmpsurf); |
1082 OutError(msgFailedSize, (imageFlags and ifCritical) <> 0); |
1082 OutError(msgFailedSize, (imageFlags and ifCritical) <> 0); |
1083 // dummy surface to replace non-critical textures that failed to load due to their size |
1083 // dummy surface to replace non-critical textures that failed to load due to their size |
1084 exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask)); |
1084 exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask)); |
1085 end; |
1085 end; |
1086 |
1086 |
1087 tmpsurf:= doSurfaceConversion(tmpsurf); |
1087 tmpsurf:= doSurfaceConversion(tmpsurf); |
1088 |
1088 |
1089 if (imageFlags and ifTransparent) <> 0 then |
1089 if (imageFlags and ifTransparent) <> 0 then |
1090 TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
1090 TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
1091 |
1091 |
1092 WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') '); |
1092 WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') '); |
1093 WriteLnToConsole(msgOK); |
1093 WriteLnToConsole(msgOK); |
1094 |
1094 |
1095 LoadImage:= tmpsurf //Result |
1095 LoadImage:= tmpsurf //Result |
1096 end; |
1096 end; |
1097 |
1097 |
1098 function glLoadExtension(extension : shortstring) : boolean; |
1098 function glLoadExtension(extension : shortstring) : boolean; |
1099 begin |
1099 begin |
1100 {$IFDEF IPHONEOS} |
1100 {$IFDEF IPHONEOS} |
1101 glLoadExtension:= false; |
1101 glLoadExtension:= false; |
1102 {$ELSE} |
1102 {$ELSE} |
1103 glLoadExtension:= glext_LoadExtension(extension); |
1103 glLoadExtension:= glext_LoadExtension(extension); |
1104 {$ENDIF} |
1104 {$ENDIF} |
1105 {$IFDEF DEBUGFILE} |
1105 {$IFDEF DEBUGFILE} |
1106 if not glLoadExtension then |
1106 if not glLoadExtension then |
1107 AddFileLog('OpenGL - "' + extension + '" failed to load') |
1107 AddFileLog('OpenGL - "' + extension + '" failed to load') |
1108 else |
1108 else |
1109 AddFileLog('OpenGL - "' + extension + '" loaded'); |
1109 AddFileLog('OpenGL - "' + extension + '" loaded'); |
1110 {$ENDIF} |
1110 {$ENDIF} |
1111 end; |
1111 end; |
1112 |
1112 |
1113 procedure SetupOpenGL; |
1113 procedure SetupOpenGL; |
1114 var vendor: shortstring; |
1114 var vendor: shortstring; |
1115 begin |
1115 begin |
1116 {$IFDEF IPHONEOS} |
1116 {$IFDEF IPHONEOS} |
1117 //these are good performance savers, perhaps we could enable them by default |
1117 //these are good performance savers, perhaps we could enable them by default |
1118 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0); |
1118 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0); |
1119 SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1); |
1119 SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1); |
1120 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); |
1120 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); |
1121 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); |
1121 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); |
1122 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); |
1122 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); |
1123 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); |
1123 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); |
1124 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); |
1124 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); |
1125 SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); |
1125 SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); |
1126 //SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); |
1126 //SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); |
1127 {$ELSE} |
1127 {$ELSE} |
1128 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
1128 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
1129 {$ENDIF} |
1129 {$ENDIF} |
1130 |
1130 |
1131 {$IFNDEF SDL13} |
1131 {$IFNDEF SDL13} |
1132 // this attribute is default in 1.3 and must be enabled in MacOSX |
1132 // this attribute is default in 1.3 and must be enabled in MacOSX |
1133 {$IFNDEF DARWIN} |
1133 {$IFNDEF DARWIN} |
1134 if cVSyncInUse then |
1134 if cVSyncInUse then |
1135 {$ENDIF} |
1135 {$ENDIF} |
1136 SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); |
1136 SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); |
1137 {$ENDIF} |
1137 {$ENDIF} |
1138 |
1138 |
1139 glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize); |
1139 glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize); |
1140 |
1140 |
1141 vendor:= LowerCase(shortstring(pchar(glGetString(GL_VENDOR)))); |
1141 vendor:= LowerCase(shortstring(pchar(glGetString(GL_VENDOR)))); |
1142 {$IFDEF DEBUGFILE} |
1142 {$IFDEF DEBUGFILE} |
1143 AddFileLog('OpenGL-- Renderer: ' + shortstring(pchar(glGetString(GL_RENDERER)))); |
1143 AddFileLog('OpenGL-- Renderer: ' + shortstring(pchar(glGetString(GL_RENDERER)))); |
1144 AddFileLog(' |----- Vendor: ' + vendor); |
1144 AddFileLog(' |----- Vendor: ' + vendor); |
1145 AddFileLog(' |----- Version: ' + shortstring(pchar(glGetString(GL_VERSION)))); |
1145 AddFileLog(' |----- Version: ' + shortstring(pchar(glGetString(GL_VERSION)))); |
1146 AddFileLog(' \----- GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize)); |
1146 AddFileLog(' \----- GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize)); |
1147 {$ENDIF} |
1147 {$ENDIF} |
1148 |
1148 |
1149 if MaxTextureSize <= 0 then |
1149 if MaxTextureSize <= 0 then |
1150 begin |
1150 begin |
1151 MaxTextureSize:= 1024; |
1151 MaxTextureSize:= 1024; |
1152 {$IFDEF DEBUGFILE} |
1152 {$IFDEF DEBUGFILE} |
1153 AddFileLog('OpenGL Warning - driver didn''t provide any valid max texture size; assuming 1024'); |
1153 AddFileLog('OpenGL Warning - driver didn''t provide any valid max texture size; assuming 1024'); |
1154 {$ENDIF} |
1154 {$ENDIF} |
1155 end; |
1155 end; |
1156 |
1156 |
1157 {$IFNDEF IPHONEOS} |
1157 {$IFNDEF IPHONEOS} |
1158 if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then |
1158 if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then |
1159 cGPUVendor:= gvNVIDIA |
1159 cGPUVendor:= gvNVIDIA |
1160 else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then |
1160 else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then |
1161 cGPUVendor:= gvATI |
1161 cGPUVendor:= gvATI |
1162 else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then |
1162 else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then |
1163 cGPUVendor:= gvIntel; |
1163 cGPUVendor:= gvIntel; |
1164 //SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two'); |
1164 //SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two'); |
1165 {$ELSE} |
1165 {$ELSE} |
1166 cGPUVendor:= gvApple; |
1166 cGPUVendor:= gvApple; |
1167 {$ENDIF} |
1167 {$ENDIF} |
1168 |
1168 |
1169 {$IFDEF DEBUGFILE} |
1169 {$IFDEF DEBUGFILE} |
1170 if cGPUVendor = gvUnknown then |
1170 if cGPUVendor = gvUnknown then |
1171 AddFileLog('OpenGL Warning - unknown hardware vendor; please report'); |
1171 AddFileLog('OpenGL Warning - unknown hardware vendor; please report'); |
1172 {$ELSE} |
1172 {$ELSE} |
1173 // just avoid 'never used' compiler warning for now |
1173 // just avoid 'never used' compiler warning for now |
1174 if cGPUVendor = gvUnknown then cGPUVendor:= gvUnknown; |
1174 if cGPUVendor = gvUnknown then cGPUVendor:= gvUnknown; |
1175 {$ENDIF} |
1175 {$ENDIF} |
1176 |
1176 |
1177 // set view port to whole window |
1177 // set view port to whole window |
1178 {$IFDEF IPHONEOS} |
1178 {$IFDEF IPHONEOS} |
1179 glViewport(0, 0, cScreenHeight, cScreenWidth); |
1179 glViewport(0, 0, cScreenHeight, cScreenWidth); |
1180 {$ELSE} |
1180 {$ELSE} |
1181 glViewport(0, 0, cScreenWidth, cScreenHeight); |
1181 glViewport(0, 0, cScreenWidth, cScreenHeight); |
1182 {$ENDIF} |
1182 {$ENDIF} |
1183 |
1183 |
1184 glMatrixMode(GL_MODELVIEW); |
1184 glMatrixMode(GL_MODELVIEW); |
1185 // prepare default translation/scaling |
1185 // prepare default translation/scaling |
1186 glLoadIdentity(); |
1186 glLoadIdentity(); |
1187 {$IFDEF IPHONEOS} |
1187 {$IFDEF IPHONEOS} |
1188 glRotatef(-90, 0, 0, 1); |
1188 glRotatef(-90, 0, 0, 1); |
1189 {$ENDIF} |
1189 {$ENDIF} |
1190 glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
1190 glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
1191 glTranslatef(0, -cScreenHeight / 2, 0); |
1191 glTranslatef(0, -cScreenHeight / 2, 0); |
1192 |
1192 |
1193 // enable alpha blending |
1193 // enable alpha blending |
1194 glEnable(GL_BLEND); |
1194 glEnable(GL_BLEND); |
1195 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1195 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1196 end; |
1196 end; |
1197 |
1197 |
1198 procedure SetScale(f: GLfloat); |
1198 procedure SetScale(f: GLfloat); |
1199 var |
1199 var |
1200 {$IFDEF IPHONEOS} |
1200 {$IFDEF IPHONEOS} |
1201 scale: GLfloat = 1.5; |
1201 scale: GLfloat = 1.5; |
1202 {$ELSE} |
1202 {$ELSE} |
1203 scale: GLfloat = 2.0; |
1203 scale: GLfloat = 2.0; |
1204 {$ENDIF} |
1204 {$ENDIF} |
1205 begin |
1205 begin |
1206 // leave immediately if scale factor did not change |
1206 // leave immediately if scale factor did not change |
1207 if f = cScaleFactor then exit; |
1207 if f = cScaleFactor then exit; |
1208 |
1208 |
1209 if f = scale then glPopMatrix // "return" to default scaling |
1209 if f = scale then glPopMatrix // "return" to default scaling |
1210 else // other scaling |
1210 else // other scaling |
1211 begin |
1211 begin |
1212 glPushMatrix; // save default scaling |
1212 glPushMatrix; // save default scaling |
1213 glLoadIdentity; |
1213 glLoadIdentity; |
1214 {$IFDEF IPHONEOS} |
1214 {$IFDEF IPHONEOS} |
1215 glRotatef(-90, 0, 0, 1); |
1215 glRotatef(-90, 0, 0, 1); |
1216 {$ENDIF} |
1216 {$ENDIF} |
1217 glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0); |
1217 glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0); |
1218 glTranslatef(0, -cScreenHeight / 2, 0); |
1218 glTranslatef(0, -cScreenHeight / 2, 0); |
1219 end; |
1219 end; |
1220 |
1220 |
1221 cScaleFactor:= f; |
1221 cScaleFactor:= f; |
1222 end; |
1222 end; |
1223 |
1223 |
1224 //////////////////////////////////////////////////////////////////////////////// |
1224 //////////////////////////////////////////////////////////////////////////////// |
1225 procedure AddProgress; |
1225 procedure AddProgress; |
1226 var r: TSDL_Rect; |
1226 var r: TSDL_Rect; |
1227 texsurf: PSDL_Surface; |
1227 texsurf: PSDL_Surface; |
1228 begin |
1228 begin |
1229 if Step = 0 then |
1229 if Step = 0 then |
1230 begin |
1230 begin |
1231 {$IFDEF SDL_IMAGE_NEWER} |
1231 {$IFDEF SDL_IMAGE_NEWER} |
1232 WriteToConsole('Init SDL_image... '); |
1232 WriteToConsole('Init SDL_image... '); |
1233 SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true); |
1233 SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true); |
1234 WriteLnToConsole(msgOK); |
1234 WriteLnToConsole(msgOK); |
1235 {$ENDIF} |
1235 {$ENDIF} |
1236 |
1236 |
1237 WriteToConsole(msgLoading + 'progress sprite: '); |
1237 WriteToConsole(msgLoading + 'progress sprite: '); |
1238 texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent); |
1238 texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent); |
1239 |
1239 |
1240 ProgrTex:= Surface2Tex(texsurf, false); |
1240 ProgrTex:= Surface2Tex(texsurf, false); |
1241 |
1241 |
1242 squaresize:= texsurf^.w shr 1; |
1242 squaresize:= texsurf^.w shr 1; |
1243 numsquares:= texsurf^.h div squaresize; |
1243 numsquares:= texsurf^.h div squaresize; |
1244 SDL_FreeSurface(texsurf); |
1244 SDL_FreeSurface(texsurf); |
1245 end; |
1245 end; |
1246 |
1246 |
1247 TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true); |
1247 TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true); |
1248 |
1248 |
1249 glClear(GL_COLOR_BUFFER_BIT); |
1249 glClear(GL_COLOR_BUFFER_BIT); |
1250 glEnable(GL_TEXTURE_2D); |
1250 glEnable(GL_TEXTURE_2D); |
1251 if Step < numsquares then r.x:= 0 |
1251 if Step < numsquares then r.x:= 0 |
1252 else r.x:= squaresize; |
1252 else r.x:= squaresize; |
1253 |
1253 |
1254 r.y:= (Step mod numsquares) * squaresize; |
1254 r.y:= (Step mod numsquares) * squaresize; |
1255 r.w:= squaresize; |
1255 r.w:= squaresize; |
1256 r.h:= squaresize; |
1256 r.h:= squaresize; |
1257 |
1257 |
1258 DrawFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex); |
1258 DrawFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex); |
1259 |
1259 |
1260 glDisable(GL_TEXTURE_2D); |
1260 glDisable(GL_TEXTURE_2D); |
1261 SDL_GL_SwapBuffers(); |
1261 SDL_GL_SwapBuffers(); |
1262 {$IFDEF SDL13} |
1262 {$IFDEF SDL13} |
1263 SDL_RenderPresent(); |
1263 SDL_RenderPresent(); |
1264 {$ENDIF} |
1264 {$ENDIF} |
1265 inc(Step); |
1265 inc(Step); |
1266 |
1266 |
1267 end; |
1267 end; |
1268 |
1268 |
1269 |
1269 |
1270 procedure FinishProgress; |
1270 procedure FinishProgress; |
1271 begin |
1271 begin |
1272 WriteLnToConsole('Freeing progress surface... '); |
1272 WriteLnToConsole('Freeing progress surface... '); |
1273 FreeTexture(ProgrTex); |
1273 FreeTexture(ProgrTex); |
1274 |
1274 |
1275 {$IFDEF IPHONEOS} |
1275 {$IFDEF IPHONEOS} |
1276 // show overlay buttons |
1276 // show overlay buttons |
1277 IPH_showControls; |
1277 IPH_showControls; |
1278 {$ENDIF} |
1278 {$ENDIF} |
1279 end; |
1279 end; |
1280 |
1280 |
1281 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
1281 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
1282 var y, x, i, j: LongInt; |
1282 var y, x, i, j: LongInt; |