Advertisement
Guest User

windowless opengl context C++

a guest
Mar 21st, 2014
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. void createWindowlessOpenGLContext()
  2. {
  3.     static glXCreateContextAttribsARBProc glXCreateContextAttribsARB = NULL;
  4.     static glXMakeContextCurrentARBProc   glXMakeContextCurrentARB   = NULL;
  5.  
  6.     glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  7.     glXMakeContextCurrentARB   = (glXMakeContextCurrentARBProc)   glXGetProcAddressARB( (const GLubyte *) "glXMakeContextCurrent"      );
  8.     CV_Assert(glXCreateContextAttribsARB != 0);
  9.     CV_Assert(glXMakeContextCurrentARB != 0);
  10.  
  11.     const char *displayName = NULL;
  12.     Display* display = XOpenDisplay( displayName );
  13.     CV_Assert(display != 0);
  14.  
  15.     static int visualAttribs[] = { None };
  16.     int numberOfFramebufferConfigurations = 0;
  17.     GLXFBConfig* fbConfigs = glXChooseFBConfig( display, DefaultScreen(display), visualAttribs, &numberOfFramebufferConfigurations );
  18.     CV_Assert(fbConfigs != 0);
  19.  
  20.     int context_attribs[] = {
  21.         GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
  22.         GLX_CONTEXT_MINOR_VERSION_ARB, 3,
  23.         GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
  24.         //    GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
  25.         //    GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
  26.         None
  27.     };
  28.  
  29.     GLXContext openGLContext = glXCreateContextAttribsARB( display, fbConfigs[0], 0, True, context_attribs);
  30.  
  31.  
  32.     int pbufferAttribs[] = {
  33.         GLX_PBUFFER_WIDTH,  32,
  34.         GLX_PBUFFER_HEIGHT, 32,
  35.         None
  36.     };
  37.     GLXPbuffer pbuffer = glXCreatePbuffer( display, fbConfigs[0], pbufferAttribs );
  38.  
  39.     XFree( fbConfigs );
  40.     XSync( display, False );
  41.  
  42.     if ( !glXMakeContextCurrent( display, pbuffer, pbuffer, openGLContext ) )
  43.     {
  44.         CV_Assert(false);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement