port over newtree's vid system. works, but doesn't seem fully functional yet

This commit is contained in:
Bill Currie 2000-10-31 00:11:59 +00:00
parent b8e5b2807b
commit d428926cca
32 changed files with 2195 additions and 2610 deletions

View file

@ -42,7 +42,7 @@
#include "quakefs.h" #include "quakefs.h"
#include "qdefs.h" #include "qdefs.h"
typedef struct typedef struct usercmd_s
{ {
vec3_t viewangles; vec3_t viewangles;
@ -287,6 +287,7 @@ extern cvar_t *cl_sbar;
extern cvar_t *cl_hudswap; extern cvar_t *cl_hudswap;
extern cvar_t *cl_pitchdriftspeed; extern cvar_t *cl_pitchdriftspeed;
extern cvar_t *cl_freelook;
extern cvar_t *lookspring; extern cvar_t *lookspring;
extern cvar_t *lookstrafe; extern cvar_t *lookstrafe;
extern cvar_t *sensitivity; extern cvar_t *sensitivity;

View file

@ -31,32 +31,38 @@
#ifndef __CONTEXT_X11_H__ #ifndef __CONTEXT_X11_H__
#define __CONTEXT_X11_H__ #define __CONTEXT_X11_H__
#include <qtypes.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include "cvar.h"
#include "qtypes.h"
void GetEvent( void ); void GetEvent( void );
extern Display *x_disp; extern Display *x_disp;
extern int x_screen; extern int x_screen;
extern Window x_root; extern Window x_root;
extern XVisualInfo *x_visinfo; extern XVisualInfo *x_visinfo;
extern Visual *x_vis; extern Visual *x_vis;
extern Window x_win; extern Window x_win;
extern qboolean doShm; extern qboolean doShm;
extern int x_shmeventtype; extern int x_shmeventtype;
extern qboolean oktodraw; extern qboolean oktodraw;
extern cvar_t *vid_fullscreen;
qboolean x11_add_event( int event, void (*event_handler)(XEvent *)); qboolean x11_add_event (int event, void (*event_handler)(XEvent *));
qboolean x11_del_event( int event, void (*event_handler)(XEvent *)); qboolean x11_del_event (int event, void (*event_handler)(XEvent *));
void x11_process_event( void ); void x11_process_event (void);
void x11_process_events( void ); void x11_process_events (void);
void x11_open_display( void ); void x11_open_display (void);
void x11_close_display( void ); void x11_close_display (void);
void x11_create_null_cursor(void); void x11_create_null_cursor (void);
void x11_set_vidmode(int width, int height); void x11_set_vidmode (int, int);
void x11_restore_vidmode(void); void x11_restore_vidmode (void);
void x11_create_window(int width, int height); void x11_create_window (int, int);
void x11_grab_keyboard(void); void x11_grab_keyboard (void);
void x11_set_caption (char *);
void x11_force_view_port (void);
void x11_Init_Cvars (void);
#endif // __CONTEXT_X11_H__ #endif // __CONTEXT_X11_H__

View file

@ -3,9 +3,8 @@
Definitions for XFree86 DGA and VidMode support Definitions for XFree86 DGA and VidMode support
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se] Copyright (C) 2000 Jeff Teunissen <deek@dusknet.dhs.org>
Copyright (C) 2000 contributors of the QuakeForge project Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
Please see the file "AUTHORS" for a list of contributors
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
@ -28,21 +27,19 @@
$Id$ $Id$
*/ */
#ifndef __dga_check_h #ifndef __dga_check_h_
#define __dga_check_h #define __dga_check_h_
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include "cvar.h" #include "qtypes.h"
extern cvar_t *vid_dga_mouseaccel;
/* /*
VID_CheckDGA VID_CheckDGA
Check for the presence of the XFree86-DGA support in the X server Check for the presence of the XFree86-DGA support in the X server
*/ */
int VID_CheckDGA(Display *dpy, int *maj_ver, int *min_ver, int *hasvideo); qboolean VID_CheckDGA (Display *, int *, int *, int *);
/* /*
@ -50,6 +47,6 @@ int VID_CheckDGA(Display *dpy, int *maj_ver, int *min_ver, int *hasvideo);
Check for the presence of the XFree86-VMode X server extension Check for the presence of the XFree86-VMode X server extension
*/ */
int VID_CheckVMode(Display *dpy, int *maj_ver, int *min_ver); qboolean VID_CheckVMode (Display *, int *, int *);
#endif /* __dga_check_h */ #endif // __dga_check_h_

View file

@ -1,7 +1,7 @@
/* /*
input.h input.h
@description@ External (non-keyboard) input devices
Copyright (C) 1996-1997 Id Software, Inc. Copyright (C) 1996-1997 Id Software, Inc.
@ -26,30 +26,35 @@
$Id$ $Id$
*/ */
#ifndef __input_h #ifndef _INPUT_H
#define __input_h #define _INPUT_H
#include "client.h"
#include "cvar.h" #include "cvar.h"
#include "protocol.h"
#include "qtypes.h"
#define freelook (in_mlook.state&1 || cl_freelook->int_val)
void IN_Init (void); void IN_Init (void);
void IN_Init_Cvars (void);
void IN_Shutdown (void); void IN_Shutdown (void);
void IN_Commands (void); void IN_Commands (void);
// oportunity for devices to stick commands on the script buffer // oportunity for devices to stick commands on the script buffer
void IN_Move (usercmd_t *cmd); void IN_SendKeyEvents (void);
// Perform Key_Event () callbacks until the input que is empty
struct usercmd_s;
void IN_Move (struct usercmd_s *cmd);
// add additional movement on top of the keyboard move cmd // add additional movement on top of the keyboard move cmd
void IN_ClearStates (void); void IN_ModeChanged (void);
// restores all button and position states to defaults // called whenever screen dimensions change
void IN_SendKeyEvents (void); void IN_HandlePause (qboolean paused);
void IN_HandlePause (qboolean pause); extern cvar_t *_windowed_mouse;
extern cvar_t *_windowed_mouse; #endif // _INPUT_H
#endif // __input_h

View file

@ -71,6 +71,7 @@ void JOY_Move (usercmd_t *);
you have successfully enabled it. you have successfully enabled it.
*/ */
void JOY_Init (void); void JOY_Init (void);
void JOY_Init_Cvars (void);
/* /*
JOY_Shutdown () JOY_Shutdown ()

View file

@ -164,7 +164,8 @@ void R_PushDlights (vec3_t entorigin);
extern int reinit_surfcache; // if 1, surface cache is currently empty and extern int reinit_surfcache; // if 1, surface cache is currently empty and
extern qboolean r_cache_thrash; // set if thrashing the surface cache extern qboolean r_cache_thrash; // set if thrashing the surface cache
int D_SurfaceCacheForRes (int width, int height); void *D_SurfaceCacheAddress (void);
int D_SurfaceCacheForRes (int width, int height);
void D_FlushCaches (void); void D_FlushCaches (void);
void D_DeleteSurfaceCache (void); void D_DeleteSurfaceCache (void);
void D_InitCaches (void *buffer, int size); void D_InitCaches (void *buffer, int size);

View file

@ -1,7 +1,7 @@
/* /*
vid.h vid.h
@description@ video driver defs
Copyright (C) 1996-1997 Id Software, Inc. Copyright (C) 1996-1997 Id Software, Inc.
@ -26,83 +26,79 @@
$Id$ $Id$
*/ */
#ifndef __vid_h #ifndef __vid_h_
#define __vid_h #define __vid_h_
#include "qtypes.h" #include "qtypes.h"
#define VID_CBITS 6 #define VID_CBITS 6
#define VID_GRADES (1 << VID_CBITS) #define VID_GRADES (1 << VID_CBITS)
typedef struct vrect_s typedef struct vrect_s {
{
int x,y,width,height; int x,y,width,height;
struct vrect_s *pnext; struct vrect_s *pnext;
} vrect_t; } vrect_t;
typedef struct typedef struct {
{
pixel_t *buffer; // invisible buffer pixel_t *buffer; // invisible buffer
pixel_t *colormap; // 256 * VID_GRADES size pixel_t *colormap; // 256 * VID_GRADES size
unsigned short *colormap16; // 256 * VID_GRADES size unsigned short *colormap16; // 256 * VID_GRADES size
int fullbright; // index of first fullbright color int fullbright; // index of first fullbright color
unsigned rowbytes; // may be > width if displayed in a window unsigned int rowbytes; // may be > width if displayed in a window
unsigned width; unsigned int width;
unsigned height; unsigned int height;
float aspect; // width / height -- < 0 is taller than wide float aspect; // width / height -- < 0 is taller than wide
int numpages; int numpages;
int recalc_refdef; // if true, recalc vid-based stuff int recalc_refdef; // if true, recalc vid-based stuff
pixel_t *conbuffer; pixel_t *conbuffer;
int conrowbytes; int conrowbytes;
unsigned conwidth; unsigned int conwidth;
unsigned conheight; unsigned int conheight;
int maxwarpwidth; int maxwarpwidth;
int maxwarpheight; int maxwarpheight;
pixel_t *direct; // direct drawing to framebuffer, if not pixel_t *direct; // direct drawing to framebuffer, if not
// NULL // NULL
} viddef_t; } viddef_t;
extern viddef_t vid; // global video state extern viddef_t vid; // global video state
extern unsigned short d_8to16table[256]; extern unsigned short d_8to16table[256];
extern unsigned d_8to24table[256]; extern unsigned int d_8to24table[256];
extern void (*vid_menudrawfn)(void); extern int scr_width, scr_height;
extern void (*vid_menukeyfn)(int key);
qboolean VID_Is8bit(void);
void VID_SetPalette (unsigned char *palette);
// called at startup and after any gamma correction // called at startup and after any gamma correction
void VID_SetPalette (unsigned char *palette);
void VID_ShiftPalette (unsigned char *palette);
// called for bonus and pain flashes, and for underwater color changes // called for bonus and pain flashes, and for underwater color changes
void VID_ShiftPalette (unsigned char *palette);
void VID_Init_Cvars (void);
void VID_Init (unsigned char *palette);
void VID_InitCvars (void);
// Called at startup to set up translation tables, takes 256 8 bit RGB values // Called at startup to set up translation tables, takes 256 8 bit RGB values
// the palette data will go away after the call, so it must be copied off if // the palette data will go away after the call, so it must be copied off if
// the video driver will need it again // the video driver will need it again
void VID_Init (unsigned char *);
void VID_Shutdown (void);
// Called at shutdown // Called at shutdown
void VID_Shutdown (void);
void VID_Update (vrect_t *rects);
// flushes the given rectangles from the view buffer to the screen // flushes the given rectangles from the view buffer to the screen
void VID_Update (vrect_t *rects);
int VID_SetMode (int modenum, unsigned char *palette);
// sets the mode; only used by the Quake engine for resetting to mode 0 (the // sets the mode; only used by the Quake engine for resetting to mode 0 (the
// base mode) on memory allocation failures // base mode) on memory allocation failures
int VID_SetMode (int modenum, unsigned char *palette);
void VID_HandlePause (qboolean pause);
// called only on Win32, when pause happens, so the mouse can be released // called only on Win32, when pause happens, so the mouse can be released
void VID_HandlePause (qboolean pause);
void VID_LockBuffer (void);
void VID_UnlockBuffer (void);
qboolean VID_Is8bit (void);
void VID_SetCaption (char *text); void VID_SetCaption (char *text);
// used to set window caption
#if defined(_WIN32) && !defined(WINDED) void VID_GetWindowSize (int def_w, int def_h);
void VID_LockBuffer (void);
void VID_UnlockBuffer (void);
#else
#define VID_LockBuffer()
#define VID_UnlockBuffer()
#endif
#endif // __vid_h #endif // __vid_h_

View file

@ -132,7 +132,7 @@ client_LIBS= -L. -lqfsys -lqfsnd -lqfcd -lqfjs -lqfnet $(SOUND_LIBS) $(NET_LIBS)
client_SOURCES= cl_cam.c cl_demo.c cl_input.c cl_main.c cl_parse.c \ client_SOURCES= cl_cam.c cl_demo.c cl_input.c cl_main.c cl_parse.c \
cl_tent.c console.c keys.c menu.c sbar.c r_part.c r_view.c \ cl_tent.c console.c keys.c menu.c sbar.c r_part.c r_view.c \
nonintel.c gib.c gib_instructions.c gib_vars.c \ nonintel.c gib.c gib_instructions.c gib_vars.c \
gib_interpret.c gib_modules.c gib_parse.c gib_stack.c gib_interpret.c gib_modules.c gib_parse.c gib_stack.c vid.c
server_SOURCES= host.c host_cmd.c \ server_SOURCES= host.c host_cmd.c \
pr_cmds.c pr_edict.c pr_exec.c \ pr_cmds.c pr_edict.c pr_exec.c \
@ -174,7 +174,7 @@ nuq_mgl_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfjs.a libqfnet.a
# #
# ... Sam Lantinga's Simple DirectMedia Layer, version 1.0 and higher # ... Sam Lantinga's Simple DirectMedia Layer, version 1.0 and higher
# #
sdl_SOURCES= vid_sdl.c sdl_SOURCES= vid_sdl.c in_sdl.c
nuq_sdl_SOURCES= $(combined_SOURCES) $(soft_SOURCES) $(sdl_SOURCES) nuq_sdl_SOURCES= $(combined_SOURCES) $(soft_SOURCES) $(sdl_SOURCES)
nuq_sdl_LDADD= $(client_LIBS) $(SDL_LIBS) nuq_sdl_LDADD= $(client_LIBS) $(SDL_LIBS)
@ -221,7 +221,7 @@ nuq_3dfx_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfjs.a libqfnet.a
# #
# ... OpenGL in X Window # ... OpenGL in X Window
# #
glx_SOURCES= vid_glx.c $(x11_SOURCES) glx_SOURCES= vid_glx.c vid_common_gl.c $(x11_SOURCES)
nuq_glx_SOURCES= $(combined_SOURCES) $(ogl_SOURCES) $(glx_SOURCES) nuq_glx_SOURCES= $(combined_SOURCES) $(ogl_SOURCES) $(glx_SOURCES)
nuq_glx_LDADD= $(client_LIBS) $(GLX_LIBS) $(X_PRE_LIBS) $(VIDMODE_LIBS) $(DGA_LIBS) $(X_LIBS) -lX11 $(X_EXTRA_LIBS) $(DL_LIBS) nuq_glx_LDADD= $(client_LIBS) $(GLX_LIBS) $(X_PRE_LIBS) $(VIDMODE_LIBS) $(DGA_LIBS) $(X_LIBS) -lX11 $(X_EXTRA_LIBS) $(DL_LIBS)
@ -230,10 +230,10 @@ nuq_glx_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfjs.a libqfnet.a
# #
# ... Sam Lantinga's Simple DirectMedia Layer, version 1.1 and higher, in GL mode # ... Sam Lantinga's Simple DirectMedia Layer, version 1.1 and higher, in GL mode
# #
sgl_SOURCES= vid_sgl.c sgl_SOURCES= vid_sgl.c vid_common_gl.c in_sdl.c
nuq_sgl_SOURCES= $(combined_SOURCES) $(ogl_SOURCES) $(sgl_SOURCES) nuq_sgl_SOURCES= $(combined_SOURCES) $(ogl_SOURCES) $(sgl_SOURCES)
nuq_sgl_LDADD= $(client_LIBS) $(SDL_LIBS) $(GLX_LIBS) $(DL_LIBS) nuq_sgl_LDADD= $(client_LIBS) $(X_LIBS) $(SDL_LIBS) $(GLX_LIBS) $(DL_LIBS)
nuq_sgl_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfjs.a libqfnet.a nuq_sgl_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfjs.a libqfnet.a
# #

View file

@ -55,6 +55,7 @@ cvar_t *cl_nolerp;
cvar_t *cl_sbar; cvar_t *cl_sbar;
cvar_t *cl_hudswap; cvar_t *cl_hudswap;
cvar_t *cl_freelook;
cvar_t *lookspring; cvar_t *lookspring;
cvar_t *lookstrafe; cvar_t *lookstrafe;
cvar_t *sensitivity; cvar_t *sensitivity;
@ -101,6 +102,7 @@ CL_InitCvars(void)
cl_sbar = Cvar_Get ("cl_sbar", "1", CVAR_ARCHIVE, "Use old status bar"); cl_sbar = Cvar_Get ("cl_sbar", "1", CVAR_ARCHIVE, "Use old status bar");
cl_hudswap = Cvar_Get ("cl_hudswap", "0", CVAR_ARCHIVE, "HUD on left side?"); cl_hudswap = Cvar_Get ("cl_hudswap", "0", CVAR_ARCHIVE, "HUD on left side?");
cl_freelook = Cvar_Get("freelook", "0", CVAR_ARCHIVE, "force +mlook");
lookspring = Cvar_Get("lookspring", "0", CVAR_ARCHIVE, "None"); lookspring = Cvar_Get("lookspring", "0", CVAR_ARCHIVE, "None");
lookstrafe = Cvar_Get("lookstrafe", "0", CVAR_ARCHIVE, "None"); lookstrafe = Cvar_Get("lookstrafe", "0", CVAR_ARCHIVE, "None");
sensitivity = Cvar_Get("sensitivity", "3", CVAR_ARCHIVE, "None"); sensitivity = Cvar_Get("sensitivity", "3", CVAR_ARCHIVE, "None");

View file

@ -49,7 +49,8 @@
#include <X11/keysym.h> #include <X11/keysym.h>
#include <X11/extensions/XShm.h> #include <X11/extensions/XShm.h>
#include <errno.h> #include <errno.h>
#include <values.h> #include <limits.h>
#include <sys/poll.h>
#ifdef HAVE_VIDMODE #ifdef HAVE_VIDMODE
# include <X11/extensions/xf86vmode.h> # include <X11/extensions/xf86vmode.h>
@ -57,6 +58,8 @@
#include "context_x11.h" #include "context_x11.h"
#include "dga_check.h" #include "dga_check.h"
#include "va.h"
#include "qargs.h"
#include "qtypes.h" #include "qtypes.h"
#include "vid.h" #include "vid.h"
#include "sys.h" #include "sys.h"
@ -83,8 +86,9 @@ static Atom aWMDelete = 0;
#ifdef HAVE_VIDMODE #ifdef HAVE_VIDMODE
static XF86VidModeModeInfo **vidmodes; static XF86VidModeModeInfo **vidmodes;
static int nummodes, hasvidmode = 0; static int nummodes;
#endif #endif
static int hasvidmode = 0;
cvar_t *vid_fullscreen; cvar_t *vid_fullscreen;
@ -94,7 +98,7 @@ static int xss_blanking;
static int xss_exposures; static int xss_exposures;
qboolean qboolean
x11_add_event(int event, void (*event_handler)(XEvent *)) x11_add_event (int event, void (*event_handler) (XEvent *))
{ {
if (event >= LASTEvent) { if (event >= LASTEvent) {
printf("event: %d, LASTEvent: %d\n", event, LASTEvent); printf("event: %d, LASTEvent: %d\n", event, LASTEvent);
@ -108,7 +112,7 @@ x11_add_event(int event, void (*event_handler)(XEvent *))
} }
qboolean qboolean
x11_del_event(int event, void (*event_handler)(XEvent *)) x11_del_event (int event, void (*event_handler) (XEvent *))
{ {
if (event >= LASTEvent) if (event >= LASTEvent)
return false; return false;
@ -120,7 +124,7 @@ x11_del_event(int event, void (*event_handler)(XEvent *))
} }
void void
x11_process_event( void ) x11_process_event (void)
{ {
XEvent x_event; XEvent x_event;
@ -132,15 +136,15 @@ x11_process_event( void )
return; return;
} }
if (event_handlers[x_event.type]) if (event_handlers[x_event.type])
event_handlers[x_event.type](&x_event); event_handlers[x_event.type] (&x_event);
} }
void void
x11_process_events(void) x11_process_events (void)
{ {
/* Get events from X server. */ /* Get events from X server. */
while ( XPending( x_disp )) { while (XPending (x_disp)) {
x11_process_event(); x11_process_event ();
} }
} }
@ -149,18 +153,18 @@ x11_process_events(void)
// ======================================================================== // ========================================================================
static void static void
TragicDeath(int sig) TragicDeath (int sig)
{ {
printf("Received signal %d, exiting...\n", sig); printf ("Received signal %d, exiting...\n", sig);
Sys_Quit(); Sys_Quit ();
exit(sig); exit (sig);
//XCloseDisplay(x_disp); //XCloseDisplay(x_disp);
//VID_Shutdown(); //VID_Shutdown();
//Sys_Error("This death brought to you by the number %d\n", signal_num); //Sys_Error("This death brought to you by the number %d\n", signal_num);
} }
void void
x11_open_display( void ) x11_open_display (void)
{ {
if ( !x_disp ) { if ( !x_disp ) {
x_disp = XOpenDisplay( NULL ); x_disp = XOpenDisplay( NULL );
@ -193,7 +197,7 @@ x11_open_display( void )
} }
void void
x11_close_display( void ) x11_close_display (void)
{ {
if (nullcursor != None) { if (nullcursor != None) {
XFreeCursor(x_disp, nullcursor); XFreeCursor(x_disp, nullcursor);
@ -201,7 +205,7 @@ x11_close_display( void )
} }
if (!--x_disp_ref_count) { if (!--x_disp_ref_count) {
XCloseDisplay( x_disp ); XCloseDisplay( x_disp );
x_disp = NULL; x_disp = 0;
} }
} }
@ -211,7 +215,7 @@ x11_close_display( void )
Create an empty cursor Create an empty cursor
*/ */
void void
x11_create_null_cursor(void) x11_create_null_cursor (void)
{ {
Pixmap cursormask; Pixmap cursormask;
XGCValues xgc; XGCValues xgc;
@ -237,11 +241,8 @@ x11_create_null_cursor(void)
void void
x11_set_vidmode(int width, int height) x11_set_vidmode(int width, int height)
{ {
#ifdef HAVE_VIDMODE
int i; int i;
#endif int best_mode = 0, best_x = INT_MAX, best_y = INT_MAX;
vid_fullscreen = Cvar_Get ("vid_fullscreen","0",0,"None");
XGetScreenSaver (x_disp, &xss_timeout, &xss_interval, &xss_blanking, XGetScreenSaver (x_disp, &xss_timeout, &xss_interval, &xss_blanking,
&xss_exposures); &xss_exposures);
@ -260,51 +261,47 @@ x11_set_vidmode(int width, int height)
#endif #endif
#ifdef HAVE_VIDMODE #ifdef HAVE_VIDMODE
hasvidmode = VID_CheckVMode(x_disp, NULL, NULL); if (!(hasvidmode = VID_CheckVMode(x_disp, NULL, NULL))) {
if (hasvidmode) { Cvar_Set (vid_fullscreen, "0");
if (! XF86VidModeGetAllModeLines(x_disp, DefaultScreen(x_disp), return;
&nummodes, &vidmodes)
|| nummodes <= 0) {
hasvidmode = 0;
}
} }
Con_SafePrintf ("hasvidmode = %i\nnummodes = %i\n", hasvidmode, nummodes);
if (hasvidmode && vid_fullscreen->int_val) { XF86VidModeGetAllModeLines(x_disp, x_screen, &nummodes, &vidmodes);
int smallest_mode=0, x=MAXINT, y=MAXINT;
// FIXME: does this depend on mode line order in XF86Config? if (vid_fullscreen->int_val) {
for (i=0; i<nummodes; i++) { for (i = 0; i < nummodes; i++) {
if (x>vidmodes[i]->hdisplay || y>vidmodes[i]->vdisplay) { if ((best_x > vidmodes[i]->hdisplay) ||
smallest_mode=i; (best_y > vidmodes[i]->vdisplay)) {
x=vidmodes[i]->hdisplay; if ((vidmodes[i]->hdisplay >= width) &&
y=vidmodes[i]->vdisplay; (vidmodes[i]->vdisplay >= height)) {
best_mode = i;
best_x = vidmodes[i]->hdisplay;
best_y = vidmodes[i]->vdisplay;
}
} }
printf("%dx%d\n",vidmodes[i]->hdisplay,vidmodes[i]->vdisplay); printf("%dx%d\n", vidmodes[i]->hdisplay, vidmodes[i]->vdisplay);
} }
// chose the smallest mode that our window fits into; XF86VidModeSwitchToMode (x_disp, x_screen, vidmodes[best_mode]);
for (i=smallest_mode; x11_force_view_port ();
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);
_windowed_mouse = Cvar_Get ("_windowed_mouse","1",CVAR_ARCHIVE|CVAR_ROM,"None");
} else
#endif #endif
_windowed_mouse = Cvar_Get ("_windowed_mouse","0",CVAR_ARCHIVE,"None");
} }
void void
x11_create_window(int width, int height) x11_Init_Cvars ()
{
vid_fullscreen = Cvar_Get ("vid_fullscreen", "0", CVAR_ARCHIVE,
"Toggles fullscreen game mode");
}
void
x11_create_window (int width, int height)
{ {
XSetWindowAttributes attr; XSetWindowAttributes attr;
unsigned long mask; XClassHint *ClassHint;
XSizeHints *SizeHints;
char *resname;
unsigned long mask;
/* window attributes */ /* window attributes */
attr.background_pixel = 0; attr.background_pixel = 0;
@ -313,35 +310,69 @@ x11_create_window(int width, int height)
attr.event_mask = X_MASK; attr.event_mask = X_MASK;
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
#ifdef HAVE_VIDMODE
if (hasvidmode && vid_fullscreen->int_val) { if (hasvidmode && vid_fullscreen->int_val) {
attr.override_redirect=1; attr.override_redirect=1;
mask|=CWOverrideRedirect; mask|=CWOverrideRedirect;
} }
#endif
x_win = XCreateWindow(x_disp, x_root, 0, 0, width, height,
0, x_visinfo->depth, InputOutput,
x_vis, mask, &attr);
/* Give it a title */
XStoreName(x_disp, x_win, "XQuake");
/* Make window respond to Delete events */ x_win = XCreateWindow (x_disp, x_root, 0, 0, width, height,
aWMDelete = XInternAtom(x_disp, "WM_DELETE_WINDOW", False); 0, x_visinfo->depth, InputOutput,
XSetWMProtocols(x_disp, x_win, &aWMDelete, 1); x_vis, mask, &attr);
XMapWindow(x_disp, x_win); // Set window size hints
XRaiseWindow(x_disp, x_win); SizeHints = XAllocSizeHints ();
if (SizeHints) {
SizeHints->flags = (PMinSize | PMaxSize);
SizeHints->min_width = width;
SizeHints->min_height = height;
SizeHints->max_width = width;
SizeHints->max_height = height;
XSetWMNormalHints (x_disp, x_win, SizeHints);
XFree (SizeHints);
}
// Set window title
x11_set_caption (va ("%s %s", PROGRAM, VERSION));
// Set icon name
XSetIconName (x_disp, x_win, PROGRAM);
// Set window class
ClassHint = XAllocClassHint ();
if (ClassHint) {
resname = strrchr (com_argv[0], '/');
ClassHint->res_name = (resname ? resname + 1 : resname);
ClassHint->res_class = PROGRAM;
XSetClassHint (x_disp, x_win, ClassHint);
XFree (ClassHint);
}
// Make window respond to Delete events
aWMDelete = XInternAtom (x_disp, "WM_DELETE_WINDOW", False);
XSetWMProtocols (x_disp, x_win, &aWMDelete, 1);
if (vid_fullscreen->int_val) {
XMoveWindow (x_disp, x_win, 0, 0);
XWarpPointer(x_disp, None, x_win, 0, 0, 0, 0,
vid.width+2, vid.height+2);
x11_force_view_port ();
}
XMapWindow (x_disp, x_win);
XRaiseWindow (x_disp, x_win);
} }
void void
x11_restore_vidmode(void) x11_restore_vidmode (void)
{ {
XSetScreenSaver (x_disp, xss_timeout, xss_interval, xss_blanking, XSetScreenSaver (x_disp, xss_timeout, xss_interval, xss_blanking,
xss_exposures); xss_exposures);
#ifdef HAVE_VIDMODE #ifdef HAVE_VIDMODE
if (hasvidmode) { if (hasvidmode) {
XF86VidModeSwitchToMode (x_disp, DefaultScreen (x_disp), XF86VidModeSwitchToMode (x_disp, x_screen,
vidmodes[0]); vidmodes[0]);
XFree(vidmodes); XFree(vidmodes);
} }
@ -349,7 +380,7 @@ x11_restore_vidmode(void)
} }
void void
x11_grab_keyboard(void) x11_grab_keyboard (void)
{ {
#ifdef HAVE_VIDMODE #ifdef HAVE_VIDMODE
if (hasvidmode && vid_fullscreen->int_val) { if (hasvidmode && vid_fullscreen->int_val) {
@ -358,3 +389,26 @@ x11_grab_keyboard(void)
} }
#endif #endif
} }
void
x11_set_caption (char *text)
{
if (x_disp && x_win && text)
XStoreName (x_disp, x_win, text);
}
void
x11_force_view_port (void)
{
#ifdef HAVE_VIDMODE
int x, y;
if (vid_fullscreen->int_val) {
do {
XF86VidModeSetViewPort (x_disp, x_screen, 0, 0);
poll (0, 0, 50);
XF86VidModeGetViewPort (x_disp, x_screen, &x, &y);
} while (x || y);
}
#endif
}

View file

@ -50,6 +50,12 @@ surfcache_t *sc_rover, *sc_base;
#define GUARDSIZE 4 #define GUARDSIZE 4
void *
D_SurfaceCacheAddress (void)
{
return sc_base;
}
int D_SurfaceCacheForRes (int width, int height) int D_SurfaceCacheForRes (int width, int height)
{ {

View file

@ -29,21 +29,20 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" #include "config.h"
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#if defined(HAVE_DGA) #ifdef HAVE_DGA
#include <X11/extensions/xf86dga.h> #include <X11/extensions/xf86dga.h>
#endif #endif
#if defined(HAVE_VIDMODE) #ifdef HAVE_VIDMODE
#include <X11/extensions/xf86vmode.h> #include <X11/extensions/xf86vmode.h>
#endif #endif
#include <dga_check.h> #include "dga_check.h"
/* /*
@ -51,31 +50,34 @@
Check for the presence of the XFree86-DGA X server extension Check for the presence of the XFree86-DGA X server extension
*/ */
int qboolean
VID_CheckDGA(Display *dpy, int *maj_ver, int *min_ver, int *hasvideo) VID_CheckDGA (Display *dpy, int *maj_ver, int *min_ver, int *hasvideo)
{ {
#if defined(HAVE_DGA) #ifdef HAVE_DGA
int event_base, error_base, dgafeat, dummy; int event_base, error_base, dgafeat, dummy;
if (! XF86DGAQueryExtension(dpy, &event_base, &error_base)) { if (!XF86DGAQueryExtension (dpy, &event_base, &error_base)) {
return 0; return false;
} }
if (maj_ver == NULL) maj_ver = &dummy; if (!maj_ver) maj_ver = &dummy;
if (min_ver == NULL) min_ver = &dummy; if (!min_ver) min_ver = &dummy;
if (! XF86DGAQueryVersion(dpy, maj_ver, min_ver)) { if (!XF86DGAQueryVersion (dpy, maj_ver, min_ver)) {
return 0; return false;
} }
if (! XF86DGAQueryDirectVideo(dpy, DefaultScreen(dpy), &dgafeat)) {
if (!hasvideo) hasvideo = &dummy;
if (!XF86DGAQueryDirectVideo (dpy, DefaultScreen (dpy), &dgafeat)) {
*hasvideo = 0; *hasvideo = 0;
} else { } else {
*hasvideo = (dgafeat & XF86DGADirectPresent); *hasvideo = (dgafeat & XF86DGADirectPresent);
} }
return 1; return true;
#else #else
return 0; return false;
#endif // HAVE_DGA #endif // HAVE_DGA
} }
@ -85,26 +87,26 @@ VID_CheckDGA(Display *dpy, int *maj_ver, int *min_ver, int *hasvideo)
Check for the presence of the XFree86-VidMode X server extension Check for the presence of the XFree86-VidMode X server extension
*/ */
int qboolean
VID_CheckVMode(Display *dpy, int *maj_ver, int *min_ver) VID_CheckVMode (Display *dpy, int *maj_ver, int *min_ver)
{ {
#if defined(HAVE_VIDMODE) #if defined(HAVE_VIDMODE)
int event_base, error_base; int event_base, error_base;
int dummy; int dummy;
if (! XF86VidModeQueryExtension(dpy, &event_base, &error_base)) { if (! XF86VidModeQueryExtension(dpy, &event_base, &error_base)) {
return 0; return false;
} }
if (maj_ver == NULL) maj_ver = &dummy; if (maj_ver == NULL) maj_ver = &dummy;
if (min_ver == NULL) min_ver = &dummy; if (min_ver == NULL) min_ver = &dummy;
if (! XF86VidModeQueryVersion(dpy, maj_ver, min_ver)) { if (! XF86VidModeQueryVersion(dpy, maj_ver, min_ver)) {
return 0; return false;
} }
return 1; return true;
#else #else
return 0; return false;
#endif // HAVE_VIDMODE #endif // HAVE_VIDMODE
} }

View file

@ -905,12 +905,15 @@ void Host_Init (quakeparms_t *parms)
Cmd_Exec_File (fs_globalcfg->string); Cmd_Exec_File (fs_globalcfg->string);
Cbuf_Execute_Sets (); Cbuf_Execute_Sets ();
IN_Init_Cvars();
VID_Init_Cvars ();
Cmd_StuffCmds_f (); Cmd_StuffCmds_f ();
Cbuf_Execute_Sets (); Cbuf_Execute_Sets ();
V_Init (); V_Init ();
SCR_InitCvars (); SCR_InitCvars ();
VID_InitCvars (); VID_Init_Cvars ();
COM_Init (); COM_Init ();
// reparse the command line for + commands other than set // reparse the command line for + commands other than set

View file

@ -1,7 +1,7 @@
/* /*
in_null.c in_null.c
@description@ for systems without a mouse
Copyright (C) 1996-1997 Id Software, Inc. Copyright (C) 1996-1997 Id Software, Inc.
@ -27,14 +27,18 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include <config.h>
#endif #endif
#include "quakedef.h"
void IN_Init (void) void IN_Init (void)
{ {
} }
void IN_Init_Cvars (void)
{
}
void IN_Shutdown (void) void IN_Shutdown (void)
{ {
} }
@ -47,6 +51,16 @@ void IN_Move (usercmd_t *cmd)
{ {
} }
void IN_HandlePause (qboolean pause) /*
===========
IN_ModeChanged
===========
*/
void IN_ModeChanged (void)
{
}
void
IN_HandlePause (qboolean paused)
{ {
} }

340
source/in_sdl.c Normal file
View file

@ -0,0 +1,340 @@
/*
in_sdl.c
general sdl input driver
Copyright (C) 1996-1997 Id Software, Inc.
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
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <SDL.h>
#include "client.h"
#include "compat.h"
#include "console.h"
#include "cvar.h"
#include "draw.h"
#include "host.h"
#include "input.h"
#include "joystick.h"
#include "keys.h"
#include "menu.h"
#include "sys.h"
#include "qargs.h"
#include "qendian.h"
#include "vid.h"
#include "view.h"
#ifdef WIN32
// fixme: this is evil...
#include <windows.h>
HWND mainwindow;
#endif
cvar_t *_windowed_mouse;
int old_windowed_mouse;
int modestate; // fixme: just to avoid cross-comp. errors - remove later
static qboolean mouse_avail;
static float mouse_x, mouse_y;
static int mouse_oldbuttonstate = 0;
extern viddef_t vid; // global video state
/*
================
IN_SendKeyEvents
================
*/
void
IN_SendKeyEvents (void)
{
SDL_Event event;
int sym, state, but;
int modstate;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
case SDL_KEYUP:
sym = event.key.keysym.sym;
state = event.key.state;
modstate = SDL_GetModState();
switch(sym) {
case SDLK_DELETE: sym = K_DEL; break;
case SDLK_BACKSPACE: sym = K_BACKSPACE; break;
case SDLK_F1: sym = K_F1; break;
case SDLK_F2: sym = K_F2; break;
case SDLK_F3: sym = K_F3; break;
case SDLK_F4: sym = K_F4; break;
case SDLK_F5: sym = K_F5; break;
case SDLK_F6: sym = K_F6; break;
case SDLK_F7: sym = K_F7; break;
case SDLK_F8: sym = K_F8; break;
case SDLK_F9: sym = K_F9; break;
case SDLK_F10: sym = K_F10; break;
case SDLK_F11: sym = K_F11; break;
case SDLK_F12: sym = K_F12; break;
case SDLK_BREAK:
case SDLK_PAUSE: sym = K_PAUSE; break;
case SDLK_UP: sym = K_UPARROW; break;
case SDLK_DOWN: sym = K_DOWNARROW; break;
case SDLK_RIGHT: sym = K_RIGHTARROW; break;
case SDLK_LEFT: sym = K_LEFTARROW; break;
case SDLK_INSERT: sym = K_INS; break;
case SDLK_HOME: sym = K_HOME; break;
case SDLK_END: sym = K_END; break;
case SDLK_PAGEUP: sym = K_PGUP; break;
case SDLK_PAGEDOWN: sym = K_PGDN; break;
case SDLK_RSHIFT:
case SDLK_LSHIFT: sym = K_SHIFT; break;
case SDLK_RCTRL:
case SDLK_LCTRL: sym = K_CTRL; break;
case SDLK_RALT:
case SDLK_LALT: sym = K_ALT; break;
case SDLK_CAPSLOCK: sym = K_CAPSLOCK; break;
case SDLK_KP0:
if(modstate & KMOD_NUM) sym = K_INS;
else sym = SDLK_0;
break;
case SDLK_KP1:
if(modstate & KMOD_NUM) sym = K_END;
else sym = SDLK_1;
break;
case SDLK_KP2:
if(modstate & KMOD_NUM) sym = K_DOWNARROW;
else sym = SDLK_2;
break;
case SDLK_KP3:
if(modstate & KMOD_NUM) sym = K_PGDN;
else sym = SDLK_3;
break;
case SDLK_KP4:
if(modstate & KMOD_NUM) sym = K_LEFTARROW;
else sym = SDLK_4;
break;
case SDLK_KP5: sym = SDLK_5; break;
case SDLK_KP6:
if(modstate & KMOD_NUM) sym = K_RIGHTARROW;
else sym = SDLK_6;
break;
case SDLK_KP7:
if(modstate & KMOD_NUM) sym = K_HOME;
else sym = SDLK_7;
break;
case SDLK_KP8:
if(modstate & KMOD_NUM) sym = K_UPARROW;
else sym = SDLK_8;
break;
case SDLK_KP9:
if(modstate & KMOD_NUM) sym = K_PGUP;
else sym = SDLK_9;
break;
case SDLK_KP_PERIOD:
if(modstate & KMOD_NUM) sym = K_DEL;
else sym = SDLK_PERIOD;
break;
case SDLK_KP_DIVIDE: sym = SDLK_SLASH; break;
case SDLK_KP_MULTIPLY: sym = SDLK_ASTERISK; break;
case SDLK_KP_MINUS: sym = SDLK_MINUS; break;
case SDLK_KP_PLUS: sym = SDLK_PLUS; break;
case SDLK_KP_ENTER: sym = SDLK_RETURN; break;
case SDLK_KP_EQUALS: sym = SDLK_EQUALS; break;
}
// If we're not directly handled and still above 255
// just force it to 0
if(sym > 255) sym = 0;
Key_Event(sym, state);
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
but = event.button.button;
if (but == 2)
but = 3;
else if (but == 3)
but = 2;
switch (but) {
case 1:
case 2:
case 3:
Key_Event(K_MOUSE1 + but - 1, event.type
== SDL_MOUSEBUTTONDOWN);
break;
case 4:
Key_Event(K_MWHEELUP, 1);
Key_Event(K_MWHEELUP, 0);
break;
case 5:
Key_Event(K_MWHEELDOWN, 1);
Key_Event(K_MWHEELDOWN, 0);
break;
}
break;
case SDL_MOUSEMOTION:
if (_windowed_mouse->value) {
if ((event.motion.x != (vid.width/2))
|| (event.motion.y != (vid.height/2)) ) {
// *2 for vid_sdl.c, *10 for vid_sgl.c.
mouse_x = event.motion.xrel*2;
mouse_y = event.motion.yrel*2;
if ((event.motion.x < ((vid.width/2)-(vid.width/4))) ||
(event.motion.x > ((vid.width/2)+(vid.width/4))) ||
(event.motion.y < ((vid.height/2)-(vid.height/4))) ||
(event.motion.y > ((vid.height/2)+(vid.height/4))) )
SDL_WarpMouse(vid.width/2, vid.height/2);
}
} else {
// following are *2 in vid_sdl.c, vid_sgl.c is *10
mouse_x = event.motion.xrel*10;
mouse_y = event.motion.yrel*10;
}
break;
case SDL_QUIT:
CL_Disconnect ();
Sys_Quit ();
break;
default:
break;
}
}
}
void
IN_Commands (void)
{
JOY_Command ();
if (old_windowed_mouse != _windowed_mouse->value) {
old_windowed_mouse = _windowed_mouse->value;
if (!_windowed_mouse->value) {
// SDL_ShowCursor (0);
SDL_WM_GrabInput (SDL_GRAB_OFF);
} else {
SDL_WM_GrabInput (SDL_GRAB_ON);
// SDL_ShowCursor (1);
}
}
}
void
IN_Init (void)
{
JOY_Init ();
if ( COM_CheckParm("-nomouse") && !_windowed_mouse->value)
return;
mouse_x = mouse_y = 0.0;
mouse_avail = 1;
// SDL_ShowCursor (0);
// SDL_WM_GrabInput (SDL_GRAB_ON);
// FIXME: disable DGA if in_dgamouse says to.
}
void
IN_Init_Cvars (void)
{
JOY_Init_Cvars ();
_windowed_mouse = Cvar_Get ("_windowed_mouse","0",CVAR_ARCHIVE,"None");
// m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, "None");
}
void
IN_Shutdown (void)
{
mouse_avail = 0;
}
void IN_Frame(void)
{
int i;
int mouse_buttonstate;
if (!mouse_avail) return;
i = SDL_GetMouseState(NULL, NULL);
/* Quake swaps the second and third buttons */
mouse_buttonstate = (i & ~0x06) | ((i & 0x02)<<1) | ((i & 0x04)>>1);
for (i=0 ; i<3 ; i++) {
if ( (mouse_buttonstate & (1<<i)) && !(mouse_oldbuttonstate & (1<<i)) )
Key_Event (K_MOUSE1 + i, true);
if ( !(mouse_buttonstate & (1<<i)) && (mouse_oldbuttonstate & (1<<i)) )
Key_Event (K_MOUSE1 + i, false);
}
mouse_oldbuttonstate = mouse_buttonstate;
}
void
IN_Move (usercmd_t *cmd)
{
JOY_Move (cmd);
if (!mouse_avail)
return;
/* from vid_sdl.c
if (m_filter->value) {
mouse_x = (mouse_x + old_mouse_x) * 0.5;
mouse_y = (mouse_y + old_mouse_y) * 0.5;
}
old_mouse_x = mouse_x;
old_mouse_y = mouse_y;
*/
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
if ( (in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1) ))
cmd->sidemove += m_side->value * mouse_x;
else
cl.viewangles[YAW] -= m_yaw->value * mouse_x;
if (freelook)
V_StopPitchDrift ();
if ( freelook && !(in_strafe.state & 1)) {
cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH] + (m_pitch->value * mouse_y), 80);
} else {
if ((in_strafe.state & 1) && noclip_anglehack)
cmd->upmove -= m_forward->value * mouse_y;
else
cmd->forwardmove -= m_forward->value * mouse_y;
}
mouse_x = mouse_y = 0.0;
}
void
IN_HandlePause (qboolean paused)
{
}

View file

@ -30,20 +30,9 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" #include "config.h"
#endif #endif
#include "qtypes.h"
#include "keys.h"
#include "client.h"
#include "sys.h"
#include "console.h"
#include "cvar.h"
#include "cmd.h"
#include "host.h"
#include "qargs.h"
#include "joystick.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
@ -54,6 +43,19 @@
#include <vgakeyboard.h> #include <vgakeyboard.h>
#include <vgamouse.h> #include <vgamouse.h>
#include "client.h"
#include "cmd.h"
#include "compat.h"
#include "console.h"
#include "cvar.h"
#include "host.h"
#include "input.h"
#include "joystick.h"
#include "keys.h"
#include "qargs.h"
#include "qtypes.h"
#include "sys.h"
#include "view.h"
static int UseKeyboard = 1; static int UseKeyboard = 1;
static int UseMouse = 1; static int UseMouse = 1;
@ -72,7 +74,6 @@ static void IN_init_mouse();
cvar_t *_windowed_mouse; cvar_t *_windowed_mouse;
cvar_t *m_filter; cvar_t *m_filter;
static cvar_t *mouse_button_commands[3];
static void keyhandler(int scancode, int state) static void keyhandler(int scancode, int state)
{ {
@ -107,7 +108,8 @@ void Force_CenterView_f(void)
} }
int IN_Init(void) void
IN_Init (void)
{ {
if (COM_CheckParm("-nokbd")) UseKeyboard = 0; if (COM_CheckParm("-nokbd")) UseKeyboard = 0;
if (COM_CheckParm("-nomouse")) UseMouse = 0; if (COM_CheckParm("-nomouse")) UseMouse = 0;
@ -120,10 +122,18 @@ int IN_Init(void)
JOY_Init(); JOY_Init();
in_svgalib_inited = 1; in_svgalib_inited = 1;
return 1; return;
} }
static void IN_init_kb() void
IN_Init_Cvars (void)
{
JOY_Init_Cvars();
m_filter = Cvar_Get ("m_filter","0",0,"None");
}
static void
IN_init_kb (void)
{ {
int i; int i;
@ -237,22 +247,19 @@ static void IN_init_kb()
scantokey[111] = K_DEL; scantokey[111] = K_DEL;
scantokey[119] = K_PAUSE; scantokey[119] = K_PAUSE;
if (keyboard_init()) { if (keyboard_init ()) {
Sys_Error("keyboard_init() failed"); Sys_Error ("keyboard_init() failed");
} }
keyboard_seteventhandler(keyhandler); keyboard_seteventhandler(keyhandler);
} }
static void IN_init_mouse() static void
IN_init_mouse()
{ {
int mtype; int mtype;
char *mousedev; char *mousedev;
int mouserate = MOUSE_DEFAULTSAMPLERATE; int mouserate = MOUSE_DEFAULTSAMPLERATE;
mouse_button_commands[0] = Cvar_Get ("mouse1","+attack",0,"None");
mouse_button_commands[1] = Cvar_Get ("mouse2","+strafe",0,"None");
mouse_button_commands[2] = Cvar_Get ("mouse2","+forward",0,"None");
m_filter = Cvar_Get ("m_filter","0",0,"None");
Cmd_AddCommand("force_centerview", Force_CenterView_f); Cmd_AddCommand("force_centerview", Force_CenterView_f);
mouse_buttons = 3; mouse_buttons = 3;
@ -363,23 +370,18 @@ void IN_Move(usercmd_t *cmd)
mouse_y *= sensitivity->value; mouse_y *= sensitivity->value;
/* Add mouse X/Y movement to cmd */ /* Add mouse X/Y movement to cmd */
if ( (in_strafe.state & 1) || if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook)) {
(lookstrafe->int_val && (in_mlook.state & 1) )) {
cmd->sidemove += m_side->value * mouse_x; cmd->sidemove += m_side->value * mouse_x;
} else { } else {
cl.viewangles[YAW] -= m_yaw->value * mouse_x; cl.viewangles[YAW] -= m_yaw->value * mouse_x;
} }
if ((in_mlook.state & 1)) V_StopPitchDrift(); if (freelook)
V_StopPitchDrift();
if ((in_mlook.state & 1) && !(in_strafe.state & 1)) { if (freelook && !(in_strafe.state & 1)) {
cl.viewangles[PITCH] += m_pitch->value * mouse_y; cl.viewangles[PITCH] += m_pitch->value * mouse_y;
if (cl.viewangles[PITCH] > 80) { cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
cl.viewangles[PITCH] = 80;
}
if (cl.viewangles[PITCH] < -70) {
cl.viewangles[PITCH] = -70;
}
} else { } else {
if ((in_strafe.state & 1) && noclip_anglehack) { if ((in_strafe.state & 1) && noclip_anglehack) {
cmd->upmove -= m_forward->value * mouse_y; cmd->upmove -= m_forward->value * mouse_y;
@ -389,6 +391,7 @@ void IN_Move(usercmd_t *cmd)
} }
} }
void IN_HandlePause (qboolean pause) void
IN_HandlePause (qboolean paused)
{ {
} }

View file

@ -1,7 +1,7 @@
/* /*
in_win.c in_win.c
@description@ windows 95 mouse and joystick code
Copyright (C) 1996-1997 Id Software, Inc. Copyright (C) 1996-1997 Id Software, Inc.
@ -26,13 +26,24 @@
$Id$ $Id$
*/ */
#ifdef HAVE_CONFIG_H // 02/21/97 JCB Added extended DirectInput code to support external controllers.
# include "config.h"
#endif
#include <dinput.h> #ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef __MINGW32__
# define INITGUID
#endif
#include "quakedef.h"
#include "winquake.h" #include "winquake.h"
#include "dosisms.h" #include <dinput.h>
#include "client.h"
#include "keys.h"
#include "console.h"
#include "qargs.h"
#include "cmd.h"
#include "input.h"
//#include "dosisms.h"
#define DINPUT_BUFFERSIZE 16 #define DINPUT_BUFFERSIZE 16
#define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d) #define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
@ -40,31 +51,33 @@
HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion, HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion,
LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter); LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
// mouse variables // mouse public variables
cvar_t *m_filter;
int mouse_buttons; float mouse_x, mouse_y;
int mouse_oldbuttonstate; qboolean mouseactive;
POINT current_pos; unsigned int uiWheelMessage;
int mouse_x, mouse_y, old_mouse_x, old_mouse_y, mx_accum, my_accum;
static qboolean restore_spi; // mouse local variables
static int originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
unsigned int uiWheelMessage; static int mouse_buttons;
qboolean mouseactive; static int mouse_oldbuttonstate;
qboolean mouseinitialized; static POINT current_pos;
static qboolean mouseparmsvalid, mouseactivatetoggle; static float old_mouse_x, old_mouse_y, mx_accum, my_accum;
static qboolean mouseshowtoggle = 1; static qboolean mouseinitialized;
static qboolean dinput_acquired; static cvar_t *m_filter;
static qboolean restore_spi;
static unsigned int mstate_di; static int originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
static qboolean mouseparmsvalid, mouseactivatetoggle;
static qboolean mouseshowtoggle = 1;
static qboolean dinput_acquired;
static unsigned int mstate_di;
// joystick defines and variables // joystick defines and variables
// where should defines be moved? // where should defines be moved?
#define JOY_ABSOLUTE_AXIS 0x00000000 // control like a joystick #define JOY_ABSOLUTE_AXIS 0x00000000 // control like a joystick
#define JOY_RELATIVE_AXIS 0x00000010 // control like a mouse, spinner, trackball #define JOY_RELATIVE_AXIS 0x00000010 // control like a mouse, spinner, trackball
#define JOY_MAX_AXES 6 // X, Y, Z, R, U, V #define JOY_MAX_AXES 6 // X, Y, Z, R, U, V
#define JOY_AXIS_X 0 #define JOY_AXIS_X 0
#define JOY_AXIS_Y 1 #define JOY_AXIS_Y 1
#define JOY_AXIS_Z 2 #define JOY_AXIS_Z 2
@ -77,46 +90,47 @@ enum _ControlList
AxisNada = 0, AxisForward, AxisLook, AxisSide, AxisTurn AxisNada = 0, AxisForward, AxisLook, AxisSide, AxisTurn
}; };
DWORD dwAxisFlags[JOY_MAX_AXES] = static DWORD dwAxisFlags[JOY_MAX_AXES] =
{ {
JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, JOY_RETURNR, JOY_RETURNU, JOY_RETURNV JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
}; };
DWORD dwAxisMap[JOY_MAX_AXES]; static DWORD dwAxisMap[JOY_MAX_AXES];
DWORD dwControlMap[JOY_MAX_AXES]; static DWORD dwControlMap[JOY_MAX_AXES];
PDWORD pdwRawValue[JOY_MAX_AXES]; static PDWORD pdwRawValue[JOY_MAX_AXES];
// none of these cvars are saved over a session // none of these cvars are saved over a session
// this means that advanced controller configuration needs to be executed // this means that advanced controller configuration needs to be executed
// each time. this avoids any problems with getting back to a default usage // each time. this avoids any problems with getting back to a default usage
// or when changing from one controller to another. this way at least something // or when changing from one controller to another. this way at least something
// works. // works.
cvar_t *in_joystick; static cvar_t *in_joystick;
cvar_t *joy_name; static cvar_t *joy_name;
cvar_t *joy_advanced; static cvar_t *joy_advanced;
cvar_t *joy_advaxisx; static cvar_t *joy_advaxisx;
cvar_t *joy_advaxisy; static cvar_t *joy_advaxisy;
cvar_t *joy_advaxisz; static cvar_t *joy_advaxisz;
cvar_t *joy_advaxisr; static cvar_t *joy_advaxisr;
cvar_t *joy_advaxisu; static cvar_t *joy_advaxisu;
cvar_t *joy_advaxisv; static cvar_t *joy_advaxisv;
cvar_t *joy_forwardthreshold; static cvar_t *joy_forwardthreshold;
cvar_t *joy_sidethreshold; static cvar_t *joy_sidethreshold;
cvar_t *joy_pitchthreshold; static cvar_t *joy_pitchthreshold;
cvar_t *joy_yawthreshold; static cvar_t *joy_yawthreshold;
cvar_t *joy_forwardsensitivity; static cvar_t *joy_forwardsensitivity;
cvar_t *joy_sidesensitivity; static cvar_t *joy_sidesensitivity;
cvar_t *joy_pitchsensitivity; static cvar_t *joy_pitchsensitivity;
cvar_t *joy_yawsensitivity; static cvar_t *joy_yawsensitivity;
cvar_t *joy_wwhack1; static cvar_t *joy_wwhack1;
cvar_t *joy_wwhack2; static cvar_t *joy_wwhack2;
qboolean joy_avail, joy_advancedinit, joy_haspov; static qboolean joy_avail, joy_advancedinit, joy_haspov;
DWORD joy_oldbuttonstate, joy_oldpovstate; static DWORD joy_oldbuttonstate, joy_oldpovstate;
static int joy_id;
static DWORD joy_flags;
static DWORD joy_numbuttons;
int joy_id; // misc locals
DWORD joy_flags;
DWORD joy_numbuttons;
static LPDIRECTINPUT g_pdi; static LPDIRECTINPUT g_pdi;
static LPDIRECTINPUTDEVICE g_pMouse; static LPDIRECTINPUTDEVICE g_pMouse;
@ -158,18 +172,17 @@ static DIDATAFORMAT df = {
rgodf, // and here they are rgodf, // and here they are
}; };
// forward-referenced functions // forward-referenced functions, locals
void IN_StartupJoystick (void); static void IN_StartupJoystick (void);
void Joy_AdvancedUpdate_f (void); static void Joy_AdvancedUpdate_f (void);
void IN_JoyMove (usercmd_t *cmd); static void IN_JoyMove (usercmd_t *cmd);
/* /*
=========== ===========
Force_CenterView_f Force_CenterView_f
=========== ===========
*/ */
void Force_CenterView_f (void) static void Force_CenterView_f (void)
{ {
cl.viewangles[PITCH] = 0; cl.viewangles[PITCH] = 0;
} }
@ -301,12 +314,12 @@ void IN_DeactivateMouse (void)
} }
else else
{ {
if (restore_spi) if (restore_spi)
SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0); SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
ClipCursor (NULL); ClipCursor (NULL);
ReleaseCapture (); ReleaseCapture ();
} }
mouseactive = false; mouseactive = false;
} }
@ -338,7 +351,7 @@ void IN_RestoreOriginalMouseState (void)
IN_InitDInput IN_InitDInput
=========== ===========
*/ */
qboolean IN_InitDInput (void) static qboolean IN_InitDInput (void)
{ {
HRESULT hr; HRESULT hr;
DIPROPDWORD dipdw = { DIPROPDWORD dipdw = {
@ -357,7 +370,7 @@ qboolean IN_InitDInput (void)
if (hInstDI == NULL) if (hInstDI == NULL)
{ {
Con_SafePrintf ("Couldn't load dinput.dll\n"); Con_Printf ("Couldn't load dinput.dll\n");
return false; return false;
} }
} }
@ -368,7 +381,7 @@ qboolean IN_InitDInput (void)
if (!pDirectInputCreate) if (!pDirectInputCreate)
{ {
Con_SafePrintf ("Couldn't get DI proc addr\n"); Con_Printf ("Couldn't get DI proc addr\n");
return false; return false;
} }
} }
@ -386,7 +399,7 @@ qboolean IN_InitDInput (void)
if (FAILED(hr)) if (FAILED(hr))
{ {
Con_SafePrintf ("Couldn't open DI mouse device\n"); Con_Printf ("Couldn't open DI mouse device\n");
return false; return false;
} }
@ -395,7 +408,7 @@ qboolean IN_InitDInput (void)
if (FAILED(hr)) if (FAILED(hr))
{ {
Con_SafePrintf ("Couldn't set DI mouse format\n"); Con_Printf ("Couldn't set DI mouse format\n");
return false; return false;
} }
@ -405,7 +418,7 @@ qboolean IN_InitDInput (void)
if (FAILED(hr)) if (FAILED(hr))
{ {
Con_SafePrintf ("Couldn't set DI coop level\n"); Con_Printf ("Couldn't set DI coop level\n");
return false; return false;
} }
@ -416,7 +429,7 @@ qboolean IN_InitDInput (void)
if (FAILED(hr)) if (FAILED(hr))
{ {
Con_SafePrintf ("Couldn't set DI buffersize\n"); Con_Printf ("Couldn't set DI buffersize\n");
return false; return false;
} }
@ -429,9 +442,9 @@ qboolean IN_InitDInput (void)
IN_StartupMouse IN_StartupMouse
=========== ===========
*/ */
void IN_StartupMouse (void) static void IN_StartupMouse (void)
{ {
HDC hdc; // HDC hdc;
if ( COM_CheckParm ("-nomouse") ) if ( COM_CheckParm ("-nomouse") )
return; return;
@ -444,11 +457,11 @@ void IN_StartupMouse (void)
if (dinput) if (dinput)
{ {
Con_SafePrintf ("DirectInput initialized\n"); Con_Printf ("DirectInput initialized\n");
} }
else else
{ {
Con_SafePrintf ("DirectInput not initialized\n"); Con_Printf ("DirectInput not initialized\n");
} }
} }
@ -492,30 +505,6 @@ IN_Init
*/ */
void IN_Init (void) void IN_Init (void)
{ {
// mouse variables
m_filter = Cvar_Get("m_filter", "0", CVAR_ARCHIVE, "None");
// joystick variables
in_joystick = Cvar_Get("joystick", "0", CVAR_ARCHIVE, "None");
joy_name = Cvar_Get("joyname", "joystick", CVAR_NONE, "None");
joy_advanced = Cvar_Get("joyadvanced", "0", CVAR_NONE, "None");
joy_advaxisx = Cvar_Get("joyadvaxisx", "0", CVAR_NONE, "None");
joy_advaxisy = Cvar_Get("joyadvaxisy", "0", CVAR_NONE, "None");
joy_advaxisz = Cvar_Get("joyadvaxisz", "0", CVAR_NONE, "None");
joy_advaxisr = Cvar_Get("joyadvaxisr", "0", CVAR_NONE, "None");
joy_advaxisu = Cvar_Get("joyadvaxisu", "0", CVAR_NONE, "None");
joy_advaxisv = Cvar_Get("joyadvaxisv", "0", CVAR_NONE, "None");
joy_forwardthreshold = Cvar_Get("joyforwardthreshold", "0.15", CVAR_NONE, "None");
joy_sidethreshold = Cvar_Get("joysidethreshold", "0.15", CVAR_NONE, "None");
joy_pitchthreshold = Cvar_Get("joypitchthreshold", "0.15", CVAR_NONE, "None");
joy_yawthreshold = Cvar_Get("joyyawthreshold", "0.15", CVAR_NONE, "None");
joy_forwardsensitivity = Cvar_Get("joyforwardsensitivity", "-1.0", CVAR_NONE, "None");
joy_sidesensitivity = Cvar_Get("joysidesensitivity", "-1.0", CVAR_NONE, "None");
joy_pitchsensitivity = Cvar_Get("joypitchsensitivity", "1.0", CVAR_NONE, "None");
joy_yawsensitivity = Cvar_Get("joyyawsensitivity", "-1.0", CVAR_NONE, "None");
joy_wwhack1 = Cvar_Get("joywwhack1", "0.0", CVAR_NONE, "None");
joy_wwhack2 = Cvar_Get("joywwhack2", "0.0", CVAR_NONE, "None");
Cmd_AddCommand ("force_centerview", Force_CenterView_f); Cmd_AddCommand ("force_centerview", Force_CenterView_f);
Cmd_AddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f); Cmd_AddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f);
@ -525,6 +514,33 @@ void IN_Init (void)
IN_StartupJoystick (); IN_StartupJoystick ();
} }
void IN_Init_Cvars (void)
{
// mouse variables
m_filter = Cvar_Get("m_filter", "0", CVAR_NONE, "None");
// joystick variables
in_joystick = Cvar_Get("joystick", "0", CVAR_ARCHIVE, "None");
joy_name = Cvar_Get("joyname", "joystick", CVAR_NONE, "None");
joy_advanced = Cvar_Get("joyadvanced", "0", CVAR_NONE, "None");
joy_advaxisx = Cvar_Get("joyadvaxisx", "0", CVAR_NONE, "None");
joy_advaxisy = Cvar_Get("joyadvaxisy", "0", CVAR_NONE, "None");
joy_advaxisz = Cvar_Get("joyadvaxisz", "0", CVAR_NONE, "None");
joy_advaxisr = Cvar_Get("joyadvaxisr", "0", CVAR_NONE, "None");
joy_advaxisu = Cvar_Get("joyadvaxisu", "0", CVAR_NONE, "None");
joy_advaxisv = Cvar_Get("joyadvaxisv", "0", CVAR_NONE, "None");
joy_forwardthreshold = Cvar_Get("joyforwardthreshold", "0.15", CVAR_NONE, "None");
joy_sidethreshold = Cvar_Get("joysidethreshold", "0.15", CVAR_NONE, "None");
joy_pitchthreshold = Cvar_Get("joypitchthreshold", "0.15", CVAR_NONE, "None");
joy_yawthreshold = Cvar_Get("joyyawthreshold", "0.15", CVAR_NONE, "None");
joy_forwardsensitivity = Cvar_Get("joyforwardsensitivity", "-1.0", CVAR_NONE, "None");
joy_sidesensitivity = Cvar_Get("joysidesensitivity", "-1.0", CVAR_NONE, "None");
joy_pitchsensitivity = Cvar_Get("joypitchsensitivity", "1.0", CVAR_NONE, "None");
joy_yawsensitivity = Cvar_Get("joyyawsensitivity", "-1.0", CVAR_NONE, "None");
joy_wwhack1 = Cvar_Get("joywwhack1", "0.0", CVAR_NONE, "None");
joy_wwhack2 = Cvar_Get("joywwhack2", "0.0", CVAR_NONE, "None");
}
/* /*
=========== ===========
IN_Shutdown IN_Shutdown
@ -557,7 +573,7 @@ IN_MouseEvent
*/ */
void IN_MouseEvent (int mstate) void IN_MouseEvent (int mstate)
{ {
int i; int i;
if (mouseactive && !dinput) if (mouseactive && !dinput)
{ {
@ -573,7 +589,7 @@ void IN_MouseEvent (int mstate)
if ( !(mstate & (1<<i)) && if ( !(mstate & (1<<i)) &&
(mouse_oldbuttonstate & (1<<i)) ) (mouse_oldbuttonstate & (1<<i)) )
{ {
Key_Event (K_MOUSE1 + i, false); Key_Event (K_MOUSE1 + i, false);
} }
} }
@ -589,8 +605,8 @@ IN_MouseMove
*/ */
void IN_MouseMove (usercmd_t *cmd) void IN_MouseMove (usercmd_t *cmd)
{ {
int mx, my; int mx, my;
HDC hdc; // HDC hdc;
int i; int i;
DIDEVICEOBJECTDATA od; DIDEVICEOBJECTDATA od;
DWORD dwElements; DWORD dwElements;
@ -680,16 +696,13 @@ void IN_MouseMove (usercmd_t *cmd)
else else
{ {
GetCursorPos (&current_pos); GetCursorPos (&current_pos);
mx = current_pos.x - window_center_x + mx_accum; mx = current_pos.x - window_center_x + mx_accum;
my = current_pos.y - window_center_y + my_accum; my = current_pos.y - window_center_y + my_accum;
mx_accum = 0; mx_accum = 0;
my_accum = 0; my_accum = 0;
} }
//if (mx || my) if (m_filter->value)
// Con_DPrintf("mx=%d, my=%d\n", mx, my);
if (m_filter->int_val)
{ {
mouse_x = (mx + old_mouse_x) * 0.5; mouse_x = (mx + old_mouse_x) * 0.5;
mouse_y = (my + old_mouse_y) * 0.5; mouse_y = (my + old_mouse_y) * 0.5;
@ -707,24 +720,18 @@ void IN_MouseMove (usercmd_t *cmd)
mouse_y *= sensitivity->value; mouse_y *= sensitivity->value;
// add mouse X/Y movement to cmd // add mouse X/Y movement to cmd
if ( (in_strafe.state & 1) || (lookstrafe->int_val && (in_mlook.state & 1) )) if ( (in_strafe.state & 1) || (lookstrafe->int_val && freelook))
cmd->sidemove += m_side->value * mouse_x; cmd->sidemove += m_side->value * mouse_x;
else else
cl.viewangles[YAW] -= m_yaw->value * mouse_x; cl.viewangles[YAW] -= m_yaw->value * mouse_x;
if (in_mlook.state & 1) if (freelook)
V_StopPitchDrift (); V_StopPitchDrift ();
if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) if ( freelook && !(in_strafe.state & 1)) {
{
cl.viewangles[PITCH] += m_pitch->value * mouse_y; cl.viewangles[PITCH] += m_pitch->value * mouse_y;
if (cl.viewangles[PITCH] > 80) cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
cl.viewangles[PITCH] = 80; } else {
if (cl.viewangles[PITCH] < -70)
cl.viewangles[PITCH] = -70;
}
else
{
if ((in_strafe.state & 1) && noclip_anglehack) if ((in_strafe.state & 1) && noclip_anglehack)
cmd->upmove -= m_forward->value * mouse_y; cmd->upmove -= m_forward->value * mouse_y;
else else
@ -762,21 +769,18 @@ IN_Accumulate
*/ */
void IN_Accumulate (void) void IN_Accumulate (void)
{ {
int mx, my; // int mx, my;
HDC hdc; // HDC hdc;
if (mouseactive) if (mouseactive)
{ {
if (!dinput) GetCursorPos (&current_pos);
{
GetCursorPos (&current_pos);
mx_accum += current_pos.x - window_center_x; mx_accum += current_pos.x - window_center_x;
my_accum += current_pos.y - window_center_y; my_accum += current_pos.y - window_center_y;
// force the mouse to the center, so there's room to move // force the mouse to the center, so there's room to move
SetCursorPos (window_center_x, window_center_y); SetCursorPos (window_center_x, window_center_y);
}
} }
} }
@ -803,11 +807,11 @@ void IN_ClearStates (void)
IN_StartupJoystick IN_StartupJoystick
=============== ===============
*/ */
void IN_StartupJoystick (void) static void IN_StartupJoystick (void)
{ {
int i, numdevs; int /*i,*/ numdevs;
JOYCAPS jc; JOYCAPS jc;
MMRESULT mmr; MMRESULT mmr = !JOYERR_NOERROR;
// assume no joystick // assume no joystick
joy_avail = false; joy_avail = false;
@ -872,7 +876,7 @@ void IN_StartupJoystick (void)
RawValuePointer RawValuePointer
=========== ===========
*/ */
PDWORD RawValuePointer (int axis) static PDWORD RawValuePointer (int axis)
{ {
switch (axis) switch (axis)
{ {
@ -889,15 +893,15 @@ PDWORD RawValuePointer (int axis)
case JOY_AXIS_V: case JOY_AXIS_V:
return &ji.dwVpos; return &ji.dwVpos;
} }
return NULL;
} }
/* /*
=========== ===========
Joy_AdvancedUpdate_f Joy_AdvancedUpdate_f
=========== ===========
*/ */
void Joy_AdvancedUpdate_f (void) static void Joy_AdvancedUpdate_f (void)
{ {
// called once by IN_ReadJoystick and by user whenever an update is needed // called once by IN_ReadJoystick and by user whenever an update is needed
@ -913,7 +917,7 @@ void Joy_AdvancedUpdate_f (void)
pdwRawValue[i] = RawValuePointer(i); pdwRawValue[i] = RawValuePointer(i);
} }
if( joy_advanced->int_val == 0.0) if( joy_advanced->int_val)
{ {
// default joystick initialization // default joystick initialization
// 2 axes only with joystick control // 2 axes only with joystick control
@ -924,7 +928,7 @@ void Joy_AdvancedUpdate_f (void)
} }
else else
{ {
if (Q_strcmp (joy_name->string, "joystick") != 0) if (strcmp (joy_name->string, "joystick") != 0)
{ {
// notify user of advanced controller // notify user of advanced controller
Con_Printf ("\n%s configured\n\n", joy_name->string); Con_Printf ("\n%s configured\n\n", joy_name->string);
@ -1039,7 +1043,7 @@ void IN_Commands (void)
IN_ReadJoystick IN_ReadJoystick
=============== ===============
*/ */
qboolean IN_ReadJoystick (void) static qboolean IN_ReadJoystick (void)
{ {
memset (&ji, 0, sizeof(ji)); memset (&ji, 0, sizeof(ji));
@ -1060,7 +1064,7 @@ qboolean IN_ReadJoystick (void)
else else
{ {
// read error occurred // read error occurred
// turning off the joystick seems too harsh for 1 read error,\ // turning off the joystick seems too harsh for 1 read error,
// but what should be done? // but what should be done?
// Con_Printf ("IN_ReadJoystick: no response\n"); // Con_Printf ("IN_ReadJoystick: no response\n");
// joy_avail = false; // joy_avail = false;
@ -1074,7 +1078,7 @@ qboolean IN_ReadJoystick (void)
IN_JoyMove IN_JoyMove
=========== ===========
*/ */
void IN_JoyMove (usercmd_t *cmd) static void IN_JoyMove (usercmd_t *cmd)
{ {
float speed, aspeed; float speed, aspeed;
float fAxisValue, fTemp; float fAxisValue, fTemp;
@ -1136,7 +1140,7 @@ void IN_JoyMove (usercmd_t *cmd)
switch (dwAxisMap[i]) switch (dwAxisMap[i])
{ {
case AxisForward: case AxisForward:
if ((!joy_advanced->int_val) && (in_mlook.state & 1)) if (!joy_advanced->int_val && freelook)
{ {
// user wants forward control to become look control // user wants forward control to become look control
if (fabs(fAxisValue) > joy_pitchthreshold->value) if (fabs(fAxisValue) > joy_pitchthreshold->value)
@ -1159,7 +1163,7 @@ void IN_JoyMove (usercmd_t *cmd)
// disable pitch return-to-center unless requested by user // disable pitch return-to-center unless requested by user
// *** this code can be removed when the lookspring bug is fixed // *** this code can be removed when the lookspring bug is fixed
// *** the bug always has the lookspring feature on // *** the bug always has the lookspring feature on
if(lookspring->int_val) if (!lookspring->int_val)
V_StopPitchDrift(); V_StopPitchDrift();
} }
} }
@ -1181,7 +1185,7 @@ void IN_JoyMove (usercmd_t *cmd)
break; break;
case AxisTurn: case AxisTurn:
if ((in_strafe.state & 1) || (lookstrafe->int_val && (in_mlook.state & 1))) if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook))
{ {
// user wants turn control to become side control // user wants turn control to become side control
if (fabs(fAxisValue) > joy_sidethreshold->value) if (fabs(fAxisValue) > joy_sidethreshold->value)
@ -1208,7 +1212,7 @@ void IN_JoyMove (usercmd_t *cmd)
break; break;
case AxisLook: case AxisLook:
if (in_mlook.state & 1) if (freelook)
{ {
if (fabs(fAxisValue) > joy_pitchthreshold->value) if (fabs(fAxisValue) > joy_pitchthreshold->value)
{ {
@ -1229,7 +1233,7 @@ void IN_JoyMove (usercmd_t *cmd)
// disable pitch return-to-center unless requested by user // disable pitch return-to-center unless requested by user
// *** this code can be removed when the lookspring bug is fixed // *** this code can be removed when the lookspring bug is fixed
// *** the bug always has the lookspring feature on // *** the bug always has the lookspring feature on
if(lookspring->int_val) if (!lookspring->int_val)
V_StopPitchDrift(); V_StopPitchDrift();
} }
} }
@ -1247,6 +1251,7 @@ void IN_JoyMove (usercmd_t *cmd)
cl.viewangles[PITCH] = -70.0; cl.viewangles[PITCH] = -70.0;
} }
void IN_HandlePause (qboolean pause) void
IN_HandlePause (qboolean paused)
{ {
} }

View file

@ -35,11 +35,18 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <string.h>
#include <errno.h> #include <errno.h>
#include <string.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/keysym.h> #include <X11/keysym.h>
@ -48,6 +55,7 @@
#include <X11/extensions/xf86dga.h> #include <X11/extensions/xf86dga.h>
#endif #endif
#include "dga_check.h"
#include "d_local.h" #include "d_local.h"
#include "sound.h" #include "sound.h"
#include "keys.h" #include "keys.h"
@ -59,34 +67,31 @@
#include "console.h" #include "console.h"
#include "client.h" #include "client.h"
#include "context_x11.h" #include "context_x11.h"
#include "qargs.h"
#include "host.h" #include "host.h"
#include "input.h"
#include "joystick.h" #include "joystick.h"
#include "qargs.h"
#include "view.h"
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
cvar_t *_windowed_mouse; cvar_t *_windowed_mouse;
cvar_t *m_filter; cvar_t *m_filter;
cvar_t *in_dgamouse;
#ifdef HAVE_DGA cvar_t *in_dga;
cvar_t *in_dga_mouseaccel; cvar_t *in_dga_mouseaccel;
cvar_t *in_nodga_grab;
#endif static qboolean dga_avail;
static qboolean dga_active;
static qboolean mouse_avail; static qboolean mouse_avail;
static float mouse_x, mouse_y; static float mouse_x, mouse_y;
static float old_mouse_x, old_mouse_y; static float old_mouse_x, old_mouse_y;
static int p_mouse_x, p_mouse_y; static int p_mouse_x, p_mouse_y;
static float old__windowed_mouse;
#define KEY_MASK (KeyPressMask | KeyReleaseMask) #define KEY_MASK (KeyPressMask | KeyReleaseMask)
#define MOUSE_MASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask) #define MOUSE_MASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
#define INPUT_MASK (KEY_MASK | MOUSE_MASK) #define INPUT_MASK (KEY_MASK | MOUSE_MASK)
static int static int
XLateKey(XKeyEvent *ev) XLateKey(XKeyEvent *ev)
{ {
@ -161,7 +166,7 @@ XLateKey(XKeyEvent *ev)
case XK_Meta_R: key = K_ALT; break; case XK_Meta_R: key = K_ALT; break;
case XK_Caps_Lock: key = K_CAPSLOCK; break; case XK_Caps_Lock: key = K_CAPSLOCK; break;
case XK_KP_Begin: key = K_AUX30; break; case XK_KP_Begin: key = KP_5; break;
case XK_Insert: key = K_INS; break; case XK_Insert: key = K_INS; break;
case XK_KP_Insert: key = KP_INS; break; case XK_KP_Insert: key = KP_INS; break;
@ -215,14 +220,14 @@ XLateKey(XKeyEvent *ev)
static void static void
event_key(XEvent *event) event_key (XEvent *event)
{ {
Key_Event(XLateKey(&event->xkey), event->type == KeyPress); Key_Event (XLateKey (&event->xkey), event->type == KeyPress);
} }
static void static void
event_button(XEvent *event) event_button (XEvent *event)
{ {
int but; int but;
@ -264,28 +269,22 @@ center_pointer(void)
static void static void
event_motion(XEvent *event) event_motion (XEvent *event)
{ {
#ifdef HAVE_DGA if (dga_active) {
if (in_dgamouse->int_val) {
mouse_x += event->xmotion.x_root * in_dga_mouseaccel->value; mouse_x += event->xmotion.x_root * in_dga_mouseaccel->value;
mouse_y += event->xmotion.y_root * in_dga_mouseaccel->value; mouse_y += event->xmotion.y_root * in_dga_mouseaccel->value;
} else } else {
#endif if (!p_mouse_x && !p_mouse_y) {
{ Con_Printf("event->xmotion.x: %d\n", event->xmotion.x);
//printf("_windowed_mouse: %s\n", _windowed_mouse->int_val); Con_Printf("event->xmotion.y: %d\n", event->xmotion.y);
//printf("CurrentTime: %ld\n", CurrentTime); }
if (_windowed_mouse->int_val) { if (vid_fullscreen->int_val || _windowed_mouse->int_val) {
if (!event->xmotion.send_event) { if (!event->xmotion.send_event) {
mouse_x += (event->xmotion.x - p_mouse_x); mouse_x += (event->xmotion.x - p_mouse_x);
mouse_y += (event->xmotion.y - p_mouse_y); mouse_y += (event->xmotion.y - p_mouse_y);
#undef ABS if (abs(vid.width/2 - event->xmotion.x) > vid.width / 4
#define ABS(a) (((int)(a) < 0) ? -(a) : (a)) || abs(vid.height/2 - event->xmotion.y) > vid.height / 4) {
if (ABS(vid.width/2 - event->xmotion.x)
> vid.width / 4
|| ABS(vid.height/2 - event->xmotion.y)
> vid.height / 4) {
#undef ABS
center_pointer(); center_pointer();
} }
} }
@ -302,19 +301,34 @@ event_motion(XEvent *event)
void void
IN_Commands (void) IN_Commands (void)
{ {
JOY_Command (); static int old_windowed_mouse;
if (old__windowed_mouse != _windowed_mouse->int_val) { static int old_in_dga;
old__windowed_mouse = _windowed_mouse->int_val;
if (!_windowed_mouse->int_val) { JOY_Command ();
/* ungrab the pointer */
XUngrabPointer(x_disp,CurrentTime); if ((old_windowed_mouse != _windowed_mouse->int_val)
} else { || (old_in_dga != in_dga->int_val)) {
/* grab the pointer */ old_windowed_mouse = _windowed_mouse->int_val;
XGrabPointer(x_disp, x_win, True, MOUSE_MASK, GrabModeAsync, old_in_dga = in_dga->int_val;
GrabModeAsync, x_win, None, CurrentTime);
//XGrabPointer(x_disp,x_win,True,0,GrabModeAsync, if (_windowed_mouse->int_val) { // grab the pointer
// GrabModeAsync,x_win,None,CurrentTime); XGrabPointer (x_disp, x_win, True, MOUSE_MASK, GrabModeAsync,
GrabModeAsync, x_win, None, CurrentTime);
#ifdef HAVE_DGA
if (dga_avail && in_dga->int_val && !dga_active) {
XF86DGADirectVideo (x_disp, DefaultScreen (x_disp),
XF86DGADirectMouse);
dga_active = true;
}
#endif
} else { // ungrab the pointer
#ifdef HAVE_DGA
if (dga_avail && in_dga->int_val && dga_active) {
XF86DGADirectVideo (x_disp, DefaultScreen (x_disp), 0);
dga_active = false;
}
#endif
XUngrabPointer (x_disp, CurrentTime);
} }
} }
} }
@ -339,22 +353,23 @@ IN_Move (usercmd_t *cmd)
if (m_filter->int_val) { if (m_filter->int_val) {
mouse_x = (mouse_x + old_mouse_x) * 0.5; mouse_x = (mouse_x + old_mouse_x) * 0.5;
mouse_y = (mouse_y + old_mouse_y) * 0.5; mouse_y = (mouse_y + old_mouse_y) * 0.5;
}
old_mouse_x = mouse_x; old_mouse_x = mouse_x;
old_mouse_y = mouse_y; old_mouse_y = mouse_y;
}
mouse_x *= sensitivity->value; mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value; mouse_y *= sensitivity->value;
if ( (in_strafe.state & 1) || (lookstrafe->int_val && (in_mlook.state & 1) )) if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook))
cmd->sidemove += m_side->value * mouse_x; cmd->sidemove += m_side->value * mouse_x;
else else
cl.viewangles[YAW] -= m_yaw->value * mouse_x; cl.viewangles[YAW] -= m_yaw->value * mouse_x;
if (in_mlook.state & 1)
if (freelook)
V_StopPitchDrift (); V_StopPitchDrift ();
if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) { if (freelook && !(in_strafe.state & 1)) {
cl.viewangles[PITCH] += m_pitch->value * mouse_y; cl.viewangles[PITCH] += m_pitch->value * mouse_y;
cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80); cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
} else { } else {
@ -366,24 +381,6 @@ IN_Move (usercmd_t *cmd)
mouse_x = mouse_y = 0.0; mouse_x = mouse_y = 0.0;
} }
/*
static void IN_ExtraOptionDraw(unsigned int options_draw_cursor)
{
// Windowed Mouse
M_Print(16, options_draw_cursor+=8, " Use Mouse");
M_DrawCheckbox(220, options_draw_cursor, _windowed_mouse->int_val);
}
static void IN_ExtraOptionCmd(int option_cursor)
{
switch (option_cursor) {
case 1: // _windowed_mouse
Cvar_SetValue (_windowed_mouse, !_windowed_mouse->int_val);
break;
}
}
*/
/* /*
Called at shutdown Called at shutdown
*/ */
@ -391,30 +388,30 @@ void
IN_Shutdown (void) IN_Shutdown (void)
{ {
JOY_Shutdown (); JOY_Shutdown ();
Con_Printf("IN_Shutdown\n");
Con_Printf ("IN_Shutdown\n");
mouse_avail = 0; mouse_avail = 0;
if (x_disp) { if (x_disp) {
XAutoRepeatOn(x_disp); XAutoRepeatOn (x_disp);
#ifdef HAVE_DGA #ifdef HAVE_DGA
XF86DGADirectVideo(x_disp, DefaultScreen(x_disp), 0); XF86DGADirectVideo (x_disp, DefaultScreen (x_disp), 0);
#endif #endif
} }
x11_close_display(); x11_close_display();
} }
extern int scr_width, scr_height; void
int
IN_Init (void) IN_Init (void)
{ {
// open the display // open the display
if (!x_disp) if (!x_disp)
Sys_Error("IN: No display!!\n"); Sys_Error("IN: No display!!\n");
if (!x_win) if (!x_win)
Sys_Error("IN: No window!!\n"); Sys_Error("IN: No window!!\n");
x11_open_display (); // call to increment the reference counter x11_open_display (); // call to increment the reference counter
{ {
int attribmask = CWEventMask; int attribmask = CWEventMask;
XWindowAttributes attribs_1; XWindowAttributes attribs_1;
@ -429,41 +426,16 @@ IN_Init (void)
JOY_Init (); JOY_Init ();
_windowed_mouse = Cvar_Get ("_windowed_mouse","0",CVAR_ARCHIVE,"None"); XAutoRepeatOff (x_disp);
m_filter = Cvar_Get ("m_filter","0",CVAR_ARCHIVE,"None");
XAutoRepeatOff(x_disp); if (COM_CheckParm("-nomouse"))
return;
if (COM_CheckParm("-nomouse")) return 1; dga_avail = VID_CheckDGA (x_disp, NULL, NULL, NULL);
#ifdef HAVE_DGA if (vid_fullscreen->int_val) {
in_dgamouse = Cvar_Get ("in_dgamouse", "0", CVAR_ROM, Cvar_Set (_windowed_mouse, "1");
"1 if you have DGA mouse support"); _windowed_mouse->flags |= CVAR_ROM;
in_dga_mouseaccel = Cvar_Get ("in_dga_mouseaccel", "1", CVAR_ARCHIVE,
"None");
in_nodga_grab = Cvar_Get ("in_nodga_grab", "0", CVAR_ROM,
"grab keyboard and mouse input when using -nodga");
if (COM_CheckParm ("-nodga")) {
if (in_nodga_grab->int_val) {
XGrabKeyboard (x_disp, x_win, True, GrabModeAsync,
GrabModeAsync, CurrentTime);
XGrabPointer (x_disp, x_win, True, MOUSE_MASK, GrabModeAsync,
GrabModeAsync, x_win, None, CurrentTime);
}
} else {
XGrabKeyboard (x_disp, x_win, True, GrabModeAsync,
GrabModeAsync, CurrentTime);
XF86DGADirectVideo(x_disp, DefaultScreen(x_disp),
XF86DGADirectMouse|XF86DGADirectKeyb);
XGrabPointer (x_disp, x_win, True, MOUSE_MASK, GrabModeAsync,
GrabModeAsync, x_win, None, CurrentTime);
Cvar_SetROM (in_dgamouse, "1");
} }
#endif
mouse_x = mouse_y = 0.0; mouse_x = mouse_y = 0.0;
mouse_avail = 1; mouse_avail = 1;
@ -474,9 +446,21 @@ IN_Init (void)
x11_add_event(ButtonRelease, &event_button); x11_add_event(ButtonRelease, &event_button);
x11_add_event(MotionNotify, &event_motion); x11_add_event(MotionNotify, &event_motion);
return 1; return;
} }
void IN_HandlePause (qboolean pause) void
IN_Init_Cvars (void)
{
JOY_Init_Cvars ();
_windowed_mouse = Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, "None");
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, "None");
in_dga = Cvar_Get ("in_dga", "1", CVAR_ARCHIVE, "DGA Input support");
in_dga_mouseaccel = Cvar_Get ("in_dga_mouseaccel", "1", CVAR_ARCHIVE,
"None");
}
void
IN_HandlePause (qboolean paused)
{ {
} }

View file

@ -41,6 +41,7 @@
#include "cvar.h" #include "cvar.h"
#include "keys.h" #include "keys.h"
#include "protocol.h" #include "protocol.h"
#include "view.h"
#define JOY_MAX_AXES 6 #define JOY_MAX_AXES 6
#define JOY_MAX_BUTTONS 10 #define JOY_MAX_BUTTONS 10
@ -149,10 +150,6 @@ JOY_Move (usercmd_t *cmd)
void void
JOY_Init (void) JOY_Init (void)
{ {
joy_device = Cvar_Get ("joy_device", "/dev/js0", CVAR_NONE|CVAR_ROM, "Joystick device");
joy_enable = Cvar_Get ("joy_enable", "1", CVAR_NONE|CVAR_ARCHIVE, "Joystick enable flag");
joy_sensitivity = Cvar_Get ("joy_sensitivity", "1", CVAR_NONE|CVAR_ARCHIVE, "Joystick sensitivity");
// Open joystick device // Open joystick device
joy_handle = open (joy_device->string, O_RDONLY|O_NONBLOCK); joy_handle = open (joy_device->string, O_RDONLY|O_NONBLOCK);
if (joy_handle < 0) { if (joy_handle < 0) {
@ -169,11 +166,6 @@ JOY_Init (void)
} }
} else { } else {
// Initialize joystick if found and enabled // Initialize joystick if found and enabled
for (i = 0; i < JOY_MAX_AXES; i++) {
joy_axes[i].axis = Cvar_Get (joy_axes[i].var.name,
joy_axes[i].var.string,
CVAR_ARCHIVE, "None");
}
for (i = 0; i < JOY_MAX_BUTTONS; i++) { for (i = 0; i < JOY_MAX_BUTTONS; i++) {
joy_buttons[i].old = 0; joy_buttons[i].old = 0;
joy_buttons[i].current = 0; joy_buttons[i].current = 0;
@ -184,6 +176,22 @@ JOY_Init (void)
} }
} }
void
JOY_Init_Cvars (void)
{
int i;
joy_device = Cvar_Get ("joy_device", "/dev/js0", CVAR_NONE|CVAR_ROM, "Joystick device");
joy_enable = Cvar_Get ("joy_enable", "1", CVAR_NONE|CVAR_ARCHIVE, "Joystick enable flag");
joy_sensitivity = Cvar_Get ("joy_sensitivity", "1", CVAR_NONE|CVAR_ARCHIVE, "Joystick sensitivity");
for (i = 0; i < JOY_MAX_AXES; i++) {
joy_axes[i].axis = Cvar_Get (joy_axes[i].var.name,
joy_axes[i].var.string,
CVAR_ARCHIVE, "None");
}
}
void void
JOY_Shutdown (void) JOY_Shutdown (void)
{ {

View file

@ -30,6 +30,7 @@
# include "config.h" # include "config.h"
#endif #endif
#include "console.h"
#include "cvar.h" #include "cvar.h"
#include "protocol.h" #include "protocol.h"
#include "qtypes.h" #include "qtypes.h"
@ -54,12 +55,16 @@ JOY_Move (usercmd_t *cmd)
void void
JOY_Init (void) JOY_Init (void)
{
Con_DPrintf ("This system does not have joystick support.\n");
}
void
JOY_Init_Cvars (void)
{ {
joy_device = Cvar_Get ("joy_device", "none", CVAR_NONE|CVAR_ROM, "Joystick device"); joy_device = Cvar_Get ("joy_device", "none", CVAR_NONE|CVAR_ROM, "Joystick device");
joy_enable = Cvar_Get ("joy_enable", "1", CVAR_NONE|CVAR_ARCHIVE, "Joystick enable flag"); joy_enable = Cvar_Get ("joy_enable", "1", CVAR_NONE|CVAR_ARCHIVE, "Joystick enable flag");
joy_sensitivity = Cvar_Get ("joy_sensitivity", "1", CVAR_NONE|CVAR_ARCHIVE, "Joystick sensitivity"); joy_sensitivity = Cvar_Get ("joy_sensitivity", "1", CVAR_NONE|CVAR_ARCHIVE, "Joystick sensitivity");
Con_DPrintf ("This system does not have joystick support.\n");
} }
void void

80
source/vid.c Normal file
View file

@ -0,0 +1,80 @@
/*
vid.c
general video driver functions
Copyright (C) 1996-1997 Id Software, Inc.
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$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "cvar.h"
#include "vid.h"
#include "va.h"
#include "qargs.h"
#include "sys.h"
extern viddef_t vid; // global video state
int scr_width, scr_height;
cvar_t *vid_width;
cvar_t *vid_height;
void
VID_GetWindowSize (int def_w, int def_h)
{
int pnum;
vid_width = Cvar_Get ("vid_width", va("%d",def_w), CVAR_ROM, "screen width");
vid_height = Cvar_Get ("vid_height", va("%d",def_h), CVAR_ROM, "screen height");
if ((pnum=COM_CheckParm("-width"))) {
if (pnum >= com_argc-1)
Sys_Error("VID: -width <width>\n");
Cvar_SetROM (vid_width, com_argv[pnum+1]);
if (!vid_width->int_val)
Sys_Error("VID: Bad window width\n");
}
if ((pnum=COM_CheckParm("-height"))) {
if (pnum >= com_argc-1)
Sys_Error("VID: -height <height>\n");
Cvar_SetROM (vid_height, com_argv[pnum+1]);
if (!vid_height->int_val)
Sys_Error("VID: Bad window height\n");
}
if ((pnum=COM_CheckParm("-winsize"))) {
if (pnum >= com_argc-2)
Sys_Error("VID: -winsize <width> <height>\n");
Cvar_SetROM (vid_width, com_argv[pnum+1]);
Cvar_SetROM (vid_height, com_argv[pnum+2]);
if (!vid_width->int_val || !vid_height->int_val)
Sys_Error("VID: Bad window width/height\n");
}
scr_width = vid.width = vid_width->int_val;
scr_height = vid.height = vid_height->int_val;
}

View file

@ -29,94 +29,54 @@
$Id$ $Id$
*/ */
#include "qtypes.h" #ifdef HAVE_CONFIG_H
#include "glquake.h" #include "config.h"
#include "sys.h" #endif
#include "console.h"
#include "cvar.h"
#include "sbar.h"
#include "qendian.h"
#include "qargs.h"
//#include "lib_replace.h"
#include "host.h"
#include "quakefs.h"
#include <stdio.h> #ifdef HAVE_STRING_H
#include <stdlib.h>
#include <signal.h>
#include <string.h> #include <string.h>
#endif
#include <GL/gl.h>
#include <GL/fxmesa.h>
#include <glide/sst1vid.h>
#include <sys/signal.h>
#ifdef HAVE_DLFCN_H #ifdef HAVE_DLFCN_H
# include <dlfcn.h> # include <dlfcn.h>
#endif #endif
#ifndef RTLD_LAZY #ifndef RTLD_LAZY
# ifdef DL_LAZY # ifdef DL_LAZY
# define RTLD_LAZY DL_LAZY # define RTLD_LAZY DL_LAZY
# else # else
# define RTLD_LAZY 0 # define RTLD_LAZY 0
# endif # endif
#endif #endif
#include <GL/gl.h> #include "console.h"
#include <GL/fxmesa.h> #include "glquake.h"
#include <glide/sst1vid.h> #include "qargs.h"
#include "qendian.h"
#include "quakedef.h"
#include "quakefs.h"
#include "sbar.h"
#include "sys.h"
#include "va.h"
#define WARP_WIDTH 320 #define WARP_WIDTH 320
#define WARP_HEIGHT 200 #define WARP_HEIGHT 200
//unsigned short d_8to16table[256];
unsigned d_8to24table[256];
unsigned char d_15to8table[65536];
static cvar_t *vid_mode;
static cvar_t *vid_redrawfull;
static cvar_t *vid_waitforrefresh;
extern cvar_t *gl_triplebuffer;
#ifdef HAVE_DLOPEN
static void *dlhand = NULL;
#endif
static fxMesaContext fc = NULL; static fxMesaContext fc = NULL;
static int scr_width, scr_height;
static qboolean is8bit = 0; static void *dlhand;
int VID_options_items = 0; int VID_options_items = 0;
extern void GL_Init_Common(void);
extern void VID_Init8bitPalette(void);
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
//int texture_mode = GL_NEAREST; void
//int texture_mode = GL_NEAREST_MIPMAP_NEAREST; VID_Shutdown(void)
//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;
// ARB Multitexture
int gl_mtex_enum = TEXTURE0_SGIS;
qboolean gl_arb_mtex = 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)
{
}
void VID_Shutdown(void)
{ {
if (!fc) if (!fc)
return; return;
@ -124,16 +84,18 @@ void VID_Shutdown(void)
fxMesaDestroyContext(fc); fxMesaDestroyContext(fc);
} }
void signal_handler(int sig) void
signal_handler(int sig)
{ {
printf("Received signal %d, exiting...\n", sig); printf("Received signal %d, exiting...\n", sig);
Host_Shutdown(); Host_Shutdown();
abort(); abort();
//Sys_Quit(); // Sys_Quit();
exit(0); exit(0);
} }
void InitSig(void) void
InitSig(void)
{ {
signal(SIGHUP, signal_handler); signal(SIGHUP, signal_handler);
signal(SIGINT, signal_handler); signal(SIGINT, signal_handler);
@ -147,151 +109,6 @@ void InitSig(void)
signal(SIGTERM, signal_handler); signal(SIGTERM, signal_handler);
} }
void VID_ShiftPalette(unsigned char *p)
{
// VID_SetPalette(p);
}
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;
QFile *f;
char s[255];
//#endif
float dist, bestdist;
//
// 8 8 8 encoding
//
Con_Printf("Converting 8to24\n");
pal = palette;
table = d_8to24table;
for (i=0 ; i<256 ; i++)
{
r = pal[0];
g = pal[1];
b = pal[2];
pal += 3;
// 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] = 0; // 255 is transparent
// JACK: 3D distance calcs - k is last closest, l is the distance.
{
static qboolean palflag = false;
// FIXME: Precalculate this and cache to disk.
if (palflag)
return;
palflag = true;
}
COM_FOpenFile("glquake/15to8.pal", &f);
if (f) {
Qread(f, d_15to8table, 1<<15);
Qclose(f);
} 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;
}
snprintf(s, sizeof(s), "%s/glquake", com_gamedir);
Sys_mkdir (s);
snprintf(s, sizeof(s), "%s/glquake/15to8.pal", com_gamedir);
if ((f = Qopen(s, "wb")) != NULL) {
Qwrite(f, d_15to8table, 1<<15);
Qclose(f);
}
}
}
/*
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;
}
#ifdef HAVE_DLOPEN
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;
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;
} else {
Con_Printf ("none found\n");
}
dlclose(dlhand);
dlhand = NULL;
#else
gl_mtexable = false;
#endif
}
typedef void (GLAPIENTRY *gl3DfxSetDitherModeEXT_FUNC) (GrDitherMode_t mode); typedef void (GLAPIENTRY *gl3DfxSetDitherModeEXT_FUNC) (GrDitherMode_t mode);
/* /*
@ -299,45 +116,17 @@ typedef void (GLAPIENTRY *gl3DfxSetDitherModeEXT_FUNC) (GrDitherMode_t mode);
GL_Init GL_Init
=============== ===============
*/ */
void GL_Init (void) void
GL_Init (void)
{ {
gl_vendor = glGetString (GL_VENDOR); GL_Init_Common ();
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: "); Con_Printf ("Dithering: ");
dlhand = dlopen (NULL, RTLD_LAZY); dlhand = dlopen (NULL, RTLD_LAZY);
if (dlhand == NULL) { if (dlhand == NULL) {
Con_SafePrintf ("unable to set.\n"); Con_Printf ("unable to set.\n");
return; return;
} }
@ -361,26 +150,8 @@ void GL_Init (void)
dlhand = NULL; dlhand = NULL;
} }
/* void
================= GL_EndRendering (void)
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(); glFlush();
fxMesaSwapBuffers(); fxMesaSwapBuffers();
@ -458,90 +229,17 @@ findres(int *width, int *height)
return GR_RESOLUTION_640x480; return GR_RESOLUTION_640x480;
} }
qboolean VID_Is8bit(void)
{
return is8bit;
}
typedef void (GLAPIENTRY *glColorTableEXT_FUNC) (GLenum, GLenum, GLsizei, typedef void (GLAPIENTRY *glColorTableEXT_FUNC) (GLenum, GLenum, GLsizei,
GLenum, GLenum, const GLvoid *); GLenum, GLenum, const GLvoid *);
typedef void (GLAPIENTRY *gl3DfxSetPaletteEXT_FUNC) (GLuint *pal); typedef void (GLAPIENTRY *gl3DfxSetPaletteEXT_FUNC) (GLuint *pal);
void VID_Init8bitPalette() void
{ VID_Init(unsigned char *palette)
// 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")) {
char *oldpal;
GLubyte table[256][4];
gl3DfxSetPaletteEXT_FUNC load_texture = NULL;
Con_SafePrintf("3DFX_set_global_palette.\n");
load_texture = (void *) dlsym(dlhand, "gl3DfxSetPaletteEXT");
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++;
}
load_texture((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;
}
dlclose(dlhand);
dlhand = NULL;
Con_SafePrintf ("not found.\n");
}
void VID_Init(unsigned char *palette)
{ {
int i; int i;
GLint attribs[32]; GLint attribs[32];
char gldir[MAX_OSPATH];
int width = 640, height = 480;
vid_mode = Cvar_Get ("vid_mode", "5", 0, "None"); VID_GetWindowSize (640, 480);
vid_redrawfull = Cvar_Get ("vid_redrawfull", "0", 0," None");
vid_waitforrefresh = Cvar_Get ("vid_waitforrefresh", "0", CVAR_ARCHIVE,
"None");
vid.maxwarpwidth = WARP_WIDTH; vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT; vid.maxwarpheight = WARP_HEIGHT;
@ -558,11 +256,6 @@ void VID_Init(unsigned char *palette)
attribs[4] = 1; attribs[4] = 1;
attribs[5] = FXMESA_NONE; 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) if ((i = COM_CheckParm("-conwidth")) != 0)
vid.conwidth = atoi(com_argv[i+1]); vid.conwidth = atoi(com_argv[i+1]);
else else
@ -581,20 +274,17 @@ void VID_Init(unsigned char *palette)
if (vid.conheight < 200) if (vid.conheight < 200)
vid.conheight = 200; vid.conheight = 200;
fc = fxMesaCreateContext(0, findres(&width, &height), GR_REFRESH_75Hz, fc = fxMesaCreateContext(0, findres(&scr_width, &scr_height),
attribs); GR_REFRESH_75Hz, attribs);
if (!fc) if (!fc)
Sys_Error("Unable to create 3DFX context.\n"); Sys_Error("Unable to create 3DFX context.\n");
scr_width = width;
scr_height = height;
fxMesaMakeCurrent(fc); fxMesaMakeCurrent(fc);
if (vid.conheight > height) if (vid.conheight > scr_height)
vid.conheight = height; vid.conheight = scr_height;
if (vid.conwidth > width) if (vid.conwidth > scr_width)
vid.conwidth = width; vid.conwidth = scr_width;
vid.width = vid.conwidth; vid.width = vid.conwidth;
vid.height = vid.conheight; vid.height = vid.conheight;
@ -605,25 +295,29 @@ void VID_Init(unsigned char *palette)
GL_Init(); GL_Init();
snprintf(gldir, sizeof(gldir), "%s/glquake", com_gamedir);
Sys_mkdir (gldir);
VID_SetPalette(palette); VID_SetPalette(palette);
// Check for 3DFX Extensions and initialize them. // Check for 3DFX Extensions and initialize them.
VID_Init8bitPalette(); VID_Init8bitPalette();
Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height); Con_Printf ("Video mode %dx%d initialized.\n", scr_width, scr_height);
vid.recalc_refdef = 1; // force a surface cache flush vid.recalc_refdef = 1; // force a surface cache flush
} }
void VID_ExtraOptionDraw(unsigned int options_draw_cursor) void
VID_Init_Cvars()
{
}
void
VID_ExtraOptionDraw(unsigned int options_draw_cursor)
{ {
/* Port specific Options menu entrys */ /* Port specific Options menu entrys */
} }
void VID_ExtraOptionCmd(int option_cursor) void
VID_ExtraOptionCmd(int option_cursor)
{ {
/* /*
switch(option_cursor) switch(option_cursor)
@ -633,15 +327,12 @@ void VID_ExtraOptionCmd(int option_cursor)
} }
*/ */
} }
void VID_InitCvars ()
{
gl_triplebuffer = Cvar_Get ("gl_triplebuffer","1",CVAR_ARCHIVE,"None");
}
void VID_SetCaption (char *text) void
VID_SetCaption (char *text)
{ {
} }
void VID_HandlePause (qboolean pause) void VID_HandlePause (qboolean paused)
{ {
} }

402
source/vid_common_gl.c Normal file
View file

@ -0,0 +1,402 @@
/*
vid_common_gl.c
Common OpenGL video driver functions
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
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
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <GL/gl.h>
#ifdef HAVE_GL_GLEXT_H
#include <GL/glext.h>
#endif
#include <string.h>
#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
#include "console.h"
#include "glquake.h"
#include "input.h"
#include "qargs.h"
#include "quakefs.h"
#include "sbar.h"
#define WARP_WIDTH 320
#define WARP_HEIGHT 200
#ifdef HAVE_DLOPEN
static void *dlhand = NULL;
#endif
//unsigned short d_8to16table[256];
unsigned int d_8to24table[256];
unsigned char d_15to8table[65536];
cvar_t *vid_mode;
/*-----------------------------------------------------------------------*/
int texture_mode = GL_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;
// ARB Multitexture
int gl_mtex_enum = TEXTURE0_SGIS;
qboolean gl_arb_mtex = false;
qboolean gl_mtexable = false;
qboolean is8bit = false;
cvar_t *vid_use8bit;
/*-----------------------------------------------------------------------*/
/*
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;
}
#ifdef HAVE_DLOPEN
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;
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;
} else {
Con_Printf ("none found\n");
}
dlclose(dlhand);
dlhand = NULL;
#else
gl_mtexable = false;
#endif
}
void
VID_SetPalette (unsigned char *palette)
{
byte *pal;
unsigned int r,g,b;
unsigned int v;
int r1,g1,b1;
int k;
unsigned short i;
unsigned int *table;
QFile *f;
char s[255];
float dist, bestdist;
static qboolean palflag = false;
//
// 8 8 8 encoding
//
// Con_Printf("Converting 8to24\n");
pal = palette;
table = d_8to24table;
for (i = 0; i < 255; i++) { // used to be i<256, see d_8to24table below
r = pal[0];
g = pal[1];
b = pal[2];
pal += 3;
// 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] = 0; // 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) {
Qread(f, d_15to8table, 1<<15);
Qclose(f);
} 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;
}
snprintf(s, sizeof(s), "%s/glquake/15to8.pal", com_gamedir);
COM_CreatePath (s);
if ((f = Qopen(s, "wb")) != NULL) {
Qwrite(f, d_15to8table, 1<<15);
Qclose(f);
}
}
}
/*
===============
GL_Init_Common
===============
*/
void
GL_Init_Common (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);
glClearColor (0,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);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
CheckMultiTextureExtensions ();
}
/*
=================
GL_BeginRendering
=================
*/
void
GL_BeginRendering (int *x, int *y, int *width, int *height)
{
*x = *y = 0;
*width = scr_width;
*height = scr_height;
}
qboolean VID_Is8bit(void)
{
return is8bit;
}
#ifdef HAVE_TDFXGL
void 3dfx_Init8bitPalette()
{
// Check for 8bit Extensions and initialize them.
int i;
dlhand = dlopen (NULL, RTLD_LAZY);
Con_Printf ("8-bit GL extensions: ");
if (dlhand == NULL) {
Con_Printf ("unable to check.\n");
return;
}
if (strstr(gl_extensions, "3DFX_set_global_palette")) {
char *oldpal;
GLubyte table[256][4];
gl3DfxSetPaletteEXT_FUNC load_texture = NULL;
Con_Printf("3DFX_set_global_palette.\n");
load_texture = (void *) dlsym(dlhand, "gl3DfxSetPaletteEXT");
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++;
}
load_texture((GLuint *)table);
is8bit = true;
} else Shared_Init8bitPalette();
dlclose(dlhand);
dlhand = NULL;
Con_Printf ("not found.\n");
}
#endif
#ifdef GL_SHARED_TEXTURE_PALETTE_EXT
void
Shared_Init8bitPalette()
{
int i;
char thePalette[256*3];
char *oldPalette, *newPalette;
if (strstr(gl_extensions, "GL_EXT_shared_texture_palette") == NULL)
return;
#ifdef HAVE_TDFXGL
glColorTableEXT_FUNC load_texture = NULL;
load_texture = (void *) dlsym(dlhand, "glColorTableEXT");
#endif
Con_Printf("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++;
}
is8bit = true;
if strstr(gl_renderer, "Mesa Glide") {
#ifdef HAVE_TDFXGL
load_texture(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, (void *) thePalette);
#endif
} else
glColorTable(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, (void *) thePalette);
}
#endif
void
VID_Init8bitPalette(void)
{
if (COM_CheckParm("-no8bit")) {
Con_Printf("disabled.\n");
return;
}
vid_use8bit = Cvar_Get ("vid_use8bit", "0", CVAR_ROM,
"Whether to use Shared Palettes.");
if (vid_use8bit->value) {
#ifdef HAVE_TDFXGL
3dfx_Init8bitPalette();
#else
#ifdef GL_SHARED_TEXTURE_PALETTE_EXT
Shared_Init8bitPalette();
#endif
#endif
}
}
void
VID_LockBuffer ( void )
{
}
void
VID_UnlockBuffer ( void )
{
}
void
D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
{
}
void
D_EndDirectRect (int x, int y, int width, int height)
{
}

View file

@ -29,18 +29,46 @@
#define _BSD #define _BSD
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <ggi/ggi.h> #include <ggi/ggi.h>
#include "bothdefs.h" // needed by: common.h, net.h, client.h
#include "quakedef.h"
#include "bspfile.h" // needed by: glquake.h
#include "vid.h"
#include "sys.h"
#include "mathlib.h" // needed by: protocol.h, render.h, client.h,
// modelgen.h, glmodel.h
#include "wad.h"
#include "draw.h"
#include "cvar.h"
#include "net.h" // needed by: client.h
#include "protocol.h" // needed by: client.h
#include "cmd.h"
#include "keys.h"
#include "sbar.h"
#include "sound.h"
#include "render.h" // needed by: client.h, gl_model.h, glquake.h
#include "client.h" // need cls in this file
#include "model.h" // needed by: glquake.h
#include "console.h"
#include "qendian.h"
#include "qargs.h"
#include "compat.h"
#include "d_local.h" #include "d_local.h"
#include "input.h"
#include "cl_input.h"
#include "view.h"
#include "joystick.h"
extern viddef_t vid; // global video state extern viddef_t vid; // global video state
unsigned short d_8to16table[256]; unsigned short d_8to16table[256];
@ -78,18 +106,8 @@ static int stride, drawstride;
static int pixelsize; static int pixelsize;
static int usedbuf, havedbuf; static int usedbuf, havedbuf;
static long GGI_highhunkmark, GGI_buffersize;
static int vid_surfcachesize;
static void *vid_surfcache;
int VID_options_items = 1; int VID_options_items = 1;
void
VID_InitCvars(void)
{
}
static void static void
do_scale8(int xsize, int ysize, uint8 *dest, uint8 *src) do_scale8(int xsize, int ysize, uint8 *dest, uint8 *src)
{ {
@ -206,44 +224,54 @@ do_copy32(int xsize, int ysize, uint32 *dest, uint8 *src)
} }
// ======================================================================== void
// Tragic death handler ResetFrameBuffer(void)
// ========================================================================
void ResetFrameBuffer(void)
{ {
if (d_pzbuffer) int tbuffersize, tcachesize;
{ void *vid_surfcache;
D_FlushCaches ();
Hunk_FreeToHighMark (GGI_highhunkmark); // Calculate the sizes we want first
tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
tcachesize = D_SurfaceCacheForRes(vid.width, vid.height);
// Free the old z-buffer
if (d_pzbuffer) {
free (d_pzbuffer);
d_pzbuffer = NULL; d_pzbuffer = NULL;
} }
GGI_highhunkmark = Hunk_HighMark ();
// alloc an extra line in case we want to wrap, and allocate the z-buffer // Free the old surface cache
GGI_buffersize = vid.width * vid.height * sizeof (*d_pzbuffer); vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) {
D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
vid_surfcachesize = D_SurfaceCacheForRes (vid.width, vid.height); // Allocate the new z-buffer
d_pzbuffer = calloc (tbuffersize, 1);
GGI_buffersize += vid_surfcachesize; if (!d_pzbuffer) {
d_pzbuffer = Hunk_HighAllocName (GGI_buffersize, "video");
if (d_pzbuffer == NULL)
Sys_Error ("Not enough memory for video mode\n"); Sys_Error ("Not enough memory for video mode\n");
}
vid_surfcache = (byte *) d_pzbuffer // Allocate the new surface cache; free the z-buffer if we fail
+ vid.width * vid.height * sizeof (*d_pzbuffer); vid_surfcache = calloc (tcachesize, 1);
if (!vid_surfcache) {
free (d_pzbuffer);
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
D_InitCaches(vid_surfcache, vid_surfcachesize); D_InitCaches (vid_surfcache, tcachesize);
} }
// Called at startup to set up translation tables, takes 256 8 bit RGB values // Called at startup to set up translation tables, takes 256 8 bit RGB values
// the palette data will go away after the call, so it must be copied off if // the palette data will go away after the call, so it must be copied off if
// the video driver will need it again // the video driver will need it again
void VID_Init(unsigned char *pal) void
VID_Init (unsigned char *pal)
{ {
int pnum; int pnum;
@ -434,14 +462,15 @@ void VID_Init(unsigned char *pal)
vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048)); vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
} }
void VID_ShiftPalette(unsigned char *pal) void
VID_ShiftPalette(unsigned char *pal)
{ {
VID_SetPalette(pal); VID_SetPalette(pal);
} }
void
void VID_SetPalette(unsigned char *pal) VID_SetPalette (unsigned char *pal)
{ {
int i; int i;
@ -461,7 +490,8 @@ void VID_SetPalette(unsigned char *pal)
// Called at shutdown // Called at shutdown
void VID_Shutdown (void) void
VID_Shutdown (void)
{ {
Con_Printf("VID_Shutdown\n"); Con_Printf("VID_Shutdown\n");
@ -487,7 +517,8 @@ void VID_Shutdown (void)
// flushes the given rectangles from the view buffer to the screen // flushes the given rectangles from the view buffer to the screen
void VID_Update(vrect_t *rects) void
VID_Update (vrect_t *rects)
{ {
int height = 0; int height = 0;
@ -890,19 +921,31 @@ void IN_SendKeyEvents(void)
void void
IN_Init(void) IN_Init(void)
{ {
_windowed_mouse = Cvar_Get("_windowed_mouse", "0", CVAR_ARCHIVE, "None"); JOY_Init ();
old_windowed_mouse = -1; /* Force update */ old_windowed_mouse = -1; /* Force update */
m_filter = Cvar_Get("m_filter", "0", CVAR_ARCHIVE, "None");
if (COM_CheckParm ("-nomouse")) return; if (COM_CheckParm ("-nomouse")) return;
mouse_x = mouse_y = 0.0; mouse_x = mouse_y = 0.0;
mouse_avail = 1; mouse_avail = 1;
} }
void
IN_Init_Cvars(void)
{
JOY_Init_Cvars ();
_windowed_mouse = Cvar_Get("_windowed_mouse", "0", CVAR_ARCHIVE, "None");
m_filter = Cvar_Get("m_filter", "0", CVAR_ARCHIVE, "None");
}
void void
IN_Shutdown(void) IN_Shutdown(void)
{ {
JOY_Shutdown ();
Con_Printf("IN_Shutdown\n");
mouse_avail = 0; mouse_avail = 0;
} }
@ -910,6 +953,8 @@ IN_Shutdown(void)
void void
IN_Commands (void) IN_Commands (void)
{ {
JOY_Command ();
/* Only supported by LibGII 0.7 or later. */ /* Only supported by LibGII 0.7 or later. */
#ifdef GII_CMDCODE_PREFER_RELPTR #ifdef GII_CMDCODE_PREFER_RELPTR
if (old_windowed_mouse != _windowed_mouse->int_val) { if (old_windowed_mouse != _windowed_mouse->int_val) {
@ -920,7 +965,7 @@ IN_Commands (void)
ev.cmd.size = sizeof(gii_cmd_nodata_event); ev.cmd.size = sizeof(gii_cmd_nodata_event);
ev.cmd.type = evCommand; ev.cmd.type = evCommand;
ev.cmd.target = GII_EV_TARGET_ALL; ev.cmd.target = GII_EV_TARGET_ALL;
ev.cmd.code = (int)_windowed_mouse->int_val ? GII_CMDCODE_PREFER_RELPTR ev.cmd.code = _windowed_mouse->int_val ? GII_CMDCODE_PREFER_RELPTR
: GII_CMDCODE_PREFER_ABSPTR; : GII_CMDCODE_PREFER_ABSPTR;
ggiEventSend(ggivis, &ev); ggiEventSend(ggivis, &ev);
@ -932,7 +977,10 @@ IN_Commands (void)
void void
IN_Move(usercmd_t *cmd) IN_Move(usercmd_t *cmd)
{ {
if (!mouse_avail) return; JOY_Move (cmd);
if (!mouse_avail)
return;
if (m_filter->int_val) { if (m_filter->int_val) {
mouse_x = (mouse_x + old_mouse_x) * 0.5; mouse_x = (mouse_x + old_mouse_x) * 0.5;
@ -945,19 +993,16 @@ IN_Move(usercmd_t *cmd)
mouse_x *= sensitivity->value; mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value; mouse_y *= sensitivity->value;
if ( (in_strafe.state & 1) || (lookstrafe->int_val && freelook )) if ( (in_strafe.state & 1) || (lookstrafe->int_val && freelook))
cmd->sidemove += m_side->value * mouse_x; cmd->sidemove += m_side->value * mouse_x;
else else
cl.viewangles[YAW] -= m_yaw->value * mouse_x; cl.viewangles[YAW] -= m_yaw->value * mouse_x;
if (freelook) if (freelook)
V_StopPitchDrift (); V_StopPitchDrift ();
if ( freelook && !(in_strafe.state & 1)) { if (freelook && !(in_strafe.state & 1)) {
cl.viewangles[PITCH] += m_pitch->value * mouse_y; cl.viewangles[PITCH] += m_pitch->value * mouse_y;
if (cl.viewangles[PITCH] > 80) cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
cl.viewangles[PITCH] = 80;
if (cl.viewangles[PITCH] < -70)
cl.viewangles[PITCH] = -70;
} else { } else {
if ((in_strafe.state & 1) && noclip_anglehack) if ((in_strafe.state & 1) && noclip_anglehack)
cmd->upmove -= m_forward->value * mouse_y; cmd->upmove -= m_forward->value * mouse_y;
@ -967,6 +1012,16 @@ IN_Move(usercmd_t *cmd)
mouse_x = mouse_y = 0.0; mouse_x = mouse_y = 0.0;
} }
void VID_HandlePause (qboolean pause)
void VID_Init_Cvars(void) {}
void VID_LockBuffer(void) {}
void VID_UnlockBuffer(void) {}
void VID_SetCaption (char *text)
{
}
void VID_HandlePause (qboolean paused)
{ {
} }

View file

@ -31,22 +31,7 @@
# include "config.h" # include "config.h"
#endif #endif
#include <stdio.h> #include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <signal.h>
#include <values.h>
#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
#include <GL/glx.h> #include <GL/glx.h>
@ -57,391 +42,92 @@
# include <X11/extensions/xf86dga.h> # include <X11/extensions/xf86dga.h>
#endif #endif
#ifdef XMESA #include "compat.h"
# include <GL/xmesa.h> #include "console.h"
#endif #include "context_x11.h"
#include "qtypes.h"
#include "qendian.h"
#include "glquake.h" #include "glquake.h"
#include "host.h" #include "host.h"
#include "cvar.h"
#include "qargs.h"
#include "console.h"
#include "keys.h"
#include "menu.h"
#include "sys.h"
#include "quakefs.h"
#include "draw.h"
#include "input.h" #include "input.h"
#include "qargs.h"
#include "qendian.h"
#include "quakefs.h"
#include "sbar.h" #include "sbar.h"
#include "context_x11.h" #include "va.h"
#include "dga_check.h"
#define WARP_WIDTH 320 #define WARP_WIDTH 320
#define WARP_HEIGHT 200 #define WARP_HEIGHT 200
static qboolean vid_initialized = false; static qboolean vid_initialized = false;
static GLXContext ctx = NULL; static GLXContext ctx = NULL;
unsigned short d_8to16table[256]; extern void GL_Init_Common (void);
unsigned int d_8to24table[256]; extern void VID_Init8bitPalette (void);
unsigned char d_15to8table[65536];
cvar_t *vid_mode;
extern cvar_t *gl_triplebuffer;
extern cvar_t *in_dga_mouseaccel;
#ifdef HAVE_DGA
static int hasdgavideo = 0;
static int hasdga = 0;
#endif
#ifdef HAVE_DLOPEN
static void *dlhand = NULL;
#endif
static GLboolean (*QF_XMesaSetFXmode)(GLint mode) = NULL;
int scr_width, scr_height;
#if defined(XMESA) || defined(HAVE_DGA)
int VID_options_items = 2;
#else
int VID_options_items = 1;
#endif
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
//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_vendor;
const char *gl_renderer; const char *gl_renderer;
const char *gl_version; const char *gl_version;
const char *gl_extensions; const char *gl_extensions;
qboolean is8bit = false;
// ARB Multitexture
int gl_mtex_enum = TEXTURE0_SGIS;
qboolean gl_arb_mtex = 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)
{
}
void void
VID_Shutdown(void) VID_Shutdown (void)
{ {
if (!vid_initialized) if (!vid_initialized)
return; return;
Con_Printf("VID_Shutdown\n"); Con_Printf ("VID_Shutdown\n");
glXDestroyContext(x_disp, ctx);
XDestroyWindow(x_disp, x_win);
x11_restore_vidmode(); x11_restore_vidmode ();
#ifdef HAVE_DLOPEN x11_close_display ();
if (dlhand) {
dlclose(dlhand);
dlhand = NULL;
}
#endif
x11_close_display();
} }
#if 0 #if 0
static void static void
signal_handler(int sig) signal_handler (int sig)
{ {
printf("Received signal %d, exiting...\n", sig); printf ("Received signal %d, exiting...\n", sig);
Sys_Quit(); Sys_Quit ();
exit(sig); exit (sig);
} }
static void static void
InitSig(void) InitSig (void)
{ {
signal(SIGHUP, signal_handler); signal (SIGHUP, signal_handler);
signal(SIGINT, signal_handler); signal (SIGINT, signal_handler);
signal(SIGQUIT, signal_handler); signal (SIGQUIT, signal_handler);
signal(SIGILL, signal_handler); signal (SIGILL, signal_handler);
signal(SIGTRAP, signal_handler); signal (SIGTRAP, signal_handler);
signal(SIGIOT, signal_handler); signal (SIGIOT, signal_handler);
signal(SIGBUS, signal_handler); signal (SIGBUS, signal_handler);
/* signal(SIGFPE, signal_handler); */ /* signal (SIGFPE, signal_handler); */
signal(SIGSEGV, signal_handler); signal (SIGSEGV, signal_handler);
signal(SIGTERM, signal_handler); signal (SIGTERM, signal_handler);
} }
#endif #endif
void VID_ShiftPalette(unsigned char *p)
{
VID_SetPalette(p);
}
void VID_SetPalette (unsigned char *palette)
{
byte *pal;
unsigned int r,g,b;
unsigned int v;
int r1,g1,b1;
int k;
unsigned short i;
unsigned int *table;
QFile *f;
char s[255];
float dist, bestdist;
static qboolean palflag = false;
//
// 8 8 8 encoding
//
// Con_Printf("Converting 8to24\n");
pal = palette;
table = d_8to24table;
for (i=0 ; i<256 ; i++)
{
r = pal[0];
g = pal[1];
b = pal[2];
pal += 3;
// 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] &= 0; // 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) {
Qread(f, d_15to8table, 1<<15);
Qclose(f);
} 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;
}
snprintf(s, sizeof(s), "%s/glquake", com_gamedir);
Sys_mkdir (s);
snprintf(s, sizeof(s), "%s/glquake/15to8.pal", com_gamedir);
if ((f = Qopen(s, "wb")) != NULL) {
Qwrite(f, d_15to8table, 1<<15);
Qclose(f);
}
}
}
/*
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;
}
#ifdef HAVE_DLOPEN
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;
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;
} else {
Con_Printf ("none found\n");
}
dlclose(dlhand);
dlhand = NULL;
#else
gl_mtexable = false;
#endif
}
/* /*
=============== ===============
GL_Init GL_Init
=============== ===============
*/ */
void GL_Init (void) void
GL_Init (void)
{ {
gl_vendor = glGetString (GL_VENDOR); GL_Init_Common ();
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);
CheckMultiTextureExtensions ();
glClearColor (0,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);
/* 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);
*/
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);
} }
/* void
================= GL_EndRendering (void)
GL_BeginRendering
=================
*/
void GL_BeginRendering (int *x, int *y, int *width, int *height)
{ {
*x = *y = 0; glFlush ();
*width = scr_width; glXSwapBuffers (x_disp, x_win);
*height = scr_height;
// if (!wglMakeCurrent( maindc, baseRC ))
// Sys_Error ("wglMakeCurrent failed");
// glViewport (*x, *y, *width, *height);
}
void GL_EndRendering (void)
{
glFlush();
glXSwapBuffers(x_disp, x_win);
Sbar_Changed (); Sbar_Changed ();
} }
qboolean VID_Is8bit(void) void
{ VID_Init (unsigned char *palette)
return is8bit;
}
#ifdef GL_EXT_SHARED
void VID_Init8bitPalette()
{
// 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
void VID_Init8bitPalette(void)
{
}
#endif
void VID_Init(unsigned char *palette)
{ {
int i; int i;
int attrib[] = { int attrib[] = {
@ -453,156 +139,96 @@ void VID_Init(unsigned char *palette)
GLX_DEPTH_SIZE, 1, GLX_DEPTH_SIZE, 1,
None None
}; };
char gldir[MAX_OSPATH];
int width = 640, height = 480;
vid_mode = Cvar_Get ("vid_mode","0",0,"None"); VID_GetWindowSize (640, 480);
#ifdef HAVE_DGA
in_dga_mouseaccel = Cvar_Get("vid_dga_mouseaccel","1",CVAR_ARCHIVE,
"None");
#endif
vid.maxwarpwidth = WARP_WIDTH; vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT; vid.maxwarpheight = WARP_HEIGHT;
vid.colormap = host_colormap; vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048)); vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
/* Interpret command-line params /* Interpret command-line params
*/ */
/* Set vid parameters */ /* Set vid parameters */
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) if ((i = COM_CheckParm ("-conwidth")))
vid.conwidth = atoi(com_argv[i+1]); vid.conwidth = atoi(com_argv[i+1]);
else else
vid.conwidth = width; vid.conwidth = scr_width;
vid.conwidth &= 0xfff8; // make it a multiple of eight vid.conwidth &= 0xfff8; // make it a multiple of eight
if (vid.conwidth < 320) vid.conwidth = max (vid.conwidth, 320);
vid.conwidth = 320;
// pick a conheight that matches with correct aspect // pick a conheight that matches with correct aspect
vid.conheight = vid.conwidth * 3 / 4; vid.conheight = vid.conwidth * 3 / 4;
i = COM_CheckParm ("-conheight"); if ((i = COM_CheckParm ("-conheight"))) // conheight no smaller than 200px
if ( i != 0 ) // Set console height, but no smaller than 200 px vid.conheight = atoi (com_argv[i+1]);
vid.conheight = atoi(com_argv[i+1]); vid.conheight = max (vid.conheight, 200);
if (vid.conheight < 200)
vid.conheight = 200;
x11_open_display(); x11_open_display ();
x_visinfo = glXChooseVisual(x_disp, x_screen, attrib); x_visinfo = glXChooseVisual (x_disp, x_screen, attrib);
if (!x_visinfo) { if (!x_visinfo) {
fprintf(stderr, "Error couldn't get an RGB, Double-buffered, Depth visual\n"); fprintf (stderr, "Error couldn't get an RGB, Double-buffered, Depth visual\n");
exit(1); exit (1);
} }
x_vis = x_visinfo->visual; x_vis = x_visinfo->visual;
#ifdef HAVE_DGA x11_set_vidmode (scr_width, scr_height);
{ x11_create_window (scr_width, scr_height);
int maj_ver;
hasdga = VID_CheckDGA(x_disp, &maj_ver, NULL, &hasdgavideo);
if (!hasdga || maj_ver < 1) {
hasdga = hasdgavideo = 0;
}
}
Con_SafePrintf ("hasdga = %i\nhasdgavideo = %i\n", hasdga, hasdgavideo);
#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;
}
x11_set_vidmode(width, height);
x11_create_window(width, height);
/* Invisible cursor */ /* Invisible cursor */
x11_create_null_cursor(); x11_create_null_cursor ();
XWarpPointer(x_disp, None, x_win, 0, 0, 0, 0, x11_grab_keyboard ();
vid.width+2, vid.height+2);
x11_grab_keyboard(); XSync (x_disp, 0);
XSync(x_disp, 0); ctx = glXCreateContext (x_disp, x_visinfo, NULL, True);
ctx = glXCreateContext(x_disp, x_visinfo, NULL, True); glXMakeCurrent (x_disp, x_win, ctx);
glXMakeCurrent(x_disp, x_win, ctx); vid.height = vid.conheight = min (vid.conheight, scr_height);
vid.width = vid.conwidth = min (vid.conwidth, scr_width);
scr_width = width; vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
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; vid.numpages = 2;
//InitSig(); // trap evil signals //InitSig (); // trap evil signals
GL_Init(); GL_Init ();
snprintf(gldir, sizeof(gldir), "%s/glquake", com_gamedir); //XXX not yet GL_CheckBrightness (palette);
Sys_mkdir (gldir);
GL_CheckGamma (palette);
VID_SetPalette (palette); VID_SetPalette (palette);
// Check for 3DFX Extensions and initialize them. // Check for 8-bit extension and initialize if present
VID_Init8bitPalette(); VID_Init8bitPalette ();
Con_SafePrintf ("Video mode %dx%d initialized.\n", Con_Printf ("Video mode %dx%d initialized.\n", scr_width, scr_height);
width, height);
vid_initialized = true; vid_initialized = true;
vid.recalc_refdef = 1; // force a surface cache flush vid.recalc_refdef = 1; // force a surface cache flush
} }
void VID_InitCvars() void
VID_Init_Cvars ()
{ {
gl_triplebuffer = Cvar_Get("gl_triplebuffer","1",CVAR_ARCHIVE,"None"); x11_Init_Cvars();
} }
void VID_SetCaption (char *text) void
VID_SetCaption (char *text)
{ {
if (text && *text) {
char *temp = strdup (text);
x11_set_caption (va ("%s %s: %s", PROGRAM, VERSION, temp));
free (temp);
} else {
x11_set_caption (va ("%s %s", PROGRAM, VERSION));
}
} }
void VID_HandlePause (qboolean pause) void VID_HandlePause (qboolean paused)
{ {
} }

View file

@ -32,6 +32,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "quakedef.h" #include "quakedef.h"
#include "va.h"
#include "winquake.h" #include "winquake.h"
#include "sys.h" #include "sys.h"
#include "d_local.h" #include "d_local.h"
@ -53,6 +54,8 @@
#define MAX_MODE_LIST 30 #define MAX_MODE_LIST 30
#define VID_ROW_SIZE 3 #define VID_ROW_SIZE 3
extern void (*vid_menudrawfn)(void);
extern void (*vid_menukeyfn)(int);
/* Unused */ /* Unused */
int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes, VGA_planar; int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes, VGA_planar;
@ -95,12 +98,9 @@ extern viddef_t vid; // global video state
// Note that 0 is MODE_WINDOWED // Note that 0 is MODE_WINDOWED
cvar_t *vid_mode; cvar_t *vid_mode;
// Note that 0 is MODE_WINDOWED // Note that 0 is MODE_WINDOWED
cvar_t *_vid_default_mode;
// Note that 3 is MODE_FULLSCREEN_DEFAULT // Note that 3 is MODE_FULLSCREEN_DEFAULT
cvar_t *_vid_default_mode_win; cvar_t *_vid_default_mode_win;
cvar_t *vid_wait;
cvar_t *vid_nopageflip; cvar_t *vid_nopageflip;
cvar_t *_vid_wait_override;
cvar_t *vid_config_x; cvar_t *vid_config_x;
cvar_t *vid_config_y; cvar_t *vid_config_y;
cvar_t *vid_stretch_by_2; cvar_t *vid_stretch_by_2;
@ -138,7 +138,7 @@ static int VID_highhunkmark;
unsigned char vid_curpal[256*3]; unsigned char vid_curpal[256*3];
unsigned short d_8to16table[256]; unsigned short d_8to16table[256];
unsigned d_8to24table[256]; unsigned int d_8to24table[256];
int driver = grDETECT,mode; int driver = grDETECT,mode;
qboolean useWinDirect = true, useDirectDraw = true; qboolean useWinDirect = true, useDirectDraw = true;
@ -175,17 +175,6 @@ void VID_MenuKey (int key);
LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void AppActivate(BOOL fActive, BOOL minimize); void AppActivate(BOOL fActive, BOOL minimize);
/*
================
VID_InitCvars
================
*/
void
VID_InitCvars ()
{
// It may not look like it, but this is important
}
/* /*
================ ================
VID_RememberWindowPos VID_RememberWindowPos
@ -202,8 +191,8 @@ void VID_RememberWindowPos (void)
(rect.right > 0) && (rect.right > 0) &&
(rect.bottom > 0)) (rect.bottom > 0))
{ {
Cvar_SetValue (vid_window_x, (float)rect.left); Cvar_SetValue (vid_window_x, rect.left);
Cvar_SetValue (vid_window_y, (float)rect.top); Cvar_SetValue (vid_window_y, rect.top);
} }
} }
} }
@ -269,20 +258,6 @@ VID_CheckAdequateMem
*/ */
qboolean VID_CheckAdequateMem (int width, int height) qboolean VID_CheckAdequateMem (int width, int height)
{ {
int tbuffersize;
tbuffersize = width * height * sizeof (*d_pzbuffer);
tbuffersize += D_SurfaceCacheForRes (width, height);
// see if there's enough memory, allowing for the normal mode 0x13 pixel,
// z, and surface buffers
if ((host_parms.memsize - tbuffersize + SURFCACHE_SIZE_AT_320X200 +
0x10000 * 3) < MINIMUM_MEMORY)
{
return false; // not enough memory for mode
}
return true; return true;
} }
@ -292,41 +267,46 @@ qboolean VID_CheckAdequateMem (int width, int height)
VID_AllocBuffers VID_AllocBuffers
================ ================
*/ */
qboolean VID_AllocBuffers (int width, int height) qboolean
VID_AllocBuffers (int width, int height)
{ {
int tsize, tbuffersize; int tbuffersize, tcachesize;
void *temp_z, *temp_sc;
tbuffersize = width * height * sizeof (*d_pzbuffer); tbuffersize = width * height * sizeof (*d_pzbuffer);
tcachesize = D_SurfaceCacheForRes (width, height);
tsize = D_SurfaceCacheForRes (width, height); // Allocate the new z-buffer
temp_z = calloc (tbuffersize, 1);
tbuffersize += tsize; if (temp_z == NULL) {
Sys_Printf ("Not enough memory for video mode\n");
// see if there's enough memory, allowing for the normal mode 0x13 pixel, return false;
// z, and surface buffers
if ((host_parms.memsize - tbuffersize + SURFCACHE_SIZE_AT_320X200 +
0x10000 * 3) < MINIMUM_MEMORY)
{
Con_SafePrintf ("Not enough memory for video mode\n");
return false; // not enough memory for mode
} }
vid_surfcachesize = tsize; // Allocate the new surface cache
temp_sc = calloc (tcachesize, 1);
if (temp_sc == NULL) {
free (temp_z);
Sys_Printf ("Not enough memory for video mode\n");
return false;
}
if (d_pzbuffer) // Free the old z-buffer, switch to the new one
{ if (d_pzbuffer) {
free (d_pzbuffer);
d_pzbuffer = temp_z;
temp_z = NULL;
}
// Free surface cache, switch to the new one
vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) {
D_FlushCaches (); D_FlushCaches ();
Hunk_FreeToHighMark (VID_highhunkmark); free (vid_surfcache);
d_pzbuffer = NULL; vid_surfcache = temp_sc;
temp_sc = NULL;
} }
VID_highhunkmark = Hunk_HighMark ();
d_pzbuffer = Hunk_HighAllocName (tbuffersize, "video");
vid_surfcache = (byte *)d_pzbuffer +
width * height * sizeof (*d_pzbuffer);
return true; return true;
} }
@ -862,7 +842,7 @@ void VID_InitFullDIB (HINSTANCE hInstance)
modenum = 0; modenum = 0;
lowestres = 99999; lowestres = 99999;
Con_SafePrintf ("No 8-bpp fullscreen DIB modes found\n"); Con_Printf ("No 8-bpp fullscreen DIB modes found\n");
do do
{ {
@ -1057,7 +1037,7 @@ void VID_InitFullDIB (HINSTANCE hInstance)
if (nummodes != originalnummodes) if (nummodes != originalnummodes)
vid_default = MODE_FULLSCREEN_DEFAULT; vid_default = MODE_FULLSCREEN_DEFAULT;
else else
Con_SafePrintf ("No fullscreen DIB modes found\n"); Con_Printf ("No fullscreen DIB modes found\n");
} }
@ -1096,20 +1076,16 @@ void VID_CheckModedescFixup (int mode)
{ {
int x, y, stretch; int x, y, stretch;
if (mode == MODE_SETTABLE_WINDOW) if (mode == MODE_SETTABLE_WINDOW) {
{
modelist[mode].stretched = vid_stretch_by_2->int_val; modelist[mode].stretched = vid_stretch_by_2->int_val;
stretch = modelist[mode].stretched; stretch = modelist[mode].stretched;
if (vid_config_x->int_val < (320 << stretch)) Cvar_SetValue (vid_config_x, max (vid_config_x->int_val, 320 << stretch));
Cvar_SetValue (vid_config_x, 320 << stretch); Cvar_SetValue (vid_config_y, max (vid_config_y->int_val, 200 << stretch));
if (vid_config_y->int_val < (200 << stretch))
Cvar_SetValue (vid_config_y, 200 << stretch);
x = vid_config_x->int_val; x = vid_config_x->int_val;
y = vid_config_y->int_val; y = vid_config_y->int_val;
snprintf (modelist[mode].modedesc, sizeof(modelist[mode].modedesc), "%dx%d", x, y); snprintf (modelist[mode].modedesc, sizeof(modelist[mode].modedesc), "%dx%d", x, y);
modelist[mode].width = x; modelist[mode].width = x;
modelist[mode].height = y; modelist[mode].height = y;
} }
@ -1134,12 +1110,9 @@ char *VID_GetModeDescriptionMemCheck (int mode)
pv = VID_GetModePtr (mode); pv = VID_GetModePtr (mode);
pinfo = pv->modedesc; pinfo = pv->modedesc;
if (VID_CheckAdequateMem (pv->width, pv->height)) if (VID_CheckAdequateMem (pv->width, pv->height)) {
{
return pinfo; return pinfo;
} } else {
else
{
return NULL; return NULL;
} }
} }
@ -1648,11 +1621,11 @@ int VID_SetMode (int modenum, unsigned char *palette)
modenum = vid_default; modenum = vid_default;
} }
Cvar_SetValue (vid_mode, (float)modenum); Cvar_SetValue (vid_mode, modenum);
} }
else else
{ {
Cvar_SetValue (vid_mode, (float)vid_modenum); Cvar_SetValue (vid_mode, vid_modenum);
return 0; return 0;
} }
} }
@ -1739,7 +1712,7 @@ int VID_SetMode (int modenum, unsigned char *palette)
ReleaseDC(NULL,hdc); ReleaseDC(NULL,hdc);
vid_modenum = modenum; vid_modenum = modenum;
Cvar_SetValue (vid_mode, (float)vid_modenum); Cvar_SetValue (vid_mode, vid_modenum);
if (!VID_AllocBuffers (vid.width, vid.height)) if (!VID_AllocBuffers (vid.width, vid.height))
{ {
@ -1771,7 +1744,7 @@ int VID_SetMode (int modenum, unsigned char *palette)
ClearAllStates (); ClearAllStates ();
if (!msg_suppress_1) if (!msg_suppress_1)
Con_SafePrintf ("Video mode %s initialized\n", VID_GetModeDescription (vid_modenum)); Con_Printf ("Video mode %s initialized\n", VID_GetModeDescription (vid_modenum));
VID_SetPalette (palette); VID_SetPalette (palette);
@ -2122,22 +2095,6 @@ void VID_Init (unsigned char *palette)
int basenummodes; int basenummodes;
byte *ptmp; byte *ptmp;
vid_mode = Cvar_Get("vid_mode", "0", CVAR_NONE, "None");
vid_wait = Cvar_Get("vid_wait", "0", CVAR_NONE, "None");
vid_nopageflip = Cvar_Get("vid_nopageflip", "0", CVAR_ARCHIVE, "None");
_vid_wait_override = Cvar_Get("_vid_wait_override", "0", CVAR_ARCHIVE, "None");
_vid_default_mode = Cvar_Get("_vid_default_mode", "0", CVAR_ARCHIVE, "None");
_vid_default_mode_win = Cvar_Get("_vid_default_mode_win", "3", CVAR_ARCHIVE, "None");
vid_config_x = Cvar_Get("vid_config_x", "800", CVAR_ARCHIVE, "None");
vid_config_y = Cvar_Get("vid_config_y", "600", CVAR_ARCHIVE, "None");
vid_stretch_by_2 = Cvar_Get("vid_stretch_by_2", "1", CVAR_ARCHIVE, "None");
_windowed_mouse = Cvar_Get("_windowed_mouse", "0", CVAR_ARCHIVE, "None");
vid_fullscreen_mode = Cvar_Get("vid_fullscreen_mode", "3", CVAR_ARCHIVE, "None");
vid_windowed_mode = Cvar_Get("vid_windowed_mode", "0", CVAR_ARCHIVE, "None");
block_switch = Cvar_Get("block_switch", "0", CVAR_ARCHIVE, "None");
vid_window_x = Cvar_Get("vid_window_x", "0", CVAR_ARCHIVE, "None");
vid_window_y = Cvar_Get("vid_window_y", "0", CVAR_ARCHIVE, "None");
Cmd_AddCommand ("vid_testmode", VID_TestMode_f); Cmd_AddCommand ("vid_testmode", VID_TestMode_f);
Cmd_AddCommand ("vid_nummodes", VID_NumModes_f); Cmd_AddCommand ("vid_nummodes", VID_NumModes_f);
Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f); Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f);
@ -2238,6 +2195,22 @@ void VID_Init (unsigned char *palette)
strcpy (badmode.modedesc, "Bad mode"); strcpy (badmode.modedesc, "Bad mode");
} }
void VID_Init_Cvars ()
{
vid_mode = Cvar_Get("vid_mode", "0", CVAR_NONE, "None");
vid_nopageflip = Cvar_Get("vid_nopageflip", "0", CVAR_ARCHIVE, "None");
_vid_default_mode_win = Cvar_Get("_vid_default_mode_win", "3", CVAR_ARCHIVE, "None");
vid_config_x = Cvar_Get("vid_config_x", "800", CVAR_ARCHIVE, "None");
vid_config_y = Cvar_Get("vid_config_y", "600", CVAR_ARCHIVE, "None");
vid_stretch_by_2 = Cvar_Get("vid_stretch_by_2", "1", CVAR_ARCHIVE, "None");
_windowed_mouse = Cvar_Get("_windowed_mouse", "0", CVAR_ARCHIVE, "None");
vid_fullscreen_mode = Cvar_Get("vid_fullscreen_mode", "3", CVAR_ARCHIVE, "None");
vid_windowed_mode = Cvar_Get("vid_windowed_mode", "0", CVAR_ARCHIVE, "None");
block_switch = Cvar_Get("block_switch", "0", CVAR_ARCHIVE, "None");
vid_window_x = Cvar_Get("vid_window_x", "0", CVAR_ARCHIVE, "None");
vid_window_y = Cvar_Get("vid_window_y", "0", CVAR_ARCHIVE, "None");
}
void VID_Shutdown (void) void VID_Shutdown (void)
{ {
@ -2432,7 +2405,7 @@ void VID_Update (vrect_t *rects)
if (vid_mode->int_val != vid_realmode) if (vid_mode->int_val != vid_realmode)
{ {
VID_SetMode (vid_mode->int_val, vid_curpal); VID_SetMode (vid_mode->int_val, vid_curpal);
Cvar_SetValue (vid_mode, (float)vid_modenum); Cvar_SetValue (vid_mode, vid_modenum);
// so if mode set fails, we don't keep on // so if mode set fails, we don't keep on
// trying to set that mode // trying to set that mode
vid_realmode = vid_modenum; vid_realmode = vid_modenum;
@ -2939,7 +2912,7 @@ LONG WINAPI MainWndProc (
force_mode_set = false; force_mode_set = false;
} }
VID_SetMode ((int)vid_fullscreen_mode->int_val, vid_curpal); VID_SetMode (vid_fullscreen_mode->int_val, vid_curpal);
break; break;
case SC_SCREENSAVE: case SC_SCREENSAVE:
@ -3439,6 +3412,12 @@ void VID_MenuKey (int key)
void VID_SetCaption (char *text) void VID_SetCaption (char *text)
{ {
SetWindowText(mainwindow,(LPSTR) text); if (text && *text) {
char *temp = strdup (text);
SetWindowText (mainwindow, (LPSTR) va ("%s %s: %s", PROGRAM, VERSION, text));
free (temp);
} else {
SetWindowText (mainwindow, (LPSTR) va ("%s %s", PROGRAM, VERSION));
}
} }

View file

@ -1,7 +1,7 @@
/* /*
vid_null.c vid_null.c
@description@ null video driver to aid porting efforts
Copyright (C) 1996-1997 Id Software, Inc. Copyright (C) 1996-1997 Id Software, Inc.
@ -27,9 +27,9 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include <config.h>
#endif #endif
#include "quakedef.h"
#include "d_local.h" #include "d_local.h"
viddef_t vid; // global video state viddef_t vid; // global video state
@ -42,12 +42,7 @@ short zbuffer[BASEWIDTH*BASEHEIGHT];
byte surfcache[256*1024]; byte surfcache[256*1024];
unsigned short d_8to16table[256]; unsigned short d_8to16table[256];
unsigned d_8to24table[256]; unsigned int d_8to24table[256];
void
VID_InitCvars(void)
{
}
void VID_SetPalette (unsigned char *palette) void VID_SetPalette (unsigned char *palette)
{ {
@ -72,6 +67,10 @@ void VID_Init (unsigned char *palette)
D_InitCaches (surfcache, sizeof(surfcache)); D_InitCaches (surfcache, sizeof(surfcache));
} }
void VID_Init_Cvars ()
{
}
void VID_Shutdown (void) void VID_Shutdown (void)
{ {
} }
@ -99,8 +98,10 @@ void D_EndDirectRect (int x, int y, int width, int height)
{ {
} }
void VID_SetCaption (char *text)
{
void VID_HandlePause (qboolean pause) }
void VID_HandlePause (qboolean paused)
{ {
} }

View file

@ -1,5 +1,5 @@
/* /*
vid_sdl.c vid_sdl.c
Video driver for Sam Lantinga's Simple DirectMedia Layer Video driver for Sam Lantinga's Simple DirectMedia Layer
@ -30,38 +30,23 @@
#include "config.h" #include "config.h"
#endif #endif
#include "SDL.h" #include <stdlib.h>
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <SDL.h>
#include "host.h"
#include "menu.h"
#include "vid.h"
#include "sys.h"
#include "mathlib.h" // needed by: protocol.h, render.h, client.h,
// modelgen.h, glmodel.h
#include "wad.h"
#include "draw.h"
#include "cvar.h" #include "cvar.h"
#include "net.h" // needed by: client.h
#include "protocol.h" // needed by: client.h
#include "cmd.h"
#include "keys.h"
#include "sbar.h"
#include "sound.h"
#include "render.h" // needed by: client.h, gl_model.h, glquake.h
#include "client.h" // need cls in this file
#include "console.h"
#include "qendian.h"
#include "qargs.h"
#include "compat.h"
#include "d_local.h" #include "d_local.h"
#include "input.h" #include "host.h"
#include "qendian.h"
cvar_t *_windowed_mouse; #include "sys.h"
#include "va.h"
int old_windowed_mouse; #include "vid.h"
// static float oldin_grab = 0; // static float oldin_grab = 0;
cvar_t *vid_fullscreen;
extern viddef_t vid; // global video state extern viddef_t vid; // global video state
unsigned short d_8to16table[256]; unsigned short d_8to16table[256];
@ -73,6 +58,7 @@ HWND mainwindow;
int modestate; // fixme: just to avoid cross-comp. errors - remove later int modestate; // fixme: just to avoid cross-comp. errors - remove later
// The original defaults
#define BASEWIDTH 320 #define BASEWIDTH 320
#define BASEHEIGHT 200 #define BASEHEIGHT 200
@ -81,96 +67,112 @@ byte *VGA_pagebase;
static SDL_Surface *screen = NULL; static SDL_Surface *screen = NULL;
static qboolean mouse_avail; void
static float mouse_x, mouse_y; VID_InitBuffers (int width, int height)
static int mouse_oldbuttonstate = 0;
void VID_SetPalette (unsigned char *palette)
{ {
int i; int tbuffersize, tcachesize;
SDL_Color colors[256]; void *vid_surfcache;
for ( i=0; i<256; ++i ) // Calculate the sizes we want first
{ tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
colors[i].r = *palette++; tcachesize = D_SurfaceCacheForRes(width, height);
colors[i].g = *palette++;
colors[i].b = *palette++;
}
SDL_SetColors(screen, colors, 0, 256);
}
void VID_ShiftPalette (unsigned char *palette) // Free the old z-buffer
{ if (d_pzbuffer) {
VID_SetPalette(palette); free (d_pzbuffer);
} d_pzbuffer = NULL;
void VID_Init (unsigned char *palette)
{
int pnum, chunk;
byte *cache;
int cachesize;
//Uint8 video_bpp;
//Uint16 video_w, video_h;
Uint32 flags;
// Load the SDL library
if (SDL_Init(SDL_INIT_VIDEO)<0) //|SDL_INIT_AUDIO|SDL_INIT_CDROM) < 0)
Sys_Error("VID: Couldn't load SDL: %s", SDL_GetError());
// Set up display mode (width and height)
vid.width = BASEWIDTH;
vid.height = BASEHEIGHT;
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
if ((pnum=COM_CheckParm("-winsize")))
{
if (pnum >= com_argc-2)
Sys_Error("VID: -winsize <width> <height>\n");
vid.width = atoi(com_argv[pnum+1]);
vid.height = atoi(com_argv[pnum+2]);
if (!vid.width || !vid.height)
Sys_Error("VID: Bad window width/height\n");
} }
// Set video width, height and flags // Free the old surface cache
flags = (SDL_SWSURFACE|SDL_HWPALETTE); vid_surfcache = D_SurfaceCacheAddress ();
if ( COM_CheckParm ("-fullscreen") ) if (vid_surfcache) {
flags |= SDL_FULLSCREEN; D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
// Initialize display // Allocate the new z-buffer
if (!(screen = SDL_SetVideoMode(vid.width, vid.height, 8, flags))) d_pzbuffer = calloc (tbuffersize, 1);
Sys_Error("VID: Couldn't set video mode: %s\n", SDL_GetError()); if (!d_pzbuffer) {
VID_SetPalette(palette);
VID_SetCaption("SDLQuake");
// now know everything we need to know about the buffer
VGA_width = vid.conwidth = vid.width;
VGA_height = vid.conheight = vid.height;
vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
vid.numpages = 1;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
VGA_pagebase = vid.buffer = screen->pixels;
VGA_rowbytes = vid.rowbytes = screen->pitch;
vid.conbuffer = vid.buffer;
vid.conrowbytes = vid.rowbytes;
vid.direct = 0;
// allocate z buffer and surface cache
chunk = vid.width * vid.height * sizeof (*d_pzbuffer);
cachesize = D_SurfaceCacheForRes (vid.width, vid.height);
chunk += cachesize;
d_pzbuffer = Hunk_HighAllocName(chunk, "video");
if (d_pzbuffer == NULL)
Sys_Error ("Not enough memory for video mode\n"); Sys_Error ("Not enough memory for video mode\n");
}
// initialize the cache memory // Allocate the new surface cache; free the z-buffer if we fail
cache = (byte *) d_pzbuffer + vid.width * vid.height * vid_surfcache = calloc (tcachesize, 1);
sizeof (*d_pzbuffer); if (!vid_surfcache) {
D_InitCaches (cache, cachesize); free (d_pzbuffer);
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
// initialize the mouse D_InitCaches (vid_surfcache, tcachesize);
SDL_ShowCursor(0); }
void
VID_SetPalette (unsigned char *palette)
{
int i;
SDL_Color colors[256];
for ( i=0; i<256; ++i ) {
colors[i].r = *palette++;
colors[i].g = *palette++;
colors[i].b = *palette++;
}
SDL_SetColors (screen, colors, 0, 256);
}
void
VID_ShiftPalette (unsigned char *palette)
{
VID_SetPalette (palette);
}
void
VID_Init (unsigned char *palette)
{
//Uint8 video_bpp;
//Uint16 video_w, video_h;
Uint32 flags;
// Load the SDL library
if (SDL_Init(SDL_INIT_VIDEO)<0) //|SDL_INIT_AUDIO|SDL_INIT_CDROM) < 0)
Sys_Error("VID: Couldn't load SDL: %s", SDL_GetError());
// Set up display mode (width and height)
VID_GetWindowSize (BASEWIDTH, BASEHEIGHT);
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
// Set video width, height and flags
flags = (SDL_SWSURFACE|SDL_HWPALETTE);
if ( vid_fullscreen->int_val )
flags |= SDL_FULLSCREEN;
// Initialize display
if (!(screen = SDL_SetVideoMode(vid.width, vid.height, 8, flags)))
Sys_Error("VID: Couldn't set video mode: %s\n", SDL_GetError());
VID_SetPalette(palette);
VID_SetCaption("");
// now know everything we need to know about the buffer
VGA_width = vid.conwidth = vid.width;
VGA_height = vid.conheight = vid.height;
vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
vid.numpages = 1;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
VGA_pagebase = vid.buffer = screen->pixels;
VGA_rowbytes = vid.rowbytes = screen->pitch;
vid.conbuffer = vid.buffer;
vid.conrowbytes = vid.rowbytes;
vid.direct = 0;
// allocate z buffer and surface cache
VID_InitBuffers (vid.width, vid.height);
// initialize the mouse
SDL_ShowCursor(0);
#ifdef WIN32 #ifdef WIN32
// fixme: EVIL thing - but needed for win32 until we get // fixme: EVIL thing - but needed for win32 until we get
@ -178,23 +180,46 @@ void VID_Init (unsigned char *palette)
// could replace this with SDL_SysWMInfo // could replace this with SDL_SysWMInfo
mainwindow=GetActiveWindow(); mainwindow=GetActiveWindow();
#endif #endif
} }
void VID_Shutdown (void) void
VID_Init_Cvars ()
{ {
SDL_Quit(); vid_fullscreen = Cvar_Get ("vid_fullscreen", "0", CVAR_ROM, "Toggles fullscreen game mode");
} }
void VID_Update (vrect_t *rects) void
VID_Shutdown (void)
{ {
// I feel this is an improvement on Sam's code, as it does not SDL_Quit();
// calloc every frame. - DDOI }
while (rects) {
SDL_UpdateRect (screen, rects->x, rects->y, rects->width, void
rects->height); VID_Update (vrect_t *rects)
rects = rects->pnext; {
} SDL_Rect *sdlrects;
int n, i;
vrect_t *rect;
// Two-pass system, since Quake doesn't do it the SDL way...
// First, count the number of rectangles
n = 0;
for (rect = rects; rect; rect = rect->pnext)
++n;
// Second, copy them to SDL rectangles and update
if(!(sdlrects=(SDL_Rect *)calloc(1,n*sizeof(SDL_Rect))))
Sys_Error("Out of memory!");
i = 0;
for (rect = rects; rect; rect = rect->pnext) {
sdlrects[i].x = rect->x;
sdlrects[i].y = rect->y;
sdlrects[i].w = rect->width;
sdlrects[i].h = rect->height;
++i;
}
SDL_UpdateRects(screen, n, sdlrects);
} }
/* /*
@ -202,313 +227,57 @@ void VID_Update (vrect_t *rects)
D_BeginDirectRect D_BeginDirectRect
================ ================
*/ */
void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height) void
D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
{ {
Uint8 *offset; Uint8 *offset;
if (!screen) return;
if ( x < 0 ) x = screen->w+x-1; if (!screen) return;
offset = (Uint8 *)screen->pixels + y*screen->pitch + x; if ( x < 0 ) x = screen->w+x-1;
while ( height-- ) offset = (Uint8 *)screen->pixels + y*screen->pitch + x;
{ while ( height-- ) {
memcpy(offset, pbitmap, width); memcpy(offset, pbitmap, width);
offset += screen->pitch; offset += screen->pitch;
pbitmap += width; pbitmap += width;
} }
} }
/* /*
================ ================
D_EndDirectRect D_EndDirectRect
================ ================
*/ */
void D_EndDirectRect (int x, int y, int width, int height) void
D_EndDirectRect (int x, int y, int width, int height)
{ {
if (!screen) if (!screen) return;
return; if (x < 0) x = screen->w+x-1;
if (x < 0) SDL_UpdateRect(screen, x, y, width, height);
x = screen->w+x-1;
SDL_UpdateRect(screen, x, y, width, height);
} }
void
/* VID_LockBuffer ( void )
================
IN_SendKeyEvents
================
*/
void IN_SendKeyEvents (void)
{ {
SDL_Event event;
int sym, state, but;
int modstate;
while (SDL_PollEvent(&event))
{
switch (event.type) {
case SDL_KEYDOWN:
case SDL_KEYUP:
sym = event.key.keysym.sym;
state = event.key.state;
modstate = SDL_GetModState();
switch(sym)
{
case SDLK_DELETE: sym = K_DEL; break;
case SDLK_BACKSPACE: sym = K_BACKSPACE; break;
case SDLK_F1: sym = K_F1; break;
case SDLK_F2: sym = K_F2; break;
case SDLK_F3: sym = K_F3; break;
case SDLK_F4: sym = K_F4; break;
case SDLK_F5: sym = K_F5; break;
case SDLK_F6: sym = K_F6; break;
case SDLK_F7: sym = K_F7; break;
case SDLK_F8: sym = K_F8; break;
case SDLK_F9: sym = K_F9; break;
case SDLK_F10: sym = K_F10; break;
case SDLK_F11: sym = K_F11; break;
case SDLK_F12: sym = K_F12; break;
case SDLK_BREAK:
case SDLK_PAUSE: sym = K_PAUSE; break;
case SDLK_UP: sym = K_UPARROW; break;
case SDLK_DOWN: sym = K_DOWNARROW; break;
case SDLK_RIGHT: sym = K_RIGHTARROW; break;
case SDLK_LEFT: sym = K_LEFTARROW; break;
case SDLK_INSERT: sym = K_INS; break;
case SDLK_HOME: sym = K_HOME; break;
case SDLK_END: sym = K_END; break;
case SDLK_PAGEUP: sym = K_PGUP; break;
case SDLK_PAGEDOWN: sym = K_PGDN; break;
case SDLK_RSHIFT:
case SDLK_LSHIFT: sym = K_SHIFT; break;
case SDLK_RCTRL:
case SDLK_LCTRL: sym = K_CTRL; break;
case SDLK_RALT:
case SDLK_LALT: sym = K_ALT; break;
case SDLK_CAPSLOCK: sym = K_CAPSLOCK; break;
case SDLK_KP0:
if(modstate & KMOD_NUM)
sym = K_INS;
else
sym = SDLK_0;
break;
case SDLK_KP1:
if(modstate & KMOD_NUM)
sym = K_END;
else
sym = SDLK_1;
break;
case SDLK_KP2:
if(modstate & KMOD_NUM)
sym = K_DOWNARROW;
else
sym = SDLK_2;
break;
case SDLK_KP3:
if(modstate & KMOD_NUM)
sym = K_PGDN;
else
sym = SDLK_3;
break;
case SDLK_KP4:
if(modstate & KMOD_NUM)
sym = K_LEFTARROW;
else
sym = SDLK_4;
break;
case SDLK_KP5: sym = SDLK_5; break;
case SDLK_KP6:
if(modstate & KMOD_NUM)
sym = K_RIGHTARROW;
else
sym = SDLK_6;
break;
case SDLK_KP7:
if(modstate & KMOD_NUM)
sym = K_HOME;
else
sym = SDLK_7;
break;
case SDLK_KP8:
if(modstate & KMOD_NUM)
sym = K_UPARROW;
else
sym = SDLK_8;
break;
case SDLK_KP9:
if(modstate & KMOD_NUM)
sym = K_PGUP;
else
sym = SDLK_9;
break;
case SDLK_KP_PERIOD:
if(modstate & KMOD_NUM)
sym = K_DEL;
else
sym = SDLK_PERIOD;
break;
case SDLK_KP_DIVIDE: sym = SDLK_SLASH; break;
case SDLK_KP_MULTIPLY: sym = SDLK_ASTERISK; break;
case SDLK_KP_MINUS: sym = SDLK_MINUS; break;
case SDLK_KP_PLUS: sym = SDLK_PLUS; break;
case SDLK_KP_ENTER: sym = SDLK_RETURN; break;
case SDLK_KP_EQUALS: sym = SDLK_EQUALS; break;
}
// If we're not directly handled and still above
// 255 just force it to 0
if(sym > 255) sym = 0;
Key_Event(sym, state);
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
but = event.button.button;
if (but == 2)
but = 3;
else if (but == 3)
but = 2;
switch (but)
{
case 1:
case 2:
case 3:
Key_Event(K_MOUSE1 + but - 1, event.type == SDL_MOUSEBUTTONDOWN);
break;
case 4:
Key_Event(K_MWHEELUP, 1);
Key_Event(K_MWHEELUP, 0);
break;
case 5:
Key_Event(K_MWHEELDOWN, 1);
Key_Event(K_MWHEELDOWN, 0);
break;
}
break;
case SDL_MOUSEMOTION:
if (_windowed_mouse->int_val)
{
if ((event.motion.x != (vid.width/2))
|| (event.motion.y != (vid.height/2)) )
{
mouse_x = event.motion.xrel*10;
mouse_y = event.motion.yrel*10;
if ((event.motion.x < ((vid.width/2)-(vid.width/4))) || (event.motion.x > ((vid.width/2)+(vid.width/4))) || (event.motion.y < ((vid.height/2)-(vid.height/4))) || (event.motion.y > ((vid.height/2)+(vid.height/4))) )
SDL_WarpMouse(vid.width/2, vid.height/2);
}
}
else
{
mouse_x = event.motion.xrel*10;
mouse_y = event.motion.yrel*10;
}
break;
case SDL_QUIT:
CL_Disconnect ();
Sys_Quit ();
break;
default:
break;
}
}
} }
void IN_Commands (void) void
VID_UnlockBuffer ( void )
{ {
if (old_windowed_mouse != _windowed_mouse->int_val)
{
old_windowed_mouse = _windowed_mouse->int_val;
if (!_windowed_mouse->int_val)
SDL_WM_GrabInput (SDL_GRAB_OFF);
else
SDL_WM_GrabInput (SDL_GRAB_ON);
}
} }
void IN_Init (void) void
VID_SetCaption (char *text)
{ {
_windowed_mouse = Cvar_Get ("_windowed_mouse","0",CVAR_ARCHIVE,"None"); if (text && *text) {
char *temp = strdup (text);
if ( COM_CheckParm("-nomouse") && !_windowed_mouse->int_val) SDL_WM_SetCaption(va ("%s %s: %s", PROGRAM, VERSION, temp), NULL);
return; free (temp);
mouse_x = mouse_y = 0.0;
mouse_avail = 1;
}
void IN_Shutdown (void)
{
mouse_avail = 0;
}
void IN_Frame(void)
{
int i;
int mouse_buttonstate;
if (!mouse_avail) return;
i = SDL_GetMouseState(NULL, NULL);
/* Quake swaps the second and third buttons */
mouse_buttonstate = (i & ~0x06) | ((i & 0x02)<<1) |
((i & 0x04)>>1);
for (i=0 ; i<3 ; i++) {
if ( (mouse_buttonstate & (1<<i)) && !(mouse_oldbuttonstate & (1<<i)) )
Key_Event (K_MOUSE1 + i, true);
if ( !(mouse_buttonstate & (1<<i)) && (mouse_oldbuttonstate & (1<<i)) )
Key_Event (K_MOUSE1 + i, false);
}
mouse_oldbuttonstate = mouse_buttonstate;
}
void IN_Move (usercmd_t *cmd)
{
if (!mouse_avail)
return;
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
if ( (in_strafe.state & 1) || (lookstrafe->int_val && (in_mlook.state & 1) ))
cmd->sidemove += m_side->value * mouse_x;
else
cl.viewangles[YAW] -= m_yaw->value * mouse_x;
if (in_mlook.state & 1)
V_StopPitchDrift ();
if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) {
cl.viewangles[PITCH] += m_pitch->value * mouse_y;
if (cl.viewangles[PITCH] > 80)
cl.viewangles[PITCH] = 80;
if (cl.viewangles[PITCH] < -70)
cl.viewangles[PITCH] = -70;
} else { } else {
if ((in_strafe.state & 1) && noclip_anglehack) SDL_WM_SetCaption(va ("%s %s", PROGRAM, VERSION), NULL);
cmd->upmove -= m_forward->value * mouse_y;
else
cmd->forwardmove -= m_forward->value * mouse_y;
} }
mouse_x = mouse_y = 0.0;
} }
void VID_InitCvars () void VID_HandlePause (qboolean paused)
{
// It may not look like it, but this is important
}
void VID_SetCaption (char *text)
{
SDL_WM_SetCaption(text, NULL);
}
void VID_HandlePause (qboolean pause)
{
}
void IN_HandlePause (qboolean pause)
{ {
} }

View file

@ -27,91 +27,45 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" #include "config.h"
#endif #endif
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #ifdef HAVE_STRING_H
#include <signal.h> #include <string.h>
#include <values.h> #endif
#ifndef WIN32
#include "SDL.h" #include <sys/signal.h>
#endif
#include <SDL.h>
#include "compat.h" #include "compat.h"
#include "host.h"
#include "qtypes.h"
#include "qendian.h"
#include "glquake.h"
#include "cvar.h"
#include "qargs.h"
#include "console.h" #include "console.h"
#include "input.h" #include "host.h"
#include "keys.h" #include "qargs.h"
#include "menu.h" #include "qendian.h"
#include "sys.h" #include "sys.h"
#include "draw.h" #include "va.h"
#include "quakefs.h" #include "glquake.h"
#include "qdefs.h"
#define WARP_WIDTH 320 #define WARP_WIDTH 320
#define WARP_HEIGHT 200 #define WARP_HEIGHT 200
static qboolean vid_initialized = false; static qboolean vid_initialized = false;
cvar_t *vid_mode;
cvar_t *vid_fullscreen; cvar_t *vid_fullscreen;
extern cvar_t *gl_triplebuffer;
extern cvar_t *in_dga_mouseaccel;
cvar_t *_windowed_mouse;
cvar_t *m_filter;
#ifdef WIN32 #ifdef WIN32
/* fixme: this is evil hack */ /* FIXME: this is evil hack */
#include <windows.h> #include <windows.h>
HWND mainwindow; HWND mainwindow;
#endif #endif
unsigned short d_8to16table[256];
unsigned d_8to24table[256];
unsigned char d_15to8table[65536];
int scr_width, scr_height;
int VID_options_items = 1; int VID_options_items = 1;
int texture_mode = GL_LINEAR;
int texture_extension_number = 1;
float gldepthmin, gldepthmax;
cvar_t *gl_ztrick;
const char *gl_vendor;
const char *gl_renderer;
const char *gl_version;
const char *gl_extensions;
qboolean is8bit = false;
qboolean gl_mtexable = false;
int gl_mtex_enum = TEXTURE0_SGIS;
int modestate; int modestate;
static qboolean mouse_avail; extern void GL_Init_Common(void);
static float mouse_x, mouse_y; extern void VID_Init8bitPalette(void);
static float old_mouse_x, old_mouse_y; /*-----------------------------------------------------------------------*/
static float old__windowed_mouse;
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 void
VID_Shutdown (void) VID_Shutdown (void)
@ -123,6 +77,7 @@ VID_Shutdown (void)
SDL_Quit (); SDL_Quit ();
} }
#ifndef WIN32 #ifndef WIN32
static void static void
signal_handler(int sig) signal_handler(int sig)
@ -148,203 +103,26 @@ InitSig(void)
} }
#endif #endif
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;
QFile *f;
char s[256];
float dist, bestdist;
static qboolean palflag = false;
//
// 8 8 8 encoding
//
// Con_Printf("Converting 8to24\n");
pal = palette;
table = d_8to24table;
for (i=0; i<256; i++) {
r = pal[0];
g = pal[1];
b = pal[2];
pal += 3;
// 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) {
Qread(f, d_15to8table, 1<<15);
Qclose(f);
} 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;
}
snprintf (s, sizeof (s), "%s/glquake", com_gamedir);
Sys_mkdir (s);
snprintf(s, sizeof (s), "%s/glquake/15to8.pal", com_gamedir);
if ((f = Qopen (s, "wb")) != NULL) {
Qwrite (f, d_15to8table, 1<<15);
Qclose (f);
}
}
}
void
VID_ShiftPalette (unsigned char *palette)
{
VID_SetPalette(palette);
}
void void
GL_Init (void) GL_Init (void)
{ {
gl_vendor = glGetString (GL_VENDOR); GL_Init_Common();
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);
glClearColor (0,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);
/* 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);
*/
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;
} }
void void
GL_EndRendering (void) GL_EndRendering (void)
{ {
glFlush(); glFlush ();
SDL_GL_SwapBuffers (); SDL_GL_SwapBuffers ();
} }
qboolean
VID_Is8bit(void)
{
return is8bit;
}
#ifdef GL_EXT_SHARED
void
VID_Init8bitPalette (void)
{
// 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
void
VID_Init8bitPalette(void)
{
}
#endif
void void
VID_Init (unsigned char *palette) VID_Init (unsigned char *palette)
{ {
Uint32 flags = SDL_OPENGL; Uint32 flags = SDL_OPENGL;
int i; int i;
char gldir[MAX_OSPATH];
int width = 640, height = 480;
vid_mode = Cvar_Get ("vid_mode","0",0,"None"); VID_GetWindowSize (640, 480);
gl_ztrick = Cvar_Get ("gl_ztrick","0",CVAR_ARCHIVE,"None");
vid_fullscreen = Cvar_Get ("vid_fullscreen","0",0,"None");
vid.maxwarpwidth = WARP_WIDTH; vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT; vid.maxwarpheight = WARP_HEIGHT;
@ -354,15 +132,10 @@ VID_Init (unsigned char *palette)
// Interpret command-line params // Interpret command-line params
// Set vid parameters // Set vid parameters
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) if ((i = COM_CheckParm ("-conwidth")) != 0)
vid.conwidth = atoi(com_argv[i+1]); vid.conwidth = atoi(com_argv[i+1]);
else else
vid.conwidth = width; vid.conwidth = scr_width;
vid.conwidth &= 0xfff8; // make it a multiple of eight vid.conwidth &= 0xfff8; // make it a multiple of eight
if (vid.conwidth < 320) if (vid.conwidth < 320)
@ -380,7 +153,7 @@ VID_Init (unsigned char *palette)
Sys_Error ("Couldn't initialize SDL: %s\n", SDL_GetError ()); Sys_Error ("Couldn't initialize SDL: %s\n", SDL_GetError ());
// Check if we want fullscreen // Check if we want fullscreen
if (vid_fullscreen->int_val) { if (vid_fullscreen->value) {
flags |= SDL_FULLSCREEN; flags |= SDL_FULLSCREEN;
// Don't annoy Mesa/3dfx folks // Don't annoy Mesa/3dfx folks
#ifndef WIN32 #ifndef WIN32
@ -401,320 +174,61 @@ VID_Init (unsigned char *palette)
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 1); SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 1);
if (SDL_SetVideoMode (width, height, 8, flags) == NULL) { if (SDL_SetVideoMode (scr_width, scr_height, 8, flags) == NULL) {
Sys_Error ("Couldn't set video mode: %s\n", SDL_GetError ()); Sys_Error ("Couldn't set video mode: %s\n", SDL_GetError ());
SDL_Quit (); SDL_Quit ();
} }
scr_width = width; vid.height = vid.conheight = min (vid.conheight, scr_height);
scr_height = height; vid.width = vid.conwidth = min (vid.conwidth, scr_width);
vid.height = vid.conheight = min (vid.conheight, height);
vid.width = vid.conwidth = min (vid.conwidth, width);
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0); vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
vid.numpages = 2; vid.numpages = 2;
#ifndef WIN32 #ifndef WIN32
InitSig (); // trap evil signals InitSig (); // trap evil signals
#endif #endif
GL_Init(); GL_Init();
snprintf(gldir, sizeof(gldir), "%s/glquake", com_gamedir); //XXX not yet GL_CheckBrightness (palette);
Sys_mkdir (gldir);
GL_CheckGamma (palette);
VID_SetPalette (palette); VID_SetPalette (palette);
// Check for 3DFX Extensions and initialize them. // Check for 3DFX Extensions and initialize them.
VID_Init8bitPalette(); VID_Init8bitPalette();
Con_SafePrintf ("Video mode %dx%d initialized.\n", Con_Printf ("Video mode %dx%d initialized.\n",
width, height); scr_width, scr_height);
vid_initialized = true; vid_initialized = true;
#ifdef WIN32 #ifdef WIN32
// fixme: EVIL thing - but needed for win32 until we get // FIXME: EVIL thing - but needed for win32 until we get
// SDL_sound ready - without this DirectSound fails. // SDL_sound ready - without this DirectSound fails.
// could replace this with SDL_SysWMInfo // could replace this with SDL_SysWMInfo
mainwindow=GetActiveWindow(); mainwindow=GetActiveWindow();
#endif #endif
vid.recalc_refdef = 1; // force a surface cache flush vid.recalc_refdef = 1; // force a surface cache flush
} }
void VID_InitCvars()
{
gl_triplebuffer = Cvar_Get("gl_triplebuffer","1",CVAR_ARCHIVE,"None");
}
/*
================
IN_SendKeyEvents
================
*/
void void
IN_SendKeyEvents (void) VID_Init_Cvars ()
{ {
SDL_Event event; vid_fullscreen = Cvar_Get ("vid_fullscreen","0",0,"None");
int sym, state, but;
int modstate;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
case SDL_KEYUP:
sym = event.key.keysym.sym;
state = event.key.state;
modstate = SDL_GetModState ();
switch (sym) {
case SDLK_DELETE: sym = K_DEL; break;
case SDLK_BACKSPACE: sym = K_BACKSPACE; break;
case SDLK_F1: sym = K_F1; break;
case SDLK_F2: sym = K_F2; break;
case SDLK_F3: sym = K_F3; break;
case SDLK_F4: sym = K_F4; break;
case SDLK_F5: sym = K_F5; break;
case SDLK_F6: sym = K_F6; break;
case SDLK_F7: sym = K_F7; break;
case SDLK_F8: sym = K_F8; break;
case SDLK_F9: sym = K_F9; break;
case SDLK_F10: sym = K_F10; break;
case SDLK_F11: sym = K_F11; break;
case SDLK_F12: sym = K_F12; break;
case SDLK_BREAK:
case SDLK_PAUSE: sym = K_PAUSE; break;
case SDLK_UP: sym = K_UPARROW; break;
case SDLK_DOWN: sym = K_DOWNARROW; break;
case SDLK_RIGHT: sym = K_RIGHTARROW; break;
case SDLK_LEFT: sym = K_LEFTARROW; break;
case SDLK_INSERT: sym = K_INS; break;
case SDLK_HOME: sym = K_HOME; break;
case SDLK_END: sym = K_END; break;
case SDLK_PAGEUP: sym = K_PGUP; break;
case SDLK_PAGEDOWN: sym = K_PGDN; break;
case SDLK_RSHIFT:
case SDLK_LSHIFT: sym = K_SHIFT; break;
case SDLK_RCTRL:
case SDLK_LCTRL: sym = K_CTRL; break;
case SDLK_RALT:
case SDLK_LALT: sym = K_ALT; break;
case SDLK_CAPSLOCK: sym = K_CAPSLOCK; break;
case SDLK_KP0:
if (modstate & KMOD_NUM)
sym = K_INS;
else
sym = SDLK_0;
break;
case SDLK_KP1:
if (modstate & KMOD_NUM)
sym = K_END;
else
sym = SDLK_1;
break;
case SDLK_KP2:
if (modstate & KMOD_NUM)
sym = K_DOWNARROW;
else
sym = SDLK_2;
break;
case SDLK_KP3:
if (modstate & KMOD_NUM)
sym = K_PGDN;
else
sym = SDLK_3;
break;
case SDLK_KP4:
if (modstate & KMOD_NUM)
sym = K_LEFTARROW;
else
sym = SDLK_4;
break;
case SDLK_KP5: sym = SDLK_5; break;
case SDLK_KP6:
if (modstate & KMOD_NUM)
sym = K_RIGHTARROW;
else
sym = SDLK_6;
break;
case SDLK_KP7:
if (modstate & KMOD_NUM)
sym = K_HOME;
else
sym = SDLK_7;
break;
case SDLK_KP8:
if (modstate & KMOD_NUM)
sym = K_UPARROW;
else
sym = SDLK_8;
break;
case SDLK_KP9:
if (modstate & KMOD_NUM)
sym = K_PGUP;
else
sym = SDLK_9;
break;
case SDLK_KP_PERIOD:
if (modstate & KMOD_NUM)
sym = K_DEL;
else
sym = SDLK_PERIOD;
break;
case SDLK_KP_DIVIDE: sym = SDLK_SLASH; break;
case SDLK_KP_MULTIPLY: sym = SDLK_ASTERISK; break;
case SDLK_KP_MINUS: sym = SDLK_MINUS; break;
case SDLK_KP_PLUS: sym = SDLK_PLUS; break;
case SDLK_KP_ENTER: sym = SDLK_RETURN; break;
case SDLK_KP_EQUALS: sym = SDLK_EQUALS; break;
}
// If we're not directly handled and still above 255
// just force it to 0
if (sym > 255)
sym = 0;
Key_Event(sym, state);
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
but = event.button.button;
if (but == 2) {
but = 3;
} else if (but == 3) {
but = 2;
}
switch (but) {
case 1:
case 2:
case 3:
Key_Event(K_MOUSE1 + but - 1, event.type == SDL_MOUSEBUTTONDOWN);
break;
case 4:
Key_Event(K_MWHEELUP, 1);
Key_Event(K_MWHEELUP, 0);
break;
case 5:
Key_Event(K_MWHEELDOWN, 1);
Key_Event(K_MWHEELDOWN, 0);
break;
default:
break;
}
break;
case SDL_MOUSEMOTION:
if (_windowed_mouse->int_val) {
if ((event.motion.x != (vid.width/2)) ||
(event.motion.y != (vid.height/2)) ) {
mouse_x = event.motion.xrel*2;
mouse_y = event.motion.yrel*2;
if ( (event.motion.x < ((vid.width/2)-(vid.width/4))) ||
(event.motion.x > ((vid.width/2)+(vid.width/4))) ||
(event.motion.y < ((vid.height/2)-(vid.height/4))) ||
(event.motion.y > ((vid.height/2)+(vid.height/4))) ) {
SDL_WarpMouse(vid.width/2, vid.height/2);
}
}
} else {
mouse_x = event.motion.xrel*2;
mouse_y = event.motion.yrel*2;
}
break;
case SDL_QUIT:
CL_Disconnect ();
Sys_Quit ();
break;
default:
break;
}
}
}
void
IN_Init (void)
{
_windowed_mouse = Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, "Grab mouse and keyboard input");
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, "None");
if (COM_CheckParm ("-nomouse") && !_windowed_mouse->int_val)
return;
mouse_x = mouse_y = 0.0;
mouse_avail = 1;
SDL_ShowCursor (0);
SDL_WM_GrabInput (SDL_GRAB_ON);
// FIXME: disable DGA if in_dgamouse says to
}
void
IN_Shutdown (void)
{
mouse_avail = 0;
}
void
IN_Commands(void)
{
if (old__windowed_mouse != _windowed_mouse->int_val) {
old__windowed_mouse = _windowed_mouse->int_val;
if (_windowed_mouse->int_val) { // grab the pointer
SDL_ShowCursor (0);
SDL_WM_GrabInput (SDL_GRAB_ON);
} else { // ungrab the pointer
SDL_WM_GrabInput (SDL_GRAB_OFF);
SDL_ShowCursor (1);
}
}
}
void
IN_Move(usercmd_t *cmd)
{
if (!mouse_avail)
return;
if (m_filter->int_val) {
mouse_x = (mouse_x + old_mouse_x) * 0.5;
mouse_y = (mouse_y + old_mouse_y) * 0.5;
}
old_mouse_x = mouse_x;
old_mouse_y = mouse_y;
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
if ( (in_strafe.state & 1) || (lookstrafe->int_val && (in_mlook.state & 1) ))
cmd->sidemove += m_side->value * mouse_x;
else
cl.viewangles[YAW] -= m_yaw->value * mouse_x;
if (in_mlook.state & 1)
V_StopPitchDrift ();
if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) {
cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH] + (m_pitch->value * mouse_y), 80);
} else {
if ((in_strafe.state & 1) && noclip_anglehack)
cmd->upmove -= m_forward->value * mouse_y;
else
cmd->forwardmove -= m_forward->value * mouse_y;
}
mouse_x = mouse_y = 0.0;
} }
void void
VID_SetCaption (char *text) VID_SetCaption (char *text)
{ {
SDL_WM_SetCaption(text, NULL); if (text && *text) {
char *temp = strdup (text);
SDL_WM_SetCaption (va ("%s %s: %s", PROGRAM, VERSION, temp), NULL);
free (temp);
} else {
SDL_WM_SetCaption (va ("%s %s", PROGRAM, VERSION), NULL);
}
} }
void VID_HandlePause (qboolean paused)
void VID_HandlePause (qboolean pause)
{
}
void IN_HandlePause (qboolean pause)
{ {
} }

