2000-05-10 20:33:16 +00:00
|
|
|
/*
|
2000-05-14 18:06:53 +00:00
|
|
|
vid_glx.c
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-17 18:28:13 +00:00
|
|
|
OpenGL GLX video driver
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2000-05-23 06:36:33 +00:00
|
|
|
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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$
|
2000-05-10 20:33:16 +00:00
|
|
|
*/
|
2000-05-11 16:03:29 +00:00
|
|
|
|
2000-07-11 05:05:27 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2000-05-23 06:36:33 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <signal.h>
|
2000-07-11 05:05:27 +00:00
|
|
|
#include <values.h>
|
2000-09-24 03:43:06 +00:00
|
|
|
#include <string.h>
|
2000-05-23 06:36:33 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_DLFCN_H
|
|
|
|
# include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
#ifndef RTLD_LAZY
|
|
|
|
# ifdef DL_LAZY
|
|
|
|
# define RTLD_LAZY DL_LAZY
|
|
|
|
# else
|
|
|
|
# define RTLD_LAZY 0
|
|
|
|
# endif
|
|
|
|
#endif
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
#include <GL/glx.h>
|
|
|
|
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include <X11/cursorfont.h>
|
|
|
|
|
2000-05-23 16:57:12 +00:00
|
|
|
#ifdef HAVE_DGA
|
2000-05-23 06:36:33 +00:00
|
|
|
# include <X11/extensions/xf86dga.h>
|
2000-05-10 11:29:38 +00:00
|
|
|
#endif
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
#ifdef XMESA
|
|
|
|
# include <GL/xmesa.h>
|
|
|
|
#endif
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-07-11 05:05:27 +00:00
|
|
|
#include "qtypes.h"
|
|
|
|
#include "quakedef.h"
|
|
|
|
#include "qendian.h"
|
|
|
|
#include "glquake.h"
|
|
|
|
#include "cvar.h"
|
|
|
|
#include "qargs.h"
|
|
|
|
#include "console.h"
|
|
|
|
#include "keys.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "sys.h"
|
2000-09-24 03:43:06 +00:00
|
|
|
#include "quakefs.h"
|
2000-07-11 05:05:27 +00:00
|
|
|
#include "draw.h"
|
2000-09-24 03:43:06 +00:00
|
|
|
#include "input.h"
|
2000-07-11 05:05:27 +00:00
|
|
|
#include "sbar.h"
|
|
|
|
#include "context_x11.h"
|
|
|
|
#include "dga_check.h"
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
#define WARP_WIDTH 320
|
|
|
|
#define WARP_HEIGHT 200
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
static qboolean vid_initialized = false;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
static GLXContext ctx = NULL;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
unsigned short d_8to16table[256];
|
2000-09-22 09:08:08 +00:00
|
|
|
unsigned int d_8to24table[256];
|
2000-05-10 11:29:38 +00:00
|
|
|
unsigned char d_15to8table[65536];
|
|
|
|
|
2000-05-16 04:47:41 +00:00
|
|
|
cvar_t *vid_mode;
|
2000-05-23 06:36:33 +00:00
|
|
|
|
2000-05-23 16:57:12 +00:00
|
|
|
#ifdef HAVE_DGA
|
2000-05-23 06:36:33 +00:00
|
|
|
static int hasdgavideo = 0;
|
|
|
|
static int hasdga = 0;
|
|
|
|
#endif
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
#ifdef HAVE_DLOPEN
|
|
|
|
static void *dlhand = NULL;
|
|
|
|
#endif
|
|
|
|
static GLboolean (*QF_XMesaSetFXmode)(GLint mode) = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
int scr_width, scr_height;
|
|
|
|
|
2000-05-23 16:57:12 +00:00
|
|
|
#if defined(XMESA) || defined(HAVE_DGA)
|
2000-05-23 06:36:33 +00:00
|
|
|
int VID_options_items = 2;
|
|
|
|
#else
|
|
|
|
int VID_options_items = 1;
|
|
|
|
#endif
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
//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;
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
float gldepthmin, gldepthmax;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
const char *gl_vendor;
|
|
|
|
const char *gl_renderer;
|
|
|
|
const char *gl_version;
|
|
|
|
const char *gl_extensions;
|
|
|
|
|
|
|
|
qboolean is8bit = false;
|
2000-06-05 12:22:22 +00:00
|
|
|
|
|
|
|
// ARB Multitexture
|
|
|
|
int gl_mtex_enum = TEXTURE0_SGIS;
|
|
|
|
qboolean gl_arb_mtex = false;
|
2000-05-10 11:29:38 +00:00
|
|
|
qboolean gl_mtexable = false;
|
|
|
|
|
2000-07-27 03:37:41 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void D_EndDirectRect (int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
void
|
|
|
|
VID_Shutdown(void)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-05-23 06:36:33 +00:00
|
|
|
if (!vid_initialized)
|
2000-05-10 11:29:38 +00:00
|
|
|
return;
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
Con_Printf("VID_Shutdown\n");
|
|
|
|
glXDestroyContext(x_disp, ctx);
|
2000-10-05 16:22:18 +00:00
|
|
|
XDestroyWindow(x_disp, x_win);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-09-24 03:43:06 +00:00
|
|
|
x11_restore_vidmode();
|
2000-05-23 06:36:33 +00:00
|
|
|
#ifdef HAVE_DLOPEN
|
|
|
|
if (dlhand) {
|
|
|
|
dlclose(dlhand);
|
|
|
|
dlhand = NULL;
|
2000-05-14 19:27:44 +00:00
|
|
|
}
|
2000-05-23 06:36:33 +00:00
|
|
|
#endif
|
|
|
|
x11_close_display();
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
2000-06-29 09:21:23 +00:00
|
|
|
#if 0
|
2000-05-23 06:36:33 +00:00
|
|
|
static void
|
|
|
|
signal_handler(int sig)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
|
|
|
printf("Received signal %d, exiting...\n", sig);
|
|
|
|
Sys_Quit();
|
2000-05-23 06:36:33 +00:00
|
|
|
exit(sig);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
static void
|
|
|
|
InitSig(void)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
|
|
|
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);
|
2000-05-23 06:36:33 +00:00
|
|
|
/* signal(SIGFPE, signal_handler); */
|
2000-05-10 11:29:38 +00:00
|
|
|
signal(SIGSEGV, signal_handler);
|
|
|
|
signal(SIGTERM, signal_handler);
|
|
|
|
}
|
2000-06-29 09:21:23 +00:00
|
|
|
#endif
|
2000-05-10 11:29:38 +00:00
|
|
|
void VID_ShiftPalette(unsigned char *p)
|
|
|
|
{
|
2000-05-13 05:29:57 +00:00
|
|
|
VID_SetPalette(p);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VID_SetPalette (unsigned char *palette)
|
|
|
|
{
|
|
|
|
byte *pal;
|
2000-09-22 09:08:08 +00:00
|
|
|
unsigned int r,g,b;
|
|
|
|
unsigned int v;
|
2000-05-10 11:29:38 +00:00
|
|
|
int r1,g1,b1;
|
|
|
|
int k;
|
|
|
|
unsigned short i;
|
2000-09-22 09:08:08 +00:00
|
|
|
unsigned int *table;
|
2000-09-27 19:44:26 +00:00
|
|
|
QFile *f;
|
2000-05-10 11:29:38 +00:00
|
|
|
char s[255];
|
|
|
|
float dist, bestdist;
|
|
|
|
static qboolean palflag = false;
|
|
|
|
|
|
|
|
//
|
|
|
|
// 8 8 8 encoding
|
|
|
|
//
|
2000-05-23 06:36:33 +00:00
|
|
|
// Con_Printf("Converting 8to24\n");
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
pal = palette;
|
|
|
|
table = d_8to24table;
|
|
|
|
for (i=0 ; i<256 ; i++)
|
|
|
|
{
|
|
|
|
r = pal[0];
|
|
|
|
g = pal[1];
|
|
|
|
b = pal[2];
|
|
|
|
pal += 3;
|
2000-05-23 06:36:33 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
// v = (255<<24) + (r<<16) + (g<<8) + (b<<0);
|
|
|
|
// v = (255<<0) + (r<<8) + (g<<16) + (b<<24);
|
|
|
|
v = (255<<24) + (r<<0) + (g<<8) + (b<<16);
|
|
|
|
*table++ = v;
|
|
|
|
}
|
This is a NON-TRIVIAL update which took LordHavoc and I about 3 days to
make work properly:
Win32 thing.. If you don't free textures explicitly, you can cause a
problem with nVidia drivers.
Colored lighting is now RGB instead of RGBA. The alpha is kinda pointless
on a lightmap and the effect's not all that great. Plus people stuck with
16 bit OpenGL (any other 3dfx people out there?) will be quite pleased
with the improvement in image quality. This does include LordHavoc's
dynamic light optimization code which takes most of the pain out of having
gl_flashblend off.
All glColor*'s are now half of what they used to be, except where they
aren't. If that doesn't make sense, don't worry. If you see one that's
only half what you'd expect, don't worry---it probably is meant to be like
that.. (More below)
glDisable (GL_BLEND) is now a thing of the GL_PAST. As is GL_REPLACE.
Instead, we _always_ use GL_MODULATE and leave GL_BLEND turned on. This
seems at first like it might be a performance hit, but I swear it's much
more expensive to change blending modes and texture functions 20-30 times
every screen frame!
Win32 issue.. Even though we check for multitexture, we currently don't
use it. Reason is that I am planning to replace SGIS_multitexture with
the preferred ARB_multitexture extension which is supported in most GL 1.1
implementations and is a requirement for GL 1.2 anyway. I also wanted to
get rid of some duplicated code. Since Linux doesn't support multitexture
yet, I just commented out the code keeping me from compiling to get it to
work. Win32 should work without it until it's fixed, which shouldn't be
long since the differences between SGIS and ARB multitextures as far as
Quake is concerned is minimal AT BEST.
LordHavoc and I have been working tirelessly (well not quite, we both did
manage to sleep sometime during this ordeal) to fix the lighting in the GL
renderers! It looks DAMNED CLOSE to software's lighting now, including
the ability to overbright a color. You've gotta see this to know what I'm
talking about. That's why the glColor*'s are halved in most places. The
gamma table code and the general way it works is LordHavoc's design, but
over the course of re-implementing it in QF we did come up with a few more
small optimizations.
A lot of people have noticed that QF's fps count has gone to shit lately.
No promises that this undid whatever the problem was. That means there
could be a huge optimization lurking somewhere in the shadows, waiting for
us to fix it for a massive FPS boost. Even if there's not, the code in
this commit DOUBLED MY FPS COUNT. Granted I was getting pathetic FPS as
it was (around 30, which is pathetic even for a Voodoo3 in Linux) but
still---60 is a big improvement over 30!
Please be sure to "test" this code thuroughly.
2000-06-03 19:56:09 +00:00
|
|
|
d_8to24table[255] &= 0; // 255 is transparent
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
// JACK: 3D distance calcs - k is last closest, l is the distance.
|
|
|
|
// FIXME: Precalculate this and cache to disk.
|
|
|
|
if (palflag)
|
|
|
|
return;
|
|
|
|
palflag = true;
|
|
|
|
|
|
|
|
COM_FOpenFile("glquake/15to8.pal", &f);
|
|
|
|
if (f) {
|
2000-09-27 19:44:26 +00:00
|
|
|
Qread(f, d_15to8table, 1<<15);
|
|
|
|
Qclose(f);
|
2000-05-10 11:29:38 +00:00
|
|
|
} else {
|
|
|
|
for (i=0; i < (1<<15); i++) {
|
|
|
|
/* Maps
|
|
|
|
000000000000000
|
|
|
|
000000000011111 = Red = 0x1F
|
|
|
|
000001111100000 = Blue = 0x03E0
|
|
|
|
111110000000000 = Grn = 0x7C00
|
|
|
|
*/
|
|
|
|
r = ((i & 0x1F) << 3)+4;
|
|
|
|
g = ((i & 0x03E0) >> 2)+4;
|
|
|
|
b = ((i & 0x7C00) >> 7)+4;
|
|
|
|
pal = (unsigned char *)d_8to24table;
|
|
|
|
for (v=0,k=0,bestdist=10000.0; v<256; v++,pal+=4) {
|
|
|
|
r1 = (int)r - (int)pal[0];
|
|
|
|
g1 = (int)g - (int)pal[1];
|
|
|
|
b1 = (int)b - (int)pal[2];
|
|
|
|
dist = sqrt(((r1*r1)+(g1*g1)+(b1*b1)));
|
|
|
|
if (dist < bestdist) {
|
|
|
|
k=v;
|
|
|
|
bestdist = dist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
d_15to8table[i]=k;
|
|
|
|
}
|
2000-05-23 06:36:33 +00:00
|
|
|
snprintf(s, sizeof(s), "%s/glquake", com_gamedir);
|
2000-05-10 11:29:38 +00:00
|
|
|
Sys_mkdir (s);
|
2000-05-23 06:36:33 +00:00
|
|
|
snprintf(s, sizeof(s), "%s/glquake/15to8.pal", com_gamedir);
|
2000-09-27 19:44:26 +00:00
|
|
|
if ((f = Qopen(s, "wb")) != NULL) {
|
|
|
|
Qwrite(f, d_15to8table, 1<<15);
|
|
|
|
Qclose(f);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-09 21:34:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
CheckMultiTextureExtensions
|
|
|
|
|
|
|
|
Check for ARB, SGIS, or EXT multitexture support
|
|
|
|
*/
|
2000-06-03 22:32:53 +00:00
|
|
|
void
|
|
|
|
CheckMultiTextureExtensions ( void )
|
|
|
|
{
|
2000-06-09 21:34:21 +00:00
|
|
|
Con_Printf ("Checking for multitexture... ");
|
2000-06-05 12:22:22 +00:00
|
|
|
if (COM_CheckParm ("-nomtex"))
|
|
|
|
{
|
2000-06-09 21:34:21 +00:00
|
|
|
Con_Printf ("disabled\n");
|
2000-06-05 12:22:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-06-04 13:53:29 +00:00
|
|
|
#ifdef HAVE_DLOPEN
|
|
|
|
dlhand = dlopen (NULL, RTLD_LAZY);
|
2000-06-09 21:34:21 +00:00
|
|
|
if (dlhand == NULL)
|
2000-06-04 13:53:29 +00:00
|
|
|
{
|
2000-06-09 21:34:21 +00:00
|
|
|
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;
|
|
|
|
gl_arb_mtex = 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;
|
|
|
|
gl_arb_mtex = false;
|
|
|
|
} else if (strstr(gl_extensions, "GL_EXT_multitexture "))
|
|
|
|
{
|
|
|
|
Con_Printf ("GL_EXT_multitexture\n");
|
|
|
|
qglMTexCoord2f = (void *)dlsym(dlhand, "glMTexCoord2fEXT");
|
|
|
|
qglSelectTexture = (void *)dlsym(dlhand, "glSelectTextureEXT");
|
|
|
|
gl_mtex_enum = TEXTURE0_SGIS;
|
|
|
|
gl_mtexable = true;
|
|
|
|
gl_arb_mtex = false;
|
2000-06-04 13:53:29 +00:00
|
|
|
} else {
|
2000-06-09 21:34:21 +00:00
|
|
|
Con_Printf ("none found\n");
|
2000-06-04 13:53:29 +00:00
|
|
|
}
|
2000-06-09 21:34:21 +00:00
|
|
|
dlclose(dlhand);
|
|
|
|
dlhand = NULL;
|
2000-06-04 13:53:29 +00:00
|
|
|
#else
|
2000-06-03 22:32:53 +00:00
|
|
|
gl_mtexable = false;
|
2000-06-04 13:53:29 +00:00
|
|
|
#endif
|
2000-06-03 22:32:53 +00:00
|
|
|
}
|
2000-05-23 06:36:33 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
/*
|
|
|
|
===============
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Con_Printf ("%s %s\n", gl_renderer, gl_version);
|
|
|
|
|
2000-06-03 22:32:53 +00:00
|
|
|
CheckMultiTextureExtensions ();
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
glClearColor (0,0,0,0);
|
2000-05-10 11:29:38 +00:00
|
|
|
glCullFace(GL_FRONT);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
glEnable(GL_ALPHA_TEST);
|
|
|
|
glAlphaFunc(GL_GREATER, 0.666);
|
|
|
|
|
|
|
|
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
2000-05-17 18:28:13 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
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);
|
|
|
|
|
2000-09-28 08:12:50 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
This is a NON-TRIVIAL update which took LordHavoc and I about 3 days to
make work properly:
Win32 thing.. If you don't free textures explicitly, you can cause a
problem with nVidia drivers.
Colored lighting is now RGB instead of RGBA. The alpha is kinda pointless
on a lightmap and the effect's not all that great. Plus people stuck with
16 bit OpenGL (any other 3dfx people out there?) will be quite pleased
with the improvement in image quality. This does include LordHavoc's
dynamic light optimization code which takes most of the pain out of having
gl_flashblend off.
All glColor*'s are now half of what they used to be, except where they
aren't. If that doesn't make sense, don't worry. If you see one that's
only half what you'd expect, don't worry---it probably is meant to be like
that.. (More below)
glDisable (GL_BLEND) is now a thing of the GL_PAST. As is GL_REPLACE.
Instead, we _always_ use GL_MODULATE and leave GL_BLEND turned on. This
seems at first like it might be a performance hit, but I swear it's much
more expensive to change blending modes and texture functions 20-30 times
every screen frame!
Win32 issue.. Even though we check for multitexture, we currently don't
use it. Reason is that I am planning to replace SGIS_multitexture with
the preferred ARB_multitexture extension which is supported in most GL 1.1
implementations and is a requirement for GL 1.2 anyway. I also wanted to
get rid of some duplicated code. Since Linux doesn't support multitexture
yet, I just commented out the code keeping me from compiling to get it to
work. Win32 should work without it until it's fixed, which shouldn't be
long since the differences between SGIS and ARB multitextures as far as
Quake is concerned is minimal AT BEST.
LordHavoc and I have been working tirelessly (well not quite, we both did
manage to sleep sometime during this ordeal) to fix the lighting in the GL
renderers! It looks DAMNED CLOSE to software's lighting now, including
the ability to overbright a color. You've gotta see this to know what I'm
talking about. That's why the glColor*'s are halved in most places. The
gamma table code and the general way it works is LordHavoc's design, but
over the course of re-implementing it in QF we did come up with a few more
small optimizations.
A lot of people have noticed that QF's fps count has gone to shit lately.
No promises that this undid whatever the problem was. That means there
could be a huge optimization lurking somewhere in the shadows, waiting for
us to fix it for a massive FPS boost. Even if there's not, the code in
this commit DOUBLED MY FPS COUNT. Granted I was getting pathetic FPS as
it was (around 30, which is pathetic even for a Voodoo3 in Linux) but
still---60 is a big improvement over 30!
Please be sure to "test" this code thuroughly.
2000-06-03 19:56:09 +00:00
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
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();
|
2000-05-14 19:27:44 +00:00
|
|
|
glXSwapBuffers(x_disp, x_win);
|
2000-06-04 13:53:29 +00:00
|
|
|
Sbar_Changed ();
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qboolean VID_Is8bit(void)
|
|
|
|
{
|
|
|
|
return is8bit;
|
|
|
|
}
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
#ifdef GL_EXT_SHARED
|
|
|
|
void VID_Init8bitPalette()
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
|
|
|
// Check for 8bit Extensions and initialize them.
|
|
|
|
int i;
|
|
|
|
char thePalette[256*3];
|
|
|
|
char *oldPalette, *newPalette;
|
|
|
|
|
|
|
|
if (strstr(gl_extensions, "GL_EXT_shared_texture_palette") == NULL)
|
|
|
|
return;
|
|
|
|
|
2000-09-29 19:29:22 +00:00
|
|
|
Con_Printf("8-bit GL extensions enabled.\n");
|
2000-05-10 11:29:38 +00:00
|
|
|
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++;
|
|
|
|
}
|
|
|
|
glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, (void *) thePalette);
|
|
|
|
is8bit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2000-05-17 18:28:13 +00:00
|
|
|
|
|
|
|
void VID_Init8bitPalette(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2000-05-16 07:21:28 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
void VID_Init(unsigned char *palette)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int attrib[] = {
|
|
|
|
GLX_RGBA,
|
|
|
|
GLX_RED_SIZE, 1,
|
|
|
|
GLX_GREEN_SIZE, 1,
|
|
|
|
GLX_BLUE_SIZE, 1,
|
|
|
|
GLX_DOUBLEBUFFER,
|
|
|
|
GLX_DEPTH_SIZE, 1,
|
|
|
|
None
|
|
|
|
};
|
|
|
|
char gldir[MAX_OSPATH];
|
|
|
|
int width = 640, height = 480;
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
vid_mode = Cvar_Get ("vid_mode","0",0,"None");
|
2000-05-10 11:29:38 +00:00
|
|
|
vid.maxwarpwidth = WARP_WIDTH;
|
|
|
|
vid.maxwarpheight = WARP_HEIGHT;
|
|
|
|
vid.colormap = host_colormap;
|
|
|
|
vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
/* Interpret command-line params
|
|
|
|
*/
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
/* Set vid parameters */
|
2000-05-10 11:29:38 +00:00
|
|
|
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)
|
2000-05-21 08:24:45 +00:00
|
|
|
vid.conwidth = atoi(com_argv[i+1]);
|
2000-05-10 11:29:38 +00:00
|
|
|
else
|
2000-05-17 18:28:13 +00:00
|
|
|
vid.conwidth = width;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
vid.conwidth &= 0xfff8; // make it a multiple of eight
|
2000-05-23 06:36:33 +00:00
|
|
|
if (vid.conwidth < 320)
|
|
|
|
vid.conwidth = 320;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
// pick a conheight that matches with correct aspect
|
2000-05-23 06:36:33 +00:00
|
|
|
vid.conheight = vid.conwidth * 3 / 4;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
i = COM_CheckParm ("-conheight");
|
|
|
|
if ( i != 0 ) // Set console height, but no smaller than 200 px
|
|
|
|
vid.conheight = atoi(com_argv[i+1]);
|
|
|
|
if (vid.conheight < 200)
|
|
|
|
vid.conheight = 200;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
x11_open_display();
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-09-24 03:43:06 +00:00
|
|
|
x_visinfo = glXChooseVisual(x_disp, x_screen, attrib);
|
|
|
|
if (!x_visinfo) {
|
2000-05-23 06:36:33 +00:00
|
|
|
fprintf(stderr, "Error couldn't get an RGB, Double-buffered, Depth visual\n");
|
2000-05-10 11:29:38 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2000-09-24 03:43:06 +00:00
|
|
|
x_vis = x_visinfo->visual;
|
2000-05-23 06:36:33 +00:00
|
|
|
|
2000-05-23 16:57:12 +00:00
|
|
|
#ifdef HAVE_DGA
|
2000-05-23 06:36:33 +00:00
|
|
|
{
|
|
|
|
int maj_ver;
|
|
|
|
|
|
|
|
hasdga = VID_CheckDGA(x_disp, &maj_ver, NULL, &hasdgavideo);
|
|
|
|
if (!hasdga || maj_ver < 1) {
|
|
|
|
hasdga = hasdgavideo = 0;
|
|
|
|
}
|
|
|
|
}
|
2000-09-29 19:29:22 +00:00
|
|
|
Con_Printf ("hasdga = %i\nhasdgavideo = %i\n", hasdga, hasdgavideo);
|
2000-05-23 06:36:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_DLOPEN
|
|
|
|
dlhand = dlopen(NULL, RTLD_LAZY);
|
|
|
|
if (dlhand) {
|
|
|
|
QF_XMesaSetFXmode = dlsym(dlhand, "XMesaSetFXmode");
|
|
|
|
if (!QF_XMesaSetFXmode) {
|
|
|
|
QF_XMesaSetFXmode = dlsym(dlhand, "_XMesaSetFXmode");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
QF_XMesaSetFXmode = NULL;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#ifdef XMESA
|
|
|
|
QF_XMesaSetFXmode = XMesaSetFXmode;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
if (QF_XMesaSetFXmode) {
|
|
|
|
#ifdef XMESA
|
|
|
|
const char *str = getenv("MESA_GLX_FX");
|
|
|
|
if (str != NULL && *str != 'd') {
|
|
|
|
if (tolower(*str) == 'w') {
|
|
|
|
Cvar_Set (vid_fullscreen, "0");
|
|
|
|
} else {
|
|
|
|
Cvar_Set (vid_fullscreen, "1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* Glide uses DGA internally, so we don't want to
|
|
|
|
mess with it. */
|
|
|
|
// hasdga = 0;
|
|
|
|
}
|
|
|
|
|
2000-09-24 03:43:06 +00:00
|
|
|
x11_set_vidmode(width, height);
|
|
|
|
x11_create_window(width, height);
|
2000-07-27 03:37:41 +00:00
|
|
|
/* Invisible cursor */
|
2000-09-24 03:43:06 +00:00
|
|
|
x11_create_null_cursor();
|
2000-07-27 03:37:41 +00:00
|
|
|
|
2000-07-27 04:39:01 +00:00
|
|
|
XWarpPointer(x_disp, None, x_win, 0, 0, 0, 0,
|
|
|
|
vid.width+2, vid.height+2);
|
|
|
|
|
2000-09-24 03:43:06 +00:00
|
|
|
x11_grab_keyboard();
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
XSync(x_disp, 0);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-09-24 03:43:06 +00:00
|
|
|
ctx = glXCreateContext(x_disp, x_visinfo, NULL, True);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-14 19:27:44 +00:00
|
|
|
glXMakeCurrent(x_disp, x_win, ctx);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
scr_width = width;
|
|
|
|
scr_height = height;
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
if (vid.conheight > height)
|
|
|
|
vid.conheight = height;
|
|
|
|
if (vid.conwidth > width)
|
|
|
|
vid.conwidth = width;
|
|
|
|
vid.width = vid.conwidth;
|
|
|
|
vid.height = vid.conheight;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
|
|
|
|
vid.numpages = 2;
|
|
|
|
|
2000-06-26 17:20:38 +00:00
|
|
|
//InitSig(); // trap evil signals
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
GL_Init();
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
snprintf(gldir, sizeof(gldir), "%s/glquake", com_gamedir);
|
2000-05-10 11:29:38 +00:00
|
|
|
Sys_mkdir (gldir);
|
|
|
|
|
2000-05-31 17:46:59 +00:00
|
|
|
GL_CheckGamma (palette);
|
|
|
|
VID_SetPalette (palette);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
// Check for 3DFX Extensions and initialize them.
|
|
|
|
VID_Init8bitPalette();
|
|
|
|
|
2000-09-29 19:29:22 +00:00
|
|
|
Con_Printf ("Video mode %dx%d initialized.\n",
|
2000-05-23 06:36:33 +00:00
|
|
|
width, height);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
vid_initialized = true;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
vid.recalc_refdef = 1; // force a surface cache flush
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
void VID_InitCvars()
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
void
|
|
|
|
VID_LockBuffer ( void )
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
void
|
|
|
|
VID_UnlockBuffer ( void )
|
2000-05-17 18:28:13 +00:00
|
|
|
{
|
|
|
|
}
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-10-03 07:10:48 +00:00
|
|
|
void
|
|
|
|
VID_SetCaption (char *text)
|
2000-07-14 16:09:35 +00:00
|
|
|
{
|
2000-10-04 05:45:48 +00:00
|
|
|
if (text && *text) {
|
|
|
|
x11_set_caption (va ("%s %s: %s", PROGRAM, VERSION, text));
|
|
|
|
} else {
|
|
|
|
x11_set_caption (va ("%s %s", PROGRAM, VERSION));
|
|
|
|
}
|
2000-07-14 16:09:35 +00:00
|
|
|
}
|