562 //glScalef(1.0, 1.0, 1.0); |
562 //glScalef(1.0, 1.0, 1.0); |
563 |
563 |
564 if not isPaused then |
564 if not isPaused then |
565 MoveCamera; |
565 MoveCamera; |
566 |
566 |
|
567 if not isStereoEnabled then |
|
568 begin |
|
569 glClear(GL_COLOR_BUFFER_BIT); |
|
570 DrawWorldStereo(Lag, rmDefault) |
|
571 end |
|
572 else |
|
573 begin |
|
574 // create left fb |
|
575 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framel); |
|
576 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); |
|
577 DrawWorldStereo(Lag, rmLeftEye); |
|
578 |
|
579 // create right fb |
|
580 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framer); |
|
581 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); |
|
582 DrawWorldStereo(0, rmRightEye); |
|
583 |
|
584 // detatch drawing from fbs |
|
585 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); |
|
586 glGetFloatv(GL_COLOR_CLEAR_VALUE, @cc); |
|
587 glClearColor(0, 0, 0, 0); |
|
588 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); |
|
589 glClearColor(cc[0], cc[1], cc[2], cc[3]); |
|
590 SetScale(cDefaultZoomLevel); |
|
591 |
|
592 // enable gl stuff |
|
593 glEnable(GL_TEXTURE_2D); |
|
594 glEnable(GL_BLEND); |
|
595 glBlendFunc(GL_ONE, GL_ONE); |
|
596 |
|
597 // draw left frame |
|
598 glBindTexture(GL_TEXTURE_2D, texl); |
|
599 glColor3f(0.0, 1.0, 1.0); |
|
600 glBegin(GL_QUADS); |
|
601 glTexCoord2f(0.0, 0.0); |
|
602 glVertex2d(cScreenWidth / -2, cScreenHeight); |
|
603 glTexCoord2f(1.0, 0.0); |
|
604 glVertex2d(cScreenWidth / 2, cScreenHeight); |
|
605 glTexCoord2f(1.0, 1.0); |
|
606 glVertex2d(cScreenWidth / 2, 0); |
|
607 glTexCoord2f(0.0, 1.0); |
|
608 glVertex2d(cScreenWidth / -2, 0); |
|
609 glEnd(); |
|
610 |
|
611 // draw right frame |
|
612 glBindTexture(GL_TEXTURE_2D, texr); |
|
613 glColor3f(1.0, 0.0, 0.0); |
|
614 glBegin(GL_QUADS); |
|
615 glTexCoord2f(0.0, 0.0); |
|
616 glVertex2d(cScreenWidth / -2, cScreenHeight); |
|
617 glTexCoord2f(1.0, 0.0); |
|
618 glVertex2d(cScreenWidth / 2, cScreenHeight); |
|
619 glTexCoord2f(1.0, 1.0); |
|
620 glVertex2d(cScreenWidth / 2, 0); |
|
621 glTexCoord2f(0.0, 1.0); |
|
622 glVertex2d(cScreenWidth / -2, 0); |
|
623 glEnd(); |
|
624 |
|
625 // reset |
|
626 glColor3f(1.0, 1.0, 1.0); |
|
627 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
628 SetScale(zoom); |
|
629 end |
|
630 end; |
|
631 |
|
632 procedure ChangeDepth(rm: TRenderMode; d: GLfloat); |
|
633 begin |
|
634 if rm = rmDefault then exit |
|
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; |
|
641 |
|
642 procedure ResetDepth(rm: TRenderMode); |
|
643 begin |
|
644 if rm = rmDefault then exit; |
|
645 glMatrixMode(GL_PROJECTION); |
|
646 glTranslatef(-stereoDepth, 0, 0); |
|
647 glMatrixMode(GL_MODELVIEW); |
|
648 stereoDepth:= 0; |
|
649 end; |
|
650 |
|
651 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode); |
|
652 var i, t: LongInt; |
|
653 r: TSDL_Rect; |
|
654 tdx, tdy: Double; |
|
655 grp: TCapGroup; |
|
656 s: string[15]; |
|
657 highlight: Boolean; |
|
658 offset, offsetX, offsetY, screenBottom: LongInt; |
|
659 scale: GLfloat; |
|
660 VertexBuffer: array [0..3] of TVertex2f; |
|
661 begin |
567 if (cReducedQuality and rqNoBackground) = 0 then |
662 if (cReducedQuality and rqNoBackground) = 0 then |
568 begin |
663 begin |
569 // 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 |
570 ScreenBottom:= (WorldDy - trunc(cScreenHeight/cScaleFactor) - (cScreenHeight div 2) + cWaterLine); |
665 ScreenBottom:= (WorldDy - trunc(cScreenHeight/cScaleFactor) - (cScreenHeight div 2) + cWaterLine); |
571 offsetY:= 10 * min(0, -145 - ScreenBottom); |
666 offsetY:= 10 * min(0, -145 - ScreenBottom); |
872 offsetX:= 8; |
967 offsetX:= 8; |
873 {$ELSE} |
968 {$ELSE} |
874 offsetX:= 10; |
969 offsetX:= 10; |
875 {$ENDIF} |
970 {$ENDIF} |
876 offsetY:= cOffsetY; |
971 offsetY:= cOffsetY; |
877 inc(Frames); |
972 |
878 |
973 // don't increment fps when drawing the right frame |
879 if cShowFPS or (GameType = gmtDemo) then inc(CountTicks, Lag); |
974 if (RM = rmDefault) or (RM = rmLeftEye) then |
880 if (GameType = gmtDemo) and (CountTicks >= 1000) then |
975 begin |
881 begin |
976 inc(Frames); |
882 i:=GameTicks div 1000; |
977 |
883 t:= i mod 60; |
978 if cShowFPS or (GameType = gmtDemo) then |
884 s:= inttostr(t); |
979 inc(CountTicks, Lag); |
885 if t < 10 then s:= '0' + s; |
980 if (GameType = gmtDemo) and (CountTicks >= 1000) then |
886 i:= i div 60; |
981 begin |
887 t:= i mod 60; |
982 i:=GameTicks div 1000; |
888 s:= inttostr(t) + ':' + s; |
983 t:= i mod 60; |
889 if t < 10 then s:= '0' + s; |
984 s:= inttostr(t); |
890 s:= inttostr(i div 60) + ':' + s; |
985 if t < 10 then s:= '0' + s; |
|
986 i:= i div 60; |
|
987 t:= i mod 60; |
|
988 s:= inttostr(t) + ':' + s; |
|
989 if t < 10 then s:= '0' + s; |
|
990 s:= inttostr(i div 60) + ':' + s; |
891 |
991 |
892 if timeTexture <> nil then |
992 if timeTexture <> nil then |
893 FreeTexture(timeTexture); |
993 FreeTexture(timeTexture); |
894 timeTexture:= nil; |
994 timeTexture:= nil; |
895 |
995 |
896 tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels); |
996 tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels); |
897 tmpSurface:= doSurfaceConversion(tmpSurface); |
997 tmpSurface:= doSurfaceConversion(tmpSurface); |
898 timeTexture:= Surface2Tex(tmpSurface, false); |
998 timeTexture:= Surface2Tex(tmpSurface, false); |
899 SDL_FreeSurface(tmpSurface) |
999 SDL_FreeSurface(tmpSurface) |
900 end; |
1000 end; |
901 |
1001 |
902 if timeTexture <> nil then |
1002 if timeTexture <> nil then |
903 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); |
904 |
1004 |
905 if cShowFPS then |
1005 if cShowFPS then |
906 begin |
1006 begin |
907 if CountTicks >= 1000 then |
1007 if CountTicks >= 1000 then |
908 begin |
1008 begin |
909 FPS:= Frames; |
1009 FPS:= Frames; |
910 Frames:= 0; |
1010 Frames:= 0; |
911 CountTicks:= 0; |
1011 CountTicks:= 0; |
912 s:= inttostr(FPS) + ' fps'; |
1012 s:= inttostr(FPS) + ' fps'; |
913 if fpsTexture <> nil then |
1013 if fpsTexture <> nil then |
914 FreeTexture(fpsTexture); |
1014 FreeTexture(fpsTexture); |
915 fpsTexture:= nil; |
1015 fpsTexture:= nil; |
916 tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels); |
1016 tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels); |
917 tmpSurface:= doSurfaceConversion(tmpSurface); |
1017 tmpSurface:= doSurfaceConversion(tmpSurface); |
918 fpsTexture:= Surface2Tex(tmpSurface, false); |
1018 fpsTexture:= Surface2Tex(tmpSurface, false); |
919 SDL_FreeSurface(tmpSurface) |
1019 SDL_FreeSurface(tmpSurface) |
920 end; |
1020 end; |
921 if fpsTexture <> nil then |
1021 if fpsTexture <> nil then |
922 DrawTexture((cScreenWidth shr 1) - 60 - offsetY, offsetX, fpsTexture); |
1022 DrawTexture((cScreenWidth shr 1) - 60 - offsetY, offsetX, fpsTexture); |
923 end; |
1023 end; |
924 |
1024 |
925 if CountTicks >= 1000 then CountTicks:= 0; |
1025 if CountTicks >= 1000 then CountTicks:= 0; |
926 |
1026 |
927 // lag warning (?) |
1027 // lag warning (?) |
928 inc(SoundTimerTicks, Lag); |
1028 inc(SoundTimerTicks, Lag); |
|
1029 end; |
|
1030 |
929 if SoundTimerTicks >= 50 then |
1031 if SoundTimerTicks >= 50 then |
930 begin |
1032 begin |
931 SoundTimerTicks:= 0; |
1033 SoundTimerTicks:= 0; |
932 if cVolumeDelta <> 0 then |
1034 if cVolumeDelta <> 0 then |
933 begin |
1035 begin |