📄 glwin.c
字号:
{ if (debug) fprintf(stderr,"no GLX support.\n"); continue; } /* Visual must be in main planes which is level 0 */ glXGetConfig(w->display, this_vis, GLX_LEVEL, &val); if ( val != 0 ) { if (debug) fprintf(stderr,"no level 0 visual.\n"); continue; } /* Color Index or RGBA? It must match the requested value */ glXGetConfig(w->display, this_vis, GLX_RGBA, &val); if ( GLW_IS_RGB(type) && !val ) { if (debug) fprintf(stderr,"no RGB support.\n"); continue; } if ( GLW_IS_INDEX(type) && val ) { if (debug) fprintf(stderr,"no color index support.\n"); continue; } /* Double buffered or Single buffered? */ glXGetConfig(w->display, this_vis, GLX_DOUBLEBUFFER, &val); if ( GLW_IS_DOUBLE(type) && !val ) { if (debug) fprintf(stderr,"no double buffer support.\n"); continue; } if ( GLW_IS_SINGLE(type) && val ) { if (debug) fprintf(stderr,"no single buffer support.\n"); continue; } /* If accum requested then accum rgb size must be > 0 */ /* If alpha requested then alpha size must be > 0 */ /* if accum & alpha requested then accum alpha size must be > 0 */ if ( GLW_IS_RGB(type) ) { glXGetConfig(w->display, this_vis, GLX_ACCUM_RED_SIZE, &rval); glXGetConfig(w->display, this_vis, GLX_ACCUM_GREEN_SIZE, &gval); glXGetConfig(w->display, this_vis, GLX_ACCUM_BLUE_SIZE, &bval); glXGetConfig(w->display, this_vis, GLX_ACCUM_ALPHA_SIZE, &aval); if ( GLW_HAS_ACCUM(type) ) { if ( rval <= 0 || gval <= 0 || bval <= 0 ) { if (debug) fprintf(stderr,"accum RGB size <0.\n"); continue; } } else { if ( rval > 0 || gval > 0 || bval > 0 || aval > 0 ) { if (debug) fprintf(stderr,"accum support not demanded.\n"); continue; } } glXGetConfig(w->display, this_vis, GLX_ALPHA_SIZE, &val); if ( GLW_HAS_ALPHA(type) ) { if ( val <= 0 ) { if (debug) fprintf(stderr,"alpha size < 0.\n"); continue; } if ( GLW_HAS_ACCUM(type) && aval <= 0 ) { if (debug) fprintf(stderr,"alpha accum size < 0.\n"); continue; } } else { if ( val > 0 ) { if (debug) fprintf(stderr,"alpha support not demanded.\n"); continue; } } } /* Check depth buffer */ glXGetConfig(w->display, this_vis, GLX_DEPTH_SIZE, &val); if ( GLW_HAS_DEPTH(type) ) { if ( val <= 0 ) { if (debug) fprintf(stderr,"no depth buffer support.\n"); continue; } } else { if ( val > 0 ) { if (debug) fprintf(stderr,"depth buffer support not demanded.\n"); continue; } } /* Check stencil buffer */ glXGetConfig(w->display, this_vis, GLX_STENCIL_SIZE, &val); if ( GLW_HAS_STENCIL(type) ) { if ( val <= 0 ) { if (debug) fprintf(stderr,"no stencil buffer support.\n"); continue; } } else { if ( val > 0 ) { if (debug) fprintf(stderr,"stencil buffer support not demanded.\n"); continue; } } glXGetConfig(w->display, this_vis, GLX_BUFFER_SIZE, &this_score); if (debug) fprintf(stderr,"ok, buffer size=%d.\n",this_score); if (this_score > best_score ) { best_score = this_score; best_vis = this_vis; } } if ( best_vis ) { sampleVis.visualid = best_vis->visualid; sampleVis.screen = w->screen; if ( nvis > 0 ) XFree(vis_list); return XGetVisualInfo(w->display, VisualIDMask|VisualScreenMask, &sampleVis, &nvis); } else { if ( nvis > 0 ) XFree(vis_list); return None; }}/*old code static XVisualInfo *FindMainVisual(glWindow w,GLenum type){ int list[32], i; i = 0; list[i++] = GLX_LEVEL; list[i++] = 0; if (GLW_IS_DOUBLE(type)) { list[i++] = GLX_DOUBLEBUFFER; } if (GLW_IS_RGB(type)) { list[i++] = GLX_RGBA; list[i++] = GLX_RED_SIZE; list[i++] = 1; list[i++] = GLX_GREEN_SIZE; list[i++] = 1; list[i++] = GLX_BLUE_SIZE; list[i++] = 1; if (GLW_HAS_ALPHA(type)) { list[i++] = GLX_ALPHA_SIZE; list[i++] = 1; } if (GLW_HAS_ACCUM(type)) { list[i++] = GLX_ACCUM_RED_SIZE; list[i++] = 1; list[i++] = GLX_ACCUM_GREEN_SIZE; list[i++] = 1; list[i++] = GLX_ACCUM_BLUE_SIZE; list[i++] = 1; if (GLW_HAS_ALPHA(type)) { list[i++] = GLX_ACCUM_ALPHA_SIZE; list[i++] = 1; } } } else if (GLW_IS_INDEX(type)) { list[i++] = GLX_BUFFER_SIZE; list[i++] = 1; } if (GLW_HAS_DEPTH(type)) { list[i++] = GLX_DEPTH_SIZE; list[i++] = 1; } if (GLW_HAS_STENCIL(type)) { list[i++] = GLX_STENCIL_SIZE; list[i++] = 1; } list[i] = (int)None; return glXChooseVisual(w->display, w->screen, list);}*/static XVisualInfo *FindOverlayVisual(glWindow w){ int list[3]; list[0] = GLX_LEVEL; list[1] = 1; list[2] = (int)None; return glXChooseVisual(w->display, w->screen, list);}static GLenum GetMainWindowType(glWindow w,XVisualInfo *vi){ GLenum mask; int x, y, z; mask = (GLenum)0; glXGetConfig(w->display, vi, GLX_DOUBLEBUFFER, &x); if (x) { mask |= GLW_DOUBLE; } else { mask |= GLW_SINGLE; } glXGetConfig(w->display, vi, GLX_RGBA, &x); if (x) { mask |= GLW_RGB; glXGetConfig(w->display, vi, GLX_ALPHA_SIZE, &x); if (x > 0) { mask |= GLW_ALPHA; } glXGetConfig(w->display, vi, GLX_ACCUM_RED_SIZE, &x); glXGetConfig(w->display, vi, GLX_ACCUM_GREEN_SIZE, &y); glXGetConfig(w->display, vi, GLX_ACCUM_BLUE_SIZE, &z); if (x > 0 && y > 0 && z > 0) { mask |= GLW_ACCUM; } } else { mask |= GLW_INDEX; } glXGetConfig(w->display, vi, GLX_DEPTH_SIZE, &x); if (x > 0) { mask |= GLW_DEPTH; } glXGetConfig(w->display, vi, GLX_STENCIL_SIZE, &x); if (x > 0) { mask |= GLW_STENCIL; } if (glXIsDirect(w->display, w->cMain)) { mask |= GLW_DIRECT; } else { mask |= GLW_INDIRECT; } return mask;}static int WaitForMainWindow(Display *d, XEvent *e, char *arg){ if (e->type == MapNotify && e->xmap.window == wEvent->wMain) { return GL_TRUE; } else { return GL_FALSE; }}/*static int WaitForOverlayWindow(Display *d, XEvent *e, char *arg){ if (e->type == MapNotify && e->xmap.window == wEvent->wOverlay) { return GL_TRUE; } else { return GL_FALSE; } return GL_FALSE;}*/static void default_expose_func(glWindow w, void *user_data, int width, int height){ /* force redraw if no user drivers set */}static void create_window(glWindow w, int overlayFlag){ XSetWindowAttributes wa; XTextProperty tp; XSizeHints sh; XEvent e; wa.colormap = w->cMapMain; wa.background_pixmap = None; wa.border_pixel = 0; wa.backing_store=Always; wa.save_under=True; wa.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; w->wMain = XCreateWindow(w->display, w->root, w->x, w->y, w->w, w->h, 0, w->vInfoMain->depth, InputOutput, w->vInfoMain->visual, CWBackPixmap|CWBorderPixel|CWEventMask|CWColormap, &wa); XStringListToTextProperty(&w->title, 1, &tp); sh.flags = USPosition | USSize | PMaxSize |PResizeInc; sh.width_inc=16; sh.height_inc=16; if (w->keep_aspect) { sh.flags|=PAspect; sh.min_aspect.x=w->w; sh.min_aspect.y=w->h; sh.max_aspect.x=w->w; sh.max_aspect.y=w->h; } { Screen *scr = DefaultScreenOfDisplay(w->display); sh.max_width=WidthOfScreen(scr); sh.max_height=HeightOfScreen(scr); } if (w->wToplevel!=0) XSetTransientForHint(w->display, w->wMain, w->wToplevel); XSetWMProperties(w->display, w->wMain, &tp, &tp, 0, 0, &sh, 0, 0); w->deleteWindowAtom = XInternAtom(w->display, "WM_DELETE_WINDOW", False); XSetWMProtocols(w->display, w->wMain, &w->deleteWindowAtom, 1); XMapWindow(w->display, w->wMain); w->drawAllowFlag = GL_FALSE; w->lastEventType= -1; wEvent=w; XIfEvent(w->display, &e, WaitForMainWindow, 0); if (overlayFlag == GL_TRUE) { w->vInfoOverlay = FindOverlayVisual(w); if (w->vInfoOverlay) { w->cOverlay = glXCreateContext(w->display, w->vInfoOverlay, None, GL_TRUE); w->cMapOverlay = XCreateColormap(w->display, w->root, w->vInfoOverlay->visual, AllocNone); glwSetOverlayMap(w,256, colorMaps); wa.colormap = w->cMapOverlay; wa.background_pixmap = None; wa.border_pixel = 0; w->wOverlay = XCreateWindow(w->display, w->wMain, 0, 0, w->w, w->h, 0, w->vInfoOverlay->depth, InputOutput, w->vInfoOverlay->visual, CWBackPixmap|CWBorderPixel|CWColormap, &wa); XMapWindow(w->display, w->wOverlay); XSetWMColormapWindows(w->display, w->wMain, &w->wOverlay, 1); w->type |= GLW_OVERLAY; } else { glwError("Unable to create overlay plane!"); } } w->wait_cursor=XCreateFontCursor(w->display,XC_watch); w->user_cursor=XCreateFontCursor(w->display,XC_cross); XDefineCursor(w->display,w->wMain, w->user_cursor);}static void create_pixmap(glWindow w, int overlayFlag){ w->pixmap = XCreatePixmap(w->display, w->root, w->w, w->h, w->vInfoMain->depth); if (w->pixmap==0) glwError("Unable to create pixmap!"); else glwTrace("pixmap ok"); w->glx_pixmap =glXCreateGLXPixmap(w->display, w->vInfoMain, w->pixmap); if (w->glx_pixmap==0) glwError("Unable to create glx_pixmap!"); else glwTrace("glxpixmap ok"); }glWindow glwCreate(void){ glWindow w; int erb, evb; GLenum overlayFlag; InitWindow(); assert(wCreate!=NULL); w=wCreate; wCreate=0; if (!glXQueryExtension(w->display, &erb, &evb)) { glwError("No glx extension found!"); return NULL; } w->screen = DefaultScreen(w->display); w->root = RootWindow(w->display, w->screen); XSetErrorHandler(ErrorHandler); if (w->offscreen) w->type |= GLW_INDIRECT; if (GLW_HAS_OVERLAY(w->type)) { overlayFlag = GL_TRUE; } else { overlayFlag = GL_FALSE; } w->type &= ~GLW_OVERLAY; if (w->dmPolicy == GLW_MINIMUM_CRITERIA) w->vInfoMain = FindBestMainVisual(w,w->type); else if (w->dmPolicy == GLW_EXACT_MATCH) w->vInfoMain = FindExactMainVisual(w,w->type); if (!w->vInfoMain) { glwError("Main visual not found!"); return NULL; } if (debug) fprintf(stderr,"glwin: using visual id 0x%x\n", (unsigned)w->vInfoMain->visualid); #if defined(__cplusplus) || defined(c_plusplus) w->vInfoMainClass = w->vInfoMain->c_class;#else w->vInfoMainClass = w->vInfoMain->class;#endif w->cMain = glXCreateContext(w->display, w->vInfoMain, None, (GLW_IS_DIRECT(w->type))?GL_TRUE:GL_FALSE); if (!w->cMain) { glwError("Unable to create glx context!");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -