]> git.tdb.fi Git - libs/gltk.git/blob - source/window.cpp
Rework event passing system to allow for pointer grabs
[libs/gltk.git] / source / window.cpp
1 #include <vector>
2 #include <GL/glx.h>
3 #include <msp/core/error.h>
4 #include "window.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace GLtk {
10
11 DisplayOptions::DisplayOptions():
12         width(640),
13         height(480),
14         depth(24),
15         alpha(false),
16         doublebuffer(false),
17         multisample(0),
18         fullscreen(false)
19 { }
20
21
22 Window::Window(unsigned w, unsigned h)
23 {
24         DisplayOptions dopt;
25         dopt.width=w;
26         dopt.height=h;
27
28         init(dopt);
29 }
30
31 Window::Window(const DisplayOptions &dopt)
32 {
33         init(dopt);
34 }
35
36 Window::~Window()
37 {
38         XCloseDisplay(display);
39 }
40
41 void Window::init(const DisplayOptions &dopt)
42 {
43         display=XOpenDisplay(0);
44         if(!display)
45                 throw Exception("Couldn't open X display");
46
47         vector<int> attribs;
48         attribs.push_back(GLX_BUFFER_SIZE);
49         attribs.push_back(dopt.depth);
50         attribs.push_back(GLX_DOUBLEBUFFER);
51         attribs.push_back(1);
52         if(dopt.multisample>0)
53         {
54                 attribs.push_back(GLX_SAMPLE_BUFFERS_ARB);
55                 attribs.push_back(dopt.multisample);
56         }
57
58         XVisualInfo *visual=glXChooseVisual(display, DefaultScreen(display), &attribs.front());
59         if(!visual)
60                 throw Exception("Couldn't get a matching visual");
61
62         window=XCreateWindow(display, DefaultRootWindow(display), 0, 0, dopt.width, dopt.height, 0, CopyFromParent, InputOutput, visual->visual, 0, 0);
63 }
64
65 } // namespace GLtk
66 } // namespace Msp