gl_vidlinuxglx.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include <termios.h>
  16. #include <sys/ioctl.h>
  17. #include <sys/stat.h>
  18. #include <sys/vt.h>
  19. #include <stdarg.h>
  20. #include <stdio.h>
  21. #include <signal.h>
  22. #include "quakedef.h"
  23. #include <GL/glx.h>
  24. #include <X11/keysym.h>
  25. #include <X11/cursorfont.h>
  26. #ifdef USE_DGA
  27. #include <X11/extensions/xf86dga.h>
  28. #endif
  29. #define WARP_WIDTH 320
  30. #define WARP_HEIGHT 200
  31. static Display *dpy = NULL;
  32. static Window win;
  33. static GLXContext ctx = NULL;
  34. static float old_windowed_mouse = 0;
  35. #define KEY_MASK (KeyPressMask | KeyReleaseMask)
  36. #define MOUSE_MASK (ButtonPressMask | ButtonReleaseMask | \
  37. PointerMotionMask)
  38. #define X_MASK (KEY_MASK | MOUSE_MASK | VisibilityChangeMask)
  39. unsigned short d_8to16table[256];
  40. unsigned d_8to24table[256];
  41. unsigned char d_15to8table[65536];
  42. cvar_t _windowed_mouse = {"_windowed_mouse","0", true};
  43. cvar_t vid_mode = {"vid_mode","0",false};
  44. static float mouse_x, mouse_y;
  45. static float old_mouse_x, old_mouse_y;
  46. cvar_t m_filter = {"m_filter", "0"};
  47. static int scr_width, scr_height;
  48. /*-----------------------------------------------------------------------*/
  49. //int texture_mode = GL_NEAREST;
  50. //int texture_mode = GL_NEAREST_MIPMAP_NEAREST;
  51. //int texture_mode = GL_NEAREST_MIPMAP_LINEAR;
  52. int texture_mode = GL_LINEAR;
  53. //int texture_mode = GL_LINEAR_MIPMAP_NEAREST;
  54. //int texture_mode = GL_LINEAR_MIPMAP_LINEAR;
  55. int texture_extension_number = 1;
  56. float gldepthmin, gldepthmax;
  57. cvar_t gl_ztrick = {"gl_ztrick","1"};
  58. const char *gl_vendor;
  59. const char *gl_renderer;
  60. const char *gl_version;
  61. const char *gl_extensions;
  62. qboolean is8bit = false;
  63. qboolean isPermedia = false;
  64. qboolean gl_mtexable = false;
  65. /*-----------------------------------------------------------------------*/
  66. void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
  67. {
  68. }
  69. void D_EndDirectRect (int x, int y, int width, int height)
  70. {
  71. }
  72. static int XLateKey(XKeyEvent *ev)
  73. {
  74. int key;
  75. char buf[64];
  76. KeySym keysym;
  77. key = 0;
  78. XLookupString(ev, buf, sizeof buf, &keysym, 0);
  79. switch(keysym)
  80. {
  81. case XK_KP_Page_Up:
  82. case XK_Page_Up: key = K_PGUP; break;
  83. case XK_KP_Page_Down:
  84. case XK_Page_Down: key = K_PGDN; break;
  85. case XK_KP_Home:
  86. case XK_Home: key = K_HOME; break;
  87. case XK_KP_End:
  88. case XK_End: key = K_END; break;
  89. case XK_KP_Left:
  90. case XK_Left: key = K_LEFTARROW; break;
  91. case XK_KP_Right:
  92. case XK_Right: key = K_RIGHTARROW; break;
  93. case XK_KP_Down:
  94. case XK_Down: key = K_DOWNARROW; break;
  95. case XK_KP_Up:
  96. case XK_Up: key = K_UPARROW; break;
  97. case XK_Escape: key = K_ESCAPE; break;
  98. case XK_KP_Enter:
  99. case XK_Return: key = K_ENTER; break;
  100. case XK_Tab: key = K_TAB; break;
  101. case XK_F1: key = K_F1; break;
  102. case XK_F2: key = K_F2; break;
  103. case XK_F3: key = K_F3; break;
  104. case XK_F4: key = K_F4; break;
  105. case XK_F5: key = K_F5; break;
  106. case XK_F6: key = K_F6; break;
  107. case XK_F7: key = K_F7; break;
  108. case XK_F8: key = K_F8; break;
  109. case XK_F9: key = K_F9; break;
  110. case XK_F10: key = K_F10; break;
  111. case XK_F11: key = K_F11; break;
  112. case XK_F12: key = K_F12; break;
  113. case XK_BackSpace: key = K_BACKSPACE; break;
  114. case XK_KP_Delete:
  115. case XK_Delete: key = K_DEL; break;
  116. case XK_Pause: key = K_PAUSE; break;
  117. case XK_Shift_L:
  118. case XK_Shift_R: key = K_SHIFT; break;
  119. case XK_Execute:
  120. case XK_Control_L:
  121. case XK_Control_R: key = K_CTRL; break;
  122. case XK_Alt_L:
  123. case XK_Meta_L:
  124. case XK_Alt_R:
  125. case XK_Meta_R: key = K_ALT; break;
  126. case XK_KP_Begin: key = '5'; break;
  127. case XK_KP_Insert:
  128. case XK_Insert:key = K_INS; break;
  129. case XK_KP_Multiply: key = '*'; break;
  130. case XK_KP_Add: key = '+'; break;
  131. case XK_KP_Subtract: key = '-'; break;
  132. case XK_KP_Divide: key = '/'; break;
  133. #if 0
  134. case 0x021: key = '1';break;/* [!] */
  135. case 0x040: key = '2';break;/* [@] */
  136. case 0x023: key = '3';break;/* [#] */
  137. case 0x024: key = '4';break;/* [$] */
  138. case 0x025: key = '5';break;/* [%] */
  139. case 0x05e: key = '6';break;/* [^] */
  140. case 0x026: key = '7';break;/* [&] */
  141. case 0x02a: key = '8';break;/* [*] */
  142. case 0x028: key = '9';;break;/* [(] */
  143. case 0x029: key = '0';break;/* [)] */
  144. case 0x05f: key = '-';break;/* [_] */
  145. case 0x02b: key = '=';break;/* [+] */
  146. case 0x07c: key = '\'';break;/* [|] */
  147. case 0x07d: key = '[';break;/* [}] */
  148. case 0x07b: key = ']';break;/* [{] */
  149. case 0x022: key = '\'';break;/* ["] */
  150. case 0x03a: key = ';';break;/* [:] */
  151. case 0x03f: key = '/';break;/* [?] */
  152. case 0x03e: key = '.';break;/* [>] */
  153. case 0x03c: key = ',';break;/* [<] */
  154. #endif
  155. default:
  156. key = *(unsigned char*)buf;
  157. if (key >= 'A' && key <= 'Z')
  158. key = key - 'A' + 'a';
  159. break;
  160. }
  161. return key;
  162. }
  163. static void install_grabs(void)
  164. {
  165. XGrabPointer(dpy, win,
  166. True,
  167. 0,
  168. GrabModeAsync, GrabModeAsync,
  169. win,
  170. None,
  171. CurrentTime);
  172. #ifdef USE_DGA
  173. XF86DGADirectVideo(dpy, DefaultScreen(dpy), XF86DGADirectMouse);
  174. dgamouse = 1;
  175. #else
  176. XWarpPointer(dpy, None, win,
  177. 0, 0, 0, 0,
  178. vid.width / 2, vid.height / 2);
  179. #endif
  180. XGrabKeyboard(dpy, win,
  181. False,
  182. GrabModeAsync, GrabModeAsync,
  183. CurrentTime);
  184. // XSync(dpy, True);
  185. }
  186. static void uninstall_grabs(void)
  187. {
  188. #ifdef USE_DGA
  189. XF86DGADirectVideo(dpy, DefaultScreen(dpy), 0);
  190. dgamouse = 0;
  191. #endif
  192. XUngrabPointer(dpy, CurrentTime);
  193. XUngrabKeyboard(dpy, CurrentTime);
  194. // XSync(dpy, True);
  195. }
  196. static void GetEvent(void)
  197. {
  198. XEvent event;
  199. int b;
  200. if (!dpy)
  201. return;
  202. XNextEvent(dpy, &event);
  203. switch (event.type) {
  204. case KeyPress:
  205. case KeyRelease:
  206. Key_Event(XLateKey(&event.xkey), event.type == KeyPress);
  207. break;
  208. case MotionNotify:
  209. #ifdef USE_DGA
  210. if (dgamouse && _windowed_mouse.value) {
  211. mouse_x = event.xmotion.x_root;
  212. mouse_y = event.xmotion.y_root;
  213. } else
  214. #endif
  215. {
  216. if (_windowed_mouse.value) {
  217. mouse_x = (float) ((int)event.xmotion.x - (int)(vid.width/2));
  218. mouse_y = (float) ((int)event.xmotion.y - (int)(vid.height/2));
  219. /* move the mouse to the window center again */
  220. XSelectInput(dpy, win, X_MASK & ~PointerMotionMask);
  221. XWarpPointer(dpy, None, win, 0, 0, 0, 0,
  222. (vid.width/2), (vid.height/2));
  223. XSelectInput(dpy, win, X_MASK);
  224. }
  225. }
  226. break;
  227. case ButtonPress:
  228. b=-1;
  229. if (event.xbutton.button == 1)
  230. b = 0;
  231. else if (event.xbutton.button == 2)
  232. b = 2;
  233. else if (event.xbutton.button == 3)
  234. b = 1;
  235. if (b>=0)
  236. Key_Event(K_MOUSE1 + b, true);
  237. break;
  238. case ButtonRelease:
  239. b=-1;
  240. if (event.xbutton.button == 1)
  241. b = 0;
  242. else if (event.xbutton.button == 2)
  243. b = 2;
  244. else if (event.xbutton.button == 3)
  245. b = 1;
  246. if (b>=0)
  247. Key_Event(K_MOUSE1 + b, false);
  248. break;
  249. }
  250. if (old_windowed_mouse != _windowed_mouse.value) {
  251. old_windowed_mouse = _windowed_mouse.value;
  252. if (!_windowed_mouse.value) {
  253. /* ungrab the pointer */
  254. uninstall_grabs();
  255. } else {
  256. /* grab the pointer */
  257. install_grabs();
  258. }
  259. }
  260. }
  261. void VID_Shutdown(void)
  262. {
  263. if (!ctx)
  264. return;
  265. glXDestroyContext(dpy, ctx);
  266. }
  267. void signal_handler(int sig)
  268. {
  269. printf("Received signal %d, exiting...\n", sig);
  270. Sys_Quit();
  271. exit(0);
  272. }
  273. void InitSig(void)
  274. {
  275. signal(SIGHUP, signal_handler);
  276. signal(SIGINT, signal_handler);
  277. signal(SIGQUIT, signal_handler);
  278. signal(SIGILL, signal_handler);
  279. signal(SIGTRAP, signal_handler);
  280. signal(SIGIOT, signal_handler);
  281. signal(SIGBUS, signal_handler);
  282. signal(SIGFPE, signal_handler);
  283. signal(SIGSEGV, signal_handler);
  284. signal(SIGTERM, signal_handler);
  285. }
  286. void VID_ShiftPalette(unsigned char *p)
  287. {
  288. // VID_SetPalette(p);
  289. }
  290. void VID_SetPalette (unsigned char *palette)
  291. {
  292. byte *pal;
  293. unsigned r,g,b;
  294. unsigned v;
  295. int r1,g1,b1;
  296. int k;
  297. unsigned short i;
  298. unsigned *table;
  299. FILE *f;
  300. char s[255];
  301. float dist, bestdist;
  302. static qboolean palflag = false;
  303. //
  304. // 8 8 8 encoding
  305. //
  306. Con_Printf("Converting 8to24\n");
  307. pal = palette;
  308. table = d_8to24table;
  309. for (i=0 ; i<256 ; i++)
  310. {
  311. r = pal[0];
  312. g = pal[1];
  313. b = pal[2];
  314. pal += 3;
  315. // v = (255<<24) + (r<<16) + (g<<8) + (b<<0);
  316. // v = (255<<0) + (r<<8) + (g<<16) + (b<<24);
  317. v = (255<<24) + (r<<0) + (g<<8) + (b<<16);
  318. *table++ = v;
  319. }
  320. d_8to24table[255] &= 0xffffff; // 255 is transparent
  321. // JACK: 3D distance calcs - k is last closest, l is the distance.
  322. // FIXME: Precalculate this and cache to disk.
  323. if (palflag)
  324. return;
  325. palflag = true;
  326. COM_FOpenFile("glquake/15to8.pal", &f);
  327. if (f) {
  328. fread(d_15to8table, 1<<15, 1, f);
  329. fclose(f);
  330. } else {
  331. for (i=0; i < (1<<15); i++) {
  332. /* Maps
  333. 000000000000000
  334. 000000000011111 = Red = 0x1F
  335. 000001111100000 = Blue = 0x03E0
  336. 111110000000000 = Grn = 0x7C00
  337. */
  338. r = ((i & 0x1F) << 3)+4;
  339. g = ((i & 0x03E0) >> 2)+4;
  340. b = ((i & 0x7C00) >> 7)+4;
  341. pal = (unsigned char *)d_8to24table;
  342. for (v=0,k=0,bestdist=10000.0; v<256; v++,pal+=4) {
  343. r1 = (int)r - (int)pal[0];
  344. g1 = (int)g - (int)pal[1];
  345. b1 = (int)b - (int)pal[2];
  346. dist = sqrt(((r1*r1)+(g1*g1)+(b1*b1)));
  347. if (dist < bestdist) {
  348. k=v;
  349. bestdist = dist;
  350. }
  351. }
  352. d_15to8table[i]=k;
  353. }
  354. sprintf(s, "%s/glquake", com_gamedir);
  355. Sys_mkdir (s);
  356. sprintf(s, "%s/glquake/15to8.pal", com_gamedir);
  357. if ((f = fopen(s, "wb")) != NULL) {
  358. fwrite(d_15to8table, 1<<15, 1, f);
  359. fclose(f);
  360. }
  361. }
  362. }
  363. /*
  364. ===============
  365. GL_Init
  366. ===============
  367. */
  368. void GL_Init (void)
  369. {
  370. gl_vendor = glGetString (GL_VENDOR);
  371. Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
  372. gl_renderer = glGetString (GL_RENDERER);
  373. Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
  374. gl_version = glGetString (GL_VERSION);
  375. Con_Printf ("GL_VERSION: %s\n", gl_version);
  376. gl_extensions = glGetString (GL_EXTENSIONS);
  377. Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
  378. // Con_Printf ("%s %s\n", gl_renderer, gl_version);
  379. glClearColor (1,0,0,0);
  380. glCullFace(GL_FRONT);
  381. glEnable(GL_TEXTURE_2D);
  382. glEnable(GL_ALPHA_TEST);
  383. glAlphaFunc(GL_GREATER, 0.666);
  384. glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
  385. glShadeModel (GL_FLAT);
  386. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  387. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  388. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  389. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  390. glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  391. // glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  392. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  393. }
  394. /*
  395. =================
  396. GL_BeginRendering
  397. =================
  398. */
  399. void GL_BeginRendering (int *x, int *y, int *width, int *height)
  400. {
  401. extern cvar_t gl_clear;
  402. *x = *y = 0;
  403. *width = scr_width;
  404. *height = scr_height;
  405. // if (!wglMakeCurrent( maindc, baseRC ))
  406. // Sys_Error ("wglMakeCurrent failed");
  407. // glViewport (*x, *y, *width, *height);
  408. }
  409. void GL_EndRendering (void)
  410. {
  411. glFlush();
  412. glXSwapBuffers(dpy, win);
  413. }
  414. qboolean VID_Is8bit(void)
  415. {
  416. return is8bit;
  417. }
  418. #ifdef GL_EXT_SHARED
  419. void VID_Init8bitPalette()
  420. {
  421. // Check for 8bit Extensions and initialize them.
  422. int i;
  423. char thePalette[256*3];
  424. char *oldPalette, *newPalette;
  425. if (strstr(gl_extensions, "GL_EXT_shared_texture_palette") == NULL)
  426. return;
  427. Con_SafePrintf("8-bit GL extensions enabled.\n");
  428. glEnable( GL_SHARED_TEXTURE_PALETTE_EXT );
  429. oldPalette = (char *) d_8to24table; //d_8to24table3dfx;
  430. newPalette = thePalette;
  431. for (i=0;i<256;i++) {
  432. *newPalette++ = *oldPalette++;
  433. *newPalette++ = *oldPalette++;
  434. *newPalette++ = *oldPalette++;
  435. oldPalette++;
  436. }
  437. glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, (void *) thePalette);
  438. is8bit = true;
  439. }
  440. #else
  441. extern void gl3DfxSetPaletteEXT(GLuint *pal);
  442. void VID_Init8bitPalette(void)
  443. {
  444. // Check for 8bit Extensions and initialize them.
  445. int i;
  446. GLubyte table[256][4];
  447. char *oldpal;
  448. if (strstr(gl_extensions, "3DFX_set_global_palette") == NULL)
  449. return;
  450. Con_SafePrintf("8-bit GL extensions enabled.\n");
  451. glEnable( GL_SHARED_TEXTURE_PALETTE_EXT );
  452. oldpal = (char *) d_8to24table; //d_8to24table3dfx;
  453. for (i=0;i<256;i++) {
  454. table[i][2] = *oldpal++;
  455. table[i][1] = *oldpal++;
  456. table[i][0] = *oldpal++;
  457. table[i][3] = 255;
  458. oldpal++;
  459. }
  460. gl3DfxSetPaletteEXT((GLuint *)table);
  461. is8bit = true;
  462. }
  463. #endif
  464. void VID_Init(unsigned char *palette)
  465. {
  466. int i;
  467. int attrib[] = {
  468. GLX_RGBA,
  469. GLX_RED_SIZE, 1,
  470. GLX_GREEN_SIZE, 1,
  471. GLX_BLUE_SIZE, 1,
  472. GLX_DOUBLEBUFFER,
  473. GLX_DEPTH_SIZE, 1,
  474. None
  475. };
  476. char gldir[MAX_OSPATH];
  477. int width = 640, height = 480;
  478. int scrnum;
  479. XSetWindowAttributes attr;
  480. unsigned long mask;
  481. Window root;
  482. XVisualInfo *visinfo;
  483. S_Init();
  484. Cvar_RegisterVariable (&vid_mode);
  485. Cvar_RegisterVariable (&gl_ztrick);
  486. Cvar_RegisterVariable (&_windowed_mouse);
  487. vid.maxwarpwidth = WARP_WIDTH;
  488. vid.maxwarpheight = WARP_HEIGHT;
  489. vid.colormap = host_colormap;
  490. vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
  491. // interpret command-line params
  492. // set vid parameters
  493. if ((i = COM_CheckParm("-width")) != 0)
  494. width = atoi(com_argv[i+1]);
  495. if ((i = COM_CheckParm("-height")) != 0)
  496. height = atoi(com_argv[i+1]);
  497. if ((i = COM_CheckParm("-conwidth")) != 0)
  498. vid.conwidth = Q_atoi(com_argv[i+1]);
  499. else
  500. vid.conwidth = 640;
  501. vid.conwidth &= 0xfff8; // make it a multiple of eight
  502. if (vid.conwidth < 320)
  503. vid.conwidth = 320;
  504. // pick a conheight that matches with correct aspect
  505. vid.conheight = vid.conwidth*3 / 4;
  506. if ((i = COM_CheckParm("-conheight")) != 0)
  507. vid.conheight = Q_atoi(com_argv[i+1]);
  508. if (vid.conheight < 200)
  509. vid.conheight = 200;
  510. if (!(dpy = XOpenDisplay(NULL))) {
  511. fprintf(stderr, "Error couldn't open the X display\n");
  512. exit(1);
  513. }
  514. scrnum = DefaultScreen(dpy);
  515. root = RootWindow(dpy, scrnum);
  516. visinfo = glXChooseVisual(dpy, scrnum, attrib);
  517. if (!visinfo) {
  518. fprintf(stderr, "qkHack: Error couldn't get an RGB, Double-buffered, Depth visual\n");
  519. exit(1);
  520. }
  521. /* window attributes */
  522. attr.background_pixel = 0;
  523. attr.border_pixel = 0;
  524. attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
  525. attr.event_mask = X_MASK;
  526. mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  527. win = XCreateWindow(dpy, root, 0, 0, width, height,
  528. 0, visinfo->depth, InputOutput,
  529. visinfo->visual, mask, &attr);
  530. XMapWindow(dpy, win);
  531. XMoveWindow(dpy, win, 0, 0);
  532. XFlush(dpy);
  533. ctx = glXCreateContext(dpy, visinfo, NULL, True);
  534. glXMakeCurrent(dpy, win, ctx);
  535. scr_width = width;
  536. scr_height = height;
  537. if (vid.conheight > height)
  538. vid.conheight = height;
  539. if (vid.conwidth > width)
  540. vid.conwidth = width;
  541. vid.width = vid.conwidth;
  542. vid.height = vid.conheight;
  543. vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
  544. vid.numpages = 2;
  545. InitSig(); // trap evil signals
  546. GL_Init();
  547. sprintf (gldir, "%s/glquake", com_gamedir);
  548. Sys_mkdir (gldir);
  549. VID_SetPalette(palette);
  550. // Check for 3DFX Extensions and initialize them.
  551. VID_Init8bitPalette();
  552. Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height);
  553. vid.recalc_refdef = 1; // force a surface cache flush
  554. }
  555. void Sys_SendKeyEvents(void)
  556. {
  557. if (dpy) {
  558. while (XPending(dpy))
  559. GetEvent();
  560. }
  561. }
  562. void Force_CenterView_f (void)
  563. {
  564. cl.viewangles[PITCH] = 0;
  565. }
  566. void IN_Init(void)
  567. {
  568. }
  569. void IN_Shutdown(void)
  570. {
  571. }
  572. /*
  573. ===========
  574. IN_Commands
  575. ===========
  576. */
  577. void IN_Commands (void)
  578. {
  579. }
  580. /*
  581. ===========
  582. IN_Move
  583. ===========
  584. */
  585. void IN_MouseMove (usercmd_t *cmd)
  586. {
  587. if (m_filter.value)
  588. {
  589. mouse_x = (mouse_x + old_mouse_x) * 0.5;
  590. mouse_y = (mouse_y + old_mouse_y) * 0.5;
  591. }
  592. old_mouse_x = mouse_x;
  593. old_mouse_y = mouse_y;
  594. mouse_x *= sensitivity.value;
  595. mouse_y *= sensitivity.value;
  596. // add mouse X/Y movement to cmd
  597. if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) ))
  598. cmd->sidemove += m_side.value * mouse_x;
  599. else
  600. cl.viewangles[YAW] -= m_yaw.value * mouse_x;
  601. if (in_mlook.state & 1)
  602. V_StopPitchDrift ();
  603. if ( (in_mlook.state & 1) && !(in_strafe.state & 1))
  604. {
  605. cl.viewangles[PITCH] += m_pitch.value * mouse_y;
  606. if (cl.viewangles[PITCH] > 80)
  607. cl.viewangles[PITCH] = 80;
  608. if (cl.viewangles[PITCH] < -70)
  609. cl.viewangles[PITCH] = -70;
  610. }
  611. else
  612. {
  613. if ((in_strafe.state & 1) && noclip_anglehack)
  614. cmd->upmove -= m_forward.value * mouse_y;
  615. else
  616. cmd->forwardmove -= m_forward.value * mouse_y;
  617. }
  618. mouse_x = mouse_y = 0.0;
  619. }
  620. void IN_Move (usercmd_t *cmd)
  621. {
  622. IN_MouseMove(cmd);
  623. }
  624. void VID_UnlockBuffer() {}
  625. void VID_LockBuffer() {}