hedgewars/uWorld.pas
branchwebgl
changeset 8026 4a4f21070479
parent 7946 a99a79bbd857
child 8099 a7f02b902b6f
equal deleted inserted replaced
8023:7de85783b823 8026:4a4f21070479
    62     , uCommands
    62     , uCommands
    63     , uMobile
    63     , uMobile
    64 {$IFDEF USE_VIDEO_RECORDING}    
    64 {$IFDEF USE_VIDEO_RECORDING}    
    65     , uVideoRec
    65     , uVideoRec
    66 {$ENDIF}    
    66 {$ENDIF}    
       
    67 {$IFDEF GL2}
       
    68     , uMatrix
       
    69 {$ENDIF}
    67     ;
    70     ;
    68 
    71 
    69 var cWaveWidth, cWaveHeight: LongInt;
    72 var cWaveWidth, cWaveHeight: LongInt;
    70     AMShiftTargetX, AMShiftTargetY, AMShiftX, AMShiftY, SlotsNum: LongInt;
    73     AMShiftTargetX, AMShiftTargetY, AMShiftX, AMShiftY, SlotsNum: LongInt;
    71     AMAnimStartTime, AMState : LongInt;
    74     AMAnimStartTime, AMState : LongInt;
   753         DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8);
   756         DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8);
   754 {$ENDIF}
   757 {$ENDIF}
   755 end;
   758 end;
   756 
   759 
   757 procedure DrawWater(Alpha: byte; OffsetY: LongInt);
   760 procedure DrawWater(Alpha: byte; OffsetY: LongInt);
   758 var VertexBuffer: array [0..3] of TVertex2f;
   761 var VertexBuffer : array [0..3] of TVertex2f;
   759     r: TSDL_Rect;
   762     r		 : TSDL_Rect;
   760     lw, lh: GLfloat;
   763     lw, lh	 : GLfloat;
   761 begin
   764 begin
   762 if SuddenDeathDmg then
   765 if SuddenDeathDmg then
   763     begin
   766     begin
   764     SDWaterColorArray[0].a := Alpha;
   767     SDWaterColorArray[0].a := Alpha;
   765     SDWaterColorArray[1].a := Alpha;
   768     SDWaterColorArray[1].a := Alpha;
   781 r.y:= OffsetY + WorldDy + cWaterLine;
   784 r.y:= OffsetY + WorldDy + cWaterLine;
   782 if WorldDy < trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine then
   785 if WorldDy < trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine then
   783     begin
   786     begin
   784         if r.y < 0 then
   787         if r.y < 0 then
   785             r.y:= 0;
   788             r.y:= 0;
   786 
   789  
   787         glDisable(GL_TEXTURE_2D);
   790         glDisable(GL_TEXTURE_2D);
   788         VertexBuffer[0].X:= -lw;
   791         VertexBuffer[0].X:= -lw;
   789         VertexBuffer[0].Y:= r.y;
   792         VertexBuffer[0].Y:= r.y;
   790         VertexBuffer[1].X:= lw;
   793         VertexBuffer[1].X:= lw;
   791         VertexBuffer[1].Y:= r.y;
   794         VertexBuffer[1].Y:= r.y;
   792         VertexBuffer[2].X:= lw;
   795         VertexBuffer[2].X:= lw;
   793         VertexBuffer[2].Y:= lh;
   796         VertexBuffer[2].Y:= lh;
   794         VertexBuffer[3].X:= -lw;
   797         VertexBuffer[3].X:= -lw;
   795         VertexBuffer[3].Y:= lh;
   798         VertexBuffer[3].Y:= lh;
   796 
   799 
       
   800 {$IFNDEF GL2}
   797         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   801         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   798         glEnableClientState(GL_COLOR_ARRAY);
   802         glEnableClientState(GL_COLOR_ARRAY);
   799         if SuddenDeathDmg then
   803         if SuddenDeathDmg then
   800             glColorPointer(4, GL_UNSIGNED_BYTE, 0, @SDWaterColorArray[0])
   804             glColorPointer(4, GL_UNSIGNED_BYTE, 0, @SDWaterColorArray[0])
   801         else
   805         else
   805 
   809 
   806         glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   810         glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   807 
   811 
   808         glDisableClientState(GL_COLOR_ARRAY);
   812         glDisableClientState(GL_COLOR_ARRAY);
   809         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   813         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
       
   814 
       
   815 {$ELSE}
       
   816         UpdateModelviewProjection;
       
   817 
       
   818         BeginWater;
       
   819         if SuddenDeathDmg then
       
   820             SetColorPointer(@SDWaterColorArray[0], 4)
       
   821         else
       
   822             SetColorPointer(@WaterColorArray[0], 4);
       
   823 
       
   824         SetVertexPointer(@VertexBuffer[0], 4);
       
   825 
       
   826         glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
       
   827 
       
   828         EndWater;
       
   829 {$ENDIF}
       
   830 
       
   831         {$IFNDEF GL2}
   810         glColor4ub($FF, $FF, $FF, $FF); // must not be Tint() as color array seems to stay active and color reset is required
   832         glColor4ub($FF, $FF, $FF, $FF); // must not be Tint() as color array seems to stay active and color reset is required
       
   833         {$ENDIF}
       
   834         {$IFNDEF WEBGL}
   811         glEnable(GL_TEXTURE_2D);
   835         glEnable(GL_TEXTURE_2D);
       
   836         {$ENDIF}
   812     end;
   837     end;
   813 end;
   838 end;
   814 
   839 
   815 procedure DrawWaves(Dir, dX, dY: LongInt; tnt: Byte);
   840 procedure DrawWaves(Dir, dX, dY: LongInt; tnt: Byte);
   816 var VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
   841 var VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
   860 TextureBuffer[2].Y:= SpritesData[sprite].Texture^.ry;
   885 TextureBuffer[2].Y:= SpritesData[sprite].Texture^.ry;
   861 TextureBuffer[3].X:= TextureBuffer[0].X;
   886 TextureBuffer[3].X:= TextureBuffer[0].X;
   862 TextureBuffer[3].Y:= TextureBuffer[2].Y;
   887 TextureBuffer[3].Y:= TextureBuffer[2].Y;
   863 
   888 
   864 
   889 
   865 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   890 SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
   866 glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
   891 SetTexCoordPointer(@TextureBuffer[0], Length(VertexBuffer));
       
   892 
       
   893 {$IFDEF GL2}
       
   894 UpdateModelviewProjection;
       
   895 {$ENDIF}
       
   896 
   867 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   897 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   868 
   898 
   869 Tint($FF, $FF, $FF, $FF);
   899 Tint($FF, $FF, $FF, $FF);
   870 
   900 
   871 {for i:= -1 to cWaterSprCount do
   901 {for i:= -1 to cWaterSprCount do
  1082     if rm = rmDefault then
  1112     if rm = rmDefault then
  1083         exit
  1113         exit
  1084     else if rm = rmLeftEye then
  1114     else if rm = rmLeftEye then
  1085         d:= -d;
  1115         d:= -d;
  1086     stereoDepth:= stereoDepth + d;
  1116     stereoDepth:= stereoDepth + d;
       
  1117 
       
  1118     {$IFDEF GL2}
       
  1119     hglMatrixMode(MATRIX_PROJECTION);
       
  1120     hglTranslatef(d, 0, 0);
       
  1121     hglMatrixMode(MATRIX_MODELVIEW);
       
  1122     {$ELSE}
  1087     glMatrixMode(GL_PROJECTION);
  1123     glMatrixMode(GL_PROJECTION);
  1088     glTranslatef(d, 0, 0);
  1124     glTranslatef(d, 0, 0);
  1089     glMatrixMode(GL_MODELVIEW);
  1125     glMatrixMode(GL_MODELVIEW);
       
  1126     {$ENDIF}
  1090 {$ENDIF}
  1127 {$ENDIF}
  1091 end;
  1128 end;
  1092  
  1129  
  1093 procedure ResetDepth(rm: TRenderMode);
  1130 procedure ResetDepth(rm: TRenderMode);
  1094 begin
  1131 begin
  1095 {$IFDEF S3D_DISABLED}
  1132 {$IFNDEF S3D_DISABLED}
  1096     rm:= rm; // avoid hint
       
  1097     exit;
       
  1098 {$ELSE}
       
  1099     if rm = rmDefault then
  1133     if rm = rmDefault then
  1100         exit;
  1134         exit;
       
  1135     {$IFDEF GL2}
       
  1136     hglMatrixMode(MATRIX_PROJECTION);
       
  1137     hglTranslatef(-stereoDepth, 0, 0);
       
  1138     hglMatrixMode(MATRIX_MODELVIEW);    
       
  1139     {$ELSE}
  1101     glMatrixMode(GL_PROJECTION);
  1140     glMatrixMode(GL_PROJECTION);
  1102     glTranslatef(-stereoDepth, 0, 0);
  1141     glTranslatef(-stereoDepth, 0, 0);
  1103     glMatrixMode(GL_MODELVIEW);
  1142     glMatrixMode(GL_MODELVIEW);
  1104     stereoDepth:= 0;
  1143     {$ENDIF}
       
  1144     cStereoDepth:= 0;
  1105 {$ENDIF}
  1145 {$ENDIF}
  1106 end;
  1146 end;
  1107  
  1147  
  1108 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode);
  1148 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode);
  1109 var i, t, h: LongInt;
  1149 var i, t, h: LongInt;
  1158     changeDepth(RM, cStereo_Land);
  1198     changeDepth(RM, cStereo_Land);
  1159     DrawVisualGears(5);
  1199     DrawVisualGears(5);
  1160     DrawLand(WorldDx, WorldDy);
  1200     DrawLand(WorldDx, WorldDy);
  1161 
  1201 
  1162     DrawWater(255, 0);
  1202     DrawWater(255, 0);
       
  1203 
       
  1204 (*
       
  1205 // Attack bar
       
  1206     if CurrentTeam <> nil then
       
  1207         case AttackBar of
       
  1208         //1: begin
       
  1209         //r:= StuffPoz[sPowerBar];
       
  1210         //{$WARNINGS OFF}
       
  1211         //r.w:= (CurrentHedgehog^.Gear^.Power * 256) div cPowerDivisor;
       
  1212         //{$WARNINGS ON}
       
  1213         //DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface);
       
  1214         //end;
       
  1215         2: with CurrentHedgehog^ do
       
  1216                 begin
       
  1217                 tdx:= hwSign(Gear^.dX) * Sin(Gear^.Angle * Pi / cMaxAngle);
       
  1218                 tdy:= - Cos(Gear^.Angle * Pi / cMaxAngle);
       
  1219                 for i:= (Gear^.Power * 24) div cPowerDivisor downto 0 do
       
  1220                     DrawSprite(sprPower,
       
  1221                             hwRound(Gear^.X) + GetLaunchX(CurAmmoType, hwSign(Gear^.dX), Gear^.Angle) + LongInt(round(WorldDx + tdx * (24 + i * 2))) - 16,
       
  1222                             hwRound(Gear^.Y) + GetLaunchY(CurAmmoType, Gear^.Angle) + LongInt(round(WorldDy + tdy * (24 + i * 2))) - 16,
       
  1223                             i)
       
  1224                 end
       
  1225         end;
       
  1226 *)
  1163 
  1227 
  1164 DrawVisualGears(1);
  1228 DrawVisualGears(1);
  1165 DrawGears;
  1229 DrawGears;
  1166 DrawVisualGears(6);
  1230 DrawVisualGears(6);
  1167 
  1231 
  1425     DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8);
  1489     DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8);
  1426 
  1490 
  1427 // Chat
  1491 // Chat
  1428 DrawChat;
  1492 DrawChat;
  1429 
  1493 
       
  1494 
  1430 // various captions
  1495 // various captions
  1431 if fastUntilLag then
  1496 if fastUntilLag then
  1432     DrawTextureCentered(0, (cScreenHeight shr 1), SyncTexture);
  1497     DrawTextureCentered(0, (cScreenHeight shr 1), SyncTexture);
  1433 if isPaused then
  1498 if isPaused then
  1434     DrawTextureCentered(0, (cScreenHeight shr 1), PauseTexture);
  1499     DrawTextureCentered(0, (cScreenHeight shr 1), PauseTexture);
  1435 if not isFirstFrame and (missionTimer <> 0) or isPaused or fastUntilLag or (GameState = gsConfirm) then
  1500 if (not isFirstFrame) and (missionTimer <> 0) or isPaused or fastUntilLag or (GameState = gsConfirm) then
  1436     begin
  1501     begin
  1437     if (ReadyTimeLeft = 0) and (missionTimer > 0) then
  1502     if (ReadyTimeLeft = 0) and (missionTimer > 0) then
  1438         dec(missionTimer, Lag);
  1503         dec(missionTimer, Lag);
  1439     if missionTimer < 0 then
  1504     if missionTimer < 0 then
  1440         missionTimer:= 0; // avoid subtracting below 0
  1505         missionTimer:= 0; // avoid subtracting below 0
  1547         VertexBuffer[3].Y:= cScreenHeight;
  1612         VertexBuffer[3].Y:= cScreenHeight;
  1548 
  1613 
  1549         glDisable(GL_TEXTURE_2D);
  1614         glDisable(GL_TEXTURE_2D);
  1550 
  1615 
  1551         glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
  1616         glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
  1552         glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
  1617         glDrawArrays(GL_TRIANGLE_FAN, 0, High(VertexBuffer) - Low(VertexBuffer) + 1);
  1553 
  1618 
  1554         glEnable(GL_TEXTURE_2D);
  1619         glEnable(GL_TEXTURE_2D);
  1555         Tint($FF, $FF, $FF, $FF);
  1620         Tint($FF, $FF, $FF, $FF);
  1556         if not isFirstFrame and ((ScreenFadeValue = 0) or (ScreenFadeValue = sfMax)) then
  1621         if (not isFirstFrame) and ((ScreenFadeValue = 0) or (ScreenFadeValue = sfMax)) then
  1557             ScreenFade:= sfNone
  1622             ScreenFade:= sfNone
  1558         end
  1623         end
  1559     end;
  1624     end;
  1560 
  1625 
  1561 {$IFDEF USE_VIDEO_RECORDING}
  1626 {$IFDEF USE_VIDEO_RECORDING}
  1626                     DrawSprite(PosSprite, CursorPoint.X - (SpritesData[PosSprite].Width shr 1), cScreenHeight - CursorPoint.Y - (SpritesData[PosSprite].Height shr 1),i);
  1691                     DrawSprite(PosSprite, CursorPoint.X - (SpritesData[PosSprite].Width shr 1), cScreenHeight - CursorPoint.Y - (SpritesData[PosSprite].Height shr 1),i);
  1627                 end;
  1692                 end;
  1628         DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
  1693         DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
  1629         end
  1694         end
  1630     end;
  1695     end;
       
  1696 
  1631 isFirstFrame:= false
  1697 isFirstFrame:= false
  1632 end;
  1698 end;
  1633 
  1699 
  1634 var PrevSentPointTime: LongWord = 0;
  1700 var PrevSentPointTime: LongWord = 0;
  1635 
  1701