2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
6 Lugaru is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 Lugaru is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
24 extern int kContextWidth;
25 extern int kContextHeight;
27 bool CanInitStereo(StereoMode mode)
29 GLint stencilbits = 0;
38 case stereoHorizontalInterlaced:
39 case stereoVerticalInterlaced:
40 glGetIntegerv(GL_STENCIL_BITS, &stencilbits);
41 if ( stencilbits < 1 ) {
42 fprintf(stderr, "Failed to get a stencil buffer, interlaced stereo not available.\n");
45 fprintf(stderr, "Stencil buffer has %i bits, good.\n", stencilbits);
55 void InitStereo(StereoMode mode)
61 glDisable(GL_STENCIL_TEST);
63 case stereoHorizontalInterlaced:
64 case stereoVerticalInterlaced:
65 fprintf(stderr, "Screen width is %i, height is %i\n", kContextWidth, kContextHeight);
67 // Setup stencil buffer
68 glDisable( GL_DEPTH_TEST);
69 glDisable(GL_CULL_FACE);
70 glDisable(GL_LIGHTING);
71 glDisable(GL_TEXTURE_2D);
73 glEnable( GL_STENCIL_TEST);
75 glClear( GL_STENCIL_BUFFER_BIT );
76 glStencilFunc(GL_ALWAYS, 0x1, 0x1);
77 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
80 glViewport(0, 0, kContextWidth, kContextHeight);
81 glMatrixMode(GL_PROJECTION);
84 glOrtho((GLdouble)0, (GLdouble)kContextWidth, (GLdouble)kContextHeight, 0, -1, 1);
85 glMatrixMode(GL_MODELVIEW);
88 glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
89 glDisable(GL_LINE_SMOOTH);
91 // Add 0.5 to the coordinates, because OpenGL considers a pixel should be
92 // turned on when a line passes through the center of it.
93 if ( mode == stereoHorizontalInterlaced ) {
94 for (int y = 0; y < kContextHeight; y += 2) {
96 glVertex3f(0.5, y + 0.5, 0);
97 glVertex3f(kContextWidth + 0.5, y + 0.5, 0);
101 for (int x = 0; x < kContextWidth; x += 2) {
103 glVertex3f(x + 0.5, 0.5, 0);
104 glVertex3f(x + 0.5, kContextHeight + 0.5, 0);
109 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
112 glMatrixMode(GL_PROJECTION);
115 glStencilFunc(GL_NOTEQUAL, 0x01, 0x01);
116 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
117 glEnable( GL_DEPTH_TEST);
118 glEnable(GL_CULL_FACE);
119 glEnable(GL_LIGHTING);
120 glEnable(GL_TEXTURE_2D);
125 const char* StereoModeName(StereoMode mode)
134 case stereoHorizontalInterlaced:
135 return "Horizontal interlacing";
137 case stereoVerticalInterlaced:
138 return "Vertical interlacing";
140 case stereoHorizontalSplit:
141 return "Horizontal split";
143 case stereoVerticalSplit:
144 return "Vertical split";