sgl

view 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 source
1 #include <X11/Xlib.h>
2 #include <GL/glx.h>
3 #include "wsys.h"
5 struct window {
6 Window win;
7 GLXContext ctx;
8 struct window *next;
9 };
11 static int init(void);
12 static void shutdown(void);
13 static int set_vidmode(int xsz, int ysz, int bpp);
14 static int get_vidmode(int *xsz, int *ysz, int *bpp);
15 static int create_window(int xsz, int ysz, unsigned int flags);
16 static void close_window(int id);
18 static struct wsys_module ws = {
19 "x11-glx", 0,
20 init,
21 shutdown,
22 set_vidmode,
23 get_vidmode,
24 create_window,
25 close_window,
26 0
27 };
29 static Display *dpy;
30 static int scr;
31 static struct window *winlist;
34 void sgl_register_x11(void)
35 {
36 sgl_register_module(&ws);
37 }
39 static int init(void)
40 {
41 winlist = 0;
43 if(!(dpy = XOpenDisplay(0))) {
44 return -1;
45 }
46 scr = DefaultScreen(dpy);
48 return 0;
49 }
51 static void shutdown(void)
52 {
53 while(winlist) {
54 struct window *win = winlist;
55 winlist = winlist->next;
57 glXDestroyContext(dpy, win->ctx);
58 XCloseWindow(dpy, win->win);
59 free(win);
60 }
61 XCloseDisplay(dpy);
62 dpy = 0;
63 }
65 static int set_vidmode(int xsz, int ysz, int bpp)
66 {
67 /* TODO */
68 }
70 static int get_vidmode(int *xsz, int *ysz, int *bpp)
71 {
72 /* TODO */
73 }
75 static int create_window(int xsz, int ysz, unsigned int flags)
76 {
77 }
79 static void close_window(int id)
80 {
81 struct window dummy, *win, *prev;
82 dummy.next = winlist;
84 prev = &dummy;
85 win = prev->next;
87 while(win) {
88 if(win->win == id) {
89 glXDestroyContext(dpy, win->ctx);
90 XCloseWindow(dpy, win->win);
91 prev->next = win->next;
92 free(win);
93 return;
94 }
95 win = win->next;
96 }
97 }