1.1 --- a/src/drivers/video_x11.c Sun Feb 05 04:05:27 2006 +0000
1.2 +++ b/src/drivers/video_x11.c Mon Mar 13 12:39:07 2006 +0000
1.5 - * $Id: video_x11.c,v 1.1 2006-02-05 04:05:27 nkeynes Exp $
1.6 + * $Id: video_x11.c,v 1.2 2006-03-13 12:39:07 nkeynes Exp $
1.8 - * Parent for all X11 display drivers.
1.9 + * Shared functions for all X11-based display drivers.
1.11 * Copyright (c) 2005 Nathan Keynes.
1.14 * GNU General Public License for more details.
1.17 +#include <X11/Xlib.h>
1.18 +#include <GL/glx.h>
1.21 #include "drivers/video_x11.h"
1.24 + * General X11 parameters. The front-end driver is expected to set this up
1.25 + * by calling video_x11_set_display after initializing itself.
1.27 Display *video_x11_display = NULL;
1.28 Screen *video_x11_screen = NULL;
1.29 Window video_x11_window = 0;
1.34 +GLXContext glx_context;
1.36 +gboolean glx_open = FALSE;
1.38 void video_x11_set_display( Display *display, Screen *screen, Window window )
1.40 video_x11_display = display;
1.42 video_x11_window = window;
1.46 +gboolean video_glx_create_window( int x, int y, int width, int height )
1.49 + const char *glxExts, *glxServer;
1.50 + int visual_attrs[] = { GLX_RGBA, GLX_RED_SIZE, 4,
1.51 + GLX_GREEN_SIZE, 4,
1.53 + GLX_ALPHA_SIZE, 4,
1.54 + GLX_DEPTH_SIZE, 16,
1.57 + int screen = XScreenNumberOfScreen(video_x11_screen);
1.58 + XSetWindowAttributes win_attrs;
1.59 + XVisualInfo *visual;
1.61 + if( glXQueryVersion( video_x11_display, &major, &minor ) == False ) {
1.62 + ERROR( "X Display lacks the GLX nature" );
1.65 + if( major < 1 || minor < 2 ) {
1.66 + ERROR( "X display supports GLX %d.%d, but we need at least 1.2", major, minor );
1.70 + glxExts = glXQueryExtensionsString( video_x11_display, screen );
1.71 + glxServer = glXQueryServerString( video_x11_display, screen, GLX_VENDOR );
1.72 + INFO( "GLX version %d.%d, %s. Supported exts: %s", major, minor,
1.73 + glxServer, glxExts );
1.75 + /* Find ourselves a nice visual */
1.76 + visual = glXChooseVisual( video_x11_display,
1.79 + if( visual == NULL ) {
1.80 + ERROR( "Unable to obtain a compatible visual" );
1.84 + /* And a matching gl context */
1.85 + glx_context = glXCreateContext( video_x11_display, visual, None, True );
1.86 + if( glx_context == NULL ) {
1.87 + ERROR( "Unable to obtain a GLX Context. Possibly your system is broken in some small, undefineable way" );
1.92 + /* Ok, all good so far. Unfortunately the visual we need to use will
1.93 + * almost certainly be different from the one our frame is using. Which
1.94 + * means we have to jump through the following hoops to create a
1.95 + * child window with the appropriate settings.
1.97 + win_attrs.event_mask = 0;
1.98 + win_attrs.colormap = XCreateColormap( video_x11_display,
1.99 + RootWindowOfScreen(video_x11_screen),
1.100 + visual->visual, AllocNone );
1.101 + glx_window = XCreateWindow( video_x11_display, video_x11_window,
1.102 + x, y, width, height, 0, visual->depth,
1.103 + InputOutput, visual->visual,
1.104 + CWColormap | CWEventMask,
1.106 + if( glx_window == None ) {
1.107 + /* Hrm. Aww, no window? */
1.108 + ERROR( "Unable to create GLX window" );
1.109 + glXDestroyContext( video_x11_display, glx_context );
1.110 + if( win_attrs.colormap )
1.111 + XFreeColormap( video_x11_display, win_attrs.colormap );
1.114 + XMapRaised( video_x11_display, glx_window );
1.116 + /* And finally set the window to be the active drawing area */
1.117 + if( glXMakeCurrent( video_x11_display, glx_window, glx_context ) == False ) {
1.118 + /* Ok you have _GOT_ to be kidding me */
1.119 + ERROR( "Unable to prepare GLX window for drawing" );
1.120 + XDestroyWindow( video_x11_display, glx_window );
1.121 + XFreeColormap( video_x11_display, win_attrs.colormap );
1.122 + glXDestroyContext( video_x11_display, glx_context );
1.130 +void video_glx_swap_buffers( void )
1.132 + glXSwapBuffers( video_x11_display, glx_window );
1.135 +void video_glx_create_pixmap( int width, int height )