home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / sgi / 16337 < prev    next >
Encoding:
Text File  |  1992-11-12  |  4.8 KB  |  178 lines

  1. Newsgroups: comp.sys.sgi
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!sgigate!sgi!fido!news.csd.sgi.com!martinm
  3. From: martinm@sgi.com (Martin McDonald)
  4. Subject: Re: Stereo in a window on a RealityEngine
  5. Message-ID: <1992Nov12.155346.13219@news.csd.sgi.com>
  6. Sender: news@news.csd.sgi.com (Net News CSD)
  7. Organization: Silicon Graphics, Inc., Mountain View, CA
  8. References: <17403@borg.cs.unc.edu>
  9. Distribution: usa
  10. Date: Thu, 12 Nov 1992 15:53:46 GMT
  11. Lines: 165
  12.  
  13. In article <17403@borg.cs.unc.edu> cullip@pooh.cs.unc.edu (Timothy Cullip) writes:
  14. >We have a loaner Crimson/RealityEngine that we are evaluating for
  15. >our needs. One of our needs is stereo in a window (which I've heard
  16. >it is capable of doing. Does anyone out there have a simple example
  17. >program that demonstrates this capability? If so, could I get my
  18. >nands on the source code?
  19.  
  20. try this one out. note from the header you need to change the video
  21. output format to do stereo per window. to do this you need to be 
  22. root. run /usr/gfx/setmon 960x680_108s . then run /usr/gfx/stopgfx
  23. followed up with /usr/gfx/startgfx . you will lose some screen 
  24. real estate, but you will be able to do single window stereo.
  25. this program will be found in 4Dgifts soon.
  26.  
  27. /***********************************************************************
  28. *                                                                      *
  29. *                 Stereo In Window Sample Program                      *
  30. *                                                                      *
  31. * WARNING: YOU MUST RUN  960x680_108s  VOF TO USE STEREO IN WINDOW     *
  32. *          WILL ONLY WORK ON REALITY ENGINE                            *
  33. ***********************************************************************/
  34. #include <stdio.h>
  35. #include <gl/gl.h>
  36.  
  37. #define XSIZE 640.0
  38. #define YSIZE 512.0
  39.  
  40. static Matrix idmat = { 1.0,0.0,0.0,0.0,
  41.                         0.0,1.0,0.0,0.0,
  42.                         0.0,0.0,1.0,0.0,
  43.                         0.0,0.0,0.0,1.0,
  44. };
  45.  
  46. static float mat[] = {
  47.     AMBIENT, 0.35, 0.25,  0.1,
  48.     DIFFUSE, 0.65, 0.5, 0.35,
  49.     SPECULAR, 0.0, 0.0, 0.0,
  50.     SHININESS, 0.0,
  51.     LMNULL
  52. };
  53.  
  54. static float lig[] = {
  55.     AMBIENT, 0.0, 0.0, 0.0,
  56.     LCOLOR, 1.0, 1.0, 1.0,
  57.     POSITION, 0.0, 0.0, -1.0, 0.0,
  58.     LMNULL
  59. };
  60.  
  61. static float mod[] = {
  62.     AMBIENT, 0.3,  0.3, 0.3,
  63.     LOCALVIEWER, 0.0,
  64.     LMNULL
  65. };
  66.  
  67. static float ang = 0.0;
  68.  
  69. static float v[8][3] = { -1.0,-1.0,-1.0,
  70.                           1.0,-1.0,-1.0,
  71.                           1.0, 1.0,-1.0,
  72.                          -1.0, 1.0,-1.0,
  73.                          -1.0,-1.0, 1.0,
  74.                           1.0,-1.0, 1.0,
  75.                           1.0, 1.0, 1.0,
  76.                          -1.0, 1.0, 1.0,
  77. };
  78.  
  79. static float n[6][3] = {  0.0, 0.0, 1.0,
  80.                           0.0, 0.0,-1.0,
  81.                           0.0, 1.0, 0.0,
  82.                          -1.0, 0.0, 0.0,
  83.                           0.0,-1.0, 0.0,
  84.                           1.0, 0.0, 0.0,
  85. };
  86.  
  87. static void draw_scene(long);
  88. static void draw_polyg(float *,float *,float *,float *,float *);
  89.  
  90. main()
  91. {
  92.    foreground();
  93.    prefposition(0,XSIZE-1,0,YSIZE-1);
  94.    winopen("Stereo In Window");
  95.  
  96.    RGBmode();
  97.    doublebuffer();
  98.    stereobuffer();
  99.    gconfig();
  100.  
  101.    if (!getgconfig(GC_DOUBLE) || !getgconfig(GC_STEREO)) {
  102.      fprintf(stderr,"ERROR: Could not configure doublebuffer stereo!\n");
  103.      exit(0);
  104.      }
  105.  
  106.    subpixel(TRUE);
  107.    zbuffer(TRUE);
  108.    lsetdepth(getgdesc(GD_ZMIN),getgdesc(GD_ZMAX));
  109.  
  110.    lmdef(DEFMATERIAL, 1, 0, mat);
  111.    lmdef(DEFLIGHT,    1, 0, lig);
  112.    lmdef(DEFLMODEL,   1, 0, mod);
  113.  
  114.    lmbind(MATERIAL, 1);
  115.    lmbind(LMODEL,   1);
  116.  
  117.    mmode(MPROJECTION);
  118.    perspective(450,XSIZE/YSIZE,0.1,100.0);
  119.    mmode(MVIEWING);
  120.    loadmatrix(idmat);
  121.    lmbind(LIGHT1,1);
  122.  
  123.    while (1)  {
  124.      leftbuffer(TRUE);
  125.      rightbuffer(FALSE);
  126.      draw_scene(0);
  127.  
  128.      leftbuffer(FALSE);
  129.      rightbuffer(TRUE);
  130.      draw_scene(1);
  131.  
  132.      swapbuffers();
  133.      }
  134. }
  135.  
  136. static void draw_scene(long flag)
  137. {
  138.    czclear(0,getgdesc(GD_ZMAX));
  139.  
  140.    pushmatrix();
  141.  
  142.    /* left/right eye */
  143.    if (flag == 0)
  144.         lookat(5.0,-1.0,0.0,0.0,0.0,0.0,0);
  145.    else lookat(5.0, 1.0,0.0,0.0,0.0,0.0,0);
  146.  
  147.    ang+=2.0;
  148.    rotate(ang,'y');
  149.    rotate(ang/2.7,'z');
  150.  
  151.    cpack(0xffffffff);
  152.    draw_polyg(v[0],v[1],v[2],v[3],n[0]);
  153.    draw_polyg(v[4],v[5],v[6],v[7],n[1]);
  154.    draw_polyg(v[0],v[1],v[5],v[4],n[2]);
  155.    draw_polyg(v[1],v[2],v[6],v[5],n[3]);
  156.    draw_polyg(v[2],v[3],v[7],v[6],n[4]);
  157.    draw_polyg(v[3],v[0],v[4],v[7],n[5]);
  158.  
  159.    popmatrix();
  160. }
  161.  
  162. static void draw_polyg(float *v0,float *v1,float *v2,float *v3,float *n)
  163. {
  164.    bgnpolygon();
  165.    n3f(n);
  166.    v3f(v0);
  167.    v3f(v1);
  168.    v3f(v2);
  169.    v3f(v3);
  170.    endpolygon();
  171. }
  172.  
  173. --
  174. Martin McDonald       Up there they got a lot of sand, but down here we got a
  175. hot crustacean band. each little snail he know how to wail.  that's why it's 
  176. hotter under the water under the sea.
  177.                                                          -sebastian
  178.