home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / 3d / irit / grapdrvs / xgldraw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-20  |  21.2 KB  |  638 lines

  1. /*****************************************************************************
  2. *   An SGI GL low level drawing routines.                             *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.1, June 1993.  *
  5. *****************************************************************************/
  6.  
  7. #include <gl/gl.h>
  8. #include <gl/device.h>
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <math.h>
  13. #include <ctype.h>
  14. #include "irit_sm.h"
  15. #include "attribut.h"
  16. #include "genmat.h"
  17. #include "cagd_lib.h"
  18. #include "symb_lib.h"
  19. #include "xgldrvs.h"
  20. #include "iritgrap.h"
  21.  
  22. long
  23.     ViewWinID = 0,
  24.     ViewWinWidth = 100,
  25.     ViewWinWidth2 = 50,
  26.     ViewWinHeight = 100,
  27.     ViewWinHeight2 = 50,
  28.     ViewWinLow = 0,
  29.     ViewWinLeft = 0;
  30.  
  31. static short Colors[IG_MAX_COLOR + 1][3] =
  32. {
  33.     { 0,   0,   0   },  /* 0. BLACK */
  34.     { 0,   0,   170 },  /* 1. BLUE */
  35.     { 0,   170, 0   },  /* 2. GREEN */
  36.     { 0,   170, 170 },  /* 3. CYAN */
  37.     { 170, 0,   0   },  /* 4. RED */
  38.     { 170, 0,   170 },  /* 5. MAGENTA */
  39.     { 170, 170, 0   },  /* 6. BROWN */
  40.     { 170, 170, 170 },  /* 7. LIGHTGREY */
  41.     { 85,  85,  85  },  /* 8. DARKGRAY */
  42.     { 85,  85,  255 },  /* 9. LIGHTBLUE */
  43.     { 85,  255, 85  },  /* 10. LIGHTGREEN */
  44.     { 85,  255, 255 },  /* 11. LIGHTCYAN */
  45.     { 255, 85,  85  },  /* 12. LIGHTRED */
  46.     { 255, 85,  255 },  /* 13. LIGHTMAGENTA */
  47.     { 255, 255, 85  },  /* 14. YELLOW */
  48.     { 255, 255, 255 }   /* 15. WHITE */
  49. };
  50.  
  51. static void SetColorIndex(int c);
  52. static void SetColorRGB(int Color[3]);
  53. static void SetParamViewWindow(void);
  54. static void ClearViewArea(void);
  55.  
  56. /*****************************************************************************
  57. * DESCRIPTION:                                                               M
  58. * Draw a single Point/Vector object using current modes and transformations. M
  59. *                                                                            *
  60. * PARAMETERS:                                                                M
  61. *   PObj:     A point/vector object to draw.                                 M
  62. *                                                                            *
  63. * RETURN VALUE:                                                              M
  64. *   void                                                                     M
  65. *                                                                            *
  66. * KEYWORDS:                                                                  M
  67. *   IGDrawPtVec                                                              M
  68. *****************************************************************************/
  69. void IGDrawPtVec(IPObjectStruct *PObj)
  70. {
  71.     int i;
  72.     PointType Ends[6], Zero;
  73.     RealType
  74.     *Pt = PObj -> U.Pt;
  75.  
  76.     for (i = 0; i < 6; i++)
  77.     PT_COPY(Ends[i], Pt);
  78.  
  79.     Ends[0][0] -= IG_POINT_WIDTH;
  80.     Ends[1][0] += IG_POINT_WIDTH;
  81.     Ends[2][1] -= IG_POINT_WIDTH;
  82.     Ends[3][1] += IG_POINT_WIDTH;
  83.     Ends[4][2] -= IG_POINT_WIDTH;
  84.     Ends[5][2] += IG_POINT_WIDTH;
  85.  
  86.     for (i = 0; i < 6; i += 2) {
  87.     bgnline();
  88.     v3d(Ends[i]);
  89.     v3d(Ends[i+1]);
  90.     endline();
  91.     }
  92.  
  93.     if (IP_IS_VEC_OBJ(PObj)) {
  94.     bgnline();
  95.     v3d(Pt);
  96.     Zero[0] = Zero[1] = Zero[2] = 0.0;
  97.     v3d(Zero);
  98.     endline();
  99.     }
  100. }
  101.  
  102. /*****************************************************************************
  103. * DESCRIPTION:                                                               M
  104. * Draw a single Poly object using current modes and transformations.         M
  105. *                                                                            *
  106. * PARAMETERS:                                                                M
  107. *   PObj:     A poly object to draw.                                         M
  108. *                                                                            *
  109. * RETURN VALUE:                                                              M
  110. *   void                                                                     M
  111. *                                                                            *
  112. * KEYWORDS:                                                                  M
  113. *   IGDrawPoly                                                               M
  114. *****************************************************************************/
  115. void IGDrawPoly(IPObjectStruct *PObj)
  116. {
  117.     IPVertexStruct *V;
  118.     IPPolygonStruct
  119.     *Pl = PObj -> U.Pl;
  120.  
  121.     if (IP_IS_POLYLINE_OBJ(PObj)) {
  122.     for (; Pl != NULL; Pl = Pl -> Pnext) {
  123.         bgnline();
  124.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext)
  125.             v3d(V -> Coord);
  126.         endline();
  127.     }
  128.     }
  129.     else if (IP_IS_POINTLIST_OBJ(PObj)) {
  130.     for (; Pl != NULL; Pl = Pl -> Pnext) {
  131.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext) {
  132.         int i;
  133.         PointType Ends[6];
  134.         RealType
  135.             *Pt = V -> Coord;
  136.  
  137.         for (i = 0; i < 6; i++)
  138.             PT_COPY(Ends[i], Pt);
  139.  
  140.         Ends[0][0] -= IG_POINT_WIDTH;
  141.         Ends[1][0] += IG_POINT_WIDTH;
  142.         Ends[2][1] -= IG_POINT_WIDTH;
  143.         Ends[3][1] += IG_POINT_WIDTH;
  144.         Ends[4][2] -= IG_POINT_WIDTH;
  145.         Ends[5][2] += IG_POINT_WIDTH;
  146.  
  147.         for (i = 0; i < 6; i += 2) {
  148.             bgnline();
  149.             v3d(Ends[i]);
  150.             v3d(Ends[i+1]);
  151.             endline();
  152.         }
  153.         }
  154.     }
  155.     }
  156.     else if (IP_IS_POLYGON_OBJ(PObj)) {
  157.     int i, j,
  158.         NumOfVertices = 0;
  159.     PointType PNormal, VNormal;
  160.  
  161.     for (; Pl != NULL; Pl = Pl -> Pnext) {
  162.         if (IGGlblBackFaceCull) {
  163.             RealType P1[3], P2[3];
  164.  
  165.         MatMultVecby4by4(P1, Pl -> PVertex -> Coord,
  166.                  IritPrsrViewMat);
  167.         PT_ADD(PNormal, Pl -> PVertex -> Coord, Pl -> Plane);
  168.         MatMultVecby4by4(P2, PNormal, IritPrsrViewMat);
  169.         if (P2[2] - P1[2] > 0.0)
  170.             continue;
  171.         }
  172.  
  173.         if (IGGlblDrawPNormal) {
  174.         NumOfVertices = 0;
  175.         PNormal[0] = PNormal[1] = PNormal[2] = 0.0;
  176.         }
  177.  
  178.         if (IGGlblDrawSolid) {
  179.         bgnpolygon();
  180.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext) {
  181.             float n[3];
  182.  
  183.             n[0] = V -> Normal[0];
  184.             n[1] = V -> Normal[1];
  185.             n[2] = V -> Normal[2];
  186.             n3f(n);
  187.             v3d(V -> Coord);
  188.  
  189.             if (IGGlblDrawPNormal) {
  190.             for (j = 0; j < 3; j++)
  191.                 PNormal[j] += V -> Coord[j];
  192.             NumOfVertices++;
  193.             }
  194.         }
  195.         endpolygon();
  196.         }
  197.         else {
  198.         bgnline();
  199.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext) {
  200.             v3d(V -> Coord);
  201.             if (IP_IS_INTERNAL_VRTX(V) && !IGGlblDrawInternal) {
  202.             endline();
  203.             bgnline();
  204.             }
  205.  
  206.             if (IGGlblDrawPNormal) {
  207.             for (j = 0; j < 3; j++)
  208.                 PNormal[j] += V -> Coord[j];
  209.             NumOfVertices++;
  210.             }
  211.         }
  212.         v3d(Pl -> PVertex -> Coord);
  213.         endline();
  214.         }
  215.  
  216.         if (IGGlblDrawPNormal && IP_HAS_PLANE_POLY(Pl)) {
  217.         bgnline();
  218.         for (i = 0; i < 3; i++)
  219.             PNormal[i] /= NumOfVertices;
  220.         v3d(PNormal);
  221.         for (i = 0; i < 3; i++)
  222.             PNormal[i] += Pl -> Plane[i] * IGGlblNormalLen;
  223.         v3d(PNormal);
  224.         endline();
  225.         }
  226.  
  227.         if (IGGlblDrawVNormal) {
  228.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext) {
  229.             if (IP_HAS_NORMAL_VRTX(V)) {
  230.             for (j = 0; j < 3; j++)
  231.                 VNormal[j] = V -> Coord[j] +
  232.                          V -> Normal[j] * IGGlblNormalLen;
  233.             bgnline();
  234.             v3d(V ->Coord);
  235.             v3d(VNormal);
  236.             endline();
  237.             }
  238.         }
  239.         }
  240.     }
  241.     }
  242. }
  243.  
  244. /*****************************************************************************
  245. * DESCRIPTION:                                                               M
  246. * Sets the color of an object according to its color/rgb attributes.         M
  247. *   If object has an RGB attribute it will be used. Otherwise, if the object M
  248. * has a COLOR attribute it will use. Otherwise, WHITE will be used.         M
  249. *                                                                            *
  250. * PARAMETERS:                                                                M
  251. *   PObj:      To set the drawing color to its color.                        M
  252. *                                                                            *
  253. * RETURN VALUE:                                                              M
  254. *   void                                                                     M
  255. *                                                                            *
  256. * KEYWORDS:                                                                  M
  257. *   IGSetColorObj                                                            M
  258. *****************************************************************************/
  259. void IGSetColorObj(IPObjectStruct *PObj)
  260. {
  261.     int c, Color[3];
  262.  
  263.     if (AttrGetObjectRGBColor(PObj, &Color[0], &Color[1], &Color[2])) {
  264.     SetColorRGB(Color);
  265.     }
  266.     else if ((c = AttrGetObjectColor(PObj)) != IP_ATTR_NO_COLOR) {
  267.     SetColorIndex(c);
  268.     }
  269.     else {
  270.     /* Use white as default color: */
  271.     SetColorIndex(IG_IRIT_WHITE);
  272.     }
  273. }
  274.  
  275. /*****************************************************************************
  276. * DESCRIPTION:                                                               M
  277. * Sets the line width to draw the given object, in pixels.             M
  278. *                                                                            *
  279. * PARAMETERS:                                                                M
  280. *   Width:    In pixels of lines to draw with.                               M
  281. *                                                                            *
  282. * RETURN VALUE:                                                              M
  283. *   void                                                                     M
  284. *                                                                            *
  285. * KEYWORDS:                                                                  M
  286. *   IGSetWidthObj                                                            M
  287. *****************************************************************************/
  288. void IGSetWidthObj(int Width)
  289. {
  290.     linewidth(Width);
  291. }
  292.  
  293. /*****************************************************************************
  294. * DESCRIPTION:                                                               *
  295. * Sets the color according to the given color index.                     *
  296. *                                                                            *
  297. * PARAMETERS:                                                                *
  298. *   color:     Index of color to use. Must be between 0 and IG_MAX_COLOR.    *
  299. *                                                                            *
  300. * RETURN VALUE:                                                              *
  301. *   void                                                                     *
  302. *****************************************************************************/
  303. static void SetColorIndex(int color)
  304. {
  305.     int Color[3];
  306.  
  307.     if (color < 0 || color > IG_MAX_COLOR)
  308.         color = IG_IRIT_WHITE;
  309.  
  310.     Color[0] = Colors[color][0];
  311.     Color[1] = Colors[color][1];
  312.     Color[2] = Colors[color][2];
  313.  
  314.     SetColorRGB(Color);
  315. }
  316.  
  317. /*****************************************************************************
  318. * DESCRIPTION:                                                               *
  319. * Sets the color according to the given RGB values.                 *
  320. *                                                                            *
  321. * PARAMETERS:                                                                *
  322. *   Color:      An RGB vector of integer values between 0 and 255.           *
  323. *                                                                            *
  324. * RETURN VALUE:                                                              *
  325. *   void                                                                     *
  326. *****************************************************************************/
  327. static void SetColorRGB(int Color[3])
  328. {
  329.     int i;
  330.     static float
  331.     Ambient = 0.25,
  332.     Diffuse = 0.75,
  333.     Specular = 1.0;
  334.     static float
  335.     Material[] = {
  336.         AMBIENT,  0.25, 0.25, 0.25,
  337.         DIFFUSE,  0.75, 0.75, 0.75,
  338.         SPECULAR, 1.00, 1.00, 1.00,
  339.         SHININESS, 50,
  340.         LMNULL
  341.     };
  342.  
  343.     c3i((long *) Color);
  344.     if (IGGlblDepthCue)
  345.     lRGBrange(0, 0, 0, Color[0], Color[1], Color[2], 0x0, 0x7fffff);
  346.  
  347.     /* Prepare material structure in this color and select it. */
  348.     for (i = 0; i < 3; i++) {
  349.     Material[1 + i] = Ambient * Color[i] / 255.0;
  350.     Material[5 + i] = Diffuse * Color[i] / 255.0;
  351.     Material[9 + i] = Specular * Color[i] / 255.0;
  352.     }
  353.     lmdef(DEFMATERIAL, 1, sizeof(Material) / sizeof(float), Material);
  354. }
  355.  
  356. /*****************************************************************************
  357. * DESCRIPTION:                                                               *
  358. * Clears the viewing area.                             *
  359. *                                                                            *
  360. * PARAMETERS:                                                                *
  361. *   None                                                                     *
  362. *                                                                            *
  363. * RETURN VALUE:                                                              *
  364. *   void                                                                     *
  365. *****************************************************************************/
  366. static void ClearViewArea(void)
  367. {
  368.     SetColorRGB(IGGlblBackGroundColor);
  369.     clear();
  370.     mmode(MVIEWING);
  371.  
  372.     if (APX_EQ(IGGlblZMinClip, IGGlblZMaxClip))
  373.         IGGlblZMaxClip += EPSILON;
  374.     ortho(-1.0, 1.0, -1.0, 1.0, IGGlblZMinClip, IGGlblZMaxClip);
  375.  
  376.     if (winget() == ViewWinID) {
  377.     /* activate zbuffer only if we are in solid drawing mode. */
  378.     if (IGGlblDrawSolid) {
  379.         /* Define necessary staff for Lighting. */
  380.         lmbind(MATERIAL, 1);
  381.         lmbind(LMODEL, 1);
  382.         lmbind(LIGHT1, 1);
  383.         lmbind(LIGHT2, 2);
  384.  
  385.         zbuffer(TRUE);
  386.         zclear();
  387.     }
  388.     else {
  389.         zbuffer(FALSE);
  390.     }
  391.     }
  392. }
  393.  
  394. /*****************************************************************************
  395. * DESCRIPTION:                                                               *
  396. * Sets up the parameters of the view window.                     *
  397. *                                                                            *
  398. * PARAMETERS:                                                                *
  399. *   None                                                             *
  400. *                                                                            *
  401. * RETURN VALUE:                                                              *
  402. *   void                                                                     *
  403. *                                                                            *
  404. * KEYWORDS:                                                                  *
  405. *   SetViewWindow                                                            *
  406. *****************************************************************************/
  407. static void SetParamViewWindow(void)
  408. {
  409.     static int
  410.         OldDoDoubleBuffer = -1,
  411.     OldDepthCue = -1,
  412.     OldAntiAliasing = -1;
  413.     int Modified = FALSE;
  414.  
  415.     winset(ViewWinID);
  416.  
  417.     if (OldDoDoubleBuffer != IGGlblDoDoubleBuffer) {
  418.     if (IGGlblDoDoubleBuffer)
  419.         doublebuffer();
  420.     else
  421.         singlebuffer();
  422.     gconfig();
  423.  
  424.     Modified = TRUE;
  425.     OldDoDoubleBuffer = IGGlblDoDoubleBuffer;
  426.     }
  427.  
  428.     if (OldDepthCue != IGGlblDepthCue) {
  429.     if (IGGlblDepthCue) {
  430. #        ifndef _AIX
  431.             glcompat(GLC_ZRANGEMAP, 1);
  432. #        endif /* _AIX */
  433.         lRGBrange(0, 0, 0, 255, 255, 255, 0x0, 0x7fffff);
  434.         depthcue(IGGlblDepthCue);
  435.     }
  436.     else
  437.         depthcue(FALSE);
  438.  
  439.     Modified = TRUE;
  440.     OldDepthCue = IGGlblDepthCue;
  441.     }
  442.  
  443.     if (OldAntiAliasing != IGGlblAntiAliasing) {
  444.     if (IGGlblAntiAliasing) {
  445.         linesmooth(SML_ON | SML_SMOOTHER);
  446. #        ifndef _AIX
  447.             if (getgdesc(GD_PNTSMOOTH_CMODE) == 0 ||
  448.             getgdesc(GD_BITS_NORM_DBL_CMODE) < 8) {
  449.         }
  450.         else {
  451.             subpixel(TRUE);
  452.             pntsmooth(SMP_ON);
  453.         }
  454. #        endif /* _AIX */
  455.     }
  456.     else
  457.         linesmooth(SML_OFF);
  458.  
  459.     Modified = TRUE;
  460.     OldAntiAliasing = IGGlblAntiAliasing;
  461.     }
  462.  
  463.     /* This is wierd. without the sleep the gl get mixed up between the two  */
  464.     /* windows. If you have any idea why, let me know...             */
  465.     if (Modified)
  466.     IritSleep(100);
  467. }
  468.  
  469. /*****************************************************************************
  470. * DESCRIPTION:                                                               M
  471. * Sets up a view window.                             M
  472. *                                                                            *
  473. * PARAMETERS:                                                                M
  474. *   argc, argv:   Command line.                             M
  475. *                                                                            *
  476. * RETURN VALUE:                                                              M
  477. *   void                                                                     M
  478. *                                                                            *
  479. * KEYWORDS:                                                                  M
  480. *   SetViewWindow                                                            M
  481. *****************************************************************************/
  482. void SetViewWindow(int argc, char **argv)
  483. {
  484.     long PrefPos[4];
  485.     static int
  486.     UpdateLightPos = FALSE;
  487.     static float
  488.     Light1[] = {
  489.         AMBIENT, 0.25, 0.25, 0.25,
  490.         POSITION, 1.0, 2.0, 10.0, 0.0,
  491.         LMNULL
  492.     },
  493.     Light2[] = {
  494.         AMBIENT, 0.25, 0.25, 0.25,
  495.         POSITION, -5.0, -1.0, -10.0, 0.0,
  496.         LMNULL
  497.     };
  498.  
  499.     if (!UpdateLightPos) {
  500.     int i;
  501.  
  502.     for (i = 0; i < 4; i++)
  503.         Light1[i + 5] = IGGlblLightSrcPos[i];
  504.  
  505.     UpdateLightPos = TRUE;
  506.     }
  507.  
  508. #ifndef _AIX
  509.     foreground();
  510. #endif
  511.  
  512.     if (sscanf(IGGlblViewPrefPos, "%ld,%ld,%ld,%ld",
  513.            &PrefPos[0], &PrefPos[1], &PrefPos[2], &PrefPos[3]) == 4)
  514.     prefposition(PrefPos[0], PrefPos[1], PrefPos[2], PrefPos[3]);
  515.     else if (sscanf(IGGlblViewPrefPos, "%ld,%ld",
  516.             &PrefPos[0], &PrefPos[1]) == 2)
  517.     prefsize(PrefPos[0], PrefPos[1]);
  518.     winopen("Poly3dView");
  519.     wintitle("xGLdrvs");
  520.     ViewWinID = winget();
  521.  
  522.     RGBmode();
  523.     SetParamViewWindow();
  524.  
  525.     getorigin(&ViewWinLeft, &ViewWinLow);
  526.     getsize(&ViewWinWidth, &ViewWinHeight);
  527.     ViewWinWidth2 = ViewWinWidth / 2;
  528.     ViewWinHeight2 = ViewWinHeight / 2;
  529.     
  530.     concave(TRUE);
  531.  
  532.     /* Define necessary staff for Lighting. */
  533.     lmdef(DEFMATERIAL, 1, 0, NULL);
  534.     lmdef(DEFLMODEL, 1, 0, NULL);
  535.     lmdef(DEFLIGHT, 1, sizeof(Light1) / sizeof(float), Light1);
  536.     lmdef(DEFLIGHT, 2, sizeof(Light2) / sizeof(float), Light2);
  537.  
  538.     ClearViewArea();
  539.     if (IGGlblDoDoubleBuffer)
  540.     swapbuffers();
  541. }
  542.  
  543. /*****************************************************************************
  544. * DESCRIPTION:                                                               M
  545. * Redraws the view window.                             M
  546. *                                                                            *
  547. * PARAMETERS:                                                                M
  548. *   None                                                                     M
  549. *                                                                            *
  550. * RETURN VALUE:                                                              M
  551. *   void                                                                     M
  552. *                                                                            *
  553. * KEYWORDS:                                                                  M
  554. *   IGRedrawViewWindow                                                       M
  555. *****************************************************************************/
  556. void IGRedrawViewWindow(void)
  557. {
  558.     IPObjectStruct *PObj, *MatObj;
  559.     Matrix CrntView;
  560.     int i, j;
  561.     MatrixType IritCrntView, IritView;
  562.  
  563.     SetParamViewWindow();
  564.  
  565.     ClearViewArea();
  566.  
  567.     switch (IGGlblViewMode) {         /* Update the current view. */
  568.     case IG_VIEW_ORTHOGRAPHIC:
  569.         GEN_COPY(IritView, IritPrsrViewMat, sizeof(MatrixType));
  570.         break;
  571.     case IG_VIEW_PERSPECTIVE:
  572.         MatMultTwo4by4(IritView, IritPrsrViewMat, IritPrsrPrspMat);
  573.         break;
  574.     }
  575.  
  576.     for (PObj = IGGlblDisplayList; PObj != NULL; PObj = PObj -> Pnext) {
  577.     int Visible = TRUE;
  578.  
  579.     if ((MatObj = AttrGetObjectObjAttrib(PObj, "_animation_mat")) != NULL &&
  580.         IP_IS_MAT_OBJ(MatObj)) {
  581.         if (Visible = AttrGetObjectIntAttrib(PObj, "_isvisible")) {
  582.         MatMultTwo4by4(IritCrntView,
  583.                    *MatObj -> U.Mat, IritPrsrViewMat);
  584.         if (IGGlblViewMode == IG_VIEW_PERSPECTIVE) 
  585.             MatMultTwo4by4(IritCrntView,
  586.                    IritCrntView, IritPrsrPrspMat);
  587.         }
  588.     }
  589.     else
  590.         GEN_COPY(IritCrntView, IritView, sizeof(MatrixType));
  591.  
  592.     if (Visible) {
  593.         for (i = 0; i < 4; i++)
  594.         for (j = 0; j < 4; j++)
  595.             CrntView[i][j] = IritCrntView[i][j];
  596.         loadmatrix(CrntView);
  597.  
  598.         IGDrawObject(PObj);
  599.     }
  600.     }
  601.  
  602.     if (IGGlblDoDoubleBuffer)
  603.     swapbuffers();
  604. }
  605.  
  606. /*****************************************************************************
  607. * DESCRIPTION:                                                               M
  608. * Handles redraw of view window event.                                       M
  609. *                                                                            *
  610. * PARAMETERS:                                                                M
  611. *   None                                                                     M
  612. *                                                                            *
  613. * RETURN VALUE:                                                              M
  614. *   void                                                                     M
  615. *****************************************************************************/
  616. void IGHandleInternalEvents(void)
  617. {
  618.     Device dev;
  619.     short data;
  620.  
  621.     if (qtest()) {
  622.     if ((dev = qread(&data)) == REDRAW && data == ViewWinID) {
  623.         getorigin(&ViewWinLeft, &ViewWinLow);
  624.         getsize(&ViewWinWidth, &ViewWinHeight);
  625.         ViewWinWidth2 = ViewWinWidth / 2;
  626.         ViewWinHeight2 = ViewWinHeight / 2;
  627.         reshapeviewport();
  628.         ortho2(-0.5, ViewWinWidth - 0.5,
  629.            -0.5, ViewWinHeight - 0.5);
  630.         IGRedrawViewWindow();
  631.     }
  632.     else {
  633.         /* push it back onto the queue. */
  634.         qenter(dev, data);
  635.     }
  636.     }
  637. }
  638.