Search
lxdream.org :: lxdream/src/drivers/video_x11.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/video_x11.c
changeset 103:9b9cfc5855e0
prev94:8d80d9c7cc7d
next108:565de331ccec
author nkeynes
date Mon Mar 13 12:39:07 2006 +0000 (18 years ago)
permissions -rw-r--r--
last change More rendering work in progress. Almost there now...
file annotate diff log raw
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.3 @@ -1,7 +1,7 @@
1.4 /**
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.7 *
1.8 - * Parent for all X11 display drivers.
1.9 + * Shared functions for all X11-based display drivers.
1.10 *
1.11 * Copyright (c) 2005 Nathan Keynes.
1.12 *
1.13 @@ -16,12 +16,27 @@
1.14 * GNU General Public License for more details.
1.15 */
1.16
1.17 +#include <X11/Xlib.h>
1.18 +#include <GL/glx.h>
1.19 +#include "dream.h"
1.20 +#include "video.h"
1.21 #include "drivers/video_x11.h"
1.22
1.23 +/**
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.26 + */
1.27 Display *video_x11_display = NULL;
1.28 Screen *video_x11_screen = NULL;
1.29 Window video_x11_window = 0;
1.30
1.31 +/**
1.32 + * GLX parameters.
1.33 + */
1.34 +GLXContext glx_context;
1.35 +Window glx_window;
1.36 +gboolean glx_open = FALSE;
1.37 +
1.38 void video_x11_set_display( Display *display, Screen *screen, Window window )
1.39 {
1.40 video_x11_display = display;
1.41 @@ -29,3 +44,97 @@
1.42 video_x11_window = window;
1.43 }
1.44
1.45 +
1.46 +gboolean video_glx_create_window( int x, int y, int width, int height )
1.47 +{
1.48 + int major, minor;
1.49 + const char *glxExts, *glxServer;
1.50 + int visual_attrs[] = { GLX_RGBA, GLX_RED_SIZE, 4,
1.51 + GLX_GREEN_SIZE, 4,
1.52 + GLX_BLUE_SIZE, 4,
1.53 + GLX_ALPHA_SIZE, 4,
1.54 + GLX_DEPTH_SIZE, 16,
1.55 + GLX_DOUBLEBUFFER,
1.56 + None };
1.57 + int screen = XScreenNumberOfScreen(video_x11_screen);
1.58 + XSetWindowAttributes win_attrs;
1.59 + XVisualInfo *visual;
1.60 +
1.61 + if( glXQueryVersion( video_x11_display, &major, &minor ) == False ) {
1.62 + ERROR( "X Display lacks the GLX nature" );
1.63 + return FALSE;
1.64 + }
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.67 + return FALSE;
1.68 + }
1.69 +
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.74 +
1.75 + /* Find ourselves a nice visual */
1.76 + visual = glXChooseVisual( video_x11_display,
1.77 + screen,
1.78 + visual_attrs );
1.79 + if( visual == NULL ) {
1.80 + ERROR( "Unable to obtain a compatible visual" );
1.81 + return FALSE;
1.82 + }
1.83 +
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.88 + return FALSE;
1.89 + }
1.90 +
1.91 +
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.96 + */
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.105 + &win_attrs );
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.112 + return FALSE;
1.113 + }
1.114 + XMapRaised( video_x11_display, glx_window );
1.115 +
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.123 + return FALSE;
1.124 + }
1.125 +
1.126 + glx_open = TRUE;
1.127 + return TRUE;
1.128 +}
1.129 +
1.130 +void video_glx_swap_buffers( void )
1.131 +{
1.132 + glXSwapBuffers( video_x11_display, glx_window );
1.133 +}
1.134 +
1.135 +void video_glx_create_pixmap( int width, int height )
1.136 +{
1.137 +
1.138 +}
.