564 glClear(GL_COLOR_BUFFER_BIT); |
569 glClear(GL_COLOR_BUFFER_BIT); |
565 DrawWorldStereo(Lag, rmDefault) |
570 DrawWorldStereo(Lag, rmDefault) |
566 end |
571 end |
567 else |
572 else |
568 begin |
573 begin |
|
574 // create left fb |
569 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framel); |
575 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framel); |
570 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); |
576 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); |
571 DrawWorldStereo(Lag, rmLeftEye); |
577 DrawWorldStereo(Lag, rmLeftEye); |
|
578 |
|
579 // create right fb |
572 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framer); |
580 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framer); |
573 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); |
581 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); |
574 DrawWorldStereo(0, rmRightEye); |
582 DrawWorldStereo(0, rmRightEye); |
|
583 |
|
584 // detatch drawing from fbs |
575 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); |
585 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); |
576 glGetFloatv(GL_COLOR_CLEAR_VALUE, @cc); |
586 glGetFloatv(GL_COLOR_CLEAR_VALUE, @cc); |
577 glClearColor(0, 0, 0, 0); |
587 glClearColor(0, 0, 0, 0); |
578 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); |
588 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); |
579 glClearColor(cc[0], cc[1], cc[2], cc[3]); |
589 glClearColor(cc[0], cc[1], cc[2], cc[3]); |
580 SetScale(2.0); |
590 SetScale(cDefaultZoomLevel); |
|
591 |
|
592 // enable gl stuff |
581 glEnable(GL_TEXTURE_2D); |
593 glEnable(GL_TEXTURE_2D); |
582 glEnable(GL_BLEND); |
594 glEnable(GL_BLEND); |
583 glBlendFunc(GL_ONE, GL_ONE); |
595 glBlendFunc(GL_ONE, GL_ONE); |
|
596 |
|
597 // draw left frame |
584 glBindTexture(GL_TEXTURE_2D, texl); |
598 glBindTexture(GL_TEXTURE_2D, texl); |
585 glColor3f(0.0, 1.0, 1.0); |
599 glColor3f(0.0, 1.0, 1.0); |
586 glBegin(GL_QUADS); |
600 glBegin(GL_QUADS); |
587 glTexCoord2f(0.0, 0.0); |
601 glTexCoord2f(0.0, 0.0); |
588 glVertex2d(cScreenWidth / -2, cScreenHeight); |
602 glVertex2d(cScreenWidth / -2, cScreenHeight); |
591 glTexCoord2f(1.0, 1.0); |
605 glTexCoord2f(1.0, 1.0); |
592 glVertex2d(cScreenWidth / 2, 0); |
606 glVertex2d(cScreenWidth / 2, 0); |
593 glTexCoord2f(0.0, 1.0); |
607 glTexCoord2f(0.0, 1.0); |
594 glVertex2d(cScreenWidth / -2, 0); |
608 glVertex2d(cScreenWidth / -2, 0); |
595 glEnd(); |
609 glEnd(); |
|
610 |
|
611 // draw right frame |
596 glBindTexture(GL_TEXTURE_2D, texr); |
612 glBindTexture(GL_TEXTURE_2D, texr); |
597 glColor3f(1.0, 0.0, 0.0); |
613 glColor3f(1.0, 0.0, 0.0); |
598 glBegin(GL_QUADS); |
614 glBegin(GL_QUADS); |
599 glTexCoord2f(0.0, 0.0); |
615 glTexCoord2f(0.0, 0.0); |
600 glVertex2d(cScreenWidth / -2, cScreenHeight); |
616 glVertex2d(cScreenWidth / -2, cScreenHeight); |
603 glTexCoord2f(1.0, 1.0); |
619 glTexCoord2f(1.0, 1.0); |
604 glVertex2d(cScreenWidth / 2, 0); |
620 glVertex2d(cScreenWidth / 2, 0); |
605 glTexCoord2f(0.0, 1.0); |
621 glTexCoord2f(0.0, 1.0); |
606 glVertex2d(cScreenWidth / -2, 0); |
622 glVertex2d(cScreenWidth / -2, 0); |
607 glEnd(); |
623 glEnd(); |
|
624 |
|
625 // reset |
608 glColor3f(1.0, 1.0, 1.0); |
626 glColor3f(1.0, 1.0, 1.0); |
609 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
627 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
610 SetScale(zoom); |
628 SetScale(zoom); |
611 end |
629 end |
612 end; |
630 end; |
613 |
631 |
614 const cStereo_Sky = 0.0750; |
632 procedure ChangeDepth(rm: TRenderMode; d: GLfloat); |
615 cStereo_Horizon = 0.0250; |
633 begin |
616 cStereo_Water = 0.0125; |
634 if rm = rmDefault then exit |
617 var stereoDepth: GLfloat = 0; |
635 else if rm = rmRightEye then d:= -d; |
|
636 stereoDepth:= stereoDepth + d; |
|
637 glMatrixMode(GL_PROJECTION); |
|
638 glTranslatef(d, 0, 0); |
|
639 glMatrixMode(GL_MODELVIEW) |
|
640 end; |
618 |
641 |
619 procedure ChangeDepth(rm: TRenderMode; d: GLfloat); |
642 procedure ResetDepth(rm: TRenderMode); |
620 begin |
643 begin |
621 if rm = rmDefault then exit |
644 if rm = rmDefault then exit; |
622 else if rm = rmRightEye then d:= -d; |
645 glMatrixMode(GL_PROJECTION); |
623 stereoDepth:= stereoDepth + d; |
646 glTranslatef(-stereoDepth, 0, 0); |
624 glMatrixMode(GL_PROJECTION); |
647 glMatrixMode(GL_MODELVIEW); |
625 glTranslatef(d, 0, 0); |
648 stereoDepth:= 0; |
626 glMatrixMode(GL_MODELVIEW) |
649 end; |
627 end; |
|
628 |
650 |
629 procedure ResetDepth(rm: TRenderMode); |
651 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode); |
630 begin |
652 var i, t: LongInt; |
631 if rm = rmDefault then exit; |
653 r: TSDL_Rect; |
632 glMatrixMode(GL_PROJECTION); |
654 tdx, tdy: Double; |
633 glTranslatef(-stereoDepth, 0, 0); |
655 grp: TCapGroup; |
634 glMatrixMode(GL_MODELVIEW); |
656 s: string[15]; |
635 stereoDepth:= 0; |
657 highlight: Boolean; |
636 end; |
658 offset, offsetX, offsetY, screenBottom: LongInt; |
637 |
659 scale: GLfloat; |
638 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode); |
660 VertexBuffer: array [0..3] of TVertex2f; |
639 var i, t: LongInt; |
661 begin |
640 r: TSDL_Rect; |
|
641 tdx, tdy: Double; |
|
642 grp: TCapGroup; |
|
643 s: string[15]; |
|
644 highlight: Boolean; |
|
645 offset, offsetX, offsetY, screenBottom: LongInt; |
|
646 scale: GLfloat; |
|
647 VertexBuffer: array [0..3] of TVertex2f; |
|
648 begin |
|
649 if (cReducedQuality and rqNoBackground) = 0 then |
662 if (cReducedQuality and rqNoBackground) = 0 then |
650 begin |
663 begin |
651 // Offsets relative to camera - spare them to wimpier cpus, no bg or flakes for them anyway |
664 // Offsets relative to camera - spare them to wimpier cpus, no bg or flakes for them anyway |
652 ScreenBottom:= (WorldDy - trunc(cScreenHeight/cScaleFactor) - (cScreenHeight div 2) + cWaterLine); |
665 ScreenBottom:= (WorldDy - trunc(cScreenHeight/cScaleFactor) - (cScreenHeight div 2) + cWaterLine); |
653 offsetY:= 10 * min(0, -145 - ScreenBottom); |
666 offsetY:= 10 * min(0, -145 - ScreenBottom); |
655 HorizontOffset:= SkyOffset; |
668 HorizontOffset:= SkyOffset; |
656 if ScreenBottom > SkyOffset then |
669 if ScreenBottom > SkyOffset then |
657 HorizontOffset:= HorizontOffset + ((ScreenBottom-SkyOffset) div 20); |
670 HorizontOffset:= HorizontOffset + ((ScreenBottom-SkyOffset) div 20); |
658 |
671 |
659 // background |
672 // background |
660 ChangeDepth(RM, cStereo_Sky); |
673 ChangeDepth(RM, cStereo_Sky); |
661 DrawRepeated(sprSky, sprSkyL, sprSkyR, (WorldDx + LAND_WIDTH div 2) * 3 div 8, SkyOffset); |
674 DrawRepeated(sprSky, sprSkyL, sprSkyR, (WorldDx + LAND_WIDTH div 2) * 3 div 8, SkyOffset); |
662 ChangeDepth(RM, -cStereo_Horizon); |
675 ChangeDepth(RM, -cStereo_Horizon); |
663 DrawRepeated(sprHorizont, sprHorizontL, sprHorizontR, (WorldDx + LAND_WIDTH div 2) * 3 div 5, HorizontOffset); |
676 DrawRepeated(sprHorizont, sprHorizontL, sprHorizontR, (WorldDx + LAND_WIDTH div 2) * 3 div 5, HorizontOffset); |
664 end; |
677 end; |
665 |
678 |
666 DrawVisualGears(0); |
679 DrawVisualGears(0); |
667 |
680 |
668 if (cReducedQuality and rq2DWater) = 0 then |
681 if (cReducedQuality and rq2DWater) = 0 then |
669 begin |
682 begin |
670 // Waves |
683 // Waves |
671 DrawWater(255, SkyOffset); |
684 DrawWater(255, SkyOffset); |
672 ChangeDepth(RM, -cStereo_Water); |
685 ChangeDepth(RM, -cStereo_Water); |
673 DrawWaves( 1, 0 - WorldDx div 32, - cWaveHeight + offsetY div 35, 64); |
686 DrawWaves( 1, 0 - WorldDx div 32, - cWaveHeight + offsetY div 35, 64); |
674 ChangeDepth(RM, -cStereo_Water); |
687 ChangeDepth(RM, -cStereo_Water); |
675 DrawWaves( -1, 25 + WorldDx div 25, - cWaveHeight + offsetY div 38, 48); |
688 DrawWaves( -1, 25 + WorldDx div 25, - cWaveHeight + offsetY div 38, 48); |
676 ChangeDepth(RM, -cStereo_Water); |
689 ChangeDepth(RM, -cStereo_Water); |
677 DrawWaves( 1, 75 - WorldDx div 19, - cWaveHeight + offsetY div 45, 32); |
690 DrawWaves( 1, 75 - WorldDx div 19, - cWaveHeight + offsetY div 45, 32); |
678 ChangeDepth(RM, -cStereo_Water); |
691 ChangeDepth(RM, -cStereo_Water); |
679 DrawWaves(-1, 100 + WorldDx div 14, - cWaveHeight + offsetY div 70, 24); |
692 DrawWaves(-1, 100 + WorldDx div 14, - cWaveHeight + offsetY div 70, 24); |
680 ResetDepth(RM); |
693 ResetDepth(RM); |
681 end |
694 end |
682 else |
695 else |
683 DrawWaves(-1, 100, - (cWaveHeight + (cWaveHeight shr 1)), 0); |
696 DrawWaves(-1, 100, - (cWaveHeight + (cWaveHeight shr 1)), 0); |
684 |
697 |
685 DrawLand(WorldDx, WorldDy); |
698 DrawLand(WorldDx, WorldDy); |
715 DrawVisualGears(2); |
728 DrawVisualGears(2); |
716 |
729 |
717 DrawWater(cWaterOpacity, 0); |
730 DrawWater(cWaterOpacity, 0); |
718 |
731 |
719 // Waves |
732 // Waves |
720 ChangeDepth(RM, cStereo_Water); |
733 ChangeDepth(RM, cStereo_Water); |
721 DrawWaves( 1, 25 - WorldDx div 9, - cWaveHeight, 12); |
734 DrawWaves( 1, 25 - WorldDx div 9, - cWaveHeight, 12); |
722 |
735 |
723 if (cReducedQuality and rq2DWater) = 0 then |
736 if (cReducedQuality and rq2DWater) = 0 then |
724 begin |
737 begin |
725 //DrawWater(cWaterOpacity, - offsetY div 40); |
738 //DrawWater(cWaterOpacity, - offsetY div 40); |
726 ChangeDepth(RM, cStereo_Water); |
739 ChangeDepth(RM, cStereo_Water); |
727 DrawWaves(-1, 50 + WorldDx div 6, - cWaveHeight - offsetY div 40, 8); |
740 DrawWaves(-1, 50 + WorldDx div 6, - cWaveHeight - offsetY div 40, 8); |
728 DrawWater(cWaterOpacity, - offsetY div 20); |
741 DrawWater(cWaterOpacity, - offsetY div 20); |
729 ChangeDepth(RM, cStereo_Water); |
742 ChangeDepth(RM, cStereo_Water); |
730 DrawWaves( 1, 75 - WorldDx div 4, - cWaveHeight - offsetY div 20, 2); |
743 DrawWaves( 1, 75 - WorldDx div 4, - cWaveHeight - offsetY div 20, 2); |
731 DrawWater(cWaterOpacity, - offsetY div 10); |
744 DrawWater(cWaterOpacity, - offsetY div 10); |
732 ChangeDepth(RM, cStereo_Water); |
745 ChangeDepth(RM, cStereo_Water); |
733 DrawWaves( -1, 25 + WorldDx div 3, - cWaveHeight - offsetY div 10, 0); |
746 DrawWaves( -1, 25 + WorldDx div 3, - cWaveHeight - offsetY div 10, 0); |
734 ResetDepth(RM); |
747 ResetDepth(RM); |
735 end |
748 end |
736 else |
749 else |
737 DrawWaves(-1, 50, - (cWaveHeight shr 1), 0); |
750 DrawWaves(-1, 50, - (cWaveHeight shr 1), 0); |
738 |
751 |
739 |
752 |
954 offsetX:= 8; |
967 offsetX:= 8; |
955 {$ELSE} |
968 {$ELSE} |
956 offsetX:= 10; |
969 offsetX:= 10; |
957 {$ENDIF} |
970 {$ENDIF} |
958 offsetY:= cOffsetY; |
971 offsetY:= cOffsetY; |
|
972 |
|
973 // don't increment fps when drawing the right frame |
959 if (RM = rmDefault) or (RM = rmLeftEye) then |
974 if (RM = rmDefault) or (RM = rmLeftEye) then |
960 begin |
975 begin |
961 inc(Frames); |
976 inc(Frames); |
962 |
977 |
963 if cShowFPS or (GameType = gmtDemo) then inc(CountTicks, Lag); |
978 if cShowFPS or (GameType = gmtDemo) then |
964 if (GameType = gmtDemo) and (CountTicks >= 1000) then |
979 inc(CountTicks, Lag); |
965 begin |
980 if (GameType = gmtDemo) and (CountTicks >= 1000) then |
966 i:=GameTicks div 1000; |
981 begin |
967 t:= i mod 60; |
982 i:=GameTicks div 1000; |
968 s:= inttostr(t); |
983 t:= i mod 60; |
969 if t < 10 then s:= '0' + s; |
984 s:= inttostr(t); |
970 i:= i div 60; |
985 if t < 10 then s:= '0' + s; |
971 t:= i mod 60; |
986 i:= i div 60; |
972 s:= inttostr(t) + ':' + s; |
987 t:= i mod 60; |
973 if t < 10 then s:= '0' + s; |
988 s:= inttostr(t) + ':' + s; |
974 s:= inttostr(i div 60) + ':' + s; |
989 if t < 10 then s:= '0' + s; |
|
990 s:= inttostr(i div 60) + ':' + s; |
975 |
991 |
976 if timeTexture <> nil then |
992 if timeTexture <> nil then |
977 FreeTexture(timeTexture); |
993 FreeTexture(timeTexture); |
978 timeTexture:= nil; |
994 timeTexture:= nil; |
979 |
995 |
980 tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels); |
996 tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels); |
981 tmpSurface:= doSurfaceConversion(tmpSurface); |
997 tmpSurface:= doSurfaceConversion(tmpSurface); |
982 timeTexture:= Surface2Tex(tmpSurface, false); |
998 timeTexture:= Surface2Tex(tmpSurface, false); |
983 SDL_FreeSurface(tmpSurface) |
999 SDL_FreeSurface(tmpSurface) |
984 end; |
1000 end; |
985 |
1001 |
986 if timeTexture <> nil then |
1002 if timeTexture <> nil then |
987 DrawTexture((cScreenWidth shr 1) - 20 - timeTexture^.w - offsetY, offsetX + timeTexture^.h+5, timeTexture); |
1003 DrawTexture((cScreenWidth shr 1) - 20 - timeTexture^.w - offsetY, offsetX + timeTexture^.h+5, timeTexture); |
988 |
1004 |
989 if cShowFPS then |
1005 if cShowFPS then |
990 begin |
1006 begin |
991 if CountTicks >= 1000 then |
1007 if CountTicks >= 1000 then |
992 begin |
1008 begin |
993 FPS:= Frames; |
1009 FPS:= Frames; |
994 Frames:= 0; |
1010 Frames:= 0; |
995 CountTicks:= 0; |
1011 CountTicks:= 0; |
996 s:= inttostr(FPS) + ' fps'; |
1012 s:= inttostr(FPS) + ' fps'; |
997 if fpsTexture <> nil then |
1013 if fpsTexture <> nil then |
998 FreeTexture(fpsTexture); |
1014 FreeTexture(fpsTexture); |
999 fpsTexture:= nil; |
1015 fpsTexture:= nil; |
1000 tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels); |
1016 tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels); |
1001 tmpSurface:= doSurfaceConversion(tmpSurface); |
1017 tmpSurface:= doSurfaceConversion(tmpSurface); |
1002 fpsTexture:= Surface2Tex(tmpSurface, false); |
1018 fpsTexture:= Surface2Tex(tmpSurface, false); |
1003 SDL_FreeSurface(tmpSurface) |
1019 SDL_FreeSurface(tmpSurface) |
1004 end; |
1020 end; |
1005 if fpsTexture <> nil then |
1021 if fpsTexture <> nil then |
1006 DrawTexture((cScreenWidth shr 1) - 60 - offsetY, offsetX, fpsTexture); |
1022 DrawTexture((cScreenWidth shr 1) - 60 - offsetY, offsetX, fpsTexture); |
1007 end; |
1023 end; |
1008 |
1024 |
1009 if CountTicks >= 1000 then CountTicks:= 0; |
1025 if CountTicks >= 1000 then CountTicks:= 0; |
1010 |
1026 |
1011 // lag warning (?) |
1027 // lag warning (?) |
1012 inc(SoundTimerTicks, Lag); |
1028 inc(SoundTimerTicks, Lag); |
1013 end; |
1029 end; |
1014 |
1030 |
1015 if SoundTimerTicks >= 50 then |
1031 if SoundTimerTicks >= 50 then |
1016 begin |
1032 begin |
1017 SoundTimerTicks:= 0; |
1033 SoundTimerTicks:= 0; |