hedgewars/uRender.pas
branchwebgl
changeset 9950 2759212a27de
parent 9264 21df1a0ec9ed
parent 9792 59cde1e53ca5
child 10015 4feced261c68
equal deleted inserted replaced
9521:8054d9d775fd 9950:2759212a27de
    43 procedure DrawTextureRotatedF   (Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
    43 procedure DrawTextureRotatedF   (Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
    44 
    44 
    45 procedure DrawCircle            (X, Y, Radius, Width: LongInt);
    45 procedure DrawCircle            (X, Y, Radius, Width: LongInt);
    46 procedure DrawCircle            (X, Y, Radius, Width: LongInt; r, g, b, a: Byte);
    46 procedure DrawCircle            (X, Y, Radius, Width: LongInt; r, g, b, a: Byte);
    47 
    47 
       
    48 procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; color: LongWord); inline;
    48 procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
    49 procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
    49 procedure DrawFillRect          (r: TSDL_Rect);
    50 procedure DrawFillRect          (r: TSDL_Rect);
    50 procedure DrawHedgehog          (X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
    51 procedure DrawHedgehog          (X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
    51 procedure DrawScreenWidget      (widget: POnScreenWidget);
    52 procedure DrawScreenWidget      (widget: POnScreenWidget);
    52 
    53 
    53 procedure Tint                  (r, g, b, a: Byte); inline;
    54 procedure Tint                  (r, g, b, a: Byte); inline;
    54 procedure Tint                  (c: Longword); inline;
    55 procedure Tint                  (c: Longword); inline;
       
    56 procedure untint(); inline;
       
    57 procedure setTintAdd            (f: boolean); inline;
    55 
    58 
    56 implementation
    59 implementation
    57 uses uVariables;
    60 uses uVariables;
    58 
    61 
    59 {$IFDEF USE_TOUCH_INTERFACE}
    62 {$IFDEF USE_TOUCH_INTERFACE}
   410 if (Y + SpritesData[Sprite].Height > BottomY) then
   413 if (Y + SpritesData[Sprite].Height > BottomY) then
   411     r.h:= BottomY - Y + 1;
   414     r.h:= BottomY - Y + 1;
   412 if (X + SpritesData[Sprite].Width > RightX) then
   415 if (X + SpritesData[Sprite].Width > RightX) then
   413     r.w:= RightX - X + 1;
   416     r.w:= RightX - X + 1;
   414 
   417 
       
   418 if (r.h < r.y) or (r.w < r.x) then 
       
   419     exit;
       
   420 
   415 dec(r.h, r.y);
   421 dec(r.h, r.y);
   416 dec(r.w, r.x);
   422 dec(r.w, r.x);
   417 
   423 
   418 DrawTextureFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture)
   424 DrawTextureFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture)
   419 end;
   425 end;
   426     else
   432     else
   427         scale:= 1.0;
   433         scale:= 1.0;
   428     DrawTexture(X - round(Source^.w * scale) div 2, Top, Source, scale)
   434     DrawTexture(X - round(Source^.w * scale) div 2, Top, Source, scale)
   429 end;
   435 end;
   430 
   436 
       
   437 procedure DrawLine(X0, Y0, X1, Y1, Width: Single; color: LongWord); inline;
       
   438 begin
       
   439 DrawLine(X0, Y0, X1, Y1, Width, (color shr 24) and $FF, (color shr 16) and $FF, (color shr 8) and $FF, color and $FF)
       
   440 end;
       
   441 
   431 procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
   442 procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
   432 var VertexBuffer: array [0..1] of TVertex2f;
   443 var VertexBuffer: array [0..1] of TVertex2f;
   433 begin
   444 begin
   434     glEnable(GL_LINE_SMOOTH);
   445     glEnable(GL_LINE_SMOOTH);
   435 {$IFNDEF GL2}
   446 {$IFNDEF GL2}
   445     VertexBuffer[1].X:= X1;
   456     VertexBuffer[1].X:= X1;
   446     VertexBuffer[1].Y:= Y1;
   457     VertexBuffer[1].Y:= Y1;
   447 
   458 
   448     SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
   459     SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
   449     glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
   460     glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
   450     Tint($FF, $FF, $FF, $FF);
   461     untint;
   451 
   462     
   452     glPopMatrix;
   463     glPopMatrix;
   453 
   464 
   454     glEnable(GL_TEXTURE_2D);
   465     glEnable(GL_TEXTURE_2D);
   455 
   466 
   456 {$ELSE}
   467 {$ELSE}
   507 VertexBuffer[3].Y:= r.y + r.h;
   518 VertexBuffer[3].Y:= r.y + r.h;
   508 
   519 
   509 SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
   520 SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
   510 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   521 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   511 
   522 
   512 Tint($FF, $FF, $FF, $FF);
   523 untint;
   513 
       
   514 {$IFDEF GL2}
   524 {$IFDEF GL2}
   515 EnableTexture(True);
   525 EnableTexture(True);
   516 {$ELSE}
   526 {$ELSE}
   517 glEnable(GL_TEXTURE_2D)
   527 glEnable(GL_TEXTURE_2D)
   518 {$ENDIF}
   528 {$ENDIF}
   520 end;
   530 end;
   521 
   531 
   522 procedure DrawCircle(X, Y, Radius, Width: LongInt; r, g, b, a: Byte);
   532 procedure DrawCircle(X, Y, Radius, Width: LongInt; r, g, b, a: Byte);
   523 begin
   533 begin
   524     Tint(r, g, b, a);
   534     Tint(r, g, b, a);
   525     DrawCircle(X, Y, Radius, Width);
   535     DrawCircle(X, Y, Radius, Width); 
   526     Tint($FF, $FF, $FF, $FF);
   536     untint;
   527 end;
   537 end;
   528 
   538 
   529 procedure DrawCircle(X, Y, Radius, Width: LongInt);
   539 procedure DrawCircle(X, Y, Radius, Width: LongInt);
   530 var
   540 var
   531     i: LongInt;
   541     i: LongInt;
   664 
   674 
   665     if show or (fadeAnimStart <> 0) then
   675     if show or (fadeAnimStart <> 0) then
   666         begin
   676         begin
   667         Tint($FF, $FF, $FF, alpha);
   677         Tint($FF, $FF, $FF, alpha);
   668         DrawTexture(frame.x, frame.y, spritesData[sprite].Texture, buttonScale);
   678         DrawTexture(frame.x, frame.y, spritesData[sprite].Texture, buttonScale);
   669         Tint($FF, $FF, $FF, $FF);
   679         untint;
   670         end;
   680         end;
   671     end;
   681     end;
   672 {$ELSE}
   682 {$ELSE}
   673 begin
   683 begin
   674 {widget:= widget; // avoid hint}
   684 {widget:= widget; // avoid hint}
   678 procedure Tint(r, g, b, a: Byte); inline;
   688 procedure Tint(r, g, b, a: Byte); inline;
   679 var
   689 var
   680     nc, tw: Longword;
   690     nc, tw: Longword;
   681     scale:Real = 1.0/255.0;
   691     scale:Real = 1.0/255.0;
   682 begin
   692 begin
   683     nc:= (a shl 24) or (b shl 16) or (g shl 8) or r;
   693     nc:= (r shl 24) or (g shl 16) or (b shl 8) or a;
   684 
   694 
   685     if nc = lastTint then
   695     if nc = lastTint then
   686         exit;
   696         exit;
   687 
   697 
   688     if GrayScale then
   698     if GrayScale then
   704     lastTint:= nc;
   714     lastTint:= nc;
   705 end;
   715 end;
   706 
   716 
   707 procedure Tint(c: Longword); inline;
   717 procedure Tint(c: Longword); inline;
   708 begin
   718 begin
       
   719     if c = lastTint then exit;
   709     Tint(((c shr 24) and $FF), ((c shr 16) and $FF), (c shr 8) and $FF, (c and $FF))
   720     Tint(((c shr 24) and $FF), ((c shr 16) and $FF), (c shr 8) and $FF, (c and $FF))
   710 end;
   721 end;
   711 
   722 
       
   723 procedure untint(); inline;
       
   724 begin
       
   725     Tint($FF, $FF, $FF, $FF)
       
   726 end;
       
   727 
       
   728 procedure setTintAdd(f: boolean); inline;
       
   729 begin
       
   730     if f then
       
   731         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD)
       
   732     else
       
   733         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
       
   734 end;
   712 
   735 
   713 end.
   736 end.