6 extern int kContextWidth;
7 extern int kContextHeight;
9 bool CanInitStereo(StereoMode mode) {
10 GLint stencilbits = 0;
19 case stereoHorizontalInterlaced:
20 case stereoVerticalInterlaced:
21 glGetIntegerv(GL_STENCIL_BITS, &stencilbits);
22 if ( stencilbits < 1 ) {
23 fprintf(stderr, "Failed to get a stencil buffer, interlaced stereo not available.\n");
26 fprintf(stderr, "Stencil buffer has %i bits, good.\n", stencilbits);
36 void InitStereo(StereoMode mode) {
39 glDisable( GL_STENCIL_TEST);
42 glDisable( GL_STENCIL_TEST);
44 case stereoHorizontalInterlaced:
45 case stereoVerticalInterlaced:
47 fprintf(stderr, "Screen width is %i, height is %i\n", kContextWidth, kContextHeight);
49 glEnable( GL_STENCIL_TEST);
51 glClear( GL_STENCIL_BUFFER_BIT );
52 glStencilFunc(GL_ALWAYS, 0x1, 0x1);
53 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
56 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
57 glPixelStorei(GL_UNPACK_ROW_LENGTH, 3);
58 glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
59 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
60 glColorMask( 1.0, 1.0, 1.0, 1.0 );
61 char stencil[] = {64,127,255};
63 glViewport(0,0, kContextWidth, kContextHeight);
64 glMatrixMode(GL_PROJECTION);
66 glOrtho((GLdouble)0, (GLdouble)kContextWidth, (GLdouble)kContextHeight, 0, -1, 1);
67 glMatrixMode(GL_MODELVIEW);
70 for(int y=0;y<kContextHeight;y+=2) {
72 for(int x=0;x<kContextWidth;x++) {
74 glDrawPixels(1, 1, GL_RGB, GL_UNSIGNED_BYTE, &stencil);
78 glStencilFunc(GL_NOTEQUAL, 0x01, 0x01);
79 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
81 // Something gets screwed up due to the changes above
83 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
84 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
85 glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
86 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
91 const char* StereoModeName(StereoMode mode) {
93 case stereoNone: return "None"; break;
94 case stereoAnaglyph: return "Anaglyph"; break;
95 case stereoHorizontalInterlaced: return "Horizontal interlacing"; break;
96 case stereoVerticalInterlaced: return "Vertical interlacing"; break;
97 case stereoHorizontalSplit: return "Horizontal split"; break;
98 case stereoVerticalSplit: return "Vertical split"; break;
99 case stereoOpenGL: return "OpenGL"; break;
100 default: return "(error)"; break;