hedgewars/uRender.pas
changeset 4385 f679ffa2dc8c
parent 4378 91655618a510
child 4420 6be946bcd17a
equal deleted inserted replaced
4384:615a3e7bd850 4385:f679ffa2dc8c
    19 procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
    19 procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
    20 procedure DrawCentered(X, Top: LongInt; Source: PTexture);
    20 procedure DrawCentered(X, Top: LongInt; Source: PTexture);
    21 procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
    21 procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
    22 procedure DrawFillRect(r: TSDL_Rect);
    22 procedure DrawFillRect(r: TSDL_Rect);
    23 procedure DrawCircle(X, Y, Radius: LongInt; Width: Single; r, g, b, a: Byte);
    23 procedure DrawCircle(X, Y, Radius: LongInt; Width: Single; r, g, b, a: Byte);
       
    24 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
    24 procedure Tint(r, g, b, a: Byte); inline;
    25 procedure Tint(r, g, b, a: Byte); inline;
    25 procedure Tint(c: Longword); inline;
    26 procedure Tint(c: Longword); inline;
       
    27 
       
    28 var
       
    29     HHTexture: PTexture;
    26 
    30 
    27 implementation
    31 implementation
    28 uses uVariables;
    32 uses uVariables;
    29 var
    33 var
    30     lastTint: Longword;
    34     lastTint: Longword;
   368     glEnable(GL_TEXTURE_2D);
   372     glEnable(GL_TEXTURE_2D);
   369     glDisable(GL_LINE_SMOOTH);
   373     glDisable(GL_LINE_SMOOTH);
   370 end;
   374 end;
   371 
   375 
   372 
   376 
       
   377 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
       
   378 const VertexBuffer: array [0..3] of TVertex2f = (
       
   379         (x: -16; y: -16),
       
   380         (x:  16; y: -16),
       
   381         (x:  16; y:  16),
       
   382         (x: -16; y:  16));
       
   383 var l, r, t, b: real;
       
   384     TextureBuffer: array [0..3] of TVertex2f;
       
   385 begin
       
   386     // don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
       
   387     if (abs(X) > 32) and ((abs(X) - 16) * cScaleFactor > cScreenWidth) then
       
   388         exit;
       
   389     if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) * cScaleFactor > cScreenHeight) then
       
   390         exit;
       
   391 
       
   392     t:= Pos * 32 / HHTexture^.h;
       
   393     b:= (Pos + 1) * 32 / HHTexture^.h;
       
   394 
       
   395     if Dir = -1 then
       
   396     begin
       
   397     l:= (Step + 1) * 32 / HHTexture^.w;
       
   398     r:= Step * 32 / HHTexture^.w
       
   399     end else
       
   400     begin
       
   401     l:= Step * 32 / HHTexture^.w;
       
   402     r:= (Step + 1) * 32 / HHTexture^.w
       
   403     end;
       
   404 
       
   405 
       
   406     glPushMatrix();
       
   407     glTranslatef(X, Y, 0);
       
   408     glRotatef(Angle, 0, 0, 1);
       
   409 
       
   410     glBindTexture(GL_TEXTURE_2D, HHTexture^.id);
       
   411 
       
   412     TextureBuffer[0].X:= l;
       
   413     TextureBuffer[0].Y:= t;
       
   414     TextureBuffer[1].X:= r;
       
   415     TextureBuffer[1].Y:= t;
       
   416     TextureBuffer[2].X:= r;
       
   417     TextureBuffer[2].Y:= b;
       
   418     TextureBuffer[3].X:= l;
       
   419     TextureBuffer[3].Y:= b;
       
   420 
       
   421     glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
       
   422     glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
       
   423     glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
       
   424 
       
   425     glPopMatrix
       
   426 end;
       
   427 
       
   428 
   373 procedure Tint(r, g, b, a: Byte); inline;
   429 procedure Tint(r, g, b, a: Byte); inline;
   374 var nc: Longword;
   430 var nc: Longword;
   375 begin
   431 begin
   376 nc:= (a shl 24) or (b shl 16) or (g shl 8) or r;
   432 nc:= (a shl 24) or (b shl 16) or (g shl 8) or r;
   377 if nc = lastTint then
   433 if nc = lastTint then