hedgewars/uStore.pas
changeset 4385 f679ffa2dc8c
parent 4380 b78638b36b89
child 4390 f219628ed666
equal deleted inserted replaced
4384:615a3e7bd850 4385:f679ffa2dc8c
    25 procedure initModule;
    25 procedure initModule;
    26 procedure freeModule;
    26 procedure freeModule;
    27 
    27 
    28 procedure StoreLoad;
    28 procedure StoreLoad;
    29 procedure StoreRelease;
    29 procedure StoreRelease;
    30 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
       
    31 procedure RenderHealth(var Hedgehog: THedgehog);
    30 procedure RenderHealth(var Hedgehog: THedgehog);
    32 procedure AddProgress;
    31 procedure AddProgress;
    33 procedure FinishProgress;
    32 procedure FinishProgress;
    34 function  LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
    33 function  LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
    35 procedure SetupOpenGL;
    34 procedure SetupOpenGL;
    42 implementation
    41 implementation
    43 uses uMisc, uConsole, uLocale, uMobile, uVariables, uUtils, uTextures, uIO, uRender, uRenderUtils;
    42 uses uMisc, uConsole, uLocale, uMobile, uVariables, uUtils, uTextures, uIO, uRender, uRenderUtils;
    44 
    43 
    45 type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
    44 type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
    46 
    45 
    47 var HHTexture: PTexture;
    46 var MaxTextureSize: LongInt;
    48     MaxTextureSize: LongInt;
       
    49     cGPUVendor: TGPUVendor;
    47     cGPUVendor: TGPUVendor;
    50 
    48 
    51 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect;
    49 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect;
    52 var w, h: LongInt;
    50 var w, h: LongInt;
    53     tmpsurf: PSDL_Surface;
    51     tmpsurf: PSDL_Surface;
   361 {$IFDEF SDL_IMAGE_NEWER}
   359 {$IFDEF SDL_IMAGE_NEWER}
   362 IMG_Quit();
   360 IMG_Quit();
   363 {$ENDIF}
   361 {$ENDIF}
   364 end;
   362 end;
   365 
   363 
   366 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
       
   367 const VertexBuffer: array [0..3] of TVertex2f = (
       
   368         (x: -16; y: -16),
       
   369         (x:  16; y: -16),
       
   370         (x:  16; y:  16),
       
   371         (x: -16; y:  16));
       
   372 var l, r, t, b: real;
       
   373     TextureBuffer: array [0..3] of TVertex2f;
       
   374 begin
       
   375 // don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
       
   376 if (abs(X) > 32) and ((abs(X) - 16) * cScaleFactor > cScreenWidth) then
       
   377     exit;
       
   378 if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) * cScaleFactor > cScreenHeight) then
       
   379     exit;
       
   380 
       
   381 t:= Pos * 32 / HHTexture^.h;
       
   382 b:= (Pos + 1) * 32 / HHTexture^.h;
       
   383 
       
   384 if Dir = -1 then
       
   385    begin
       
   386    l:= (Step + 1) * 32 / HHTexture^.w;
       
   387    r:= Step * 32 / HHTexture^.w
       
   388    end else
       
   389    begin
       
   390    l:= Step * 32 / HHTexture^.w;
       
   391    r:= (Step + 1) * 32 / HHTexture^.w
       
   392    end;
       
   393 
       
   394 
       
   395 glPushMatrix();
       
   396 glTranslatef(X, Y, 0);
       
   397 glRotatef(Angle, 0, 0, 1);
       
   398 
       
   399 glBindTexture(GL_TEXTURE_2D, HHTexture^.id);
       
   400 
       
   401 TextureBuffer[0].X:= l;
       
   402 TextureBuffer[0].Y:= t;
       
   403 TextureBuffer[1].X:= r;
       
   404 TextureBuffer[1].Y:= t;
       
   405 TextureBuffer[2].X:= r;
       
   406 TextureBuffer[2].Y:= b;
       
   407 TextureBuffer[3].X:= l;
       
   408 TextureBuffer[3].Y:= b;
       
   409 
       
   410 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
       
   411 glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
       
   412 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
       
   413 
       
   414 glPopMatrix
       
   415 end;
       
   416 
       
   417 procedure StoreRelease;
   364 procedure StoreRelease;
   418 var ii: TSprite;
   365 var ii: TSprite;
   419 begin
   366 begin
   420     for ii:= Low(TSprite) to High(TSprite) do
   367     for ii:= Low(TSprite) to High(TSprite) do
   421     begin
   368     begin