*
* Command line options:
* -info print GL implementation information
+ * -stereo use stereo enabled GLX visual
*
*/
static GLint gear1, gear2, gear3;
static GLfloat angle = 0.0;
+static GLboolean stereo = GL_FALSE; /* Enable stereo. */
+static GLfloat eyesep = 5.0; /* Eye separation. */
+static GLfloat fix_point = 40.0; /* Fixation point distance. */
+static GLfloat left, right, asp; /* Stereo frustum params. */
+
/*
*
static void
-draw(void)
+do_draw(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPopMatrix();
}
+static void
+draw(void)
+{
+ if (stereo) {
+ /* First left eye. */
+ glDrawBuffer(GL_BACK_LEFT);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(left, right, -asp, asp, 5.0, 60.0);
+
+ glMatrixMode(GL_MODELVIEW);
+
+ glPushMatrix();
+ glTranslated(+0.5 * eyesep, 0.0, 0.0);
+ do_draw();
+ glPopMatrix();
+
+ /* Then right eye. */
+ glDrawBuffer(GL_BACK_RIGHT);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-right, -left, -asp, asp, 5.0, 60.0);
+
+ glMatrixMode(GL_MODELVIEW);
+
+ glPushMatrix();
+ glTranslated(-0.5 * eyesep, 0.0, 0.0);
+ do_draw();
+ glPopMatrix();
+ } else
+ do_draw();
+}
+
/* new window size or exposure */
static void
reshape(int width, int height)
{
- GLfloat h = (GLfloat) height / (GLfloat) width;
-
glViewport(0, 0, (GLint) width, (GLint) height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
+
+ if (stereo) {
+ GLfloat w;
+
+ asp = (GLfloat) height / (GLfloat) width;
+ w = fix_point * (1.0 / 5.0);
+
+ left = -5.0 * ((w - 0.5 * eyesep) / fix_point);
+ right = 5.0 * ((w + 0.5 * eyesep) / fix_point);
+ } else {
+ GLfloat h = (GLfloat) height / (GLfloat) width;
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
+ }
+
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -40.0);
}
+
static void
int x, int y, int width, int height,
Window *winRet, GLXContext *ctxRet)
{
- int attrib[] = { GLX_RGBA,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_DOUBLEBUFFER,
- GLX_DEPTH_SIZE, 1,
- None };
+ int attribs[] = { GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DOUBLEBUFFER,
+ GLX_DEPTH_SIZE, 1,
+ None };
+ int stereoAttribs[] = { GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DOUBLEBUFFER,
+ GLX_DEPTH_SIZE, 1,
+ GLX_STEREO,
+ None };
int scrnum;
XSetWindowAttributes attr;
unsigned long mask;
scrnum = DefaultScreen( dpy );
root = RootWindow( dpy, scrnum );
- visinfo = glXChooseVisual( dpy, scrnum, attrib );
+ if (stereo)
+ visinfo = glXChooseVisual( dpy, scrnum, stereoAttribs );
+ else
+ visinfo = glXChooseVisual( dpy, scrnum, attribs );
if (!visinfo) {
- printf("Error: couldn't get an RGB, Double-buffered visual\n");
+ if (stereo) {
+ printf("Error: couldn't get an RGB, "
+ "Double-buffered, Stereo visual\n");
+ } else
+ printf("Error: couldn't get an RGB, Double-buffered visual\n");
exit(1);
}
Display *dpy;
Window win;
GLXContext ctx;
- char *dpyName = ":0";
+ char *dpyName = NULL;
GLboolean printInfo = GL_FALSE;
int i;
else if (strcmp(argv[i], "-info") == 0) {
printInfo = GL_TRUE;
}
+ else if (strcmp(argv[i], "-stereo") == 0) {
+ stereo = GL_TRUE;
+ }
+ else
+ printf("Warrning: unknown parameter: %s\n", argv[i]);
}
dpy = XOpenDisplay(dpyName);
if (!dpy) {
- printf("Error: couldn't open display %s\n", dpyName);
+ printf("Error: couldn't open display %s\n",
+ dpyName ? dpyName : getenv("DISPLAY"));
return -1;
}