- PIXELFORMATDESCRIPTOR pfd;
- memset(&pfd, 0, sizeof(pfd));
-
- pfd.nSize = sizeof(pfd);
- pfd.nVersion = 1;
- pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
- if(opts.doublebuffer)
- pfd.dwFlags |= PFD_DOUBLEBUFFER;
- pfd.iPixelType = PFD_TYPE_RGBA;
- if(opts.alpha)
- pfd.cAlphaBits = 1;
- pfd.cDepthBits = 1;
- if(opts.stencil)
- pfd.cStencilBits = 1;
-
- int pf_index = ChoosePixelFormat(dc, &pfd);
- if(!pf_index)
- throw unsupported_gl_mode(opts);
- SetPixelFormat(dc, pf_index, &pfd);
-
- priv->context = wglCreateContext(dc);
- wglMakeCurrent(dc, priv->context);
-
- ReleaseDC(window.get_private().window, dc);
-#else
- std::vector<int> attribs;
-
- attribs.push_back(GLX_RGBA);
- attribs.push_back(GLX_DEPTH_SIZE);
- attribs.push_back(1);
-
- if(opts.alpha)
- {
- attribs.push_back(GLX_ALPHA_SIZE);
- attribs.push_back(1);
- }
-
- if(opts.stencil)
- {
- attribs.push_back(GLX_STENCIL_SIZE);
- attribs.push_back(1);
- }
-
- if(opts.doublebuffer)
- attribs.push_back(GLX_DOUBLEBUFFER);
-
- if(opts.multisample>0)
- {
- attribs.push_back(GLX_SAMPLE_BUFFERS_ARB);
- attribs.push_back(opts.multisample);
- }
-
- attribs.push_back(0);
-
- ::Display *dpy = display.get_private().display;
-
- XVisualInfo *vi = glXChooseVisual(dpy, DefaultScreen(dpy), &attribs.front());
- if(!vi)
- throw unsupported_gl_mode(opts);
- priv->context = glXCreateContext(dpy, vi, 0, true);
-
- XSetWindowAttributes attr;
- attr.colormap = XCreateColormap(dpy, DefaultRootWindow(dpy), vi->visual, AllocNone);
-
- priv->subwnd = XCreateWindow(dpy, window.get_private().window, 0, 0, window.get_width(), window.get_height(), 0, vi->depth, InputOutput, vi->visual, CWColormap, &attr);
- XMapWindow(dpy, priv->subwnd);
-
- XFree(vi);