示例#1
0
/* CENTRY */
int GLUTAPIENTRY 
glutGet(GLenum param)
{
  Window win, root;
  int x, y, value;
  unsigned int width, height, border, depth;

  switch (param) {
  case GLUT_INIT_WINDOW_X:
    return __glutInitX;
  case GLUT_INIT_WINDOW_Y:
    return __glutInitY;
  case GLUT_INIT_WINDOW_WIDTH:
    return __glutInitWidth;
  case GLUT_INIT_WINDOW_HEIGHT:
    return __glutInitHeight;
  case GLUT_INIT_DISPLAY_MODE:
    return __glutDisplayMode;
  case GLUT_WINDOW_X:
    XTranslateCoordinates(__glutDisplay, __glutCurrentWindow->win,
      __glutRoot, 0, 0, &x, &y, &win);
    return x;
  case GLUT_WINDOW_Y:
    XTranslateCoordinates(__glutDisplay, __glutCurrentWindow->win,
      __glutRoot, 0, 0, &x, &y, &win);
    return y;
  case GLUT_WINDOW_WIDTH:
    if (!__glutCurrentWindow->reshape) {
      XGetGeometry(__glutDisplay, __glutCurrentWindow->win,
        &root, &x, &y,
        &width, &height, &border, &depth);
      return width;
    }
    return __glutCurrentWindow->width;
  case GLUT_WINDOW_HEIGHT:
    if (!__glutCurrentWindow->reshape) {
      XGetGeometry(__glutDisplay, __glutCurrentWindow->win,
        &root, &x, &y,
        &width, &height, &border, &depth);
      return height;
    }
    return __glutCurrentWindow->height;

#define GET_CONFIG(attrib) { \
  if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) { \
    glXGetConfig(__glutDisplay, __glutCurrentWindow->vis, \
      attrib, &value); \
  } else { \
    glXGetConfig(__glutDisplay, __glutCurrentWindow->overlay->vis, \
      attrib, &value); \
  } \
}

  case GLUT_WINDOW_BUFFER_SIZE:
    GET_CONFIG(GLX_BUFFER_SIZE);
    return value;
  case GLUT_WINDOW_STENCIL_SIZE:
    GET_CONFIG(GLX_STENCIL_SIZE);
    return value;
  case GLUT_WINDOW_DEPTH_SIZE:
    GET_CONFIG(GLX_DEPTH_SIZE);
    return value;
  case GLUT_WINDOW_RED_SIZE:
    GET_CONFIG(GLX_RED_SIZE);
    return value;
  case GLUT_WINDOW_GREEN_SIZE:
    GET_CONFIG(GLX_GREEN_SIZE);
    return value;
  case GLUT_WINDOW_BLUE_SIZE:
    GET_CONFIG(GLX_BLUE_SIZE);
    return value;
  case GLUT_WINDOW_ALPHA_SIZE:
    GET_CONFIG(GLX_ALPHA_SIZE);
    return value;
  case GLUT_WINDOW_ACCUM_RED_SIZE:
    GET_CONFIG(GLX_ACCUM_RED_SIZE);
    return value;
  case GLUT_WINDOW_ACCUM_GREEN_SIZE:
    GET_CONFIG(GLX_ACCUM_GREEN_SIZE);
    return value;
  case GLUT_WINDOW_ACCUM_BLUE_SIZE:
    GET_CONFIG(GLX_ACCUM_BLUE_SIZE);
    return value;
  case GLUT_WINDOW_ACCUM_ALPHA_SIZE:
    GET_CONFIG(GLX_ACCUM_ALPHA_SIZE);
    return value;
  case GLUT_WINDOW_DOUBLEBUFFER:
    GET_CONFIG(GLX_DOUBLEBUFFER);
    return value;
  case GLUT_WINDOW_RGBA:
    GET_CONFIG(GLX_RGBA);
    return value;
  case GLUT_WINDOW_COLORMAP_SIZE:
    GET_CONFIG(GLX_RGBA);
    if (value) {
      return 0;
    } else {
#if defined(_WIN32)
      /* KLUDGE: we always assume 256 colors in CI mode on
         Win32 */
      return 256;
#else
      if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) { 
        return __glutCurrentWindow->vis->visual->map_entries;
      } else {
        return __glutCurrentWindow->overlay->vis->visual->map_entries;
      }
