From dcd1201131f6b45271df24ad751a0d7ad96be975 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 21 Oct 2000 07:15:30 +0000 Subject: [PATCH] create VID_GetWindowSize in vid.c and use it elsewhere for window size selection. in_x11.c just had refs to scr_width and scr_height removed. --- include/vid.h | 2 + source/Makefile.am | 9 ++-- source/in_x11.c | 2 - source/vid.c | 119 ++++++++++++++++++++++++++++++++++++++++++ source/vid_3dfxsvga.c | 17 ++---- source/vid_glx.c | 32 ++++-------- source/vid_sgl.c | 19 +++---- source/vid_x11.c | 62 ++++++---------------- 8 files changed, 161 insertions(+), 101 deletions(-) create mode 100644 source/vid.c diff --git a/include/vid.h b/include/vid.h index 83f4ae2..6f44028 100644 --- a/include/vid.h +++ b/include/vid.h @@ -101,4 +101,6 @@ qboolean VID_Is8bit(void); void VID_SetCaption(char *text); // used to set window caption +void VID_GetWindowSize (int def_w, int def_h); + #endif // _VID_H diff --git a/source/Makefile.am b/source/Makefile.am index 5f7d8a0..877686c 100644 --- a/source/Makefile.am +++ b/source/Makefile.am @@ -145,11 +145,10 @@ if ASM_ARCH client_ASM= snd_mixa.S cl_math.S sys_x86.S endif -client_SOURCES= cl_cmd.c cl_cvar.c cl_demo.c cl_ents.c cl_input.c cl_main.c \ - cl_misc.c cl_parse.c cl_pred.c cl_tent.c cl_cam.c teamplay.c \ - r_view.c wad.c model_alias.c model_sprite.c \ - console.c keys.c menu.c nonintel.c skin.c sbar.c \ - cl_slist.c $(client_ASM) +client_SOURCES= cl_cam.c cl_cmd.c cl_cvar.c cl_demo.c cl_ents.c cl_input.c \ + cl_main.c cl_misc.c cl_parse.c cl_pred.c cl_slist.c cl_tent.c \ + console.c keys.c menu.c model_alias.c model_sprite.c nonintel.c \ + r_view.c sbar.c skin.c teamplay.c wad.c vid.c $(client_ASM) # # Software-rendering clients diff --git a/source/in_x11.c b/source/in_x11.c index b6eb5e9..5398ab1 100644 --- a/source/in_x11.c +++ b/source/in_x11.c @@ -400,8 +400,6 @@ IN_Shutdown (void) x11_close_display(); } -extern int scr_width, scr_height; - void IN_Init (void) { diff --git a/source/vid.c b/source/vid.c new file mode 100644 index 0000000..6e980ac --- /dev/null +++ b/source/vid.c @@ -0,0 +1,119 @@ +/* + vid.c + + general video driver functions + + Copyright (C) 1996-1997 Id Software, Inc. + Copyright (C) 1999-2000 contributors of the QuakeForge project + Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se] + Copyright (C) 1999,2000 contributors of the QuakeForge project + Please see the file "AUTHORS" for a list of contributors + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + + $Id$ +*/ + +#define _BSD +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif +#include +#include +#include +#include +#include +#include +#include + +#include "qendian.h" +#include "qargs.h" +#include "quakedef.h" +#include "d_local.h" +#include "keys.h" +#include "cvar.h" +#include "menu.h" +#include "sys.h" +#include "cmd.h" +#include "input.h" +#include "draw.h" +#include "console.h" +#include "client.h" +#include "input.h" +#include "context_x11.h" +#ifdef HAVE_VIDMODE +# include +#endif +#include "dga_check.h" + +#ifdef HAVE_STRINGS_H +#include +#endif + +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 \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 \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 \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; +} diff --git a/source/vid_3dfxsvga.c b/source/vid_3dfxsvga.c index b452e17..de415f3 100644 --- a/source/vid_3dfxsvga.c +++ b/source/vid_3dfxsvga.c @@ -72,7 +72,7 @@ static void *dlhand = NULL; #endif static fxMesaContext fc = NULL; -static int scr_width, scr_height; +extern int scr_width, scr_height; static qboolean is8bit = 0; int VID_options_items = 0; @@ -367,11 +367,6 @@ 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); } @@ -533,6 +528,8 @@ void VID_Init(unsigned char *palette) char gldir[MAX_OSPATH]; int width = 640, height = 480; + VID_GetWindowSize (640, 480); + vid.maxwarpwidth = WARP_WIDTH; vid.maxwarpheight = WARP_HEIGHT; vid.colormap = host_colormap; @@ -548,11 +545,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 @@ -576,9 +568,6 @@ void VID_Init(unsigned char *palette) if (!fc) Sys_Error("Unable to create 3DFX context.\n"); - scr_width = width; - scr_height = height; - fxMesaMakeCurrent(fc); if (vid.conheight > height) diff --git a/source/vid_glx.c b/source/vid_glx.c index b2aeec2..15af873 100644 --- a/source/vid_glx.c +++ b/source/vid_glx.c @@ -384,11 +384,6 @@ 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); } @@ -440,7 +435,7 @@ void VID_Init8bitPalette(void) void VID_Init(unsigned char *palette) { int i; - int attrib[] = { + static int attrib[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, @@ -450,8 +445,8 @@ void VID_Init(unsigned char *palette) None }; char gldir[MAX_OSPATH]; - int width = 640, height = 480; + VID_GetWindowSize (640, 480); vid_mode = Cvar_Get ("vid_mode","0",0,"None"); vid.maxwarpwidth = WARP_WIDTH; vid.maxwarpheight = WARP_HEIGHT; @@ -462,15 +457,11 @@ void VID_Init(unsigned char *palette) */ /* 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) @@ -536,8 +527,8 @@ void VID_Init(unsigned char *palette) // 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(); @@ -552,13 +543,10 @@ void VID_Init(unsigned char *palette) glXMakeCurrent(x_disp, x_win, ctx); - scr_width = width; - scr_height = height; - - 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; @@ -579,7 +567,7 @@ void VID_Init(unsigned char *palette) VID_Init8bitPalette(); Con_Printf ("Video mode %dx%d initialized.\n", - width, height); + scr_width, scr_height); vid_initialized = true; diff --git a/source/vid_sgl.c b/source/vid_sgl.c index a1b2e11..74a0d91 100644 --- a/source/vid_sgl.c +++ b/source/vid_sgl.c @@ -71,7 +71,7 @@ unsigned short d_8to16table[256]; unsigned int d_8to24table[256]; unsigned char d_15to8table[65536]; -int scr_width, scr_height; +extern int scr_width, scr_height; int VID_options_items = 1; int texture_mode = GL_LINEAR; @@ -330,7 +330,8 @@ VID_Init (unsigned char *palette) Uint32 flags = SDL_OPENGL; int i; char gldir[MAX_OSPATH]; - int width = 640, height = 480; + + VID_GetWindowSize (640, 480); vid_fullscreen = Cvar_Get ("vid_fullscreen","0",0,"None"); @@ -342,11 +343,6 @@ 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 @@ -394,9 +390,6 @@ VID_Init (unsigned char *palette) SDL_Quit (); } - scr_width = width; - scr_height = height; - vid.height = vid.conheight = min (vid.conheight, height); vid.width = vid.conwidth = min (vid.conwidth, width); @@ -422,9 +415,9 @@ VID_Init (unsigned char *palette) 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 diff --git a/source/vid_x11.c b/source/vid_x11.c index d0ef90c..b081824 100644 --- a/source/vid_x11.c +++ b/source/vid_x11.c @@ -105,9 +105,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 ) @@ -468,55 +467,32 @@ void VID_Init (unsigned char *palette) int num_visuals; int template_mask; + VID_GetWindowSize (320, 200); + //plugin_load("in_x11.so"); // 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 \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 \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 \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) @@ -524,8 +500,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 = @@ -533,7 +508,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; @@ -566,15 +541,12 @@ void VID_Init (unsigned char *palette) /* Setup attributes for main window */ x11_set_vidmode(vid.width, vid.height); - /* Create the main window */ + /* Create the main window */ x11_create_window(vid.width, vid.height); /* 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) { @@ -585,7 +557,7 @@ void VID_Init (unsigned char *palette) } } -// create the GC + // create the GC { XGCValues xgcvalues; int valuemask = GCGraphicsExposures; @@ -593,12 +565,12 @@ void VID_Init (unsigned char *palette) x_gc = XCreateGC(x_disp, x_win, valuemask, &xgcvalues ); } -// map the window + // 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 @@ -608,9 +580,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) {