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 "qdefs.h"
typedef struct
typedef struct usercmd_s
{
vec3_t viewangles;
@ -287,6 +287,7 @@ extern cvar_t *cl_sbar;
extern cvar_t *cl_hudswap;
extern cvar_t *cl_pitchdriftspeed;
extern cvar_t *cl_freelook;
extern cvar_t *lookspring;
extern cvar_t *lookstrafe;
extern cvar_t *sensitivity;

View file

@ -31,32 +31,38 @@
#ifndef __CONTEXT_X11_H__
#define __CONTEXT_X11_H__
#include <qtypes.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "cvar.h"
#include "qtypes.h"
void GetEvent( void );
extern Display *x_disp;
extern Display *x_disp;
extern int x_screen;
extern Window x_root;
extern XVisualInfo *x_visinfo;
extern Visual *x_vis;
extern Window x_win;
extern qboolean doShm;
extern int x_shmeventtype;
extern qboolean oktodraw;
extern Window x_win;
extern qboolean doShm;
extern int x_shmeventtype;
extern qboolean oktodraw;
extern cvar_t *vid_fullscreen;
qboolean x11_add_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_events( void );
void x11_open_display( void );
void x11_close_display( void );
void x11_create_null_cursor(void);
void x11_set_vidmode(int width, int height);
void x11_restore_vidmode(void);
void x11_create_window(int width, int height);
void x11_grab_keyboard(void);
qboolean x11_add_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_events (void);
void x11_open_display (void);
void x11_close_display (void);
void x11_create_null_cursor (void);
void x11_set_vidmode (int, int);
void x11_restore_vidmode (void);
void x11_create_window (int, int);
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__

View file

@ -3,9 +3,8 @@
Definitions for XFree86 DGA and VidMode support
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
Copyright (C) 2000 contributors of the QuakeForge project
Please see the file "AUTHORS" for a list of contributors
Copyright (C) 2000 Jeff Teunissen <deek@dusknet.dhs.org>
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
@ -28,21 +27,19 @@
$Id$
*/
#ifndef __dga_check_h
#define __dga_check_h
#ifndef __dga_check_h_
#define __dga_check_h_
#include <X11/Xlib.h>
#include "cvar.h"
extern cvar_t *vid_dga_mouseaccel;
#include "qtypes.h"
/*
VID_CheckDGA
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
*/
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
@description@
External (non-keyboard) input devices
Copyright (C) 1996-1997 Id Software, Inc.
@ -26,30 +26,35 @@
$Id$
*/
#ifndef __input_h
#define __input_h
#ifndef _INPUT_H
#define _INPUT_H
#include "client.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_Cvars (void);
void IN_Shutdown (void);
void IN_Commands (void);
// 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
void IN_ClearStates (void);
// restores all button and position states to defaults
void IN_ModeChanged (void);
// 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.
*/
void JOY_Init (void);
void JOY_Init_Cvars (void);
/*
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 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_DeleteSurfaceCache (void);
void D_InitCaches (void *buffer, int size);

View file

@ -1,7 +1,7 @@
/*
vid.h
@description@
video driver defs
Copyright (C) 1996-1997 Id Software, Inc.
@ -26,83 +26,79 @@
$Id$
*/
#ifndef __vid_h
#define __vid_h
#ifndef __vid_h_
#define __vid_h_
#include "qtypes.h"
#define VID_CBITS 6
#define VID_GRADES (1 << VID_CBITS)
typedef struct vrect_s
{
typedef struct vrect_s {
int x,y,width,height;
struct vrect_s *pnext;
} vrect_t;
typedef struct
{
typedef struct {
pixel_t *buffer; // invisible buffer
pixel_t *colormap; // 256 * VID_GRADES size
unsigned short *colormap16; // 256 * VID_GRADES size
int fullbright; // index of first fullbright color
unsigned rowbytes; // may be > width if displayed in a window
unsigned width;
unsigned height;
float aspect; // width / height -- < 0 is taller than wide
unsigned int rowbytes; // may be > width if displayed in a window
unsigned int width;
unsigned int height;
float aspect; // width / height -- < 0 is taller than wide
int numpages;
int recalc_refdef; // if true, recalc vid-based stuff
pixel_t *conbuffer;
int conrowbytes;
unsigned conwidth;
unsigned conheight;
unsigned int conwidth;
unsigned int conheight;
int maxwarpwidth;
int maxwarpheight;
pixel_t *direct; // direct drawing to framebuffer, if not
// NULL
} viddef_t;
extern viddef_t vid; // global video state
extern unsigned short d_8to16table[256];
extern unsigned d_8to24table[256];
extern void (*vid_menudrawfn)(void);
extern void (*vid_menukeyfn)(int key);
extern viddef_t vid; // global video state
extern unsigned short d_8to16table[256];
extern unsigned int d_8to24table[256];
extern int scr_width, scr_height;
qboolean VID_Is8bit(void);
void VID_SetPalette (unsigned char *palette);
// 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
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
// the palette data will go away after the call, so it must be copied off if
// the video driver will need it again
void VID_Init (unsigned char *);
void VID_Shutdown (void);
// Called at shutdown
void VID_Shutdown (void);
void VID_Update (vrect_t *rects);
// 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
// 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
void VID_HandlePause (qboolean pause);
void VID_LockBuffer (void);
void VID_UnlockBuffer (void);
qboolean VID_Is8bit (void);
void VID_SetCaption (char *text);
// used to set window caption
#if defined(_WIN32) && !defined(WINDED)
void VID_LockBuffer (void);
void VID_UnlockBuffer (void);
#else
#define VID_LockBuffer()
#define VID_UnlockBuffer()
#endif
void VID_GetWindowSize (int def_w, int def_h);
#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 \
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 \
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 \
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
#
sdl_SOURCES= vid_sdl.c
sdl_SOURCES= vid_sdl.c in_sdl.c
nuq_sdl_SOURCES= $(combined_SOURCES) $(soft_SOURCES) $(sdl_SOURCES)
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
#
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_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
#
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_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
#

View file

@ -55,6 +55,7 @@ cvar_t *cl_nolerp;
cvar_t *cl_sbar;
cvar_t *cl_hudswap;
cvar_t *cl_freelook;
cvar_t *lookspring;
cvar_t *lookstrafe;
cvar_t *sensitivity;
@ -101,6 +102,7 @@ CL_InitCvars(void)
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_freelook = Cvar_Get("freelook", "0", CVAR_ARCHIVE, "force +mlook");
lookspring = Cvar_Get("lookspring", "0", CVAR_ARCHIVE, "None");
lookstrafe = Cvar_Get("lookstrafe", "0", CVAR_ARCHIVE, "None");
sensitivity = Cvar_Get("sensitivity", "3", CVAR_ARCHIVE, "None");

View file

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
/*
in_null.c
@description@
for systems without a mouse
Copyright (C) 1996-1997 Id Software, Inc.
@ -27,14 +27,18 @@
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
# include <config.h>
#endif
#include "quakedef.h"
void IN_Init (void)
{
}
void IN_Init_Cvars (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
# include "config.h"
#include "config.h"
#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 <stdlib.h>
#ifdef HAVE_UNISTD_H
@ -54,6 +43,19 @@
#include <vgakeyboard.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 UseMouse = 1;
@ -72,7 +74,6 @@ static void IN_init_mouse();
cvar_t *_windowed_mouse;
cvar_t *m_filter;
static cvar_t *mouse_button_commands[3];
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("-nomouse")) UseMouse = 0;
@ -120,10 +122,18 @@ int IN_Init(void)
JOY_Init();
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;
@ -237,22 +247,19 @@ static void IN_init_kb()
scantokey[111] = K_DEL;
scantokey[119] = K_PAUSE;
if (keyboard_init()) {
Sys_Error("keyboard_init() failed");
if (keyboard_init ()) {
Sys_Error ("keyboard_init() failed");
}
keyboard_seteventhandler(keyhandler);
}
static void IN_init_mouse()
static void
IN_init_mouse()
{
int mtype;
char *mousedev;
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);
mouse_buttons = 3;
@ -363,23 +370,18 @@ void IN_Move(usercmd_t *cmd)
mouse_y *= sensitivity->value;
/* 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;
} else {
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;
if (cl.viewangles[PITCH] > 80) {
cl.viewangles[PITCH] = 80;
}
if (cl.viewangles[PITCH] < -70) {
cl.viewangles[PITCH] = -70;
}
cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
} else {
if ((in_strafe.state & 1) && noclip_anglehack) {
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
@description@
windows 95 mouse and joystick code
Copyright (C) 1996-1997 Id Software, Inc.
@ -26,13 +26,24 @@
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
// 02/21/97 JCB Added extended DirectInput code to support external controllers.
#include <dinput.h>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef __MINGW32__
# define INITGUID
#endif
#include "quakedef.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 iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
@ -40,31 +51,33 @@
HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion,
LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
// mouse variables
cvar_t *m_filter;
// mouse public variables
int mouse_buttons;
int mouse_oldbuttonstate;
POINT current_pos;
int mouse_x, mouse_y, old_mouse_x, old_mouse_y, mx_accum, my_accum;
float mouse_x, mouse_y;
qboolean mouseactive;
unsigned int uiWheelMessage;
static qboolean restore_spi;
static int originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
// mouse local variables
unsigned int uiWheelMessage;
qboolean mouseactive;
qboolean mouseinitialized;
static qboolean mouseparmsvalid, mouseactivatetoggle;
static qboolean mouseshowtoggle = 1;
static qboolean dinput_acquired;
static unsigned int mstate_di;
static int mouse_buttons;
static int mouse_oldbuttonstate;
static POINT current_pos;
static float old_mouse_x, old_mouse_y, mx_accum, my_accum;
static qboolean mouseinitialized;
static cvar_t *m_filter;
static qboolean restore_spi;
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
// where should defines be moved?
#define JOY_ABSOLUTE_AXIS 0x00000000 // control like a joystick
#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_Y 1
#define JOY_AXIS_Z 2
@ -77,46 +90,47 @@ enum _ControlList
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
};
DWORD dwAxisMap[JOY_MAX_AXES];
DWORD dwControlMap[JOY_MAX_AXES];
PDWORD pdwRawValue[JOY_MAX_AXES];
static DWORD dwAxisMap[JOY_MAX_AXES];
static DWORD dwControlMap[JOY_MAX_AXES];
static PDWORD pdwRawValue[JOY_MAX_AXES];
// none of these cvars are saved over a session
// this means that advanced controller configuration needs to be executed
// 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
// works.
cvar_t *in_joystick;
cvar_t *joy_name;
cvar_t *joy_advanced;
cvar_t *joy_advaxisx;
cvar_t *joy_advaxisy;
cvar_t *joy_advaxisz;
cvar_t *joy_advaxisr;
cvar_t *joy_advaxisu;
cvar_t *joy_advaxisv;
cvar_t *joy_forwardthreshold;
cvar_t *joy_sidethreshold;
cvar_t *joy_pitchthreshold;
cvar_t *joy_yawthreshold;
cvar_t *joy_forwardsensitivity;
cvar_t *joy_sidesensitivity;
cvar_t *joy_pitchsensitivity;
cvar_t *joy_yawsensitivity;
cvar_t *joy_wwhack1;
cvar_t *joy_wwhack2;
static cvar_t *in_joystick;
static cvar_t *joy_name;
static cvar_t *joy_advanced;
static cvar_t *joy_advaxisx;
static cvar_t *joy_advaxisy;
static cvar_t *joy_advaxisz;
static cvar_t *joy_advaxisr;
static cvar_t *joy_advaxisu;
static cvar_t *joy_advaxisv;
static cvar_t *joy_forwardthreshold;
static cvar_t *joy_sidethreshold;
static cvar_t *joy_pitchthreshold;
static cvar_t *joy_yawthreshold;
static cvar_t *joy_forwardsensitivity;
static cvar_t *joy_sidesensitivity;
static cvar_t *joy_pitchsensitivity;
static cvar_t *joy_yawsensitivity;
static cvar_t *joy_wwhack1;
static cvar_t *joy_wwhack2;
qboolean joy_avail, joy_advancedinit, joy_haspov;
DWORD joy_oldbuttonstate, joy_oldpovstate;
static qboolean joy_avail, joy_advancedinit, joy_haspov;
static DWORD joy_oldbuttonstate, joy_oldpovstate;
static int joy_id;
static DWORD joy_flags;
static DWORD joy_numbuttons;
int joy_id;
DWORD joy_flags;
DWORD joy_numbuttons;
// misc locals
static LPDIRECTINPUT g_pdi;
static LPDIRECTINPUTDEVICE g_pMouse;
@ -158,18 +172,17 @@ static DIDATAFORMAT df = {
rgodf, // and here they are
};
// forward-referenced functions
void IN_StartupJoystick (void);
void Joy_AdvancedUpdate_f (void);
void IN_JoyMove (usercmd_t *cmd);
// forward-referenced functions, locals
static void IN_StartupJoystick (void);
static void Joy_AdvancedUpdate_f (void);
static void IN_JoyMove (usercmd_t *cmd);
/*
===========
Force_CenterView_f
===========
*/
void Force_CenterView_f (void)
static void Force_CenterView_f (void)
{
cl.viewangles[PITCH] = 0;
}
@ -301,12 +314,12 @@ void IN_DeactivateMouse (void)
}
else
{
if (restore_spi)
SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
if (restore_spi)
SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
ClipCursor (NULL);
ReleaseCapture ();
}
ClipCursor (NULL);
ReleaseCapture ();
}
mouseactive = false;
}
@ -338,7 +351,7 @@ void IN_RestoreOriginalMouseState (void)
IN_InitDInput
===========
*/
qboolean IN_InitDInput (void)
static qboolean IN_InitDInput (void)
{
HRESULT hr;
DIPROPDWORD dipdw = {
@ -357,7 +370,7 @@ qboolean IN_InitDInput (void)
if (hInstDI == NULL)
{
Con_SafePrintf ("Couldn't load dinput.dll\n");
Con_Printf ("Couldn't load dinput.dll\n");
return false;
}
}
@ -368,7 +381,7 @@ qboolean IN_InitDInput (void)
if (!pDirectInputCreate)
{
Con_SafePrintf ("Couldn't get DI proc addr\n");
Con_Printf ("Couldn't get DI proc addr\n");
return false;
}
}
@ -386,7 +399,7 @@ qboolean IN_InitDInput (void)
if (FAILED(hr))
{
Con_SafePrintf ("Couldn't open DI mouse device\n");
Con_Printf ("Couldn't open DI mouse device\n");
return false;
}
@ -395,7 +408,7 @@ qboolean IN_InitDInput (void)
if (FAILED(hr))
{
Con_SafePrintf ("Couldn't set DI mouse format\n");
Con_Printf ("Couldn't set DI mouse format\n");
return false;
}
@ -405,7 +418,7 @@ qboolean IN_InitDInput (void)
if (FAILED(hr))
{
Con_SafePrintf ("Couldn't set DI coop level\n");
Con_Printf ("Couldn't set DI coop level\n");
return false;
}
@ -416,7 +429,7 @@ qboolean IN_InitDInput (void)
if (FAILED(hr))
{
Con_SafePrintf ("Couldn't set DI buffersize\n");
Con_Printf ("Couldn't set DI buffersize\n");
return false;
}
@ -429,9 +442,9 @@ qboolean IN_InitDInput (void)
IN_StartupMouse
===========
*/
void IN_StartupMouse (void)
static void IN_StartupMouse (void)
{
HDC hdc;
// HDC hdc;
if ( COM_CheckParm ("-nomouse") )
return;
@ -444,11 +457,11 @@ void IN_StartupMouse (void)
if (dinput)
{
Con_SafePrintf ("DirectInput initialized\n");
Con_Printf ("DirectInput initialized\n");
}
else
{
Con_SafePrintf ("DirectInput not initialized\n");
Con_Printf ("DirectInput not initialized\n");
}
}
@ -492,30 +505,6 @@ IN_Init
*/
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 ("joyadvancedupdate", Joy_AdvancedUpdate_f);
@ -525,6 +514,33 @@ void IN_Init (void)
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
@ -557,7 +573,7 @@ IN_MouseEvent
*/
void IN_MouseEvent (int mstate)
{
int i;
int i;
if (mouseactive && !dinput)
{
@ -573,7 +589,7 @@ void IN_MouseEvent (int mstate)
if ( !(mstate & (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)
{
int mx, my;
HDC hdc;
int mx, my;
// HDC hdc;
int i;
DIDEVICEOBJECTDATA od;
DWORD dwElements;
@ -680,16 +696,13 @@ void IN_MouseMove (usercmd_t *cmd)
else
{
GetCursorPos (&current_pos);
mx = current_pos.x - window_center_x + mx_accum;
my = current_pos.y - window_center_y + my_accum;
mx_accum = 0;
my_accum = 0;
mx = current_pos.x - window_center_x + mx_accum;
my = current_pos.y - window_center_y + my_accum;
mx_accum = 0;
my_accum = 0;
}
//if (mx || my)
// Con_DPrintf("mx=%d, my=%d\n", mx, my);
if (m_filter->int_val)
if (m_filter->value)
{
mouse_x = (mx + old_mouse_x) * 0.5;
mouse_y = (my + old_mouse_y) * 0.5;
@ -707,24 +720,18 @@ void IN_MouseMove (usercmd_t *cmd)
mouse_y *= sensitivity->value;
// 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;
else
cl.viewangles[YAW] -= m_yaw->value * mouse_x;
if (in_mlook.state & 1)
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;
if (cl.viewangles[PITCH] > 80)
cl.viewangles[PITCH] = 80;
if (cl.viewangles[PITCH] < -70)
cl.viewangles[PITCH] = -70;
}
else
{
cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
} else {
if ((in_strafe.state & 1) && noclip_anglehack)
cmd->upmove -= m_forward->value * mouse_y;
else
@ -762,21 +769,18 @@ IN_Accumulate
*/
void IN_Accumulate (void)
{
int mx, my;
HDC hdc;
// int mx, my;
// HDC hdc;
if (mouseactive)
{
if (!dinput)
{
GetCursorPos (&current_pos);
GetCursorPos (&current_pos);
mx_accum += current_pos.x - window_center_x;
my_accum += current_pos.y - window_center_y;
mx_accum += current_pos.x - window_center_x;
my_accum += current_pos.y - window_center_y;
// force the mouse to the center, so there's room to move
SetCursorPos (window_center_x, window_center_y);
}
// force the mouse to the center, so there's room to move
SetCursorPos (window_center_x, window_center_y);
}
}
@ -803,17 +807,17 @@ void IN_ClearStates (void)
IN_StartupJoystick
===============
*/
void IN_StartupJoystick (void)
static void IN_StartupJoystick (void)
{
int i, numdevs;
int /*i,*/ numdevs;
JOYCAPS jc;
MMRESULT mmr;
MMRESULT mmr = !JOYERR_NOERROR;
// assume no joystick
joy_avail = false;
// abort startup if user requests no joystick
if ( COM_CheckParm ("-nojoy") )
if ( COM_CheckParm ("-nojoy") )
return;
// verify joystick driver is present
@ -846,7 +850,7 @@ void IN_StartupJoystick (void)
memset (&jc, 0, sizeof(jc));
if ((mmr = joyGetDevCaps (joy_id, &jc, sizeof(jc))) != JOYERR_NOERROR)
{
Con_Printf ("\njoystick not found -- invalid joystick capabilities (%x)\n\n", mmr);
Con_Printf ("\njoystick not found -- invalid joystick capabilities (%x)\n\n", mmr);
return;
}
@ -863,7 +867,7 @@ void IN_StartupJoystick (void)
joy_avail = true;
joy_advancedinit = false;
Con_Printf ("\njoystick detected\n\n");
Con_Printf ("\njoystick detected\n\n");
}
@ -872,7 +876,7 @@ void IN_StartupJoystick (void)
RawValuePointer
===========
*/
PDWORD RawValuePointer (int axis)
static PDWORD RawValuePointer (int axis)
{
switch (axis)
{
@ -889,15 +893,15 @@ PDWORD RawValuePointer (int axis)
case JOY_AXIS_V:
return &ji.dwVpos;
}
return NULL;
}
/*
===========
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
@ -913,7 +917,7 @@ void Joy_AdvancedUpdate_f (void)
pdwRawValue[i] = RawValuePointer(i);
}
if( joy_advanced->int_val == 0.0)
if( joy_advanced->int_val)
{
// default joystick initialization
// 2 axes only with joystick control
@ -924,7 +928,7 @@ void Joy_AdvancedUpdate_f (void)
}
else
{
if (Q_strcmp (joy_name->string, "joystick") != 0)
if (strcmp (joy_name->string, "joystick") != 0)
{
// notify user of advanced controller
Con_Printf ("\n%s configured\n\n", joy_name->string);
@ -1039,7 +1043,7 @@ void IN_Commands (void)
IN_ReadJoystick
===============
*/
qboolean IN_ReadJoystick (void)
static qboolean IN_ReadJoystick (void)
{
memset (&ji, 0, sizeof(ji));
@ -1060,7 +1064,7 @@ qboolean IN_ReadJoystick (void)
else
{
// 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?
// Con_Printf ("IN_ReadJoystick: no response\n");
// joy_avail = false;
@ -1074,7 +1078,7 @@ qboolean IN_ReadJoystick (void)
IN_JoyMove
===========
*/
void IN_JoyMove (usercmd_t *cmd)
static void IN_JoyMove (usercmd_t *cmd)
{
float speed, aspeed;
float fAxisValue, fTemp;
@ -1136,7 +1140,7 @@ void IN_JoyMove (usercmd_t *cmd)
switch (dwAxisMap[i])
{
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
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
// *** this code can be removed when the lookspring bug is fixed
// *** the bug always has the lookspring feature on
if(lookspring->int_val)
if (!lookspring->int_val)
V_StopPitchDrift();
}
}
@ -1181,7 +1185,7 @@ void IN_JoyMove (usercmd_t *cmd)
break;
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
if (fabs(fAxisValue) > joy_sidethreshold->value)
@ -1208,7 +1212,7 @@ void IN_JoyMove (usercmd_t *cmd)
break;
case AxisLook:
if (in_mlook.state & 1)
if (freelook)
{
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
// *** this code can be removed when the lookspring bug is fixed
// *** the bug always has the lookspring feature on
if(lookspring->int_val)
if (!lookspring->int_val)
V_StopPitchDrift();
}
}
@ -1247,6 +1251,7 @@ void IN_JoyMove (usercmd_t *cmd)
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 <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <string.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <X11/Xlib.h>
#include <X11/keysym.h>
@ -48,6 +55,7 @@
#include <X11/extensions/xf86dga.h>
#endif
#include "dga_check.h"
#include "d_local.h"
#include "sound.h"
#include "keys.h"
@ -59,34 +67,31 @@
#include "console.h"
#include "client.h"
#include "context_x11.h"
#include "qargs.h"
#include "host.h"
#include "input.h"
#include "joystick.h"
#include "qargs.h"
#include "view.h"
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
cvar_t *_windowed_mouse;
cvar_t *m_filter;
cvar_t *in_dgamouse;
#ifdef HAVE_DGA
cvar_t *in_dga;
cvar_t *in_dga_mouseaccel;
cvar_t *in_nodga_grab;
#endif
static qboolean dga_avail;
static qboolean dga_active;
static qboolean mouse_avail;
static float mouse_x, mouse_y;
static float old_mouse_x, old_mouse_y;
static int p_mouse_x, p_mouse_y;
static float old__windowed_mouse;
#define KEY_MASK (KeyPressMask | KeyReleaseMask)
#define MOUSE_MASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
#define INPUT_MASK (KEY_MASK | MOUSE_MASK)
static int
XLateKey(XKeyEvent *ev)
{
@ -161,7 +166,7 @@ XLateKey(XKeyEvent *ev)
case XK_Meta_R: key = K_ALT; 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_KP_Insert: key = KP_INS; break;
@ -215,14 +220,14 @@ XLateKey(XKeyEvent *ev)
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
event_button(XEvent *event)
event_button (XEvent *event)
{
int but;
@ -264,28 +269,22 @@ center_pointer(void)
static void
event_motion(XEvent *event)
event_motion (XEvent *event)
{
#ifdef HAVE_DGA
if (in_dgamouse->int_val) {
if (dga_active) {
mouse_x += event->xmotion.x_root * in_dga_mouseaccel->value;
mouse_y += event->xmotion.y_root * in_dga_mouseaccel->value;
} else
#endif
{
//printf("_windowed_mouse: %s\n", _windowed_mouse->int_val);
//printf("CurrentTime: %ld\n", CurrentTime);
if (_windowed_mouse->int_val) {
} else {
if (!p_mouse_x && !p_mouse_y) {
Con_Printf("event->xmotion.x: %d\n", event->xmotion.x);
Con_Printf("event->xmotion.y: %d\n", event->xmotion.y);
}
if (vid_fullscreen->int_val || _windowed_mouse->int_val) {
if (!event->xmotion.send_event) {
mouse_x += (event->xmotion.x - p_mouse_x);
mouse_y += (event->xmotion.y - p_mouse_y);
#undef ABS
#define ABS(a) (((int)(a) < 0) ? -(a) : (a))
if (ABS(vid.width/2 - event->xmotion.x)
> vid.width / 4
|| ABS(vid.height/2 - event->xmotion.y)
> vid.height / 4) {
#undef ABS
if (abs(vid.width/2 - event->xmotion.x) > vid.width / 4
|| abs(vid.height/2 - event->xmotion.y) > vid.height / 4) {
center_pointer();
}
}
@ -302,19 +301,34 @@ event_motion(XEvent *event)
void
IN_Commands (void)
{
JOY_Command ();
if (old__windowed_mouse != _windowed_mouse->int_val) {
old__windowed_mouse = _windowed_mouse->int_val;
static int old_windowed_mouse;
static int old_in_dga;
if (!_windowed_mouse->int_val) {
/* ungrab the pointer */
XUngrabPointer(x_disp,CurrentTime);
} else {
/* grab the pointer */
XGrabPointer(x_disp, x_win, True, MOUSE_MASK, GrabModeAsync,
GrabModeAsync, x_win, None, CurrentTime);
//XGrabPointer(x_disp,x_win,True,0,GrabModeAsync,
// GrabModeAsync,x_win,None,CurrentTime);
JOY_Command ();
if ((old_windowed_mouse != _windowed_mouse->int_val)
|| (old_in_dga != in_dga->int_val)) {
old_windowed_mouse = _windowed_mouse->int_val;
old_in_dga = in_dga->int_val;
if (_windowed_mouse->int_val) { // grab the pointer
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) {
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;
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) ))
if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook))
cmd->sidemove += m_side->value * mouse_x;
else
cl.viewangles[YAW] -= m_yaw->value * mouse_x;
if (in_mlook.state & 1)
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] = bound (-70, cl.viewangles[PITCH], 80);
} else {
@ -366,24 +381,6 @@ IN_Move (usercmd_t *cmd)
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
*/
@ -391,30 +388,30 @@ void
IN_Shutdown (void)
{
JOY_Shutdown ();
Con_Printf("IN_Shutdown\n");
Con_Printf ("IN_Shutdown\n");
mouse_avail = 0;
if (x_disp) {
XAutoRepeatOn(x_disp);
XAutoRepeatOn (x_disp);
#ifdef HAVE_DGA
XF86DGADirectVideo(x_disp, DefaultScreen(x_disp), 0);
XF86DGADirectVideo (x_disp, DefaultScreen (x_disp), 0);
#endif
}
x11_close_display();
}
extern int scr_width, scr_height;
int
void
IN_Init (void)
{
// open the display
// open the display
if (!x_disp)
Sys_Error("IN: No display!!\n");
if (!x_win)
Sys_Error("IN: No window!!\n");
x11_open_display (); // call to increment the reference counter
{
int attribmask = CWEventMask;
XWindowAttributes attribs_1;
@ -429,41 +426,16 @@ IN_Init (void)
JOY_Init ();
_windowed_mouse = Cvar_Get ("_windowed_mouse","0",CVAR_ARCHIVE,"None");
m_filter = Cvar_Get ("m_filter","0",CVAR_ARCHIVE,"None");
XAutoRepeatOff (x_disp);
XAutoRepeatOff(x_disp);
if (COM_CheckParm("-nomouse"))
return;
if (COM_CheckParm("-nomouse")) return 1;
#ifdef HAVE_DGA
in_dgamouse = Cvar_Get ("in_dgamouse", "0", CVAR_ROM,
"1 if you have DGA mouse support");
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");
dga_avail = VID_CheckDGA (x_disp, NULL, NULL, NULL);
if (vid_fullscreen->int_val) {
Cvar_Set (_windowed_mouse, "1");
_windowed_mouse->flags |= CVAR_ROM;
}
#endif
mouse_x = mouse_y = 0.0;
mouse_avail = 1;
@ -474,9 +446,21 @@ IN_Init (void)
x11_add_event(ButtonRelease, &event_button);
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 "keys.h"
#include "protocol.h"
#include "view.h"
#define JOY_MAX_AXES 6
#define JOY_MAX_BUTTONS 10
@ -149,10 +150,6 @@ JOY_Move (usercmd_t *cmd)
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
joy_handle = open (joy_device->string, O_RDONLY|O_NONBLOCK);
if (joy_handle < 0) {
@ -169,11 +166,6 @@ JOY_Init (void)
}
} else {
// 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++) {
joy_buttons[i].old = 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
JOY_Shutdown (void)
{

View file

@ -30,6 +30,7 @@
# include "config.h"
#endif
#include "console.h"
#include "cvar.h"
#include "protocol.h"
#include "qtypes.h"
@ -54,12 +55,16 @@ JOY_Move (usercmd_t *cmd)
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_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");
Con_DPrintf ("This system does not have joystick support.\n");
}
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$
*/
#include "qtypes.h"
#include "glquake.h"
#include "sys.h"
#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"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#ifdef HAVE_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
# include <dlfcn.h>
#endif
#ifndef RTLD_LAZY
# ifdef DL_LAZY
# define RTLD_LAZY DL_LAZY
# define RTLD_LAZY DL_LAZY
# else
# define RTLD_LAZY 0
# define RTLD_LAZY 0
# endif
#endif
#include <GL/gl.h>
#include <GL/fxmesa.h>
#include <glide/sst1vid.h>
#include "console.h"
#include "glquake.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_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 int scr_width, scr_height;
static qboolean is8bit = 0;
static void *dlhand;
int VID_options_items = 0;
extern void GL_Init_Common(void);
extern void VID_Init8bitPalette(void);
/*-----------------------------------------------------------------------*/
//int texture_mode = GL_NEAREST;
//int texture_mode = GL_NEAREST_MIPMAP_NEAREST;
//int texture_mode = GL_NEAREST_MIPMAP_LINEAR;
int texture_mode = GL_LINEAR;
//int texture_mode = GL_LINEAR_MIPMAP_NEAREST;
//int texture_mode = GL_LINEAR_MIPMAP_LINEAR;
int texture_extension_number = 1;
float gldepthmin, gldepthmax;
const char *gl_vendor;
const char *gl_renderer;
const char *gl_version;
const char *gl_extensions;
// 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)
void
VID_Shutdown(void)
{
if (!fc)
return;
@ -124,16 +84,18 @@ void VID_Shutdown(void)
fxMesaDestroyContext(fc);
}
void signal_handler(int sig)
void
signal_handler(int sig)
{
printf("Received signal %d, exiting...\n", sig);
Host_Shutdown();
abort();
//Sys_Quit();
// Sys_Quit();
exit(0);
}
void InitSig(void)
void
InitSig(void)
{
signal(SIGHUP, signal_handler);
signal(SIGINT, signal_handler);
@ -147,151 +109,6 @@ void InitSig(void)
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);
/*
@ -299,45 +116,17 @@ typedef void (GLAPIENTRY *gl3DfxSetDitherModeEXT_FUNC) (GrDitherMode_t mode);
GL_Init
===============
*/
void GL_Init (void)
void
GL_Init (void)
{
gl_vendor = glGetString (GL_VENDOR);
Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
gl_renderer = glGetString (GL_RENDERER);
Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
gl_version = glGetString (GL_VERSION);
Con_Printf ("GL_VERSION: %s\n", gl_version);
gl_extensions = glGetString (GL_EXTENSIONS);
Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
CheckMultiTextureExtensions ();
glClearColor (1,0,0,0);
glCullFace(GL_FRONT);
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.666);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glShadeModel (GL_FLAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
GL_Init_Common ();
Con_Printf ("Dithering: ");
dlhand = dlopen (NULL, RTLD_LAZY);
if (dlhand == NULL) {
Con_SafePrintf ("unable to set.\n");
Con_Printf ("unable to set.\n");
return;
}
@ -361,26 +150,8 @@ void GL_Init (void)
dlhand = NULL;
}
/*
=================
GL_BeginRendering
=================
*/
void GL_BeginRendering (int *x, int *y, int *width, int *height)
{
*x = *y = 0;
*width = scr_width;
*height = scr_height;
// if (!wglMakeCurrent( maindc, baseRC ))
// Sys_Error ("wglMakeCurrent failed");
// glViewport (*x, *y, *width, *height);
}
void GL_EndRendering (void)
void
GL_EndRendering (void)
{
glFlush();
fxMesaSwapBuffers();
@ -458,90 +229,17 @@ findres(int *width, int *height)
return GR_RESOLUTION_640x480;
}
qboolean VID_Is8bit(void)
{
return is8bit;
}
typedef void (GLAPIENTRY *glColorTableEXT_FUNC) (GLenum, GLenum, GLsizei,
GLenum, GLenum, const GLvoid *);
typedef void (GLAPIENTRY *gl3DfxSetPaletteEXT_FUNC) (GLuint *pal);
void VID_Init8bitPalette()
{
// Check for 8bit Extensions and initialize them.
int i;
dlhand = dlopen (NULL, RTLD_LAZY);
Con_SafePrintf ("8-bit GL extensions: ");
if (dlhand == NULL) {
Con_SafePrintf ("unable to check.\n");
return;
}
if (COM_CheckParm("-no8bit")) {
Con_SafePrintf("disabled.\n");
return;
}
if (strstr(gl_extensions, "3DFX_set_global_palette")) {
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)
void
VID_Init(unsigned char *palette)
{
int i;
GLint attribs[32];
char gldir[MAX_OSPATH];
int width = 640, height = 480;
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");
VID_GetWindowSize (640, 480);
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
@ -558,11 +256,6 @@ void VID_Init(unsigned char *palette)
attribs[4] = 1;
attribs[5] = FXMESA_NONE;
if ((i = COM_CheckParm("-width")) != 0)
width = atoi(com_argv[i+1]);
if ((i = COM_CheckParm("-height")) != 0)
height = atoi(com_argv[i+1]);
if ((i = COM_CheckParm("-conwidth")) != 0)
vid.conwidth = atoi(com_argv[i+1]);
else
@ -581,20 +274,17 @@ void VID_Init(unsigned char *palette)
if (vid.conheight < 200)
vid.conheight = 200;
fc = fxMesaCreateContext(0, findres(&width, &height), GR_REFRESH_75Hz,
attribs);
fc = fxMesaCreateContext(0, findres(&scr_width, &scr_height),
GR_REFRESH_75Hz, attribs);
if (!fc)
Sys_Error("Unable to create 3DFX context.\n");
scr_width = width;
scr_height = height;
fxMesaMakeCurrent(fc);
if (vid.conheight > height)
vid.conheight = height;
if (vid.conwidth > width)
vid.conwidth = width;
if (vid.conheight > scr_height)
vid.conheight = scr_height;
if (vid.conwidth > scr_width)
vid.conwidth = scr_width;
vid.width = vid.conwidth;
vid.height = vid.conheight;
@ -605,25 +295,29 @@ void VID_Init(unsigned char *palette)
GL_Init();
snprintf(gldir, sizeof(gldir), "%s/glquake", com_gamedir);
Sys_mkdir (gldir);
VID_SetPalette(palette);
// Check for 3DFX Extensions and initialize them.
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
}
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 */
}
void VID_ExtraOptionCmd(int option_cursor)
void
VID_ExtraOptionCmd(int 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
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.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 "input.h"
#include "cl_input.h"
#include "view.h"
#include "joystick.h"
extern viddef_t vid; // global video state
unsigned short d_8to16table[256];
@ -78,18 +106,8 @@ static int stride, drawstride;
static int pixelsize;
static int usedbuf, havedbuf;
static long GGI_highhunkmark, GGI_buffersize;
static int vid_surfcachesize;
static void *vid_surfcache;
int VID_options_items = 1;
void
VID_InitCvars(void)
{
}
static void
do_scale8(int xsize, int ysize, uint8 *dest, uint8 *src)
{
@ -206,44 +224,54 @@ do_copy32(int xsize, int ysize, uint32 *dest, uint8 *src)
}
// ========================================================================
// Tragic death handler
// ========================================================================
void ResetFrameBuffer(void)
void
ResetFrameBuffer(void)
{
if (d_pzbuffer)
{
D_FlushCaches ();
Hunk_FreeToHighMark (GGI_highhunkmark);
int tbuffersize, tcachesize;
void *vid_surfcache;
// 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;
}
GGI_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
GGI_buffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
vid_surfcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
GGI_buffersize += vid_surfcachesize;
d_pzbuffer = Hunk_HighAllocName (GGI_buffersize, "video");
if (d_pzbuffer == NULL)
// Allocate the new z-buffer
d_pzbuffer = calloc (tbuffersize, 1);
if (!d_pzbuffer) {
Sys_Error ("Not enough memory for video mode\n");
}
vid_surfcache = (byte *) d_pzbuffer
+ vid.width * vid.height * sizeof (*d_pzbuffer);
// Allocate the new surface cache; free the z-buffer if we fail
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
// the palette data will go away after the call, so it must be copied off if
// the video driver will need it again
void VID_Init(unsigned char *pal)
void
VID_Init (unsigned char *pal)
{
int pnum;
@ -434,14 +462,15 @@ void VID_Init(unsigned char *pal)
vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
}
void VID_ShiftPalette(unsigned char *pal)
void
VID_ShiftPalette(unsigned char *pal)
{
VID_SetPalette(pal);
}
void VID_SetPalette(unsigned char *pal)
void
VID_SetPalette (unsigned char *pal)
{
int i;
@ -461,7 +490,8 @@ void VID_SetPalette(unsigned char *pal)
// Called at shutdown
void VID_Shutdown (void)
void
VID_Shutdown (void)
{
Con_Printf("VID_Shutdown\n");
@ -487,7 +517,8 @@ void VID_Shutdown (void)
// 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;
@ -890,19 +921,31 @@ void IN_SendKeyEvents(void)
void
IN_Init(void)
{
_windowed_mouse = Cvar_Get("_windowed_mouse", "0", CVAR_ARCHIVE, "None");
JOY_Init ();
old_windowed_mouse = -1; /* Force update */
m_filter = Cvar_Get("m_filter", "0", CVAR_ARCHIVE, "None");
if (COM_CheckParm ("-nomouse")) return;
mouse_x = mouse_y = 0.0;
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
IN_Shutdown(void)
{
JOY_Shutdown ();
Con_Printf("IN_Shutdown\n");
mouse_avail = 0;
}
@ -910,6 +953,8 @@ IN_Shutdown(void)
void
IN_Commands (void)
{
JOY_Command ();
/* Only supported by LibGII 0.7 or later. */
#ifdef GII_CMDCODE_PREFER_RELPTR
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.type = evCommand;
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;
ggiEventSend(ggivis, &ev);
@ -932,7 +977,10 @@ IN_Commands (void)
void
IN_Move(usercmd_t *cmd)
{
if (!mouse_avail) return;
JOY_Move (cmd);
if (!mouse_avail)
return;
if (m_filter->int_val) {
mouse_x = (mouse_x + old_mouse_x) * 0.5;
@ -945,19 +993,16 @@ IN_Move(usercmd_t *cmd)
mouse_x *= 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;
else
cl.viewangles[YAW] -= m_yaw->value * mouse_x;
if (freelook)
V_StopPitchDrift ();
if ( freelook && !(in_strafe.state & 1)) {
if (freelook && !(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;
cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
} else {
if ((in_strafe.state & 1) && noclip_anglehack)
cmd->upmove -= m_forward->value * mouse_y;
@ -967,6 +1012,16 @@ IN_Move(usercmd_t *cmd)
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"
#endif
#include <stdio.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 <string.h>
#include <GL/glx.h>
@ -57,391 +42,92 @@
# include <X11/extensions/xf86dga.h>
#endif
#ifdef XMESA
# include <GL/xmesa.h>
#endif
#include "qtypes.h"
#include "qendian.h"
#include "compat.h"
#include "console.h"
#include "context_x11.h"
#include "glquake.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 "qargs.h"
#include "qendian.h"
#include "quakefs.h"
#include "sbar.h"
#include "context_x11.h"
#include "dga_check.h"
#include "va.h"
#define WARP_WIDTH 320
#define WARP_HEIGHT 200
#define WARP_WIDTH 320
#define WARP_HEIGHT 200
static qboolean vid_initialized = false;
static GLXContext ctx = NULL;
unsigned short d_8to16table[256];
unsigned int d_8to24table[256];
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
extern void GL_Init_Common (void);
extern void VID_Init8bitPalette (void);
/*-----------------------------------------------------------------------*/
//int texture_mode = GL_NEAREST;
//int texture_mode = GL_NEAREST_MIPMAP_NEAREST;
//int texture_mode = GL_NEAREST_MIPMAP_LINEAR;
int texture_mode = GL_LINEAR;
//int texture_mode = GL_LINEAR_MIPMAP_NEAREST;
//int texture_mode = GL_LINEAR_MIPMAP_LINEAR;
int texture_extension_number = 1;
float gldepthmin, gldepthmax;
const char *gl_vendor;
const char *gl_renderer;
const char *gl_version;
const char *gl_extensions;
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
VID_Shutdown(void)
VID_Shutdown (void)
{
if (!vid_initialized)
return;
Con_Printf("VID_Shutdown\n");
glXDestroyContext(x_disp, ctx);
XDestroyWindow(x_disp, x_win);
Con_Printf ("VID_Shutdown\n");
x11_restore_vidmode();
#ifdef HAVE_DLOPEN
if (dlhand) {
dlclose(dlhand);
dlhand = NULL;
}
#endif
x11_close_display();
x11_restore_vidmode ();
x11_close_display ();
}
#if 0
static void
signal_handler(int sig)
signal_handler (int sig)
{
printf("Received signal %d, exiting...\n", sig);
Sys_Quit();
exit(sig);
printf ("Received signal %d, exiting...\n", sig);
Sys_Quit ();
exit (sig);
}
static void
InitSig(void)
InitSig (void)
{
signal(SIGHUP, signal_handler);
signal(SIGINT, signal_handler);
signal(SIGQUIT, signal_handler);
signal(SIGILL, signal_handler);
signal(SIGTRAP, signal_handler);
signal(SIGIOT, signal_handler);
signal(SIGBUS, signal_handler);
/* signal(SIGFPE, signal_handler); */
signal(SIGSEGV, signal_handler);
signal(SIGTERM, signal_handler);
signal (SIGHUP, signal_handler);
signal (SIGINT, signal_handler);
signal (SIGQUIT, signal_handler);
signal (SIGILL, signal_handler);
signal (SIGTRAP, signal_handler);
signal (SIGIOT, signal_handler);
signal (SIGBUS, signal_handler);
/* signal (SIGFPE, signal_handler); */
signal (SIGSEGV, signal_handler);
signal (SIGTERM, signal_handler);
}
#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
===============
*/
void GL_Init (void)
void
GL_Init (void)
{
gl_vendor = glGetString (GL_VENDOR);
Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
gl_renderer = glGetString (GL_RENDERER);
Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
gl_version = glGetString (GL_VERSION);
Con_Printf ("GL_VERSION: %s\n", gl_version);
gl_extensions = glGetString (GL_EXTENSIONS);
Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
// Con_Printf ("%s %s\n", gl_renderer, gl_version);
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);
GL_Init_Common ();
}
/*
=================
GL_BeginRendering
=================
*/
void GL_BeginRendering (int *x, int *y, int *width, int *height)
void
GL_EndRendering (void)
{
*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();
glXSwapBuffers(x_disp, x_win);
glFlush ();
glXSwapBuffers (x_disp, x_win);
Sbar_Changed ();
}
qboolean VID_Is8bit(void)
{
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)
void
VID_Init (unsigned char *palette)
{
int i;
int attrib[] = {
@ -453,156 +139,96 @@ void VID_Init(unsigned char *palette)
GLX_DEPTH_SIZE, 1,
None
};
char gldir[MAX_OSPATH];
int width = 640, height = 480;
vid_mode = Cvar_Get ("vid_mode","0",0,"None");
#ifdef HAVE_DGA
in_dga_mouseaccel = Cvar_Get("vid_dga_mouseaccel","1",CVAR_ARCHIVE,
"None");
#endif
VID_GetWindowSize (640, 480);
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
/* Interpret command-line params
*/
/* 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]);
else
vid.conwidth = width;
vid.conwidth = scr_width;
vid.conwidth &= 0xfff8; // make it a multiple of eight
if (vid.conwidth < 320)
vid.conwidth = 320;
vid.conwidth = max (vid.conwidth, 320);
// pick a conheight that matches with correct aspect
vid.conheight = vid.conwidth * 3 / 4;
i = COM_CheckParm ("-conheight");
if ( i != 0 ) // Set console height, but no smaller than 200 px
vid.conheight = atoi(com_argv[i+1]);
if (vid.conheight < 200)
vid.conheight = 200;
if ((i = COM_CheckParm ("-conheight"))) // conheight no smaller than 200px
vid.conheight = atoi (com_argv[i+1]);
vid.conheight = max (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) {
fprintf(stderr, "Error couldn't get an RGB, Double-buffered, Depth visual\n");
exit(1);
fprintf (stderr, "Error couldn't get an RGB, Double-buffered, Depth visual\n");
exit (1);
}
x_vis = x_visinfo->visual;
#ifdef HAVE_DGA
{
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);
x11_set_vidmode (scr_width, scr_height);
x11_create_window (scr_width, scr_height);
/* Invisible cursor */
x11_create_null_cursor();
x11_create_null_cursor ();
XWarpPointer(x_disp, None, x_win, 0, 0, 0, 0,
vid.width+2, vid.height+2);
x11_grab_keyboard ();
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;
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.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
vid.numpages = 2;
//InitSig(); // trap evil signals
//InitSig (); // trap evil signals
GL_Init();
GL_Init ();
snprintf(gldir, sizeof(gldir), "%s/glquake", com_gamedir);
Sys_mkdir (gldir);
GL_CheckGamma (palette);
//XXX not yet GL_CheckBrightness (palette);
VID_SetPalette (palette);
// Check for 3DFX Extensions and initialize them.
VID_Init8bitPalette();
// Check for 8-bit extension and initialize if present
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_initialized = true;
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 "quakedef.h"
#include "va.h"
#include "winquake.h"
#include "sys.h"
#include "d_local.h"
@ -53,6 +54,8 @@
#define MAX_MODE_LIST 30
#define VID_ROW_SIZE 3
extern void (*vid_menudrawfn)(void);
extern void (*vid_menukeyfn)(int);
/* Unused */
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
cvar_t *vid_mode;
// Note that 0 is MODE_WINDOWED
cvar_t *_vid_default_mode;
// Note that 3 is MODE_FULLSCREEN_DEFAULT
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;
@ -138,7 +138,7 @@ static int VID_highhunkmark;
unsigned char vid_curpal[256*3];
unsigned short d_8to16table[256];
unsigned d_8to24table[256];
unsigned int d_8to24table[256];
int driver = grDETECT,mode;
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);
void AppActivate(BOOL fActive, BOOL minimize);
/*
================
VID_InitCvars
================
*/
void
VID_InitCvars ()
{
// It may not look like it, but this is important
}
/*
================
VID_RememberWindowPos
@ -202,8 +191,8 @@ void VID_RememberWindowPos (void)
(rect.right > 0) &&
(rect.bottom > 0))
{
Cvar_SetValue (vid_window_x, (float)rect.left);
Cvar_SetValue (vid_window_y, (float)rect.top);
Cvar_SetValue (vid_window_x, rect.left);
Cvar_SetValue (vid_window_y, rect.top);
}
}
}
@ -269,20 +258,6 @@ VID_CheckAdequateMem
*/
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;
}
@ -292,41 +267,46 @@ qboolean VID_CheckAdequateMem (int width, int height)
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);
tcachesize = D_SurfaceCacheForRes (width, height);
tsize = D_SurfaceCacheForRes (width, height);
tbuffersize += tsize;
// 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)
{
Con_SafePrintf ("Not enough memory for video mode\n");
return false; // not enough memory for mode
// Allocate the new z-buffer
temp_z = calloc (tbuffersize, 1);
if (temp_z == NULL) {
Sys_Printf ("Not enough memory for video mode\n");
return false;
}
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 ();
Hunk_FreeToHighMark (VID_highhunkmark);
d_pzbuffer = NULL;
free (vid_surfcache);
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;
}
@ -862,7 +842,7 @@ void VID_InitFullDIB (HINSTANCE hInstance)
modenum = 0;
lowestres = 99999;
Con_SafePrintf ("No 8-bpp fullscreen DIB modes found\n");
Con_Printf ("No 8-bpp fullscreen DIB modes found\n");
do
{
@ -1057,7 +1037,7 @@ void VID_InitFullDIB (HINSTANCE hInstance)
if (nummodes != originalnummodes)
vid_default = MODE_FULLSCREEN_DEFAULT;
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;
if (mode == MODE_SETTABLE_WINDOW)
{
if (mode == MODE_SETTABLE_WINDOW) {
modelist[mode].stretched = vid_stretch_by_2->int_val;
stretch = modelist[mode].stretched;
if (vid_config_x->int_val < (320 << stretch))
Cvar_SetValue (vid_config_x, 320 << stretch);
if (vid_config_y->int_val < (200 << stretch))
Cvar_SetValue (vid_config_y, 200 << stretch);
Cvar_SetValue (vid_config_x, max (vid_config_x->int_val, 320 << stretch));
Cvar_SetValue (vid_config_y, max (vid_config_y->int_val, 200 << stretch));
x = vid_config_x->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].height = y;
}
@ -1134,12 +1110,9 @@ char *VID_GetModeDescriptionMemCheck (int mode)
pv = VID_GetModePtr (mode);
pinfo = pv->modedesc;
if (VID_CheckAdequateMem (pv->width, pv->height))
{
if (VID_CheckAdequateMem (pv->width, pv->height)) {
return pinfo;
}
else
{
} else {
return NULL;
}
}
@ -1648,11 +1621,11 @@ int VID_SetMode (int modenum, unsigned char *palette)
modenum = vid_default;
}
Cvar_SetValue (vid_mode, (float)modenum);
Cvar_SetValue (vid_mode, modenum);
}
else
{
Cvar_SetValue (vid_mode, (float)vid_modenum);
Cvar_SetValue (vid_mode, vid_modenum);
return 0;
}
}
@ -1739,7 +1712,7 @@ int VID_SetMode (int modenum, unsigned char *palette)
ReleaseDC(NULL,hdc);
vid_modenum = modenum;
Cvar_SetValue (vid_mode, (float)vid_modenum);
Cvar_SetValue (vid_mode, vid_modenum);
if (!VID_AllocBuffers (vid.width, vid.height))
{
@ -1771,7 +1744,7 @@ int VID_SetMode (int modenum, unsigned char *palette)
ClearAllStates ();
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);
@ -2122,22 +2095,6 @@ void VID_Init (unsigned char *palette)
int basenummodes;
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_nummodes", VID_NumModes_f);
Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f);
@ -2238,6 +2195,22 @@ void VID_Init (unsigned char *palette)
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)
{
@ -2432,7 +2405,7 @@ void VID_Update (vrect_t *rects)
if (vid_mode->int_val != vid_realmode)
{
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
// trying to set that mode
vid_realmode = vid_modenum;
@ -2939,7 +2912,7 @@ LONG WINAPI MainWndProc (
force_mode_set = false;
}
VID_SetMode ((int)vid_fullscreen_mode->int_val, vid_curpal);
VID_SetMode (vid_fullscreen_mode->int_val, vid_curpal);
break;
case SC_SCREENSAVE:
@ -3439,6 +3412,12 @@ void VID_MenuKey (int key)
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
@description@
null video driver to aid porting efforts
Copyright (C) 1996-1997 Id Software, Inc.
@ -27,9 +27,9 @@
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
# include <config.h>
#endif
#include "quakedef.h"
#include "d_local.h"
viddef_t vid; // global video state
@ -42,12 +42,7 @@ short zbuffer[BASEWIDTH*BASEHEIGHT];
byte surfcache[256*1024];
unsigned short d_8to16table[256];
unsigned d_8to24table[256];
void
VID_InitCvars(void)
{
}
unsigned int d_8to24table[256];
void VID_SetPalette (unsigned char *palette)
{
@ -72,6 +67,10 @@ void VID_Init (unsigned char *palette)
D_InitCaches (surfcache, sizeof(surfcache));
}
void VID_Init_Cvars ()
{
}
void VID_Shutdown (void)
{
}
@ -99,8 +98,10 @@ void D_EndDirectRect (int x, int y, int width, int height)
{
}
void VID_HandlePause (qboolean pause)
void VID_SetCaption (char *text)
{
}
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
@ -30,38 +30,23 @@
#include "config.h"
#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 "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 "input.h"
cvar_t *_windowed_mouse;
int old_windowed_mouse;
#include "host.h"
#include "qendian.h"
#include "sys.h"
#include "va.h"
#include "vid.h"
// static float oldin_grab = 0;
cvar_t *vid_fullscreen;
extern viddef_t vid; // global video state
unsigned short d_8to16table[256];
@ -73,6 +58,7 @@ HWND mainwindow;
int modestate; // fixme: just to avoid cross-comp. errors - remove later
// The original defaults
#define BASEWIDTH 320
#define BASEHEIGHT 200
@ -81,96 +67,112 @@ byte *VGA_pagebase;
static SDL_Surface *screen = NULL;
static qboolean mouse_avail;
static float mouse_x, mouse_y;
static int mouse_oldbuttonstate = 0;
void VID_SetPalette (unsigned char *palette)
void
VID_InitBuffers (int width, int height)
{
int i;
SDL_Color colors[256];
int tbuffersize, tcachesize;
void *vid_surfcache;
for ( i=0; i<256; ++i )
{
colors[i].r = *palette++;
colors[i].g = *palette++;
colors[i].b = *palette++;
}
SDL_SetColors(screen, colors, 0, 256);
}
// Calculate the sizes we want first
tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
tcachesize = D_SurfaceCacheForRes(width, height);
void VID_ShiftPalette (unsigned char *palette)
{
VID_SetPalette(palette);
}
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");
// Free the old z-buffer
if (d_pzbuffer) {
free (d_pzbuffer);
d_pzbuffer = NULL;
}
// Set video width, height and flags
flags = (SDL_SWSURFACE|SDL_HWPALETTE);
if ( COM_CheckParm ("-fullscreen") )
flags |= SDL_FULLSCREEN;
// Free the old surface cache
vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) {
D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
// 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("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)
// Allocate the new z-buffer
d_pzbuffer = calloc (tbuffersize, 1);
if (!d_pzbuffer) {
Sys_Error ("Not enough memory for video mode\n");
}
// initialize the cache memory
cache = (byte *) d_pzbuffer + vid.width * vid.height *
sizeof (*d_pzbuffer);
D_InitCaches (cache, cachesize);
// Allocate the new surface cache; free the z-buffer if we fail
vid_surfcache = calloc (tcachesize, 1);
if (!vid_surfcache) {
free (d_pzbuffer);
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
// initialize the mouse
SDL_ShowCursor(0);
D_InitCaches (vid_surfcache, tcachesize);
}
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
// 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
mainwindow=GetActiveWindow();
#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
// calloc every frame. - DDOI
while (rects) {
SDL_UpdateRect (screen, rects->x, rects->y, rects->width,
rects->height);
rects = rects->pnext;
}
SDL_Quit();
}
void
VID_Update (vrect_t *rects)
{
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
================
*/
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;
offset = (Uint8 *)screen->pixels + y*screen->pitch + x;
while ( height-- )
{
memcpy(offset, pbitmap, width);
offset += screen->pitch;
pbitmap += width;
}
if (!screen) return;
if ( x < 0 ) x = screen->w+x-1;
offset = (Uint8 *)screen->pixels + y*screen->pitch + x;
while ( height-- ) {
memcpy(offset, pbitmap, width);
offset += screen->pitch;
pbitmap += width;
}
}
/*
================
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)
return;
if (x < 0)
x = screen->w+x-1;
SDL_UpdateRect(screen, x, y, width, height);
if (!screen) return;
if (x < 0) x = screen->w+x-1;
SDL_UpdateRect(screen, x, y, width, height);
}
/*
================
IN_SendKeyEvents
================
*/
void IN_SendKeyEvents (void)
void
VID_LockBuffer ( 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 ( COM_CheckParm("-nomouse") && !_windowed_mouse->int_val)
return;
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;
if (text && *text) {
char *temp = strdup (text);
SDL_WM_SetCaption(va ("%s %s: %s", PROGRAM, VERSION, temp), NULL);
free (temp);
} else {
if ((in_strafe.state & 1) && noclip_anglehack)
cmd->upmove -= m_forward->value * mouse_y;
else
cmd->forwardmove -= m_forward->value * mouse_y;
SDL_WM_SetCaption(va ("%s %s", PROGRAM, VERSION), NULL);
}
mouse_x = mouse_y = 0.0;
}
void VID_InitCvars ()
{
// 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)
void VID_HandlePause (qboolean paused)
{
}

View file

@ -27,91 +27,45 @@
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <signal.h>
#include <values.h>
#include "SDL.h"
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifndef WIN32
#include <sys/signal.h>
#endif
#include <SDL.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 "input.h"
#include "keys.h"
#include "menu.h"
#include "host.h"
#include "qargs.h"
#include "qendian.h"
#include "sys.h"
#include "draw.h"
#include "quakefs.h"
#include "qdefs.h"
#include "va.h"
#include "glquake.h"
#define WARP_WIDTH 320
#define WARP_HEIGHT 200
static qboolean vid_initialized = false;
static qboolean vid_initialized = false;
cvar_t *vid_mode;
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
/* fixme: this is evil hack */
/* FIXME: this is evil hack */
#include <windows.h>
HWND mainwindow;
#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 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;
static qboolean mouse_avail;
static float mouse_x, mouse_y;
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)
{
}
extern void GL_Init_Common(void);
extern void VID_Init8bitPalette(void);
/*-----------------------------------------------------------------------*/
void
VID_Shutdown (void)
@ -123,6 +77,7 @@ VID_Shutdown (void)
SDL_Quit ();
}
#ifndef WIN32
static void
signal_handler(int sig)
@ -148,203 +103,26 @@ InitSig(void)
}
#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
GL_Init (void)
{
gl_vendor = glGetString (GL_VENDOR);
Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
gl_renderer = glGetString (GL_RENDERER);
Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
gl_version = glGetString (GL_VERSION);
Con_Printf ("GL_VERSION: %s\n", gl_version);
gl_extensions = glGetString (GL_EXTENSIONS);
Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
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;
GL_Init_Common();
}
void
GL_EndRendering (void)
{
glFlush();
glFlush ();
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
VID_Init (unsigned char *palette)
{
Uint32 flags = SDL_OPENGL;
int i;
char gldir[MAX_OSPATH];
int width = 640, height = 480;
vid_mode = Cvar_Get ("vid_mode","0",0,"None");
gl_ztrick = Cvar_Get ("gl_ztrick","0",CVAR_ARCHIVE,"None");
vid_fullscreen = Cvar_Get ("vid_fullscreen","0",0,"None");
VID_GetWindowSize (640, 480);
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
@ -354,15 +132,10 @@ VID_Init (unsigned char *palette)
// Interpret command-line params
// 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)
vid.conwidth = atoi(com_argv[i+1]);
else
vid.conwidth = width;
vid.conwidth = scr_width;
vid.conwidth &= 0xfff8; // make it a multiple of eight
if (vid.conwidth < 320)
@ -380,7 +153,7 @@ VID_Init (unsigned char *palette)
Sys_Error ("Couldn't initialize SDL: %s\n", SDL_GetError ());
// Check if we want fullscreen
if (vid_fullscreen->int_val) {
if (vid_fullscreen->value) {
flags |= SDL_FULLSCREEN;
// Don't annoy Mesa/3dfx folks
#ifndef WIN32
@ -401,320 +174,61 @@ VID_Init (unsigned char *palette)
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 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 ());
SDL_Quit ();
}
scr_width = width;
scr_height = height;
vid.height = vid.conheight = min (vid.conheight, height);
vid.width = vid.conwidth = min (vid.conwidth, width);
vid.height = vid.conheight = min (vid.conheight, scr_height);
vid.width = vid.conwidth = min (vid.conwidth, scr_width);
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
vid.numpages = 2;
#ifndef WIN32
InitSig (); // trap evil signals
#endif
GL_Init();
snprintf(gldir, sizeof(gldir), "%s/glquake", com_gamedir);
Sys_mkdir (gldir);
GL_CheckGamma (palette);
//XXX not yet GL_CheckBrightness (palette);
VID_SetPalette (palette);
// Check for 3DFX Extensions and initialize them.
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_initialized = true;
#ifdef WIN32
// fixme: EVIL thing - but needed for win32 until we get
// SDL_sound ready - without this DirectSound fails.
// could replace this with SDL_SysWMInfo
// FIXME: EVIL thing - but needed for win32 until we get
// SDL_sound ready - without this DirectSound fails.
// could replace this with SDL_SysWMInfo
mainwindow=GetActiveWindow();
#endif
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
IN_SendKeyEvents (void)
VID_Init_Cvars ()
{
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;
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;
vid_fullscreen = Cvar_Get ("vid_fullscreen","0",0,"None");
}
void
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 pause)
{
}
void IN_HandlePause (qboolean pause)
void VID_HandlePause (qboolean paused)
{
}

View file

@ -34,17 +34,8 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#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
#include <unistd.h>
#endif
@ -56,13 +47,21 @@
#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);
unsigned short d_8to16table[256];
static byte *vid_surfcache;
static int VID_highhunkmark;
static int num_modes, current_mode;
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
VID_Shutdown(void)
{
@ -405,13 +463,12 @@ VID_SetPalette(byte *palette)
int
VID_SetMode(int modenum, unsigned char *palette)
VID_SetMode (int modenum, unsigned char *palette)
{
int bsize, zsize, tsize;
int err;
if ((modenum >= num_modes) || (modenum < 0) || !modes[modenum].width){
Cvar_SetValue (vid_mode, current_mode);
if ((modenum >= num_modes) || (modenum < 0) || !modes[modenum].width) {
Cvar_SetValue(vid_mode, current_mode);
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);
current_mode=modenum;
current_mode = modenum;
vid.width = modes[current_mode].width;
vid.height = modes[current_mode].height;
@ -446,27 +503,8 @@ VID_SetMode(int modenum, unsigned char *palette)
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
/* alloc zbuffer and surface cache */
if (d_pzbuffer) {
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);
// alloc screen buffer, z-buffer, and surface cache
VID_InitBuffers ();
/* get goin' */
err = vga_setmode(current_mode);
@ -506,6 +544,10 @@ VID_Init(unsigned char *palette)
if (svgalib_inited) return;
#if 0
Cmd_AddCommand ("gamma", VID_Gamma_f);
#endif
if (UseDisplay) {
err = vga_init();
if (err)
@ -513,11 +555,6 @@ VID_Init(unsigned char *palette)
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_describemode", VID_DescribeMode_f);
Cmd_AddCommand("vid_describemodes", VID_DescribeModes_f);
@ -558,6 +595,15 @@ VID_Init(unsigned char *palette)
/* 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
VID_Update(vrect_t *rects)
@ -692,15 +738,20 @@ VID_ExtraOptionCmd(int option_cursor)
#endif
}
void VID_InitCvars ()
{
// It may not look like it, but this is important
}
void
VID_LockBuffer ( void )
{
}
void
VID_UnlockBuffer ( void )
{
}
void VID_SetCaption (char *text)
{
}
void VID_HandlePause (qboolean pause)
void VID_HandlePause (qboolean paused)
{
}

View file

@ -30,6 +30,7 @@
# include "config.h"
#endif
#include "quakedef.h"
#include "va.h"
#include "winquake.h"
#include "sys.h"
#include "resource.h"
@ -46,6 +47,9 @@
#include "console.h"
#include "sbar.h"
extern void (*vid_menudrawfn)(void);
extern void (*vid_menukeyfn)(int);
#define MAX_MODE_LIST 30
#define VID_ROW_SIZE 3
#define WARP_WIDTH 320
@ -127,7 +131,7 @@ HWND WINAPI InitializeWindow (HINSTANCE hInstance, int nCmdShow);
extern viddef_t vid; // global video state
unsigned short d_8to16table[256];
unsigned d_8to24table[256];
unsigned int d_8to24table[256];
unsigned char d_15to8table[65536];
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;
int window_center_x, window_center_y, window_x, window_y, window_width, window_height;
RECT window_rect;
/*
================
VID_InitCvars
================
*/
void
VID_InitCvars ()
{
// It may not look like it, but this is important
}
// direct draw software compatability stuff
void VID_HandlePause (qboolean pause)
@ -469,7 +453,6 @@ int VID_SetMode (int modenum, unsigned char *palette)
SetForegroundWindow (mainwindow);
VID_SetPalette (palette);
vid_modenum = modenum;
Cvar_SetValue (vid_mode, (float)vid_modenum);
while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
@ -489,7 +472,7 @@ int VID_SetMode (int modenum, unsigned char *palette)
ClearAllStates ();
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);
@ -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_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);
@ -712,15 +697,16 @@ void GL_EndRendering (void)
Sbar_Changed();
}
void VID_SetPalette (unsigned char *palette)
void
VID_SetPalette (unsigned char *palette)
{
byte *pal;
unsigned r,g,b;
unsigned v;
unsigned int r,g,b;
unsigned int v;
int r1,g1,b1;
int k;
unsigned short i;
unsigned *table;
unsigned int *table;
QFile *f;
char s[255];
float dist, bestdist;
@ -1538,7 +1524,7 @@ void VID_InitFullDIB (HINSTANCE hInstance)
} while (!done);
if (nummodes == originalnummodes)
Con_SafePrintf ("No fullscreen DIB modes found\n");
Con_Printf ("No fullscreen DIB modes found\n");
}
qboolean VID_Is8bit() {
@ -1559,7 +1545,7 @@ void VID_Init8bitPalette()
COM_CheckParm("-no8bit"))
return;
Con_SafePrintf("8-bit GL extensions enabled.\n");
Con_Printf("8-bit GL extensions enabled.\n");
glEnable( GL_SHARED_TEXTURE_PALETTE_EXT );
oldPalette = (char *) d_8to24table; //d_8to24table3dfx;
newPalette = thePalette;
@ -1589,20 +1575,6 @@ void VID_Init (unsigned char *palette)
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_describecurrentmode", VID_DescribeCurrentMode_f);
Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f);
@ -1806,7 +1778,7 @@ void VID_Init (unsigned char *palette)
DestroyWindow (hwnd_dialog);
GL_CheckGamma(palette);
GL_CheckBrightness (palette);
VID_SetPalette (palette);
VID_SetMode (vid_default, palette);
@ -1840,6 +1812,12 @@ void VID_Init (unsigned char *palette)
fullsbardraw = false;
}
void
VID_Init_Cvars ()
{
_windowed_mouse = Cvar_Get("_windowed_mouse", "0", CVAR_ARCHIVE, "None");
}
//========================================================
// Video menu stuff
@ -1959,5 +1937,11 @@ void VID_MenuKey (int key)
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 "draw.h"
#include "console.h"
#include "va.h"
#include "client.h"
#include "host.h"
#include "input.h"
#include "context_x11.h"
#include "host.h"
#ifdef HAVE_VIDMODE
# include <X11/extensions/xf86vmode.h>
#endif
@ -97,8 +99,6 @@ int VID_options_items = 1;
static byte current_palette[768];
cvar_t *vid_fullscreen;
typedef unsigned short PIXEL16;
typedef unsigned long PIXEL24;
static PIXEL16 st2d_8to16table[256];
@ -107,9 +107,8 @@ static int shiftmask_fl=0;
static long r_shift,g_shift,b_shift;
static unsigned long r_mask,g_mask,b_mask;
static long X11_highhunkmark;
int scr_width, scr_height;
cvar_t *vid_width;
cvar_t *vid_height;
static void
shiftmask_init( void )
@ -299,38 +298,48 @@ void VID_Gamma_f (void)
static void
ResetFrameBuffer(void)
{
int vid_surfcachesize, buffersize;
void *vid_surfcache;
int mem, pwidth;
int tbuffersize, tcachesize;
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]) {
XDestroyImage(x_framebuffer[0]);
}
// Free the old z-buffer
if (d_pzbuffer) {
D_FlushCaches ();
Hunk_FreeToHighMark(X11_highhunkmark);
free (d_pzbuffer);
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 */
buffersize = vid.width * vid.height * sizeof(*d_pzbuffer);
vid_surfcachesize = D_SurfaceCacheForRes(vid.width, vid.height);
buffersize += vid_surfcachesize;
d_pzbuffer = Hunk_HighAllocName(buffersize, "video");
if (d_pzbuffer == NULL) {
// Allocate the new z-buffer
d_pzbuffer = calloc (tbuffersize, 1);
if (!d_pzbuffer) {
Sys_Error ("Not enough memory for video mode\n");
}
vid_surfcache = (byte *) d_pzbuffer
+ vid.width * vid.height * sizeof(*d_pzbuffer);
// Allocate the new surface cache; free the z-buffer if we fail
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;
if (pwidth == 3) pwidth = 4;
@ -351,53 +360,59 @@ ResetFrameBuffer(void)
static void
ResetSharedFrameBuffers(void)
{
int vid_surfcachesize, buffersize;
void *vid_surfcache;
int tbuffersize, tcachesize;
void *vid_surfcache;
int size;
int key;
int minsize = getpagesize();
int frm;
if (d_pzbuffer) {
D_FlushCaches ();
Hunk_FreeToHighMark(X11_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;
}
// Free the old surface cache
vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) {
D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
X11_highhunkmark = Hunk_HighMark ();
// alloc an extra line in case we want to wrap, and allocate the z-buffer
buffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
vid_surfcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
buffersize += vid_surfcachesize;
d_pzbuffer = Hunk_HighAllocName(buffersize, "video");
if (d_pzbuffer == NULL) {
// Allocate the new z-buffer
d_pzbuffer = calloc (tbuffersize, 1);
if (!d_pzbuffer) {
Sys_Error ("Not enough memory for video mode\n");
}
vid_surfcache = (byte *) d_pzbuffer
+ vid.width * vid.height * sizeof (*d_pzbuffer);
// Allocate the new surface cache; free the z-buffer if we fail
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
if (x_framebuffer[frm])
{
// free up old frame buffer memory
if (x_framebuffer[frm]) {
XShmDetach(x_disp, &x_shminfo[frm]);
free(x_framebuffer[frm]);
shmdt(x_shminfo[frm].shmaddr);
}
// create the image
x_framebuffer[frm] = XShmCreateImage( x_disp,
// create the image
x_framebuffer[frm] = XShmCreateImage (x_disp,
x_vis,
x_visinfo->depth,
ZPixmap,
@ -406,10 +421,10 @@ ResetSharedFrameBuffers(void)
vid.width,
vid.height );
// grab shared memory
// grab shared memory
size = x_framebuffer[frm]->bytes_per_line
* x_framebuffer[frm]->height;
if (size < 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;
// get the X server to attach to it
// get the X server to attach to it
if (!XShmAttach(x_disp, &x_shminfo[frm]))
Sys_Error("VID: XShmAttach() failed\n");
XSync(x_disp, 0);
@ -455,57 +469,32 @@ void VID_Init (unsigned char *palette)
int num_visuals;
int template_mask;
VID_GetWindowSize (320, 200);
//plugin_load("in_x11.so");
vid_fullscreen = Cvar_Get ("vid_fullscreen","0",CVAR_NONE,
"Toggles fullscreen game mode");
// Cmd_AddCommand("gamma", VID_Gamma_f);
for (i=0; i < 256; i++) vid_gamma[i] = i;
vid.width = 320;
vid.height = 200;
vid.width = vid_width->int_val;
vid.height = vid_height->int_val;
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
vid.numpages = 2;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
//vid.cbits = VID_CBITS;
//vid.grades = VID_GRADES;
srandom(getpid());
verbose=COM_CheckParm("-verbose");
// open the display
// open the display
x11_open_display();
// 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");
}
// check for command-line window size
template_mask = 0;
// specify a visual id
// specify a visual id
if ((pnum=COM_CheckParm("-visualid")))
{
if (pnum >= com_argc-1)
@ -513,8 +502,7 @@ void VID_Init (unsigned char *palette)
template.visualid = atoi(com_argv[pnum+1]);
template_mask = VisualIDMask;
}
// If not specified, use default visual
// If not specified, use default visual
else
{
template.visualid =
@ -522,7 +510,7 @@ void VID_Init (unsigned char *palette)
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_vis = x_visinfo->visual;
@ -561,9 +549,6 @@ void VID_Init (unsigned char *palette)
/* Invisible cursor */
x11_create_null_cursor();
scr_width = vid.width;
scr_height = vid.height;
if (x_visinfo->depth == 8) {
/* Create and upload the palette */
if (x_visinfo->class == PseudoColor) {
@ -574,7 +559,7 @@ void VID_Init (unsigned char *palette)
}
}
// create the GC
// create the GC
{
XGCValues xgcvalues;
int valuemask = GCGraphicsExposures;
@ -582,12 +567,9 @@ void VID_Init (unsigned char *palette)
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();
// wait for first exposure event
// wait for first exposure event
{
XEvent event;
do
@ -597,9 +579,9 @@ void VID_Init (unsigned char *palette)
oktodraw = true;
} 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 (0)
{
@ -638,6 +620,12 @@ void VID_Init (unsigned char *palette)
x11_add_event(x_shmeventtype, event_shm);
}
void
VID_Init_Cvars ()
{
x11_Init_Cvars();
}
void
VID_ShiftPalette(unsigned char *p)
@ -685,7 +673,6 @@ VID_Shutdown(void)
if (x_disp) {
x11_restore_vidmode();
x11_close_display();
x_disp = 0;
}
}
@ -780,7 +767,7 @@ VID_DitherOn( void )
void
VID_DitherOff( void )
VID_DitherOff (void)
{
if (dither) {
vid.recalc_refdef = 1;
@ -788,15 +775,28 @@ VID_DitherOff( void )
}
}
void VID_InitCvars ()
void
VID_LockBuffer ( void )
{
}
void
VID_UnlockBuffer ( void )
{
}
void
VID_SetCaption (char *text)
{
// It may not look like it, but this is important
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_SetCaption (char *text)
{
}
void VID_HandlePause (qboolean pause)
void VID_HandlePause (qboolean paused)
{
}