home *** CD-ROM | disk | FTP | other *** search
/ Amiga Magazin: Amiga-CD 2000 April & May / AMIGA_2000_04.iso / patches / mesa3.1 / mesa-glut.lha / src-glut.aos / glutGameMode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-24  |  7.5 KB  |  208 lines

  1. /*
  2.  * Amiga GLUT graphics library toolkit
  3.  * Version:  1.1
  4.  * Copyright (C) 1998 Jarno van der Linden
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Library General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Library General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Library General Public
  17.  * License along with this library; if not, write to the Free
  18.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /*
  22.  * glutAddMenuEntry.c
  23.  *
  24.  * Version 1.0  27 Jun 1998
  25.  * by Jarno van der Linden
  26.  * jarno@kcbbs.gen.nz
  27.  *
  28.  */
  29.  
  30. #include <stdlib.h>
  31. #include <inline/graphics.h>
  32. #include <inline/intuition.h>
  33. #include <graphics/modeid.h>
  34. #include "glutstuff.h"
  35.  
  36. void CloseWindowSafely(struct Window *win);
  37.  
  38. int glutEnterGameMode(void) {
  39.   struct GlutGameMode *GameMode;
  40.  
  41.  /*
  42.   * TODO:
  43.   *  open screen, open borderless (or maybe 1x1) window, bind new context
  44.   *  change the whole context and open on Screen.RastPort
  45.   */
  46.   if ((glutstuff.GameMode = GameMode = AllocVecPooled(glutPool, sizeof(struct GlutGameMode)))) {
  47.     ULONG ScreenModeID;
  48.  
  49.     /* Search best ModeID */
  50.     if ((ScreenModeID = BestModeID(BIDTAG_Depth, 8,                    /* TODO: user-configureable */
  51.                        BIDTAG_NominalWidth, glutstuff.curwin ? glutstuff.curwin->winwidth : glutstuff.initwidth,
  52.                        BIDTAG_NominalHeight, glutstuff.curwin ? glutstuff.curwin->winheight : glutstuff.initheight,
  53.                    BIDTAG_DesiredWidth, glutstuff.curwin ? glutstuff.curwin->winwidth : glutstuff.initwidth,
  54.                    BIDTAG_DesiredHeight, glutstuff.curwin ? glutstuff.curwin->winheight : glutstuff.initheight,
  55.                    TAG_DONE)) == INVALID_ID) {
  56.       /* this does work! */
  57.       FreeVecPooled(glutPool, (ULONG *)GameMode);
  58.       glutstuff.GameMode = NULL;
  59.  
  60.       return glutstuff.curwin ? glutstuff.curwin->WinID : 0;
  61.     }
  62.  
  63.     if ((GameMode->GameScreen = OpenScreenTags(0,
  64.                            SA_Width, glutstuff.curwin->winwidth,
  65.                            SA_Height, glutstuff.curwin->winheight,
  66.                            SA_DisplayID, ScreenModeID,
  67.                            SA_Depth, 8,            /* TODO: user-configureable */
  68.                            SA_SharePens, TRUE))) {
  69.       if ((GameMode->FakeyWindow.window = OpenWindowTags(0,
  70.                              WA_Left, 0,
  71.                              WA_Top, 0,
  72.                              WA_Width, glutstuff.curwin->winwidth,
  73.                              WA_Height, glutstuff.curwin->winheight,
  74.                              WA_IDCMP, glutstuff.curwin->window->IDCMPFlags,
  75.                              WA_Flags, (glutstuff.curwin->window->Flags | WFLG_BORDERLESS | WFLG_ACTIVATE | WFLG_BACKDROP) & ~(WFLG_RMBTRAP),
  76.                              WA_CustomScreen, (ULONG)GameMode->GameScreen,
  77.                              WA_MinWidth, glutstuff.curwin->winwidth,
  78.                              WA_MinHeight, glutstuff.curwin->winheight,
  79.                              WA_MaxWidth, glutstuff.curwin->winwidth,
  80.                              WA_MaxHeight, glutstuff.curwin->winheight))) {
  81.         if((GameMode->FakeyWindow.context = amigaMesaCreateContextTags(AMA_Window, GameMode->FakeyWindow.window,
  82.                                        AMA_RGBMode, (glutstuff.rgbamode ? (glutstuff.rgbamode < 0 ? GL_FALSE : GL_TRUE) : glutstuff.rgba),
  83.                                        AMA_AlphaChannel, glutstuff.alpha,
  84.                                        AMA_Stereo, (glutstuff.stereomode ? (glutstuff.stereomode < 0 ? GL_FALSE : GL_TRUE) : glutstuff.stereo),
  85.                                        AMA_DoubleBuffer, (glutstuff.doublemode ? (glutstuff.doublemode < 0 ? GL_FALSE : GL_TRUE) : glutstuff.db),
  86.                                        AMA_PaletteMode, glutstuff.palmode,
  87.                                        AMA_RastPort, GameMode->FakeyWindow.window->RPort,
  88.                                        AMA_Screen, GameMode->FakeyWindow.window->WScreen,
  89.                                        AMA_Width, glutstuff.curwin->winwidth,
  90.                                        AMA_Height, glutstuff.curwin->winheight,
  91.                                        TAG_END))) {
  92.           GameMode->backuped_port = glutstuff.msgport;
  93.           GameMode->backuped_window = glutstuff.curwin;
  94.  
  95.       dNewList(&GameMode->FakeyWindow.SubWindows);        /* QUEST: is it possible to open subwindows in gamemode? ANSWER: NO!!!!!!!!!!!! */
  96.       dNewList(&GameMode->FakeyWindow.WindowTimers);
  97.  
  98.       GameMode->FakeyWindow.window->UserData = (APTR)&GameMode->FakeyWindow;
  99.  
  100.       GameMode->FakeyWindow.mousex = -1;
  101.       GameMode->FakeyWindow.mousey = -1;
  102.  
  103.       GameMode->FakeyWindow.winwidth = GameMode->FakeyWindow.wincurwidth = GameMode->FakeyWindow.window->Width;
  104.       GameMode->FakeyWindow.winheight = GameMode->FakeyWindow.wincurheight = GameMode->FakeyWindow.window->Height;
  105.  
  106.       GameMode->FakeyWindow.needreshapegui = TRUE;
  107.       GameMode->FakeyWindow.needpositiongui = TRUE;
  108.       GameMode->FakeyWindow.needredisplay = TRUE;
  109.       GameMode->FakeyWindow.needvisibility = TRUE;
  110.       GameMode->FakeyWindow.visible = TRUE;
  111.  
  112.           glutstuff.curwin = &GameMode->FakeyWindow;
  113.           glutstuff.msgport = GameMode->FakeyWindow.window->UserPort;
  114.  
  115.       stuffLinkInWin(&GameMode->FakeyWindow);
  116.  
  117.       if (glutstuff.depth)
  118.         glEnable(GL_DEPTH_TEST);
  119.  
  120.     //ActivateWindow(win);
  121.     //glutstuff.activeWindow = gw;
  122.       DEBUGOUT(2, "%d = glutGameMode()\n", GameMode->FakeyWindow.WinID);
  123.  
  124.           return GameMode->FakeyWindow.WinID;
  125.         }
  126.  
  127.     DEBUGOUT(1, "failed to create gamecontext\n");
  128.     CloseWindow(GameMode->FakeyWindow.window);
  129.       }
  130.       else
  131.     DEBUGOUT(1, "failed to open gamewindow\n");
  132.       
  133.       CloseScreen(GameMode->GameScreen);
  134.     }
  135.     else
  136.       DEBUGOUT(1, "failed to open gamescreen\n");
  137.     
  138.     /* this does work! */
  139.     FreeVecPooled(glutPool, (ULONG *)GameMode);
  140.     glutstuff.GameMode = NULL;
  141.   }
  142.   else
  143.     DEBUGOUT(1, "failed to allocate gamemode\n");
  144.  
  145.   return glutstuff.curwin ? glutstuff.curwin->WinID : 0;
  146. }
  147.  
  148. void glutLeaveGameMode(void) {
  149.   struct GlutGameMode *GameMode;
  150.  
  151.   if ((GameMode = glutstuff.GameMode)) {
  152.     struct nnode *act;
  153.  
  154.     stuffLinkOutWin(&GameMode->FakeyWindow);
  155.  
  156.     glutstuff.curwin = GameMode->backuped_window;
  157.     glutstuff.msgport = GameMode->backuped_port;
  158.  
  159.     while ((act = nGetTail(&GameMode->FakeyWindow.WindowTimers))) {
  160.       dRemove(&GameMode->FakeyWindow.WindowTimers, act);
  161.       FreeVecPooled(glutPool, (ULONG *)act);
  162.     }
  163.  
  164.     while ((act = nGetTail(&GameMode->FakeyWindow.SubWindows)))
  165.       glutDestroyWindow(((struct GlutWindow *)act)->WinID);        /* WARNING: THIS MUST NOT HAPPEN!!! */
  166.  
  167.     if (GameMode->FakeyWindow.context)
  168.       amigaMesaDestroyContext(GameMode->FakeyWindow.context);
  169.     if (GameMode->FakeyWindow.window)
  170.       CloseWindowSafely(GameMode->FakeyWindow.window);
  171.     if (GameMode->GameScreen)
  172.       CloseScreen(GameMode->GameScreen);
  173.  
  174.     FreeVecPooled(glutPool, (ULONG *)GameMode);
  175.     glutstuff.GameMode = 0;
  176.     
  177.     stuffMakeCurrent(glutstuff.curwin);
  178.   }
  179.   else
  180.     DEBUGOUT(1, "not in gamemode before\n");
  181. }
  182.  
  183. int glutGameModeGet(GLenum mode) {
  184.  
  185.   switch (mode) {
  186.     case GLUT_GAME_MODE_ACTIVE:
  187.       return glutstuff.GameMode ? TRUE : FALSE;
  188.     case GLUT_GAME_MODE_POSSIBLE:
  189.       return TRUE;
  190.     case GLUT_GAME_MODE_WIDTH:
  191.       return glutstuff.GameMode ? glutstuff.GameMode->FakeyWindow.winwidth : -1;
  192.     case GLUT_GAME_MODE_HEIGHT:
  193.       return glutstuff.GameMode ? glutstuff.GameMode->FakeyWindow.winheight : -1;
  194.     case GLUT_GAME_MODE_PIXEL_DEPTH:
  195.       return 8;                                /* TODO: user-configureable */
  196.     case GLUT_GAME_MODE_DISPLAY_CHANGED:
  197.       return glutstuff.GameMode ? TRUE : -1;                /* this is always true, 'cause we open a new screen (aka XDisplay) */
  198.     case GLUT_GAME_MODE_REFRESH_RATE:
  199.                                         /* TODO: parse ScreenModeID for hertz */
  200.     default:
  201.       break;
  202.   }
  203.   return -1;
  204. }
  205.  
  206. void glutGameModeString(const char *string) {
  207. }
  208.