home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 1 / CD_Magazyn_EXEC_nr_1.iso / Gry / battalion.lha / Battalion / source / tk_amiga.c < prev    next >
C/C++ Source or Header  |  1999-12-23  |  23KB  |  807 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.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  26.  */
  27.  
  28. /* Mesa tkAmiga by Stefan Z (d94sz@efd.lth.se)*/
  29.  
  30. /*
  31. History:
  32.  
  33. 1.0 960315 Now almost evetything is implemented
  34. 1.1 960425 Fixed problem with double closeclicks (Thanx to Daniel Jönsson)
  35. 1.2 960731 Modified due to api change in AmigaMesa
  36. 1.3 Implemented div. Input modifier and changed windowhandling (Georg 'Wulf' Krämer)
  37.  
  38. 2.0 Modifications for vbcc version and StormMesa by Frank Wille
  39.  
  40. TODO:
  41. Exposefunc
  42. */
  43.  
  44. #undef USE_CLIP_LAYER
  45.  
  46.  
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49. #include <string.h>
  50.  
  51. #include <exec/libraries.h>
  52. #include <exec/io.h>
  53. #include <devices/inputevent.h>
  54. #include <intuition/intuition.h>
  55.  
  56. #ifdef __GNUC__
  57. #include <inline/exec.h>
  58. #include <inline/intuition.h>
  59. #include <inline/graphics.h>
  60. #ifdef USE_CLIP_LAYER
  61. #include <inline/layers.h>
  62. #endif
  63.  
  64. #else
  65. #include <proto/exec.h>
  66. #include <proto/intuition.h>
  67. #include <proto/graphics.h>
  68. #include <proto/console.h>
  69. #ifdef USE_CLIP_LAYER
  70. #include <proto/layers.h>
  71. #endif
  72. #endif
  73.  
  74. #include "tk_amiga.h"
  75. #include <GL/Amigamesa.h>
  76.  
  77.  
  78.  
  79. #define static
  80.  
  81. #if defined(__cplusplus) || defined(c_plusplus)
  82. #define class c_class
  83. #endif
  84.  
  85. #if DBG
  86. #define TKASSERT(x)                                     \
  87. if ( !(x) ) {                                           \
  88.         PrintMessage("%s(%d) Assertion failed %s\n",        \
  89.                 __FILE__, __LINE__, #x);                        \
  90. }
  91. #else
  92. #define TKASSERT(x)
  93. #endif  /* DBG */
  94.  
  95. /* Some Bitmasks for Amigaevents */
  96. #define ControlMask         (IEQUALIFIER_CONTROL)
  97. #define ShiftMask           (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT)
  98. #define MousePressedMask    (SELECTDOWN | MENUDOWN | MIDDLEDOWN)
  99.  
  100. /******************************************************************************/
  101.  
  102. struct wnd 
  103.         {
  104.         int x, y, width, height;
  105.         GLenum type;
  106.         struct amigamesa_context *context;
  107.         };
  108.  
  109. struct wnd win={0,0,100,100,TK_INDEX,NULL};
  110.  
  111.  
  112. struct Screen *screen = NULL;
  113. struct Window *tkhwnd = NULL;
  114. struct Library *ConsoleDevice = NULL;
  115. static struct IOStdReq *conio;
  116.  
  117. #ifdef USE_CLIP_LAYER
  118. struct Region *tkclipreg = NULL;
  119. #endif
  120.  
  121. /* Local prototypes */
  122. struct Region *clipWindow(struct Window *win,
  123.         LONG minX, LONG minY, LONG maxX, LONG maxY);
  124. struct Region *clipWindowToBorders(struct Window *win);
  125.  
  126. /* key map */
  127. static char keymap[128] = { 0 };  /* state of all raw keys */
  128.  
  129.  
  130. GLboolean tkPopupEnable = TRUE;
  131.  
  132. /* Fixed palette support.  */
  133. /*
  134. #define BLACK   PALETTERGB(0,0,0)
  135. #define WHITE   PALETTERGB(255,255,255)
  136. #define NUM_STATIC_COLORS   (COLOR_BTNHIGHLIGHT - COLOR_SCROLLBAR + 1)
  137. */
  138. static void (*ExposeFunc)(int, int)              = NULL;
  139. static void (*ReshapeFunc)(GLsizei, GLsizei)     = NULL;
  140. static void (*DisplayFunc)(void)                 = NULL;
  141. static GLenum (*KeyDownFunc)(int, GLenum)        = NULL;
  142. static GLenum (*KeyUpFunc)(int, GLenum)          = NULL;
  143. static GLenum (*MouseDownFunc)(int, int, GLenum) = NULL;
  144. static GLenum (*MouseUpFunc)(int, int, GLenum)   = NULL;
  145. static GLenum (*MouseMoveFunc)(int, int, GLenum) = NULL;
  146. static void (*IdleFunc)(void)                    = NULL;
  147.  
  148. /*
  149.  *  Prototypes for the debugging functions go here
  150.  */
  151.  
  152. #define DBGFUNC 0
  153. #if DBGFUNC
  154.  
  155. static void DbgPrintf( const char *Format, ... );
  156. static void pwi( void );
  157. static void pwr(RECT *pr);
  158. /*static void ShowPixelFormat(HDC hdc);*/
  159.  
  160. #endif
  161.  
  162. #ifdef USE_CLIP_LAYER
  163. /* Get from clipping example of the RKM */
  164. /*
  165. ** clipWindow()
  166. ** Clip a window to a specified rectangle (given by upper left and
  167. ** lower right corner.)  the removed region is returned so that it
  168. ** may be re-installed later.
  169. */
  170. struct Region *clipWindow(struct Window *win,
  171.         LONG minX, LONG minY, LONG maxX, LONG maxY)
  172. {
  173. struct Region    *new_region;
  174. struct Rectangle  my_rectangle;
  175.  
  176. /* set up the limits for the clip */
  177. my_rectangle.MinX = minX;
  178. my_rectangle.MinY = minY;
  179. my_rectangle.MaxX = maxX;
  180. my_rectangle.MaxY = maxY;
  181.  
  182. /* get a new region and OR in the limits. */
  183. if (NULL != (new_region = NewRegion()))
  184.         {
  185.         if (FALSE == OrRectRegion(new_region, &my_rectangle))
  186.                 {
  187.                 DisposeRegion(new_region);
  188.                 new_region = NULL;
  189.                 }
  190.         }
  191.  
  192. /* Install the new region, and return any existing region.
  193. ** If the above allocation and region processing failed, then
  194. ** new_region will be NULL and no clip region will be installed.
  195. */
  196. return(InstallClipRegion(win->WLayer, new_region));
  197. }
  198.  
  199. /*
  200. ** clipWindowToBorders()
  201. ** clip a window to its borders.
  202. ** The removed region is returned so that it may be re-installed later.
  203. */
  204. struct Region *clipWindowToBorders(struct Window *win)
  205. {
  206. return(clipWindow(win, win->BorderLeft, win->BorderTop,
  207.         win->Width - win->BorderRight - 1, win->Height - win->BorderBottom - 1));
  208. }
  209. #endif
  210.  
  211. float tkRGBMap[8][3] = 
  212.         {
  213.         {   0, 0, 0 },
  214.         {   1, 0, 0 },
  215.         {   0, 1, 0 },
  216.         {   1, 1, 0 },
  217.         {   0, 0, 1 },
  218.         {   1, 0, 1 },
  219.         {   0, 1, 1 },
  220.         {   1, 1, 1 }
  221.         };
  222.  
  223. int atk_setIDCMPs(void)
  224. {
  225.     int mask;
  226.     mask=IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE;
  227.     if (ReshapeFunc)
  228.         mask |=IDCMP_NEWSIZE;
  229.     if (KeyDownFunc)
  230.         mask |=IDCMP_RAWKEY;
  231.     if (MouseDownFunc||MouseUpFunc)
  232.         mask |=IDCMP_MOUSEBUTTONS;
  233.     if (MouseMoveFunc)
  234.         mask |= IDCMP_MOUSEMOVE;
  235.  
  236.     return(mask);
  237. }
  238.  
  239. /* TODO (*ExposeFunc)(int, int)   */
  240.  
  241. void atk_modifyIDCMP(void)
  242. {
  243.     if(tkhwnd)
  244.     {
  245.         ModifyIDCMP( tkhwnd, atk_setIDCMPs() );
  246.     }
  247. }
  248.  
  249.  
  250. int atk_SpecialKeyConv(int code)
  251. {
  252.     int key = 0;
  253.  
  254.     switch (code) {
  255.         case 0x40:        key = TK_SPACE;     break;
  256.         case 0x41:        key = TK_BACKSPACE; break;
  257.         case 0x42:        key = TK_TAB;       break;
  258.         case 0x43:
  259.         case 0x44:        key = TK_RETURN;    break;
  260.         case 0x45:        key = TK_ESCAPE;    break;
  261.         case 0x46:        key = TK_DEL;       break;
  262.         case CURSORLEFT:  key = TK_LEFT;      break;
  263.         case CURSORRIGHT: key = TK_RIGHT;     break;
  264.         case CURSORUP:    key = TK_UP;        break;
  265.         case CURSORDOWN:  key = TK_DOWN;      break;
  266.         case 0x60:        key = TK_SHIFT_L;   break;
  267.         case 0x61:        key = TK_SHIFT_R;   break;
  268.         case 0x63:        key = TK_CONTROL_L; break;
  269.         case 0x64:        key = TK_ALT_L;     break;
  270.         case 0x65:        key = TK_ALT_R;     break;
  271.     }
  272.     return (key);
  273. }
  274.  
  275.  
  276. int atk_RawKeyConv(UWORD code,UWORD qual)
  277. {
  278.     static struct InputEvent ie = {
  279.       NULL,IECLASS_RAWKEY,0,0,0
  280.     };
  281.     int cnt,key = 0;
  282.     UBYTE buf[8];
  283.  
  284.     ie.ie_Code = code;
  285.     ie.ie_Qualifier = qual;
  286.     ie.ie_position.ie_addr = NULL;  /* ??? @@@@ */
  287.     if (RawKeyConvert(&ie,buf,8,NULL) == 1)
  288.         return ((unsigned)buf[0]);
  289.     return (0);
  290. }
  291.  
  292.  
  293. GLenum atk_SendKeyEvents()
  294. {
  295.     int i,key;
  296.     char code;
  297.     UWORD qual;
  298.     GLenum mask,redraw=GL_FALSE;
  299.  
  300.     for (i=0; i<0x68; i++) {
  301.         if (code = keymap[i]) {
  302.             mask = 0;
  303.             if (i < 0x40) {
  304.                 qual = 0;
  305.                 if (code & 2) {
  306.                     qual |= IEQUALIFIER_LSHIFT;
  307.                     mask |= TK_SHIFT;
  308.                 }
  309.                 if (code & 4) {
  310.                     qual |= IEQUALIFIER_CONTROL;
  311.                     mask |= TK_CONTROL;
  312.                 }
  313.                 if (!(key = atk_RawKeyConv((UWORD)i,qual)))
  314.                     key = atk_SpecialKeyConv(i);
  315.             }
  316.             else
  317.                 key = atk_SpecialKeyConv(i);
  318.  
  319.             if (code & 16) {
  320.                 /* key release event */
  321.                 keymap[i] = 0;
  322.                 if (key && KeyUpFunc)
  323.                     if ((*KeyUpFunc)(key,mask) == GL_TRUE)
  324.                         redraw = GL_TRUE;
  325.             }
  326.             else if (key && KeyDownFunc) {
  327.                 if ((*KeyDownFunc)(key,mask) == GL_TRUE)
  328.                     redraw = GL_TRUE;
  329.             }
  330.         }
  331.     }
  332.     return (redraw);
  333. }
  334.  
  335.  
  336. /***************************************************************
  337.  *                                                             *
  338.  *  Exported Functions go here                                 *
  339.  *                                                             *
  340.  ***************************************************************/
  341.  
  342.  
  343. void tkNewCursor(GLint id, GLubyte *shapeBuf, GLubyte *maskBuf,
  344.                  GLenum fgColor, GLenum bgColor, GLint hotX, GLint hotY)
  345. {
  346. /* cursor.c */ 
  347. }
  348.  
  349. void tkSetCursor(GLint id)
  350. {
  351. /* cursor.s*/
  352. }
  353.  
  354. void tkErrorPopups(GLboolean bEnable)
  355. {
  356.     tkPopupEnable = bEnable;
  357. }
  358.  
  359. void tkCloseWindow(void)
  360. {
  361.     if (ConsoleDevice) {
  362.         CloseDevice((struct IORequest *)conio);
  363.         DeleteMsgPort(conio->io_Message.mn_ReplyPort);
  364.         DeleteIORequest(conio);
  365.         ConsoleDevice = NULL;
  366.     }
  367.  
  368.     if (win.context) 
  369.     {
  370.         AmigaMesaDestroyContext(win.context);
  371.         win.context=NULL;
  372.     }
  373. #ifdef USE_CLIP_LAYER
  374.     if (tkclipreg)
  375.     {
  376.         tkclipreg = InstallClipRegion(tkhwnd->WLayer, tkclipreg);
  377.         DisposeRegion(tkclipreg);
  378.         tkclipreg = NULL;
  379.     }
  380. #endif
  381.     if (tkhwnd)
  382.     {
  383.         CloseWindow(tkhwnd);
  384.         tkhwnd=NULL;
  385.     }
  386. }
  387.  
  388.  
  389. void tkExec(void)
  390. {
  391.     struct IntuiMessage *msg;
  392.     BOOL done = FALSE;
  393.     BOOL press=FALSE;
  394.     BOOL rawkey = FALSE;
  395.     int key,id;
  396.     /* Redraw handling changed by Wulf 11. Aug. 96 to ensure the
  397.        same handling under all systems */
  398.     GLenum Redraw=GL_FALSE;
  399.  
  400.     for (key=0; key<128; keymap[key++]=0);  /* reset keymap */
  401.  
  402.     if (ReshapeFunc)
  403.         (*ReshapeFunc)(tkhwnd->Width-tkhwnd->BorderLeft-tkhwnd->BorderRight-2,
  404.                        tkhwnd->Height-tkhwnd->BorderTop-tkhwnd->BorderBottom-2);
  405.  
  406.     if (DisplayFunc)
  407.         (*DisplayFunc)();
  408.  
  409.  
  410.     while (!done)
  411.     {
  412.         if (msg = (struct IntuiMessage *)GetMsg(tkhwnd->UserPort))
  413.         {
  414.             id=msg->Class;
  415.             /* after ReplyMsg, you are nolonger allowed to use msg !*/
  416.             switch (id)
  417.             {
  418.                 case IDCMP_NEWSIZE:
  419.                     /* Sizes should be adjusted by border, but painting isn't adjusted :-( */
  420.                     win.width=  tkhwnd->Width-tkhwnd->BorderLeft-tkhwnd->BorderRight-2;
  421.                     win.height= tkhwnd->Height-tkhwnd->BorderTop-tkhwnd->BorderBottom-2;
  422. #ifdef USE_CLIP_LAYER
  423.                     if (tkclipreg) /* Get rid of last clipping region */
  424.                     {
  425.                         DisposeRegion(InstallClipRegion(msg->IDCMPWindow->WLayer,NULL));
  426.                     }
  427.                     clipWindowToBorders(msg->IDCMPWindow);
  428. #endif
  429.                     ReplyMsg((struct Message *)msg);
  430.                     if (ReshapeFunc)
  431.                         (*ReshapeFunc)(win.width, win.height);
  432.                     Redraw = GL_TRUE;
  433.                     break;
  434.  
  435.                 case IDCMP_RAWKEY:
  436.                     {
  437.                         char k = 1;
  438.  
  439.                         key = (int)(msg->Code & 0x7f);
  440.                         if (key < 0x40) {
  441.                             if (msg->Qualifier & ShiftMask)
  442.                                 k |= 2;
  443. #if 0 /* don't want CTRL-keys for Battalion! */
  444.                             if (msg->Qualifier & ControlMask)
  445.                                 k |= 4;
  446. #endif
  447.                         }
  448.                         if (msg->Code & IECODE_UP_PREFIX)
  449.                             keymap[key] |= 16;  /* release flag */
  450.                         else
  451.                             keymap[key] = k;
  452.                         ReplyMsg((struct Message *)msg);
  453.                         rawkey = TRUE;
  454.                     }
  455.                     break;
  456.  
  457.                 case IDCMP_MOUSEMOVE:
  458.                     if (MouseMoveFunc) {
  459.                         int x = msg->MouseX,y = msg->MouseY;
  460.                         ReplyMsg((struct Message *)msg);
  461.                         Redraw = (*MouseMoveFunc)(x,y,press);
  462.                     } else
  463.                         ReplyMsg((struct Message *)msg);
  464.                     break;                  
  465.  
  466.                 case IDCMP_MOUSEBUTTONS:
  467.                     /* Buttonhandling changed phx 22.12.99 */
  468.                     {
  469.                         GLenum mask = 0;
  470.                         int x = msg->MouseX, y = msg->MouseY;
  471.                         switch (msg->Code & 0x7f)
  472.                         {
  473.                             case IECODE_LBUTTON:
  474.                                 mask |= TK_LEFTBUTTON; break;
  475.                             case IECODE_MBUTTON:
  476.                                 mask |= TK_MIDDLEBUTTON; break;
  477.                             case IECODE_RBUTTON:
  478.                                 mask |= TK_RIGHTBUTTON; break;
  479.                         }
  480.                         if (msg->Qualifier & ControlMask)
  481.                             mask |= TK_CONTROL;
  482.                         if (msg->Qualifier & ShiftMask)
  483.                             mask |= TK_SHIFT;
  484.                         if (msg->Code & IECODE_UP_PREFIX)
  485.                         {
  486.                             if (MouseUpFunc)
  487.                             {
  488.                                 ReplyMsg((struct Message *)msg);
  489.                                 Redraw = (*MouseUpFunc)(x,y,mask);
  490.                             } else
  491.                                 ReplyMsg((struct Message *)msg);
  492.                             press=0;
  493.                         }
  494.                         else
  495.                         {
  496.                             press=mask;
  497.                             if (MouseDownFunc) {
  498.                                 ReplyMsg((struct Message *)msg);
  499.                                 Redraw = (*MouseDownFunc)(x,y,mask);
  500.                             } else
  501.                                 ReplyMsg((struct Message *)msg);
  502.                         }
  503.                     }
  504.                     break;
  505.  
  506.                 case IDCMP_REFRESHWINDOW:   /* Not entierly tested! Wulf 11.08.96 */
  507.                     BeginRefresh(msg->IDCMPWindow);  /* Refresh Gadgets */
  508.                     EndRefresh(msg->IDCMPWindow, TRUE);
  509.                     ReplyMsg((struct Message *)msg);
  510.                     if (ExposeFunc)
  511.                         (*ExposeFunc)(win.width, win.height);
  512.                     Redraw = GL_TRUE;
  513.                     break;
  514.  
  515.                 case IDCMP_CLOSEWINDOW:
  516.                     ReplyMsg((struct Message *)msg);
  517.                     done = TRUE;
  518.                     break;
  519.  
  520.                 default:
  521.                     ReplyMsg((struct Message *)msg);
  522.                     break;
  523.             }
  524.         }
  525.  
  526. #if 0
  527.         if (rawkey) {
  528.             rawkey = FALSE;
  529.         }
  530.         else {
  531. #endif
  532.             if (atk_SendKeyEvents() == GL_TRUE)
  533.                 Redraw = GL_TRUE;
  534.  
  535.             /* TODO Fill this with tests and call apropriate functions */
  536.             if (IdleFunc)
  537.             {
  538.                 (*IdleFunc)();
  539.                 Redraw = GL_TRUE;
  540.             }
  541.             if ((Redraw==GL_TRUE) && DisplayFunc) /* Redraw handling changed by Wulf 11. Aug. 96 */
  542.             {
  543.                 (*DisplayFunc)();
  544.                 Redraw = GL_FALSE;
  545.             }
  546.             if(!done && !IdleFunc)
  547.             {
  548.                 WaitPort(tkhwnd->UserPort);
  549.             }
  550. /*        }*/
  551.     }
  552.     tkQuit();      /* do not return after quit */
  553. }
  554.  
  555.  
  556. void tkExposeFunc(void (*Func)(int, int))
  557. {
  558.     ExposeFunc = Func;
  559.     atk_modifyIDCMP();
  560. }
  561.  
  562. void tkReshapeFunc(void (*Func)(GLsizei, GLsizei))
  563. {
  564.     ReshapeFunc = Func;
  565.     atk_modifyIDCMP();
  566. }
  567.  
  568. void tkDisplayFunc(void (*Func)(void))
  569. {
  570.     DisplayFunc = Func;
  571. }
  572.  
  573. void tkKeyDownFunc(GLenum (*Func)(int, GLenum))
  574. {
  575.     KeyDownFunc = Func;
  576.     atk_modifyIDCMP();
  577. }
  578.  
  579. void tkKeyUpFunc(GLenum (*Func)(int, GLenum))
  580. {
  581.     KeyUpFunc = Func;
  582. }
  583.  
  584. void tkMouseDownFunc(GLenum (*Func)(int, int, GLenum))
  585. {
  586.     MouseDownFunc = Func;
  587.     atk_modifyIDCMP();
  588. }
  589.  
  590. void tkMouseUpFunc(GLenum (*Func)(int, int, GLenum))
  591. {
  592.     MouseUpFunc = Func;
  593.     atk_modifyIDCMP();
  594. }
  595.  
  596. void tkMouseMoveFunc(GLenum (*Func)(int, int, GLenum))
  597. {
  598.     MouseMoveFunc = Func;
  599.     atk_modifyIDCMP();
  600. }
  601.  
  602. void tkIdleFunc(void (*Func)(void))
  603. {
  604.     IdleFunc = Func;
  605. }
  606.  
  607. void tkInitPosition(int x, int y, int width, int height)
  608. {
  609.     win.x=x;
  610.     win.y=y;
  611.     win.width=width;
  612.     win.height=height;
  613. }
  614.  
  615. void tkInitDisplayMode(GLenum type)
  616. {
  617.     win.type = type;
  618. }
  619.  
  620. GLenum tkInitWindow(char *title)
  621. {
  622.     struct MsgPort *conport;
  623.     GLenum   Result  =GL_FALSE,
  624.              RGB_Flag=GL_TRUE,
  625.              DB_Flag =GL_FALSE;
  626.  
  627.     if (!(screen = LockPubScreen("MESA")))
  628.         screen = LockPubScreen(NULL);
  629.     if (screen)
  630.     {
  631.         /* open the window on the public screen */
  632.         tkhwnd = OpenWindowTags(NULL,
  633.                                 WA_Left,  win.x,        WA_Top,    win.x,
  634.                                 WA_InnerWidth, win.width,WA_InnerHeight, win.height,
  635.                                 WA_DragBar,             TRUE,
  636.                                 WA_CloseGadget,         TRUE,
  637.                                 WA_SizeGadget,          TRUE,
  638.                                 WA_DepthGadget,         TRUE,
  639.                                 WA_SmartRefresh,        TRUE,
  640.                                 WA_ReportMouse,         TRUE,
  641.                                 WA_NoCareRefresh,       TRUE,
  642.                                 WA_RMBTrap,             TRUE, /* Detect right mouse events, no Menus */
  643.                                 WA_SizeBBottom,         TRUE,
  644.                                 WA_Activate,            TRUE,
  645.                                 WA_MinWidth,100,        WA_MinHeight,30,
  646.                                 WA_MaxWidth,-1,         WA_MaxHeight,-1,
  647.                                 WA_IDCMP,               atk_setIDCMPs(),
  648.                                 WA_Flags,               WFLG_SIZEGADGET | WFLG_DRAGBAR,
  649.                                 WA_Title,               title,
  650.                                 WA_PubScreen,           screen,
  651.                                 TAG_END);
  652.  
  653.         /* Unlock the screen.  The window now acts as a lock on
  654.         ** the screen, and we do not need the screen after the
  655.         ** window has been closed.  */
  656.         UnlockPubScreen(NULL, screen);
  657.         if (tkhwnd)
  658.         {
  659. #ifdef USE_CLIP_LAYER
  660.             tkclipreg = clipWindowToBorders(tkhwnd);
  661. #endif
  662.             if (win.type & TK_INDEX)
  663.             {
  664.                 RGB_Flag=GL_FALSE;
  665.             }
  666.             if (win.type & TK_DOUBLE)
  667.             {
  668.                 DB_Flag=GL_TRUE;
  669.             }
  670.  
  671.             win.context=AmigaMesaCreateContextTags(
  672.                             AMA_Window,(unsigned long)  tkhwnd,
  673.                             AMA_RastPort,(unsigned long)tkhwnd->RPort,
  674.                             AMA_Screen,(unsigned long)  tkhwnd->WScreen,
  675.                             AMA_RGBMode,                RGB_Flag,
  676.                             AMA_DoubleBuf,              DB_Flag,
  677.                             AMA_NoStencil,              GL_TRUE,
  678.                             AMA_Left,                   tkhwnd->BorderLeft,
  679.                             AMA_Bottom,                 tkhwnd->BorderBottom,
  680.                             AMA_Width,                  win.width,
  681.                             AMA_Height,                 win.height,
  682.                             AMA_Fast,                   GL_TRUE,
  683.                             TAG_DONE,0);
  684.  
  685.             AmigaMesaMakeCurrent(win.context,win.context->buffer);
  686.  
  687.             /* open console.device */
  688.             if (conport = CreateMsgPort()) {
  689.                 if (conio = CreateIORequest(conport,
  690.                                             sizeof(struct IOStdReq))) {
  691.                     if (OpenDevice("console.device",-1,
  692.                                    (struct IORequest *)conio,0) == 0) {
  693.                         ConsoleDevice = (struct Library *)conio->io_Device;
  694.                         Result = GL_TRUE;
  695.                     }
  696.                     else {
  697.                         DeleteIORequest(conio);
  698.                         DeleteMsgPort(conport);
  699.                     }
  700.                 }
  701.                 else
  702.                     DeleteMsgPort(conport);
  703.             }
  704.             if (Result == GL_FALSE)
  705.               printf("Couldn't open console.device!\n");
  706.         }
  707.         else
  708.         {
  709.             printf("Failed to open window.\n");
  710.         }
  711.     }
  712.     return (Result);
  713. }
  714.  
  715.  
  716.  
  717. /******************************************************************************/
  718.  
  719. /*
  720.  * You cannot just call DestroyWindow() here.  The programs do not expect
  721.  * tkQuit() to return;  DestroyWindow() just sends a WM_DESTROY message
  722.  */
  723.  
  724. void tkQuit(void)
  725. {
  726.     tkCloseWindow();
  727.     exit(0);    /*TODO*/
  728. }
  729.  
  730. /******************************************************************************/
  731.  
  732. void tkSetOneColor(int index, float r, float g, float b)
  733. {
  734.     AmigaMesaSetOneColor(win.context,index,r,g,b);
  735. }
  736.  
  737. void tkSetFogRamp(int density, int startIndex)
  738. {
  739. /* TODO */
  740. printf("tkSetFogRamp(%d,%d) TODO\n",density,startIndex);
  741. }
  742.  
  743. void tkSetGreyRamp(void)
  744. {
  745.  /* TODO */
  746. printf("tkSetGreyRamp() TODO\n");
  747.  
  748. }
  749.  
  750. void tkSetRGBMap( int Size, float *Values )
  751. {
  752. /* TODO */
  753. printf("tkSetRGBMap(%d,%f) TODO\n",Size,*Values);
  754. }
  755.  
  756. void tkSetOverlayMap(int size, float *rgb)
  757. {
  758. printf("tkSetOverlayMap(%d,%f) TODO\n",size,*rgb);
  759. }
  760. /******************************************************************************/
  761.  
  762. void tkSwapBuffers(void)
  763. {
  764.     AmigaMesaSwapBuffers(win.context);
  765. }
  766.  
  767. /******************************************************************************/
  768.  
  769. GLint tkGetColorMapSize(void)
  770. {
  771.  /* TODO */
  772.     printf("tkGetColorMapSize() TODO\n");
  773.     return(255);
  774. }
  775.  
  776. void tkGetMouseLoc(int *x, int *y)
  777. {
  778.     *x = tkhwnd->MouseX;
  779.     *y = tkhwnd->MouseY;
  780. }
  781.  
  782.  
  783. GLenum tkGetDisplayMode(void)
  784. {
  785.     return win.type;
  786. }
  787.  
  788. GLenum tkSetWindowLevel(GLenum level)
  789. {
  790. printf("tkSetWindowLevel(%d) TODO\n",level);
  791. return GL_FALSE;
  792. }
  793.  
  794. /*
  795. TK_RGBImageRec *tkRGBImageLoad(char *fileName)
  796. {
  797. printf("tkRGBImageLoad(%s) TODO\n",fileName);
  798. }
  799. */
  800.  
  801. void tkGetSystem(TKenum type, void *ptr)
  802. {
  803. printf("tkGetSystem(%d,*ptr) TODO\n",type);
  804. /* getset.c */
  805. }
  806. #undef USE_CLIP_LAYER
  807.