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
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program 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.
15 See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 extern int kContextWidth;
27 extern int kContextHeight;
29 bool CanInitStereo(StereoMode mode)
31 GLint stencilbits = 0;
40 case stereoHorizontalInterlaced:
41 case stereoVerticalInterlaced:
42 glGetIntegerv(GL_STENCIL_BITS, &stencilbits);
43 if ( stencilbits < 1 ) {
44 fprintf(stderr, "Failed to get a stencil buffer, interlaced stereo not available.\n");
47 fprintf(stderr, "Stencil buffer has %i bits, good.\n", stencilbits);
57 void InitStereo(StereoMode mode)
63 glDisable(GL_STENCIL_TEST);
65 case stereoHorizontalInterlaced:
66 case stereoVerticalInterlaced:
67 fprintf(stderr, "Screen width is %i, height is %i\n", kContextWidth, kContextHeight);
69 // Setup stencil buffer
70 glDisable( GL_DEPTH_TEST);
71 glDisable(GL_CULL_FACE);
72 glDisable(GL_LIGHTING);
73 glDisable(GL_TEXTURE_2D);
75 glEnable( GL_STENCIL_TEST);
77 glClear( GL_STENCIL_BUFFER_BIT );
78 glStencilFunc(GL_ALWAYS, 0x1, 0x1);
79 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
82 glViewport(0, 0, kContextWidth, kContextHeight);
83 glMatrixMode(GL_PROJECTION);
86 glOrtho((GLdouble)0, (GLdouble)kContextWidth, (GLdouble)kContextHeight, 0, -1, 1);
87 glMatrixMode(GL_MODELVIEW);
90 glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
91 glDisable(GL_LINE_SMOOTH);
93 // Add 0.5 to the coordinates, because OpenGL considers a pixel should be
94 // turned on when a line passes through the center of it.
95 if ( mode == stereoHorizontalInterlaced ) {
96 for (int y = 0; y < kContextHeight; y += 2) {
98 glVertex3f(0.5, y + 0.5, 0);
99 glVertex3f(kContextWidth + 0.5, y + 0.5, 0);
103 for (int x = 0; x < kContextWidth; x += 2) {
105 glVertex3f(x + 0.5, 0.5, 0);
106 glVertex3f(x + 0.5, kContextHeight + 0.5, 0);
111 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
114 glMatrixMode(GL_PROJECTION);
117 glStencilFunc(GL_NOTEQUAL, 0x01, 0x01);
118 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
119 glEnable( GL_DEPTH_TEST);
120 glEnable(GL_CULL_FACE);
121 glEnable(GL_LIGHTING);
122 glEnable(GL_TEXTURE_2D);
127 const char* StereoModeName(StereoMode mode)
136 case stereoHorizontalInterlaced:
137 return "Horizontal interlacing";
139 case stereoVerticalInterlaced:
140 return "Vertical interlacing";
142 case stereoHorizontalSplit:
143 return "Horizontal split";
145 case stereoVerticalSplit:
146 return "Vertical split";