2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
21 #include "Graphic/Stereo.hpp"
25 extern int kContextWidth;
26 extern int kContextHeight;
28 bool CanInitStereo(StereoMode mode)
30 GLint stencilbits = 0;
37 case stereoHorizontalInterlaced:
38 case stereoVerticalInterlaced:
39 glGetIntegerv(GL_STENCIL_BITS, &stencilbits);
40 if ( stencilbits < 1 ) {
41 fprintf(stderr, "Failed to get a stencil buffer, interlaced stereo not available.\n");
44 fprintf(stderr, "Stencil buffer has %i bits, good.\n", stencilbits);
54 void InitStereo(StereoMode mode)
60 glDisable(GL_STENCIL_TEST);
62 case stereoHorizontalInterlaced:
63 case stereoVerticalInterlaced:
64 fprintf(stderr, "Screen width is %i, height is %i\n", kContextWidth, kContextHeight);
66 // Setup stencil buffer
67 glDisable( GL_DEPTH_TEST);
68 glDisable(GL_CULL_FACE);
69 glDisable(GL_LIGHTING);
70 glDisable(GL_TEXTURE_2D);
72 glEnable( GL_STENCIL_TEST);
74 glClear( GL_STENCIL_BUFFER_BIT );
75 glStencilFunc(GL_ALWAYS, 0x1, 0x1);
76 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
79 glViewport(0, 0, kContextWidth, kContextHeight);
80 glMatrixMode(GL_PROJECTION);
83 glOrtho((GLdouble)0, (GLdouble)kContextWidth, (GLdouble)kContextHeight, 0, -1, 1);
84 glMatrixMode(GL_MODELVIEW);
87 glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
88 glDisable(GL_LINE_SMOOTH);
90 // Add 0.5 to the coordinates, because OpenGL considers a pixel should be
91 // turned on when a line passes through the center of it.
92 if ( mode == stereoHorizontalInterlaced ) {
93 for (int y = 0; y < kContextHeight; y += 2) {
95 glVertex3f(0.5, y + 0.5, 0);
96 glVertex3f(kContextWidth + 0.5, y + 0.5, 0);
100 for (int x = 0; x < kContextWidth; x += 2) {
102 glVertex3f(x + 0.5, 0.5, 0);
103 glVertex3f(x + 0.5, kContextHeight + 0.5, 0);
108 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
111 glMatrixMode(GL_PROJECTION);
114 glStencilFunc(GL_NOTEQUAL, 0x01, 0x01);
115 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
116 glEnable( GL_DEPTH_TEST);
117 glEnable(GL_CULL_FACE);
118 glEnable(GL_LIGHTING);
119 glEnable(GL_TEXTURE_2D);
124 const std::string StereoModeName(StereoMode mode)
133 case stereoHorizontalInterlaced:
134 return "Horizontal interlacing";
136 case stereoVerticalInterlaced:
137 return "Vertical interlacing";
139 case stereoHorizontalSplit:
140 return "Horizontal split";
142 case stereoVerticalSplit:
143 return "Vertical split";