2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2017 - 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);
53 void InitStereo(StereoMode mode)
59 glDisable(GL_STENCIL_TEST);
61 case stereoHorizontalInterlaced:
62 case stereoVerticalInterlaced:
63 fprintf(stderr, "Screen width is %i, height is %i\n", kContextWidth, kContextHeight);
65 // Setup stencil buffer
66 glDisable(GL_DEPTH_TEST);
67 glDisable(GL_CULL_FACE);
68 glDisable(GL_LIGHTING);
69 glDisable(GL_TEXTURE_2D);
71 glEnable(GL_STENCIL_TEST);
73 glClear(GL_STENCIL_BUFFER_BIT);
74 glStencilFunc(GL_ALWAYS, 0x1, 0x1);
75 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
78 glViewport(0, 0, kContextWidth, kContextHeight);
79 glMatrixMode(GL_PROJECTION);
82 glOrtho((GLdouble)0, (GLdouble)kContextWidth, (GLdouble)kContextHeight, 0, -1, 1);
83 glMatrixMode(GL_MODELVIEW);
86 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
87 glDisable(GL_LINE_SMOOTH);
89 // Add 0.5 to the coordinates, because OpenGL considers a pixel should be
90 // turned on when a line passes through the center of it.
91 if (mode == stereoHorizontalInterlaced) {
92 for (int y = 0; y < kContextHeight; y += 2) {
94 glVertex3f(0.5, y + 0.5, 0);
95 glVertex3f(kContextWidth + 0.5, y + 0.5, 0);
99 for (int x = 0; x < kContextWidth; x += 2) {
101 glVertex3f(x + 0.5, 0.5, 0);
102 glVertex3f(x + 0.5, kContextHeight + 0.5, 0);
107 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
110 glMatrixMode(GL_PROJECTION);
113 glStencilFunc(GL_NOTEQUAL, 0x01, 0x01);
114 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
115 glEnable(GL_DEPTH_TEST);
116 glEnable(GL_CULL_FACE);
117 glEnable(GL_LIGHTING);
118 glEnable(GL_TEXTURE_2D);
122 const std::string StereoModeName(StereoMode mode)
131 case stereoHorizontalInterlaced:
132 return "Horizontal interlacing";
134 case stereoVerticalInterlaced:
135 return "Vertical interlacing";
137 case stereoHorizontalSplit:
138 return "Horizontal split";
140 case stereoVerticalSplit:
141 return "Vertical split";