glcontext.cc

来自「机器人人3D仿真工具,可以加入到Simbad仿真环境下应用。」· CC 代码 · 共 644 行 · 第 1/2 页

CC
644
字号
  swa.colormap = cmap;  swa.border_pixel = 0;  swa.event_mask = StructureNotifyMask;  win = XCreateWindow(::display, RootWindow(::display, visual->screen),                      0, 0, this->reqWidth, this->reqHeight,                      0, visual->depth, InputOutput, visual->visual,                      CWBorderPixel|CWColormap|CWEventMask, &swa);  // REMOVE XMapWindow(::display, win);  //XIfEvent(::display, &event, WaitForNotify, (char*)win);  this->drawable = win;  this->context = cx;  int a[5];  glXGetConfig(::display, visual, GLX_RED_SIZE, a + 0);  glXGetConfig(::display, visual, GLX_GREEN_SIZE, a + 1);  glXGetConfig(::display, visual, GLX_BLUE_SIZE, a + 2);  glXGetConfig(::display, visual, GLX_ALPHA_SIZE, a + 3);  glXGetConfig(::display, visual, GLX_DEPTH_SIZE, a + 4);  // Print some info about the configuration  PRINT_MSG6(1, "rendering: [Xlib unmapped] direct [%s] RGBA [%d %d %d %d] depth [%d]",             (glXIsDirect(::display, this->context) ? "yes" : "no"),             a[0], a[1], a[2], a[3], a[4]);  return 0;}//////////////////////////////////////////////////////////////////////////////// Create GLX pixmap for offscreen renderingint GLContext::InitGLXPixmap(GLXContext shareList){  XVisualInfo *visual;  Window win;  int depth;  int attrCount;  int attrList[32];  // TODO: honor color bits request  attrCount = 0;  attrList[attrCount++] = GLX_RGBA;  attrList[attrCount++] = GLX_DEPTH_SIZE;  attrList[attrCount++] = this->reqDepth;  attrList[attrCount++] = None;  PRINT_MSG0(2, "trying GLX rendering");      // Get the default window and window depth  win = DefaultRootWindow(::display);  depth = DefaultDepth(::display, DefaultScreen(display));  // Create X pixmap  this->Xpixmap = XCreatePixmap(::display, win, this->reqWidth, this->reqHeight, depth);  if (!this->Xpixmap)  {        PRINT_MSG0(2, "unable to create X pixmap");    return -1;  }  // Find a suitable visual  visual = glXChooseVisual(::display, DefaultScreen(display), attrList);  if (!visual)  {    PRINT_GL_ERR();        PRINT_MSG0(2, "unable to get suitable visual");    return -1;  }  // Create a GLX pixmap  this->pixmap = glXCreateGLXPixmap(::display, visual, this->Xpixmap);  if (!this->pixmap)  {    PRINT_GL_ERR();    PRINT_MSG0(2, "unable to create glX pixmap");    return -1;  }  // Use this pixemap as our drawable  this->drawable = pixmap;    // Create the rendering context  this->context = glXCreateContext(::display, visual, shareList, False);  if (!this->context)  {    PRINT_GL_ERR();    PRINT_MSG0(2, "unable to create context");    return -1;  }  int a[5];  glXGetConfig(::display, visual, GLX_RED_SIZE, a + 0);  glXGetConfig(::display, visual, GLX_GREEN_SIZE, a + 1);  glXGetConfig(::display, visual, GLX_BLUE_SIZE, a + 2);  glXGetConfig(::display, visual, GLX_ALPHA_SIZE, a + 3);  glXGetConfig(::display, visual, GLX_DEPTH_SIZE, a + 4);  // Print some info about the configuration  PRINT_MSG6(1, "rendering: [GLX offscreen] direct [%s] RGBA [%d %d %d %d] depth [%d]",             (glXIsDirect(::display, this->context) ? "yes" : "no"),             a[0], a[1], a[2], a[3], a[4]);          return 0;}//////////////////////////////////////////////////////////////////////////////// Create SGI pbuffer for offscreen renderingint GLContext::InitSGIX( GLXContext shareList ){#ifdef HAVE_PBUFFER  int i;  XVisualInfo *visual;  GLXFBConfigSGIX config, *configs;  int config_count;  int attrCount;  int attrList[32];  int a[10];  // TODO: honor color bits request  attrCount = 0;  attrList[attrCount++] = GLX_RENDER_TYPE_SGIX;  attrList[attrCount++] = GLX_RGBA_BIT_SGIX;  attrList[attrCount++] = GLX_DEPTH_SIZE;  attrList[attrCount++] = this->reqDepth;  attrList[attrCount++] = None;    PRINT_MSG0(2, "trying SGIX pbuffer rendering");  // Get possible configurations  config = NULL;  config_count = 0;  configs = glXChooseFBConfigSGIX(::display, 0, attrList, &config_count);  PRINT_GL_ERR();      // Loop through configs and look for a suitable one  for (i = 0; i < config_count; i++)  {    config = configs[i];    glXGetFBConfigAttribSGIX(::display, config, GLX_RED_SIZE, a + 0);    glXGetFBConfigAttribSGIX(::display, config, GLX_GREEN_SIZE, a + 1);    glXGetFBConfigAttribSGIX(::display, config, GLX_BLUE_SIZE, a + 2);    glXGetFBConfigAttribSGIX(::display, config, GLX_ALPHA_SIZE, a + 3);    glXGetFBConfigAttribSGIX(::display, config, GLX_DEPTH_SIZE, a + 4);            // Print some info about the configuration    PRINT_MSG5(2, "[SGIX pbuffer] RGBA [%d %d %d %d] depth [%d]",               a[0], a[1], a[2], a[3], a[4]);        this->pbuffer = glXCreateGLXPbufferSGIX(::display, config,                                            this->reqWidth, this->reqHeight, attrList);    PRINT_GL_ERR();    if (this->pbuffer)      break;  }  if (!this->pbuffer)  {    PRINT_MSG0(2, "unable to create SGIX pbuffer; no matching configs");    return -1;  }  // Use this buffer as our drawable  this->drawable = pbuffer;   // Get the visual  visual = glXGetVisualFromFBConfigSGIX(::display, config);  PRINT_GL_ERR();  if (!visual)  {    PRINT_MSG0(2, "unable to get suitable visual");    return -1;  }  // Get the rendering context  this->context = glXCreateContext(::display, visual, shareList, True);  PRINT_GL_ERR();  if (!this->context)  {    PRINT_MSG0(2, "unable to create context");    return -1;  }  glXGetFBConfigAttribSGIX(::display, config, GLX_RED_SIZE, a + 0);  glXGetFBConfigAttribSGIX(::display, config, GLX_GREEN_SIZE, a + 1);  glXGetFBConfigAttribSGIX(::display, config, GLX_BLUE_SIZE, a + 2);  glXGetFBConfigAttribSGIX(::display, config, GLX_ALPHA_SIZE, a + 3);  glXGetFBConfigAttribSGIX(::display, config, GLX_DEPTH_SIZE, a + 4);    // Print some info about the configuration  PRINT_MSG6(1, "rendering: [SGIX pbuffer] direct [%s] RGBA [%d %d %d %d] depth [%d]",             (glXIsDirect(::display, this->context) ? "yes" : "no"),              a[0], a[1], a[2], a[3], a[4]);  return 0;#else  PRINT_MSG0(2, "trying pbuffer rendering -- extension not present");  return -1;#endif}//////////////////////////////////////////////////////////////////////////////// Create SGI pbuffer for offscreen renderingint GLContext::InitGLXP( GLXContext shareList ){#ifdef HAVE_PBUFFER  XVisualInfo *visual;  GLXFBConfig config, *configs;  int i;  int nitems;  // TODO: honor color bits request    int attrib[]  =    {      //    GLX_DOUBLEBUFFER,  False,      GLX_RED_SIZE,      1,      GLX_GREEN_SIZE,    1,      GLX_BLUE_SIZE,     1,      GLX_DEPTH_SIZE,    this->reqDepth,      GLX_RENDER_TYPE,   GLX_RGBA_BIT,      //    GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT | GLX_WINDOW_BIT,      None    };  int pbufAttrib[] =    {      GLX_PBUFFER_WIDTH,   this->reqWidth,      GLX_PBUFFER_HEIGHT,  this->reqHeight,      //    GLX_RENDER_TYPE,     GLX_RGBA_BIT,      //    GLX_DEPTH_SIZE, this->reqDepth,      GLX_LARGEST_PBUFFER, False,      None    };  int a[10];    PRINT_MSG0(2, "trying GLXP pbuffer rendering");  config = NULL;  configs = glXChooseFBConfig(::display,0,attrib,&nitems);  PRINT_GL_ERR();  if (!configs)  {    PRINT_MSG0(2, "unable to create GLXP pbuffer; no matching configs");    return -1;  }    for (i=0;i<nitems;i++)  {    config = configs[i];    this->pbuffer = glXCreatePbuffer(::display, config, pbufAttrib);    PRINT_GL_ERR();    if (this->pbuffer)      break;  }  if (!this->pbuffer)  {    PRINT_MSG0(2, "unable to create GLXP pbuffer;");    return -1;  }    // Use this buffer as our drawable  this->drawable = pbuffer;   // Get the visual  visual = glXGetVisualFromFBConfig(::display, config);  PRINT_GL_ERR();  if (!visual)  {    PRINT_MSG0(2, "unable to get suitable visual");    return -1;  }  // Get the rendering context  this->context = glXCreateContext(::display, visual, shareList, True);  PRINT_GL_ERR();  if (!this->context)  {    PRINT_MSG0(2, "unable to create context");    return -1;  }  glXGetFBConfigAttrib(::display, config, GLX_RED_SIZE, a + 0);  glXGetFBConfigAttrib(::display, config, GLX_GREEN_SIZE, a + 1);  glXGetFBConfigAttrib(::display, config, GLX_BLUE_SIZE, a + 2);  glXGetFBConfigAttrib(::display, config, GLX_ALPHA_SIZE, a + 3);  glXGetFBConfigAttrib(::display, config, GLX_DEPTH_SIZE, a + 4);    // Print some info about the configuration  PRINT_MSG6(1, "rendering: [GLXP pbuffer] direct [%s] RGBA [%d %d %d %d] depth [%d]",             (glXIsDirect(::display, this->context) ? "yes" : "no"),              a[0], a[1], a[2], a[3], a[4]);  return 0;#else  PRINT_MSG0(2, "trying pbuffer rendering -- extension not present");  return -1;#endif}//////////////////////////////////////////////////////////////////////////////// Finalize the cameravoid GLContext::Fini(){  return;}//////////////////////////////////////////////////////////////////////////////// Make this the current rendering contextint GLContext::MakeCurrent(){  if (!glXMakeCurrent(::display, this->drawable, this->context))  {    PRINT_GL_ERR();    return -1;  }  return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?