View file

@ -34,17 +34,8 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include <config.h> # include <config.h>
#endif #endif
#include "d_local.h"
#include "cvar.h"
#include "cmd.h"
#include "sys.h"
#include "console.h"
#include "host.h"
#include "input.h"
#include "qargs.h"
#include "qendian.h"
#include <stdio.h> #include <stdlib.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -56,13 +47,21 @@
#include <vga.h> #include <vga.h>
#include "cmd.h"
#include "console.h"
#include "cvar.h"
#include "d_local.h"
#include "host.h"
#include "input.h"
#include "qargs.h"
#include "qendian.h"
#include "sys.h"
void VGA_UpdatePlanarScreen (void *srcbuffer); void VGA_UpdatePlanarScreen (void *srcbuffer);
unsigned short d_8to16table[256]; unsigned short d_8to16table[256];
static byte *vid_surfcache;
static int VID_highhunkmark;
static int num_modes, current_mode; static int num_modes, current_mode;
static vga_modeinfo *modes; static vga_modeinfo *modes;
@ -359,6 +358,65 @@ get_mode(char *name, int width, int height, int depth)
} }
void
VID_InitBuffers (void)
{
int buffersize, zbuffersize, cachesize;
void *vid_surfcache;
// Calculate the sizes we want first
buffersize = vid.rowbytes * vid.height;
zbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
cachesize = D_SurfaceCacheForRes(vid.width, vid.height);
// Free the old screen buffer
if (vid.buffer) {
free (vid.buffer);
vid.conbuffer = vid.buffer = NULL;
}
// Free the old z-buffer
if (d_pzbuffer) {
free (d_pzbuffer);
d_pzbuffer = NULL;
}
// Free the old surface cache
vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) {
D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
// Allocate the new screen buffer
vid.conbuffer = vid.buffer = calloc (buffersize, 1);
if (!vid.conbuffer) {
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new z-buffer
d_pzbuffer = calloc (zbuffersize, 1);
if (!d_pzbuffer) {
free (vid.buffer);
vid.conbuffer = vid.buffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new surface cache; free the z-buffer if we fail
vid_surfcache = calloc (cachesize, 1);
if (!vid_surfcache) {
free (vid.buffer);
free (d_pzbuffer);
vid.conbuffer = vid.buffer = NULL;
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
D_InitCaches (vid_surfcache, cachesize);
}
void void
VID_Shutdown(void) VID_Shutdown(void)
{ {
@ -405,13 +463,12 @@ VID_SetPalette(byte *palette)
int int
VID_SetMode(int modenum, unsigned char *palette) VID_SetMode (int modenum, unsigned char *palette)
{ {
int bsize, zsize, tsize;
int err; int err;
if ((modenum >= num_modes) || (modenum < 0) || !modes[modenum].width){ if ((modenum >= num_modes) || (modenum < 0) || !modes[modenum].width) {
Cvar_SetValue (vid_mode, current_mode); Cvar_SetValue(vid_mode, current_mode);
Con_Printf("No such video mode: %d\n",modenum); Con_Printf("No such video mode: %d\n",modenum);
@ -420,7 +477,7 @@ VID_SetMode(int modenum, unsigned char *palette)
Cvar_SetValue (vid_mode, modenum); Cvar_SetValue (vid_mode, modenum);
current_mode=modenum; current_mode = modenum;
vid.width = modes[current_mode].width; vid.width = modes[current_mode].width;
vid.height = modes[current_mode].height; vid.height = modes[current_mode].height;
@ -446,27 +503,8 @@ VID_SetMode(int modenum, unsigned char *palette)
vid.maxwarpwidth = WARP_WIDTH; vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT; vid.maxwarpheight = WARP_HEIGHT;
/* alloc zbuffer and surface cache */ // alloc screen buffer, z-buffer, and surface cache
if (d_pzbuffer) { VID_InitBuffers ();
D_FlushCaches();
Hunk_FreeToHighMark (VID_highhunkmark);
d_pzbuffer = NULL;
vid_surfcache = NULL;
}
bsize = vid.rowbytes * vid.height;
tsize = D_SurfaceCacheForRes (vid.width, vid.height);
zsize = vid.width * vid.height * sizeof(*d_pzbuffer);
VID_highhunkmark = Hunk_HighMark ();
d_pzbuffer = Hunk_HighAllocName (bsize+tsize+zsize, "video");
vid_surfcache = ((byte *)d_pzbuffer) + zsize;
vid.conbuffer = vid.buffer = (pixel_t *)(((byte *)d_pzbuffer) + zsize + tsize);
D_InitCaches (vid_surfcache, tsize);
/* get goin' */ /* get goin' */
err = vga_setmode(current_mode); err = vga_setmode(current_mode);
@ -506,6 +544,10 @@ VID_Init(unsigned char *palette)
if (svgalib_inited) return; if (svgalib_inited) return;
#if 0
Cmd_AddCommand ("gamma", VID_Gamma_f);
#endif
if (UseDisplay) { if (UseDisplay) {
err = vga_init(); err = vga_init();
if (err) if (err)
@ -513,11 +555,6 @@ VID_Init(unsigned char *palette)
VID_InitModes(); VID_InitModes();
vid_mode = Cvar_Get ("vid_mode","5",0,"None");
vid_redrawfull = Cvar_Get ("vid_redrawfull","0",0,"None");
vid_waitforrefresh = Cvar_Get ("vid_waitforrefresh","0",
CVAR_ARCHIVE,"None");
Cmd_AddCommand("vid_nummodes", VID_NumModes_f); Cmd_AddCommand("vid_nummodes", VID_NumModes_f);
Cmd_AddCommand("vid_describemode", VID_DescribeMode_f); Cmd_AddCommand("vid_describemode", VID_DescribeMode_f);
Cmd_AddCommand("vid_describemodes", VID_DescribeModes_f); Cmd_AddCommand("vid_describemodes", VID_DescribeModes_f);
@ -558,6 +595,15 @@ VID_Init(unsigned char *palette)
/* IN_Init(); */ /* IN_Init(); */
} }
void
VID_Init_Cvars ()
{
vid_mode = Cvar_Get ("vid_mode","5",0,"None");
vid_redrawfull = Cvar_Get ("vid_redrawfull","0",0,"None");
vid_waitforrefresh = Cvar_Get ("vid_waitforrefresh","0",
CVAR_ARCHIVE,"None");
}
void void
VID_Update(vrect_t *rects) VID_Update(vrect_t *rects)
@ -692,15 +738,20 @@ VID_ExtraOptionCmd(int option_cursor)
#endif #endif
} }
void VID_InitCvars () void
VID_LockBuffer ( void )
{
}
void
VID_UnlockBuffer ( void )
{ {
// It may not look like it, but this is important
} }
void VID_SetCaption (char *text) void VID_SetCaption (char *text)
{ {
} }
void VID_HandlePause (qboolean pause) void VID_HandlePause (qboolean paused)
{ {
} }

View file

@ -30,6 +30,7 @@
# include "config.h" # include "config.h"
#endif #endif
#include "quakedef.h" #include "quakedef.h"
#include "va.h"
#include "winquake.h" #include "winquake.h"
#include "sys.h" #include "sys.h"
#include "resource.h" #include "resource.h"
@ -46,6 +47,9 @@
#include "console.h" #include "console.h"
#include "sbar.h" #include "sbar.h"
extern void (*vid_menudrawfn)(void);
extern void (*vid_menukeyfn)(int);
#define MAX_MODE_LIST 30 #define MAX_MODE_LIST 30
#define VID_ROW_SIZE 3 #define VID_ROW_SIZE 3
#define WARP_WIDTH 320 #define WARP_WIDTH 320
@ -127,7 +131,7 @@ HWND WINAPI InitializeWindow (HINSTANCE hInstance, int nCmdShow);
extern viddef_t vid; // global video state extern viddef_t vid; // global video state
unsigned short d_8to16table[256]; unsigned short d_8to16table[256];
unsigned d_8to24table[256]; unsigned int d_8to24table[256];
unsigned char d_15to8table[65536]; unsigned char d_15to8table[65536];
float gldepthmin, gldepthmax; float gldepthmin, gldepthmax;
@ -159,31 +163,11 @@ qboolean gl_mtexable = false;
//==================================== //====================================
cvar_t *vid_mode;
cvar_t *_vid_default_mode;
cvar_t *_vid_default_mode_win;
cvar_t *vid_wait;
cvar_t *vid_nopageflip;
cvar_t *_vid_wait_override;
cvar_t *vid_config_x;
cvar_t *vid_config_y;
cvar_t *vid_stretch_by_2;
cvar_t *_windowed_mouse; cvar_t *_windowed_mouse;
int window_center_x, window_center_y, window_x, window_y, window_width, window_height; int window_center_x, window_center_y, window_x, window_y, window_width, window_height;
RECT window_rect; RECT window_rect;
/*
================
VID_InitCvars
================
*/
void
VID_InitCvars ()
{
// It may not look like it, but this is important
}
// direct draw software compatability stuff // direct draw software compatability stuff
void VID_HandlePause (qboolean pause) void VID_HandlePause (qboolean pause)
@ -469,7 +453,6 @@ int VID_SetMode (int modenum, unsigned char *palette)
SetForegroundWindow (mainwindow); SetForegroundWindow (mainwindow);
VID_SetPalette (palette); VID_SetPalette (palette);
vid_modenum = modenum; vid_modenum = modenum;
Cvar_SetValue (vid_mode, (float)vid_modenum);
while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{ {
@ -489,7 +472,7 @@ int VID_SetMode (int modenum, unsigned char *palette)
ClearAllStates (); ClearAllStates ();
if (!msg_suppress_1) if (!msg_suppress_1)
Con_SafePrintf ("Video mode %s initialized.\n", VID_GetModeDescription (vid_modenum)); Con_Printf ("Video mode %s initialized.\n", VID_GetModeDescription (vid_modenum));
VID_SetPalette (palette); VID_SetPalette (palette);
@ -647,6 +630,8 @@ void GL_Init (void)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 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_MODULATE);
@ -712,15 +697,16 @@ void GL_EndRendering (void)
Sbar_Changed(); Sbar_Changed();
} }
void VID_SetPalette (unsigned char *palette) void
VID_SetPalette (unsigned char *palette)
{ {
byte *pal; byte *pal;
unsigned r,g,b; unsigned int r,g,b;
unsigned v; unsigned int v;
int r1,g1,b1; int r1,g1,b1;
int k; int k;
unsigned short i; unsigned short i;
unsigned *table; unsigned int *table;
QFile *f; QFile *f;
char s[255]; char s[255];
float dist, bestdist; float dist, bestdist;
@ -1538,7 +1524,7 @@ void VID_InitFullDIB (HINSTANCE hInstance)
} while (!done); } while (!done);
if (nummodes == originalnummodes) if (nummodes == originalnummodes)
Con_SafePrintf ("No fullscreen DIB modes found\n"); Con_Printf ("No fullscreen DIB modes found\n");
} }
qboolean VID_Is8bit() { qboolean VID_Is8bit() {
@ -1559,7 +1545,7 @@ void VID_Init8bitPalette()
COM_CheckParm("-no8bit")) COM_CheckParm("-no8bit"))
return; return;
Con_SafePrintf("8-bit GL extensions enabled.\n"); Con_Printf("8-bit GL extensions enabled.\n");
glEnable( GL_SHARED_TEXTURE_PALETTE_EXT ); glEnable( GL_SHARED_TEXTURE_PALETTE_EXT );
oldPalette = (char *) d_8to24table; //d_8to24table3dfx; oldPalette = (char *) d_8to24table; //d_8to24table3dfx;
newPalette = thePalette; newPalette = thePalette;
@ -1589,20 +1575,6 @@ void VID_Init (unsigned char *palette)
memset(&devmode, 0, sizeof(devmode)); memset(&devmode, 0, sizeof(devmode));
// Note that 0 is MODE_WINDOWED
vid_mode = Cvar_Get("vid_mode", "0", CVAR_NONE, "None");
_vid_default_mode = Cvar_Get("_vid_default_mode", "0", CVAR_ARCHIVE, "None");
// Note that 3 is MODE_FULLSCREEN_DEFAULT
_vid_default_mode_win = Cvar_Get("_vid_default_mode_win", "3", CVAR_ARCHIVE, "None");
vid_wait = Cvar_Get("vid_wait", "0", CVAR_NONE, "None");
vid_nopageflip = Cvar_Get("vid_nopageflip", "0", CVAR_ARCHIVE, "None");
_vid_wait_override = Cvar_Get("_vid_wait_override", "0", CVAR_ARCHIVE, "None");
vid_config_x = Cvar_Get("vid_config_x", "800", CVAR_ARCHIVE, "None");
vid_config_y = Cvar_Get("vid_config_y", "600", CVAR_ARCHIVE, "None");
vid_stretch_by_2 = Cvar_Get("vid_stretch_by_2", "1", CVAR_ARCHIVE, "None");
_windowed_mouse = Cvar_Get("_windowed_mouse", "0", CVAR_ARCHIVE, "None");
Cmd_AddCommand ("vid_nummodes", VID_NumModes_f); Cmd_AddCommand ("vid_nummodes", VID_NumModes_f);
Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f); Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f);
Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f); Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f);
@ -1806,7 +1778,7 @@ void VID_Init (unsigned char *palette)
DestroyWindow (hwnd_dialog); DestroyWindow (hwnd_dialog);
GL_CheckGamma(palette); GL_CheckBrightness (palette);
VID_SetPalette (palette); VID_SetPalette (palette);
VID_SetMode (vid_default, palette); VID_SetMode (vid_default, palette);
@ -1840,6 +1812,12 @@ void VID_Init (unsigned char *palette)
fullsbardraw = false; fullsbardraw = false;
} }
void
VID_Init_Cvars ()
{
_windowed_mouse = Cvar_Get("_windowed_mouse", "0", CVAR_ARCHIVE, "None");
}
//======================================================== //========================================================
// Video menu stuff // Video menu stuff
@ -1959,5 +1937,11 @@ void VID_MenuKey (int key)
void VID_SetCaption (char *text) void VID_SetCaption (char *text)
{ {
SetWindowText(mainwindow,(LPSTR) text); if (text && *text) {
char *temp = strdup (text);
SetWindowText(mainwindow,(LPSTR) va ("%s %s: %s", PROGRAM, VERSION, temp));
free (temp);
} else {
SetWindowText(mainwindow,(LPSTR) va ("%s %s", PROGRAM, VERSION));
}
} }

