]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
-3dfx support for linux!
authormercury <mercury@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 11 Sep 2000 17:56:42 +0000 (17:56 +0000)
committermercury <mercury@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 11 Sep 2000 17:56:42 +0000 (17:56 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@25 d7cf8633-e32d-0410-b094-e92efae38249

glquake.h
keys.h
makefile
vid_3dfxsvga.c [new file with mode: 0644]

index 4852986b3f6753d8bf4b423e0e658fe3af0efc6d..46511e6cffe6d0b281e0fcfdf412c7d159865f95 100644 (file)
--- a/glquake.h
+++ b/glquake.h
@@ -286,7 +286,9 @@ extern void (APIENTRY *glColorTableEXT)(int, int, int, int, int, const void*);
 
 extern void (*qglMTexCoord2f) (GLenum, GLfloat, GLfloat);
 extern void (*qglSelectTexture) (GLenum);
 
 extern void (*qglMTexCoord2f) (GLenum, GLfloat, GLfloat);
 extern void (*qglSelectTexture) (GLenum);
+#ifndef MESA
 extern void (*glColorTableEXT)(int, int, int, int, int, const void*);
 extern void (*glColorTableEXT)(int, int, int, int, int, const void*);
+#endif
 
 #endif
 
 
 #endif
 
diff --git a/keys.h b/keys.h
index 3fbefd080570b229001e0746cac25110fc0a77c2..b8749341cee363f71f7ebed42354010fb248b0da 100644 (file)
--- a/keys.h
+++ b/keys.h
@@ -18,103 +18,130 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 */
 
 
 */
 
-//
 // these are the key numbers that should be passed to Key_Event
 // these are the key numbers that should be passed to Key_Event
-//
-#define        K_TAB                   9
-#define        K_ENTER                 13
-#define        K_ESCAPE                27
-#define        K_SPACE                 32
-
-// normal keys should be passed as lowercased ascii
-
-#define        K_BACKSPACE             127
-#define        K_UPARROW               128
-#define        K_DOWNARROW             129
-#define        K_LEFTARROW             130
-#define        K_RIGHTARROW    131
-
-#define        K_ALT                   132
-#define        K_CTRL                  133
-#define        K_SHIFT                 134
-#define        K_F1                    135
-#define        K_F2                    136
-#define        K_F3                    137
-#define        K_F4                    138
-#define        K_F5                    139
-#define        K_F6                    140
-#define        K_F7                    141
-#define        K_F8                    142
-#define        K_F9                    143
-#define        K_F10                   144
-#define        K_F11                   145
-#define        K_F12                   146
-#define        K_INS                   147
-#define        K_DEL                   148
-#define        K_PGDN                  149
-#define        K_PGUP                  150
-#define        K_HOME                  151
-#define        K_END                   152
-
-#define K_PAUSE                        255
-
-//
-// mouse buttons generate virtual keys
-//
-#define        K_MOUSE1                200
-#define        K_MOUSE2                201
-#define        K_MOUSE3                202
-
-//
-// joystick buttons
-//
-#define        K_JOY1                  203
-#define        K_JOY2                  204
-#define        K_JOY3                  205
-#define        K_JOY4                  206
-
-//
-// aux keys are for multi-buttoned joysticks to generate so they can use
-// the normal binding process
-//
-#define        K_AUX1                  207
-#define        K_AUX2                  208
-#define        K_AUX3                  209
-#define        K_AUX4                  210
-#define        K_AUX5                  211
-#define        K_AUX6                  212
-#define        K_AUX7                  213
-#define        K_AUX8                  214
-#define        K_AUX9                  215
-#define        K_AUX10                 216
-#define        K_AUX11                 217
-#define        K_AUX12                 218
-#define        K_AUX13                 219
-#define        K_AUX14                 220
-#define        K_AUX15                 221
-#define        K_AUX16                 222
-#define        K_AUX17                 223
-#define        K_AUX18                 224
-#define        K_AUX19                 225
-#define        K_AUX20                 226
-#define        K_AUX21                 227
-#define        K_AUX22                 228
-#define        K_AUX23                 229
-#define        K_AUX24                 230
-#define        K_AUX25                 231
-#define        K_AUX26                 232
-#define        K_AUX27                 233
-#define        K_AUX28                 234
-#define        K_AUX29                 235
-#define        K_AUX30                 236
-#define        K_AUX31                 237
-#define        K_AUX32                 238
-
-// JACK: Intellimouse(c) Mouse Wheel Support
-
-#define K_MWHEELUP             239
-#define K_MWHEELDOWN   240
 
 
+typedef enum {
+       K_TAB = 9,
+       K_ENTER = 13,
+       K_ESCAPE = 27,
+       K_SPACE = 32,
+
+       // normal keys should be passed as lowercased ascii
+
+       K_BACKSPACE = 127,
+
+       K_CAPSLOCK,
+       K_PRNTSCR,
+       K_SCRLCK,
+       K_PAUSE,
+
+       K_UPARROW,
+       K_DOWNARROW,
+       K_LEFTARROW,
+       K_RIGHTARROW,
+
+       K_ALT,
+       K_CTRL,
+       K_SHIFT,
+       K_F1,
+       K_F2,
+       K_F3,
+       K_F4,
+       K_F5,
+       K_F6,
+       K_F7,
+       K_F8,
+       K_F9,
+       K_F10,
+       K_F11,
+       K_F12,
+       K_INS,
+       K_DEL,
+       K_PGDN,
+       K_PGUP,
+       K_HOME,
+       K_END,
+
+
+       // Keypad stuff..
+
+       KP_NUMLCK,
+       KP_DIVIDE,
+       KP_MULTIPLY,
+
+       KP_HOME,
+       KP_UPARROW,
+       KP_PGUP,
+       KP_MINUS,
+
+       KP_LEFTARROW,
+       KP_5,
+       KP_RIGHTARROW,
+       KP_PLUS,
+
+       KP_END,
+       KP_DOWNARROW,
+       KP_PGDN,
+
+
+       KP_INS,
+       KP_DEL,
+       KP_ENTER,
+
+       // mouse buttons generate virtual keys
+       K_MOUSE1 = 200,
+       K_MOUSE2,
+       K_MOUSE3,
+
+       // joystick buttons
+       K_JOY1,
+       K_JOY2,
+       K_JOY3,
+       K_JOY4,
+
+       //
+       //// aux keys are for multi-buttoned joysticks to generate so they can use
+       //// the normal binding process
+       ////
+       //
+       K_AUX1,
+       K_AUX2,
+       K_AUX3,
+       K_AUX4,
+       K_AUX5,
+       K_AUX6,
+       K_AUX7,
+       K_AUX8,
+       K_AUX9,
+       K_AUX10,
+       K_AUX11,
+       K_AUX12,
+       K_AUX13,
+       K_AUX14,
+       K_AUX15,
+       K_AUX16,
+       K_AUX17,
+       K_AUX18,
+       K_AUX19,
+       K_AUX20,
+       K_AUX21,
+       K_AUX22,
+       K_AUX23,
+       K_AUX24,
+       K_AUX25,
+       K_AUX26,
+       K_AUX27,
+       K_AUX28,
+       K_AUX29,
+       K_AUX30,
+       K_AUX31,
+       K_AUX32,
+
+       // JACK: Intellimouse(c) Mouse Wheel Support
+
+       K_MWHEELUP,
+       K_MWHEELDOWN
+} keynum_t;
 
 
 typedef enum {key_game, key_console, key_message, key_menu} keydest_t;
 
 
 typedef enum {key_game, key_console, key_message, key_menu} keydest_t;
index 4bf38b5b3f1b0d625fe2552465a81a411ac7e2a4..175b2301b00c6a0163f357e2ab0da07b30f0454c 100644 (file)
--- a/makefile
+++ b/makefile
@@ -1,17 +1,21 @@
-TARGET = darkplacesglx
-
-OBJECTS = cd_linux.o chase.o cl_demo.o cl_input.o cl_main.o cl_parse.o cl_tent.o cmd.o common.o console.o cpu_noasm.o crc.o cvar.o fractalnoise.o gl_draw.o gl_poly.o gl_refrag.o gl_rmain.o gl_rmisc.o gl_rsurf.o gl_screen.o gl_warp.o host.o host_cmd.o image.o keys.o mathlib.o menu.o model_alias.o model_brush.o model_shared.o model_sprite.o net_bsd.o net_udp.o net_dgrm.o net_loop.o net_main.o net_vcr.o pr_cmds.o pr_edict.o pr_exec.o r_light.o r_part.o sbar.o snd_dma.o snd_mem.o snd_mix.o snd_linux.o sv_main.o sv_move.o sv_phys.o sv_user.o sys_linux.o transform.o vid_shared.o vid_glx.o view.o wad.o world.o zone.o
+OBJECTS = cd_linux.o chase.o cl_demo.o cl_input.o cl_main.o cl_parse.o cl_tent.o cmd.o common.o console.o cpu_noasm.o crc.o cvar.o fractalnoise.o gl_draw.o gl_poly.o gl_refrag.o gl_rmain.o gl_rmisc.o gl_rsurf.o gl_screen.o gl_warp.o host.o host_cmd.o image.o keys.o mathlib.o menu.o model_alias.o model_brush.o model_shared.o model_sprite.o net_bsd.o net_udp.o net_dgrm.o net_loop.o net_main.o net_vcr.o pr_cmds.o pr_edict.o pr_exec.o r_light.o r_part.o sbar.o snd_dma.o snd_mem.o snd_mix.o snd_linux.o sv_main.o sv_move.o sv_phys.o sv_user.o sys_linux.o transform.o view.o wad.o world.o zone.o vid_shared.o
 
 OPTIMIZATIONS = -O6 -ffast-math -funroll-loops -fomit-frame-pointer -fexpensive-optimizations
 
 OPTIMIZATIONS = -O6 -ffast-math -funroll-loops -fomit-frame-pointer -fexpensive-optimizations
-CFLAGS = -Wall -Werror -I/usr/X11/include $(OPTIMIZATIONS)
+CFLAGS = -Wall -Werror -I/usr/X11R6/include -I/usr/include/glide $(OPTIMIZATIONS)
 #CFLAGS = -Wall -Werror -I/usr/X11/include -ggdb $(OPTIMIZATIONS)
 #CFLAGS = -Wall -Werror -I/usr/X11/include -ggdb $(OPTIMIZATIONS)
-LIBS = -L/usr/X11/lib -lc -lm -lXext -lXxf86dga -lXxf86vm -lGL
+LIBS = -L/usr/X11R6/lib -lc -lm -lXext -lXxf86dga -lXxf86vm -lGL -ldl
+
+all: darkplaces-glx darkplaces-3dfx
 
 
-#quick:
-#      gcc -o $(TARGET) $(CFLAGS) cd_linux.c chase.c cl_demo.c cl_input.c cl_main.c cl_parse.c cl_tent.c cmd.c common.c console.c cpu_noasm.c crc.c cvar.c fractalnoise.c gl_draw.c gl_poly.c gl_refrag.c gl_rmain.c gl_rmisc.c gl_rsurf.c gl_screen.c gl_warp.c host.c host_cmd.c image.c keys.c mathlib.c menu.c model_alias.c model_brush.c model_shared.c model_sprite.c net_bsd.c net_udp.c net_dgrm.c net_loop.c net_main.c net_vcr.c pr_cmds.c pr_edict.c pr_exec.c r_light.c r_part.c sbar.c snd_dma.c snd_mem.c snd_mix.c snd_linux.c sv_main.c sv_move.c sv_phys.c sv_user.c sys_linux.c transform.c vid_shared.c vid_glx.c view.c wad.c world.c zone.c $(LIBS)
 .c.o:
        gcc $(CFLAGS) -c $*.c
 
 .c.o:
        gcc $(CFLAGS) -c $*.c
 
-$(TARGET) : $(OBJECTS)
-       gcc $(LIBS) -o $(TARGET) $(OBJECTS) $(LIBS)
+darkplaces-glx: $(OBJECTS) vid_glx.o
+       gcc -o $@ $^ $(LIBS)
+
+darkplaces-3dfx: $(OBJECTS) in_svgalib.o vid_3dfxsvga.o
+       gcc -o $@ $^ $(LIBS)
+
 
 
+clean:
+       rm -f darkplaces-glx $(OBJECTS)
diff --git a/vid_3dfxsvga.c b/vid_3dfxsvga.c
new file mode 100644 (file)
index 0000000..813a525
--- /dev/null
@@ -0,0 +1,528 @@
+/*
+       vid_3dfxsvga.c
+
+       OpenGL device driver for 3Dfx chipsets running Linux
+
+       Copyright (C) 1996-1997  Id Software, Inc.
+       Copyright (C) 1999,2000  Nelson Rush.
+       Copyright (C) 1999,2000  contributors of the QuakeForge project
+       Please see the file "AUTHORS" for a list of contributors
+
+       This program is free software; you can redistribute it and/or
+       modify it under the terms of the GNU General Public License
+       as published by the Free Software Foundation; either version 2
+       of the License, or (at your option) any later version.
+
+       This program is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+       See the GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with this program; if not, write to:
+
+               Free Software Foundation, Inc.
+               59 Temple Place - Suite 330
+               Boston, MA  02111-1307, USA
+
+       $Id$
+*/
+
+#include "quakedef.h"
+#include "sys.h"
+#include "console.h"
+#include "sbar.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+
+#include <dlfcn.h>
+
+#include <GL/gl.h>
+#include <GL/fxmesa.h>
+#include <glide/sst1vid.h>
+
+#define WARP_WIDTH              320
+#define WARP_HEIGHT             200
+
+
+//unsigned short       d_8to16table[256];
+unsigned               d_8to24table[256];
+unsigned char  d_15to8table[65536];
+
+cvar_t         vid_mode = {"vid_mode","0",false};
+
+viddef_t       vid;    // global video state
+
+static void    *dlhand = NULL;
+
+static fxMesaContext fc = NULL;
+static int     scr_width, scr_height;
+
+int    VID_options_items = 0;
+
+/*-----------------------------------------------------------------------*/
+
+//int  texture_mode = GL_NEAREST;
+//int  texture_mode = GL_NEAREST_MIPMAP_NEAREST;
+//int  texture_mode = GL_NEAREST_MIPMAP_LINEAR;
+int    texture_mode = GL_LINEAR;
+//int  texture_mode = GL_LINEAR_MIPMAP_NEAREST;
+//int  texture_mode = GL_LINEAR_MIPMAP_LINEAR;
+
+int    texture_extension_number = 1;
+
+float          gldepthmin, gldepthmax;
+
+const char *gl_vendor;
+const char *gl_renderer;
+const char *gl_version;
+const char *gl_extensions;
+
+void (*qglColorTableEXT) (int, int, int, int, int, const void*);
+void (*qgl3DfxSetPaletteEXT) (GLuint *);
+void (*qglMTexCoord2f) (GLenum, GLfloat, GLfloat);
+void (*qglSelectTexture) (GLenum);
+
+int gl_mtex_enum = 0;
+
+// LordHavoc: in GLX these are never set, simply provided to make the rest of the code work
+qboolean is8bit = false;
+qboolean isPermedia = false;
+qboolean isATI = false;
+qboolean isG200 = false;
+qboolean isRagePro = false;
+qboolean gl_mtexable = false;
+qboolean gl_arrays = false;
+
+/*-----------------------------------------------------------------------*/
+void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
+{
+}
+
+void D_EndDirectRect (int x, int y, int width, int height)
+{
+}
+
+void VID_Shutdown(void)
+{
+       if (!fc)
+               return;
+
+       fxMesaDestroyContext(fc);
+}
+
+void signal_handler(int sig)
+{
+       printf("Received signal %d, exiting...\n", sig);
+       Host_Shutdown();
+       abort();
+       //Sys_Quit();
+       exit(0);
+}
+
+void InitSig(void)
+{
+       signal(SIGHUP, signal_handler);
+       signal(SIGINT, signal_handler);
+       signal(SIGQUIT, signal_handler);
+       signal(SIGILL, signal_handler);
+       signal(SIGTRAP, signal_handler);
+//     signal(SIGIOT, signal_handler);
+       signal(SIGBUS, signal_handler);
+//     signal(SIGFPE, signal_handler);
+       signal(SIGSEGV, signal_handler);
+       signal(SIGTERM, signal_handler);
+}
+
+/*
+       CheckMultiTextureExtensions
+
+       Check for ARB, SGIS, or EXT multitexture support
+*/
+void
+CheckMultiTextureExtensions ( void )
+{
+       Con_Printf ("Checking for multitexture... ");
+       if (COM_CheckParm ("-nomtex"))
+       {
+               Con_Printf ("disabled\n");
+               return;
+       }
+       dlhand = dlopen (NULL, RTLD_LAZY);
+       if (dlhand == NULL)
+       {
+               Con_Printf ("unable to check\n");
+               return;
+       }
+       if (strstr(gl_extensions, "GL_ARB_multitexture "))
+       {
+               Con_Printf ("GL_ARB_multitexture\n");
+               qglMTexCoord2f = (void *)dlsym(dlhand, "glMultiTexCoord2fARB");
+               qglSelectTexture = (void *)dlsym(dlhand, "glActiveTextureARB");
+               gl_mtex_enum = GL_TEXTURE0_ARB;
+               gl_mtexable = true;
+       } else if (strstr(gl_extensions, "GL_SGIS_multitexture "))
+       {
+               Con_Printf ("GL_SGIS_multitexture\n");
+               qglMTexCoord2f = (void *)dlsym(dlhand, "glMTexCoord2fSGIS");
+               qglSelectTexture = (void *)dlsym(dlhand, "glSelectTextureSGIS");
+               gl_mtex_enum = TEXTURE0_SGIS;
+               gl_mtexable = true;
+       } else {
+               Con_Printf ("none found\n");
+       }
+       dlclose(dlhand);
+       dlhand = NULL;          
+}
+
+
+typedef void (GLAPIENTRY *gl3DfxSetDitherModeEXT_FUNC) (GrDitherMode_t mode);
+
+/*
+===============
+GL_Init
+===============
+*/
+void GL_Init (void)
+{
+       gl_vendor = glGetString (GL_VENDOR);
+       Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
+       gl_renderer = glGetString (GL_RENDERER);
+       Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
+
+       gl_version = glGetString (GL_VERSION);
+       Con_Printf ("GL_VERSION: %s\n", gl_version);
+       gl_extensions = glGetString (GL_EXTENSIONS);
+       Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
+
+       CheckMultiTextureExtensions ();
+
+       glClearColor (1,0,0,0);
+       glCullFace(GL_FRONT);
+       glEnable(GL_TEXTURE_2D);
+
+       glEnable(GL_ALPHA_TEST);
+       glAlphaFunc(GL_GREATER, 0.666);
+
+       glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
+       glShadeModel (GL_FLAT);
+
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
+       glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+       glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+
+       Con_Printf ("Dithering: ");
+
+       dlhand = dlopen (NULL, RTLD_LAZY);
+
+       if (dlhand == NULL) {
+               Con_SafePrintf ("unable to set.\n");
+               return;
+       }
+
+       if (strstr(gl_extensions, "3DFX_set_dither_mode")) {
+               gl3DfxSetDitherModeEXT_FUNC dither_select = NULL;
+
+               dither_select = (void *) dlsym(dlhand, "gl3DfxSetDitherModeEXT");
+
+               if (COM_CheckParm ("-dither_2x2")) {
+                       dither_select(GR_DITHER_2x2);
+                       Con_Printf ("2x2.\n");
+               } else if (COM_CheckParm ("-dither_4x4")) {
+                       dither_select(GR_DITHER_4x4);
+                       Con_Printf ("4x4.\n");
+               } else {
+                       glDisable(GL_DITHER);
+                       Con_Printf ("disabled.\n");
+               }
+       }
+       dlclose(dlhand);
+       dlhand = NULL;
+}
+
+/*
+=================
+GL_BeginRendering
+
+=================
+*/
+void GL_BeginRendering (int *x, int *y, int *width, int *height)
+{
+       *x = *y = 0;
+       *width = scr_width;
+       *height = scr_height;
+
+//    if (!wglMakeCurrent( maindc, baseRC ))
+//             Sys_Error ("wglMakeCurrent failed");
+
+//     glViewport (*x, *y, *width, *height);
+}
+
+
+void GL_EndRendering (void)
+{
+       glFlush();
+       fxMesaSwapBuffers();
+}
+
+static int resolutions[][3]={
+       { 320,  200,    GR_RESOLUTION_320x200 },
+       { 320,  240,    GR_RESOLUTION_320x240 },
+       { 400,  256,    GR_RESOLUTION_400x256 },
+       { 400,  300,    GR_RESOLUTION_400x300 },
+       { 512,  256,    GR_RESOLUTION_512x256 },
+       { 512,  384,    GR_RESOLUTION_512x384 },
+       { 640,  200,    GR_RESOLUTION_640x200 },
+       { 640,  350,    GR_RESOLUTION_640x350 },
+       { 640,  400,    GR_RESOLUTION_640x400 },
+       { 640,  480,    GR_RESOLUTION_640x480 },
+       { 800,  600,    GR_RESOLUTION_800x600 },
+       { 856,  480,    GR_RESOLUTION_856x480 },
+       { 960,  720,    GR_RESOLUTION_960x720 },
+#ifdef GR_RESOLUTION_1024x768
+       { 1024, 768,    GR_RESOLUTION_1024x768 },
+#endif
+#ifdef GR_RESOLUTION_1152x864
+       { 1152, 864,    GR_RESOLUTION_1152x864 },
+#endif
+#ifdef GR_RESOLUTION_1280x960
+       { 1280, 960,    GR_RESOLUTION_1280x960 },
+#endif
+#ifdef GR_RESOLUTION_1280x1024
+       { 1280, 1024,   GR_RESOLUTION_1280x1024 },
+#endif
+#ifdef GR_RESOLUTION_1600x1024
+       { 1600, 1024,   GR_RESOLUTION_1600x1024 },
+#endif
+#ifdef GR_RESOLUTION_1600x1200
+       { 1600, 1200,   GR_RESOLUTION_1600x1200 },
+#endif
+#ifdef GR_RESOLUTION_1792x1344
+       { 1792, 1344,   GR_RESOLUTION_1792x1344 },
+#endif
+#ifdef GR_RESOLUTION_1856x1392
+       { 1856, 1392,   GR_RESOLUTION_1856x1392 },
+#endif
+#ifdef GR_RESOLUTION_1920x1440
+       { 1920, 1440,   GR_RESOLUTION_1920x1440 },
+#endif
+#ifdef GR_RESOLUTION_2048x1536
+       { 2048, 1536,   GR_RESOLUTION_2048x1536 },
+#endif
+#ifdef GR_RESOLUTION_2048x2048
+       { 2048, 2048,   GR_RESOLUTION_2048x2048 }
+#endif
+};
+
+#define NUM_RESOLUTIONS                (sizeof(resolutions)/(sizeof(int)*3))
+
+
+static int
+findres(int *width, int *height)
+{
+       int i;
+
+       for(i=0; i < NUM_RESOLUTIONS; i++) {
+               if((*width <= resolutions[i][0]) &&
+                  (*height <= resolutions[i][1])) {
+                       *width = resolutions[i][0];
+                       *height = resolutions[i][1];
+                       return resolutions[i][2];
+               }
+       }
+
+       *width = 640;
+       *height = 480;
+       return GR_RESOLUTION_640x480;
+}
+
+qboolean VID_Is8bit(void)
+{
+       return is8bit;
+}
+
+typedef void (GLAPIENTRY *glColorTableEXT_FUNC) (GLenum, GLenum, GLsizei, 
+               GLenum, GLenum, const GLvoid *);
+typedef void (GLAPIENTRY *gl3DfxSetPaletteEXT_FUNC) (GLuint *pal);
+
+void VID_Init8bitPalette()
+{
+       // Check for 8bit Extensions and initialize them.
+       int i;
+
+       dlhand = dlopen (NULL, RTLD_LAZY);
+
+       Con_SafePrintf ("8-bit GL extensions: ");
+
+       if (dlhand == NULL) {
+               Con_SafePrintf ("unable to check.\n");
+               return;
+       }
+
+       if (COM_CheckParm("-no8bit")) {
+               Con_SafePrintf("disabled.\n");
+               return;
+       }
+
+       if (strstr(gl_extensions, "3DFX_set_global_palette") && (qgl3DfxSetPaletteEXT = dlsym(dlhand, "gl3DfxSetPaletteEXT")) != NULL)
+       {
+               GLubyte table[256][4];
+               char *oldpal;
+
+               Con_SafePrintf("3DFX_set_global_palette.\n");
+               glEnable( GL_SHARED_TEXTURE_PALETTE_EXT );
+               oldpal = (char *) d_8to24table; //d_8to24table3dfx;
+               for (i=0;i<256;i++)
+               {
+                       table[i][2] = *oldpal++;
+                       table[i][1] = *oldpal++;
+                       table[i][0] = *oldpal++;
+                       table[i][3] = 255;
+                       oldpal++;
+               }
+               qgl3DfxSetPaletteEXT((GLuint *)table);
+               is8bit = true;
+       } else if (strstr(gl_extensions, "GL_EXT_shared_texture_palette")) {
+               char thePalette[256*3];
+               char *oldPalette, *newPalette;
+               glColorTableEXT_FUNC load_texture = NULL;
+
+               Con_SafePrintf("GL_EXT_shared.\n");
+               load_texture = (void *) dlsym(dlhand, "glColorTableEXT");
+
+               glEnable( GL_SHARED_TEXTURE_PALETTE_EXT );
+               oldPalette = (char *) d_8to24table; //d_8to24table3dfx;
+               newPalette = thePalette;
+               for (i=0;i<256;i++) {
+                       *newPalette++ = *oldPalette++;
+                       *newPalette++ = *oldPalette++;
+                       *newPalette++ = *oldPalette++;
+                       oldPalette++;
+               }
+               load_texture(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, (void *) thePalette);
+               is8bit = true;
+       } else {
+               Con_SafePrintf ("not found.\n");
+       }
+
+       dlclose(dlhand);
+       dlhand = NULL;
+}
+
+extern void Check_Gamma (unsigned char *pal);
+void VID_Setup15to8Palette ();
+
+void VID_Init(unsigned char *palette)
+{
+       int i;
+       GLint attribs[32];
+       char    gldir[MAX_OSPATH];
+       int width = 640, height = 480;
+
+// set vid parameters
+       attribs[0] = FXMESA_DOUBLEBUFFER;
+       attribs[1] = FXMESA_ALPHA_SIZE;
+       attribs[2] = 1;
+       attribs[3] = FXMESA_DEPTH_SIZE;
+       attribs[4] = 1;
+       attribs[5] = FXMESA_NONE;
+
+       if ((i = COM_CheckParm("-width")) != 0)
+               width = atoi(com_argv[i+1]);
+       if ((i = COM_CheckParm("-height")) != 0)
+               height = atoi(com_argv[i+1]);
+
+       if ((i = COM_CheckParm("-conwidth")) != 0)
+               vid.conwidth = atoi(com_argv[i+1]);
+       else
+               vid.conwidth = 640;
+
+       vid.conwidth &= 0xfff8; // make it a multiple of eight
+
+       if (vid.conwidth < 320)
+               vid.conwidth = 320;
+
+       // pick a conheight that matches with correct aspect
+       vid.conheight = vid.conwidth*3 / 4;
+
+       if ((i = COM_CheckParm("-conheight")) != 0)
+               vid.conheight = atoi(com_argv[i+1]);
+       if (vid.conheight < 200)
+               vid.conheight = 200;
+
+       fc = fxMesaCreateContext(0, findres(&width, &height), GR_REFRESH_75Hz,
+               attribs);
+       if (!fc)
+               Sys_Error("Unable to create 3DFX context.\n");
+
+       scr_width = width;
+       scr_height = height;
+
+       fxMesaMakeCurrent(fc);
+
+       if (vid.conheight > height)
+               vid.conheight = height;
+       if (vid.conwidth > width)
+               vid.conwidth = width;
+       vid.width = vid.conwidth;
+       vid.height = vid.conheight;
+
+       vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
+
+       InitSig(); // trap evil signals
+
+       GL_Init();
+
+       snprintf(gldir, sizeof(gldir), "%s/glquake", com_gamedir);
+       Sys_mkdir (gldir);
+
+       VID_SetPalette(palette);
+
+       Check_Gamma(palette);
+
+       // Check for 3DFX Extensions and initialize them.
+       VID_Init8bitPalette();
+
+       if (is8bit) // LordHavoc: avoid calculating 15to8 table if it won't be used
+               VID_Setup15to8Palette ();
+
+       Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height);
+
+       vid.recalc_refdef = 1;                          // force a surface cache flush
+}
+
+void VID_ExtraOptionDraw(unsigned int options_draw_cursor)
+{
+/* Port specific Options menu entrys */
+}
+
+void VID_ExtraOptionCmd(int option_cursor)
+{
+/*
+       switch(option_cursor)
+       {
+       case 12:  // Always start with 12
+       break;
+       }
+*/
+}
+void VID_InitCvars ()
+{
+}
+
+void VID_SetCaption (char *text)
+{
+}
+
+void VID_HandlePause (qboolean pause)
+{
+}