sgl
diff src/wsys_x11.c @ 3:1b6c5dadb460
started hacking the X11 module
author | John Tsiombikas <nuclear@siggraph.org> |
---|---|
date | Wed, 11 May 2011 09:09:43 +0300 |
parents | |
children | 648f8604d2b2 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/wsys_x11.c Wed May 11 09:09:43 2011 +0300 1.3 @@ -0,0 +1,97 @@ 1.4 +#include <X11/Xlib.h> 1.5 +#include <GL/glx.h> 1.6 +#include "wsys.h" 1.7 + 1.8 +struct window { 1.9 + Window win; 1.10 + GLXContext ctx; 1.11 + struct window *next; 1.12 +}; 1.13 + 1.14 +static int init(void); 1.15 +static void shutdown(void); 1.16 +static int set_vidmode(int xsz, int ysz, int bpp); 1.17 +static int get_vidmode(int *xsz, int *ysz, int *bpp); 1.18 +static int create_window(int xsz, int ysz, unsigned int flags); 1.19 +static void close_window(int id); 1.20 + 1.21 +static struct wsys_module ws = { 1.22 + "x11-glx", 0, 1.23 + init, 1.24 + shutdown, 1.25 + set_vidmode, 1.26 + get_vidmode, 1.27 + create_window, 1.28 + close_window, 1.29 + 0 1.30 +}; 1.31 + 1.32 +static Display *dpy; 1.33 +static int scr; 1.34 +static struct window *winlist; 1.35 + 1.36 + 1.37 +void sgl_register_x11(void) 1.38 +{ 1.39 + sgl_register_module(&ws); 1.40 +} 1.41 + 1.42 +static int init(void) 1.43 +{ 1.44 + winlist = 0; 1.45 + 1.46 + if(!(dpy = XOpenDisplay(0))) { 1.47 + return -1; 1.48 + } 1.49 + scr = DefaultScreen(dpy); 1.50 + 1.51 + return 0; 1.52 +} 1.53 + 1.54 +static void shutdown(void) 1.55 +{ 1.56 + while(winlist) { 1.57 + struct window *win = winlist; 1.58 + winlist = winlist->next; 1.59 + 1.60 + glXDestroyContext(dpy, win->ctx); 1.61 + XCloseWindow(dpy, win->win); 1.62 + free(win); 1.63 + } 1.64 + XCloseDisplay(dpy); 1.65 + dpy = 0; 1.66 +} 1.67 + 1.68 +static int set_vidmode(int xsz, int ysz, int bpp) 1.69 +{ 1.70 + /* TODO */ 1.71 +} 1.72 + 1.73 +static int get_vidmode(int *xsz, int *ysz, int *bpp) 1.74 +{ 1.75 + /* TODO */ 1.76 +} 1.77 + 1.78 +static int create_window(int xsz, int ysz, unsigned int flags) 1.79 +{ 1.80 +} 1.81 + 1.82 +static void close_window(int id) 1.83 +{ 1.84 + struct window dummy, *win, *prev; 1.85 + dummy.next = winlist; 1.86 + 1.87 + prev = &dummy; 1.88 + win = prev->next; 1.89 + 1.90 + while(win) { 1.91 + if(win->win == id) { 1.92 + glXDestroyContext(dpy, win->ctx); 1.93 + XCloseWindow(dpy, win->win); 1.94 + prev->next = win->next; 1.95 + free(win); 1.96 + return; 1.97 + } 1.98 + win = win->next; 1.99 + } 1.100 +}