View file

@ -63,10 +63,12 @@
#include "input.h" #include "input.h"
#include "draw.h" #include "draw.h"
#include "console.h" #include "console.h"
#include "va.h"
#include "client.h" #include "client.h"
#include "host.h"
#include "input.h" #include "input.h"
#include "context_x11.h" #include "context_x11.h"
#include "host.h"
#ifdef HAVE_VIDMODE #ifdef HAVE_VIDMODE
# include <X11/extensions/xf86vmode.h> # include <X11/extensions/xf86vmode.h>
#endif #endif
@ -97,8 +99,6 @@ int VID_options_items = 1;
static byte current_palette[768]; static byte current_palette[768];
cvar_t *vid_fullscreen;
typedef unsigned short PIXEL16; typedef unsigned short PIXEL16;
typedef unsigned long PIXEL24; typedef unsigned long PIXEL24;
static PIXEL16 st2d_8to16table[256]; static PIXEL16 st2d_8to16table[256];
@ -107,9 +107,8 @@ static int shiftmask_fl=0;
static long r_shift,g_shift,b_shift; static long r_shift,g_shift,b_shift;
static unsigned long r_mask,g_mask,b_mask; static unsigned long r_mask,g_mask,b_mask;
static long X11_highhunkmark; cvar_t *vid_width;
cvar_t *vid_height;
int scr_width, scr_height;
static void static void
shiftmask_init( void ) shiftmask_init( void )
@ -299,38 +298,48 @@ void VID_Gamma_f (void)
static void static void
ResetFrameBuffer(void) ResetFrameBuffer(void)
{ {
int vid_surfcachesize, buffersize; int tbuffersize, tcachesize;
void *vid_surfcache;
int mem, pwidth; void *vid_surfcache;
int mem, pwidth;
// Calculate the sizes we want first
tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
tcachesize = D_SurfaceCacheForRes(vid.width, vid.height);
if (x_framebuffer[0]) { if (x_framebuffer[0]) {
XDestroyImage(x_framebuffer[0]); XDestroyImage(x_framebuffer[0]);
} }
// Free the old z-buffer
if (d_pzbuffer) { if (d_pzbuffer) {
D_FlushCaches (); free (d_pzbuffer);
Hunk_FreeToHighMark(X11_highhunkmark);
d_pzbuffer = NULL; d_pzbuffer = NULL;
} }
X11_highhunkmark = Hunk_HighMark ();
/* Alloc an extra line in case we want to wrap, and allocate // Free the old surface cache
the z-buffer */ vid_surfcache = D_SurfaceCacheAddress ();
buffersize = vid.width * vid.height * sizeof(*d_pzbuffer); if (vid_surfcache) {
D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
vid_surfcachesize = D_SurfaceCacheForRes(vid.width, vid.height); // Allocate the new z-buffer
d_pzbuffer = calloc (tbuffersize, 1);
buffersize += vid_surfcachesize; if (!d_pzbuffer) {
d_pzbuffer = Hunk_HighAllocName(buffersize, "video");
if (d_pzbuffer == NULL) {
Sys_Error ("Not enough memory for video mode\n"); Sys_Error ("Not enough memory for video mode\n");
} }
vid_surfcache = (byte *) d_pzbuffer // Allocate the new surface cache; free the z-buffer if we fail
+ vid.width * vid.height * sizeof(*d_pzbuffer); vid_surfcache = calloc (tcachesize, 1);
if (!vid_surfcache) {
free (d_pzbuffer);
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
D_InitCaches(vid_surfcache, vid_surfcachesize); D_InitCaches (vid_surfcache, tcachesize);
pwidth = x_visinfo->depth / 8; pwidth = x_visinfo->depth / 8;
if (pwidth == 3) pwidth = 4; if (pwidth == 3) pwidth = 4;
@ -351,53 +360,59 @@ ResetFrameBuffer(void)
static void static void
ResetSharedFrameBuffers(void) ResetSharedFrameBuffers(void)
{ {
int vid_surfcachesize, buffersize; int tbuffersize, tcachesize;
void *vid_surfcache; void *vid_surfcache;
int size; int size;
int key; int key;
int minsize = getpagesize(); int minsize = getpagesize();
int frm; int frm;
if (d_pzbuffer) { // Calculate the sizes we want first
D_FlushCaches (); tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
Hunk_FreeToHighMark(X11_highhunkmark); tcachesize = D_SurfaceCacheForRes(vid.width, vid.height);
// Free the old z-buffer
if (d_pzbuffer) {
free (d_pzbuffer);
d_pzbuffer = NULL; d_pzbuffer = NULL;
} }
X11_highhunkmark = Hunk_HighMark (); // Free the old surface cache
vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) {
D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
// alloc an extra line in case we want to wrap, and allocate the z-buffer // Allocate the new z-buffer
buffersize = vid.width * vid.height * sizeof (*d_pzbuffer); d_pzbuffer = calloc (tbuffersize, 1);
if (!d_pzbuffer) {
vid_surfcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
buffersize += vid_surfcachesize;
d_pzbuffer = Hunk_HighAllocName(buffersize, "video");
if (d_pzbuffer == NULL) {
Sys_Error ("Not enough memory for video mode\n"); Sys_Error ("Not enough memory for video mode\n");
} }
vid_surfcache = (byte *) d_pzbuffer // Allocate the new surface cache; free the z-buffer if we fail
+ vid.width * vid.height * sizeof (*d_pzbuffer); vid_surfcache = calloc (tcachesize, 1);
if (!vid_surfcache) {
free (d_pzbuffer);
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
D_InitCaches(vid_surfcache, vid_surfcachesize); D_InitCaches (vid_surfcache, tcachesize);
for (frm=0 ; frm<2 ; frm++) for (frm=0 ; frm<2 ; frm++) {
{
// free up old frame buffer memory // free up old frame buffer memory
if (x_framebuffer[frm]) {
if (x_framebuffer[frm])
{
XShmDetach(x_disp, &x_shminfo[frm]); XShmDetach(x_disp, &x_shminfo[frm]);
free(x_framebuffer[frm]); free(x_framebuffer[frm]);
shmdt(x_shminfo[frm].shmaddr); shmdt(x_shminfo[frm].shmaddr);
} }
// create the image // create the image
x_framebuffer[frm] = XShmCreateImage (x_disp,
x_framebuffer[frm] = XShmCreateImage( x_disp,
x_vis, x_vis,
x_visinfo->depth, x_visinfo->depth,
ZPixmap, ZPixmap,
@ -406,10 +421,10 @@ ResetSharedFrameBuffers(void)
vid.width, vid.width,
vid.height ); vid.height );
// grab shared memory // grab shared memory
size = x_framebuffer[frm]->bytes_per_line size = x_framebuffer[frm]->bytes_per_line
* x_framebuffer[frm]->height; * x_framebuffer[frm]->height;
if (size < minsize) if (size < minsize)
Sys_Error("VID: Window must use at least %d bytes\n", minsize); Sys_Error("VID: Window must use at least %d bytes\n", minsize);
@ -427,8 +442,7 @@ ResetSharedFrameBuffers(void)
x_framebuffer[frm]->data = x_shminfo[frm].shmaddr; x_framebuffer[frm]->data = x_shminfo[frm].shmaddr;
// get the X server to attach to it // get the X server to attach to it
if (!XShmAttach(x_disp, &x_shminfo[frm])) if (!XShmAttach(x_disp, &x_shminfo[frm]))
Sys_Error("VID: XShmAttach() failed\n"); Sys_Error("VID: XShmAttach() failed\n");
XSync(x_disp, 0); XSync(x_disp, 0);
@ -455,57 +469,32 @@ void VID_Init (unsigned char *palette)
int num_visuals; int num_visuals;
int template_mask; int template_mask;
VID_GetWindowSize (320, 200);
//plugin_load("in_x11.so"); //plugin_load("in_x11.so");
vid_fullscreen = Cvar_Get ("vid_fullscreen","0",CVAR_NONE,
"Toggles fullscreen game mode");
// Cmd_AddCommand("gamma", VID_Gamma_f); // Cmd_AddCommand("gamma", VID_Gamma_f);
for (i=0; i < 256; i++) vid_gamma[i] = i; for (i=0; i < 256; i++) vid_gamma[i] = i;
vid.width = 320; vid.width = vid_width->int_val;
vid.height = 200; vid.height = vid_height->int_val;
vid.maxwarpwidth = WARP_WIDTH; vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT; vid.maxwarpheight = WARP_HEIGHT;
vid.numpages = 2; vid.numpages = 2;
vid.colormap = host_colormap; vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048)); vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
//vid.cbits = VID_CBITS;
//vid.grades = VID_GRADES;
srandom(getpid()); srandom(getpid());
verbose=COM_CheckParm("-verbose"); verbose=COM_CheckParm("-verbose");
// open the display // open the display
x11_open_display(); x11_open_display();
// check for command-line window size // check for command-line window size
if ((pnum=COM_CheckParm("-winsize")))
{
if (pnum >= com_argc-2)
Sys_Error("VID: -winsize <width> <height>\n");
vid.width = atoi(com_argv[pnum+1]);
vid.height = atoi(com_argv[pnum+2]);
if (!vid.width || !vid.height)
Sys_Error("VID: Bad window width/height\n");
}
if ((pnum=COM_CheckParm("-width"))) {
if (pnum >= com_argc-1)
Sys_Error("VID: -width <width>\n");
vid.width = atoi(com_argv[pnum+1]);
if (!vid.width)
Sys_Error("VID: Bad window width\n");
}
if ((pnum=COM_CheckParm("-height"))) {
if (pnum >= com_argc-1)
Sys_Error("VID: -height <height>\n");
vid.height = atoi(com_argv[pnum+1]);
if (!vid.height)
Sys_Error("VID: Bad window height\n");
}
template_mask = 0; template_mask = 0;
// specify a visual id // specify a visual id
if ((pnum=COM_CheckParm("-visualid"))) if ((pnum=COM_CheckParm("-visualid")))
{ {
if (pnum >= com_argc-1) if (pnum >= com_argc-1)
@ -513,8 +502,7 @@ void VID_Init (unsigned char *palette)
template.visualid = atoi(com_argv[pnum+1]); template.visualid = atoi(com_argv[pnum+1]);
template_mask = VisualIDMask; template_mask = VisualIDMask;
} }
// If not specified, use default visual
// If not specified, use default visual
else else
{ {
template.visualid = template.visualid =
@ -522,7 +510,7 @@ void VID_Init (unsigned char *palette)
template_mask = VisualIDMask; template_mask = VisualIDMask;
} }
// pick a visual- warn if more than one was available // pick a visual- warn if more than one was available
x_visinfo = XGetVisualInfo(x_disp, template_mask, &template, &num_visuals); x_visinfo = XGetVisualInfo(x_disp, template_mask, &template, &num_visuals);
x_vis = x_visinfo->visual; x_vis = x_visinfo->visual;
@ -561,9 +549,6 @@ void VID_Init (unsigned char *palette)
/* Invisible cursor */ /* Invisible cursor */
x11_create_null_cursor(); x11_create_null_cursor();
scr_width = vid.width;
scr_height = vid.height;
if (x_visinfo->depth == 8) { if (x_visinfo->depth == 8) {
/* Create and upload the palette */ /* Create and upload the palette */
if (x_visinfo->class == PseudoColor) { if (x_visinfo->class == PseudoColor) {
@ -574,7 +559,7 @@ void VID_Init (unsigned char *palette)
} }
} }
// create the GC // create the GC
{ {
XGCValues xgcvalues; XGCValues xgcvalues;
int valuemask = GCGraphicsExposures; int valuemask = GCGraphicsExposures;
@ -582,12 +567,9 @@ void VID_Init (unsigned char *palette)
x_gc = XCreateGC(x_disp, x_win, valuemask, &xgcvalues ); x_gc = XCreateGC(x_disp, x_win, valuemask, &xgcvalues );
} }
// map the window
XMapWindow(x_disp, x_win);
XRaiseWindow(x_disp, x_win);
x11_grab_keyboard(); x11_grab_keyboard();
// wait for first exposure event // wait for first exposure event
{ {
XEvent event; XEvent event;
do do
@ -597,9 +579,9 @@ void VID_Init (unsigned char *palette)
oktodraw = true; oktodraw = true;
} while (!oktodraw); } while (!oktodraw);
} }
// now safe to draw // now safe to draw
// even if MITSHM is available, make sure it's a local connection // even if MITSHM is available, make sure it's a local connection
if (XShmQueryExtension(x_disp)) if (XShmQueryExtension(x_disp))
//if (0) //if (0)
{ {
@ -638,6 +620,12 @@ void VID_Init (unsigned char *palette)
x11_add_event(x_shmeventtype, event_shm); x11_add_event(x_shmeventtype, event_shm);
} }
void
VID_Init_Cvars ()
{
x11_Init_Cvars();
}
void void
VID_ShiftPalette(unsigned char *p) VID_ShiftPalette(unsigned char *p)
@ -685,7 +673,6 @@ VID_Shutdown(void)
if (x_disp) { if (x_disp) {
x11_restore_vidmode(); x11_restore_vidmode();
x11_close_display(); x11_close_display();
x_disp = 0;
} }
} }
@ -780,7 +767,7 @@ VID_DitherOn( void )
void void
VID_DitherOff( void ) VID_DitherOff (void)
{ {
if (dither) { if (dither) {
vid.recalc_refdef = 1; vid.recalc_refdef = 1;
@ -788,15 +775,28 @@ VID_DitherOff( void )
} }
} }
void VID_InitCvars () void
{ VID_LockBuffer ( void )
// It may not look like it, but this is important
}
void VID_SetCaption (char *text)
{ {
} }
void VID_HandlePause (qboolean pause) void
VID_UnlockBuffer ( void )
{
}
void
VID_SetCaption (char *text)
{
if (text && *text) {
char *temp = strdup (text);
x11_set_caption (va ("%s %s: %s", PROGRAM, VERSION, temp));
free (temp);
} else {
x11_set_caption (va ("%s %s", PROGRAM, VERSION));
}
}
void VID_HandlePause (qboolean paused)
{ {
} }