hedgewars/uRender.pas
changeset 10325 7315870716f2
parent 10324 5d90d8ca9657
child 10326 1748eed62a95
equal deleted inserted replaced
10324:5d90d8ca9657 10325:7315870716f2
    52 procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; color: LongWord); inline;
    52 procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; color: LongWord); inline;
    53 procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
    53 procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
    54 procedure DrawRect              (rect: TSDL_Rect; r, g, b, a: Byte; Fill: boolean);
    54 procedure DrawRect              (rect: TSDL_Rect; r, g, b, a: Byte; Fill: boolean);
    55 procedure DrawHedgehog          (X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
    55 procedure DrawHedgehog          (X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
    56 procedure DrawScreenWidget      (widget: POnScreenWidget);
    56 procedure DrawScreenWidget      (widget: POnScreenWidget);
    57 procedure DrawWaterBody         (pVertexBuffer: Pointer);
    57 procedure DrawWater             (Alpha: byte; OffsetY, OffsetX: LongInt);
    58 
    58 
    59 procedure RenderClear           ();
    59 procedure RenderClear           ();
    60 procedure RenderSetClearColor      (r, g, b, a: real);
    60 procedure RenderSetClearColor      (r, g, b, a: real);
    61 procedure Tint                  (r, g, b, a: Byte); inline;
    61 procedure Tint                  (r, g, b, a: Byte); inline;
    62 procedure Tint                  (c: Longword); inline;
    62 procedure Tint                  (c: Longword); inline;
  1288 {$ENDIF}
  1288 {$ENDIF}
  1289 
  1289 
  1290     openglUseColorOnly(false);
  1290     openglUseColorOnly(false);
  1291 end;
  1291 end;
  1292 
  1292 
  1293 procedure DrawWaterBody(pVertexBuffer: Pointer);
  1293 procedure DrawWater(Alpha: byte; OffsetY, OffsetX: LongInt);
  1294 begin
  1294 var VertexBuffer : array [0..7] of TVertex2f;
  1295         UpdateModelviewProjection;
  1295     watertop, lx, rx, firsti, afteri, n: LongInt;
  1296 
  1296 begin
  1297         BeginWater;
  1297 
  1298 
  1298 // those
  1299         if SuddenDeathDmg then
  1299 firsti:= -1;
  1300             SetColorPointer(@SDWaterColorArray[0], 4)
  1300 afteri:=  0;
  1301         else
  1301 
  1302             SetColorPointer(@WaterColorArray[0], 4);
  1302 watertop:= OffsetY + WorldDy + cWaterLine;
  1303 
  1303 
  1304         SetVertexPointer(pVertexBuffer, 4);
  1304 if watertop < 0 then
  1305 
  1305     watertop:= 0;
  1306         glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
  1306 
  1307 
  1307 // if no walls are needed, then bottom water surface spans full view width
  1308         EndWater;
  1308 if (WorldEdge <> weSea) then
       
  1309     begin
       
  1310     lx:= ViewLeftX;
       
  1311     rx:= ViewRightX;
       
  1312     end
       
  1313 else
       
  1314     begin
       
  1315     lx:= LeftX  + WorldDx - OffsetX;
       
  1316     rx:= RightX + WorldDx + OffsetX;
       
  1317 
       
  1318     if lx > ViewLeftX then
       
  1319         begin
       
  1320         VertexBuffer[0].X:= ViewLeftX;
       
  1321         VertexBuffer[0].Y:= ViewTopY;
       
  1322         VertexBuffer[1].X:= lx;
       
  1323         VertexBuffer[1].Y:= ViewTopY;
       
  1324         // shares vertices 2 and 3 with bottom water
       
  1325         firsti:= 0;
       
  1326         afteri:= 4;
       
  1327         end;
       
  1328 
       
  1329     if rx < ViewRightX then
       
  1330         begin
       
  1331         VertexBuffer[6].X:= ViewRightX;
       
  1332         VertexBuffer[6].Y:= ViewTopY;
       
  1333         VertexBuffer[7].X:= rx;
       
  1334         VertexBuffer[7].Y:= ViewTopY;
       
  1335         // shares vertices 4 and 5 with bottom water
       
  1336         if firsti < 0 then
       
  1337             firsti:= 4;
       
  1338         afteri:= 8;
       
  1339         end;
       
  1340     end;
       
  1341 
       
  1342 if watertop < ViewBottomY then
       
  1343     begin
       
  1344     // shares vertices 2-5 with water walls
       
  1345 
       
  1346     // starts at vertex 2
       
  1347     if (firsti < 0) or (firsti > 2) then
       
  1348         firsti:= 2;
       
  1349     // ends at vertex 5
       
  1350     if afteri < 6 then
       
  1351         afteri:= 6;
       
  1352     end;
       
  1353 
       
  1354 if firsti < 0 then
       
  1355     exit; // nothing to draw at all!
       
  1356 
       
  1357 if firsti < 4 then
       
  1358     begin
       
  1359     VertexBuffer[2].X:= ViewLeftX;
       
  1360     VertexBuffer[2].Y:= ViewBottomY;
       
  1361     VertexBuffer[3].X:= lx;
       
  1362     VertexBuffer[3].Y:= watertop;
       
  1363     end;
       
  1364 
       
  1365 if afteri > 4 then
       
  1366     begin
       
  1367     VertexBuffer[4].X:= ViewRightX;
       
  1368     VertexBuffer[4].Y:= ViewBottomY;
       
  1369     VertexBuffer[5].X:= rx;
       
  1370     VertexBuffer[5].Y:= watertop;
       
  1371     end;
       
  1372 
       
  1373 // number of points to draw
       
  1374 n:= afteri - firsti;
       
  1375 
       
  1376 // drawing time
       
  1377 
       
  1378 UpdateModelviewProjection;
       
  1379 
       
  1380 BeginWater;
       
  1381 
       
  1382 if SuddenDeathDmg then
       
  1383     begin // only set alpha if it differs from what we want
       
  1384     if SDWaterColorArray[0].a <> Alpha then
       
  1385         begin
       
  1386         SDWaterColorArray[0].a := Alpha;
       
  1387         SDWaterColorArray[1].a := Alpha;
       
  1388         SDWaterColorArray[2].a := Alpha;
       
  1389         SDWaterColorArray[3].a := Alpha;
       
  1390         SDWaterColorArray[4].a := Alpha;
       
  1391         SDWaterColorArray[5].a := Alpha;
       
  1392         SDWaterColorArray[6].a := Alpha;
       
  1393         SDWaterColorArray[7].a := Alpha;
       
  1394         end;
       
  1395     SetColorPointer(@SDWaterColorArray[0], 8);
       
  1396     end
       
  1397 else
       
  1398     begin
       
  1399     if WaterColorArray[0].a <> Alpha then
       
  1400         begin
       
  1401         WaterColorArray[0].a := Alpha;
       
  1402         WaterColorArray[1].a := Alpha;
       
  1403         WaterColorArray[2].a := Alpha;
       
  1404         WaterColorArray[3].a := Alpha;
       
  1405         WaterColorArray[4].a := Alpha;
       
  1406         WaterColorArray[5].a := Alpha;
       
  1407         WaterColorArray[6].a := Alpha;
       
  1408         WaterColorArray[7].a := Alpha;
       
  1409         end;
       
  1410     SetColorPointer(@WaterColorArray[0], 8);
       
  1411     end;
       
  1412 
       
  1413 SetVertexPointer(@VertexBuffer[0], 8);
       
  1414 
       
  1415 glDrawArrays(GL_TRIANGLE_STRIP, firsti, n);
       
  1416 
       
  1417 EndWater;
       
  1418 
       
  1419 
       
  1420 {$IFNDEF GL2}
       
  1421 // must not be Tint() as color array seems to stay active and color reset is required
       
  1422 glColor4ub($FF, $FF, $FF, $FF);
       
  1423 {$ENDIF}
  1309 end;
  1424 end;
  1310 
  1425 
  1311 procedure openglTint(r, g, b, a: Byte); inline;
  1426 procedure openglTint(r, g, b, a: Byte); inline;
  1312 {$IFDEF GL2}
  1427 {$IFDEF GL2}
  1313 const
  1428 const