home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 1 / CD_Magazyn_EXEC_nr_1.iso / Gry / battalion.lha / Battalion / source / tk.c < prev    next >
C/C++ Source or Header  |  1999-12-23  |  43KB  |  1,291 lines

  1. /*
  2.  * (c) Copyright 1993, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED 
  4.  * Permission to use, copy, modify, and distribute this software for 
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that 
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission. 
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  * 
  25.  * US Government Users Restricted Rights 
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  36.  */
  37.  
  38. /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
  39. /* remember to put this back into battalion.c once it is retrieved
  40.  * from the mac. This funxtion should be useful for the mac tk
  41.  * library as well as the unix one ... if the window coordinates
  42.  * match the code written for the mouse down below should be the
  43.  * same for the mac else it should work with some slight tweaking
  44.  
  45.  
  46. GLenum mouseKey(int key, GLenum mask)
  47.     {
  48.     if ((mode == DEMOMODE) && showOptions)
  49.         processKey(key, mask);
  50.     
  51.     return GL_TRUE;
  52.     }
  53. */
  54.  
  55. #include <stdio.h>
  56. #include <stdlib.h>
  57. #include <string.h>
  58. #include <X11/keysym.h>
  59.  
  60. #include "battalion.h"
  61.  
  62. #if defined(__cplusplus) || defined(c_plusplus)
  63. #define class c_class
  64. #endif
  65.  
  66.  
  67. /******************************************************************************/
  68.  
  69. static struct _WINDOWINFO
  70.     {
  71.     int x, y;
  72.     int width, height;
  73.     GLenum type;
  74.     } windInfo = { -1, -1, 100, 100, 0};
  75.     
  76. static Display *display         = 0;
  77. static XVisualInfo *visualInfo  = 0;
  78. static Window window            = 0;
  79. static int screen               = 0; 
  80. static GLXContext context       = 0;
  81.  
  82.  
  83.  
  84. static GLenum (*KeyDownFunc)(int, GLenum)           = NULL;
  85. static GLenum (*MouseDownFunc)(int, int, GLenum)    = NULL;
  86. static GLenum (*MouseUpFunc)(int, int, GLenum)      = NULL;
  87. static GLenum (*MouseMoveFunc)(int, int, GLenum)    = NULL;
  88.  
  89. static int lastEventType = -1;
  90. static Colormap colorMap;
  91.  
  92. static float colorMaps[] = {
  93.     0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 1.000000, 
  94.     0.000000, 1.000000, 0.333333, 0.776471, 0.443137, 0.556863, 
  95.     0.443137, 0.556863, 0.219608, 0.666667, 0.666667, 0.333333, 
  96.     0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333, 
  97.     0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333, 
  98.     0.666667, 0.333333, 0.039216, 0.078431, 0.117647, 0.156863, 
  99.     0.200000, 0.239216, 0.278431, 0.317647, 0.356863, 0.400000, 
  100.     0.439216, 0.478431, 0.517647, 0.556863, 0.600000, 0.639216, 
  101.     0.678431, 0.717647, 0.756863, 0.800000, 0.839216, 0.878431, 
  102.     0.917647, 0.956863, 0.000000, 0.000000, 0.000000, 0.000000, 
  103.     0.000000, 0.000000, 0.000000, 0.000000, 0.247059, 0.247059, 
  104.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  105.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  106.     0.498039, 0.498039, 0.749020, 0.749020, 0.749020, 0.749020, 
  107.     0.749020, 0.749020, 0.749020, 0.749020, 1.000000, 1.000000, 
  108.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  109.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  110.     0.000000, 0.000000, 0.247059, 0.247059, 0.247059, 0.247059, 
  111.     0.247059, 0.247059, 0.247059, 0.247059, 0.498039, 0.498039, 
  112.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  113.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  114.     0.749020, 0.749020, 1.000000, 1.000000, 1.000000, 1.000000, 
  115.     1.000000, 1.000000, 1.000000, 1.000000, 0.000000, 0.000000, 
  116.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  117.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  118.     0.247059, 0.247059, 0.498039, 0.498039, 0.498039, 0.498039, 
  119.     0.498039, 0.498039, 0.498039, 0.498039, 0.749020, 0.749020, 
  120.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  121.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  122.     1.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  123.     0.000000, 0.000000, 0.000000, 0.000000, 0.247059, 0.247059, 
  124.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  125.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  126.     0.498039, 0.498039, 0.749020, 0.749020, 0.749020, 0.749020, 
  127.     0.749020, 0.749020, 0.749020, 0.749020, 1.000000, 1.000000, 
  128.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  129.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  130.     0.000000, 0.000000, 0.247059, 0.247059, 0.247059, 0.247059, 
  131.     0.247059, 0.247059, 0.247059, 0.247059, 0.498039, 0.498039, 
  132.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  133.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  134.     0.749020, 0.749020, 1.000000, 1.000000, 1.000000, 1.000000, 
  135.     1.000000, 1.000000, 1.000000, 1.000000, 0.000000, 0.000000, 
  136.     1.000000, 1.000000, 0.000000, 0.000000, 1.000000, 1.000000, 
  137.     0.333333, 0.443137, 0.776471, 0.556863, 0.443137, 0.219608, 
  138.     0.556863, 0.666667, 0.666667, 0.333333, 0.666667, 0.333333, 
  139.     0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333, 
  140.     0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333, 
  141.     0.039216, 0.078431, 0.117647, 0.156863, 0.200000, 0.239216, 
  142.     0.278431, 0.317647, 0.356863, 0.400000, 0.439216, 0.478431, 
  143.     0.517647, 0.556863, 0.600000, 0.639216, 0.678431, 0.717647, 
  144.     0.756863, 0.800000, 0.839216, 0.878431, 0.917647, 0.956863, 
  145.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  146.     0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451, 
  147.     0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176, 
  148.     0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000, 
  149.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  150.     0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451, 
  151.     0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176, 
  152.     0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000, 
  153.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  154.     0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451, 
  155.     0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176, 
  156.     0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000, 
  157.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  158.     0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451, 
  159.     0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176, 
  160.     0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000, 
  161.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  162.     0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451, 
  163.     0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176, 
  164.     0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000, 
  165.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  166.     0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451, 
  167.     0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176, 
  168.     0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000, 
  169.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  170.     0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451, 
  171.     0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176, 
  172.     0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000, 
  173.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  174.     0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451, 
  175.     0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176, 
  176.     0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000, 
  177.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  178.     0.854902, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  179.     1.000000, 1.000000, 1.000000, 1.000000, 0.333333, 0.443137, 
  180.     0.443137, 0.219608, 0.776471, 0.556863, 0.556863, 0.666667, 
  181.     0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333, 
  182.     0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333, 
  183.     0.666667, 0.333333, 0.666667, 0.333333, 0.039216, 0.078431, 
  184.     0.117647, 0.156863, 0.200000, 0.239216, 0.278431, 0.317647, 
  185.     0.356863, 0.400000, 0.439216, 0.478431, 0.517647, 0.556863, 
  186.     0.600000, 0.639216, 0.678431, 0.717647, 0.756863, 0.800000, 
  187.     0.839216, 0.878431, 0.917647, 0.956863, 0.000000, 0.000000, 
  188.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  189.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  190.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  191.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  192.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  193.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  194.     0.000000, 0.000000, 0.247059, 0.247059, 0.247059, 0.247059, 
  195.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  196.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  197.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  198.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  199.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  200.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  201.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  202.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  203.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  204.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  205.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  206.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  207.     0.498039, 0.498039, 0.498039, 0.498039, 0.749020, 0.749020, 
  208.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  209.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  210.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  211.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  212.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  213.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  214.     0.749020, 0.749020, 1.000000, 1.000000, 1.000000, 1.000000, 
  215.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  216.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  217.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  218.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  219.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  220.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  221. };
  222.  
  223. /******************************************************************************/
  224.  
  225. void tkCloseWindow(void)
  226.     {
  227.  
  228.     if (display)
  229.         {
  230.         glFlush();
  231.         glFinish();
  232.         XDestroyWindow(display, window);
  233.         glXDestroyContext(display, context);
  234.         XFreeColormap(display, colorMap);
  235.         XFree((char *)visualInfo);
  236.         display = 0;
  237.  
  238.         KeyDownFunc     = 0;
  239.         MouseDownFunc   = 0;
  240.         MouseUpFunc     = 0;
  241.         MouseMoveFunc   = 0;
  242.  
  243.         lastEventType   = -1;
  244.         }
  245.     }
  246.  
  247. /******************************************************************************/
  248.  
  249. static GLenum DoNextEvent(void)
  250. {
  251.     XEvent current, ahead;
  252.     char buf[1000];
  253.     KeySym ks;
  254.     int key;
  255.     GLenum mask;
  256.     extern int paused;
  257.     float winClickX, winClickY;
  258.  
  259.     XNextEvent(display, ¤t);
  260.     switch (current.type) {
  261.     
  262.       case MappingNotify:
  263.         XRefreshKeyboardMapping((XMappingEvent *)¤t);
  264.         lastEventType = MappingNotify;
  265.  
  266.         return GL_FALSE;
  267.  
  268.       case UnmapNotify:
  269.         paused = 1;
  270.         return GL_FALSE;
  271.  
  272.       case Expose:
  273.         while (XEventsQueued(current.xexpose.display, QueuedAfterReading) > 0)
  274.             {
  275.             XPeekEvent(current.xexpose.display, &ahead);
  276.             if (ahead.xexpose.window != current.xexpose.window || ahead.type != Expose)
  277.                 {
  278.                 break;
  279.                 }
  280.             XNextEvent(display, ¤t);
  281.             }
  282.             
  283.         if (current.xexpose.count == 0)
  284.             {
  285.             reshape(windInfo.width, windInfo.height);
  286.             if (lastEventType == ConfigureNotify)
  287.                 {
  288.                 lastEventType = Expose;
  289.                 return GL_FALSE;
  290.                 }
  291.             else
  292.                 {
  293.                 lastEventType = Expose;
  294.                 return GL_TRUE;
  295.                 }
  296.             }
  297.             
  298.         return GL_FALSE;
  299.  
  300.       case ConfigureNotify:
  301.         lastEventType   = ConfigureNotify;
  302.         windInfo.width  = current.xconfigure.width;
  303.         windInfo.height = current.xconfigure.height;
  304.         reshape(windInfo.width, windInfo.height);
  305.         return GL_TRUE;
  306.  
  307.       case ButtonPress:
  308.         lastEventType = ButtonPress;
  309.  
  310.             mask = 0;
  311.             if (current.xbutton.button == 1)
  312.                 {
  313.                 mask |= TK_LEFTBUTTON;
  314.                 }
  315.             if (current.xbutton.button == 2)
  316.                 {
  317.                 mask |= TK_MIDDLEBUTTON;
  318.                 }
  319.             if (current.xbutton.button == 3)
  320.                 {
  321.                 mask |= TK_RIGHTBUTTON;
  322.                 }
  323.  
  324.             /* here we are going to do a little kludge to allow the user to pick the
  325.             monsters using the mouse rather than the 6-9 keys. If the user clicks the
  326.             mouse within a specified area then the appropriate digit will be sent to
  327.             simulate that number being pressed */
  328.             
  329.             #define col_1_left      0.17
  330.             #define col_1_right     0.386
  331.             #define col_2_left      0.657
  332.             #define col_2_right     0.814
  333.             
  334.             #define row_1_top       0.327
  335.             #define row_1_bottom    0.49
  336.             #define row_2_top       0.655
  337.             #define row_2_bottom    0.836
  338.             
  339.             winClickX = (float) current.xbutton.x / windInfo.width;
  340.             winClickY = (float) current.xbutton.y / windInfo.height;
  341.             
  342.             if ((winClickX > col_1_left) && (winClickX < col_1_right) &&
  343.                 (winClickY > row_1_top) && (winClickY < row_1_bottom))
  344.                  mouseKey(TK_6, 0);
  345.             
  346.             if ((winClickX > col_1_left) && (winClickX < col_1_right) &&
  347.                 (winClickY > row_2_top) && (winClickY < row_2_bottom))
  348.                  mouseKey(TK_8, 0);
  349.             
  350.             if ((winClickX > col_2_left) && (winClickX < col_2_right) &&
  351.                 (winClickY > row_1_top) && (winClickY < row_1_bottom))
  352.                  mouseKey(TK_7, 0);
  353.             
  354.             if ((winClickX > col_2_left) && (winClickX < col_2_right) &&
  355.                 (winClickY > row_2_top) && (winClickY < row_2_bottom))
  356.                  mouseKey(TK_9, 0);
  357.             
  358.     
  359.  
  360.             return MouseDown(current.xbutton.x, current.xbutton.y, mask);
  361.  
  362.         
  363.       case ButtonRelease:
  364.         lastEventType = ButtonRelease;
  365.  
  366.             mask = 0;
  367.             if (current.xbutton.button == 1)
  368.                 {
  369.                 mask |= TK_LEFTBUTTON;
  370.                 }
  371.             if (current.xbutton.button == 2)
  372.                 {
  373.                 mask |= TK_MIDDLEBUTTON;
  374.                 }
  375.             if (current.xbutton.button == 3)
  376.                 {
  377.                 mask |= TK_RIGHTBUTTON;
  378.                 }
  379.                 
  380.             return MouseUp(current.xbutton.x, current.xbutton.y, mask);
  381.  
  382.       case KeyPress:
  383.         lastEventType = KeyPress;
  384.         XLookupString(¤t.xkey, buf, sizeof(buf), &ks, 0);
  385.         switch (ks) {
  386.           case XK_a:            key = TK_a;             break;
  387.           case XK_A:            key = TK_A;             break;
  388.           case XK_z:            key = TK_z;             break;
  389.           case XK_Z:            key = TK_Z;             break;
  390.           case XK_Control_L:    key = TK_CONTROL_L;     break;
  391.           case XK_Control_R:    key = TK_CONTROL_R;     break;
  392.           case XK_Left:         key = TK_LEFT;          break;
  393.           case XK_Up:           key = TK_UP;            break;
  394.           case XK_Right:        key = TK_RIGHT;         break;
  395.           case XK_Down:         key = TK_DOWN;          break;
  396.  
  397.           case XK_I:            key = TK_I;             break;
  398.           case XK_J:            key = TK_J;             break;
  399.           case XK_K:            key = TK_K;             break;
  400.           case XK_L:            key = TK_L;             break;
  401.           case XK_i:            key = TK_i;             break;
  402.           case XK_j:            key = TK_j;             break;
  403.           case XK_k:            key = TK_k;             break;
  404.           case XK_l:            key = TK_l;             break;
  405.  
  406.           case XK_1:            key = TK_1;             break;
  407.           case XK_2:            key = TK_2;             break;
  408.           case XK_3:            key = TK_3;             break;
  409.           case XK_4:            key = TK_4;             break;
  410.  
  411.           case XK_D:            key = TK_D;             break;
  412.           case XK_H:            key = TK_H;             break;
  413.           case XK_M:            key = TK_M;             break;
  414.           case XK_P:            key = TK_P;             break;
  415.           case XK_S:            key = TK_S;             break;
  416. /* T? */  case XK_T:            key = TK_T;             break;
  417.           case XK_d:            key = TK_d;             break;
  418.           case XK_h:            key = TK_h;             break;
  419.           case XK_m:            key = TK_m;             break;
  420.           case XK_p:            key = TK_p;             break;
  421.           case XK_s:            key = TK_s;             break;
  422.  
  423.           case XK_6:            key = TK_6;             break;
  424.           case XK_7:            key = TK_7;             break;
  425.           case XK_8:            key = TK_8;             break;
  426.           case XK_9:            key = TK_9;             break;
  427.           case XK_space:        key = TK_SPACE;         break;
  428.           case XK_Escape:       key = TK_ESCAPE;        break;
  429.  
  430.           case XK_q:            key = TK_q;             break;
  431.           case XK_w:            key = TK_w;             break;
  432.           case XK_Q:            key = TK_q;             break;
  433.           case XK_W:            key = TK_w;             break;
  434.  
  435.           case XK_g:            key = TK_g;             break;
  436.           case XK_G:            key = TK_G;             break;
  437.  
  438.           default:              key = GL_FALSE;         break;
  439.         }
  440.  
  441.         if (key)
  442.             {
  443.             return processKey(key, 0);
  444.             }
  445.         else
  446.             {
  447.             return GL_FALSE;
  448.             }
  449.  
  450. /*
  451.  * Stuff below added by Johan Hagman for ctrl key to turn weapon on
  452.  * rather than as a toggle for the weapon
  453.  */
  454.  
  455.       case KeyRelease:
  456.         lastEventType = KeyPress;
  457.         XLookupString(¤t.xkey, buf, sizeof(buf), &ks, 0);
  458.         switch (ks) {
  459.           case XK_Control_L:    key = TK_CONTROL_L;     break;
  460.           default:              key = GL_FALSE;         break;
  461.         }
  462.  
  463.         if (key)
  464.             return processKeyRelease(key);
  465.         else
  466.             return GL_FALSE;
  467.  
  468.     }
  469.     return GL_FALSE;
  470. }
  471.  
  472. /******************************************************************************/
  473.  
  474. /********************************************
  475. Andy's new shorter version of the tkExec
  476. function to try and speed things up a bit
  477. ********************************************/
  478. void tkExec(void)
  479.     {
  480.     while (GL_TRUE)
  481.         {
  482.         id();
  483.         
  484.         while (XPending(display))
  485.             DoNextEvent();
  486.         }
  487.     }
  488.  
  489.  
  490. /******************************************************************************/
  491.  
  492. void tkGetMouseLoc(int *x, int *y)
  493.     {
  494.     int junk;
  495.  
  496.     *x = 0;
  497.     *y = 0;
  498.     XQueryPointer(display, window, (Window *)&junk, (Window *)&junk,
  499.                   &junk, &junk, x, y, (unsigned int *)&junk);
  500.     }
  501.  
  502. /******************************************************************************/
  503.  
  504. static XVisualInfo *FindVisual(GLenum type)
  505.     {
  506.     int list[32];
  507.     int i;
  508.  
  509.     i = 0;
  510.  
  511.     list[i++] = GLX_LEVEL;
  512.     list[i++] = 0;
  513.  
  514.     if (TK_IS_DOUBLE(type)) {
  515.         list[i++] = (int) GLX_DOUBLEBUFFER;
  516.     }
  517.  
  518.     if (TK_IS_RGB(type))
  519.         {
  520.         list[i++] = GLX_RGBA;
  521.         list[i++] = GLX_RED_SIZE;
  522.         list[i++] = 1;
  523.         list[i++] = GLX_GREEN_SIZE;
  524.         list[i++] = 1;
  525.         list[i++] = GLX_BLUE_SIZE;
  526.         list[i++] = 1;
  527.  
  528.         if (TK_HAS_ALPHA(type))
  529.             {
  530.             list[i++] = GLX_ALPHA_SIZE;
  531.             list[i++] = 1;
  532.             }
  533.  
  534.         if (TK_HAS_ACCUM(type))
  535.             {
  536.             list[i++] = GLX_ACCUM_RED_SIZE;
  537.             list[i++] = 1;
  538.             list[i++] = GLX_ACCUM_GREEN_SIZE;
  539.             list[i++] = 1;
  540.             list[i++] = GLX_ACCUM_BLUE_SIZE;
  541.             list[i++] = 1;
  542.             
  543.             if (TK_HAS_ALPHA(type))
  544.                 {
  545.                 list[i++] = GLX_ACCUM_ALPHA_SIZE;
  546.                 list[i++] = 1;
  547.             }
  548.             }
  549.         }
  550.     else if (TK_IS_INDEX(type))
  551.         {
  552.         list[i++] = GLX_BUFFER_SIZE;
  553.         list[i++] = 1;
  554.         }
  555.  
  556.     if (TK_HAS_DEPTH(type))
  557.         {
  558.         list[i++] = GLX_DEPTH_SIZE;
  559.         list[i++] = 1;
  560.         }
  561.  
  562.     if (TK_HAS_STENCIL(type))
  563.         {
  564.         list[i++] = GLX_STENCIL_SIZE;
  565.         list[i++] = 1;
  566.         }
  567.  
  568.     list[i] = None;
  569.     
  570.     return glXChooseVisual(display, screen, (int *) list);
  571.     }
  572.  
  573. /******************************************************************************/
  574.  
  575. static int MakeVisualType(XVisualInfo *vi)
  576.     {
  577.     GLenum mask;
  578.     int x, y, z;
  579.  
  580.     mask = 0;
  581.  
  582.     glXGetConfig(display, vi, GLX_RGBA, &x);
  583.     
  584.     if (x) {
  585.         mask |= TK_RGB;
  586.         
  587.         glXGetConfig(display, vi, GLX_ALPHA_SIZE, &x);
  588.         if (x > 0)
  589.             {
  590.             mask |= TK_ALPHA;
  591.             }
  592.             
  593.         glXGetConfig(display, vi, GLX_ACCUM_RED_SIZE, &x);
  594.         glXGetConfig(display, vi, GLX_ACCUM_GREEN_SIZE, &y);
  595.         glXGetConfig(display, vi, GLX_ACCUM_BLUE_SIZE, &z);
  596.         
  597.         if (x > 0 && y > 0 && z > 0)
  598.             {
  599.             mask |= TK_ACCUM;
  600.             }
  601.         }
  602.     else
  603.         {
  604.         mask |= TK_INDEX;
  605.         }
  606.  
  607.     glXGetConfig(display, vi, GLX_DOUBLEBUFFER, &x);
  608.     if (x)
  609.         {
  610.         mask |= TK_DOUBLE;
  611.         }
  612.     else
  613.         {
  614.         mask |= TK_SINGLE;
  615.         }
  616.  
  617.     glXGetConfig(display, vi, GLX_DEPTH_SIZE, &x);
  618.     if (x > 0)
  619.         {
  620.         mask |= TK_DEPTH;
  621.         }
  622.  
  623.     glXGetConfig(display, vi, GLX_STENCIL_SIZE, &x);
  624.     if (x > 0)
  625.         {
  626.         mask |= TK_STENCIL;
  627.         }
  628.  
  629.     if (glXIsDirect(display, context))
  630.         {
  631.         mask |= TK_DIRECT;
  632.         }
  633.     else
  634.         {
  635.         mask |= TK_INDIRECT;
  636.         }
  637.  
  638.     return mask;
  639.     }
  640.  
  641. /******************************************************************************/
  642.  
  643. static int WaitForMapNotify(Display *d, XEvent *e, char *arg)
  644.     {
  645.     Display *display;
  646.     char *arguments;
  647.     
  648.     display = d;
  649.     arguments = arg;
  650.     
  651.         if (e->type == MapNotify && e->xmap.window == window) {
  652.             return GL_TRUE;
  653.         }
  654.         return GL_FALSE;
  655.     }
  656.  
  657. /******************************************************************************/
  658.  
  659. void tkInitPosition(int x, int y, int width, int height)
  660.     {
  661.     windInfo.x      = x;
  662.     windInfo.y      = y;
  663.     windInfo.width  = width;
  664.     windInfo.height = height;
  665.     }
  666.  
  667. /******************************************************************************/
  668.  
  669. void tkInitDisplayMode(GLenum type)
  670.     {
  671.     windInfo.type = type;
  672.     }
  673.  
  674. /******************************************************************************/
  675.  
  676. GLenum tkInitWindow(char *title)
  677. {
  678.     XSetWindowAttributes wa;
  679.     XSizeHints sh;
  680.     XEvent e;
  681.     int erb, evb;
  682.     unsigned long mask;
  683.  
  684.     if (!display)
  685.         {
  686.         display = XOpenDisplay(0);
  687.         if (!display)
  688.             {
  689.             fprintf(stderr, "Can't connect to display!\n");
  690.             return GL_FALSE;
  691.             }
  692.             
  693.         if (!glXQueryExtension(display, &erb, &evb))
  694.             {
  695.             fprintf(stderr, "No glx extension!\n");
  696.             return GL_FALSE;
  697.             }
  698.             
  699.         screen = DefaultScreen(display);
  700.         }
  701.  
  702.     visualInfo = FindVisual(windInfo.type);
  703.     
  704.     if (!visualInfo)
  705.         {
  706.         fprintf(stderr, "Window type not found!\n");
  707.         return GL_FALSE;
  708.         }
  709.  
  710.     context = glXCreateContext(display, visualInfo, None,
  711.                                (TK_IS_DIRECT(windInfo.type)) ? GL_TRUE
  712.                                                              : GL_FALSE);
  713.     if (!context)
  714.         {
  715.         fprintf(stderr, "Can't create a context!\n");
  716.         return GL_FALSE;
  717.         }
  718.  
  719.     windInfo.type = MakeVisualType(visualInfo);
  720.  
  721.     if (TK_IS_INDEX(windInfo.type))
  722.         {
  723.         if (visualInfo->class != StaticColor && visualInfo->class != StaticGray)
  724.             {
  725.             colorMap = XCreateColormap(display, RootWindow(display, screen),
  726.                                        visualInfo->visual, AllocAll);
  727.             }
  728.         else
  729.             {
  730.             colorMap = XCreateColormap(display, RootWindow(display, screen),
  731.                                        visualInfo->visual, AllocNone);
  732.             }
  733.             
  734.         wa.colormap = colorMap;
  735.         tkSetRGBMap(256, colorMaps);
  736.         wa.background_pixel = 7;
  737.         wa.border_pixel = 0;
  738.         }
  739.     else
  740.         {
  741.         colorMap = XCreateColormap(display, RootWindow(display, screen),
  742.                                    visualInfo->visual, AllocNone);
  743.         wa.colormap = colorMap;
  744.         tkSetRGBMap(256, colorMaps);
  745.         wa.background_pixel = 0xFFFFFFFF;
  746.         wa.border_pixel = 0;
  747.         }
  748.         
  749.     wa.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask |
  750.  
  751.                     KeyReleaseMask |
  752.  
  753.                     ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
  754.  
  755.     mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap;
  756.  
  757.     window = XCreateWindow(display, RootWindow(display, screen), 0, 0,
  758.                            windInfo.width, windInfo.height, 0,
  759.                            visualInfo->depth, InputOutput, visualInfo->visual,
  760.                            mask, &wa);
  761.     
  762.     if ((windInfo.x != -1) && (windInfo.y != -1))
  763.         {
  764.         sh.flags    = USPosition;
  765.         sh.x        = windInfo.x + 10;
  766.         sh.y        = windInfo.y + 10;
  767.         
  768.         XSetStandardProperties(display, window, title, title, None, 0, 0, &sh);
  769.         }
  770.     else
  771.         {
  772.         XSetStandardProperties(display, window, title, title, None, 0, 0, 0);
  773.         }
  774.  
  775.     XMapWindow(display, window);
  776.     XIfEvent(display, &e, WaitForMapNotify, 0);
  777.  
  778.     XSetWMColormapWindows(display, window, &window, 1);
  779.  
  780.     if (!glXMakeCurrent(display, window, context))
  781.         {
  782.         fprintf(stderr, "Can't make window current drawable!\n");
  783.         return GL_FALSE;
  784.         }
  785.  
  786.     XFlush(display);
  787.  
  788.     return GL_TRUE;
  789. }
  790.  
  791. /******************************************************************************/
  792.  
  793. static int Ignore(Display *parm1, XErrorEvent *parm2)
  794.     {
  795.     Display *display;
  796.     XErrorEvent *error;
  797.     
  798.     display = parm1;
  799.     error = parm2;
  800.     
  801.         return 0;
  802.     }
  803.  
  804. /******************************************************************************/
  805.  
  806. void tkSetRGBMap(int size, float *rgb)
  807. {
  808.     XErrorHandler old_handler;
  809.     XColor c;
  810.     int rShift, gShift, bShift, max, i;
  811.  
  812.     old_handler = XSetErrorHandler(Ignore);
  813.  
  814.     switch (visualInfo->class) {
  815.       case DirectColor:
  816.         max = (size > visualInfo->colormap_size) ? visualInfo->colormap_size
  817.                                                  : size;
  818.         for (i = 0; i < max; i++)
  819.             {
  820.             rShift = ffs((unsigned int)visualInfo->red_mask) - 1;
  821.             gShift = ffs((unsigned int)visualInfo->green_mask) - 1;
  822.             bShift = ffs((unsigned int)visualInfo->blue_mask) - 1;
  823.             c.pixel = ((i << rShift) & visualInfo->red_mask) |
  824.                       ((i << gShift) & visualInfo->green_mask) |
  825.                       ((i << bShift) & visualInfo->blue_mask);
  826.                       
  827.             c.red = (unsigned short)(rgb[i] * 65535.0 + 0.5);
  828.             c.green = (unsigned short)(rgb[size+i] * 65535.0 + 0.5);
  829.             c.blue = (unsigned short)(rgb[size*2+i] * 65535.0 + 0.5);
  830.             
  831.             c.flags = DoRed | DoGreen | DoBlue;
  832.             XStoreColor(display, colorMap, &c);
  833.             }
  834.         break;
  835.         
  836.       case GrayScale:
  837.       case PseudoColor:
  838.         max = (size > visualInfo->colormap_size) ? visualInfo->colormap_size
  839.                                                  : size;
  840.         for (i = 0; i < max; i++) {
  841.             c.pixel = i;
  842.             c.red = (unsigned short)(rgb[i] * 65535.0 + 0.5);
  843.             c.green = (unsigned short)(rgb[size+i] *
  844.                                        65535.0 + 0.5);
  845.             c.blue = (unsigned short)(rgb[size*2+i] *
  846.                                       65535.0 + 0.5);
  847.             c.flags = DoRed | DoGreen | DoBlue;
  848.             XStoreColor(display, colorMap, &c);
  849.         }
  850.         break;
  851.     }
  852.  
  853.     XSync(display, 0);
  854.     XSetErrorHandler(old_handler);
  855. }
  856.  
  857. /******************************************************************************/
  858.  
  859. void tkSwapBuffers(void)
  860. {
  861.     if (display) {
  862.         glXSwapBuffers(display, window);
  863.     }
  864. }
  865.  
  866. /******************************************************************************/
  867.  
  868. /*
  869.  * Stuff below added by Johan Hagman for pointer
  870.  * grabbing in Solaris battalion
  871.  */
  872.  
  873. void unGrabPointer()
  874. {
  875.     /* Ungrab the pointer */
  876.     XUngrabPointer(display, CurrentTime);
  877. }
  878.  
  879.  
  880. void grabPointer()
  881. {
  882.     /* Grab the pointer so you cannot move the  mouse out of the main
  883.      * window. Also set the cursor to a new cursor with no shape.
  884.      */
  885.     if (XGrabPointer(display, window, True,
  886.                         ButtonReleaseMask | ButtonPressMask,
  887.                         GrabModeAsync, GrabModeAsync, window,
  888.                         None, CurrentTime) != GrabSuccess)
  889.     {
  890.         /* Error while grab - not too bad but let user know */  
  891.         fprintf(stderr, "Warning: Pointer grab unsuccessful.");
  892.     }
  893. }
  894.  
  895. /******************************************************************************/
  896.  
  897.  
  898. /********************************************
  899.  * void tkExec(void)
  900.     {
  901.     GLenum flag;
  902.  
  903.     while (GL_TRUE)
  904.         {
  905.         if (IdleFunc)
  906.             {
  907.             if (IdleFunc)
  908.                 {
  909.                 (*IdleFunc)();
  910.                 }
  911.             flag = GL_FALSE;
  912.             while (XPending(display))
  913.                 {
  914.                 flag |= DoNextEvent();
  915.                 }
  916.             if (flag == GL_TRUE)
  917.                 {
  918.                 if (DisplayFunc)
  919.                     {
  920.                     (*DisplayFunc)();
  921.                     }
  922.                 }
  923.             }
  924.         else
  925.             {
  926.             if (DoNextEvent() == GL_TRUE)
  927.                 {
  928.                 if (DisplayFunc)
  929.                     {
  930.                     (*DisplayFunc)();
  931.                     }
  932.                 }
  933.             }
  934.         }
  935.     }
  936.  
  937. ************************************************/
  938.  
  939. /*
  940. void tkSetOneColor(int index, float r, float g, float b)
  941. {
  942.     XErrorHandler old_handler;
  943.     XColor c;
  944.     int rShift, gShift, bShift;
  945.  
  946.     old_handler = XSetErrorHandler(Ignore);
  947.  
  948.     switch (visualInfo->class) {
  949.       case DirectColor:
  950.         rShift = ffs((unsigned int)visualInfo->red_mask) - 1;
  951.         gShift = ffs((unsigned int)visualInfo->green_mask) - 1;
  952.         bShift = ffs((unsigned int)visualInfo->blue_mask) - 1;
  953.         c.pixel = ((index << rShift) & visualInfo->red_mask) |
  954.                   ((index << gShift) & visualInfo->green_mask) |
  955.                   ((index << bShift) & visualInfo->blue_mask);
  956.         c.red = (unsigned short)(r * 65535.0 + 0.5);
  957.         c.green = (unsigned short)(g * 65535.0 + 0.5);
  958.         c.blue = (unsigned short)(b * 65535.0 + 0.5);
  959.         c.flags = DoRed | DoGreen | DoBlue;
  960.         XStoreColor(display, colorMap, &c);
  961.         break;
  962.       case GrayScale:
  963.       case PseudoColor:
  964.         if (index < visualInfo->colormap_size) {
  965.             c.pixel = index;
  966.             c.red = (unsigned short)(r * 65535.0 + 0.5);
  967.             c.green = (unsigned short)(g * 65535.0 + 0.5);
  968.             c.blue = (unsigned short)(b * 65535.0 + 0.5);
  969.             c.flags = DoRed | DoGreen | DoBlue;
  970.             XStoreColor(display, colorMap, &c);
  971.         }
  972.         break;
  973.     }
  974.  
  975.     XSync(display, 0);
  976.     XSetErrorHandler(old_handler);
  977. }
  978. */
  979. /******************************************************************************/
  980. /*
  981. void tkSetFogRamp(int density, int startIndex)
  982. {
  983.     XErrorHandler old_handler;
  984.     XColor c[256];
  985.     int rShift, gShift, bShift, intensity, fogValues, colorValues;
  986.     int i, j, k;
  987.  
  988.     old_handler = XSetErrorHandler(Ignore);
  989.  
  990.     switch (visualInfo->class) {
  991.       case DirectColor:
  992.         fogValues = 1 << density;
  993.         colorValues = 1 << startIndex;
  994.         for (i = 0; i < colorValues; i++) {
  995.             for (j = 0; j < fogValues; j++) {
  996.                 k = i * fogValues + j;
  997.                 intensity = i * fogValues + j * colorValues;
  998.                 if (intensity > visualInfo->colormap_size) {
  999.                     intensity = visualInfo->colormap_size;
  1000.                 }
  1001.                 intensity = (intensity << 8) | intensity;
  1002.                 rShift = ffs((unsigned int)visualInfo->red_mask) - 1;
  1003.                 gShift = ffs((unsigned int)visualInfo->green_mask) - 1;
  1004.                 bShift = ffs((unsigned int)visualInfo->blue_mask) - 1;
  1005.                 c[k].pixel = ((k << rShift) & visualInfo->red_mask) |
  1006.                              ((k << gShift) & visualInfo->green_mask) |
  1007.                              ((k << bShift) & visualInfo->blue_mask);
  1008.                 c[k].red = (unsigned short)intensity;
  1009.                 c[k].green = (unsigned short)intensity;
  1010.                 c[k].blue = (unsigned short)intensity;
  1011.                 c[k].flags = DoRed | DoGreen | DoBlue;
  1012.             }
  1013.         }
  1014.         XStoreColors(display, colorMap, c, visualInfo->colormap_size);
  1015.         break;
  1016.       case GrayScale:
  1017.       case PseudoColor:
  1018.         fogValues = 1 << density;
  1019.         colorValues = 1 << startIndex;
  1020.         for (i = 0; i < colorValues; i++) {
  1021.             for (j = 0; j < fogValues; j++) {
  1022.                 k = i * fogValues + j;
  1023.                 intensity = i * fogValues + j * colorValues;
  1024.                 if (intensity > visualInfo->colormap_size) {
  1025.                     intensity = visualInfo->colormap_size;
  1026.                 }
  1027.                 intensity = (intensity << 8) | intensity;
  1028.                 c[k].pixel = k;
  1029.                 c[k].red = (unsigned short)intensity;
  1030.                 c[k].green = (unsigned short)intensity;
  1031.                 c[k].blue = (unsigned short)intensity;
  1032.                 c[k].flags = DoRed | DoGreen | DoBlue;
  1033.             }
  1034.         }
  1035.         XStoreColors(display, colorMap, c, visualInfo->colormap_size);
  1036.         break;
  1037.     }
  1038.  
  1039.     XSync(display, 0);
  1040.     XSetErrorHandler(old_handler);
  1041. }
  1042. */
  1043. /******************************************************************************/
  1044. /*
  1045. void tkSetGreyRamp(void)
  1046. {
  1047.     XErrorHandler old_handler;
  1048.     XColor c[256];
  1049.     float intensity;
  1050.     int rShift, gShift, bShift, i;
  1051.  
  1052.     old_handler = XSetErrorHandler(Ignore);
  1053.  
  1054.     switch (visualInfo->class) {
  1055.       case DirectColor:
  1056.         for (i = 0; i < visualInfo->colormap_size; i++) {
  1057.             intensity = (float)i / (float)visualInfo->colormap_size *
  1058.                         65535.0 + 0.5;
  1059.             rShift = ffs((unsigned int)visualInfo->red_mask) - 1;
  1060.             gShift = ffs((unsigned int)visualInfo->green_mask) - 1;
  1061.             bShift = ffs((unsigned int)visualInfo->blue_mask) - 1;
  1062.             c[i].pixel = ((i << rShift) & visualInfo->red_mask) |
  1063.                          ((i << gShift) & visualInfo->green_mask) |
  1064.                          ((i << bShift) & visualInfo->blue_mask);
  1065.             c[i].red = (unsigned short)intensity;
  1066.             c[i].green = (unsigned short)intensity;
  1067.             c[i].blue = (unsigned short)intensity;
  1068.             c[i].flags = DoRed | DoGreen | DoBlue;
  1069.         }
  1070.         XStoreColors(display, colorMap, c, visualInfo->colormap_size);
  1071.         break;
  1072.       case GrayScale:
  1073.       case PseudoColor:
  1074.         for (i = 0; i < visualInfo->colormap_size; i++) {
  1075.             intensity = (float)i / (float)visualInfo->colormap_size *
  1076.                         65535.0 + 0.5;
  1077.             c[i].pixel = i;
  1078.             c[i].red = (unsigned short)intensity;
  1079.             c[i].green = (unsigned short)intensity;
  1080.             c[i].blue = (unsigned short)intensity;
  1081.             c[i].flags = DoRed | DoGreen | DoBlue;
  1082.         }
  1083.         XStoreColors(display, colorMap, c, visualInfo->colormap_size);
  1084.         break;
  1085.     }
  1086.  
  1087.     XSync(display, 0);
  1088.     XSetErrorHandler(old_handler);
  1089. }
  1090. */
  1091.  
  1092. /*
  1093.       case MotionNotify:
  1094.         lastEventType = MotionNotify;
  1095.         if (MouseMoveFunc) {
  1096.             GLenum mask;
  1097.  
  1098.             mask = 0;
  1099.             if (current.xmotion.state & Button1Mask) {
  1100.                 mask |= TK_LEFTBUTTON;
  1101.             }
  1102.             if (current.xmotion.state & Button2Mask) {
  1103.                 mask |= TK_MIDDLEBUTTON;
  1104.             }
  1105.             if (current.xmotion.state & Button3Mask) {
  1106.                 mask |= TK_RIGHTBUTTON;
  1107.             }
  1108.             return (*MouseMoveFunc)(current.xmotion.x, current.xmotion.y, mask);
  1109.         } else {
  1110.             return GL_FALSE;
  1111.         }
  1112. */
  1113.  
  1114. /*
  1115.  float tkRGBMap[8][3] = {
  1116.     {
  1117.         0, 0, 0
  1118.     },
  1119.     {
  1120.         1, 0, 0
  1121.     },
  1122.     {
  1123.         0, 1, 0
  1124.     },
  1125.     {
  1126.         1, 1, 0
  1127.     },
  1128.     {
  1129.         0, 0, 1
  1130.     },
  1131.     {
  1132.         1, 0, 1
  1133.     },
  1134.     {
  1135.         0, 1, 1
  1136.     },
  1137.     {
  1138.         1, 1, 1
  1139.     }
  1140. };
  1141.  
  1142.  */
  1143. /******************************************************************************/
  1144. /*
  1145. void tkQuit(void)
  1146. {
  1147.  
  1148.     exit(0);
  1149. }
  1150. */
  1151.  
  1152.  /******************************************************************************/
  1153. /*
  1154. void tkExposeFunc(void (*Func)(int, int))
  1155. {
  1156.  
  1157.     ExposeFunc = Func;
  1158. }
  1159. */
  1160. /******************************************************************************/
  1161. /*
  1162. void tkReshapeFunc(void (*Func)(int, int))
  1163. {
  1164.  
  1165.     ReshapeFunc = Func;
  1166. }
  1167. */
  1168. /******************************************************************************/
  1169. /*
  1170. void tkDisplayFunc(void (*Func)(void))
  1171. {
  1172.  
  1173.     DisplayFunc = Func;
  1174. }
  1175. */
  1176. /******************************************************************************/
  1177. /*
  1178. void tkKeyDownFunc(GLenum (*Func)(int, GLenum))
  1179. {
  1180.  
  1181.     KeyDownFunc = Func;
  1182. }
  1183. */
  1184. /******************************************************************************/
  1185. /*
  1186. void tkMouseDownFunc(GLenum (*Func)(int, int, GLenum))
  1187. {
  1188.  
  1189.     MouseDownFunc = Func;
  1190. }
  1191. */
  1192. /******************************************************************************/
  1193. /*
  1194. void tkMouseUpFunc(GLenum (*Func)(int, int, GLenum))
  1195. {
  1196.  
  1197.     MouseUpFunc = Func;
  1198. }
  1199. */
  1200. /******************************************************************************/
  1201. /*
  1202. void tkMouseMoveFunc(GLenum (*Func)(int, int, GLenum))
  1203. {
  1204.  
  1205.     MouseMoveFunc = Func;
  1206. }
  1207. */
  1208. /******************************************************************************/
  1209. /*
  1210. void tkIdleFunc(void (*Func)(void))
  1211. {
  1212.  
  1213.     IdleFunc = Func;
  1214. }
  1215. */
  1216. /******************************************************************************/
  1217. /*
  1218. GLint tkGetColorMapSize(void)
  1219. {
  1220.  
  1221.     if (!display) {
  1222.         return 0;
  1223.     } else {
  1224.         return visualInfo->colormap_size;
  1225.     }
  1226. }
  1227. */
  1228.  
  1229. /******************************************************************************/
  1230. /*
  1231. Display *tkGetXDisplay(void)
  1232.     {
  1233.     return display;
  1234.     }
  1235. */
  1236. /******************************************************************************/
  1237. /*
  1238. Window tkGetXWindow(void)
  1239.     {
  1240.     return window;
  1241.     }
  1242. */
  1243.  
  1244.  
  1245. /*
  1246. static void (*ExposeFunc)(int, int)                 = NULL;
  1247. static void (*ReshapeFunc)(int, int)                = NULL;
  1248. static void (*DisplayFunc)(void)                    = NULL;
  1249. static void (*IdleFunc)(void)                       = NULL;
  1250. */
  1251.  
  1252.  
  1253.  
  1254.  
  1255. /*
  1256.           case XK_0:            key = TK_0;             break;
  1257.           case XK_5:            key = TK_5;             break;
  1258.           case XK_B:            key = TK_B;             break;
  1259.           case XK_C:            key = TK_C;             break;
  1260.           case XK_E:            key = TK_E;             break;
  1261.           case XK_F:            key = TK_F;             break;
  1262.           case XK_G:            key = TK_G;             break;
  1263.           case XK_N:            key = TK_N;             break;
  1264.           case XK_O:            key = TK_O;             break;
  1265.           case XK_Q:            key = TK_Q;             break;
  1266.           case XK_R:            key = TK_R;             break;
  1267.           case XK_U:            key = TK_U;             break;
  1268.           case XK_V:            key = TK_V;             break;
  1269.           case XK_W:            key = TK_W;             break;
  1270.           case XK_X:            key = TK_X;             break;
  1271.           case XK_Y:            key = TK_Y;             break;
  1272.           case XK_b:            key = TK_b;             break;
  1273.           case XK_c:            key = TK_c;             break;
  1274.           case XK_e:            key = TK_e;             break;
  1275.           case XK_f:            key = TK_f;             break;
  1276.           case XK_g:            key = TK_g;             break;
  1277.           case XK_n:            key = TK_n;             break;
  1278.           case XK_o:            key = TK_o;             break;
  1279.           case XK_r:            key = TK_r;             break;
  1280.           case XK_t:            key = TK_t;             break;
  1281.           case XK_u:            key = TK_u;             break;
  1282.           case XK_v:            key = TK_v;             break;
  1283.           case XK_x:            key = TK_x;             break;
  1284.           case XK_y:            key = TK_y;             break;
  1285.           case XK_Shift_L:      key = TK_SHIFT_L;       break;
  1286.           case XK_Shift_R:      key = TK_SHIFT_R;       break;
  1287.           case XK_Return:       key = TK_RETURN;        break;
  1288. */
  1289.  
  1290.  
  1291.