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_usingvsync = false;
93 static qboolean vid_usevsync = false;
94 static qboolean vid_x11_hardwaregammasupported = false;
95 static qboolean vid_x11_dgasupported = false;
96 static int vid_x11_gammarampsize = 0;
98 #if !defined(__APPLE__) && !defined(SUNOS)
99 cvar_t vid_dgamouse = {CVAR_SAVE, "vid_dgamouse", "1", "make use of DGA mouse input"};
100 static qboolean vid_usingdgamouse = false;
103 qboolean vidmode_ext = false;
105 static int win_x, win_y;
107 static XF86VidModeModeInfo init_vidmode;
108 static qboolean vid_isfullscreen = false;
110 static Visual *vidx11_visual;
111 static Colormap vidx11_colormap;
113 /*-----------------------------------------------------------------------*/
115 static int XLateKey(XKeyEvent *ev, char *ascii)
119 KeySym keysym, shifted;
121 keysym = XLookupKeysym (ev, 0);
122 XLookupString(ev, buf, sizeof buf, &shifted, 0);
127 case XK_KP_Page_Up: key = K_KP_PGUP; break;
128 case XK_Page_Up: key = K_PGUP; break;
130 case XK_KP_Page_Down: key = K_KP_PGDN; break;
131 case XK_Page_Down: key = K_PGDN; break;
133 case XK_KP_Home: key = K_KP_HOME; break;
134 case XK_Home: key = K_HOME; break;
136 case XK_KP_End: key = K_KP_END; break;
137 case XK_End: key = K_END; break;
139 case XK_KP_Left: key = K_KP_LEFTARROW; break;
140 case XK_Left: key = K_LEFTARROW; break;
142 case XK_KP_Right: key = K_KP_RIGHTARROW; break;
143 case XK_Right: key = K_RIGHTARROW; break;
145 case XK_KP_Down: key = K_KP_DOWNARROW; break;
146 case XK_Down: key = K_DOWNARROW; break;
148 case XK_KP_Up: key = K_KP_UPARROW; break;
149 case XK_Up: key = K_UPARROW; break;
151 case XK_Escape: key = K_ESCAPE; break;
153 case XK_KP_Enter: key = K_KP_ENTER; break;
154 case XK_Return: key = K_ENTER; break;
156 case XK_Tab: key = K_TAB; break;
158 case XK_F1: key = K_F1; break;
160 case XK_F2: key = K_F2; break;
162 case XK_F3: key = K_F3; break;
164 case XK_F4: key = K_F4; break;
166 case XK_F5: key = K_F5; break;
168 case XK_F6: key = K_F6; break;
170 case XK_F7: key = K_F7; break;
172 case XK_F8: key = K_F8; break;
174 case XK_F9: key = K_F9; break;
176 case XK_F10: key = K_F10; break;
178 case XK_F11: key = K_F11; break;
180 case XK_F12: key = K_F12; break;
182 case XK_BackSpace: key = K_BACKSPACE; break;
184 case XK_KP_Delete: key = K_KP_DEL; break;
185 case XK_Delete: key = K_DEL; break;
187 case XK_Pause: key = K_PAUSE; break;
190 case XK_Shift_R: key = K_SHIFT; break;
194 case XK_Control_R: key = K_CTRL; break;
198 case XK_ISO_Level3_Shift:
200 case XK_Meta_R: key = K_ALT; break;
202 case XK_KP_Begin: key = K_KP_5; break;
204 case XK_Insert:key = K_INS; break;
205 case XK_KP_Insert: key = K_KP_INS; break;
207 case XK_KP_Multiply: key = K_KP_MULTIPLY; break;
208 case XK_KP_Add: key = K_KP_PLUS; break;
209 case XK_KP_Subtract: key = K_KP_MINUS; break;
210 case XK_KP_Divide: key = K_KP_SLASH; break;
212 case XK_section: key = '~'; break;
218 if (keysym >= 'A' && keysym <= 'Z')
219 key = keysym - 'A' + 'a';
229 static Cursor CreateNullCursor(Display *display, Window root)
237 cursormask = XCreatePixmap(display, root, 1, 1, 1);
238 xgc.function = GXclear;
239 gc = XCreateGC(display, cursormask, GCFunction, &xgc);
240 XFillRectangle(display, cursormask, gc, 0, 0, 1, 1);
241 dummycolour.pixel = 0;
243 dummycolour.flags = 04;
244 cursor = XCreatePixmapCursor(display, cursormask, cursormask, &dummycolour,&dummycolour, 0,0);
245 XFreePixmap(display,cursormask);
250 void VID_GrabMouse(qboolean grab)
252 qboolean usedgamouse;
255 usedgamouse = grab && vid.mouseaim && vid_dgamouse.integer;
256 #if !defined(__APPLE__) && !defined(SUNOS)
257 if (!vid_x11_dgasupported)
262 #if !defined(__APPLE__) && !defined(SUNOS)
263 if(vid_usingmouse && (vid_usingdgamouse != usedgamouse))
264 VID_GrabMouse(false); // ungrab first!
266 if (!vid_usingmouse && mouse_avail && win)
268 XWindowAttributes attribs_1;
269 XSetWindowAttributes attribs_2;
271 XGetWindowAttributes(vidx11_display, win, &attribs_1);
272 attribs_2.event_mask = attribs_1.your_event_mask | KEY_MASK | MOUSE_MASK;
273 XChangeWindowAttributes(vidx11_display, win, CWEventMask, &attribs_2);
276 XDefineCursor(vidx11_display, win, CreateNullCursor(vidx11_display, win));
278 XGrabPointer(vidx11_display, win, True, 0, GrabModeAsync, GrabModeAsync, win, None, CurrentTime);
280 #if !defined(__APPLE__) && !defined(SUNOS)
281 vid_usingdgamouse = usedgamouse;
284 XF86DGADirectVideo(vidx11_display, DefaultScreen(vidx11_display), XF86DGADirectMouse);
285 XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, 0, 0);
289 XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, vid.width / 2, vid.height / 2);
291 if (vid_grabkeyboard.integer || vid_isfullscreen)
292 XGrabKeyboard(vidx11_display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
294 cl_ignoremousemoves = 2;
295 vid_usingmouse = true;
302 #if !defined(__APPLE__) && !defined(SUNOS)
303 if (vid_usingdgamouse)
304 XF86DGADirectVideo(vidx11_display, DefaultScreen(vidx11_display), 0);
305 vid_usingdgamouse = false;
308 XUngrabPointer(vidx11_display, CurrentTime);
309 XUngrabKeyboard(vidx11_display, CurrentTime);
313 XUndefineCursor(vidx11_display, win);
315 cl_ignoremousemoves = 2;
316 vid_usingmouse = false;
321 static keynum_t buttonremap[18] =
343 static void HandleEvents(void)
348 qboolean dowarp = false;
353 while (XPending(vidx11_display))
355 XNextEvent(vidx11_display, &event);
361 key = XLateKey (&event.xkey, &ascii);
362 Key_Event(key, ascii, true);
367 key = XLateKey (&event.xkey, &ascii);
368 Key_Event(key, ascii, false);
375 #if !defined(__APPLE__) && !defined(SUNOS)
376 if (vid_usingdgamouse)
378 in_mouse_x += event.xmotion.x_root;
379 in_mouse_y += event.xmotion.y_root;
384 if (!event.xmotion.send_event)
386 in_mouse_x += event.xmotion.x - in_windowmouse_x;
387 in_mouse_y += event.xmotion.y - in_windowmouse_y;
388 if (abs(vid.width/2 - event.xmotion.x) + abs(vid.height/2 - event.xmotion.y))
389 //if (abs(vid.width/2 - event.xmotion.x) > vid.width / 4 || abs(vid.height/2 - event.xmotion.y) > vid.height / 4)
394 in_windowmouse_x = event.xmotion.x;
395 in_windowmouse_y = event.xmotion.y;
399 // mouse button pressed
400 if (event.xbutton.button <= 18)
401 Key_Event(buttonremap[event.xbutton.button - 1], 0, true);
403 Con_Printf("HandleEvents: ButtonPress gave value %d, 1-18 expected\n", event.xbutton.button);
407 // mouse button released
408 if (event.xbutton.button <= 18)
409 Key_Event(buttonremap[event.xbutton.button - 1], 0, false);
411 Con_Printf("HandleEvents: ButtonRelease gave value %d, 1-18 expected\n", event.xbutton.button);
416 win_x = event.xcreatewindow.x;
417 win_y = event.xcreatewindow.y;
420 case ConfigureNotify:
421 // window changed size/location
422 win_x = event.xconfigure.x;
423 win_y = event.xconfigure.y;
424 if(vid_resizable.integer < 2)
426 vid.width = event.xconfigure.width;
427 vid.height = event.xconfigure.height;
431 // window has been destroyed
435 // window manager messages
436 if ((event.xclient.format == 32) && ((unsigned int)event.xclient.data.l[0] == wm_delete_window_atom))
444 VID_RestoreSystemGamma();
449 // window iconified/rolledup/whatever
451 VID_RestoreSystemGamma();
456 // window is now the input focus
457 vid_activewindow = true;
462 // window is no longer the input focus
463 vid_activewindow = false;
464 VID_RestoreSystemGamma();
467 // mouse entered window
477 /* move the mouse to the window center again */
478 in_windowmouse_x = (int)(vid.width / 2);
479 in_windowmouse_y = (int)(vid.height / 2);
480 XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, (int)in_windowmouse_x, (int)in_windowmouse_y);
484 static void *prjobj = NULL;
486 static void GL_CloseLibrary(void)
492 qglXGetProcAddressARB = NULL;
495 gl_platformextensions = "";
498 static int GL_OpenLibrary(const char *name)
500 Con_Printf("Loading OpenGL driver %s\n", name);
502 if (!(prjobj = dlopen(name, RTLD_LAZY | RTLD_GLOBAL)))
504 Con_Printf("Unable to open symbol list for %s\n", name);
507 strlcpy(gl_driver, name, sizeof(gl_driver));
511 void *GL_GetProcAddress(const char *name)
514 if (qglXGetProcAddressARB != NULL)
515 p = (void *) qglXGetProcAddressARB((GLubyte *)name);
517 p = (void *) dlsym(prjobj, name);
521 void VID_Shutdown(void)
523 if (!ctx || !vidx11_display)
526 VID_GrabMouse(false);
527 VID_RestoreSystemGamma();
529 // FIXME: glXDestroyContext here?
530 if (vid_isfullscreen)
531 XF86VidModeSwitchToMode(vidx11_display, vidx11_screen, &init_vidmode);
533 XDestroyWindow(vidx11_display, win);
534 XCloseDisplay(vidx11_display);
537 vid_isfullscreen = false;
538 vidx11_display = NULL;
546 void signal_handler(int sig)
548 Con_Printf("Received signal %d, exiting...\n", sig);
549 VID_RestoreSystemGamma();
555 signal(SIGHUP, signal_handler);
556 signal(SIGINT, signal_handler);
557 signal(SIGQUIT, signal_handler);
558 signal(SIGILL, signal_handler);
559 signal(SIGTRAP, signal_handler);
560 signal(SIGIOT, signal_handler);
561 signal(SIGBUS, signal_handler);
562 signal(SIGFPE, signal_handler);
563 signal(SIGSEGV, signal_handler);
564 signal(SIGTERM, signal_handler);
567 void VID_Finish (void)
569 vid_usevsync = vid_vsync.integer && !cls.timedemo && gl_videosyncavailable;
570 if (vid_usingvsync != vid_usevsync && gl_videosyncavailable)
572 vid_usingvsync = vid_usevsync;
573 if (qglXSwapIntervalSGI (vid_usevsync))
574 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");
577 if (r_render.integer)
580 if (r_speeds.integer || gl_finish.integer)
582 qglFinish();CHECKGLERROR
584 qglXSwapBuffers(vidx11_display, win);CHECKGLERROR
587 if (vid_x11_hardwaregammasupported)
588 VID_UpdateGamma(false, vid_x11_gammarampsize);
591 int VID_SetGamma(unsigned short *ramps, int rampsize)
593 return XF86VidModeSetGammaRamp(vidx11_display, vidx11_screen, rampsize, ramps, ramps + rampsize, ramps + rampsize*2);
596 int VID_GetGamma(unsigned short *ramps, int rampsize)
598 return XF86VidModeGetGammaRamp(vidx11_display, vidx11_screen, rampsize, ramps, ramps + rampsize, ramps + rampsize*2);
603 #if !defined(__APPLE__) && !defined(SUNOS)
604 Cvar_RegisterVariable (&vid_dgamouse);
606 InitSig(); // trap evil signals
607 // COMMANDLINEOPTION: Input: -nomouse disables mouse support (see also vid_mouse cvar)
608 if (COM_CheckParm ("-nomouse"))
612 void VID_BuildGLXAttrib(int *attrib, qboolean stencil, qboolean stereobuffer, int samples)
614 *attrib++ = GLX_RGBA;
615 *attrib++ = GLX_RED_SIZE;*attrib++ = stencil ? 8 : 5;
616 *attrib++ = GLX_GREEN_SIZE;*attrib++ = stencil ? 8 : 5;
617 *attrib++ = GLX_BLUE_SIZE;*attrib++ = stencil ? 8 : 5;
618 *attrib++ = GLX_DOUBLEBUFFER;
619 *attrib++ = GLX_DEPTH_SIZE;*attrib++ = stencil ? 24 : 16;
620 // if stencil is enabled, ask for alpha too
623 *attrib++ = GLX_STENCIL_SIZE;*attrib++ = 8;
624 *attrib++ = GLX_ALPHA_SIZE;*attrib++ = 8;
627 *attrib++ = GLX_STEREO;
630 *attrib++ = GLX_SAMPLE_BUFFERS_ARB;
632 *attrib++ = GLX_SAMPLES_ARB;
638 int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate, int stereobuffer, int samples)
642 XSetWindowAttributes attr;
643 XClassHint *clshints;
648 XVisualInfo *visinfo;
649 int MajorVersion, MinorVersion;
650 const char *drivername;
652 #if defined(__APPLE__) && defined(__MACH__)
653 drivername = "/usr/X11R6/lib/libGL.1.dylib";
655 drivername = "libGL.so.1";
657 // 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
658 // 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
659 // LordHavoc: although this works on MacOSX, it's useless there (as there is only one system libGL)
660 i = COM_CheckParm("-gl_driver");
661 if (i && i < com_argc - 1)
662 drivername = com_argv[i + 1];
663 if (!GL_OpenLibrary(drivername))
665 Con_Printf("Unable to load GL driver \"%s\"\n", drivername);
669 if (!(vidx11_display = XOpenDisplay(NULL)))
671 Con_Print("Couldn't open the X display\n");
675 vidx11_screen = DefaultScreen(vidx11_display);
676 root = RootWindow(vidx11_display, vidx11_screen);
678 // Get video mode list
679 MajorVersion = MinorVersion = 0;
680 if (!XF86VidModeQueryVersion(vidx11_display, &MajorVersion, &MinorVersion))
684 Con_DPrintf("Using XFree86-VidModeExtension Version %d.%d\n", MajorVersion, MinorVersion);
688 if ((qglXChooseVisual = (XVisualInfo *(GLAPIENTRY *)(Display *dpy, int screen, int *attribList))GL_GetProcAddress("glXChooseVisual")) == NULL
689 || (qglXCreateContext = (GLXContext (GLAPIENTRY *)(Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct))GL_GetProcAddress("glXCreateContext")) == NULL
690 || (qglXDestroyContext = (void (GLAPIENTRY *)(Display *dpy, GLXContext ctx))GL_GetProcAddress("glXDestroyContext")) == NULL
691 || (qglXMakeCurrent = (Bool (GLAPIENTRY *)(Display *dpy, GLXDrawable drawable, GLXContext ctx))GL_GetProcAddress("glXMakeCurrent")) == NULL
692 || (qglXSwapBuffers = (void (GLAPIENTRY *)(Display *dpy, GLXDrawable drawable))GL_GetProcAddress("glXSwapBuffers")) == NULL
693 || (qglXQueryExtensionsString = (const char *(GLAPIENTRY *)(Display *dpy, int screen))GL_GetProcAddress("glXQueryExtensionsString")) == NULL)
695 Con_Printf("glX functions not found in %s\n", gl_driver);
699 VID_BuildGLXAttrib(attrib, bpp == 32, stereobuffer, samples);
700 visinfo = qglXChooseVisual(vidx11_display, vidx11_screen, attrib);
701 if (!visinfo && (samples == 1))
703 /* Some Mesa drivers reject sample buffers with 1 sample, so try
704 * entirely without one */
705 VID_BuildGLXAttrib(attrib, bpp == 32, stereobuffer, 0);
706 visinfo = qglXChooseVisual(vidx11_display, vidx11_screen, attrib);
710 Con_Print("Couldn't get an RGB, Double-buffered, Depth visual\n");
716 int best_fit, best_dist, dist, x, y;
718 // Are we going fullscreen? If so, let's change video mode
721 XF86VidModeModeLine *current_vidmode;
722 XF86VidModeModeInfo **vidmodes;
725 // This nice hack comes from the SDL source code
726 current_vidmode = (XF86VidModeModeLine*)((char*)&init_vidmode + sizeof(init_vidmode.dotclock));
727 XF86VidModeGetModeLine(vidx11_display, vidx11_screen, (int*)&init_vidmode.dotclock, current_vidmode);
729 XF86VidModeGetAllModeLines(vidx11_display, vidx11_screen, &num_vidmodes, &vidmodes);
733 for (i = 0; i < num_vidmodes; i++)
735 if (width > vidmodes[i]->hdisplay || height > vidmodes[i]->vdisplay)
738 x = width - vidmodes[i]->hdisplay;
739 y = height - vidmodes[i]->vdisplay;
740 dist = (x * x) + (y * y);
741 if (dist < best_dist)
750 // LordHavoc: changed from ActualWidth/ActualHeight =,
751 // to width/height =, so the window will take the full area of
753 width = vidmodes[best_fit]->hdisplay;
754 height = vidmodes[best_fit]->vdisplay;
756 // change to the mode
757 XF86VidModeSwitchToMode(vidx11_display, vidx11_screen, vidmodes[best_fit]);
758 vid_isfullscreen = true;
760 // Move the viewport to top left
761 XF86VidModeSetViewPort(vidx11_display, vidx11_screen, 0, 0);
770 // LordHavoc: save the visual for use in gamma ramp settings later
771 vidx11_visual = visinfo->visual;
773 /* window attributes */
774 attr.background_pixel = 0;
775 attr.border_pixel = 0;
776 // LordHavoc: save the colormap for later, too
777 vidx11_colormap = attr.colormap = XCreateColormap(vidx11_display, root, visinfo->visual, AllocNone);
778 attr.event_mask = X_MASK;
779 if (vid_isfullscreen)
781 mask = CWBackPixel | CWColormap | CWSaveUnder | CWBackingStore | CWEventMask | CWOverrideRedirect;
782 attr.override_redirect = True;
783 attr.backing_store = NotUseful;
784 attr.save_under = False;
787 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
789 win = XCreateWindow(vidx11_display, root, 0, 0, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr);
791 wmhints = XAllocWMHints();
792 if(XpmCreatePixmapFromData(vidx11_display, win,
793 (gamemode == GAME_NEXUIZ) ? nexuiz_xpm : darkplaces_xpm,
794 &wmhints->icon_pixmap, &wmhints->icon_mask, NULL) == XpmSuccess)
795 wmhints->flags |= IconPixmapHint | IconMaskHint;
797 clshints = XAllocClassHint();
798 clshints->res_name = strdup(gamename);
799 clshints->res_class = strdup("DarkPlaces");
801 szhints = XAllocSizeHints();
802 if(vid_resizable.integer == 0)
804 szhints->min_width = szhints->max_width = width;
805 szhints->min_height = szhints->max_height = height;
806 szhints->flags |= PMinSize | PMaxSize;
809 XmbSetWMProperties(vidx11_display, win, gamename, gamename, (char **) com_argv, com_argc, szhints, wmhints, clshints);
813 //XStoreName(vidx11_display, win, gamename);
814 XMapWindow(vidx11_display, win);
816 // LordHavoc: making the close button on a window do the right thing
817 // seems to involve this mess, sigh...
818 wm_delete_window_atom = XInternAtom(vidx11_display, "WM_DELETE_WINDOW", false);
819 XSetWMProtocols(vidx11_display, win, &wm_delete_window_atom, 1);
821 if (vid_isfullscreen)
823 XMoveWindow(vidx11_display, win, 0, 0);
824 XRaiseWindow(vidx11_display, win);
825 XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, 0, 0);
826 XFlush(vidx11_display);
827 // Move the viewport to top left
828 XF86VidModeSetViewPort(vidx11_display, vidx11_screen, 0, 0);
831 //XSync(vidx11_display, False);
833 ctx = qglXCreateContext(vidx11_display, visinfo, NULL, True);
836 Con_Printf ("glXCreateContext failed\n");
840 if (!qglXMakeCurrent(vidx11_display, win, ctx))
842 Con_Printf ("glXMakeCurrent failed\n");
846 XSync(vidx11_display, False);
848 if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL)
850 Con_Printf ("glGetString not found in %s\n", gl_driver);
854 gl_extensions = (const char *)qglGetString(GL_EXTENSIONS);
856 gl_platformextensions = qglXQueryExtensionsString(vidx11_display, vidx11_screen);
858 gl_videosyncavailable = false;
860 // COMMANDLINEOPTION: Linux GLX: -nogetprocaddress disables GLX_ARB_get_proc_address (not required, more formal method of getting extension functions)
861 // COMMANDLINEOPTION: BSD GLX: -nogetprocaddress disables GLX_ARB_get_proc_address (not required, more formal method of getting extension functions)
862 // COMMANDLINEOPTION: MacOSX GLX: -nogetprocaddress disables GLX_ARB_get_proc_address (not required, more formal method of getting extension functions)
863 GL_CheckExtension("GLX_ARB_get_proc_address", getprocaddressfuncs, "-nogetprocaddress", false);
864 // COMMANDLINEOPTION: Linux GLX: -novideosync disables GLX_SGI_swap_control
865 // COMMANDLINEOPTION: BSD GLX: -novideosync disables GLX_SGI_swap_control
866 // COMMANDLINEOPTION: MacOSX GLX: -novideosync disables GLX_SGI_swap_control
867 gl_videosyncavailable = GL_CheckExtension("GLX_SGI_swap_control", swapcontrolfuncs, "-novideosync", false);
869 vid_usingmouse = false;
870 vid_usingvsync = false;
872 vid_activewindow = true;
873 vid_x11_hardwaregammasupported = XF86VidModeGetGammaRampSize(vidx11_display, vidx11_screen, &vid_x11_gammarampsize) != 0;
874 #if !defined(__APPLE__) && !defined(SUNOS)
875 vid_x11_dgasupported = XF86DGAQueryVersion(vidx11_display, &MajorVersion, &MinorVersion);
876 if (!vid_x11_dgasupported)
877 Con_Print( "Failed to detect XF86DGA Mouse extension\n" );
883 void Sys_SendKeyEvents(void)
885 static qboolean sound_active = true;
887 // enable/disable sound on focus gain/loss
888 if (!vid_hidden && (vid_activewindow || !snd_mutewhenidle.integer))
901 sound_active = false;