📄 glut_overlay.c
字号:
{ if (overlay->visAlloced) XFree(overlay->vis); XDestroyWindow(__glutDisplay, overlay->win); glXDestroyContext(__glutDisplay, overlay->ctx); if (overlay->colormap) { /* Only color index overlays have colormap data structure. */ __glutFreeColormap(overlay->colormap); } free(overlay);}static XVisualInfo *determineOverlayVisual(int *treatAsSingle, Bool * visAlloced, void **fbc){ if (__glutDisplayString) { XVisualInfo *vi; int i; /* __glutDisplayString should be NULL except if glutInitDisplayString has been called to register a different display string. Calling glutInitDisplayString means using a string instead of an integer mask determine the visual to use. Using the function pointer variable __glutDetermineVisualFromString below avoids linking in the code for implementing glutInitDisplayString (ie, glut_dstr.o) unless glutInitDisplayString gets called by the application. */ assert(__glutDetermineVisualFromString); /* Try three overlay layers. */ *visAlloced = False; *fbc = NULL; for (i = 1; i <= 3; i++) { requiredOverlayCriteria[0].value = i; vi = __glutDetermineVisualFromString(__glutDisplayString, treatAsSingle, requiredOverlayCriteria, numRequiredOverlayCriteria, requiredOverlayCriteriaMask, fbc); if (vi) { return vi; } } return NULL; } else { *visAlloced = True; *fbc = NULL; return __glutDetermineVisual(__glutDisplayMode, treatAsSingle, getOverlayVisualInfo); }}/* CENTRY */void GLUTAPIENTRYglutEstablishOverlay(void){ GLUToverlay *overlay; GLUTwindow *window; XSetWindowAttributes wa; void *fbc; /* Register a routine to free an overlay with glut_win.c; this keeps glut_win.c from pulling in all of glut_overlay.c when no overlay functionality is used by the application. */ __glutFreeOverlayFunc = __glutFreeOverlay; window = __glutCurrentWindow; /* Allow for an existant overlay to be re-established perhaps if you wanted a different display mode. */ if (window->overlay) {#if !defined(_WIN32) addStaleWindow(window, window->overlay->win);#endif __glutFreeOverlay(window->overlay); } overlay = (GLUToverlay *) malloc(sizeof(GLUToverlay)); if (!overlay) __glutFatalError("out of memory."); overlay->vis = determineOverlayVisual(&overlay->treatAsSingle, &overlay->visAlloced, &fbc); if (!overlay->vis) { __glutFatalError("lacks overlay support."); }#if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_fbconfig) if (fbc) { window->ctx = __glut_glXCreateContextWithConfigSGIX(__glutDisplay, fbc, GLX_RGBA_TYPE_SGIX, None, __glutTryDirect); } else#endif { overlay->ctx = glXCreateContext(__glutDisplay, overlay->vis, None, __glutTryDirect); } if (!overlay->ctx) { __glutFatalError( "failed to create overlay OpenGL rendering context."); }#if !defined(_WIN32) overlay->isDirect = glXIsDirect(__glutDisplay, overlay->ctx); if (__glutForceDirect) { if (!overlay->isDirect) { __glutFatalError("direct rendering not possible."); } }#endif __glutSetupColormap(overlay->vis, &overlay->colormap, &overlay->cmap); overlay->transparentPixel = __glutGetTransparentPixel(__glutDisplay, overlay->vis); wa.colormap = overlay->cmap; wa.background_pixel = overlay->transparentPixel; wa.event_mask = window->eventMask & GLUT_OVERLAY_EVENT_FILTER_MASK; wa.border_pixel = 0;#if defined(_WIN32) /* XXX Overlays not supported in Win32 yet. */#else overlay->win = XCreateWindow(__glutDisplay, window->win, 0, 0, window->width, window->height, 0, overlay->vis->depth, InputOutput, overlay->vis->visual, CWBackPixel | CWBorderPixel | CWEventMask | CWColormap, &wa);#endif if (window->children) { /* Overlay window must be lowered below any GLUT subwindows. */ XLowerWindow(__glutDisplay, overlay->win); } XMapWindow(__glutDisplay, overlay->win); overlay->shownState = 1; overlay->display = NULL; /* Make sure a reshape gets delivered. */ window->forceReshape = True;#if !defined(_WIN32) __glutPutOnWorkList(__glutToplevelOf(window), GLUT_COLORMAP_WORK);#endif window->overlay = overlay; glutUseLayer(GLUT_OVERLAY); if (overlay->treatAsSingle) { glDrawBuffer(GL_FRONT); glReadBuffer(GL_FRONT); }}void GLUTAPIENTRYglutRemoveOverlay(void){ GLUTwindow *window = __glutCurrentWindow; GLUToverlay *overlay = __glutCurrentWindow->overlay; if (!window->overlay) return; /* If using overlay, switch to the normal layer. */ if (window->renderWin == overlay->win) { glutUseLayer(GLUT_NORMAL); }#if !defined(_WIN32) addStaleWindow(window, overlay->win);#endif __glutFreeOverlay(overlay); window->overlay = NULL;#if !defined(_WIN32) __glutPutOnWorkList(__glutToplevelOf(window), GLUT_COLORMAP_WORK);#endif}void GLUTAPIENTRYglutUseLayer(GLenum layer){ GLUTwindow *window = __glutCurrentWindow; switch (layer) { case GLUT_NORMAL:#ifdef _WIN32 window->renderDc = window->hdc;#endif window->renderWin = window->win; window->renderCtx = window->ctx; break; case GLUT_OVERLAY: /* Did you crash here? Calling glutUseLayer(GLUT_OVERLAY) without an overlay established is erroneous. Fix your code. */#ifdef _WIN32 window->renderDc = window->overlay->hdc;#endif window->renderWin = window->overlay->win; window->renderCtx = window->overlay->ctx; break; default: __glutWarning("glutUseLayer: unknown layer, %d.", layer); break; } __glutSetWindow(window);}void GLUTAPIENTRYglutPostOverlayRedisplay(void){ __glutPostRedisplay(__glutCurrentWindow, GLUT_OVERLAY_REDISPLAY_WORK);}/* The advantage of this routine is that it saves the cost of a glutSetWindow call (entailing an expensive OpenGL context switch), particularly useful when multiple windows need redisplays posted at the same times. */void GLUTAPIENTRYglutPostWindowOverlayRedisplay(int win){ __glutPostRedisplay(__glutWindowList[win - 1], GLUT_OVERLAY_REDISPLAY_WORK);}void GLUTAPIENTRYglutOverlayDisplayFunc(GLUTdisplayCB displayFunc){ if (!__glutCurrentWindow->overlay) { __glutWarning("glutOverlayDisplayFunc: window has no overlay established"); return; } __glutCurrentWindow->overlay->display = displayFunc;}void GLUTAPIENTRYglutHideOverlay(void){ if (!__glutCurrentWindow->overlay) { __glutWarning("glutHideOverlay: window has no overlay established"); return; } XUnmapWindow(__glutDisplay, __glutCurrentWindow->overlay->win); __glutCurrentWindow->overlay->shownState = 0;}void GLUTAPIENTRYglutShowOverlay(void){ if (!__glutCurrentWindow->overlay) { __glutWarning("glutShowOverlay: window has no overlay established"); return; } XMapWindow(__glutDisplay, __glutCurrentWindow->overlay->win); __glutCurrentWindow->overlay->shownState = 1;}int GLUTAPIENTRYglutLayerGet(GLenum param){ switch (param) { case GLUT_OVERLAY_POSSIBLE: { XVisualInfo *vi; Bool dummy, visAlloced; void *fbc; vi = determineOverlayVisual(&dummy, &visAlloced, &fbc); if (vi) { if (visAlloced) XFree(vi); return 1; } return 0; } case GLUT_LAYER_IN_USE: return __glutCurrentWindow->renderWin != __glutCurrentWindow->win; case GLUT_HAS_OVERLAY: return __glutCurrentWindow->overlay != NULL; case GLUT_TRANSPARENT_INDEX: if (__glutCurrentWindow->overlay) { return __glutCurrentWindow->overlay->transparentPixel; } else { return -1; } case GLUT_NORMAL_DAMAGED: /* __glutWindowDamaged is used so the damage state within the window (or overlay belwo) can be cleared before calling a display callback so on return, the state does not have to be cleared (since upon return from the callback the window could be destroyed (or layer removed). */ return (__glutCurrentWindow->workMask & GLUT_REPAIR_WORK) || __glutWindowDamaged; case GLUT_OVERLAY_DAMAGED: if (__glutCurrentWindow->overlay) { return (__glutCurrentWindow->workMask & GLUT_OVERLAY_REPAIR_WORK) || __glutWindowDamaged; } else { return -1; } default: __glutWarning("invalid glutLayerGet param: %d", param); return -1; }}/* ENDCENTRY */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -