1999-12-25 05:32:39 +00:00
|
|
|
/*
|
2000-04-30 22:27:58 +00:00
|
|
|
vid_glx.c
|
2000-03-24 09:55:33 +00:00
|
|
|
|
2000-04-17 14:49:32 +00:00
|
|
|
OpenGL GLX video driver
|
2000-03-24 09:55:33 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 1999-2000 Nelson Rush.
|
|
|
|
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
|
|
|
|
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$
|
1999-12-25 05:32:39 +00:00
|
|
|
*/
|
2000-01-09 05:23:14 +00:00
|
|
|
|
2000-05-01 13:08:01 +00:00
|
|
|
#include <values.h>
|
2000-02-19 20:54:58 +00:00
|
|
|
#include <qtypes.h>
|
|
|
|
#include <quakedef.h>
|
|
|
|
#include <glquake.h>
|
|
|
|
#include <cvar.h>
|
|
|
|
#include <console.h>
|
|
|
|
#include <keys.h>
|
|
|
|
#include <menu.h>
|
2000-01-29 18:46:26 +00:00
|
|
|
#include <sys.h>
|
|
|
|
#include <lib_replace.h>
|
|
|
|
#include <draw.h>
|
2000-03-14 10:25:46 +00:00
|
|
|
#include <context_x11.h>
|
1999-12-25 05:32:39 +00:00
|
|
|
|
2000-01-09 05:55:26 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2000-01-19 01:55:15 +00:00
|
|
|
#include <ctype.h>
|
2000-01-09 05:55:26 +00:00
|
|
|
#include <signal.h>
|
|
|
|
|
2000-01-19 01:55:15 +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
|
|
|
|
|
1999-12-25 05:32:39 +00:00
|
|
|
#include <GL/glx.h>
|
|
|
|
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include <X11/cursorfont.h>
|
|
|
|
|
2000-01-19 01:55:15 +00:00
|
|
|
#ifdef HAS_DGA
|
|
|
|
# include <X11/extensions/xf86dga.h>
|
2000-05-01 10:36:00 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAS_VIDMODE
|
2000-01-19 01:55:15 +00:00
|
|
|
# include <X11/extensions/xf86vmode.h>
|
1999-12-25 05:32:39 +00:00
|
|
|
#endif
|
2000-02-19 20:54:58 +00:00
|
|
|
#include <dga_check.h>
|
1999-12-25 05:32:39 +00:00
|
|
|
|
2000-01-09 01:11:44 +00:00
|
|
|
#ifdef XMESA
|
2000-01-19 01:55:15 +00:00
|
|
|
# include <GL/xmesa.h>
|
2000-01-09 01:11:44 +00:00
|
|
|
#endif
|
1999-12-25 05:32:39 +00:00
|
|
|
|
|
|
|
#define WARP_WIDTH 320
|
|
|
|
#define WARP_HEIGHT 200
|
|
|
|
|
2000-04-17 14:49:32 +00:00
|
|
|
static qboolean vid_initialized = false;
|
|
|
|
|
2000-01-15 04:09:22 +00:00
|
|
|
static int screen;
|
2000-02-19 08:24:15 +00:00
|
|
|
Window x_win;
|
2000-01-15 04:09:22 +00:00
|
|
|
static GLXContext ctx = NULL;
|
1999-12-25 05:32:39 +00:00
|
|
|
|
2000-02-19 08:24:15 +00:00
|
|
|
#define X_MASK (VisibilityChangeMask | StructureNotifyMask)
|
1999-12-25 05:32:39 +00:00
|
|
|
|
|
|
|
unsigned short d_8to16table[256];
|
2000-01-15 04:09:22 +00:00
|
|
|
unsigned d_8to24table[256];
|
1999-12-25 05:32:39 +00:00
|
|
|
unsigned char d_15to8table[65536];
|
|
|
|
|
2000-02-27 07:13:32 +00:00
|
|
|
cvar_t *vid_mode;
|
2000-05-01 22:53:16 +00:00
|
|
|
cvar_t *vid_fullscreen;
|
2000-02-28 19:13:16 +00:00
|
|
|
extern cvar_t *gl_triplebuffer;
|
2000-02-29 06:45:26 +00:00
|
|
|
extern cvar_t *vid_dga_mouseaccel;
|
2000-01-15 04:09:22 +00:00
|
|
|
|
2000-05-01 10:36:00 +00:00
|
|
|
#ifdef HAS_VIDMODE
|
2000-01-15 04:09:22 +00:00
|
|
|
static XF86VidModeModeInfo **vidmodes;
|
2000-05-01 10:36:00 +00:00
|
|
|
static int nummodes, hasvidmode = 0;
|
|
|
|
#endif
|
|
|
|
#ifdef HAS_DGA
|
|
|
|
static int hasdgavideo = 0;
|
|
|
|
static int hasdga = 0;
|
2000-01-15 04:09:22 +00:00
|
|
|
#endif
|
1999-12-25 05:32:39 +00:00
|
|
|
|
2000-05-01 10:36:00 +00:00
|
|
|
|
2000-01-19 01:55:15 +00:00
|
|
|
#ifdef HAVE_DLOPEN
|
|
|
|
static void *dlhand = NULL;
|
|
|
|
#endif
|
|
|
|
static GLboolean (*QF_XMesaSetFXmode)(GLint mode) = NULL;
|
|
|
|
|
|
|
|
|
1999-12-25 05:32:39 +00:00
|
|
|
static int scr_width, scr_height;
|
|
|
|
|
2000-01-19 01:55:15 +00:00
|
|
|
#if defined(XMESA) || defined(HAS_DGA)
|
2000-01-09 05:55:26 +00:00
|
|
|
int VID_options_items = 2;
|
2000-01-09 03:03:42 +00:00
|
|
|
#else
|
2000-01-09 05:55:26 +00:00
|
|
|
int VID_options_items = 1;
|
2000-01-09 03:03:42 +00:00
|
|
|
#endif
|
|
|
|
|
1999-12-25 05:32:39 +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;
|
|
|
|
|
|
|
|
float gldepthmin, gldepthmax;
|
|
|
|
|
2000-02-27 07:13:32 +00:00
|
|
|
cvar_t *gl_ztrick;
|
1999-12-25 05:32:39 +00:00
|
|
|
|
|
|
|
const char *gl_vendor;
|
|
|
|
const char *gl_renderer;
|
|
|
|
const char *gl_version;
|
|
|
|
const char *gl_extensions;
|
|
|
|
|
|
|
|
qboolean is8bit = false;
|
|
|
|
qboolean gl_mtexable = 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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-01-15 04:09:22 +00:00
|
|
|
void
|
|
|
|
VID_Shutdown(void)
|
1999-12-25 05:32:39 +00:00
|
|
|
{
|
2000-04-17 14:49:32 +00:00
|
|
|
if (!vid_initialized)
|
|
|
|
return;
|
|
|
|
|
2000-02-20 04:20:00 +00:00
|
|
|
Con_Printf("VID_Shutdown\n");
|
1999-12-25 05:32:39 +00:00
|
|
|
|
2000-04-15 04:08:20 +00:00
|
|
|
glXDestroyContext(x_disp, ctx);
|
2000-04-01 06:05:03 +00:00
|
|
|
|
2000-05-01 10:36:00 +00:00
|
|
|
#ifdef HAS_VIDMODE
|
2000-01-15 04:09:22 +00:00
|
|
|
if (hasvidmode) {
|
|
|
|
int i;
|
|
|
|
|
2000-05-01 13:08:01 +00:00
|
|
|
XF86VidModeSwitchToMode (x_disp, DefaultScreen (x_disp),
|
|
|
|
vidmodes[0]);
|
2000-01-15 04:09:22 +00:00
|
|
|
for (i = 0; i < nummodes; i++) {
|
|
|
|
if (vidmodes[i]->private) XFree(vidmodes[i]->private);
|
|
|
|
}
|
|
|
|
XFree(vidmodes);
|
|
|
|
}
|
|
|
|
#endif
|
2000-01-19 01:55:15 +00:00
|
|
|
#ifdef HAVE_DLOPEN
|
|
|
|
if (dlhand) {
|
|
|
|
dlclose(dlhand);
|
|
|
|
dlhand = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2000-03-14 10:25:46 +00:00
|
|
|
x11_close_display();
|
1999-12-25 05:32:39 +00:00
|
|
|
}
|
2000-04-17 14:49:32 +00:00
|
|
|
|
2000-01-15 04:09:22 +00:00
|
|
|
static void
|
|
|
|
signal_handler(int sig)
|
1999-12-25 05:32:39 +00:00
|
|
|
{
|
|
|
|
printf("Received signal %d, exiting...\n", sig);
|
|
|
|
Sys_Quit();
|
2000-01-15 04:09:22 +00:00
|
|
|
exit(sig);
|
1999-12-25 05:32:39 +00:00
|
|
|
}
|
|
|
|
|
2000-01-15 04:09:22 +00:00
|
|
|
static void
|
|
|
|
InitSig(void)
|
1999-12-25 05:32:39 +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-01-03 08:00:46 +00:00
|
|
|
/* signal(SIGFPE, signal_handler); */
|
1999-12-25 05:32:39 +00:00
|
|
|
signal(SIGSEGV, signal_handler);
|
|
|
|
signal(SIGTERM, signal_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VID_ShiftPalette(unsigned char *p)
|
|
|
|
{
|
2000-01-19 08:15:30 +00:00
|
|
|
VID_SetPalette(p);
|
1999-12-25 05:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VID_SetPalette (unsigned char *palette)
|
|
|
|
{
|
|
|
|
byte *pal;
|
|
|
|
unsigned r,g,b;
|
|
|
|
unsigned v;
|
|
|
|
int r1,g1,b1;
|
|
|
|
int k;
|
|
|
|
unsigned short i;
|
|
|
|
unsigned *table;
|
2000-02-08 07:23:09 +00:00
|
|
|
QFile *f;
|
1999-12-25 05:32:39 +00:00
|
|
|
char s[255];
|
|
|
|
float dist, bestdist;
|
|
|
|
static qboolean palflag = false;
|
|
|
|
|
|
|
|
//
|
|
|
|
// 8 8 8 encoding
|
|
|
|
//
|
2000-01-19 08:33:15 +00:00
|
|
|
// Con_Printf("Converting 8to24\n");
|
1999-12-25 05:32:39 +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-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:32:39 +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;
|
|
|
|
}
|
|
|
|
d_8to24table[255] &= 0xffffff; // 255 is transparent
|
|
|
|
|
|
|
|
// 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-02-08 07:23:09 +00:00
|
|
|
Qread(f, d_15to8table, 1<<15);
|
|
|
|
Qclose(f);
|
1999-12-25 05:32:39 +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-01-05 00:05:48 +00:00
|
|
|
snprintf(s, sizeof(s), "%s/glquake", com_gamedir);
|
1999-12-25 05:32:39 +00:00
|
|
|
Sys_mkdir (s);
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(s, sizeof(s), "%s/glquake/15to8.pal", com_gamedir);
|
2000-02-08 07:23:09 +00:00
|
|
|
if ((f = Qopen(s, "wb")) != NULL) {
|
|
|
|
Qwrite(f, d_15to8table, 1<<15);
|
|
|
|
Qclose(f);
|
1999-12-25 05:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-15 04:09:22 +00:00
|
|
|
|
1999-12-25 05:32:39 +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-02-27 03:34:54 +00:00
|
|
|
glClearColor (0,0,0,0);
|
1999-12-25 05:32:39 +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-01-18 03:38:04 +00:00
|
|
|
|
|
|
|
/* glShadeMode(GL_SMOOTH) should look better then GL_FLAT but
|
|
|
|
I don't know if it looks any better, sure is slower
|
|
|
|
glShadeModel (GL_SMOOTH);
|
|
|
|
*/
|
1999-12-25 05:32:39 +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);
|
|
|
|
|
|
|
|
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
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-02-19 08:24:15 +00:00
|
|
|
glXSwapBuffers(x_disp, x_win);
|
1999-12-25 05:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qboolean VID_Is8bit(void)
|
|
|
|
{
|
|
|
|
return is8bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GL_EXT_SHARED
|
2000-03-19 15:59:51 +00:00
|
|
|
void VID_Init8bitPalette()
|
1999-12-25 05:32:39 +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;
|
|
|
|
|
|
|
|
Con_SafePrintf("8-bit GL extensions enabled.\n");
|
|
|
|
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-03-19 15:59:51 +00:00
|
|
|
void VID_Init8bitPalette(void)
|
1999-12-25 05:32:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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;
|
|
|
|
XSetWindowAttributes attr;
|
|
|
|
unsigned long mask;
|
|
|
|
Window root;
|
|
|
|
XVisualInfo *visinfo;
|
|
|
|
|
2000-02-27 07:13:32 +00:00
|
|
|
vid_mode = Cvar_Get ("vid_mode","0",0,"None");
|
|
|
|
gl_ztrick = Cvar_Get ("gl_ztrick","0",CVAR_ARCHIVE,"None");
|
2000-05-01 22:53:16 +00:00
|
|
|
vid_fullscreen = Cvar_Get ("vid_fullscreen","0",0,"None");
|
2000-02-27 07:13:32 +00:00
|
|
|
#ifdef HAS_DGA
|
|
|
|
vid_dga_mouseaccel = Cvar_Get("vid_dga_mouseaccel","1",CVAR_ARCHIVE,
|
|
|
|
"None");
|
2000-03-19 15:59:51 +00:00
|
|
|
#endif
|
1999-12-25 05:32:39 +00:00
|
|
|
vid.maxwarpwidth = WARP_WIDTH;
|
|
|
|
vid.maxwarpheight = WARP_HEIGHT;
|
|
|
|
vid.colormap = host_colormap;
|
|
|
|
vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
|
|
|
|
|
2000-01-19 01:55:15 +00:00
|
|
|
/* Interpret command-line params
|
|
|
|
*/
|
1999-12-25 05:32:39 +00:00
|
|
|
|
2000-01-19 01:55:15 +00:00
|
|
|
/* Set vid parameters */
|
1999-12-25 05:32:39 +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)
|
|
|
|
vid.conwidth = Q_atoi(com_argv[i+1]);
|
|
|
|
else
|
2000-01-15 04:09:22 +00:00
|
|
|
vid.conwidth = width;
|
1999-12-25 05:32:39 +00:00
|
|
|
|
|
|
|
vid.conwidth &= 0xfff8; // make it a multiple of eight
|
2000-02-19 20:54:58 +00:00
|
|
|
if (vid.conwidth < 320)
|
|
|
|
vid.conwidth = 320;
|
1999-12-25 05:32:39 +00:00
|
|
|
|
|
|
|
// pick a conheight that matches with correct aspect
|
2000-02-15 19:25:09 +00:00
|
|
|
vid.conheight = vid.conwidth * 3 / 4;
|
1999-12-25 05:32:39 +00:00
|
|
|
|
2000-02-15 19:25:09 +00:00
|
|
|
i = COM_CheckParm ("-conheight");
|
|
|
|
if ( i != 0 ) // Set console height, but no smaller than 200 px
|
2000-02-19 20:54:58 +00:00
|
|
|
vid.conheight = Q_atoi(com_argv[i+1]);
|
|
|
|
if (vid.conheight < 200)
|
|
|
|
vid.conheight = 200;
|
1999-12-25 05:32:39 +00:00
|
|
|
|
2000-03-14 10:25:46 +00:00
|
|
|
x11_open_display();
|
1999-12-25 05:32:39 +00:00
|
|
|
|
2000-02-19 08:24:15 +00:00
|
|
|
screen = DefaultScreen(x_disp);
|
|
|
|
root = RootWindow(x_disp, screen);
|
1999-12-25 05:32:39 +00:00
|
|
|
|
2000-02-19 08:24:15 +00:00
|
|
|
visinfo = glXChooseVisual(x_disp, screen, attrib);
|
1999-12-25 05:32:39 +00:00
|
|
|
if (!visinfo) {
|
2000-01-19 01:55:15 +00:00
|
|
|
fprintf(stderr, "Error couldn't get an RGB, Double-buffered, Depth visual\n");
|
1999-12-25 05:32:39 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2000-01-15 04:09:22 +00:00
|
|
|
|
2000-01-19 01:55:15 +00:00
|
|
|
#ifdef HAS_DGA
|
2000-01-15 04:09:22 +00:00
|
|
|
{
|
|
|
|
int maj_ver;
|
|
|
|
|
2000-02-19 08:24:15 +00:00
|
|
|
hasdga = VID_CheckDGA(x_disp, &maj_ver, NULL, &hasdgavideo);
|
2000-01-15 04:09:22 +00:00
|
|
|
if (!hasdga || maj_ver < 1) {
|
|
|
|
hasdga = hasdgavideo = 0;
|
|
|
|
}
|
|
|
|
}
|
2000-05-01 11:08:00 +00:00
|
|
|
Con_SafePrintf ("hasdga = %i\nhasdgavideo = %i\n", hasdga, hasdgavideo);
|
|
|
|
#endif
|
|
|
|
#ifdef HAS_VIDMODE
|
2000-02-19 08:24:15 +00:00
|
|
|
hasvidmode = VID_CheckVMode(x_disp, NULL, NULL);
|
2000-05-02 12:01:55 +00:00
|
|
|
if (hasvidmode) {
|
2000-02-19 08:24:15 +00:00
|
|
|
if (! XF86VidModeGetAllModeLines(x_disp, DefaultScreen(x_disp),
|
2000-01-15 04:09:22 +00:00
|
|
|
&nummodes, &vidmodes)
|
|
|
|
|| nummodes <= 0) {
|
|
|
|
hasvidmode = 0;
|
|
|
|
}
|
|
|
|
}
|
2000-05-01 11:08:00 +00:00
|
|
|
Con_SafePrintf ("hasvidmode = %i\nnummodes = %i\n", hasvidmode, nummodes);
|
2000-01-15 04:09:22 +00:00
|
|
|
#endif
|
2000-01-19 01:55:15 +00:00
|
|
|
#ifdef HAVE_DLOPEN
|
|
|
|
dlhand = dlopen(NULL, RTLD_LAZY);
|
|
|
|
if (dlhand) {
|
|
|
|
QF_XMesaSetFXmode = dlsym(dlhand, "XMesaSetFXmode");
|
|
|
|
if (!QF_XMesaSetFXmode) {
|
2000-02-19 08:24:15 +00:00
|
|
|
QF_XMesaSetFXmode = dlsym(dlhand, "_XMesaSetFXmode");
|
2000-01-19 01:55:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
QF_XMesaSetFXmode = NULL;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#ifdef XMESA
|
|
|
|
QF_XMesaSetFXmode = XMesaSetFXmode;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
if (QF_XMesaSetFXmode) {
|
|
|
|
#ifdef XMESA
|
|
|
|
const char *str = getenv("MESA_GLX_FX");
|
2000-04-16 14:26:53 +00:00
|
|
|
if (str != NULL && *str != 'd') {
|
2000-01-19 01:55:15 +00:00
|
|
|
if (tolower(*str) == 'w') {
|
2000-05-01 22:53:16 +00:00
|
|
|
Cvar_Set (vid_fullscreen, "0");
|
2000-01-19 01:55:15 +00:00
|
|
|
} else {
|
2000-05-01 22:53:16 +00:00
|
|
|
Cvar_Set (vid_fullscreen, "1");
|
2000-01-19 01:55:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* Glide uses DGA internally, so we don't want to
|
|
|
|
mess with it. */
|
2000-04-28 20:37:25 +00:00
|
|
|
// hasdga = 0;
|
2000-01-19 01:55:15 +00:00
|
|
|
}
|
|
|
|
|
1999-12-25 05:32:39 +00:00
|
|
|
/* window attributes */
|
|
|
|
attr.background_pixel = 0;
|
|
|
|
attr.border_pixel = 0;
|
2000-02-19 08:24:15 +00:00
|
|
|
attr.colormap = XCreateColormap(x_disp, root, visinfo->visual, AllocNone);
|
1999-12-25 05:32:39 +00:00
|
|
|
attr.event_mask = X_MASK;
|
|
|
|
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
|
|
|
|
|
2000-05-01 13:08:01 +00:00
|
|
|
#ifdef HAS_VIDMODE
|
2000-05-01 22:53:16 +00:00
|
|
|
if (hasvidmode && vid_fullscreen->value) {
|
2000-05-01 13:08:01 +00:00
|
|
|
int smallest_mode=0, x=MAXINT, y=MAXINT;
|
|
|
|
|
|
|
|
attr.override_redirect=1;
|
|
|
|
mask|=CWOverrideRedirect;
|
|
|
|
|
|
|
|
// FIXME: does this depend on mode line order in XF86Config?
|
|
|
|
for (i=0; i<nummodes; i++) {
|
|
|
|
if (x>vidmodes[i]->hdisplay || y>vidmodes[i]->vdisplay) {
|
|
|
|
smallest_mode=i;
|
|
|
|
x=vidmodes[i]->hdisplay;
|
|
|
|
y=vidmodes[i]->vdisplay;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// chose the smallest mode that our window fits into;
|
|
|
|
for (i=smallest_mode;
|
|
|
|
i!=(smallest_mode+1)%nummodes;
|
|
|
|
i=(i?i-1:nummodes-1)) {
|
|
|
|
if (vidmodes[i]->hdisplay>=width
|
|
|
|
&& vidmodes[i]->vdisplay>=height) {
|
|
|
|
XF86VidModeSwitchToMode (x_disp, DefaultScreen (x_disp),
|
|
|
|
vidmodes[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XF86VidModeSetViewPort(x_disp, DefaultScreen (x_disp), 0, 0);
|
|
|
|
in_grab = Cvar_Get ("in_grab","1",CVAR_ARCHIVE|CVAR_ROM,"None");
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
in_grab = Cvar_Get ("in_grab","0",CVAR_ARCHIVE,"None");
|
|
|
|
|
2000-02-19 08:24:15 +00:00
|
|
|
x_win = XCreateWindow(x_disp, root, 0, 0, width, height,
|
1999-12-25 05:32:39 +00:00
|
|
|
0, visinfo->depth, InputOutput,
|
|
|
|
visinfo->visual, mask, &attr);
|
2000-02-19 08:24:15 +00:00
|
|
|
XMapWindow(x_disp, x_win);
|
2000-05-01 13:08:01 +00:00
|
|
|
#ifdef HAS_VIDMODE
|
2000-05-02 12:03:44 +00:00
|
|
|
if (hasvidmode && vid_fullscreen->value) {
|
2000-05-01 13:08:01 +00:00
|
|
|
XRaiseWindow(x_disp, x_win);
|
|
|
|
XGrabKeyboard(x_disp, x_win, 1, GrabModeAsync, GrabModeAsync,
|
|
|
|
CurrentTime);
|
|
|
|
}
|
|
|
|
#endif
|
1999-12-25 05:32:39 +00:00
|
|
|
|
2000-02-19 08:24:15 +00:00
|
|
|
XSync(x_disp, 0);
|
1999-12-25 05:32:39 +00:00
|
|
|
|
2000-02-19 08:24:15 +00:00
|
|
|
ctx = glXCreateContext(x_disp, visinfo, NULL, True);
|
1999-12-25 05:32:39 +00:00
|
|
|
|
2000-02-19 08:24:15 +00:00
|
|
|
glXMakeCurrent(x_disp, x_win, ctx);
|
1999-12-25 05:32:39 +00:00
|
|
|
|
|
|
|
scr_width = width;
|
|
|
|
scr_height = height;
|
|
|
|
|
|
|
|
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);
|
|
|
|
vid.numpages = 2;
|
|
|
|
|
|
|
|
InitSig(); // trap evil signals
|
|
|
|
|
|
|
|
GL_Init();
|
|
|
|
|
2000-02-15 19:25:09 +00:00
|
|
|
snprintf(gldir, sizeof(gldir), "%s/glquake", com_gamedir);
|
1999-12-25 05:32:39 +00:00
|
|
|
Sys_mkdir (gldir);
|
|
|
|
|
|
|
|
VID_SetPalette(palette);
|
|
|
|
|
|
|
|
// Check for 3DFX Extensions and initialize them.
|
|
|
|
VID_Init8bitPalette();
|
|
|
|
|
2000-02-19 20:54:58 +00:00
|
|
|
Con_SafePrintf ("Video mode %dx%d initialized.\n",
|
|
|
|
width, height);
|
1999-12-25 05:32:39 +00:00
|
|
|
|
2000-04-17 14:49:32 +00:00
|
|
|
vid_initialized = true;
|
|
|
|
|
2000-01-15 04:09:22 +00:00
|
|
|
vid.recalc_refdef = 1; // force a surface cache flush
|
2000-01-09 01:11:44 +00:00
|
|
|
}
|
2000-02-28 19:13:16 +00:00
|
|
|
|
|
|
|
void VID_InitCvars()
|
|
|
|
{
|
|
|
|
gl_triplebuffer = Cvar_Get("gl_triplebuffer","1",CVAR_ARCHIVE,"None");
|
|
|
|
}
|
2000-03-31 23:58:53 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
VID_LockBuffer ( void )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_UnlockBuffer ( void )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|