home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / mesa / src-tk / fxevent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-31  |  17.7 KB  |  933 lines

  1. /* event.c modified for 3Dfx driver */
  2.  
  3. #if defined(FX)
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <stdarg.h>
  9.  
  10. #if defined(__WIN32__)
  11. #include <windows.h>
  12. #include <conio.h>
  13. #endif
  14.  
  15. #include "gltk.h"
  16. #include "GL/fxmesa.h"
  17.  
  18. /******************************************************************************/
  19.  
  20. void (*ExposeFunc)(int, int) = 0;
  21. void (*ReshapeFunc)(int, int) = 0;
  22. void (*DisplayFunc)(void) = 0;
  23. GLenum (*KeyDownFunc)(int, GLenum) = 0;
  24. GLenum (*MouseDownFunc)(int, int, GLenum) = 0;
  25. GLenum (*MouseUpFunc)(int, int, GLenum) = 0;
  26. GLenum (*MouseMoveFunc)(int, int, GLenum) = 0;
  27. void (*IdleFunc)(void) = 0;
  28.  
  29. static int width,height;
  30. static int startx = 0,starty = 0;
  31. static fxMesaContext fc=NULL;
  32. static int WindowType = 0;
  33.  
  34. /******************************************************************************/
  35. #ifdef __linux__
  36.  
  37. #include <stdio.h>
  38. #include <sys/types.h>
  39. #include <unistd.h>
  40. #include <termios.h>
  41. #include <fcntl.h>
  42.  
  43. GLenum tkSetWindowLevel(GLenum level)
  44. {
  45.     return GL_TRUE;
  46. }
  47.  
  48. void tkNewCursor(GLint id, GLubyte *shapeBuf, GLubyte *maskBuf, GLenum fgColor,
  49.                  GLenum bgColor, GLint hotX, GLint hotY)
  50. {
  51. }
  52.  
  53. void tkSetCursor(GLint id)
  54. {
  55. }
  56.  
  57. void tkGetMouseLoc (int *x, int *y)
  58. {
  59.         *x = (int)0;
  60.         *y = (int)0;
  61. }
  62.  
  63. void tkGetSystem(TKenum type, void *ptr)
  64. {
  65.         type = (TKenum)NULL;
  66.         ptr = NULL;
  67. }
  68.  
  69. void tkCloseWindow() {}
  70.  
  71. void tkSetFogRamp(int density, int startIndex) {}
  72.  
  73. #define NCOLORS 8
  74. float tkRGBMap[NCOLORS][3] = {
  75.     {0,0,0},
  76.     {1,0,0},
  77.     {0,1,0},
  78.     {1,1,0},
  79.     {0,0,1},
  80.     {1,0,1},
  81.     {0,1,1},
  82.     {1,1,1}
  83. };
  84.  
  85. static int sg_tty_fd = -1;
  86.  
  87. int 
  88. tty_open_nonblock (void)
  89. {
  90.   struct termios term;
  91.  
  92.   sg_tty_fd = open ("/dev/tty", O_RDONLY, -1, -1);
  93.   if (sg_tty_fd < 0)
  94.   {
  95.     printf ("error opening /dev/tty\n");
  96.     return (sg_tty_fd);
  97.   }
  98.  
  99.  
  100.   if (tcgetattr (sg_tty_fd, &term) == -1)
  101.     perror ("tty_open_nonblock:tcgetattr");
  102.  
  103.   /*
  104.    * If the user wants signals to be valid so that things like suspend
  105.    * and interrupt (^Z & ^C) work for terminal-connected lines,
  106.    * we need to set the ISIG flag.  We also want to post process
  107.    * newlines in this case so they get mapped to CRNL
  108.    */
  109.                                                     
  110.   term.c_lflag = ISIG;
  111.   term.c_oflag = OPOST | ONLCR;
  112.  
  113.   term.c_iflag &= ~INPCK;
  114.   term.c_cflag &= ~PARENB;
  115.  
  116.   term.c_iflag = 0;
  117.   term.c_lflag &= ~ICANON;
  118.   term.c_lflag &= ~ECHO;
  119.   term.c_cc[VMIN] = 1;
  120.   term.c_cc[VTIME] = 0;
  121.   term.c_cflag |= CLOCAL | CS8 | CREAD;
  122.  
  123.   if (tcsetattr (sg_tty_fd, TCSADRAIN, &term) == -1)
  124.     perror ("tty_open_nonblock:tcflush");
  125.  
  126.   if (fcntl (sg_tty_fd, F_SETFL, O_NONBLOCK) == -1)
  127.     perror ("tty_open_nonblock:fcntl");
  128.  
  129.   if (tcflush (sg_tty_fd, TCIFLUSH) == -1)
  130.     perror ("tty_open_nonblock:tcflush");
  131.   return 0;
  132. }
  133.  
  134. int 
  135. tty_read (int *charptr)
  136. {
  137.   int rc;
  138.  
  139.   rc = read (sg_tty_fd, charptr, 1);
  140.   return (rc);
  141. }
  142.  
  143. #elif !defined(__WIN32__)    /* DOS section */
  144.  
  145. int _tkkbhit(void )
  146. {
  147.     return(kbhit());
  148. }
  149.  
  150. int _tkgetch(void )
  151. {
  152.     return(getch());
  153. }
  154.  
  155. #else
  156.  
  157. static HWND        hWndMain = 0;
  158. static HANDLE    hMainInstance = 0;
  159. static int        fullscreen = GL_TRUE;
  160. static int        qhead = 0;
  161. static int        qtail = 0;
  162. static int        queue[256] = {0};
  163. static char        *fakeName = "WinTkMesa3DfxApplication";
  164. static char        *argvbuf[32];
  165. static char        cmdLineBuffer[1024];
  166.  
  167. char **commandLineToArgv(LPSTR lpCmdLine,int *pArgc);
  168.  
  169. /*
  170.  * MainWndproc
  171.  *
  172.  * Callback for all Windows messages
  173.  */
  174. long FAR PASCAL MainWndproc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
  175. {
  176.     PAINTSTRUCT    ps;
  177.     HDC            hdc;
  178.  
  179.     switch(message)
  180.     {
  181.         case WM_SETCURSOR:
  182.             if(!fullscreen)
  183.             {
  184.                 SetCursor(NULL);
  185.                 return(0);
  186.             }
  187.             break;
  188.  
  189.         case WM_CREATE:
  190.             break;
  191.  
  192.         case WM_PAINT:
  193.             hdc = BeginPaint(hWnd,&ps);
  194.             EndPaint(hWnd,&ps);
  195.             return(1);
  196.         
  197.         case WM_CLOSE:
  198.             tkQuit();
  199.             break;
  200.  
  201.         case WM_DESTROY:
  202.             break;
  203.  
  204.         case WM_MOVE:
  205.             if(!grSstControl(GR_CONTROL_MOVE))
  206.             {
  207.                 tkQuit();
  208.                 return(0);
  209.             }
  210.             break;
  211.  
  212.         case WM_DISPLAYCHANGE:
  213.         case WM_SIZE:
  214.             {
  215.                 RECT    rect;
  216.  
  217.                 GetClientRect(hWndMain,&rect);
  218.                 if(ReshapeFunc)
  219.                     (*ReshapeFunc)(rect.right,rect.bottom);
  220.             }
  221.             if(!grSstControl(GR_CONTROL_RESIZE))
  222.             {
  223.                 tkQuit();
  224.                 return(0);
  225.             }
  226.             break;
  227.  
  228.         case WM_ACTIVATE:
  229.             {
  230.                 WORD    fActive = LOWORD(wParam);
  231.                 BOOL    fMinimized = (BOOL) HIWORD(wParam);
  232.  
  233.                 if((fActive == WA_INACTIVE) || fMinimized)
  234.                     grSstControl(GR_CONTROL_DEACTIVATE);
  235.                 else
  236.                     grSstControl(GR_CONTROL_ACTIVATE);
  237.             }
  238.             break;
  239.  
  240.         case WM_KEYDOWN: 
  241.             switch (wParam) { 
  242.             case VK_LEFT:
  243.                 queue[qhead++] = 0;
  244.                 qhead &= 255;
  245.                 queue[qhead++] = 'K';
  246.                 qhead &= 255;
  247.                 break;
  248.             case VK_RIGHT:
  249.                 queue[qhead++] = 0;
  250.                 qhead &= 255;
  251.                 queue[qhead++] = 'M';
  252.                 qhead &= 255;
  253.                 break;
  254.             case VK_UP:
  255.                 queue[qhead++] = 0;
  256.                 qhead &= 255;
  257.                 queue[qhead++] = 'H';
  258.                 qhead &= 255;
  259.                 break;
  260.            case VK_DOWN:
  261.                 queue[qhead++] = 0;
  262.                 qhead &= 255;
  263.                 queue[qhead++] = 'P';
  264.                 qhead &= 255;
  265.                 break;
  266.             }
  267.             break;
  268.  
  269.         case WM_CHAR:
  270.             if(!isascii(wParam))
  271.                 break;
  272.             queue[qhead++] = wParam;
  273.             qhead &= 255;
  274.             break;
  275.  
  276.         default:
  277.             break;
  278.     }
  279.     return(DefWindowProc(hWnd,message,wParam,lParam));
  280. } /* MainWndproc */
  281.  
  282. /*
  283.  * initApplication
  284.  *
  285.  * Do that Windows initialization stuff...
  286.  */
  287. static BOOL initApplication(HANDLE hInstance,int nCmdShow)
  288. {
  289.     WNDCLASS    wc;
  290.     BOOL        rc;
  291.  
  292.     wc.style = CS_DBLCLKS;
  293.     wc.lpfnWndProc = MainWndproc;
  294.     wc.cbClsExtra = 0;
  295.     wc.cbWndExtra = 0;
  296.     wc.hInstance = hInstance;
  297.     wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);    /* generic icon */
  298.     wc.hCursor = LoadCursor(NULL,IDC_ARROW);
  299.     wc.hbrBackground = GetStockObject(BLACK_BRUSH);
  300.     wc.lpszMenuName =  NULL;
  301.     wc.lpszClassName = "WinTkMesa3DfxClass";
  302.     rc = RegisterClass(&wc);
  303.     if(!rc)
  304.         return(FALSE);
  305.     hMainInstance = hInstance;
  306.     return(TRUE);
  307. } /* initApplication */
  308.  
  309. /*
  310.  * WinMain
  311.  */
  312. int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
  313.                    LPSTR lpCmdLine,int nCmdShow)
  314. {
  315.     int            argc;
  316.     char        **argv;
  317.     extern int    main(int argc,char **argv);
  318.  
  319.     if(!initApplication(hInstance,nCmdShow))
  320.         return(FALSE);
  321.     argv = commandLineToArgv(lpCmdLine,&argc);
  322.     main(argc,argv);
  323.     if(hWndMain)
  324.     {
  325.         DestroyWindow(hWndMain);
  326.         hWndMain = 0;
  327.     }
  328.     return(FALSE);
  329. } /* WinMain */
  330.  
  331. /*
  332.  * Converts lpCmdLine to WinMain into argc, argv
  333.  */
  334. char **commandLineToArgv(LPSTR lpCmdLine,int *pArgc)
  335. {
  336.     char    *p,*pEnd;
  337.     int        argc = 0;
  338.  
  339.     argvbuf[argc++] = fakeName;
  340.     if(lpCmdLine == NULL)
  341.     {
  342.         *pArgc = argc;
  343.         return(argvbuf);
  344.     }
  345.     strcpy(cmdLineBuffer,lpCmdLine);
  346.     p = cmdLineBuffer;
  347.     pEnd = p + strlen(cmdLineBuffer);
  348.     if(pEnd >= &cmdLineBuffer[1022])
  349.         pEnd = &cmdLineBuffer[1022];
  350.     while(1)
  351.     {
  352.         /* skip over white space */
  353.         while(*p == ' ')
  354.             p++;
  355.         if(p >= pEnd)
  356.             break;
  357.         argvbuf[argc++] = p;
  358.         if(argc >= 32)
  359.             break;
  360.         /* skip till there's a 0 or a white space */
  361.         while(*p && (*p != ' '))
  362.             p++;
  363.         if(*p == ' ')
  364.             *p++ = 0;
  365.     }
  366.     *pArgc = argc;
  367.     return(argvbuf);
  368. }
  369.  
  370. int _tkkbhit(void)
  371. {
  372.     MSG        msg;
  373.  
  374.     if(qhead != qtail)
  375.         return(1);
  376.     while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  377.     {
  378.         TranslateMessage(&msg);
  379.         DispatchMessage(&msg);      /* this might change qhead */
  380.         if(qhead != qtail)
  381.             return(1);
  382.     }
  383.     return(0);
  384. }
  385.  
  386. char _tkgetch(void)
  387. {
  388.     MSG        msg;
  389.     char    rv;
  390.  
  391.     if(qtail != qhead)
  392.     {
  393.         rv = queue[qtail++];
  394.         qtail &= 255;
  395.         return(rv);
  396.     }
  397.     while(GetMessage(&msg,NULL,0,0))
  398.     {
  399.         TranslateMessage(&msg);
  400.         DispatchMessage(&msg);
  401.         if(qtail != qhead)
  402.         {
  403.             rv = queue[qtail++];
  404.             qtail &= 255;
  405.             return(rv);
  406.         }
  407.     }
  408.     /* Should never get here!! */
  409.     /* printf("Bad exit..\n"); */
  410.     /* fflush(stdout); */
  411. }
  412.  
  413. #endif
  414.  
  415. void tkExec(void)
  416. {
  417.     static int firsttime=1;
  418.     int key;
  419.     int ch;
  420.     GLenum mask=0;
  421.  
  422. #ifdef __linux__
  423.     if (firsttime) {
  424.         if (ReshapeFunc)
  425.             (*ReshapeFunc)(width, height);
  426.  
  427.         tty_open_nonblock ();
  428.         firsttime = 0;
  429.         ch = 0;
  430.     }
  431.  
  432.     while (ch!=0x1b) {
  433.        /* TODO: block on tty_read() if there's no idle loop! */
  434.        key = tty_read ( &ch );
  435.                   
  436.        if ( key >= 0 ) {
  437.           ch &= 0xFF;
  438. #else
  439.     if(ReshapeFunc && firsttime) {
  440.        (*ReshapeFunc)(width,height);
  441.        firsttime=0;
  442.        ch=0;
  443.     }
  444.  
  445.     while (ch!=27) {
  446.        if(_tkkbhit()) {
  447.           ch = _tkgetch();
  448.  
  449.           if(KeyDownFunc) {
  450. #endif
  451.                 switch(ch) {
  452.                     case ' ':
  453.                         key = TK_SPACE;
  454.                         break;
  455.                     case '1':
  456.                         key = TK_1;
  457.                         break;
  458.                     case '2':
  459.                         key = TK_2;
  460.                         break;
  461.                     case '3':
  462.                         key = TK_3;
  463.                         break;
  464.                     case '4':
  465.                         key = TK_4;
  466.                         break;
  467.                     case '5':
  468.                         key = TK_5;
  469.                         break;
  470.                     case '6':
  471.                         key = TK_6;
  472.                         break;
  473.                     case '7':
  474.                         key = TK_7;
  475.                         break;
  476.                     case '8':
  477.                         key = TK_8;
  478.                         break;
  479.                     case '9':
  480.                         key = TK_9;
  481.                         break;
  482.                     case '0':
  483.                         key = TK_0;
  484.                         break;
  485.                     case 'a':
  486.                         key = TK_a;
  487.                         break;
  488.                     case 'b':
  489.                         key = TK_b;
  490.                         break;
  491.                     case 'c':
  492.                         key = TK_c;
  493.                         break;
  494.                     case 'd':
  495.                         key = TK_d;
  496.                         break;
  497.                     case 'e':
  498.                         key = TK_e;
  499.                         break;
  500.                     case 'f':
  501.                         key = TK_f;
  502.                         break;
  503.                     case 'g':
  504.                         key = TK_g;
  505.                         break;
  506.                     case 'h':
  507.                         key = TK_h;
  508.                         break;
  509.                     case 'i':
  510.                         key = TK_i;
  511.                         break;
  512.                     case 'j':
  513.                         key = TK_j;
  514.                         break;
  515.                     case 'k':
  516.                         key = TK_k;
  517.                         break;
  518.                     case 'l':
  519.                         key = TK_l;
  520.                         break;
  521.                     case 'm':
  522.                         key = TK_m;
  523.                         break;
  524.                     case 'n':
  525.                         key = TK_n;
  526.                         break;
  527.                     case 'o':
  528.                         key = TK_o;
  529.                         break;
  530.                     case 'p':
  531.                         key = TK_p;
  532.                         break;
  533.                     case 'q':
  534.                         key = TK_q;
  535.                         break;
  536.                     case 'r':
  537.                         key = TK_r;
  538.                         break;
  539.                     case 's':
  540.                         key = TK_s;
  541.                         break;
  542.                     case 't':
  543.                         key = TK_t;
  544.                         break;
  545.                     case 'u':
  546.                         key = TK_u;
  547.                         break;
  548.                     case 'v':
  549.                         key = TK_v;
  550.                         break;
  551.                     case 'w':
  552.                         key = TK_w;
  553.                         break;
  554.                     case 'x':
  555.                         key = TK_x;
  556.                         break;
  557.                     case 'y':
  558.                         key = TK_y;
  559.                         break;
  560.                     case 'z':
  561.                         key = TK_z;
  562.                         break;
  563.                     case 'A':
  564.                         key = TK_A;
  565.                         break;
  566.                     case 'B':
  567.                         key = TK_B;
  568.                         break;
  569.                     case 'C':
  570.                         key = TK_C;
  571.                         break;
  572.                     case 'D':
  573.                         key = TK_D;
  574.                         break;
  575.                     case 'E':
  576.                         key = TK_E;
  577.                         break;
  578.                     case 'F':
  579.                         key = TK_F;
  580.                         break;
  581.                     case 'G':
  582.                         key = TK_G;
  583.                         break;
  584.                     case 'H':
  585.                         key = TK_H;
  586.                         break;
  587.                     case 'I':
  588.                         key = TK_I;
  589.                         break;
  590.                     case 'J':
  591.                         key = TK_J;
  592.                         break;
  593.                     case 'K':
  594.                         key = TK_K;
  595.                         break;
  596.                     case 'L':
  597.                         key = TK_L;
  598.                         break;
  599.                     case 'M':
  600.                         key = TK_M;
  601.                         break;
  602.                     case 'N':
  603.                         key = TK_N;
  604.                         break;
  605.                     case 'O':
  606.                         key = TK_O;
  607.                         break;
  608.                     case 'P':
  609.                         key = TK_P;
  610.                         break;
  611.                     case 'Q':
  612.                         key = TK_Q;
  613.                         break;
  614.                     case 'R':
  615.                         key = TK_R;
  616.                         break;
  617.                     case 'S':
  618.                         key = TK_S;
  619.                         break;
  620.                     case 'T':
  621.                         key = TK_T;
  622.                         break;
  623.                     case 'U':
  624.                         key = TK_U;
  625.                         break;
  626.                     case 'V':
  627.                         key = TK_V;
  628.                         break;
  629.                     case 'W':
  630.                         key = TK_W;
  631.                         break;
  632.                     case 'X':
  633.                         key = TK_X;
  634.                         break;
  635.                     case 'Y':
  636.                         key = TK_Y;
  637.                         break;
  638.                     case 'Z':
  639.                         key = TK_Z;
  640.                         break;
  641. #ifdef __linux__
  642.                                         case 0x1b:
  643.                                                 key = tty_read ( &ch );
  644.                                                 if (key < 0)
  645.                                                 {
  646.                                                     key = TK_ESCAPE;
  647.                                                     break;
  648.                                                 }
  649.  
  650.                                                 key = tty_read ( &ch );
  651.                                                 if (key < 0)
  652.                                                     break;
  653.  
  654.                                                 ch &= 0xFF;
  655.                                                 switch ( ch ) {
  656.                                                         case 'A':
  657.                                                                 key = TK_UP;
  658.                                                                 break;
  659.                                                         case 'B':
  660.                                                                 key = TK_DOWN;
  661.                                                                 break;
  662.                                                         case 'C':
  663.                                                                 key = TK_RIGHT;
  664.                                                                 break;
  665.                                                         case 'D':
  666.                                                                 key = TK_LEFT;
  667.                                                                 break;
  668.                                                 }
  669.                                                 break;
  670. #else
  671.                     case 27:
  672.                         key = TK_ESCAPE;
  673.                         break;
  674.                     case 0:
  675.                     case 0xe0:
  676.                         ch = _tkgetch();
  677.                         switch( ch ) {
  678.                             case 'P':
  679.                                 key = TK_DOWN;
  680.                                 break;
  681.                             case 'M':
  682.                                 key = TK_RIGHT;
  683.                                 break;
  684.                             case 'K':
  685.                                 key = TK_LEFT;
  686.                                 break;
  687.                             case 'H':
  688.                                 key = TK_UP;
  689.                                 break;
  690.                         }
  691.                         break;
  692. #endif
  693.                     /*default:
  694.                         printf("\n====%x %c %d\n",ch,ch,ch);
  695.                         break;*/
  696.                     }
  697.                     (*KeyDownFunc)(key,mask);
  698.                     key = 0;
  699.                 }
  700. #ifndef __linux__
  701.             }
  702. #endif
  703.  
  704.             if (IdleFunc)
  705.                 (*IdleFunc)();
  706.  
  707.             if(DisplayFunc)
  708.                 (*DisplayFunc)();
  709.         }
  710.  
  711. }
  712.  
  713.  
  714.  
  715. /******************************************************************************/
  716.  
  717. void tkExposeFunc(void (*Func)(int, int))
  718. {
  719.  
  720.     ExposeFunc = Func;
  721. }
  722.  
  723. /******************************************************************************/
  724.  
  725. void tkReshapeFunc(void (*Func)(int, int))
  726. {
  727.  
  728.     ReshapeFunc = Func;
  729. }
  730.  
  731. /******************************************************************************/
  732.  
  733. void tkDisplayFunc(void (*Func)(void))
  734. {
  735.  
  736.     DisplayFunc = Func;
  737. }
  738.  
  739. /******************************************************************************/
  740.  
  741. void tkKeyDownFunc(GLenum (*Func)(int, GLenum))
  742. {
  743.  
  744.     KeyDownFunc = Func;
  745. }
  746.  
  747. /******************************************************************************/
  748.  
  749. void tkMouseDownFunc(GLenum (*Func)(int, int, GLenum))
  750. {
  751.  
  752.     MouseDownFunc = Func;
  753. }
  754.  
  755. /******************************************************************************/
  756.  
  757. void tkMouseUpFunc(GLenum (*Func)(int, int, GLenum))
  758. {
  759.  
  760.     MouseUpFunc = Func;
  761. }
  762.  
  763. /******************************************************************************/
  764.  
  765. void tkMouseMoveFunc(GLenum (*Func)(int, int, GLenum))
  766. {
  767.  
  768.     MouseMoveFunc = Func;
  769. }
  770.  
  771. /******************************************************************************/
  772.  
  773. void tkIdleFunc(void (*Func)(void))
  774. {
  775.  
  776.     IdleFunc = Func;
  777. }
  778.  
  779. /******************************************************************************/
  780.  
  781. void tkInitDisplayMode(GLenum type)
  782. {
  783. #ifdef WIN32
  784.     if(!hMainInstance)
  785.         initApplication(0,FALSE);
  786. #endif
  787.         WindowType = type;
  788. }
  789.  
  790. void tkInitPosition(int x, int y, int w, int h)
  791. {
  792.    startx = x;
  793.    starty = y;
  794.  
  795. #ifdef __linux__
  796.    /* larger sizes don't seem to work */
  797.    if (w>640)
  798.       w = 640;
  799.    if (h>480)
  800.       h = 480;
  801. #endif
  802.    width=w;
  803.    height=h;
  804. }
  805.  
  806. void tkSwapBuffers(void)
  807. {
  808.     fxMesaSwapBuffers();
  809. }
  810.  
  811. void tkQuit(void)
  812. {
  813.     fxMesaDestroyContext(fc);
  814. #ifdef WIN32
  815.     if(hWndMain)
  816.         DestroyWindow(hWndMain);
  817.     hWndMain = 0;
  818. #endif
  819.     exit(0);
  820. }
  821.  
  822. GLenum tkInitWindow(char *title)
  823. {
  824. #define NUM_RES 3
  825.  
  826.    static GrScreenResolution_t res[NUM_RES+1] = {
  827.       GR_RESOLUTION_512x384,
  828.       GR_RESOLUTION_640x480,
  829.       GR_RESOLUTION_800x600,
  830.       GR_RESOLUTION_NONE};
  831.    static int xres[NUM_RES]={512,640,800};
  832.    static int yres[NUM_RES]={384,480,600};
  833.    int i;
  834.    GLuint window;
  835.    GLint attribs[100];
  836.  
  837.    /* Build fxMesa attribute list */
  838.    i = 0;
  839.    if (TK_IS_DOUBLE(WindowType)) {
  840.       attribs[i] = FXMESA_DOUBLEBUFFER;
  841.       i++;
  842.    }
  843.    if (TK_HAS_DEPTH(WindowType)) {
  844.       attribs[i] = FXMESA_DEPTH_SIZE;
  845.       i++;
  846.       attribs[i] = 1;
  847.       i++;
  848.    }
  849.    if (TK_HAS_ALPHA(WindowType)) {
  850.       attribs[i] = FXMESA_ALPHA_SIZE;
  851.       i++;
  852.       attribs[i] = 1;
  853.       i++;
  854.    }
  855.    if (TK_HAS_ACCUM(WindowType)) {
  856.       attribs[i] = FXMESA_ACCUM_SIZE;
  857.       i++;
  858.       attribs[i] = 1;
  859.       i++;
  860.    }
  861.    if (TK_HAS_STENCIL(WindowType)) {
  862.       attribs[i] = FXMESA_STENCIL_SIZE;
  863.       i++;
  864.       attribs[i] = 1;
  865.       i++;
  866.    }
  867.    attribs[i] = FXMESA_NONE;  /* end of list */
  868.  
  869.    /* find smallest screen size >= requested size */
  870.    for(i=0;i<NUM_RES;i++)
  871.       if((width<=xres[i]) && (height<=yres[i]))
  872.          break;
  873.  
  874. #ifdef __WIN32__
  875.    if(i == NUM_RES)
  876.       fullscreen = GL_FALSE;
  877.    hWndMain = CreateWindowEx(WS_EX_APPWINDOW,"WinTkMesa3DfxClass",title,
  878.                              WS_OVERLAPPED | WS_CAPTION  | WS_THICKFRAME |
  879.                              WS_MAXIMIZEBOX | WS_MINIMIZEBOX | 
  880.                              WS_VISIBLE |    /* so we don't have to call ShowWindow */
  881.                              WS_POPUP |      /* non-app window */
  882.                              WS_SYSMENU,     /* so we get an icon in the tray */
  883.                              startx,starty,
  884.                              fullscreen ? 200 : width,
  885.                              fullscreen ? 200 : height,
  886.                              NULL,NULL,hMainInstance,NULL);
  887.    if(!hWndMain)
  888.       return(GL_FALSE);
  889.    ShowWindow(hWndMain,SW_NORMAL);
  890.    UpdateWindow(hWndMain);
  891.    window = (GLuint)(fullscreen ? 0 : hWndMain);
  892. #else
  893.    /* linux */
  894.    if(i == NUM_RES)
  895.       i = NUM_RES-1;  /* largest possible */
  896.    window = 0;
  897. #endif
  898.    width = xres[i];
  899.    height = yres[i];
  900.    fc = fxMesaCreateContext(window, res[i], GR_REFRESH_75Hz, attribs);
  901.    if(!fc) {
  902.       printf("Error creating fxMesa context\n");
  903.       return(GL_FALSE);
  904.    }
  905.    fxMesaMakeCurrent(fc);
  906.    return(GL_TRUE);
  907. }
  908.  
  909. void tkSetOneColor(int index, float r, float g, float b)
  910. {
  911. }
  912.  
  913. void tkSetGreyRamp(void)
  914. {
  915. }
  916.  
  917. void tkSetRGBMap( int Size, float *Values )
  918. {
  919. }
  920.  
  921. GLint tkGetColorMapSize(void)
  922. {
  923.     return 256;
  924. }
  925.  
  926. #else
  927.  
  928. void tk_dummy_func(void)
  929. {
  930. }
  931.  
  932. #endif /*defined(FX)*/
  933.