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/>.
25 extern int kContextWidth;
26 extern int kContextHeight;
28 bool CanInitStereo(StereoMode mode)
30 GLint stencilbits = 0;
39 case stereoHorizontalInterlaced:
40 case stereoVerticalInterlaced:
41 glGetIntegerv(GL_STENCIL_BITS, &stencilbits);
42 if ( stencilbits < 1 ) {
43 fprintf(stderr, "Failed to get a stencil buffer, interlaced stereo not available.\n");
46 fprintf(stderr, "Stencil buffer has %i bits, good.\n", stencilbits);
56 void InitStereo(StereoMode mode)
62 glDisable(GL_STENCIL_TEST);
64 case stereoHorizontalInterlaced:
65 case stereoVerticalInterlaced:
66 fprintf(stderr, "Screen width is %i, height is %i\n", kContextWidth, kContextHeight);
68 // Setup stencil buffer
69 glDisable( GL_DEPTH_TEST);
70 glDisable(GL_CULL_FACE);
71 glDisable(GL_LIGHTING);
72 glDisable(GL_TEXTURE_2D);
74 glEnable( GL_STENCIL_TEST);
76 glClear( GL_STENCIL_BUFFER_BIT );
77 glStencilFunc(GL_ALWAYS, 0x1, 0x1);
78 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
81 glViewport(0, 0, kContextWidth, kContextHeight);
82 glMatrixMode(GL_PROJECTION);
85 glOrtho((GLdouble)0, (GLdouble)kContextWidth, (GLdouble)kContextHeight, 0, -1, 1);
86 glMatrixMode(GL_MODELVIEW);
89 glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
90 glDisable(GL_LINE_SMOOTH);
92 // Add 0.5 to the coordinates, because OpenGL considers a pixel should be
93 // turned on when a line passes through the center of it.
94 if ( mode == stereoHorizontalInterlaced ) {
95 for (int y = 0; y < kContextHeight; y += 2) {
97 glVertex3f(0.5, y + 0.5, 0);
98 glVertex3f(kContextWidth + 0.5, y + 0.5, 0);
102 for (int x = 0; x < kContextWidth; x += 2) {
104 glVertex3f(x + 0.5, 0.5, 0);
105 glVertex3f(x + 0.5, kContextHeight + 0.5, 0);
110 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
113 glMatrixMode(GL_PROJECTION);
116 glStencilFunc(GL_NOTEQUAL, 0x01, 0x01);
117 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
118 glEnable( GL_DEPTH_TEST);
119 glEnable(GL_CULL_FACE);
120 glEnable(GL_LIGHTING);
121 glEnable(GL_TEXTURE_2D);
126 const char* StereoModeName(StereoMode mode)
135 case stereoHorizontalInterlaced:
136 return "Horizontal interlacing";
138 case stereoVerticalInterlaced:
139 return "Vertical interlacing";
141 case stereoHorizontalSplit:
142 return "Horizontal split";
144 case stereoVerticalSplit:
145 return "Vertical split";