562 //glScalef(1.0, 1.0, 1.0); |
557 //glScalef(1.0, 1.0, 1.0); |
563 |
558 |
564 if not isPaused then |
559 if not isPaused then |
565 MoveCamera; |
560 MoveCamera; |
566 |
561 |
|
562 if not isStereoEnabled then |
|
563 begin |
|
564 glClear(GL_COLOR_BUFFER_BIT); |
|
565 DrawWorldStereo(Lag, rmDefault) |
|
566 end |
|
567 else |
|
568 begin |
|
569 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framel); |
|
570 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); |
|
571 DrawWorldStereo(Lag, rmLeftEye); |
|
572 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framer); |
|
573 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); |
|
574 DrawWorldStereo(0, rmRightEye); |
|
575 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); |
|
576 glGetFloatv(GL_COLOR_CLEAR_VALUE, @cc); |
|
577 glClearColor(0, 0, 0, 0); |
|
578 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); |
|
579 glClearColor(cc[0], cc[1], cc[2], cc[3]); |
|
580 SetScale(2.0); |
|
581 glEnable(GL_TEXTURE_2D); |
|
582 glEnable(GL_BLEND); |
|
583 glBlendFunc(GL_ONE, GL_ONE); |
|
584 glBindTexture(GL_TEXTURE_2D, texl); |
|
585 glColor3f(0.0, 1.0, 1.0); |
|
586 glBegin(GL_QUADS); |
|
587 glTexCoord2f(0.0, 0.0); |
|
588 glVertex2d(cScreenWidth / -2, cScreenHeight); |
|
589 glTexCoord2f(1.0, 0.0); |
|
590 glVertex2d(cScreenWidth / 2, cScreenHeight); |
|
591 glTexCoord2f(1.0, 1.0); |
|
592 glVertex2d(cScreenWidth / 2, 0); |
|
593 glTexCoord2f(0.0, 1.0); |
|
594 glVertex2d(cScreenWidth / -2, 0); |
|
595 glEnd(); |
|
596 glBindTexture(GL_TEXTURE_2D, texr); |
|
597 glColor3f(1.0, 0.0, 0.0); |
|
598 glBegin(GL_QUADS); |
|
599 glTexCoord2f(0.0, 0.0); |
|
600 glVertex2d(cScreenWidth / -2, cScreenHeight); |
|
601 glTexCoord2f(1.0, 0.0); |
|
602 glVertex2d(cScreenWidth / 2, cScreenHeight); |
|
603 glTexCoord2f(1.0, 1.0); |
|
604 glVertex2d(cScreenWidth / 2, 0); |
|
605 glTexCoord2f(0.0, 1.0); |
|
606 glVertex2d(cScreenWidth / -2, 0); |
|
607 glEnd(); |
|
608 glColor3f(1.0, 1.0, 1.0); |
|
609 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
610 SetScale(zoom); |
|
611 end |
|
612 end; |
|
613 |
|
614 const cStereo_Sky = 0.0750; |
|
615 cStereo_Horizon = 0.0250; |
|
616 cStereo_Water = 0.0125; |
|
617 var stereoDepth: GLfloat = 0; |
|
618 |
|
619 procedure ChangeDepth(rm: TRenderMode; d: GLfloat); |
|
620 begin |
|
621 if rm = rmDefault then exit |
|
622 else if rm = rmRightEye then d:= -d; |
|
623 stereoDepth:= stereoDepth + d; |
|
624 glMatrixMode(GL_PROJECTION); |
|
625 glTranslatef(d, 0, 0); |
|
626 glMatrixMode(GL_MODELVIEW) |
|
627 end; |
|
628 |
|
629 procedure ResetDepth(rm: TRenderMode); |
|
630 begin |
|
631 if rm = rmDefault then exit; |
|
632 glMatrixMode(GL_PROJECTION); |
|
633 glTranslatef(-stereoDepth, 0, 0); |
|
634 glMatrixMode(GL_MODELVIEW); |
|
635 stereoDepth:= 0; |
|
636 end; |
|
637 |
|
638 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode); |
|
639 var i, t: LongInt; |
|
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 |
567 if (cReducedQuality and rqNoBackground) = 0 then |
649 if (cReducedQuality and rqNoBackground) = 0 then |
568 begin |
650 begin |
569 // Offsets relative to camera - spare them to wimpier cpus, no bg or flakes for them anyway |
651 // Offsets relative to camera - spare them to wimpier cpus, no bg or flakes for them anyway |
570 ScreenBottom:= (WorldDy - trunc(cScreenHeight/cScaleFactor) - (cScreenHeight div 2) + cWaterLine); |
652 ScreenBottom:= (WorldDy - trunc(cScreenHeight/cScaleFactor) - (cScreenHeight div 2) + cWaterLine); |
571 offsetY:= 10 * min(0, -145 - ScreenBottom); |
653 offsetY:= 10 * min(0, -145 - ScreenBottom); |
573 HorizontOffset:= SkyOffset; |
655 HorizontOffset:= SkyOffset; |
574 if ScreenBottom > SkyOffset then |
656 if ScreenBottom > SkyOffset then |
575 HorizontOffset:= HorizontOffset + ((ScreenBottom-SkyOffset) div 20); |
657 HorizontOffset:= HorizontOffset + ((ScreenBottom-SkyOffset) div 20); |
576 |
658 |
577 // background |
659 // background |
|
660 ChangeDepth(RM, cStereo_Sky); |
578 DrawRepeated(sprSky, sprSkyL, sprSkyR, (WorldDx + LAND_WIDTH div 2) * 3 div 8, SkyOffset); |
661 DrawRepeated(sprSky, sprSkyL, sprSkyR, (WorldDx + LAND_WIDTH div 2) * 3 div 8, SkyOffset); |
|
662 ChangeDepth(RM, -cStereo_Horizon); |
579 DrawRepeated(sprHorizont, sprHorizontL, sprHorizontR, (WorldDx + LAND_WIDTH div 2) * 3 div 5, HorizontOffset); |
663 DrawRepeated(sprHorizont, sprHorizontL, sprHorizontR, (WorldDx + LAND_WIDTH div 2) * 3 div 5, HorizontOffset); |
580 end; |
664 end; |
581 |
665 |
582 DrawVisualGears(0); |
666 DrawVisualGears(0); |
583 |
667 |
584 if (cReducedQuality and rq2DWater) = 0 then |
668 if (cReducedQuality and rq2DWater) = 0 then |
585 begin |
669 begin |
586 // Waves |
670 // Waves |
587 DrawWater(255, SkyOffset); |
671 DrawWater(255, SkyOffset); |
|
672 ChangeDepth(RM, -cStereo_Water); |
588 DrawWaves( 1, 0 - WorldDx div 32, - cWaveHeight + offsetY div 35, 64); |
673 DrawWaves( 1, 0 - WorldDx div 32, - cWaveHeight + offsetY div 35, 64); |
|
674 ChangeDepth(RM, -cStereo_Water); |
589 DrawWaves( -1, 25 + WorldDx div 25, - cWaveHeight + offsetY div 38, 48); |
675 DrawWaves( -1, 25 + WorldDx div 25, - cWaveHeight + offsetY div 38, 48); |
|
676 ChangeDepth(RM, -cStereo_Water); |
590 DrawWaves( 1, 75 - WorldDx div 19, - cWaveHeight + offsetY div 45, 32); |
677 DrawWaves( 1, 75 - WorldDx div 19, - cWaveHeight + offsetY div 45, 32); |
|
678 ChangeDepth(RM, -cStereo_Water); |
591 DrawWaves(-1, 100 + WorldDx div 14, - cWaveHeight + offsetY div 70, 24); |
679 DrawWaves(-1, 100 + WorldDx div 14, - cWaveHeight + offsetY div 70, 24); |
|
680 ResetDepth(RM); |
592 end |
681 end |
593 else |
682 else |
594 DrawWaves(-1, 100, - (cWaveHeight + (cWaveHeight shr 1)), 0); |
683 DrawWaves(-1, 100, - (cWaveHeight + (cWaveHeight shr 1)), 0); |
595 |
684 |
596 DrawLand(WorldDx, WorldDy); |
685 DrawLand(WorldDx, WorldDy); |
626 DrawVisualGears(2); |
715 DrawVisualGears(2); |
627 |
716 |
628 DrawWater(cWaterOpacity, 0); |
717 DrawWater(cWaterOpacity, 0); |
629 |
718 |
630 // Waves |
719 // Waves |
|
720 ChangeDepth(RM, cStereo_Water); |
631 DrawWaves( 1, 25 - WorldDx div 9, - cWaveHeight, 12); |
721 DrawWaves( 1, 25 - WorldDx div 9, - cWaveHeight, 12); |
632 |
722 |
633 if (cReducedQuality and rq2DWater) = 0 then |
723 if (cReducedQuality and rq2DWater) = 0 then |
634 begin |
724 begin |
635 //DrawWater(cWaterOpacity, - offsetY div 40); |
725 //DrawWater(cWaterOpacity, - offsetY div 40); |
|
726 ChangeDepth(RM, cStereo_Water); |
636 DrawWaves(-1, 50 + WorldDx div 6, - cWaveHeight - offsetY div 40, 8); |
727 DrawWaves(-1, 50 + WorldDx div 6, - cWaveHeight - offsetY div 40, 8); |
637 DrawWater(cWaterOpacity, - offsetY div 20); |
728 DrawWater(cWaterOpacity, - offsetY div 20); |
|
729 ChangeDepth(RM, cStereo_Water); |
638 DrawWaves( 1, 75 - WorldDx div 4, - cWaveHeight - offsetY div 20, 2); |
730 DrawWaves( 1, 75 - WorldDx div 4, - cWaveHeight - offsetY div 20, 2); |
639 DrawWater(cWaterOpacity, - offsetY div 10); |
731 DrawWater(cWaterOpacity, - offsetY div 10); |
|
732 ChangeDepth(RM, cStereo_Water); |
640 DrawWaves( -1, 25 + WorldDx div 3, - cWaveHeight - offsetY div 10, 0); |
733 DrawWaves( -1, 25 + WorldDx div 3, - cWaveHeight - offsetY div 10, 0); |
|
734 ResetDepth(RM); |
641 end |
735 end |
642 else |
736 else |
643 DrawWaves(-1, 50, - (cWaveHeight shr 1), 0); |
737 DrawWaves(-1, 50, - (cWaveHeight shr 1), 0); |
644 |
738 |
645 |
739 |