gl_vidlinux_svga.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  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 <asm/io.h>
  23. /*#include "vga.h" */
  24. #include "vgakeyboard.h"
  25. #include "vgamouse.h"
  26. #include "quakedef.h"
  27. #include "GL/fxmesa.h"
  28. #define WARP_WIDTH 320
  29. #define WARP_HEIGHT 200
  30. static fxMesaContext fc = NULL;
  31. #define stringify(m) { #m, m }
  32. unsigned short d_8to16table[256];
  33. unsigned d_8to24table[256];
  34. unsigned char d_15to8table[65536];
  35. int num_shades=32;
  36. struct
  37. {
  38. char *name;
  39. int num;
  40. } mice[] =
  41. {
  42. stringify(MOUSE_MICROSOFT),
  43. stringify(MOUSE_MOUSESYSTEMS),
  44. stringify(MOUSE_MMSERIES),
  45. stringify(MOUSE_LOGITECH),
  46. stringify(MOUSE_BUSMOUSE),
  47. stringify(MOUSE_PS2),
  48. };
  49. static unsigned char scantokey[128];
  50. int num_mice = sizeof (mice) / sizeof(mice[0]);
  51. int d_con_indirect = 0;
  52. int svgalib_inited=0;
  53. int UseMouse = 1;
  54. int UseKeyboard = 1;
  55. int mouserate = MOUSE_DEFAULTSAMPLERATE;
  56. cvar_t vid_mode = {"vid_mode","5",false};
  57. cvar_t vid_redrawfull = {"vid_redrawfull","0",false};
  58. cvar_t vid_waitforrefresh = {"vid_waitforrefresh","0",true};
  59. char *framebuffer_ptr;
  60. cvar_t mouse_button_commands[3] =
  61. {
  62. {"mouse1","+attack"},
  63. {"mouse2","+strafe"},
  64. {"mouse3","+forward"},
  65. };
  66. int mouse_buttons;
  67. int mouse_buttonstate;
  68. int mouse_oldbuttonstate;
  69. float mouse_x, mouse_y;
  70. float old_mouse_x, old_mouse_y;
  71. int mx, my;
  72. cvar_t _windowed_mouse = {"_windowed_mouse", "1", true};
  73. cvar_t m_filter = {"m_filter","0"};
  74. int scr_width, scr_height;
  75. /*-----------------------------------------------------------------------*/
  76. //int texture_mode = GL_NEAREST;
  77. //int texture_mode = GL_NEAREST_MIPMAP_NEAREST;
  78. //int texture_mode = GL_NEAREST_MIPMAP_LINEAR;
  79. int texture_mode = GL_LINEAR;
  80. //int texture_mode = GL_LINEAR_MIPMAP_NEAREST;
  81. //int texture_mode = GL_LINEAR_MIPMAP_LINEAR;
  82. int texture_extension_number = 1;
  83. float gldepthmin, gldepthmax;
  84. cvar_t gl_ztrick = {"gl_ztrick","1"};
  85. const char *gl_vendor;
  86. const char *gl_renderer;
  87. const char *gl_version;
  88. const char *gl_extensions;
  89. qboolean is8bit = false;
  90. qboolean isPermedia = false;
  91. qboolean gl_mtexable = false;
  92. /*-----------------------------------------------------------------------*/
  93. void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
  94. {
  95. }
  96. void D_EndDirectRect (int x, int y, int width, int height)
  97. {
  98. }
  99. /*
  100. =================
  101. VID_Gamma_f
  102. Keybinding command
  103. =================
  104. */
  105. void VID_Gamma_f (void)
  106. {
  107. float gamma, f, inf;
  108. unsigned char palette[768];
  109. int i;
  110. if (Cmd_Argc () == 2)
  111. {
  112. gamma = Q_atof (Cmd_Argv(1));
  113. for (i=0 ; i<768 ; i++)
  114. {
  115. f = pow ( (host_basepal[i]+1)/256.0 , gamma );
  116. inf = f*255 + 0.5;
  117. if (inf < 0)
  118. inf = 0;
  119. if (inf > 255)
  120. inf = 255;
  121. palette[i] = inf;
  122. }
  123. VID_SetPalette (palette);
  124. vid.recalc_refdef = 1; // force a surface cache flush
  125. }
  126. }
  127. int matchmouse(int mouse, char *name)
  128. {
  129. int i;
  130. for (i=0 ; i<num_mice ; i++)
  131. if (!strcmp(mice[i].name, name))
  132. return i;
  133. return mouse;
  134. }
  135. #if 0
  136. void vtswitch(int newconsole)
  137. {
  138. int fd;
  139. struct vt_stat x;
  140. // switch consoles and wait until reactivated
  141. fd = open("/dev/console", O_RDONLY);
  142. ioctl(fd, VT_GETSTATE, &x);
  143. ioctl(fd, VT_ACTIVATE, newconsole);
  144. ioctl(fd, VT_WAITACTIVE, x.v_active);
  145. close(fd);
  146. }
  147. #endif
  148. void keyhandler(int scancode, int state)
  149. {
  150. int sc;
  151. sc = scancode & 0x7f;
  152. // Con_Printf("scancode=%x (%d%s)\n", scancode, sc, scancode&0x80?"+128":"");
  153. Key_Event(scantokey[sc], state == KEY_EVENTPRESS);
  154. }
  155. void VID_Shutdown(void)
  156. {
  157. if (!fc)
  158. return;
  159. fxMesaDestroyContext(fc);
  160. if (UseKeyboard)
  161. keyboard_close();
  162. }
  163. void signal_handler(int sig)
  164. {
  165. printf("Received signal %d, exiting...\n", sig);
  166. VID_Shutdown();
  167. exit(0);
  168. }
  169. void InitSig(void)
  170. {
  171. signal(SIGHUP, signal_handler);
  172. signal(SIGQUIT, signal_handler);
  173. signal(SIGILL, signal_handler);
  174. signal(SIGTRAP, signal_handler);
  175. signal(SIGIOT, signal_handler);
  176. signal(SIGBUS, signal_handler);
  177. signal(SIGFPE, signal_handler);
  178. signal(SIGSEGV, signal_handler);
  179. signal(SIGTERM, signal_handler);
  180. }
  181. void VID_ShiftPalette(unsigned char *p)
  182. {
  183. VID_SetPalette(p);
  184. }
  185. void VID_SetPalette (unsigned char *palette)
  186. {
  187. byte *pal;
  188. unsigned short r,g,b;
  189. int v;
  190. int r1,g1,b1;
  191. int k;
  192. unsigned short i;
  193. unsigned *table;
  194. FILE *f;
  195. char s[255];
  196. float dist, bestdist;
  197. static qboolean palflag = false;
  198. //
  199. // 8 8 8 encoding
  200. //
  201. pal = palette;
  202. table = d_8to24table;
  203. for (i=0 ; i<256 ; i++)
  204. {
  205. r = pal[0];
  206. g = pal[1];
  207. b = pal[2];
  208. pal += 3;
  209. // v = (255<<24) + (r<<16) + (g<<8) + (b<<0);
  210. // v = (255<<0) + (r<<8) + (g<<16) + (b<<24);
  211. v = (255<<24) + (r<<0) + (g<<8) + (b<<16);
  212. *table++ = v;
  213. }
  214. d_8to24table[255] &= 0xffffff; // 255 is transparent
  215. // JACK: 3D distance calcs - k is last closest, l is the distance.
  216. // FIXME: Precalculate this and cache to disk.
  217. if (palflag)
  218. return;
  219. palflag = true;
  220. COM_FOpenFile("glquake/15to8.pal", &f);
  221. if (f) {
  222. fread(d_15to8table, 1<<15, 1, f);
  223. fclose(f);
  224. } else {
  225. for (i=0; i < (1<<15); i++) {
  226. /* Maps
  227. 000000000000000
  228. 000000000011111 = Red = 0x1F
  229. 000001111100000 = Blue = 0x03E0
  230. 111110000000000 = Grn = 0x7C00
  231. */
  232. r = ((i & 0x1F) << 3)+4;
  233. g = ((i & 0x03E0) >> 2)+4;
  234. b = ((i & 0x7C00) >> 7)+4;
  235. pal = (unsigned char *)d_8to24table;
  236. for (v=0,k=0,bestdist=10000.0; v<256; v++,pal+=4) {
  237. r1 = (int)r - (int)pal[0];
  238. g1 = (int)g - (int)pal[1];
  239. b1 = (int)b - (int)pal[2];
  240. dist = sqrt(((r1*r1)+(g1*g1)+(b1*b1)));
  241. if (dist < bestdist) {
  242. k=v;
  243. bestdist = dist;
  244. }
  245. }
  246. d_15to8table[i]=k;
  247. }
  248. sprintf(s, "%s/glquake", com_gamedir);
  249. Sys_mkdir (s);
  250. sprintf(s, "%s/glquake/15to8.pal", com_gamedir);
  251. if ((f = fopen(s, "wb")) != NULL) {
  252. fwrite(d_15to8table, 1<<15, 1, f);
  253. fclose(f);
  254. }
  255. }
  256. }
  257. /*
  258. ===============
  259. GL_Init
  260. ===============
  261. */
  262. void GL_Init (void)
  263. {
  264. gl_vendor = glGetString (GL_VENDOR);
  265. Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
  266. gl_renderer = glGetString (GL_RENDERER);
  267. Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
  268. gl_version = glGetString (GL_VERSION);
  269. Con_Printf ("GL_VERSION: %s\n", gl_version);
  270. gl_extensions = glGetString (GL_EXTENSIONS);
  271. Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
  272. // Con_Printf ("%s %s\n", gl_renderer, gl_version);
  273. glClearColor (1,0,0,0);
  274. glCullFace(GL_FRONT);
  275. glEnable(GL_TEXTURE_2D);
  276. glEnable(GL_ALPHA_TEST);
  277. glAlphaFunc(GL_GREATER, 0.666);
  278. glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
  279. glShadeModel (GL_FLAT);
  280. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  281. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  282. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  283. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  284. glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  285. // glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  286. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  287. }
  288. /*
  289. =================
  290. GL_BeginRendering
  291. =================
  292. */
  293. void GL_BeginRendering (int *x, int *y, int *width, int *height)
  294. {
  295. extern cvar_t gl_clear;
  296. *x = *y = 0;
  297. *width = scr_width;
  298. *height = scr_height;
  299. // if (!wglMakeCurrent( maindc, baseRC ))
  300. // Sys_Error ("wglMakeCurrent failed");
  301. // glViewport (*x, *y, *width, *height);
  302. }
  303. void GL_EndRendering (void)
  304. {
  305. glFlush();
  306. fxMesaSwapBuffers();
  307. }
  308. void Init_KBD(void)
  309. {
  310. int i;
  311. if (COM_CheckParm("-nokbd")) UseKeyboard = 0;
  312. if (UseKeyboard)
  313. {
  314. for (i=0 ; i<128 ; i++)
  315. scantokey[i] = ' ';
  316. scantokey[ 1] = K_ESCAPE;
  317. scantokey[ 2] = '1';
  318. scantokey[ 3] = '2';
  319. scantokey[ 4] = '3';
  320. scantokey[ 5] = '4';
  321. scantokey[ 6] = '5';
  322. scantokey[ 7] = '6';
  323. scantokey[ 8] = '7';
  324. scantokey[ 9] = '8';
  325. scantokey[ 10] = '9';
  326. scantokey[ 11] = '0';
  327. scantokey[ 12] = '-';
  328. scantokey[ 13] = '=';
  329. scantokey[ 14] = K_BACKSPACE;
  330. scantokey[ 15] = K_TAB;
  331. scantokey[ 16] = 'q';
  332. scantokey[ 17] = 'w';
  333. scantokey[ 18] = 'e';
  334. scantokey[ 19] = 'r';
  335. scantokey[ 20] = 't';
  336. scantokey[ 21] = 'y';
  337. scantokey[ 22] = 'u';
  338. scantokey[ 23] = 'i';
  339. scantokey[ 24] = 'o';
  340. scantokey[ 25] = 'p';
  341. scantokey[ 26] = '[';
  342. scantokey[ 27] = ']';
  343. scantokey[ 28] = K_ENTER;
  344. scantokey[ 29] = K_CTRL; //left
  345. scantokey[ 30] = 'a';
  346. scantokey[ 31] = 's';
  347. scantokey[ 32] = 'd';
  348. scantokey[ 33] = 'f';
  349. scantokey[ 34] = 'g';
  350. scantokey[ 35] = 'h';
  351. scantokey[ 36] = 'j';
  352. scantokey[ 37] = 'k';
  353. scantokey[ 38] = 'l';
  354. scantokey[ 39] = ';';
  355. scantokey[ 40] = '\'';
  356. scantokey[ 41] = '`';
  357. scantokey[ 42] = K_SHIFT; //left
  358. scantokey[ 43] = '\\';
  359. scantokey[ 44] = 'z';
  360. scantokey[ 45] = 'x';
  361. scantokey[ 46] = 'c';
  362. scantokey[ 47] = 'v';
  363. scantokey[ 48] = 'b';
  364. scantokey[ 49] = 'n';
  365. scantokey[ 50] = 'm';
  366. scantokey[ 51] = ',';
  367. scantokey[ 52] = '.';
  368. scantokey[ 53] = '/';
  369. scantokey[ 54] = K_SHIFT; //right
  370. scantokey[ 55] = '*'; //keypad
  371. scantokey[ 56] = K_ALT; //left
  372. scantokey[ 57] = ' ';
  373. // 58 caps lock
  374. scantokey[ 59] = K_F1;
  375. scantokey[ 60] = K_F2;
  376. scantokey[ 61] = K_F3;
  377. scantokey[ 62] = K_F4;
  378. scantokey[ 63] = K_F5;
  379. scantokey[ 64] = K_F6;
  380. scantokey[ 65] = K_F7;
  381. scantokey[ 66] = K_F8;
  382. scantokey[ 67] = K_F9;
  383. scantokey[ 68] = K_F10;
  384. // 69 numlock
  385. // 70 scrollock
  386. scantokey[ 71] = K_HOME;
  387. scantokey[ 72] = K_UPARROW;
  388. scantokey[ 73] = K_PGUP;
  389. scantokey[ 74] = '-';
  390. scantokey[ 75] = K_LEFTARROW;
  391. scantokey[ 76] = '5';
  392. scantokey[ 77] = K_RIGHTARROW;
  393. scantokey[ 79] = K_END;
  394. scantokey[ 78] = '+';
  395. scantokey[ 80] = K_DOWNARROW;
  396. scantokey[ 81] = K_PGDN;
  397. scantokey[ 82] = K_INS;
  398. scantokey[ 83] = K_DEL;
  399. // 84 to 86 not used
  400. scantokey[ 87] = K_F11;
  401. scantokey[ 88] = K_F12;
  402. // 89 to 95 not used
  403. scantokey[ 96] = K_ENTER; //keypad enter
  404. scantokey[ 97] = K_CTRL; //right
  405. scantokey[ 98] = '/';
  406. scantokey[ 99] = K_F12; // print screen, bind to screenshot by default
  407. scantokey[100] = K_ALT; // right
  408. scantokey[101] = K_PAUSE; // break
  409. scantokey[102] = K_HOME;
  410. scantokey[103] = K_UPARROW;
  411. scantokey[104] = K_PGUP;
  412. scantokey[105] = K_LEFTARROW;
  413. scantokey[106] = K_RIGHTARROW;
  414. scantokey[107] = K_END;
  415. scantokey[108] = K_DOWNARROW;
  416. scantokey[109] = K_PGDN;
  417. scantokey[110] = K_INS;
  418. scantokey[111] = K_DEL;
  419. scantokey[119] = K_PAUSE;
  420. if (keyboard_init())
  421. Sys_Error("keyboard_init() failed");
  422. keyboard_seteventhandler(keyhandler);
  423. }
  424. }
  425. #define NUM_RESOLUTIONS 3
  426. static resolutions[NUM_RESOLUTIONS][3]={
  427. { 512, 384, GR_RESOLUTION_512x384 },
  428. { 640, 400, GR_RESOLUTION_640x400 },
  429. { 640, 480, GR_RESOLUTION_640x480 }
  430. };
  431. int findres(int *width, int *height)
  432. {
  433. int i;
  434. for(i=0;i<NUM_RESOLUTIONS;i++)
  435. if((*width<=resolutions[i][0]) && (*height<=resolutions[i][1])) {
  436. *width = resolutions[i][0];
  437. *height = resolutions[i][1];
  438. return resolutions[i][2];
  439. }
  440. *width = 640;
  441. *height = 480;
  442. return GR_RESOLUTION_640x480;
  443. }
  444. qboolean VID_Is8bit(void)
  445. {
  446. return is8bit;
  447. }
  448. #ifdef GL_EXT_SHARED
  449. void VID_Init8bitPalette()
  450. {
  451. // Check for 8bit Extensions and initialize them.
  452. int i;
  453. char thePalette[256*3];
  454. char *oldPalette, *newPalette;
  455. if (strstr(gl_extensions, "GL_EXT_shared_texture_palette") == NULL)
  456. return;
  457. Con_SafePrintf("8-bit GL extensions enabled.\n");
  458. glEnable( GL_SHARED_TEXTURE_PALETTE_EXT );
  459. oldPalette = (char *) d_8to24table; //d_8to24table3dfx;
  460. newPalette = thePalette;
  461. for (i=0;i<256;i++) {
  462. *newPalette++ = *oldPalette++;
  463. *newPalette++ = *oldPalette++;
  464. *newPalette++ = *oldPalette++;
  465. oldPalette++;
  466. }
  467. glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, (void *) thePalette);
  468. is8bit = true;
  469. }
  470. #else
  471. extern void gl3DfxSetPaletteEXT(GLuint *pal);
  472. void VID_Init8bitPalette(void)
  473. {
  474. // Check for 8bit Extensions and initialize them.
  475. int i;
  476. GLubyte table[256][4];
  477. char *oldpal;
  478. if (strstr(gl_extensions, "3DFX_set_global_palette") == NULL)
  479. return;
  480. Con_SafePrintf("8-bit GL extensions enabled.\n");
  481. glEnable( GL_SHARED_TEXTURE_PALETTE_EXT );
  482. oldpal = (char *) d_8to24table; //d_8to24table3dfx;
  483. for (i=0;i<256;i++) {
  484. table[i][2] = *oldpal++;
  485. table[i][1] = *oldpal++;
  486. table[i][0] = *oldpal++;
  487. table[i][3] = 255;
  488. oldpal++;
  489. }
  490. gl3DfxSetPaletteEXT((GLuint *)table);
  491. is8bit = true;
  492. }
  493. #endif
  494. void VID_Init(unsigned char *palette)
  495. {
  496. int i;
  497. GLint attribs[32];
  498. char gldir[MAX_OSPATH];
  499. int width = 640, height = 480;
  500. S_Init();
  501. Init_KBD();
  502. Cvar_RegisterVariable (&vid_mode);
  503. Cvar_RegisterVariable (&vid_redrawfull);
  504. Cvar_RegisterVariable (&vid_waitforrefresh);
  505. Cvar_RegisterVariable (&gl_ztrick);
  506. vid.maxwarpwidth = WARP_WIDTH;
  507. vid.maxwarpheight = WARP_HEIGHT;
  508. vid.colormap = host_colormap;
  509. vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
  510. // interpret command-line params
  511. // set vid parameters
  512. attribs[0] = FXMESA_DOUBLEBUFFER;
  513. attribs[1] = FXMESA_ALPHA_SIZE;
  514. attribs[2] = 1;
  515. attribs[3] = FXMESA_DEPTH_SIZE;
  516. attribs[4] = 1;
  517. attribs[5] = FXMESA_NONE;
  518. if ((i = COM_CheckParm("-width")) != 0)
  519. width = atoi(com_argv[i+1]);
  520. if ((i = COM_CheckParm("-height")) != 0)
  521. height = atoi(com_argv[i+1]);
  522. if ((i = COM_CheckParm("-conwidth")) != 0)
  523. vid.conwidth = Q_atoi(com_argv[i+1]);
  524. else
  525. vid.conwidth = 640;
  526. vid.conwidth &= 0xfff8; // make it a multiple of eight
  527. if (vid.conwidth < 320)
  528. vid.conwidth = 320;
  529. // pick a conheight that matches with correct aspect
  530. vid.conheight = vid.conwidth*3 / 4;
  531. if ((i = COM_CheckParm("-conheight")) != 0)
  532. vid.conheight = Q_atoi(com_argv[i+1]);
  533. if (vid.conheight < 200)
  534. vid.conheight = 200;
  535. fc = fxMesaCreateContext(0, findres(&width, &height), GR_REFRESH_75Hz,
  536. attribs);
  537. if (!fc)
  538. Sys_Error("Unable to create 3DFX context.\n");
  539. scr_width = width;
  540. scr_height = height;
  541. fxMesaMakeCurrent(fc);
  542. if (vid.conheight > height)
  543. vid.conheight = height;
  544. if (vid.conwidth > width)
  545. vid.conwidth = width;
  546. vid.width = vid.conwidth;
  547. vid.height = vid.conheight;
  548. vid.aspect = ((float)vid.height / (float)vid.width) *
  549. (320.0 / 240.0);
  550. vid.numpages = 2;
  551. InitSig(); // trap evil signals
  552. GL_Init();
  553. sprintf (gldir, "%s/glquake", com_gamedir);
  554. Sys_mkdir (gldir);
  555. VID_SetPalette(palette);
  556. // Check for 3DFX Extensions and initialize them.
  557. VID_Init8bitPalette();
  558. Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height);
  559. vid.recalc_refdef = 1; // force a surface cache flush
  560. }
  561. void Sys_SendKeyEvents(void)
  562. {
  563. if (UseKeyboard)
  564. while (keyboard_update());
  565. }
  566. void Force_CenterView_f (void)
  567. {
  568. cl.viewangles[PITCH] = 0;
  569. }
  570. void mousehandler(int buttonstate, int dx, int dy)
  571. {
  572. mouse_buttonstate = buttonstate;
  573. mx += dx;
  574. my += dy;
  575. }
  576. void IN_Init(void)
  577. {
  578. int mtype;
  579. char *mousedev;
  580. int mouserate;
  581. if (UseMouse)
  582. {
  583. Cvar_RegisterVariable (&mouse_button_commands[0]);
  584. Cvar_RegisterVariable (&mouse_button_commands[1]);
  585. Cvar_RegisterVariable (&mouse_button_commands[2]);
  586. Cmd_AddCommand ("force_centerview", Force_CenterView_f);
  587. mouse_buttons = 3;
  588. mtype = vga_getmousetype();
  589. mousedev = "/dev/mouse";
  590. if (getenv("MOUSEDEV")) mousedev = getenv("MOUSEDEV");
  591. if (COM_CheckParm("-mdev"))
  592. mousedev = com_argv[COM_CheckParm("-mdev")+1];
  593. mouserate = 1200;
  594. if (getenv("MOUSERATE")) mouserate = atoi(getenv("MOUSERATE"));
  595. if (COM_CheckParm("-mrate"))
  596. mouserate = atoi(com_argv[COM_CheckParm("-mrate")+1]);
  597. if (mouse_init(mousedev, mtype, mouserate))
  598. {
  599. Con_Printf("No mouse found\n");
  600. UseMouse = 0;
  601. }
  602. else
  603. mouse_seteventhandler(mousehandler);
  604. }
  605. }
  606. void IN_Shutdown(void)
  607. {
  608. if (UseMouse)
  609. mouse_close();
  610. }
  611. /*
  612. ===========
  613. IN_Commands
  614. ===========
  615. */
  616. void IN_Commands (void)
  617. {
  618. if (UseMouse)
  619. {
  620. // poll mouse values
  621. while (mouse_update())
  622. ;
  623. // perform button actions
  624. if ((mouse_buttonstate & MOUSE_LEFTBUTTON) &&
  625. !(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
  626. Key_Event (K_MOUSE1, true);
  627. else if (!(mouse_buttonstate & MOUSE_LEFTBUTTON) &&
  628. (mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
  629. Key_Event (K_MOUSE1, false);
  630. if ((mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
  631. !(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
  632. Key_Event (K_MOUSE2, true);
  633. else if (!(mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
  634. (mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
  635. Key_Event (K_MOUSE2, false);
  636. if ((mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
  637. !(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
  638. Key_Event (K_MOUSE3, true);
  639. else if (!(mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
  640. (mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
  641. Key_Event (K_MOUSE3, false);
  642. mouse_oldbuttonstate = mouse_buttonstate;
  643. }
  644. }
  645. /*
  646. ===========
  647. IN_Move
  648. ===========
  649. */
  650. void IN_MouseMove (usercmd_t *cmd)
  651. {
  652. if (!UseMouse)
  653. return;
  654. // poll mouse values
  655. while (mouse_update())
  656. ;
  657. if (m_filter.value)
  658. {
  659. mouse_x = (mx + old_mouse_x) * 0.5;
  660. mouse_y = (my + old_mouse_y) * 0.5;
  661. }
  662. else
  663. {
  664. mouse_x = mx;
  665. mouse_y = my;
  666. }
  667. old_mouse_x = mx;
  668. old_mouse_y = my;
  669. mx = my = 0; // clear for next update
  670. mouse_x *= sensitivity.value;
  671. mouse_y *= sensitivity.value;
  672. // add mouse X/Y movement to cmd
  673. if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) ))
  674. cmd->sidemove += m_side.value * mouse_x;
  675. else
  676. cl.viewangles[YAW] -= m_yaw.value * mouse_x;
  677. if (in_mlook.state & 1)
  678. V_StopPitchDrift ();
  679. if ( (in_mlook.state & 1) && !(in_strafe.state & 1))
  680. {
  681. cl.viewangles[PITCH] += m_pitch.value * mouse_y;
  682. if (cl.viewangles[PITCH] > 80)
  683. cl.viewangles[PITCH] = 80;
  684. if (cl.viewangles[PITCH] < -70)
  685. cl.viewangles[PITCH] = -70;
  686. }
  687. else
  688. {
  689. if ((in_strafe.state & 1) && noclip_anglehack)
  690. cmd->upmove -= m_forward.value * mouse_y;
  691. else
  692. cmd->forwardmove -= m_forward.value * mouse_y;
  693. }
  694. }
  695. void IN_Move (usercmd_t *cmd)
  696. {
  697. IN_MouseMove(cmd);
  698. }
  699. void VID_LockBuffer (void) {}
  700. void VID_UnlockBuffer (void) {}