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>
18 GLDisplayOptions::GLDisplayOptions():
25 GLWindow::GLWindow(unsigned w, unsigned h)
32 GLWindow::GLWindow(const DisplayOptions &dopt, const GLDisplayOptions &gl_dopt)
41 glXMakeCurrent(display, window, 0);
42 glXDestroyContext(display, context);
45 void GLWindow::swap_buffers()
47 glXSwapBuffers(display, window);
55 attribs.push_back(GLX_RGBA);
56 attribs.push_back(GLX_BUFFER_SIZE);
57 attribs.push_back(24);
60 attribs.push_back(GLX_ALPHA_SIZE);
63 if(gl_options.doublebuffer)
64 attribs.push_back(GLX_DOUBLEBUFFER);
65 if(gl_options.multisample>0)
67 attribs.push_back(GLX_SAMPLE_BUFFERS_ARB);
68 attribs.push_back(gl_options.multisample);
72 XVisualInfo *visual=glXChooseVisual(display, DefaultScreen(display), &attribs.front());
74 throw Exception("Couldn't get a matching GLX visual");
76 context=glXCreateContext(display, visual, 0, true);
78 throw Exception("Couldn't create a GLX context");
80 window=XCreateWindow(display, DefaultRootWindow(display), 0, 0, options.width, options.height, 0, CopyFromParent, InputOutput, CopyFromParent, 0, 0);
82 throw Exception("Couldn't create a window");
84 XSelectInput(display, window, ButtonPressMask|ButtonReleaseMask|PointerMotionMask|KeyPressMask|KeyReleaseMask);
86 glXMakeCurrent(display, window, context);