15 * along with this program; if not, write to the Free Software |
15 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
17 *) |
17 *) |
18 |
18 |
19 {$INCLUDE "options.inc"} |
19 {$INCLUDE "options.inc"} |
20 {$IF GLunit = GL}{$DEFINE GLunit:=GL}{$ENDIF} |
|
21 |
20 |
22 unit uWorld; |
21 unit uWorld; |
23 interface |
22 interface |
24 uses SDLh, uGears, uConsts, uFloat, uRandom, uTypes, uRenderUtils; |
23 uses SDLh, uGears, uConsts, uFloat, uRandom, uTypes, uRenderUtils; |
25 |
24 |
879 {$ENDIF} |
877 {$ENDIF} |
880 |
878 |
881 FinishRender(); |
879 FinishRender(); |
882 end; |
880 end; |
883 |
881 |
884 procedure ChangeDepth(rm: TRenderMode; d: GLfloat); |
|
885 var tmp: LongInt; |
|
886 begin |
|
887 {$IFNDEF USE_S3D_RENDERING} |
|
888 rm:= rm; d:= d; tmp:= tmp; // avoid hint |
|
889 {$ELSE} |
|
890 d:= d / 5; |
|
891 if rm = rmDefault then |
|
892 exit |
|
893 else if rm = rmLeftEye then |
|
894 d:= -d; |
|
895 cStereoDepth:= cStereoDepth + d; |
|
896 openglTranslProjMatrix(d, 0, 0); |
|
897 tmp:= round(d / cScaleFactor * cScreenWidth); |
|
898 ViewLeftX := ViewLeftX - tmp; |
|
899 ViewRightX:= ViewRightX - tmp; |
|
900 {$ENDIF} |
|
901 end; |
|
902 |
|
903 procedure ResetDepth(rm: TRenderMode); |
|
904 var tmp: LongInt; |
|
905 begin |
|
906 {$IFNDEF USE_S3D_RENDERING} |
|
907 rm:= rm; tmp:= tmp; // avoid hint |
|
908 {$ELSE} |
|
909 if rm = rmDefault then |
|
910 exit; |
|
911 openglTranslProjMatrix(-cStereoDepth, 0, 0); |
|
912 tmp:= round(cStereoDepth / cScaleFactor * cScreenWidth); |
|
913 ViewLeftX := ViewLeftX + tmp; |
|
914 ViewRightX:= ViewRightX + tmp; |
|
915 cStereoDepth:= 0; |
|
916 {$ENDIF} |
|
917 end; |
|
918 |
|
919 procedure RenderWorldEdge; |
882 procedure RenderWorldEdge; |
920 var |
883 var |
921 //VertexBuffer: array [0..3] of TVertex2f; |
884 //VertexBuffer: array [0..3] of TVertex2f; |
922 tmp, w: LongInt; |
885 tmp, w: LongInt; |
923 rect: TSDL_Rect; |
886 rect: TSDL_Rect; |
1198 var i, t: LongInt; |
1161 var i, t: LongInt; |
1199 r: TSDL_Rect; |
1162 r: TSDL_Rect; |
1200 tdx, tdy: Double; |
1163 tdx, tdy: Double; |
1201 s: shortstring; |
1164 s: shortstring; |
1202 offsetX, offsetY, screenBottom: LongInt; |
1165 offsetX, offsetY, screenBottom: LongInt; |
1203 VertexBuffer: array [0..3] of TVertex2f; |
|
1204 replicateToLeft, replicateToRight, tmp: boolean; |
1166 replicateToLeft, replicateToRight, tmp: boolean; |
|
1167 a: Byte; |
1205 begin |
1168 begin |
1206 if WorldEdge <> weWrap then |
1169 if WorldEdge <> weWrap then |
1207 begin |
1170 begin |
1208 replicateToLeft := false; |
1171 replicateToLeft := false; |
1209 replicateToRight:= false; |
1172 replicateToRight:= false; |
1630 else |
1593 else |
1631 ScreenFadeValue:= 0; |
1594 ScreenFadeValue:= 0; |
1632 end; |
1595 end; |
1633 if ScreenFade <> sfNone then |
1596 if ScreenFade <> sfNone then |
1634 begin |
1597 begin |
|
1598 r.x:= ViewLeftX; |
|
1599 r.y:= ViewTopY; |
|
1600 r.w:= ViewWidth; |
|
1601 r.h:= ViewHeight; |
|
1602 |
1635 case ScreenFade of |
1603 case ScreenFade of |
1636 sfToBlack, sfFromBlack: Tint(0, 0, 0, ScreenFadeValue * 255 div 1000); |
1604 sfToBlack, sfFromBlack: DrawRect(r, 0, 0, 0, ScreenFadeValue * 255 div 1000, true); |
1637 sfToWhite, sfFromWhite: Tint($FF, $FF, $FF, ScreenFadeValue * 255 div 1000); |
1605 sfToWhite, sfFromWhite: DrawRect(r, $FF, $FF, $FF, ScreenFadeValue * 255 div 1000, true); |
1638 end; |
1606 end; |
1639 |
1607 |
1640 VertexBuffer[0].X:= -cScreenWidth; |
|
1641 VertexBuffer[0].Y:= cScreenHeight; |
|
1642 VertexBuffer[1].X:= -cScreenWidth; |
|
1643 VertexBuffer[1].Y:= 0; |
|
1644 VertexBuffer[2].X:= cScreenWidth; |
|
1645 VertexBuffer[2].Y:= 0; |
|
1646 VertexBuffer[3].X:= cScreenWidth; |
|
1647 VertexBuffer[3].Y:= cScreenHeight; |
|
1648 |
|
1649 EnableTexture(false); |
|
1650 |
|
1651 SetVertexPointer(@VertexBuffer[0], 4); |
|
1652 glDrawArrays(GL_TRIANGLE_FAN, 0, High(VertexBuffer) - Low(VertexBuffer) + 1); |
|
1653 |
|
1654 EnableTexture(true); |
|
1655 untint; |
|
1656 if not isFirstFrame and ((ScreenFadeValue = 0) or (ScreenFadeValue = sfMax)) then |
1608 if not isFirstFrame and ((ScreenFadeValue = 0) or (ScreenFadeValue = sfMax)) then |
1657 ScreenFade:= sfNone |
1609 ScreenFade:= sfNone |
1658 end |
1610 end |
1659 end; |
1611 end; |
1660 |
1612 |
1671 recTexture:= Surface2Tex(tmpSurface, false); |
1623 recTexture:= Surface2Tex(tmpSurface, false); |
1672 SDL_FreeSurface(tmpSurface) |
1624 SDL_FreeSurface(tmpSurface) |
1673 end; |
1625 end; |
1674 DrawTexture( -(cScreenWidth shr 1) + 50, 20, recTexture); |
1626 DrawTexture( -(cScreenWidth shr 1) + 50, 20, recTexture); |
1675 |
1627 |
|
1628 //a:= Byte(Round(127*(1 + sin(RealTicks*0.007)))); |
|
1629 a:= Byte(min(255, abs(-255 + ((RealTicks div 2) and 511)))); |
|
1630 |
1676 // draw red circle |
1631 // draw red circle |
1677 glDisable(GL_TEXTURE_2D); |
1632 DrawCircleFilled(-(cScreenWidth shr 1) + 30, 35, 10, $FF, $00, $00, a); |
1678 Tint($FF, $00, $00, Byte(Round(127*(1 + sin(SDL_GetTicks()*0.007))))); |
|
1679 glBegin(GL_POLYGON); |
|
1680 for i:= 0 to 20 do |
|
1681 glVertex2f(-(cScreenWidth shr 1) + 30 + sin(i*2*Pi/20)*10, 35 + cos(i*2*Pi/20)*10); |
|
1682 glEnd(); |
|
1683 untint; |
|
1684 glEnable(GL_TEXTURE_2D); |
|
1685 end; |
1633 end; |
1686 {$ENDIF} |
1634 {$ENDIF} |
1687 |
1635 |
1688 SetScale(zoom); |
1636 SetScale(zoom); |
1689 |
1637 |