hedgewars/uStore.pas
changeset 2671 7e0f88013fe8
parent 2670 1b327b7515ed
child 2672 0f1403bf267a
equal deleted inserted replaced
2670:1b327b7515ed 2671:7e0f88013fe8
    26 {$ELSE}
    26 {$ELSE}
    27 	GL, GLext,
    27 	GL, GLext,
    28 {$ENDIF}
    28 {$ENDIF}
    29 uFloat;
    29 uFloat;
    30 
    30 
    31 procedure StoreInit;
       
    32 procedure StoreLoad;
    31 procedure StoreLoad;
    33 procedure StoreRelease;
    32 procedure StoreRelease;
    34 procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt);
    33 procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt);
    35 procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt);
    34 procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt);
    36 procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
    35 procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
    53 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL
    52 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL
    54 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer);
    53 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer);
    55 procedure RenderHealth(var Hedgehog: THedgehog);
    54 procedure RenderHealth(var Hedgehog: THedgehog);
    56 procedure AddProgress;
    55 procedure AddProgress;
    57 procedure FinishProgress;
    56 procedure FinishProgress;
    58 function  LoadImage(const filename: string; imageFlags: Integer): PSDL_Surface;
    57 function  LoadImage(const filename: string; imageFlags: LongInt): PSDL_Surface;
    59 procedure SetupOpenGL;
    58 procedure SetupOpenGL;
    60 procedure SetScale(f: GLfloat);
    59 procedure SetScale(f: GLfloat);
    61 
    60 
    62 
    61 
    63 var PixelFormat: PSDL_PixelFormat = nil;
    62 var PixelFormat: PSDL_PixelFormat = nil;
    64  SDLPrimSurface: PSDL_Surface = nil;
    63    SDLPrimSurface: PSDL_Surface = nil;
    65    PauseTexture,
    64    PauseTexture,
    66    SyncTexture,
    65    SyncTexture,
    67    ConfirmTexture: PTexture;
    66    ConfirmTexture: PTexture;
    68    cScaleFactor: GLfloat = 2.0;
    67    cScaleFactor: GLfloat = 2.0;
    69    SupportNPOTT: Boolean = false;
    68    SupportNPOTT: Boolean = false;
    71 implementation
    70 implementation
    72 uses uMisc, uConsole, uLand, uLocale, uWorld;
    71 uses uMisc, uConsole, uLand, uLocale, uWorld;
    73 
    72 
    74 type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel);
    73 type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel);
    75 
    74 
    76 var
    75 var	HHTexture: PTexture;
    77     HHTexture: PTexture;
       
    78 	MaxTextureSize: Integer;
    76 	MaxTextureSize: Integer;
    79 	cGPUVendor: TGPUVendor;
    77 	{$IFNDEF IPHONEOS}cGPUVendor: TGPUVendor = gvUnknown;{$ENDIF}
    80 
       
    81 procedure StoreInit;
       
    82 begin
       
    83 	cGPUVendor:= gvUnknown;
       
    84 end;
       
    85 
    78 
    86 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean);
    79 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean);
    87 var r: TSDL_Rect;
    80 var r: TSDL_Rect;
    88 begin
    81 begin
    89 r:= rect^;
    82 r:= rect^;
   263     fi: THWFont;
   256     fi: THWFont;
   264     ai: TAmmoType;
   257     ai: TAmmoType;
   265     tmpsurf: PSDL_Surface;
   258     tmpsurf: PSDL_Surface;
   266     i: LongInt;
   259     i: LongInt;
   267 begin
   260 begin
   268 
       
   269 AddProgress;
       
   270 
   261 
   271 for fi:= Low(THWFont) to High(THWFont) do
   262 for fi:= Low(THWFont) to High(THWFont) do
   272 	with Fontz[fi] do
   263 	with Fontz[fi] do
   273 		begin
   264 		begin
   274 		s:= Pathz[ptFonts] + '/' + Name;
   265 		s:= Pathz[ptFonts] + '/' + Name;
   360 //SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1);
   351 //SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1);
   361 //SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1);
   352 //SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1);
   362 {$ENDIF}
   353 {$ENDIF}
   363 AddProgress;
   354 AddProgress;
   364 
   355 
       
   356 {$IFNDEF IPHONEOS}
       
   357 	// remove this ifndef when updating sdl_image
   365 IMG_Quit();
   358 IMG_Quit();
       
   359 {$ENDIF}
   366 end;
   360 end;
   367 
   361 
   368 procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
   362 procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
   369 var rr: TSDL_Rect;
   363 var rr: TSDL_Rect;
   370     _l, _r, _t, _b: real;
   364     _l, _r, _t, _b: real;
   969 str(Hedgehog.Gear^.Health, s);
   963 str(Hedgehog.Gear^.Health, s);
   970 if Hedgehog.HealthTagTex <> nil then FreeTexture(Hedgehog.HealthTagTex);
   964 if Hedgehog.HealthTagTex <> nil then FreeTexture(Hedgehog.HealthTagTex);
   971 Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16)
   965 Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16)
   972 end;
   966 end;
   973 
   967 
   974 function  LoadImage(const filename: string; imageFlags: Integer): PSDL_Surface;
   968 function  LoadImage(const filename: string; imageFlags: LongInt): PSDL_Surface;
   975 var tmpsurf: PSDL_Surface;
   969 var tmpsurf: PSDL_Surface;
   976     s: shortstring;
   970     s: shortstring;
   977 {$IFDEF IPHONEOS}
   971 {$IFDEF DONTUSE}
   978     tmpP: PLongWordArray;
   972     tmpP: PLongWordArray;
   979     tmpA, tmpR, tmpG, tmpB: LongWord;
   973     tmpA, tmpR, tmpG, tmpB: LongWord;
   980     i: LongInt;
   974     i: LongInt;
   981 {$ENDIF}
   975 {$ENDIF}
   982 begin
   976 begin
   983 	WriteToConsole(msgLoading + filename + '... ');
   977 	WriteToConsole(msgLoading + filename + ' [flags: ' + inttostr(imageFlags) + ']... ');
   984 
   978 
   985 	s:= filename + '.png';
   979 	s:= filename + '.png';
   986 	tmpsurf:= IMG_Load(Str2PChar(s));
   980 	tmpsurf:= IMG_Load(Str2PChar(s));
   987 
   981 
   988 	if (imageFlags and ifLowRes) <> 0 then
   982 	if (imageFlags and ifLowRes) <> 0 then
  1095 end;
  1089 end;
  1096 
  1090 
  1097 procedure SetupOpenGL;
  1091 procedure SetupOpenGL;
  1098 var vendor: shortstring;
  1092 var vendor: shortstring;
  1099 begin
  1093 begin
  1100 glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
  1094 	glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
  1101 
  1095 	vendor:= LowerCase(string(pchar(glGetString(GL_VENDOR))));
  1102 WriteLnToConsole('OpenGL - Renderer: ' + string(pchar(glGetString(GL_RENDERER))));
  1096 
  1103 {$IFDEF DEBUGFILE}
  1097 {$IFDEF DEBUGFILE}
  1104 AddFileLog('OpenGL - Vendor: ' + string(pchar(glGetString(GL_VENDOR))));
  1098 	AddFileLog('OpenGL - Renderer: ' + string(pchar(glGetString(GL_RENDERER))));
  1105 AddFileLog('OpenGL - Version: ' + string(pchar(glGetString(GL_VERSION))));
  1099 	AddFileLog('  |----- Vendor: ' + vendor);
       
  1100 	AddFileLog('  |----- Version: ' + string(pchar(glGetString(GL_VERSION))));
       
  1101 	AddFileLog('  \----- GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize));
  1106 {$ENDIF}
  1102 {$ENDIF}
  1107 WriteLnToConsole('OpenGL - GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize));
       
  1108 
  1103 
  1109 	if MaxTextureSize = 0 then
  1104 	if MaxTextureSize = 0 then
  1110 	begin
  1105 	begin
  1111 		MaxTextureSize:= 1024;
  1106 		MaxTextureSize:= 1024;
  1112 {$IFDEF DEBUGFILE}
  1107 {$IFDEF DEBUGFILE}
  1113 		AddFileLog('OpenGL Warning - driver didn''t provide any valid max texture size; assuming 1024');
  1108 		AddFileLog('OpenGL Warning - driver didn''t provide any valid max texture size; assuming 1024');
  1114 {$ENDIF}
  1109 {$ENDIF}
  1115 	end;
  1110 	end;
  1116 
  1111 
  1117 vendor:= LowerCase(string(pchar(glGetString(GL_VENDOR))));
  1112 {$IFNDEF IPHONEOS}
  1118 if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then
  1113 if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then
  1119 	cGPUVendor:= gvNVIDIA
  1114 	cGPUVendor:= gvNVIDIA
  1120 else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then
  1115 else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then
  1121 	cGPUVendor:= gvATI
  1116 	cGPUVendor:= gvATI
  1122 else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then
  1117 else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then
  1123 	cGPUVendor:= gvIntel;
  1118 	cGPUVendor:= gvIntel;
  1124 
  1119 
  1125 	
       
  1126 {$IFNDEF IPHONEOS}
       
  1127 //SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two');
  1120 //SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two');
  1128 {$ENDIF}
  1121 {$ENDIF}
  1129 
  1122 
  1130 // set view port to whole window
  1123 // set view port to whole window
  1131 glViewport(0, 0, cScreenWidth, cScreenHeight);
  1124 glViewport(0, 0, cScreenWidth, cScreenHeight);
  1173 
  1166 
  1174 procedure AddProgress;
  1167 procedure AddProgress;
  1175 var r: TSDL_Rect;
  1168 var r: TSDL_Rect;
  1176     texsurf: PSDL_Surface;
  1169     texsurf: PSDL_Surface;
  1177 begin
  1170 begin
  1178 if Step = 0 then
  1171 	if Step = 0 then
  1179    begin
  1172 	begin
  1180    WriteToConsole(msgLoading + 'progress sprite: ');
  1173 	{$IFNDEF IPHONEOS}
  1181    texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent);
  1174 	// remove this ifndef when updating sdl_image
  1182    ProgrTex:= Surface2Tex(texsurf, false);
  1175 		WriteToConsole('Init SDL_image... ');
  1183    SDL_FreeSurface(texsurf);
  1176 		SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
  1184    squaresize:= ProgrTex^.w shr 1;
  1177 		WriteLnToConsole(msgOK);
  1185    numsquares:= ProgrTex^.h div squaresize;
  1178 	{$ENDIF}
  1186    end;
  1179 	
       
  1180 		WriteToConsole(msgLoading + 'progress sprite: ');
       
  1181 		texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent);
       
  1182 		ProgrTex:= Surface2Tex(texsurf, false);
       
  1183 		SDL_FreeSurface(texsurf);
       
  1184 		squaresize:= ProgrTex^.w shr 1;
       
  1185 		numsquares:= ProgrTex^.h div squaresize;
       
  1186 	end;
  1187 
  1187 
  1188 TryDo(ProgrTex <> nil, 'ProgrTex = nil!', true);
  1188 TryDo(ProgrTex <> nil, 'ProgrTex = nil!', true);
  1189 
  1189 
  1190 glClear(GL_COLOR_BUFFER_BIT);
  1190 glClear(GL_COLOR_BUFFER_BIT);
  1191 glEnable(GL_TEXTURE_2D);
  1191 glEnable(GL_TEXTURE_2D);