2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <X11/Xutil.h>
30 #include <X11/keysym.h>
31 #include <X11/cursorfont.h>
34 #include <X11/extensions/XShm.h>
35 #if !defined(__APPLE__) && !defined(__MACH__) && !defined(SUNOS)
36 #include <X11/extensions/xf86dga.h>
38 #include <X11/extensions/xf86vmode.h>
41 #include "darkplaces.xpm"
43 // Tell startup code that we have a client
44 int cl_available = true;
46 // note: if we used the XRandR extension we could support refresh rates
47 qboolean vid_supportrefreshrate = false;
50 XVisualInfo *(GLAPIENTRY *qglXChooseVisual)(Display *dpy, int screen, int *attribList);
51 GLXContext (GLAPIENTRY *qglXCreateContext)(Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct);
52 void (GLAPIENTRY *qglXDestroyContext)(Display *dpy, GLXContext ctx);
53 Bool (GLAPIENTRY *qglXMakeCurrent)(Display *dpy, GLXDrawable drawable, GLXContext ctx);
54 void (GLAPIENTRY *qglXSwapBuffers)(Display *dpy, GLXDrawable drawable);
55 const char *(GLAPIENTRY *qglXQueryExtensionsString)(Display *dpy, int screen);
57 //GLX_ARB_get_proc_address
58 void *(GLAPIENTRY *qglXGetProcAddressARB)(const GLubyte *procName);
60 static dllfunction_t getprocaddressfuncs[] =
62 {"glXGetProcAddressARB", (void **) &qglXGetProcAddressARB},
66 //GLX_SGI_swap_control
67 GLint (GLAPIENTRY *qglXSwapIntervalSGI)(GLint interval);
69 static dllfunction_t swapcontrolfuncs[] =
71 {"glXSwapIntervalSGI", (void **) &qglXSwapIntervalSGI},
75 static Display *vidx11_display = NULL;
76 static int vidx11_screen;
78 static GLXContext ctx = NULL;
80 Atom wm_delete_window_atom;
82 #define KEY_MASK (KeyPressMask | KeyReleaseMask)
83 #define MOUSE_MASK (ButtonPressMask | ButtonReleaseMask | \
84 PointerMotionMask | ButtonMotionMask)
85 #define X_MASK (KEY_MASK | MOUSE_MASK | VisibilityChangeMask | \
86 StructureNotifyMask | FocusChangeMask | EnterWindowMask | \
90 static qboolean mouse_avail = true;
91 static qboolean vid_usingmouse = false;
92 static qboolean vid_usingdgamouse = false;
93 static qboolean vid_usingvsync = false;
94 static qboolean vid_usevsync = false;
95 static qboolean vid_x11_hardwaregammasupported = false;
96 static qboolean vid_x11_dgasupported = false;
97 static int vid_x11_gammarampsize = 0;
98 static float mouse_x, mouse_y;
99 static int p_mouse_x, p_mouse_y;
101 #if !defined(__APPLE__) && !defined(SUNOS)
102 cvar_t vid_dgamouse = {CVAR_SAVE, "vid_dgamouse", "1", "make use of DGA mouse input"};
105 qboolean vidmode_ext = false;
107 static int win_x, win_y;
109 static XF86VidModeModeInfo init_vidmode;
110 static qboolean vid_isfullscreen = false;
112 static Visual *vidx11_visual;
113 static Colormap vidx11_colormap;
115 /*-----------------------------------------------------------------------*/
117 static int XLateKey(XKeyEvent *ev, char *ascii)
121 KeySym keysym, shifted;
123 keysym = XLookupKeysym (ev, 0);
124 XLookupString(ev, buf, sizeof buf, &shifted, 0);
129 case XK_KP_Page_Up: key = K_KP_PGUP; break;
130 case XK_Page_Up: key = K_PGUP; break;
132 case XK_KP_Page_Down: key = K_KP_PGDN; break;
133 case XK_Page_Down: key = K_PGDN; break;
135 case XK_KP_Home: key = K_KP_HOME; break;
136 case XK_Home: key = K_HOME; break;
138 case XK_KP_End: key = K_KP_END; break;
139 case XK_End: key = K_END; break;
141 case XK_KP_Left: key = K_KP_LEFTARROW; break;
142 case XK_Left: key = K_LEFTARROW; break;
144 case XK_KP_Right: key = K_KP_RIGHTARROW; break;
145 case XK_Right: key = K_RIGHTARROW; break;
147 case XK_KP_Down: key = K_KP_DOWNARROW; break;
148 case XK_Down: key = K_DOWNARROW; break;
150 case XK_KP_Up: key = K_KP_UPARROW; break;
151 case XK_Up: key = K_UPARROW; break;
153 case XK_Escape: key = K_ESCAPE; break;
155 case XK_KP_Enter: key = K_KP_ENTER; break;
156 case XK_Return: key = K_ENTER; break;
158 case XK_Tab: key = K_TAB; break;
160 case XK_F1: key = K_F1; break;
162 case XK_F2: key = K_F2; break;
164 case XK_F3: key = K_F3; break;
166 case XK_F4: key = K_F4; break;
168 case XK_F5: key = K_F5; break;
170 case XK_F6: key = K_F6; break;
172 case XK_F7: key = K_F7; break;
174 case XK_F8: key = K_F8; break;
176 case XK_F9: key = K_F9; break;
178 case XK_F10: key = K_F10; break;
180 case XK_F11: key = K_F11; break;
182 case XK_F12: key = K_F12; break;
184 case XK_BackSpace: key = K_BACKSPACE; break;
186 case XK_KP_Delete: key = K_KP_DEL; break;
187 case XK_Delete: key = K_DEL; break;
189 case XK_Pause: key = K_PAUSE; break;
192 case XK_Shift_R: key = K_SHIFT; break;
196 case XK_Control_R: key = K_CTRL; break;
200 case XK_ISO_Level3_Shift:
202 case XK_Meta_R: key = K_ALT; break;
204 case XK_KP_Begin: key = K_KP_5; break;
206 case XK_Insert:key = K_INS; break;
207 case XK_KP_Insert: key = K_KP_INS; break;
209 case XK_KP_Multiply: key = K_KP_MULTIPLY; break;
210 case XK_KP_Add: key = K_KP_PLUS; break;
211 case XK_KP_Subtract: key = K_KP_MINUS; break;
212 case XK_KP_Divide: key = K_KP_SLASH; break;
214 case XK_section: key = '~'; break;
220 if (keysym >= 'A' && keysym <= 'Z')
221 key = keysym - 'A' + 'a';
231 static Cursor CreateNullCursor(Display *display, Window root)
239 cursormask = XCreatePixmap(display, root, 1, 1, 1);
240 xgc.function = GXclear;
241 gc = XCreateGC(display, cursormask, GCFunction, &xgc);
242 XFillRectangle(display, cursormask, gc, 0, 0, 1, 1);
243 dummycolour.pixel = 0;
245 dummycolour.flags = 04;
246 cursor = XCreatePixmapCursor(display, cursormask, cursormask, &dummycolour,&dummycolour, 0,0);
247 XFreePixmap(display,cursormask);
252 static void IN_Activate (qboolean grab)
258 #if !defined(__APPLE__) && !defined(SUNOS)
259 if(vid_usingmouse && (vid_usingdgamouse != !!vid_dgamouse.integer))
260 IN_Activate(false); // ungrab first!
262 if (!vid_usingmouse && mouse_avail && win)
264 XWindowAttributes attribs_1;
265 XSetWindowAttributes attribs_2;
267 XGetWindowAttributes(vidx11_display, win, &attribs_1);
268 attribs_2.event_mask = attribs_1.your_event_mask | KEY_MASK | MOUSE_MASK;
269 XChangeWindowAttributes(vidx11_display, win, CWEventMask, &attribs_2);
272 XDefineCursor(vidx11_display, win, CreateNullCursor(vidx11_display, win));
274 XGrabPointer(vidx11_display, win, True, 0, GrabModeAsync, GrabModeAsync, win, None, CurrentTime);
276 #if !defined(__APPLE__) && !defined(SUNOS)
277 if (vid_dgamouse.integer && vid_x11_dgasupported)
279 XF86DGADirectVideo(vidx11_display, DefaultScreen(vidx11_display), XF86DGADirectMouse);
280 XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, 0, 0);
284 XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, vid.width / 2, vid.height / 2);
286 if (vid_grabkeyboard.integer || vid_isfullscreen)
287 XGrabKeyboard(vidx11_display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
289 mouse_x = mouse_y = 0;
290 cl_ignoremousemoves = 2;
291 vid_usingmouse = true;
292 vid_usingdgamouse = !!vid_dgamouse.integer;
299 #if !defined(__APPLE__) && !defined(SUNOS)
300 if (vid_x11_dgasupported)
301 XF86DGADirectVideo(vidx11_display, DefaultScreen(vidx11_display), 0);
304 XUngrabPointer(vidx11_display, CurrentTime);
305 XUngrabKeyboard(vidx11_display, CurrentTime);
309 XUndefineCursor(vidx11_display, win);
311 cl_ignoremousemoves = 2;
312 vid_usingmouse = false;
317 static keynum_t buttonremap[18] =
339 static void HandleEvents(void)
344 qboolean dowarp = false;
349 while (XPending(vidx11_display))
351 XNextEvent(vidx11_display, &event);
357 key = XLateKey (&event.xkey, &ascii);
358 Key_Event(key, ascii, true);
363 key = XLateKey (&event.xkey, &ascii);
364 Key_Event(key, ascii, false);
371 #if !defined(__APPLE__) && !defined(SUNOS)
372 if (vid_dgamouse.integer == 1 && vid_x11_dgasupported)
374 mouse_x += event.xmotion.x_root;
375 mouse_y += event.xmotion.y_root;
381 if (!event.xmotion.send_event)
383 mouse_x += event.xmotion.x - p_mouse_x;
384 mouse_y += event.xmotion.y - p_mouse_y;
385 if (abs(vid.width/2 - event.xmotion.x) > vid.width / 4 || abs(vid.height/2 - event.xmotion.y) > vid.height / 4)
388 p_mouse_x = event.xmotion.x;
389 p_mouse_y = event.xmotion.y;
393 // ui_mouseupdate(event.xmotion.x, event.xmotion.y);
397 // mouse button pressed
398 if (event.xbutton.button <= 18)
399 Key_Event(buttonremap[event.xbutton.button - 1], 0, true);
401 Con_Printf("HandleEvents: ButtonPress gave value %d, 1-18 expected\n", event.xbutton.button);
405 // mouse button released
406 if (event.xbutton.button <= 18)
407 Key_Event(buttonremap[event.xbutton.button - 1], 0, false);
409 Con_Printf("HandleEvents: ButtonRelease gave value %d, 1-18 expected\n", event.xbutton.button);
414 win_x = event.xcreatewindow.x;
415 win_y = event.xcreatewindow.y;
418 case ConfigureNotify:
419 // window changed size/location
420 win_x = event.xconfigure.x;
421 win_y = event.xconfigure.y;
422 if(vid_resizable.integer < 2)
424 vid.width = event.xconfigure.width;
425 vid.height = event.xconfigure.height;
429 // window has been destroyed
433 // window manager messages
434 if ((event.xclient.format == 32) && ((unsigned int)event.xclient.data.l[0] == wm_delete_window_atom))
440 VID_RestoreSystemGamma();
443 // window iconified/rolledup/whatever
445 VID_RestoreSystemGamma();
448 // window is now the input focus
449 vid_activewindow = true;
452 // window is no longer the input focus
453 vid_activewindow = false;
454 VID_RestoreSystemGamma();
457 // mouse entered window
467 /* move the mouse to the window center again */
468 p_mouse_x = vid.width / 2;
469 p_mouse_y = vid.height / 2;
470 XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, p_mouse_x, p_mouse_y);
474 static void *prjobj = NULL;
476 static void GL_CloseLibrary(void)
482 qglXGetProcAddressARB = NULL;
485 gl_platformextensions = "";
488 static int GL_OpenLibrary(const char *name)
490 Con_Printf("Loading OpenGL driver %s\n", name);
492 if (!(prjobj = dlopen(name, RTLD_LAZY | RTLD_GLOBAL)))
494 Con_Printf("Unable to open symbol list for %s\n", name);
497 strlcpy(gl_driver, name, sizeof(gl_driver));
501 void *GL_GetProcAddress(const char *name)
504 if (qglXGetProcAddressARB != NULL)
505 p = (void *) qglXGetProcAddressARB((GLubyte *)name);
507 p = (void *) dlsym(prjobj, name);
511 void VID_Shutdown(void)
513 if (!ctx || !vidx11_display)
519 VID_RestoreSystemGamma();
521 // FIXME: glXDestroyContext here?
522 if (vid_isfullscreen)
523 XF86VidModeSwitchToMode(vidx11_display, vidx11_screen, &init_vidmode);
525 XDestroyWindow(vidx11_display, win);
526 XCloseDisplay(vidx11_display);
529 vid_isfullscreen = false;
530 vidx11_display = NULL;
538 void signal_handler(int sig)
540 Con_Printf("Received signal %d, exiting...\n", sig);
541 VID_RestoreSystemGamma();
547 signal(SIGHUP, signal_handler);
548 signal(SIGINT, signal_handler);
549 signal(SIGQUIT, signal_handler);
550 signal(SIGILL, signal_handler);
551 signal(SIGTRAP, signal_handler);
552 signal(SIGIOT, signal_handler);
553 signal(SIGBUS, signal_handler);
554 signal(SIGFPE, signal_handler);
555 signal(SIGSEGV, signal_handler);
556 signal(SIGTERM, signal_handler);
559 void VID_Finish (qboolean allowmousegrab)
561 qboolean vid_usemouse;
563 vid_usevsync = vid_vsync.integer && !cls.timedemo && gl_videosyncavailable;
564 if (vid_usingvsync != vid_usevsync && gl_videosyncavailable)
566 vid_usingvsync = vid_usevsync;
567 if (qglXSwapIntervalSGI (vid_usevsync))
568 Con_Print("glXSwapIntervalSGI didn't accept the vid_vsync change, it will take effect on next vid_restart (GLX_SGI_swap_control does not allow turning off vsync)\n");
571 // handle the mouse state when windowed if that's changed
572 vid_usemouse = false;
573 if (allowmousegrab && vid_mouse.integer && !key_consoleactive && (key_dest != key_game || !cls.demoplayback))
575 if (!vid_activewindow)
576 vid_usemouse = false;
577 if (vid_isfullscreen)
579 IN_Activate(vid_usemouse);
581 if (r_render.integer)
584 if (r_speeds.integer || gl_finish.integer)
586 qglFinish();CHECKGLERROR
588 qglXSwapBuffers(vidx11_display, win);CHECKGLERROR
591 if (vid_x11_hardwaregammasupported)
592 VID_UpdateGamma(false, vid_x11_gammarampsize);
595 int VID_SetGamma(unsigned short *ramps, int rampsize)
597 return XF86VidModeSetGammaRamp(vidx11_display, vidx11_screen, rampsize, ramps, ramps + rampsize, ramps + rampsize*2);
600 int VID_GetGamma(unsigned short *ramps, int rampsize)
602 return XF86VidModeGetGammaRamp(vidx11_display, vidx11_screen, rampsize, ramps, ramps + rampsize, ramps + rampsize*2);
607 #if !defined(__APPLE__) && !defined(SUNOS)
608 Cvar_RegisterVariable (&vid_dgamouse);
610 InitSig(); // trap evil signals
611 // COMMANDLINEOPTION: Input: -nomouse disables mouse support (see also vid_mouse cvar)
612 if (COM_CheckParm ("-nomouse"))
616 void VID_BuildGLXAttrib(int *attrib, qboolean stencil, qboolean stereobuffer)
618 *attrib++ = GLX_RGBA;
619 *attrib++ = GLX_RED_SIZE;*attrib++ = 1;
620 *attrib++ = GLX_GREEN_SIZE;*attrib++ = 1;
621 *attrib++ = GLX_BLUE_SIZE;*attrib++ = 1;
622 *attrib++ = GLX_DOUBLEBUFFER;
623 *attrib++ = GLX_DEPTH_SIZE;*attrib++ = 1;
624 // if stencil is enabled, ask for alpha too
627 *attrib++ = GLX_STENCIL_SIZE;*attrib++ = 8;
628 *attrib++ = GLX_ALPHA_SIZE;*attrib++ = 1;
631 *attrib++ = GLX_STEREO;
635 int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate, int stereobuffer)
639 XSetWindowAttributes attr;
640 XClassHint *clshints;
645 XVisualInfo *visinfo;
646 int MajorVersion, MinorVersion;
647 const char *drivername;
649 #if defined(__APPLE__) && defined(__MACH__)
650 drivername = "/usr/X11R6/lib/libGL.1.dylib";
652 drivername = "libGL.so.1";
654 // COMMANDLINEOPTION: Linux GLX: -gl_driver <drivername> selects a GL driver library, default is libGL.so.1, useful only for using fxmesa or similar, if you don't know what this is for, you don't need it
655 // COMMANDLINEOPTION: BSD GLX: -gl_driver <drivername> selects a GL driver library, default is libGL.so.1, useful only for using fxmesa or similar, if you don't know what this is for, you don't need it
656 // LordHavoc: although this works on MacOSX, it's useless there (as there is only one system libGL)
657 i = COM_CheckParm("-gl_driver");
658 if (i && i < com_argc - 1)
659 drivername = com_argv[i + 1];
660 if (!GL_OpenLibrary(drivername))
662 Con_Printf("Unable to load GL driver \"%s\"\n", drivername);
666 if (!(vidx11_display = XOpenDisplay(NULL)))
668 Con_Print("Couldn't open the X display\n");
672 vidx11_screen = DefaultScreen(vidx11_display);
673 root = RootWindow(vidx11_display, vidx11_screen);
675 // Get video mode list
676 MajorVersion = MinorVersion = 0;
677 if (!XF86VidModeQueryVersion(vidx11_display, &MajorVersion, &MinorVersion))
681 Con_DPrintf("Using XFree86-VidModeExtension Version %d.%d\n", MajorVersion, MinorVersion);
685 if ((qglXChooseVisual = (XVisualInfo *(GLAPIENTRY *)(Display *dpy, int screen, int *attribList))GL_GetProcAddress("glXChooseVisual")) == NULL
686 || (qglXCreateContext = (GLXContext (GLAPIENTRY *)(Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct))GL_GetProcAddress("glXCreateContext")) == NULL
687 || (qglXDestroyContext = (void (GLAPIENTRY *)(Display *dpy, GLXContext ctx))GL_GetProcAddress("glXDestroyContext")) == NULL
688 || (qglXMakeCurrent = (Bool (GLAPIENTRY *)(Display *dpy, GLXDrawable drawable, GLXContext ctx))GL_GetProcAddress("glXMakeCurrent")) == NULL
689 || (qglXSwapBuffers = (void (GLAPIENTRY *)(Display *dpy, GLXDrawable drawable))GL_GetProcAddress("glXSwapBuffers")) == NULL
690 || (qglXQueryExtensionsString = (const char *(GLAPIENTRY *)(Display *dpy, int screen))GL_GetProcAddress("glXQueryExtensionsString")) == NULL)
692 Con_Printf("glX functions not found in %s\n", gl_driver);
696 VID_BuildGLXAttrib(attrib, bpp == 32, stereobuffer);
697 visinfo = qglXChooseVisual(vidx11_display, vidx11_screen, attrib);
700 Con_Print("Couldn't get an RGB, Double-buffered, Depth visual\n");
706 int best_fit, best_dist, dist, x, y;
708 // Are we going fullscreen? If so, let's change video mode
711 XF86VidModeModeLine *current_vidmode;
712 XF86VidModeModeInfo **vidmodes;
715 // This nice hack comes from the SDL source code
716 current_vidmode = (XF86VidModeModeLine*)((char*)&init_vidmode + sizeof(init_vidmode.dotclock));
717 XF86VidModeGetModeLine(vidx11_display, vidx11_screen, (int*)&init_vidmode.dotclock, current_vidmode);
719 XF86VidModeGetAllModeLines(vidx11_display, vidx11_screen, &num_vidmodes, &vidmodes);
723 for (i = 0; i < num_vidmodes; i++)
725 if (width > vidmodes[i]->hdisplay || height > vidmodes[i]->vdisplay)
728 x = width - vidmodes[i]->hdisplay;
729 y = height - vidmodes[i]->vdisplay;
730 dist = (x * x) + (y * y);
731 if (dist < best_dist)
740 // LordHavoc: changed from ActualWidth/ActualHeight =,
741 // to width/height =, so the window will take the full area of
743 width = vidmodes[best_fit]->hdisplay;
744 height = vidmodes[best_fit]->vdisplay;
746 // change to the mode
747 XF86VidModeSwitchToMode(vidx11_display, vidx11_screen, vidmodes[best_fit]);
748 vid_isfullscreen = true;
750 // Move the viewport to top left
751 XF86VidModeSetViewPort(vidx11_display, vidx11_screen, 0, 0);
760 // LordHavoc: save the visual for use in gamma ramp settings later
761 vidx11_visual = visinfo->visual;
763 /* window attributes */
764 attr.background_pixel = 0;
765 attr.border_pixel = 0;
766 // LordHavoc: save the colormap for later, too
767 vidx11_colormap = attr.colormap = XCreateColormap(vidx11_display, root, visinfo->visual, AllocNone);
768 attr.event_mask = X_MASK;
769 if (vid_isfullscreen)
771 mask = CWBackPixel | CWColormap | CWSaveUnder | CWBackingStore | CWEventMask | CWOverrideRedirect;
772 attr.override_redirect = True;
773 attr.backing_store = NotUseful;
774 attr.save_under = False;
777 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
779 win = XCreateWindow(vidx11_display, root, 0, 0, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr);
781 wmhints = XAllocWMHints();
782 if(XpmCreatePixmapFromData(vidx11_display, win,
783 (gamemode == GAME_NEXUIZ) ? nexuiz_xpm : darkplaces_xpm,
784 &wmhints->icon_pixmap, &wmhints->icon_mask, NULL) == XpmSuccess)
785 wmhints->flags |= IconPixmapHint | IconMaskHint;
787 clshints = XAllocClassHint();
788 clshints->res_name = strdup(gamename);
789 clshints->res_class = strdup("DarkPlaces");
791 szhints = XAllocSizeHints();
792 if(vid_resizable.integer == 0)
794 szhints->min_width = szhints->max_width = width;
795 szhints->min_height = szhints->max_height = height;
796 szhints->flags |= PMinSize | PMaxSize;
799 XmbSetWMProperties(vidx11_display, win, gamename, gamename, (char **) com_argv, com_argc, szhints, wmhints, clshints);
803 //XStoreName(vidx11_display, win, gamename);
804 XMapWindow(vidx11_display, win);
806 // LordHavoc: making the close button on a window do the right thing
807 // seems to involve this mess, sigh...
808 wm_delete_window_atom = XInternAtom(vidx11_display, "WM_DELETE_WINDOW", false);
809 XSetWMProtocols(vidx11_display, win, &wm_delete_window_atom, 1);
811 if (vid_isfullscreen)
813 XMoveWindow(vidx11_display, win, 0, 0);
814 XRaiseWindow(vidx11_display, win);
815 XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, 0, 0);
816 XFlush(vidx11_display);
817 // Move the viewport to top left
818 XF86VidModeSetViewPort(vidx11_display, vidx11_screen, 0, 0);
821 //XSync(vidx11_display, False);
823 ctx = qglXCreateContext(vidx11_display, visinfo, NULL, True);
826 Con_Printf ("glXCreateContext failed\n");
830 if (!qglXMakeCurrent(vidx11_display, win, ctx))
832 Con_Printf ("glXMakeCurrent failed\n");
836 XSync(vidx11_display, False);
838 if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL)
840 Con_Printf ("glGetString not found in %s\n", gl_driver);
844 gl_renderer = (const char *)qglGetString(GL_RENDERER);
845 gl_vendor = (const char *)qglGetString(GL_VENDOR);
846 gl_version = (const char *)qglGetString(GL_VERSION);
847 gl_extensions = (const char *)qglGetString(GL_EXTENSIONS);
849 gl_platformextensions = qglXQueryExtensionsString(vidx11_display, vidx11_screen);
851 Con_DPrintf("GL_VENDOR: %s\n", gl_vendor);
852 Con_DPrintf("GL_RENDERER: %s\n", gl_renderer);
853 Con_DPrintf("GL_VERSION: %s\n", gl_version);
854 Con_DPrintf("GL_EXTENSIONS: %s\n", gl_extensions);
855 Con_DPrintf("%s_EXTENSIONS: %s\n", gl_platform, gl_platformextensions);
857 gl_videosyncavailable = false;
859 // COMMANDLINEOPTION: Linux GLX: -nogetprocaddress disables GLX_ARB_get_proc_address (not required, more formal method of getting extension functions)
860 // COMMANDLINEOPTION: BSD GLX: -nogetprocaddress disables GLX_ARB_get_proc_address (not required, more formal method of getting extension functions)
861 // COMMANDLINEOPTION: MacOSX GLX: -nogetprocaddress disables GLX_ARB_get_proc_address (not required, more formal method of getting extension functions)
862 GL_CheckExtension("GLX_ARB_get_proc_address", getprocaddressfuncs, "-nogetprocaddress", false);
863 // COMMANDLINEOPTION: Linux GLX: -novideosync disables GLX_SGI_swap_control
864 // COMMANDLINEOPTION: BSD GLX: -novideosync disables GLX_SGI_swap_control
865 // COMMANDLINEOPTION: MacOSX GLX: -novideosync disables GLX_SGI_swap_control
866 gl_videosyncavailable = GL_CheckExtension("GLX_SGI_swap_control", swapcontrolfuncs, "-novideosync", false);
868 vid_usingmouse = false;
869 vid_usingvsync = false;
871 vid_activewindow = true;
872 vid_x11_hardwaregammasupported = XF86VidModeGetGammaRampSize(vidx11_display, vidx11_screen, &vid_x11_gammarampsize) != 0;
873 #if !defined(__APPLE__) && !defined(SUNOS)
874 vid_x11_dgasupported = XF86DGAQueryVersion(vidx11_display, &MajorVersion, &MinorVersion);
875 if (!vid_x11_dgasupported)
876 Con_Print( "Failed to detect XF86DGA Mouse extension\n" );
882 void Sys_SendKeyEvents(void)
884 static qboolean sound_active = true;
886 // enable/disable sound on focus gain/loss
887 if (!vid_hidden && (vid_activewindow || !snd_mutewhenidle.integer))
900 sound_active = false;
911 in_mouse_x = mouse_x;
912 in_mouse_y = mouse_y;