hedgewars/uRender.pas
changeset 10324 5d90d8ca9657
parent 10318 c2e81eea375f
child 10325 7315870716f2
equal deleted inserted replaced
10323:72e6df962cb6 10324:5d90d8ca9657
   696 begin
   696 begin
   697 DrawTextureFromRectDir(X, Y, W, H, r, SourceTexture, 1)
   697 DrawTextureFromRectDir(X, Y, W, H, r, SourceTexture, 1)
   698 end;
   698 end;
   699 
   699 
   700 procedure DrawTextureFromRectDir(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture; Dir: LongInt);
   700 procedure DrawTextureFromRectDir(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture; Dir: LongInt);
   701 var rr: TSDL_Rect;
   701 var _l, _r, _t, _b: real;
   702     _l, _r, _t, _b: real;
       
   703     VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
   702     VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
       
   703     xw, yh: LongInt;
   704 begin
   704 begin
   705 if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then
   705 if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then
   706     exit;
   706     exit;
   707 
   707 
   708 {if isDxAreaOffscreen(X, W) <> 0 then
   708 {if isDxAreaOffscreen(X, W) <> 0 then
   714 if (abs(X) > W) and ((abs(X + W / 2) - W / 2) * 2 > ViewWidth) then
   714 if (abs(X) > W) and ((abs(X + W / 2) - W / 2) * 2 > ViewWidth) then
   715     exit;
   715     exit;
   716 if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) * 2 > ViewHeight) then
   716 if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) * 2 > ViewHeight) then
   717     exit;
   717     exit;
   718 
   718 
   719 rr.x:= X;
       
   720 rr.y:= Y;
       
   721 rr.w:= W;
       
   722 rr.h:= H;
       
   723 
       
   724 _l:= r^.x / SourceTexture^.w * SourceTexture^.rx;
   719 _l:= r^.x / SourceTexture^.w * SourceTexture^.rx;
   725 _r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx;
   720 _r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx;
       
   721 
       
   722 // if direction is mirrored, switch left and right
       
   723 if Dir < 0 then
       
   724     begin
       
   725     _t:= _l;
       
   726     _l:= _r;
       
   727     _r:= _t;
       
   728     end;
       
   729 
   726 _t:= r^.y / SourceTexture^.h * SourceTexture^.ry;
   730 _t:= r^.y / SourceTexture^.h * SourceTexture^.ry;
   727 _b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry;
   731 _b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry;
   728 
   732 
   729 glBindTexture(GL_TEXTURE_2D, SourceTexture^.id);
   733 glBindTexture(GL_TEXTURE_2D, SourceTexture^.id);
   730 
   734 
   731 if Dir < 0 then
   735 xw:= X + W;
   732     begin
   736 yh:= Y + H;
   733     VertexBuffer[0].X:= X + rr.w div 2;
   737 
   734     VertexBuffer[0].Y:= Y;
   738 VertexBuffer[0].X:= X;
   735     VertexBuffer[1].X:= X - rr.w div 2;
   739 VertexBuffer[0].Y:= Y;
   736     VertexBuffer[1].Y:= Y;
   740 VertexBuffer[1].X:= xw;
   737     VertexBuffer[2].X:= X - rr.w div 2;
   741 VertexBuffer[1].Y:= Y;
   738     VertexBuffer[2].Y:= rr.h + Y;
   742 VertexBuffer[2].X:= xw;
   739     VertexBuffer[3].X:= X + rr.w div 2;
   743 VertexBuffer[2].Y:= yh;
   740     VertexBuffer[3].Y:= rr.h + Y;
   744 VertexBuffer[3].X:= X;
   741     end
   745 VertexBuffer[3].Y:= yh;
   742 else
       
   743     begin
       
   744     VertexBuffer[0].X:= X;
       
   745     VertexBuffer[0].Y:= Y;
       
   746     VertexBuffer[1].X:= rr.w + X;
       
   747     VertexBuffer[1].Y:= Y;
       
   748     VertexBuffer[2].X:= rr.w + X;
       
   749     VertexBuffer[2].Y:= rr.h + Y;
       
   750     VertexBuffer[3].X:= X;
       
   751     VertexBuffer[3].Y:= rr.h + Y;
       
   752     end;
       
   753 
   746 
   754 TextureBuffer[0].X:= _l;
   747 TextureBuffer[0].X:= _l;
   755 TextureBuffer[0].Y:= _t;
   748 TextureBuffer[0].Y:= _t;
   756 TextureBuffer[1].X:= _r;
   749 TextureBuffer[1].X:= _r;
   757 TextureBuffer[1].Y:= _t;
   750 TextureBuffer[1].Y:= _t;