]> git.jsancho.org Git - lugaru.git/commitdiff
Moved stereo initialization code to a separate file.
authorVadim Trochinsky <vadim.trochinsky@gmail.com>
Tue, 18 May 2010 17:05:37 +0000 (19:05 +0200)
committerVadim Trochinsky <vadim.trochinsky@gmail.com>
Tue, 18 May 2010 17:05:37 +0000 (19:05 +0200)
CMakeLists.txt
Source/OpenGL_Windows.cpp
Source/Stereo.cpp [new file with mode: 0644]
Source/Stereo.h

index 7d3799595caa524d3b0933f43166983ae4df1cb9..c56a43ad6f0ad882180d5fce573840991725e3e5 100644 (file)
@@ -77,6 +77,7 @@ set(LUGARU_SRCS
        ${SRCDIR}/OpenGL_Windows.cpp
        ${SRCDIR}/openal_wrapper.cpp
        ${SRCDIR}/WinInput.cpp
+       ${SRCDIR}/Stereo.cpp
 )
 
 set(LUGARU_H
@@ -110,6 +111,7 @@ set(LUGARU_H
        ${SRCDIR}/pack_private.h
        ${SRCDIR}/private.h
        ${SRCDIR}/unpack_private.h
+       ${SRCDIR}/Stereo.h
 )
 
 if(UNIX)
index 576df7ecafdd761ca1b138d6448a567f9491c6b4..d4251fca6af1c3a8089ec13a33b9f1e6e5509c4a 100644 (file)
@@ -1037,56 +1037,11 @@ Boolean SetUp (Game & game)
        game.newscreenwidth=screenwidth;
        game.newscreenheight=screenheight;
 
-       GLint stencilbits = 0;
-       glGetIntegerv(GL_STENCIL_BITS, &stencilbits);
-       if ( stencilbits < 1 ) {
-               fprintf(stderr, "Failed to get a stencil buffer!\n");
-               SDL_Quit();
-               return false; 
-       }
-       
-       if ( stereomode == stereoHorizontalInterlaced || stereomode == stereoVerticalInterlaced ) {
-               fprintf(stderr, "Stencil buffer has %i bits, good.\n", stencilbits);
-               fprintf(stderr, "Screen width is %i, height is %i\n", kContextWidth, kContextHeight);
-               
-               glEnable( GL_STENCIL_TEST);
-               glClearStencil(0);
-               glClear(  GL_STENCIL_BUFFER_BIT );
-               glStencilFunc(GL_ALWAYS, 0x1, 0x1);
-               glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
-               
-               
-               glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-               glPixelStorei(GL_UNPACK_ROW_LENGTH, 3);
-               glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
-               glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
-               glColorMask( 1.0, 1.0, 1.0, 1.0 );
-               char stencil[] = {64,127,255};
-               
-               glViewport(0,0, kContextWidth, kContextHeight);
-               glMatrixMode(GL_PROJECTION);
-               glLoadIdentity();
-               glOrtho((GLdouble)0, (GLdouble)kContextWidth, (GLdouble)kContextHeight, 0, -1, 1);
-               glMatrixMode(GL_MODELVIEW);
-               glLoadIdentity();
-               
-               for(int y=0;y<kContextHeight;y+=2) {
-                       
-                       for(int x=0;x<kContextWidth;x++) {
-                               glRasterPos2i(x, y);
-                               glDrawPixels(1, 1, GL_RGB, GL_UNSIGNED_BYTE, &stencil);
-                       }
-               }
-               
-               glStencilFunc(GL_NOTEQUAL, 0x01, 0x01);
-               glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
-
-               // Something gets screwed up due to the changes above
-               // revert to default.
-               glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
-               glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
-               glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
-               glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
+       if ( CanInitStereo(stereomode) ) {
+               InitStereo(stereomode);
+       } else {
+               fprintf(stderr, "Failed to initialize stereo, disabling.\n");
+               stereomode = stereoNone;
        }
 
        game.InitGame();
diff --git a/Source/Stereo.cpp b/Source/Stereo.cpp
new file mode 100644 (file)
index 0000000..815e177
--- /dev/null
@@ -0,0 +1,86 @@
+
+#include "Game.h"
+#include "Stereo.h"
+
+
+extern int kContextWidth;
+extern int kContextHeight;
+
+bool CanInitStereo(StereoMode mode) {
+       GLint stencilbits = 0;
+       
+       switch(mode) {
+               case stereoNone:
+                       return true;
+                       break;
+               case stereoAnaglyph:
+                       return true;
+                       break;
+               case stereoHorizontalInterlaced:
+               case stereoVerticalInterlaced:
+                       glGetIntegerv(GL_STENCIL_BITS, &stencilbits);
+                       if ( stencilbits < 1 ) {
+                               fprintf(stderr, "Failed to get a stencil buffer, interlaced stereo not available.\n");
+                               return false;
+                       } else {
+                               fprintf(stderr, "Stencil buffer has %i bits, good.\n", stencilbits);
+                       }
+                       
+               default:
+                       return false;
+       }
+
+}
+
+void InitStereo(StereoMode mode) {
+       switch(mode) {
+               case stereoNone:
+                       return;
+               case stereoAnaglyph:
+                       return;
+               case stereoHorizontalInterlaced:
+               case stereoVerticalInterlaced:
+                       
+                       fprintf(stderr, "Screen width is %i, height is %i\n", kContextWidth, kContextHeight);
+                       
+                       glEnable( GL_STENCIL_TEST);
+                       glClearStencil(0);
+                       glClear(  GL_STENCIL_BUFFER_BIT );
+                       glStencilFunc(GL_ALWAYS, 0x1, 0x1);
+                       glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
+                       
+                       
+                       glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+                       glPixelStorei(GL_UNPACK_ROW_LENGTH, 3);
+                       glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
+                       glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
+                       glColorMask( 1.0, 1.0, 1.0, 1.0 );
+                       char stencil[] = {64,127,255};
+                       
+                       glViewport(0,0, kContextWidth, kContextHeight);
+                       glMatrixMode(GL_PROJECTION);
+                       glLoadIdentity();
+                       glOrtho((GLdouble)0, (GLdouble)kContextWidth, (GLdouble)kContextHeight, 0, -1, 1);
+                       glMatrixMode(GL_MODELVIEW);
+                       glLoadIdentity();
+                       
+                       for(int y=0;y<kContextHeight;y+=2) {
+                               
+                               for(int x=0;x<kContextWidth;x++) {
+                                       glRasterPos2i(x, y);
+                                       glDrawPixels(1, 1, GL_RGB, GL_UNSIGNED_BYTE, &stencil);
+                               }
+                       }
+                       
+                       glStencilFunc(GL_NOTEQUAL, 0x01, 0x01);
+                       glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
+
+                       // Something gets screwed up due to the changes above
+                       // revert to default.
+                       glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
+                       glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+                       glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
+                       glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
+       }
+       
+}
\ No newline at end of file
index 084a9f4de56313bdca719e2303a1f245fc30edee..c0de10f9ac3ebbff224d04b45d4ad9a2fd029eb5 100644 (file)
@@ -25,4 +25,7 @@ extern StereoMode stereomode;
 extern float stereoseparation;
 extern bool  stereoreverse;
 
+bool CanInitStereo(StereoMode mode);
+void InitStereo(StereoMode mode);
+
 #endif
\ No newline at end of file