#endif /* _WIN32 */
    }
  case GLUT_WINDOW_PARENT:
    return __glutCurrentWindow->parent ?
      __glutCurrentWindow->parent->num + 1 : 0;
  case GLUT_WINDOW_NUM_CHILDREN:
    {
      int num = 0;
      GLUTwindow *children = __glutCurrentWindow->children;

      while (children) {
        num++;
        children = children->siblings;
      }
      return num;
    }
  case GLUT_WINDOW_NUM_SAMPLES:
#if defined(GLX_VERSION_1_1) && defined(GLX_SGIS_multisample)
    if (__glutIsSupportedByGLX("GLX_SGIS_multisample")) {
      GET_CONFIG(GLX_SAMPLES_SGIS);
      return value;
    } else {
      return 0;
    }
#else
    /* Independent of GLX server support, multisampling not
       supported by GLX client-side. */
    return 0;
#endif
  case GLUT_WINDOW_STEREO:
    GET_CONFIG(GLX_STEREO);
    return value;
  case GLUT_WINDOW_CURSOR:
    return __glutCurrentWindow->cursor;
  case GLUT_SCREEN_WIDTH:
    return DisplayWidth(__glutDisplay, __glutScreen);
  case GLUT_SCREEN_HEIGHT:
    return DisplayHeight(__glutDisplay, __glutScreen);
  case GLUT_SCREEN_WIDTH_MM:
    return DisplayWidthMM(__glutDisplay, __glutScreen);
  case GLUT_SCREEN_HEIGHT_MM:
    return DisplayHeightMM(__glutDisplay, __glutScreen);
  case GLUT_MENU_NUM_ITEMS:
    return __glutCurrentMenu->num;
  case GLUT_DISPLAY_MODE_POSSIBLE:
    {
      XVisualInfo *vi;
      Bool dummy, visAlloced;
      void *fbc;

#if defined(_WIN32)      
      /* Our fake glXChooseVisual (which is called by
         __glutDetermineVisual) needs an HDC to work with, so grab one
         from the "root" window. */
      XHDC = GetDC(GetDesktopWindow());
#endif
      vi = __glutDetermineWindowVisual(&dummy, &visAlloced, &fbc);
#if defined(_WIN32)      
      ReleaseDC(GetDesktopWindow(), XHDC);
#endif
      if (vi) {
        if (visAlloced)
          XFree(vi);
        return 1;
      }
      return 0;
    }
  case GLUT_ELAPSED_TIME:
    {
#ifdef OLD_VMS
       struct timeval6 elapsed, beginning, now;
#else
       struct timeval elapsed, beginning, now;
#endif

       __glutInitTime(&beginning);
      GETTIMEOFDAY(&now);
      TIMEDELTA(elapsed, now, beginning);
      /* Return elapsed milliseconds. */
#if defined(__vms) && ( __VMS_VER < 70000000 )
      return (int) (elapsed.val / TICKS_PER_MILLISECOND);
#else
      return (int) ((elapsed.tv_sec * 1000) + (elapsed.tv_usec / 1000));
#endif
    }
  case GLUT_WINDOW_FORMAT_ID:
#if defined(_WIN32)
    return GetPixelFormat(__glutCurrentWindow->hdc);
#else
    if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) {
      return (int) __glutCurrentWindow->vis->visualid;
    } else {
      return (int) __glutCurrentWindow->overlay->vis->visualid;
    }
