]> git.jsancho.org Git - lugaru.git/blobdiff - Source/OpenGL_Windows.cpp
Merged with parent
[lugaru.git] / Source / OpenGL_Windows.cpp
index 3a508adf06f02f099e76279e19f3f0705f32587b..f118ce7a6810413cd863ddeca95e54504db72b6e 100644 (file)
@@ -19,6 +19,7 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 
+
 #ifdef WIN32
 #define UINT8 WIN32API_UINT8
 #define UINT16 WIN32API_UINT16
@@ -35,7 +36,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 extern "C" {
        #include "zlib.h"
        #include "png.h"
-       #include "jpeglib.h"
+   #ifdef WIN32
+               #define INT32 INT32_jpeg
+               #include "jpeglib.h"
+               #undef INT32
+       #else
+               #include "jpeglib.h"
+       #endif
 }
 
 static bool load_image(const char * fname, TGAImageRec & tex);
@@ -110,12 +117,12 @@ extern float volume;
 #include "gamegl.h"
 #include "MacCompatibility.h"
 
+
 #ifdef WIN32
 #include <shellapi.h>
+#include "win-res/resource.h"
 #endif
 
-#include "res/resource.h"
-
 using namespace std;
 
 
@@ -313,7 +320,12 @@ void ShutdownDSp ()
 
 void DrawGL (Game & game)
 {
-       game.DrawGLScene();
+       if ( stereomode == stereoNone ) {
+               game.DrawGLScene(stereoCenter);
+       } else {
+               game.DrawGLScene(stereoLeft);
+               game.DrawGLScene(stereoRight);
+       }
 }
 
 
@@ -568,7 +580,7 @@ Boolean SetUp (Game & game)
        randSeed = UpTime().lo;
 
        osx = 0;
-       ifstream ipstream(ConvertFileName("/Data/config.txt"), std::ios::in /*| std::ios::nocreate*/);
+       ifstream ipstream(ConvertFileName(":Data:config.txt"), std::ios::in /*| std::ios::nocreate*/);
        detail=1;
        ismotionblur=0;
        usermousesensitivity=1;
@@ -618,7 +630,7 @@ Boolean SetUp (Game & game)
        selectDetail(kContextWidth, kContextHeight, kBitsPerPixel, detail);
 
        if(!ipstream) {
-               ofstream opstream(ConvertFileName("/Data/config.txt", "w"));
+               ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
                opstream << "Screenwidth:\n";
                opstream << kContextWidth;
                opstream << "\nScreenheight:\n";
@@ -916,7 +928,8 @@ Boolean SetUp (Game & game)
     SDL_ShowCursor(0);
 
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-
+    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
+    
     if (SDL_SetVideoMode(kContextWidth, kContextHeight, 0, sdlflags) == NULL)
     {
         fprintf(stderr, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
@@ -965,7 +978,6 @@ Boolean SetUp (Game & game)
        glDisable( GL_FOG);
        glDisable( GL_LIGHTING);
        glDisable( GL_LOGIC_OP);
-       glDisable( GL_STENCIL_TEST);
        glDisable( GL_TEXTURE_1D);
        glDisable( GL_TEXTURE_2D);
        glPixelTransferi( GL_MAP_COLOR, GL_FALSE);
@@ -1007,6 +1019,56 @@ 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; 
+       }
+       
+       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);
+
        game.InitGame();
 
        return true;
@@ -1499,6 +1561,7 @@ int main(int argc, char **argv)
                }
        }
 
+
        bool LoadImage(const char * fname, TGAImageRec & tex)
        {
                bool res = true;