]> icculus.org git repositories - divverent/darkplaces.git/blob - vid_glx.c
optimized AngleVectors calls (pass NULL for vectors that should not be generated)
[divverent/darkplaces.git] / vid_glx.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
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.
8
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.  
12
13 See the GNU General Public License for more details.
14
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.
18 */
19
20 #include <termios.h>
21 #include <sys/ioctl.h>
22 #include <sys/stat.h>
23 #include <sys/vt.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <signal.h>
27
28 #include <dlfcn.h>
29
30 #include "quakedef.h"
31
32 #include <GL/glx.h>
33
34 #include <X11/keysym.h>
35 #include <X11/cursorfont.h>
36
37 #include <X11/extensions/XShm.h>
38 #include <X11/extensions/xf86dga.h>
39 #include <X11/extensions/xf86vmode.h>
40
41 static Display *dpy = NULL;
42 static int scrnum;
43 static Window win;
44 static GLXContext ctx = NULL;
45
46 #define KEY_MASK (KeyPressMask | KeyReleaseMask)
47 #define MOUSE_MASK (ButtonPressMask | ButtonReleaseMask | \
48                     PointerMotionMask | ButtonMotionMask )
49 #define X_MASK (KEY_MASK | MOUSE_MASK | VisibilityChangeMask | StructureNotifyMask )
50
51
52 cvar_t vid_mode = {"vid_mode", "0", false};
53 cvar_t vid_fullscreen = {"vid_fullscreen", "1"};
54
55 viddef_t        vid;                            // global video state
56
57 static qboolean         mouse_avail = true;
58 static qboolean         mouse_active = false;
59 // static qboolean              dga_active;
60 static float    mouse_x, mouse_y;
61 static float    old_mouse_x, old_mouse_y;
62 static int p_mouse_x, p_mouse_y;
63
64 static cvar_t in_mouse = {"in_mouse", "1", false};
65 static cvar_t in_dga = {"in_dga", "1", false};
66 static cvar_t in_dga_mouseaccel = {"in_dga_mouseaccel", "1", false};
67 static cvar_t m_filter = {"m_filter", "0"};
68 static cvar_t _windowed_mouse = {"_windowed_mouse", "1"};
69
70 qboolean vidmode_ext = false;
71
72 static int win_x, win_y;
73
74 static int scr_width, scr_height;
75
76 static XF86VidModeModeInfo **vidmodes;
77 //static int default_dotclock_vidmode;
78 static int num_vidmodes;
79 static qboolean vidmode_active = false;
80
81 /*-----------------------------------------------------------------------*/
82
83 float           gldepthmin, gldepthmax;
84
85 const char *gl_vendor;
86 const char *gl_renderer;
87 const char *gl_version;
88 const char *gl_extensions;
89
90 //static float vid_gamma = 1.0;
91
92 // LordHavoc: ARB multitexture support
93 int gl_mtex_enum = 0;
94
95 /*-----------------------------------------------------------------------*/
96 static int
97 XLateKey(XKeyEvent *ev/*, qboolean modified*/)
98 {
99 //      char tmp[2];
100         int key = 0;
101         KeySym keysym;
102
103         keysym = XLookupKeysym(ev, 0);
104
105         switch(keysym) {
106                 case XK_KP_Page_Up:     key = KP_PGUP; break;
107                 case XK_Page_Up:        key = K_PGUP; break;
108
109                 case XK_KP_Page_Down:   key = KP_PGDN; break;
110                 case XK_Page_Down:      key = K_PGDN; break;
111
112                 case XK_KP_Home:        key = KP_HOME; break;
113                 case XK_Home:           key = K_HOME; break;
114
115                 case XK_KP_End:         key = KP_END; break;
116                 case XK_End:            key = K_END; break;
117
118                 case XK_KP_Left:        key = KP_LEFTARROW; break;
119                 case XK_Left:           key = K_LEFTARROW; break;
120
121                 case XK_KP_Right:       key = KP_RIGHTARROW; break;
122                 case XK_Right:          key = K_RIGHTARROW; break;
123
124                 case XK_KP_Down:        key = KP_DOWNARROW; break;
125                 case XK_Down:           key = K_DOWNARROW; break;
126
127                 case XK_KP_Up:          key = KP_UPARROW; break;
128                 case XK_Up:                     key = K_UPARROW; break;
129
130                 case XK_Escape:         key = K_ESCAPE; break;
131
132                 case XK_KP_Enter:       key = KP_ENTER; break;
133                 case XK_Return:         key = K_ENTER; break;
134
135                 case XK_Tab:            key = K_TAB; break;
136
137                 case XK_F1:                     key = K_F1; break;
138                 case XK_F2:                     key = K_F2; break;
139                 case XK_F3:                     key = K_F3; break;
140                 case XK_F4:                     key = K_F4; break;
141                 case XK_F5:                     key = K_F5; break;
142                 case XK_F6:                     key = K_F6; break;
143                 case XK_F7:                     key = K_F7; break;
144                 case XK_F8:                     key = K_F8; break;
145                 case XK_F9:                     key = K_F9; break;
146                 case XK_F10:            key = K_F10; break;
147                 case XK_F11:            key = K_F11; break;
148                 case XK_F12:            key = K_F12; break;
149
150                 case XK_BackSpace:      key = K_BACKSPACE; break;
151
152                 case XK_KP_Delete:      key = KP_DEL; break;
153                 case XK_Delete:         key = K_DEL; break;
154
155                 case XK_Pause:          key = K_PAUSE; break;
156
157                 case XK_Shift_L:
158                 case XK_Shift_R:        key = K_SHIFT; break;
159
160                 case XK_Execute:
161                 case XK_Control_L:
162                 case XK_Control_R:      key = K_CTRL; break;
163
164                 case XK_Mode_switch:
165                 case XK_Alt_L:
166                 case XK_Meta_L:
167                 case XK_Alt_R:
168                 case XK_Meta_R:         key = K_ALT; break;
169
170                 case XK_Caps_Lock:      key = K_CAPSLOCK; break;
171                 case XK_KP_Begin:       key = KP_5; break;
172
173                 case XK_Insert:         key = K_INS; break;
174                 case XK_KP_Insert:      key = KP_INS; break;
175
176                 case XK_KP_Multiply:    key = KP_MULTIPLY; break;
177                 case XK_KP_Add:         key = KP_PLUS; break;
178                 case XK_KP_Subtract:    key = KP_MINUS; break;
179                 case XK_KP_Divide:      key = KP_DIVIDE; break;
180
181                 /* For Sun keyboards */
182                 case XK_F27:            key = K_HOME; break;
183                 case XK_F29:            key = K_PGUP; break;
184                 case XK_F33:            key = K_END; break;
185                 case XK_F35:            key = K_PGDN; break;
186
187                 default:
188                         if (keysym < 128) {
189                                 /* ASCII keys */
190                                 key = keysym;
191                                 if (/*!modified && */((key >= 'A') && (key <= 'Z'))) {
192                                         key = key + ('a' - 'A');
193                                 }
194                         }
195                         break;
196         }
197
198         return key;
199 }
200
201 static Cursor CreateNullCursor(Display *display, Window root)
202 {
203     Pixmap cursormask; 
204     XGCValues xgc;
205     GC gc;
206     XColor dummycolour;
207     Cursor cursor;
208
209     cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/);
210     xgc.function = GXclear;
211     gc =  XCreateGC(display, cursormask, GCFunction, &xgc);
212     XFillRectangle(display, cursormask, gc, 0, 0, 1, 1);
213     dummycolour.pixel = 0;
214     dummycolour.red = 0;
215     dummycolour.flags = 04;
216     cursor = XCreatePixmapCursor(display, cursormask, cursormask,
217           &dummycolour,&dummycolour, 0,0);
218     XFreePixmap(display,cursormask);
219     XFreeGC(display,gc);
220     return cursor;
221 }
222
223 static void install_grabs(void)
224 {
225         XWindowAttributes attribs_1;
226         XSetWindowAttributes attribs_2;
227
228         XGetWindowAttributes(dpy, win, &attribs_1);
229         attribs_2.event_mask = attribs_1.your_event_mask | KEY_MASK | MOUSE_MASK;
230         XChangeWindowAttributes(dpy, win, CWEventMask, &attribs_2);
231
232 // inviso cursor
233         XDefineCursor(dpy, win, CreateNullCursor(dpy, win));
234
235         XGrabPointer(dpy, win,  True, 0, GrabModeAsync, GrabModeAsync,
236                      win, None, CurrentTime);
237
238         if (in_dga.value) {
239                 int MajorVersion, MinorVersion;
240
241                 if (!XF86DGAQueryVersion(dpy, &MajorVersion, &MinorVersion)) { 
242                         // unable to query, probalby not supported
243                         Con_Printf( "Failed to detect XF86DGA Mouse\n" );
244                         in_dga.value = 0;
245                 } else {
246                         in_dga.value = 1;
247                         XF86DGADirectVideo(dpy, DefaultScreen(dpy), XF86DGADirectMouse);
248                         XWarpPointer(dpy, None, win, 0, 0, 0, 0, 0, 0);
249                 }
250         } else {
251                 XWarpPointer(dpy, None, win,
252                                          0, 0, 0, 0,
253                                          vid.width / 2, vid.height / 2);
254         }
255
256         XGrabKeyboard(dpy, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
257
258         mouse_active = true;
259         mouse_x = mouse_y = 0;
260
261 //      XSync(dpy, True);
262 }
263
264 static void uninstall_grabs(void)
265 {
266         if (!dpy || !win)
267                 return;
268
269         if (in_dga.value == 1) {
270                 XF86DGADirectVideo(dpy, DefaultScreen(dpy), 0);
271         }
272
273         XUngrabPointer(dpy, CurrentTime);
274         XUngrabKeyboard(dpy, CurrentTime);
275
276 // inviso cursor
277         XUndefineCursor(dpy, win);
278
279         mouse_active = false;
280 }
281
282 static void HandleEvents(void)
283 {
284         XEvent event;
285 //      KeySym ks;
286         int b;
287         qboolean dowarp = false;
288
289         if (!dpy)
290                 return;
291
292         while (XPending(dpy)) {
293                 XNextEvent(dpy, &event);
294
295                 switch (event.type) {
296                 case KeyPress:
297                 case KeyRelease:
298                         Key_Event(XLateKey(&event.xkey), event.type == KeyPress);
299                         break;
300
301                 case MotionNotify:
302                         if (in_dga.value == 1) {
303                                 mouse_x += event.xmotion.x_root * in_dga_mouseaccel.value;
304                                 mouse_y += event.xmotion.y_root * in_dga_mouseaccel.value;
305                         } else {
306                                 if (!p_mouse_x && !p_mouse_y) {
307                                         Con_Printf("event->xmotion.x: %d\n", event.xmotion.x);
308                                         Con_Printf("event->xmotion.y: %d\n", event.xmotion.y);
309                                 }
310                                 if (vid_fullscreen.value || _windowed_mouse.value) {
311                                         if (!event.xmotion.send_event) {
312                                                 mouse_x += (event.xmotion.x - p_mouse_x);
313                                                 mouse_y += (event.xmotion.y - p_mouse_y);
314                                                 if (abs(vid.width/2 - event.xmotion.x) > vid.width / 4
315                                                 || abs(vid.height/2 - event.xmotion.y) > vid.height / 4) {
316                                                         dowarp = true;
317                                                 }
318                                         }
319                                 } else {
320                                         mouse_x += (event.xmotion.x - p_mouse_x);
321                                         mouse_y += (event.xmotion.y - p_mouse_y);
322                                 }
323                                 p_mouse_x = event.xmotion.x;
324                                 p_mouse_y = event.xmotion.y;
325                         }
326                         break;
327
328                 case ButtonPress:
329                         b=-1;
330                         if (event.xbutton.button == 1)
331                                 b = 0;
332                         else if (event.xbutton.button == 2)
333                                 b = 2;
334                         else if (event.xbutton.button == 3)
335                                 b = 1;
336                         if (b>=0)
337                                 Key_Event(K_MOUSE1 + b, true);
338                         break;
339
340                 case ButtonRelease:
341                         b=-1;
342                         if (event.xbutton.button == 1)
343                                 b = 0;
344                         else if (event.xbutton.button == 2)
345                                 b = 2;
346                         else if (event.xbutton.button == 3)
347                                 b = 1;
348                         if (b>=0)
349                                 Key_Event(K_MOUSE1 + b, false);
350                         break;
351
352                 case CreateNotify :
353                         win_x = event.xcreatewindow.x;
354                         win_y = event.xcreatewindow.y;
355                         break;
356
357                 case ConfigureNotify :
358                         win_x = event.xconfigure.x;
359                         win_y = event.xconfigure.y;
360                         break;
361                 }
362         }
363
364         if (dowarp) {
365                 /* move the mouse to the window center again */
366                 p_mouse_x = vid.width / 2;
367                 p_mouse_y = vid.height / 2;
368                 XWarpPointer(dpy, None, win, 0, 0, 0, 0, p_mouse_x, p_mouse_y);
369         }
370
371 }
372
373 static void IN_DeactivateMouse( void ) 
374 {
375         if (!mouse_avail || !dpy || !win)
376                 return;
377
378         if (mouse_active) {
379                 uninstall_grabs();
380                 mouse_active = false;
381         }
382 }
383
384 static void IN_ActivateMouse( void ) 
385 {
386         if (!mouse_avail || !dpy || !win)
387                 return;
388
389         if (!mouse_active) {
390                 mouse_x = mouse_y = 0; // don't spazz
391                 install_grabs();
392                 mouse_active = true;
393         }
394 }
395
396
397 void VID_Shutdown(void)
398 {
399         if (!ctx || !dpy)
400                 return;
401
402         if (dpy) {
403                 uninstall_grabs();
404
405                 if (vidmode_active)
406                         XF86VidModeSwitchToMode(dpy, scrnum, vidmodes[0]);
407 /* Disabled, causes a segfault during shutdown.
408                 if (ctx)
409                         glXDestroyContext(dpy, ctx);
410 */
411                 if (win)
412                         XDestroyWindow(dpy, win);
413                 XCloseDisplay(dpy);
414         }
415         vidmode_active = false;
416         dpy = NULL;
417         win = 0;
418         ctx = NULL;
419 }
420
421 void signal_handler(int sig)
422 {
423         printf("Received signal %d, exiting...\n", sig);
424         Sys_Quit();
425         exit(0);
426 }
427
428 void InitSig(void)
429 {
430         signal(SIGHUP, signal_handler);
431         signal(SIGINT, signal_handler);
432         signal(SIGQUIT, signal_handler);
433         signal(SIGILL, signal_handler);
434         signal(SIGTRAP, signal_handler);
435         signal(SIGIOT, signal_handler);
436         signal(SIGBUS, signal_handler);
437         signal(SIGFPE, signal_handler);
438         signal(SIGSEGV, signal_handler);
439         signal(SIGTERM, signal_handler);
440 }
441
442 void VID_CheckMultitexture(void) 
443 {
444         void *prjobj;
445         qglMTexCoord2f = NULL;
446         qglSelectTexture = NULL;
447         // Check to see if multitexture is disabled
448         if (COM_CheckParm("-nomtex"))
449         {
450                 Con_Printf("...multitexture disabled\n");
451                 return;
452         }
453         if ((prjobj = dlopen(NULL, RTLD_LAZY)) == NULL)
454         {
455                 Con_Printf("Unable to open symbol list for main program.\n");
456                 return;
457         }
458         // Test for ARB_multitexture
459         if (!COM_CheckParm("-SGISmtex") && strstr(gl_extensions, "GL_ARB_multitexture "))
460         {
461                 Con_Printf("...using GL_ARB_multitexture\n");
462                 qglMTexCoord2f = (void *) dlsym(prjobj, "glMultiTexCoord2fARB");
463                 qglSelectTexture = (void *) dlsym(prjobj, "glActiveTextureARB");
464                 gl_mtexable = true;
465                 gl_mtex_enum = GL_TEXTURE0_ARB;
466         }
467         else if (strstr(gl_extensions, "GL_SGIS_multitexture ")) // Test for SGIS_multitexture (if ARB_multitexture not found)
468         {
469                 Con_Printf("...using GL_SGIS_multitexture\n");
470                 qglMTexCoord2f = (void *) dlsym(prjobj, "glMTexCoord2fSGIS");
471                 qglSelectTexture = (void *) dlsym(prjobj, "glSelectTextureSGIS");
472                 gl_mtexable = true;
473                 gl_mtex_enum = TEXTURE0_SGIS;
474         }
475         else
476                 Con_Printf("...multitexture disabled (not detected)\n");
477         dlclose(prjobj);
478 }
479
480 void VID_CheckCVA(void)
481 {
482         void *prjobj;
483         qglLockArraysEXT = NULL;
484         qglUnlockArraysEXT = NULL;
485         gl_supportslockarrays = false;
486         if (COM_CheckParm("-nocva"))
487         {
488                 Con_Printf("...compiled vertex arrays disabled\n");
489                 return;
490         }
491         if ((prjobj = dlopen(NULL, RTLD_LAZY)) == NULL)
492         {
493                 Con_Printf("Unable to open symbol list for main program.\n");
494                 return;
495         }
496         if (strstr(gl_extensions, "GL_EXT_compiled_vertex_array"))
497         {
498                 Con_Printf("...using compiled vertex arrays\n");
499                 qglLockArraysEXT = (void *) dlsym(prjobj, "glLockArraysEXT");
500                 qglUnlockArraysEXT = (void *) dlsym(prjobj, "glUnlockArraysEXT");
501                 gl_supportslockarrays = true;
502         }
503         dlclose(prjobj);
504 }
505
506 /*
507 =================
508 GL_BeginRendering
509
510 =================
511 */
512 void GL_BeginRendering (int *x, int *y, int *width, int *height)
513 {
514         *x = *y = 0;
515         *width = scr_width;
516         *height = scr_height;
517
518 //      glViewport (*x, *y, *width, *height);
519 }
520
521
522 void GL_EndRendering (void)
523 {
524         if (!r_render.value)
525                 return;
526         glFlush();
527         glXSwapBuffers(dpy, win);
528 }
529
530 void VID_Init()
531 {
532         int i;
533         int attrib[] = {
534                 GLX_RGBA,
535                 GLX_RED_SIZE, 1,
536                 GLX_GREEN_SIZE, 1,
537                 GLX_BLUE_SIZE, 1,
538                 GLX_DOUBLEBUFFER,
539                 GLX_DEPTH_SIZE, 1,
540                 None
541         };
542 //      char    gldir[MAX_OSPATH];
543         int width = 640, height = 480;
544         XSetWindowAttributes attr;
545         unsigned long mask;
546         Window root;
547         XVisualInfo *visinfo;
548         qboolean fullscreen = true;
549         int MajorVersion, MinorVersion;
550         int actualWidth, actualHeight;
551
552         Cvar_RegisterVariable (&vid_mode);
553         Cvar_RegisterVariable (&vid_fullscreen);
554         Cvar_RegisterVariable (&in_mouse);
555         Cvar_RegisterVariable (&in_dga);
556         Cvar_RegisterVariable (&in_dga_mouseaccel);
557         Cvar_RegisterVariable (&m_filter);
558         
559 // interpret command-line params
560
561 // set vid parameters
562         if ((i = COM_CheckParm("-window")) != 0)
563                 fullscreen = false;
564
565         if ((i = COM_CheckParm("-width")) != 0)
566                 width = atoi(com_argv[i+1]);
567
568         if ((i = COM_CheckParm("-height")) != 0)
569                 height = atoi(com_argv[i+1]);
570
571         if ((i = COM_CheckParm("-conwidth")) != 0)
572                 vid.conwidth = atoi(com_argv[i+1]);
573         else
574                 vid.conwidth = 640;
575
576         vid.conwidth &= 0xfff8; // make it a multiple of eight
577
578         if (vid.conwidth < 320)
579                 vid.conwidth = 320;
580
581         // pick a conheight that matches with correct aspect
582         vid.conheight = vid.conwidth*3 / 4;
583
584         if ((i = COM_CheckParm("-conheight")) != 0)
585                 vid.conheight = atoi(com_argv[i+1]);
586         if (vid.conheight < 200)
587                 vid.conheight = 200;
588
589         if (!(dpy = XOpenDisplay(NULL))) {
590                 fprintf(stderr, "Error couldn't open the X display\n");
591                 exit(1);
592         }
593
594         scrnum = DefaultScreen(dpy);
595         root = RootWindow(dpy, scrnum);
596
597         // Get video mode list
598         MajorVersion = MinorVersion = 0;
599         if (!XF86VidModeQueryVersion(dpy, &MajorVersion, &MinorVersion)) { 
600                 vidmode_ext = false;
601         } else {
602                 Con_Printf("Using XFree86-VidModeExtension Version %d.%d\n", MajorVersion, MinorVersion);
603                 vidmode_ext = true;
604         }
605
606         visinfo = glXChooseVisual(dpy, scrnum, attrib);
607         if (!visinfo) {
608                 fprintf(stderr, "qkHack: Error couldn't get an RGB, Double-buffered, Depth visual\n");
609                 exit(1);
610         }
611
612         if (vidmode_ext) {
613                 int best_fit, best_dist, dist, x, y;
614                 
615                 XF86VidModeGetAllModeLines(dpy, scrnum, &num_vidmodes, &vidmodes);
616
617                 // Are we going fullscreen?  If so, let's change video mode
618                 if (fullscreen) {
619                         best_dist = 9999999;
620                         best_fit = -1;
621
622                         for (i = 0; i < num_vidmodes; i++) {
623                                 if (width > vidmodes[i]->hdisplay ||
624                                         height > vidmodes[i]->vdisplay)
625                                         continue;
626
627                                 x = width - vidmodes[i]->hdisplay;
628                                 y = height - vidmodes[i]->vdisplay;
629                                 dist = (x * x) + (y * y);
630                                 if (dist < best_dist) {
631                                         best_dist = dist;
632                                         best_fit = i;
633                                 }
634                         }
635
636                         if (best_fit != -1) {
637                                 actualWidth = vidmodes[best_fit]->hdisplay;
638                                 actualHeight = vidmodes[best_fit]->vdisplay;
639
640                                 // change to the mode
641                                 XF86VidModeSwitchToMode(dpy, scrnum, vidmodes[best_fit]);
642                                 vidmode_active = true;
643
644                                 // Move the viewport to top left
645                                 XF86VidModeSetViewPort(dpy, scrnum, 0, 0);
646                         } else
647                                 fullscreen = 0;
648                 }
649         }
650
651         /* window attributes */
652         attr.background_pixel = 0;
653         attr.border_pixel = 0;
654         attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
655         attr.event_mask = X_MASK;
656         if (vidmode_active) {
657                 mask = CWBackPixel | CWColormap | CWSaveUnder | CWBackingStore | 
658                         CWEventMask | CWOverrideRedirect;
659                 attr.override_redirect = True;
660                 attr.backing_store = NotUseful;
661                 attr.save_under = False;
662         } else
663                 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
664
665         win = XCreateWindow(dpy, root, 0, 0, width, height,
666                                                 0, visinfo->depth, InputOutput,
667                                                 visinfo->visual, mask, &attr);
668         XMapWindow(dpy, win);
669
670         if (vidmode_active) {
671                 XMoveWindow(dpy, win, 0, 0);
672                 XRaiseWindow(dpy, win);
673                 XWarpPointer(dpy, None, win, 0, 0, 0, 0, 0, 0);
674                 XFlush(dpy);
675                 // Move the viewport to top left
676                 XF86VidModeSetViewPort(dpy, scrnum, 0, 0);
677         }
678
679         XFlush(dpy);
680
681         ctx = glXCreateContext(dpy, visinfo, NULL, True);
682
683         glXMakeCurrent(dpy, win, ctx);
684
685         scr_width = width;
686         scr_height = height;
687
688         if (vid.conheight > height)
689                 vid.conheight = height;
690         if (vid.conwidth > width)
691                 vid.conwidth = width;
692         vid.width = vid.conwidth;
693         vid.height = vid.conheight;
694
695         vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
696
697         InitSig(); // trap evil signals
698
699         GL_Init();
700
701         Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height);
702
703         vid.recalc_refdef = 1;                          // force a surface cache flush
704
705         install_grabs();
706 }
707
708 void Sys_SendKeyEvents(void)
709 {
710         HandleEvents();
711 }
712
713 void Force_CenterView_f (void)
714 {
715         cl.viewangles[PITCH] = 0;
716 }
717
718 void IN_Init(void)
719 {
720 }
721
722 void IN_Shutdown(void)
723 {
724 }
725
726 /*
727 ===========
728 IN_Commands
729 ===========
730 */
731 void IN_Commands (void)
732 {
733         if (!dpy || !win)
734                 return;
735
736         if (vidmode_active || key_dest == key_game)
737                 IN_ActivateMouse();
738         else
739                 IN_DeactivateMouse ();
740 }
741
742 /*
743 ===========
744 IN_Move
745 ===========
746 */
747 void IN_MouseMove (usercmd_t *cmd)
748 {
749         if (!mouse_avail)
750                 return;
751
752         if (!mouse_avail)
753                 return;
754
755         if (m_filter.value) {
756                 mouse_x = (mouse_x + old_mouse_x) * 0.5;
757                 mouse_y = (mouse_y + old_mouse_y) * 0.5;
758
759                 old_mouse_x = mouse_x;
760                 old_mouse_y = mouse_y;
761         }
762
763         mouse_x *= sensitivity.value;
764         mouse_y *= sensitivity.value;
765         
766         if (in_strafe.state & 1)
767                 cmd->sidemove += m_side.value * mouse_x;
768         else
769                 cl.viewangles[YAW] -= m_yaw.value * mouse_x;
770                 
771 /*        if (freelook)*/
772                 V_StopPitchDrift ();
773
774         if (/*freelook && */!(in_strafe.state & 1)) {
775                 cl.viewangles[PITCH] += m_pitch.value * mouse_y;
776                 cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
777         } else {
778                 if ((in_strafe.state & 1) && noclip_anglehack)
779                         cmd->upmove -= m_forward.value * mouse_y;
780                 else
781                         cmd->forwardmove -= m_forward.value * mouse_y;
782         }
783         mouse_x = mouse_y = 0.0;
784 }
785
786 void IN_Move (usercmd_t *cmd)
787 {
788         IN_MouseMove(cmd);
789 }
790
791