#endif
  default:
    __glutWarning("invalid glutGet parameter: %d", param);
    return -1;
  }
}
示例#2
0
/* ARGSUSED5 */  /* Only Win32 uses gameMode parameter. */
GLUTwindow *
__glutCreateWindow(GLUTwindow * parent,
                   int x, int y, int width, int height, int gameMode)
{
    GLUTwindow *window;
    XSetWindowAttributes wa;
    unsigned long attribMask;
    int winnum;
    int i;
#if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_fbconfig)
    GLXFBConfigSGIX fbc;
#else
    void *fbc;
#endif

#if defined(_WIN32)
    WNDCLASS wc;
    int style;

    if (!GetClassInfo(GetModuleHandle(NULL), "GLUT", &wc)) {
        __glutOpenWin32Connection(NULL);
    }
#else
    if (!__glutDisplay) {
        __glutOpenXConnection(NULL);
    }
#endif
    if (__glutGameModeWindow) {
        __glutFatalError("cannot create windows in game mode.");
    }
    winnum = getUnusedWindowSlot();
    window = (GLUTwindow *) malloc(sizeof(GLUTwindow));
    if (!window) {
        __glutFatalError("out of memory.");
    }
    window->num = winnum;

#if !defined(_WIN32)
    window->vis = __glutDetermineWindowVisual(&window->treatAsSingle,
                  &window->visAlloced, (void**) &fbc);
    if (!window->vis) {
        __glutFatalError(
            "visual with necessary capabilities not found.");
    }
    __glutSetupColormap(window->vis, &window->colormap, &window->cmap);
#endif
    window->eventMask = StructureNotifyMask | ExposureMask;

    attribMask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
    wa.background_pixmap = None;
    wa.border_pixel = 0;
    wa.colormap = window->cmap;
    wa.event_mask = window->eventMask;
    if (parent) {
        if (parent->eventMask & GLUT_HACK_STOP_PROPAGATE_MASK)
            wa.event_mask |= GLUT_HACK_STOP_PROPAGATE_MASK;
        attribMask |= CWDontPropagate;
        wa.do_not_propagate_mask = parent->eventMask & GLUT_DONT_PROPAGATE_FILTER_MASK;
    } else {
        wa.do_not_propagate_mask = 0;
    }

    /* Stash width and height before Win32's __glutAdjustCoords
       possibly overwrites the values. */
    window->width = width;
    window->height = height;
    window->forceReshape = True;
    window->ignoreKeyRepeat = False;

#if defined(_WIN32)
    __glutAdjustCoords(parent ? parent->win : NULL,
                       &x, &y, &width, &height);
    if (parent) {
        style = WS_CHILD;
    } else {
        if (gameMode) {
            /* Game mode window should be a WS_POPUP window to
               ensure that the taskbar is hidden by it.  A standard
               WS_OVERLAPPEDWINDOW does not hide the task bar. */
            style = WS_POPUP | WS_MAXIMIZE;
        } else {
            /* A standard toplevel window with borders and such. */
            style = WS_OVERLAPPEDWINDOW;
        }
    }
    window->win = CreateWindow("GLUT", "GLUT",
                               WS_CLIPSIBLINGS | WS_CLIPCHILDREN | style,
                               x, y, width, height, parent ? parent->win : __glutRoot,
                               NULL, GetModuleHandle(NULL), 0);
    window->hdc = GetDC(window->win);
    /* Must set the XHDC for fake glXChooseVisual & fake
       glXCreateContext & fake XAllocColorCells. */
    XHDC = window->hdc;
    window->vis = __glutDetermineWindowVisual(&window->treatAsSingle,
                  &window->visAlloced, &fbc);
    if (!window->vis) {
        __glutFatalError(
            "pixel format with necessary capabilities not found.");
    }
    if (!SetPixelFormat(window->hdc,
                        ChoosePixelFormat(window->hdc, window->vis),
                        window->vis)) {
        __glutFatalError("SetPixelFormat failed during window create.");
    }
    __glutSetupColormap(window->vis, &window->colormap, &window->cmap);
    /* Make sure subwindows get a windowStatus callback. */
    if (parent) {
        PostMessage(parent->win, WM_ACTIVATE, 0, 0);
    }
    window->renderDc = window->hdc;
#else
    window->win = XCreateWindow(__glutDisplay,
                                parent == NULL ? __glutRoot : parent->win,
                                x, y, width, height, 0,
                                window->vis->depth, InputOutput, window->vis->visual,
                                attribMask, &wa);
#endif
    window->renderWin = window->win;
#if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_fbconfig)
    if (fbc) {
        window->ctx = glXCreateContextWithConfigSGIX(__glutDisplay, fbc,
                      GLX_RGBA_TYPE_SGIX, None, __glutTryDirect);
    } else
#endif
    {
        window->ctx = glXCreateContext(__glutDisplay, window->vis,
                                       None, __glutTryDirect);
    }
    if (!window->ctx) {
        __glutFatalError(
            "failed to create OpenGL rendering context.");
    }
    window->renderCtx = window->ctx;
#if !defined(_WIN32)
    window->isDirect = glXIsDirect(__glutDisplay, window->ctx);
    if (__glutForceDirect) {
        if (!window->isDirect)
            __glutFatalError("direct rendering not possible.");
    }
#endif

    window->parent = parent;
    if (parent) {
        window->siblings = parent->children;
        parent->children = window;
    } else {
        window->siblings = NULL;
    }
    window->overlay = NULL;
    window->children = NULL;
    window->display = __glutDefaultDisplay;
    window->reshape = __glutDefaultReshape;
    window->mouse = NULL;
    window->motion = NULL;
    window->passive = NULL;
    window->entry = NULL;
    window->keyboard = NULL;
    window->keyboardUp = NULL;
    window->windowStatus = NULL;
    window->visibility = NULL;
    window->special = NULL;
    window->specialUp = NULL;
    window->buttonBox = NULL;
    window->dials = NULL;
    window->spaceMotion = NULL;
    window->spaceRotate = NULL;
    window->spaceButton = NULL;
    window->tabletMotion = NULL;
    window->tabletButton = NULL;
#ifdef _WIN32
    window->joystick = NULL;
    window->joyPollInterval = 0;
#endif
    window->tabletPos[0] = -1;
    window->tabletPos[1] = -1;
    window->shownState = 0;
    window->visState = -1;  /* not VisibilityUnobscured,
                             VisibilityPartiallyObscured, or
                             VisibilityFullyObscured */
    window->entryState = -1;  /* not EnterNotify or LeaveNotify */

    window->desiredConfMask = 0;
    window->buttonUses = 0;
    window->cursor = GLUT_CURSOR_INHERIT;

    /* Setup window to be mapped when glutMainLoop starts. */
    window->workMask = GLUT_MAP_WORK;
#ifdef _WIN32
    if (gameMode) {
        /* When mapping a game mode window, just show
           the window.  We have already created the game
           mode window with a maximize flag at creation
           time.  Doing a ShowWindow(window->win, SW_SHOWNORMAL)
           would be wrong for a game mode window since it
           would unmaximize the window. */
        window->desiredMapState = GameModeState;
    } else {
        window->desiredMapState = NormalState;
    }
#else
    window->desiredMapState = NormalState;
#endif
    window->prevWorkWin = __glutWindowWorkList;
    __glutWindowWorkList = window;

    /* Initially, no menus attached. */
    for (i = 0; i < GLUT_MAX_MENUS; i++) {
        window->menu[i] = 0;
    }

    /* Add this new window to the window list. */
    __glutWindowList[winnum] = window;

    /* Make the new window the current window. */
    __glutSetWindow(window);

    __glutDetermineMesaSwapHackSupport();

    if (window->treatAsSingle) {
        /* We do this because either the window really is single
           buffered (in which case this is redundant, but harmless,
           because this is the initial single-buffered context
           state); or we are treating a double buffered window as a
           single-buffered window because the system does not appear
           to export any suitable single- buffered visuals (in which
           the following are necessary). */
        glDrawBuffer(GL_FRONT);
        glReadBuffer(GL_FRONT);
    }
    return window;
}