From: martinm@sgi.com (Martin McDonald)
Subject: Re: Stereo in a window on a RealityEngine
Organization: Silicon Graphics, Inc., Mountain View, CA
Distribution: usa
Date: Thu, 12 Nov 1992 15:53:46 GMT

In article <17403@borg.cs.unc.edu> cullip@pooh.cs.unc.edu (Timothy Cullip) writes:
>We have a loaner Crimson/RealityEngine that we are evaluating for
>our needs. One of our needs is stereo in a window (which I've heard
>it is capable of doing. Does anyone out there have a simple example
>program that demonstrates this capability? If so, could I get my
>nands on the source code?

try this one out. note from the header you need to change the video
output format to do stereo per window. to do this you need to be 
root. run /usr/gfx/setmon 960x680_108s . then run /usr/gfx/stopgfx
followed up with /usr/gfx/startgfx . you will lose some screen 
real estate, but you will be able to do single window stereo.
this program will be found in 4Dgifts soon.

/***********************************************************************
*                                                                      *
*                 Stereo In Window Sample Program                      *
*                                                                      *
* WARNING: YOU MUST RUN  960x680_108s  VOF TO USE STEREO IN WINDOW     *
*          WILL ONLY WORK ON REALITY ENGINE                            *
***********************************************************************/
#include <stdio.h>
#include <gl/gl.h>

#define XSIZE 640.0
#define YSIZE 512.0

static Matrix idmat = { 1.0,0.0,0.0,0.0,
                        0.0,1.0,0.0,0.0,
                        0.0,0.0,1.0,0.0,
                        0.0,0.0,0.0,1.0,
};

static float mat[] = {
    AMBIENT, 0.35, 0.25,  0.1,
    DIFFUSE, 0.65, 0.5, 0.35,
    SPECULAR, 0.0, 0.0, 0.0,
    SHININESS, 0.0,
    LMNULL
};

static float lig[] = {
    AMBIENT, 0.0, 0.0, 0.0,
    LCOLOR, 1.0, 1.0, 1.0,
    POSITION, 0.0, 0.0, -1.0, 0.0,
    LMNULL
};

static float mod[] = {
    AMBIENT, 0.3,  0.3, 0.3,
    LOCALVIEWER, 0.0,
    LMNULL
};

static float ang = 0.0;

static float v[8][3] = { -1.0,-1.0,-1.0,
                          1.0,-1.0,-1.0,
                          1.0, 1.0,-1.0,
                         -1.0, 1.0,-1.0,
                         -1.0,-1.0, 1.0,
                          1.0,-1.0, 1.0,
                          1.0, 1.0, 1.0,
                         -1.0, 1.0, 1.0,
};

static float n[6][3] = {  0.0, 0.0, 1.0,
                          0.0, 0.0,-1.0,
                          0.0, 1.0, 0.0,
                         -1.0, 0.0, 0.0,
                          0.0,-1.0, 0.0,
                          1.0, 0.0, 0.0,
};

static void draw_scene(long);
static void draw_polyg(float *,float *,float *,float *,float *);

main()
{
   foreground();
   prefposition(0,XSIZE-1,0,YSIZE-1);
   winopen("Stereo In Window");

   RGBmode();
   doublebuffer();
   stereobuffer();
   gconfig();

   if (!getgconfig(GC_DOUBLE) || !getgconfig(GC_STEREO)) {
     fprintf(stderr,"ERROR: Could not configure doublebuffer stereo!\n");
     exit(0);
     }

   subpixel(TRUE);
   zbuffer(TRUE);
   lsetdepth(getgdesc(GD_ZMIN),getgdesc(GD_ZMAX));

   lmdef(DEFMATERIAL, 1, 0, mat);
   lmdef(DEFLIGHT,    1, 0, lig);
   lmdef(DEFLMODEL,   1, 0, mod);

   lmbind(MATERIAL, 1);
   lmbind(LMODEL,   1);

   mmode(MPROJECTION);
   perspective(450,XSIZE/YSIZE,0.1,100.0);
   mmode(MVIEWING);
   loadmatrix(idmat);
   lmbind(LIGHT1,1);

   while (1)  {
     leftbuffer(TRUE);
     rightbuffer(FALSE);
     draw_scene(0);

     leftbuffer(FALSE);
     rightbuffer(TRUE);
     draw_scene(1);

     swapbuffers();
     }
}

static void draw_scene(long flag)
{
   czclear(0,getgdesc(GD_ZMAX));

   pushmatrix();

   /* left/right eye */
   if (flag == 0)
        lookat(5.0,-1.0,0.0,0.0,0.0,0.0,0);
   else lookat(5.0, 1.0,0.0,0.0,0.0,0.0,0);

   ang+=2.0;
   rotate(ang,'y');
   rotate(ang/2.7,'z');

   cpack(0xffffffff);
   draw_polyg(v[0],v[1],v[2],v[3],n[0]);
   draw_polyg(v[4],v[5],v[6],v[7],n[1]);
   draw_polyg(v[0],v[1],v[5],v[4],n[2]);
   draw_polyg(v[1],v[2],v[6],v[5],n[3]);
   draw_polyg(v[2],v[3],v[7],v[6],n[4]);
   draw_polyg(v[3],v[0],v[4],v[7],n[5]);

   popmatrix();
}

static void draw_polyg(float *v0,float *v1,float *v2,float *v3,float *n)
{
   bgnpolygon();
   n3f(n);
   v3f(v0);
   v3f(v1);
   v3f(v2);
   v3f(v3);
   endpolygon();
}

--
Martin McDonald       Up there they got a lot of sand, but down here we got a
hot crustacean band. each little snail he know how to wail.  that's why it's 
hotter under the water under the sea.
                                                         -sebastian
Newsgroups: comp.sys.sgi