|  | @@ -3,11 +3,46 @@
 | 
	
		
			
			| 3 | 3 |  using namespace slop;
 | 
	
		
			
			| 4 | 4 |  
 | 
	
		
			
			| 5 | 5 |  slop::SlopWindow::SlopWindow() {
 | 
	
		
			
			| 6 |  | -    XVisualInfo visual;
 | 
	
		
			
			| 7 |  | -    XMatchVisualInfo(x11->display, DefaultScreen(x11->display), 32, TrueColor, &visual);
 | 
	
		
			
			|  | 6 | +    // Load up a opengl context
 | 
	
		
			
			|  | 7 | +    static int attributeList[] = { GLX_RENDER_TYPE, GLX_RGBA_BIT,
 | 
	
		
			
			|  | 8 | +                                   GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
 | 
	
		
			
			|  | 9 | +                                   GLX_DOUBLEBUFFER, True,
 | 
	
		
			
			|  | 10 | +                                   GLX_RED_SIZE, 1,
 | 
	
		
			
			|  | 11 | +                                   GLX_GREEN_SIZE, 1,
 | 
	
		
			
			|  | 12 | +                                   GLX_BLUE_SIZE, 1,
 | 
	
		
			
			|  | 13 | +                                   GLX_ALPHA_SIZE, 1,
 | 
	
		
			
			|  | 14 | +				   GLX_DEPTH_SIZE, 1,
 | 
	
		
			
			|  | 15 | +                                   None };
 | 
	
		
			
			|  | 16 | +    int nelements;
 | 
	
		
			
			|  | 17 | +    int render_event_base, render_error_base;
 | 
	
		
			
			|  | 18 | +    if(!XRenderQueryExtension(x11->display, &render_event_base, &render_error_base)) {
 | 
	
		
			
			|  | 19 | +        throw new std::runtime_error("No XRENDER extension found\n");
 | 
	
		
			
			|  | 20 | +    }
 | 
	
		
			
			|  | 21 | +
 | 
	
		
			
			|  | 22 | +    GLXFBConfig* fbc = glXChooseFBConfig(x11->display, DefaultScreen(x11->display), attributeList, &nelements);
 | 
	
		
			
			|  | 23 | +    GLXFBConfig fbconfig;
 | 
	
		
			
			|  | 24 | +    if ( !fbc ) {
 | 
	
		
			
			|  | 25 | +        throw new std::runtime_error("No matching visuals available.\n");
 | 
	
		
			
			|  | 26 | +    }
 | 
	
		
			
			|  | 27 | +    XVisualInfo* vi ;
 | 
	
		
			
			|  | 28 | +    XRenderPictFormat *pictFormat;
 | 
	
		
			
			|  | 29 | +    int i;
 | 
	
		
			
			|  | 30 | +    for (i=0; i<nelements; i++) {
 | 
	
		
			
			|  | 31 | +        vi = glXGetVisualFromFBConfig(x11->display, fbc[i]);
 | 
	
		
			
			|  | 32 | +        if (!vi) { continue; }
 | 
	
		
			
			|  | 33 | +        pictFormat = XRenderFindVisualFormat(x11->display, vi->visual);
 | 
	
		
			
			|  | 34 | +        if (!pictFormat) { continue; }
 | 
	
		
			
			|  | 35 | +        if(pictFormat->direct.alphaMask > 0) {
 | 
	
		
			
			|  | 36 | +            fbconfig = fbc[i];
 | 
	
		
			
			|  | 37 | +            break;
 | 
	
		
			
			|  | 38 | +        }
 | 
	
		
			
			|  | 39 | +    }
 | 
	
		
			
			|  | 40 | +    if (i == nelements ) {
 | 
	
		
			
			|  | 41 | +	    throw new std::runtime_error( "No matching visuals available" );
 | 
	
		
			
			|  | 42 | +    }
 | 
	
		
			
			| 8 | 43 |  
 | 
	
		
			
			| 9 | 44 |      XSetWindowAttributes attributes;
 | 
	
		
			
			| 10 |  | -    attributes.colormap = XCreateColormap( x11->display, x11->root, visual.visual, AllocNone );
 | 
	
		
			
			|  | 45 | +    attributes.colormap = XCreateColormap(x11->display, RootWindow(x11->display, vi->screen), vi->visual, AllocNone);
 | 
	
		
			
			| 11 | 46 |      attributes.background_pixmap = None;
 | 
	
		
			
			| 12 | 47 |      attributes.border_pixel = 0;
 | 
	
		
			
			| 13 | 48 |      // Disable window decorations.
 | 
	
	
		
			
			|  | @@ -18,15 +53,15 @@ slop::SlopWindow::SlopWindow() {
 | 
	
		
			
			| 18 | 53 |  
 | 
	
		
			
			| 19 | 54 |  
 | 
	
		
			
			| 20 | 55 |      // Create the window
 | 
	
		
			
			| 21 |  | -    window = XCreateWindow( slop::x11->display, x11->root, 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ),
 | 
	
		
			
			| 22 |  | -                            0, visual.depth, InputOutput,
 | 
	
		
			
			| 23 |  | -                            visual.visual, valueMask, &attributes );
 | 
	
		
			
			|  | 56 | +    window = XCreateWindow( x11->display, x11->root, 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ),
 | 
	
		
			
			|  | 57 | +                            0, vi->depth, InputOutput,
 | 
	
		
			
			|  | 58 | +                            vi->visual, valueMask, &attributes );
 | 
	
		
			
			| 24 | 59 |  
 | 
	
		
			
			| 25 | 60 |      if ( !window ) {
 | 
	
		
			
			| 26 | 61 |          throw new std::runtime_error( "Couldn't create a GL window!" );
 | 
	
		
			
			| 27 | 62 |      }
 | 
	
		
			
			| 28 | 63 |  
 | 
	
		
			
			| 29 |  | -	// Prep some hints for the window
 | 
	
		
			
			|  | 64 | +    // Prep some hints for the window
 | 
	
		
			
			| 30 | 65 |      static char title[] = "slop";
 | 
	
		
			
			| 31 | 66 |      XWMHints* startup_state = XAllocWMHints();
 | 
	
		
			
			| 32 | 67 |      startup_state->initial_state = NormalState;
 | 
	
	
		
			
			|  | @@ -46,18 +81,17 @@ slop::SlopWindow::SlopWindow() {
 | 
	
		
			
			| 46 | 81 |      char name[] = "slop";
 | 
	
		
			
			| 47 | 82 |      classhints.res_name = name;
 | 
	
		
			
			| 48 | 83 |      classhints.res_class = name;
 | 
	
		
			
			| 49 |  | -	// Finally send it all over...
 | 
	
		
			
			|  | 84 | +    // Finally send it all over...
 | 
	
		
			
			| 50 | 85 |      XSetClassHint( x11->display, window, &classhints );
 | 
	
		
			
			| 51 | 86 |      XSetWMProperties( x11->display, window, &textprop, &textprop, NULL, 0, &sizehints, startup_state, NULL );
 | 
	
		
			
			| 52 | 87 |      XFree( startup_state );
 | 
	
		
			
			| 53 |  | -	// Keep the window on top of all other windows.
 | 
	
		
			
			| 54 |  | -	Atom stateAbove = XInternAtom(x11->display, "_NET_WM_STATE_ABOVE", False);
 | 
	
		
			
			| 55 |  | -	XChangeProperty(x11->display, window, XInternAtom(x11->display, "_NET_WM_STATE", False), XA_ATOM, 32, PropModeReplace, (unsigned char *) &stateAbove, 1);
 | 
	
		
			
			|  | 88 | +    // Keep the window on top of all other windows.
 | 
	
		
			
			|  | 89 | +    Atom stateAbove = XInternAtom(x11->display, "_NET_WM_STATE_ABOVE", False);
 | 
	
		
			
			|  | 90 | +    XChangeProperty(x11->display, window, XInternAtom(x11->display, "_NET_WM_STATE", False), XA_ATOM, 32, PropModeReplace, (unsigned char *) &stateAbove, 1);
 | 
	
		
			
			| 56 | 91 |  
 | 
	
		
			
			| 57 |  | -    // Load up a opengl context
 | 
	
		
			
			| 58 |  | -    context = glXCreateContext( x11->display, &visual, 0, True );
 | 
	
		
			
			|  | 92 | +    context = glXCreateNewContext( x11->display, fbconfig, GLX_RGBA_TYPE, 0, True );
 | 
	
		
			
			| 59 | 93 |      if ( !context ) {
 | 
	
		
			
			| 60 |  | -		throw new std::runtime_error( "Failed to create an OpenGL context." );
 | 
	
		
			
			|  | 94 | +        throw new std::runtime_error( "Failed to create an OpenGL context." );
 | 
	
		
			
			| 61 | 95 |      }
 | 
	
		
			
			| 62 | 96 |      setCurrent();
 | 
	
		
			
			| 63 | 97 |      // Finally we grab some OpenGL 3.3 stuffs.
 | 
	
	
		
			
			|  | @@ -71,7 +105,7 @@ slop::SlopWindow::SlopWindow() {
 | 
	
		
			
			| 71 | 105 |      camera = glm::ortho( 0.0f, (float)WidthOfScreen( x11->screen ), (float)HeightOfScreen( x11->screen ), 0.0f, -1.0f, 1.0f);
 | 
	
		
			
			| 72 | 106 |  
 | 
	
		
			
			| 73 | 107 |      // Last, we actually display the window <:o)
 | 
	
		
			
			| 74 |  | -	XMapWindow( x11->display, window );
 | 
	
		
			
			|  | 108 | +    XMapWindow( x11->display, window );
 | 
	
		
			
			| 75 | 109 |  }
 | 
	
		
			
			| 76 | 110 |  
 | 
	
		
			
			| 77 | 111 |  slop::SlopWindow::~SlopWindow() {
 |