home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / stereo / GL_5.2 / grid.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.1 KB  |  129 lines

  1. /*
  2.  * Copyright (C) 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *                                grid.c
  19.  *
  20.  *     Program that draws a test pattern for stereo; the left eye's image
  21.  *   is blue, and has the text 'left' to the left.  The right eye's image
  22.  *   is red, and says 'right' to the right.  If stereo is working properly,
  23.  *   the grids should overlap exactly, creating a purplish image through 
  24.  *   both eyes, and there should be minimal leaking from one eye to the other.
  25.  */
  26.  
  27. #include <string.h>
  28.  
  29. #include "stereo.h"
  30.  
  31. /*
  32.  * If, for some reason, stereo.h and libstereo.a aren't available, the
  33.  * following #define's may be used instead of the previous #include:
  34.  * #define YMAXSTEREO 491
  35.  * #define YOFFSET 532
  36.  *
  37.  * I am anticipating the definitions potentially changing in the
  38.  * future (due to incompatible screen formats, for example), and want
  39.  * to minimize the number of changes I'll have to make.
  40.  */
  41.  
  42. void
  43. draw_grid()
  44. {
  45.     int i;
  46.  
  47.     ortho2(0, XMAXSCREEN+0.5, 0, YMAXSTEREO+0.5);
  48.  
  49.     recti(0, 0, XMAXSCREEN, YMAXSTEREO);
  50.  
  51.     translate(XMAXSCREEN/2.0, YMAXSTEREO/2.0, 0.0);
  52.     scale(2.0, 1.0, 1.0);
  53.  
  54.     for (i = -128; i<=128; i+=32)
  55.     {
  56.         move2i(i, -128); draw2i(i, 128);
  57.     }
  58.  
  59.     for (i = -128; i<=128; i+=32)
  60.     {
  61.         move2i(-128, i); draw2i(128, i);
  62.     }
  63.  
  64.     circ(0.0, 0.0, YMAXSTEREO/2.0);
  65.     circ(0.0, 0.0, 8.0);
  66. }
  67.  
  68. void
  69. draw_test()
  70. {
  71.     viewport(0, XMAXSCREEN, 0, YMAXSCREEN);
  72.     color(BLACK); clear();
  73.  
  74.     color(RED);
  75.     viewport(0, XMAXSCREEN, 0, YMAXSTEREO);
  76.     draw_grid();
  77.     cmov2i(180, 0);
  78.     charstr("right");
  79.  
  80.     color(BLUE);
  81.     viewport(0, XMAXSCREEN, YOFFSET, YOFFSET+YMAXSTEREO);
  82.     draw_grid();
  83.     cmov2i(-200, 0);
  84.     charstr("left");
  85. }
  86.  
  87. main(int argc, char **argv)
  88. {
  89.     long dev; short val;
  90.  
  91.     prefposition(0, getgdesc(GD_XPMAX), 0, getgdesc(GD_YPMAX));
  92.  
  93.     {    /* Open window with name of executable */
  94.         char *t;
  95.         winopen((t=strrchr(argv[0], '/')) != NULL ? t+1 : argv[0]);
  96.     }
  97.  
  98.     stereo_on(STR_RECT);    /* From libstereo.a */
  99.     /* If libstereo.a isn't available, use:
  100.      * if (getgdesc(GD_STEREO)) setmonitor(STR_RECT);
  101.      */
  102.  
  103.     qdevice(ESCKEY);        /* press "Esc" key to exit */
  104.     qdevice(LEFTMOUSE);    /* Keep window manager from moving window */
  105.     qdevice(MIDDLEMOUSE);    /* Keep window manager from moving window */
  106.     qdevice(WINQUIT);
  107.  
  108.     draw_test();
  109.  
  110.     while (1) 
  111.     {
  112.         switch (dev=qread(&val))
  113.         {
  114.         case ESCKEY:
  115.             if (val) break;
  116.         case WINQUIT:
  117.             stereo_off();
  118.             /*
  119.              * If libstereo.a isn't around, use:
  120.              * if (getgdesc(GD_STEREO)) setmonitor(monitor);
  121.              */
  122.             exit(0);
  123.         case REDRAW:
  124.             draw_test();
  125.             break;
  126.         }
  127.     }
  128. }
  129.