3 This file is part of libmspgbase
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
9 #include <msp/core/error.h>
16 GLDisplayOptions::GLDisplayOptions():
24 GLWindow::GLWindow(unsigned w, unsigned h)
31 GLWindow::GLWindow(const DisplayOptions &dopt, const GLDisplayOptions &gl_dopt)
40 glXMakeContextCurrent(display, 0, 0, 0);
41 glXDestroyWindow(display, glx_wnd);
42 glXDestroyContext(display, context);
45 void GLWindow::swap_buffers()
47 glXSwapBuffers(display, glx_wnd);
56 attribs.push_back(GLX_RENDER_TYPE);
57 attribs.push_back(GLX_RGBA_BIT);
59 attribs.push_back(GLX_DRAWABLE_TYPE);
60 attribs.push_back(GLX_WINDOW_BIT);
62 attribs.push_back(GLX_DEPTH_SIZE);
67 attribs.push_back(GLX_ALPHA_SIZE);
71 if(gl_options.stencil)
73 attribs.push_back(GLX_STENCIL_SIZE);
77 if(gl_options.doublebuffer)
79 attribs.push_back(GLX_DOUBLEBUFFER);
80 attribs.push_back(true);
83 if(gl_options.multisample>0)
85 attribs.push_back(GLX_SAMPLE_BUFFERS_ARB);
86 attribs.push_back(gl_options.multisample);
89 attribs.push_back(None);
92 GLXFBConfig *config=glXChooseFBConfig(display, DefaultScreen(display), &attribs.front(), &count);
94 throw Exception("Couldn't get a GLX framebuffer configuration");
96 context=glXCreateNewContext(display, config[0], GLX_RGBA_TYPE, 0, true);
98 throw Exception("Couldn't create a GLX context");
100 XVisualInfo *vi=glXGetVisualFromFBConfig(display, config[0]);
101 Handle root=RootWindow(display, vi->screen);
103 Colormap cmap=XCreateColormap(display, root, vi->visual, AllocNone);
104 XSetWindowAttributes attr;
107 Handle wnd=XCreateWindow(display, root, 0, 0, options.width, options.height, 0, vi->depth, InputOutput, vi->visual, CWColormap, &attr);
110 glx_wnd=glXCreateWindow(display, config[0], wnd, 0);
112 glXMakeContextCurrent(display, glx_wnd, glx_wnd, context);
117 void GLWindow::on_event(const XEvent &event)
119 if(event.type==ConfigureNotify)
120 glViewport(0, 0, options.width, options.height);