2001-04-15 04:18:22 +00:00
|
|
|
/*
|
|
|
|
vid_wgl.c
|
|
|
|
|
|
|
|
Win32 WGL vid component
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2003-01-15 15:31:36 +00:00
|
|
|
static __attribute__ ((unused)) const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
#include "winquake.h"
|
|
|
|
|
|
|
|
#include "QF/cdaudio.h"
|
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/console.h"
|
2001-06-01 00:39:31 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-04-17 06:55:50 +00:00
|
|
|
#include "QF/input.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
#include "QF/keys.h"
|
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/qendian.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2001-04-17 06:55:50 +00:00
|
|
|
#include "QF/screen.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
#include "QF/sound.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/va.h"
|
2001-04-17 06:55:50 +00:00
|
|
|
#include "QF/vid.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "QF/GL/funcs.h"
|
2003-01-06 18:28:13 +00:00
|
|
|
#include "QF/GL/qf_vid.h"
|
2001-04-17 06:55:50 +00:00
|
|
|
|
2001-06-01 00:39:31 +00:00
|
|
|
#include "compat.h"
|
2001-04-17 06:55:50 +00:00
|
|
|
#include "in_win.h"
|
2001-07-05 17:28:19 +00:00
|
|
|
#include "r_cvar.h"
|
2002-08-20 19:16:11 +00:00
|
|
|
#include "win32/resources/resource.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "sbar.h"
|
2001-04-17 06:55:50 +00:00
|
|
|
|
2001-10-29 16:45:03 +00:00
|
|
|
extern const char *gl_renderer;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
HWND mainwindow;
|
|
|
|
qboolean win_canalttab = false;
|
|
|
|
modestate_t modestate = MS_UNINIT;
|
|
|
|
RECT window_rect;
|
|
|
|
DEVMODE win_gdevmode;
|
|
|
|
int window_center_x, window_center_y, window_x, window_y, window_width,
|
|
|
|
window_height;
|
|
|
|
|
|
|
|
static HGLRC (GLAPIENTRY *qf_wglCreateContext) (HDC);
|
|
|
|
static BOOL (GLAPIENTRY *qf_wglDeleteContext) (HGLRC);
|
|
|
|
static HGLRC (GLAPIENTRY *qf_wglGetCurrentContext) (void);
|
|
|
|
static HDC (GLAPIENTRY *qf_wglGetCurrentDC) (void);
|
|
|
|
static BOOL (GLAPIENTRY *qf_wglMakeCurrent) (HDC, HGLRC);
|
2001-07-05 17:28:19 +00:00
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
#define MAX_MODE_LIST 30
|
|
|
|
#define VID_ROW_SIZE 3
|
|
|
|
#define WARP_WIDTH 320
|
|
|
|
#define WARP_HEIGHT 200
|
|
|
|
#define MAXWIDTH 10000
|
|
|
|
#define MAXHEIGHT 10000
|
|
|
|
#define BASEWIDTH 320
|
|
|
|
#define BASEHEIGHT 200
|
|
|
|
|
|
|
|
#define MODE_WINDOWED 0
|
|
|
|
#define NO_MODE (MODE_WINDOWED - 1)
|
|
|
|
#define MODE_FULLSCREEN_DEFAULT (MODE_WINDOWED + 1)
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
modestate_t type;
|
2002-06-27 18:50:26 +00:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int modenum;
|
|
|
|
int dib;
|
|
|
|
int fullscreen;
|
|
|
|
int bpp;
|
|
|
|
int halfscreen;
|
|
|
|
char modedesc[17];
|
2001-04-15 04:18:22 +00:00
|
|
|
} vmode_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2002-06-27 18:50:26 +00:00
|
|
|
int width;
|
|
|
|
int height;
|
2001-04-15 04:18:22 +00:00
|
|
|
} lmode_t;
|
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static lmode_t lowresmodes[] = {
|
2001-04-15 04:18:22 +00:00
|
|
|
{320, 200},
|
|
|
|
{320, 240},
|
|
|
|
{400, 300},
|
|
|
|
{512, 384},
|
|
|
|
};
|
|
|
|
|
2002-06-24 21:35:37 +00:00
|
|
|
static int nummodes;
|
|
|
|
static vmode_t modelist[MAX_MODE_LIST];
|
|
|
|
static vmode_t badmode;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-06-24 21:35:37 +00:00
|
|
|
static qboolean windowed, leavecurrentmode;
|
|
|
|
static int windowed_mouse;
|
2001-04-15 04:18:22 +00:00
|
|
|
static HICON hIcon;
|
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static RECT WindowRect;
|
|
|
|
static DWORD WindowStyle;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static int vid_modenum = NO_MODE;
|
|
|
|
static int vid_realmode;
|
|
|
|
static int vid_default = MODE_WINDOWED;
|
2002-06-27 18:50:26 +00:00
|
|
|
static int windowed_default;
|
|
|
|
static qboolean fullsbardraw = true;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static HDC maindc;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static char *VID_GetModeDescription (int mode);
|
|
|
|
static void GL_Init (void);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static void * (WINAPI *glGetProcAddress) (const char *symbol) = NULL;
|
2002-08-16 18:29:21 +00:00
|
|
|
|
|
|
|
void *
|
|
|
|
QFGL_GetProcAddress (void *handle, const char *name)
|
|
|
|
{
|
|
|
|
void *glfunc = NULL;
|
|
|
|
|
|
|
|
if (glGetProcAddress)
|
|
|
|
glfunc = glGetProcAddress (name);
|
|
|
|
if (!glfunc)
|
|
|
|
glfunc = GetProcAddress (handle, name);
|
|
|
|
return glfunc;
|
|
|
|
}
|
2002-06-24 21:35:37 +00:00
|
|
|
|
|
|
|
void *
|
|
|
|
QFGL_LoadLibrary (void)
|
|
|
|
{
|
|
|
|
void *handle;
|
|
|
|
|
|
|
|
if (!(handle = LoadLibrary (gl_driver->string)))
|
|
|
|
Sys_Error ("Couldn't load OpenGL library %s!", gl_driver->string);
|
|
|
|
(FARPROC)glGetProcAddress = GetProcAddress (handle, "wglGetProcAddress");
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//====================================
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static void
|
2001-04-15 04:18:22 +00:00
|
|
|
CenterWindow (HWND hWndCenter, int width, int height, BOOL lefttopjustify)
|
|
|
|
{
|
2002-06-27 18:50:26 +00:00
|
|
|
int CenterX, CenterY;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
CenterX = (GetSystemMetrics (SM_CXSCREEN) - width) / 2;
|
|
|
|
CenterY = (GetSystemMetrics (SM_CYSCREEN) - height) / 2;
|
|
|
|
if (CenterX > CenterY * 2)
|
2002-06-27 18:50:26 +00:00
|
|
|
CenterX >>= 1; // dual screens
|
2001-04-15 04:18:22 +00:00
|
|
|
CenterX = (CenterX < 0) ? 0 : CenterX;
|
|
|
|
CenterY = (CenterY < 0) ? 0 : CenterY;
|
|
|
|
SetWindowPos (hWndCenter, NULL, CenterX, CenterY, 0, 0,
|
|
|
|
SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
|
|
|
|
}
|
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static qboolean
|
2001-04-15 04:18:22 +00:00
|
|
|
VID_SetWindowedMode (int modenum)
|
|
|
|
{
|
2002-06-27 18:50:26 +00:00
|
|
|
HDC hdc;
|
|
|
|
int lastmodestate, width, height;
|
|
|
|
RECT rect;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
lastmodestate = modestate;
|
|
|
|
|
|
|
|
WindowRect.top = WindowRect.left = 0;
|
|
|
|
|
|
|
|
WindowRect.right = modelist[modenum].width;
|
|
|
|
WindowRect.bottom = modelist[modenum].height;
|
|
|
|
|
|
|
|
window_width = modelist[modenum].width;
|
|
|
|
window_height = modelist[modenum].height;
|
|
|
|
|
|
|
|
WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU |
|
|
|
|
WS_MINIMIZEBOX | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
|
|
|
|
|
|
|
|
rect = WindowRect;
|
|
|
|
AdjustWindowRect (&rect, WindowStyle, FALSE);
|
|
|
|
|
|
|
|
width = rect.right - rect.left;
|
|
|
|
height = rect.bottom - rect.top;
|
|
|
|
|
|
|
|
// Create the window
|
|
|
|
mainwindow = CreateWindow ("QuakeForge", "GLQuakeWorld",
|
2001-08-25 02:47:11 +00:00
|
|
|
WindowStyle, rect.left, rect.top, width, height,
|
|
|
|
NULL, NULL, global_hInstance, NULL);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
if (!mainwindow)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Couldn't create DIB window (%lx)",GetLastError());
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
// Center and show the window
|
2001-04-15 04:18:22 +00:00
|
|
|
CenterWindow (mainwindow, WindowRect.right - WindowRect.left,
|
2002-06-27 18:50:26 +00:00
|
|
|
WindowRect.bottom - WindowRect.top, false);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
ShowWindow (mainwindow, SW_SHOWDEFAULT);
|
|
|
|
UpdateWindow (mainwindow);
|
|
|
|
|
|
|
|
modestate = MS_WINDOWED;
|
|
|
|
|
2002-06-27 18:50:26 +00:00
|
|
|
// because we have set the background brush for the window to NULL
|
|
|
|
// (to avoid flickering when re-sizing the window on the desktop),
|
|
|
|
// we clear the window to black when created, otherwise it will be
|
|
|
|
// empty while Quake starts up.
|
2001-08-25 02:47:11 +00:00
|
|
|
hdc = GetDC (mainwindow);
|
2001-04-15 04:18:22 +00:00
|
|
|
PatBlt (hdc, 0, 0, WindowRect.right, WindowRect.bottom, BLACKNESS);
|
2002-06-27 18:50:26 +00:00
|
|
|
ReleaseDC (mainwindow, hdc);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
if (vid.conheight > modelist[modenum].height)
|
|
|
|
vid.conheight = modelist[modenum].height;
|
|
|
|
if (vid.conwidth > modelist[modenum].width)
|
|
|
|
vid.conwidth = modelist[modenum].width;
|
2001-10-22 02:15:30 +00:00
|
|
|
scr_width = vid.width = vid.conwidth;
|
|
|
|
scr_height = vid.height = vid.conheight;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
vid.numpages = 2;
|
|
|
|
|
|
|
|
if(hIcon) {
|
|
|
|
SendMessage (mainwindow, WM_SETICON, (WPARAM) TRUE, (LPARAM) hIcon);
|
|
|
|
SendMessage (mainwindow, WM_SETICON, (WPARAM) FALSE, (LPARAM) hIcon);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static qboolean
|
2001-04-15 04:18:22 +00:00
|
|
|
VID_SetFullDIBMode (int modenum)
|
|
|
|
{
|
2002-06-27 18:50:26 +00:00
|
|
|
HDC hdc;
|
|
|
|
int lastmodestate, width, height;
|
|
|
|
RECT rect;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-06-27 18:50:26 +00:00
|
|
|
memset (&win_gdevmode,0,sizeof(win_gdevmode));
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
if (!leavecurrentmode) {
|
2001-10-22 04:13:56 +00:00
|
|
|
win_gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
|
|
|
win_gdevmode.dmBitsPerPel = modelist[modenum].bpp;
|
|
|
|
win_gdevmode.dmPelsWidth = modelist[modenum].width <<
|
2001-04-15 04:18:22 +00:00
|
|
|
modelist[modenum].halfscreen;
|
2001-10-22 04:13:56 +00:00
|
|
|
win_gdevmode.dmPelsHeight = modelist[modenum].height;
|
|
|
|
win_gdevmode.dmSize = sizeof (win_gdevmode);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2001-10-22 04:13:56 +00:00
|
|
|
if (ChangeDisplaySettings (&win_gdevmode, CDS_FULLSCREEN) !=
|
2001-04-15 04:18:22 +00:00
|
|
|
DISP_CHANGE_SUCCESSFUL)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Couldn't set fullscreen DIB mode (%lx)",
|
2001-08-25 02:47:11 +00:00
|
|
|
GetLastError());
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lastmodestate = modestate;
|
|
|
|
modestate = MS_FULLDIB;
|
|
|
|
|
|
|
|
WindowRect.top = WindowRect.left = 0;
|
|
|
|
|
|
|
|
WindowRect.right = modelist[modenum].width;
|
|
|
|
WindowRect.bottom = modelist[modenum].height;
|
|
|
|
|
|
|
|
|
|
|
|
window_width = modelist[modenum].width;
|
|
|
|
window_height = modelist[modenum].height;
|
|
|
|
|
|
|
|
// FIXME: some drivers have broken FS popup window handling
|
|
|
|
// until I find way around it, or find some other cause for it
|
|
|
|
// this is way to avoid it
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
if (COM_CheckParm ("-brokenpopup")) WindowStyle = 0;
|
|
|
|
else WindowStyle = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
rect = WindowRect;
|
|
|
|
AdjustWindowRect (&rect, WindowStyle, FALSE);
|
|
|
|
|
|
|
|
width = rect.right - rect.left;
|
|
|
|
height = rect.bottom - rect.top;
|
|
|
|
|
|
|
|
// Create the DIB window
|
|
|
|
mainwindow = CreateWindow ("QuakeForge", "GLQuakeWorld",
|
|
|
|
WindowStyle, rect.left, rect.top, width, height, NULL, NULL,
|
|
|
|
global_hInstance, NULL);
|
|
|
|
|
|
|
|
if (!mainwindow)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Couldn't create DIB window (%lx)",GetLastError());
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
ShowWindow (mainwindow, SW_SHOWDEFAULT);
|
|
|
|
UpdateWindow (mainwindow);
|
|
|
|
|
|
|
|
// Because we have set the background brush for the window to NULL
|
|
|
|
// (to avoid flickering when re-sizing the window on the desktop), we
|
|
|
|
// clear the window to black when created, otherwise it will be
|
|
|
|
// empty while Quake starts up.
|
|
|
|
hdc = GetDC (mainwindow);
|
|
|
|
PatBlt (hdc, 0, 0, WindowRect.right, WindowRect.bottom, BLACKNESS);
|
|
|
|
ReleaseDC (mainwindow, hdc);
|
|
|
|
|
|
|
|
if (vid.conheight > modelist[modenum].height)
|
|
|
|
vid.conheight = modelist[modenum].height;
|
|
|
|
if (vid.conwidth > modelist[modenum].width)
|
|
|
|
vid.conwidth = modelist[modenum].width;
|
2001-10-22 02:15:30 +00:00
|
|
|
scr_width = vid.width = vid.conwidth;
|
|
|
|
scr_height = vid.height = vid.conheight;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
vid.numpages = 2;
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
// needed because we're not getting WM_MOVE messages fullscreen on NT
|
2001-04-15 04:18:22 +00:00
|
|
|
window_x = 0;
|
|
|
|
window_y = 0;
|
|
|
|
|
|
|
|
if (hIcon) {
|
|
|
|
SendMessage (mainwindow, WM_SETICON, (WPARAM) TRUE, (LPARAM) hIcon);
|
|
|
|
SendMessage (mainwindow, WM_SETICON, (WPARAM) FALSE, (LPARAM) hIcon);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static int
|
2001-04-15 04:18:22 +00:00
|
|
|
VID_SetMode (int modenum, unsigned char *palette)
|
|
|
|
{
|
2002-12-12 05:12:09 +00:00
|
|
|
int original_mode;
|
2002-06-27 18:50:26 +00:00
|
|
|
qboolean stat = 0;
|
|
|
|
MSG msg;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
if ((windowed && (modenum != 0)) ||
|
|
|
|
(!windowed && (modenum < 1)) || (!windowed && (modenum >= nummodes))) {
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Bad video mode");
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
// so Con_Printfs don't mess us up by forcing vid and snd updates
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
CDAudio_Pause ();
|
|
|
|
|
|
|
|
if (vid_modenum == NO_MODE)
|
|
|
|
original_mode = windowed_default;
|
|
|
|
else
|
|
|
|
original_mode = vid_modenum;
|
|
|
|
|
|
|
|
// Set either the fullscreen or windowed mode
|
|
|
|
if (modelist[modenum].type == MS_WINDOWED) {
|
2001-08-30 20:04:13 +00:00
|
|
|
if (in_grab->int_val && key_dest == key_game) {
|
2001-04-15 04:18:22 +00:00
|
|
|
stat = VID_SetWindowedMode (modenum);
|
|
|
|
IN_ActivateMouse ();
|
|
|
|
IN_HideMouse ();
|
|
|
|
} else {
|
|
|
|
IN_DeactivateMouse ();
|
|
|
|
IN_ShowMouse ();
|
|
|
|
stat = VID_SetWindowedMode (modenum);
|
|
|
|
}
|
|
|
|
} else if (modelist[modenum].type == MS_FULLDIB) {
|
|
|
|
stat = VID_SetFullDIBMode (modenum);
|
|
|
|
IN_ActivateMouse ();
|
|
|
|
IN_HideMouse ();
|
|
|
|
} else {
|
|
|
|
Sys_Error ("VID_SetMode: Bad mode type in modelist");
|
|
|
|
}
|
|
|
|
|
2001-10-22 04:13:56 +00:00
|
|
|
VID_UpdateWindowStatus (window_x, window_y);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
CDAudio_Resume ();
|
|
|
|
|
|
|
|
if (!stat) {
|
|
|
|
Sys_Error ("Couldn't set video mode");
|
|
|
|
}
|
2002-06-27 18:50:26 +00:00
|
|
|
|
|
|
|
// Now we try to make sure we get the focus on the mode switch, because
|
|
|
|
// sometimes in some systems we don't. We grab the foreground, then
|
|
|
|
// finish setting up, pump all our messages, and sleep for a little while
|
|
|
|
// to let messages finish bouncing around the system, then we put
|
|
|
|
// ourselves at the top of the z order, then grab the foreground again,
|
|
|
|
// Who knows if it helps, but it probably doesn't hurt
|
2001-04-15 04:18:22 +00:00
|
|
|
SetForegroundWindow (mainwindow);
|
|
|
|
VID_SetPalette (palette);
|
|
|
|
vid_modenum = modenum;
|
|
|
|
|
|
|
|
while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) {
|
|
|
|
TranslateMessage (&msg);
|
|
|
|
DispatchMessage (&msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sleep (100);
|
|
|
|
|
|
|
|
SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0,
|
|
|
|
SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW |
|
|
|
|
SWP_NOCOPYBITS);
|
|
|
|
|
|
|
|
SetForegroundWindow (mainwindow);
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
// fix the leftover Alt from any Alt-Tab or the like that switched us away
|
2001-11-12 20:58:06 +00:00
|
|
|
IN_ClearStates ();
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2001-04-17 06:55:50 +00:00
|
|
|
Con_Printf ("Video mode %s initialized.\n",
|
|
|
|
VID_GetModeDescription (vid_modenum));
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
VID_SetPalette (palette);
|
|
|
|
|
|
|
|
vid.recalc_refdef = 1;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-10-22 04:13:56 +00:00
|
|
|
VID_UpdateWindowStatus (int w_x, int w_y)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
2001-10-22 04:13:56 +00:00
|
|
|
window_rect.left = window_x = w_x;
|
|
|
|
window_rect.top = window_y = w_y;
|
2001-04-15 04:18:22 +00:00
|
|
|
window_rect.right = window_x + window_width;
|
|
|
|
window_rect.bottom = window_y + window_height;
|
|
|
|
window_center_x = (window_rect.left + window_rect.right) / 2;
|
|
|
|
window_center_y = (window_rect.top + window_rect.bottom) / 2;
|
|
|
|
|
|
|
|
IN_UpdateClipCursor ();
|
|
|
|
}
|
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static void
|
2001-04-15 04:18:22 +00:00
|
|
|
GL_Init (void)
|
|
|
|
{
|
2001-04-17 06:55:50 +00:00
|
|
|
GL_Init_Common ();
|
2001-04-15 04:18:22 +00:00
|
|
|
if (strnicmp (gl_renderer, "PowerVR", 7) == 0)
|
|
|
|
fullsbardraw = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GL_EndRendering (void)
|
|
|
|
{
|
2002-02-27 05:22:21 +00:00
|
|
|
if (!scr_skipupdate || block_drawing) {
|
|
|
|
qfglFinish ();
|
2001-04-15 04:18:22 +00:00
|
|
|
SwapBuffers (maindc);
|
2002-02-27 05:22:21 +00:00
|
|
|
}
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
// handle the mouse state when windowed if that's changed
|
2001-04-15 04:18:22 +00:00
|
|
|
if (modestate == MS_WINDOWED) {
|
2001-08-30 20:04:13 +00:00
|
|
|
if (!in_grab->int_val) {
|
2001-04-15 04:18:22 +00:00
|
|
|
if (windowed_mouse) {
|
|
|
|
IN_DeactivateMouse ();
|
|
|
|
IN_ShowMouse ();
|
|
|
|
windowed_mouse = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
windowed_mouse = true;
|
2001-04-17 06:55:50 +00:00
|
|
|
if (key_dest == key_game && !in_mouse_avail && ActiveApp) {
|
2001-04-15 04:18:22 +00:00
|
|
|
IN_ActivateMouse ();
|
|
|
|
IN_HideMouse ();
|
2001-04-17 06:55:50 +00:00
|
|
|
} else if (in_mouse_avail && key_dest != key_game) {
|
2001-04-15 04:18:22 +00:00
|
|
|
IN_DeactivateMouse ();
|
|
|
|
IN_ShowMouse ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fullsbardraw)
|
|
|
|
Sbar_Changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_Shutdown (void)
|
|
|
|
{
|
2002-06-27 18:50:26 +00:00
|
|
|
HGLRC hRC;
|
|
|
|
HDC hDC;
|
|
|
|
int i, temp[8192];
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
#ifdef SPLASH_SCREEN
|
2002-06-27 18:50:26 +00:00
|
|
|
if(hwnd_dialog)
|
|
|
|
DestroyWindow (hwnd_dialog);
|
2001-04-15 04:18:22 +00:00
|
|
|
#endif
|
|
|
|
|
2001-05-25 04:03:47 +00:00
|
|
|
if (vid.initialized) {
|
2001-10-22 04:13:56 +00:00
|
|
|
win_canalttab = false;
|
2001-07-05 17:28:19 +00:00
|
|
|
hRC = qf_wglGetCurrentContext ();
|
|
|
|
hDC = qf_wglGetCurrentDC ();
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2001-07-05 17:28:19 +00:00
|
|
|
qf_wglMakeCurrent (NULL, NULL);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
// LordHavoc: free textures before closing (may help NVIDIA)
|
|
|
|
for (i = 0; i < 8192; i++)
|
2002-06-27 18:50:26 +00:00
|
|
|
temp[i] = i + 1;
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDeleteTextures (8192, temp);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
if (hRC)
|
2001-07-05 17:28:19 +00:00
|
|
|
qf_wglDeleteContext (hRC);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-06-27 18:50:26 +00:00
|
|
|
if (hDC && mainwindow)
|
|
|
|
ReleaseDC (mainwindow, hDC);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
if (modestate == MS_FULLDIB)
|
|
|
|
ChangeDisplaySettings (NULL, 0);
|
|
|
|
|
2002-06-27 18:50:26 +00:00
|
|
|
if (maindc && mainwindow)
|
|
|
|
ReleaseDC (mainwindow, maindc);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
AppActivate (false, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static BOOL
|
2001-04-15 04:18:22 +00:00
|
|
|
bSetupPixelFormat (HDC hDC)
|
|
|
|
{
|
|
|
|
PIXELFORMATDESCRIPTOR pfd ;
|
2002-06-27 18:50:26 +00:00
|
|
|
int pixelformat;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-06-27 18:50:26 +00:00
|
|
|
memset (&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
|
|
|
|
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
|
|
|
pfd.nVersion = 1;
|
|
|
|
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
|
2001-04-15 04:18:22 +00:00
|
|
|
pfd.iPixelType = PFD_TYPE_RGBA;
|
|
|
|
|
2002-06-27 18:50:26 +00:00
|
|
|
if (!modelist[vid_default].bpp)
|
|
|
|
pfd.cColorBits = 16;
|
|
|
|
else
|
|
|
|
pfd.cColorBits = modelist[vid_default].bpp;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
pfd.cDepthBits = 32;
|
|
|
|
pfd.iLayerType = PFD_MAIN_PLANE;
|
|
|
|
|
|
|
|
if ((pixelformat = ChoosePixelFormat (hDC, &pfd)) == 0) {
|
|
|
|
MessageBox (NULL, "ChoosePixelFormat failed", "Error", MB_OK);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SetPixelFormat (hDC, pixelformat, &pfd) == FALSE) {
|
|
|
|
MessageBox (NULL, "SetPixelFormat failed", "Error", MB_OK);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static int
|
2001-04-15 04:18:22 +00:00
|
|
|
VID_NumModes (void)
|
|
|
|
{
|
|
|
|
return nummodes;
|
|
|
|
}
|
|
|
|
|
2003-01-07 20:02:30 +00:00
|
|
|
static vmode_t *
|
2001-04-15 04:18:22 +00:00
|
|
|
VID_GetModePtr (int modenum)
|
|
|
|
{
|
|
|
|
if ((modenum >= 0) && (modenum < nummodes))
|
|
|
|
return &modelist[modenum];
|
|
|
|
else
|
|
|
|
return &badmode;
|
|
|
|
}
|
|
|
|
|
2003-01-07 20:02:30 +00:00
|
|
|
static char *
|
2001-04-15 04:18:22 +00:00
|
|
|
VID_GetModeDescription (int mode)
|
|
|
|
{
|
2002-06-27 18:50:26 +00:00
|
|
|
char *pinfo;
|
|
|
|
vmode_t *pv;
|
|
|
|
static char temp[100];
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
if ((mode < 0) || (mode >= nummodes))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!leavecurrentmode) {
|
|
|
|
pv = VID_GetModePtr (mode);
|
|
|
|
pinfo = pv->modedesc;
|
|
|
|
} else {
|
|
|
|
snprintf (temp, sizeof (temp), "Desktop resolution (%dx%d)",
|
|
|
|
modelist[MODE_FULLSCREEN_DEFAULT].width,
|
|
|
|
modelist[MODE_FULLSCREEN_DEFAULT].height);
|
|
|
|
pinfo = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// KJB: Added this to return the mode driver name in description for console
|
2002-12-16 23:26:14 +00:00
|
|
|
static char *
|
2001-04-15 04:18:22 +00:00
|
|
|
VID_GetExtModeDescription (int mode)
|
|
|
|
{
|
|
|
|
static char pinfo[40];
|
2002-06-27 18:50:26 +00:00
|
|
|
vmode_t *pv;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
if ((mode < 0) || (mode >= nummodes))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pv = VID_GetModePtr (mode);
|
|
|
|
if (modelist[mode].type == MS_FULLDIB) {
|
|
|
|
if (!leavecurrentmode) {
|
|
|
|
snprintf (pinfo, sizeof (pinfo), "%s fullscreen", pv->modedesc);
|
|
|
|
} else {
|
|
|
|
snprintf (pinfo, sizeof (pinfo), "Desktop resolution (%dx%d)",
|
|
|
|
modelist[MODE_FULLSCREEN_DEFAULT].width,
|
|
|
|
modelist[MODE_FULLSCREEN_DEFAULT].height);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (modestate == MS_WINDOWED)
|
|
|
|
snprintf (pinfo, sizeof (pinfo), "%s windowed", pv->modedesc);
|
|
|
|
else
|
|
|
|
snprintf (pinfo, sizeof (pinfo), "windowed");
|
|
|
|
}
|
|
|
|
|
|
|
|
return pinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static void
|
2001-04-15 04:18:22 +00:00
|
|
|
VID_InitDIB (HINSTANCE hInstance)
|
|
|
|
{
|
2002-06-27 18:50:26 +00:00
|
|
|
WNDCLASS wc;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-06-27 18:50:26 +00:00
|
|
|
// Register the frame class
|
2001-04-15 04:18:22 +00:00
|
|
|
wc.style = 0;
|
|
|
|
wc.lpfnWndProc = (WNDPROC) MainWndProc;
|
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 0;
|
|
|
|
wc.hInstance = hInstance;
|
|
|
|
wc.hIcon = 0;
|
|
|
|
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
|
|
|
|
wc.hbrBackground = NULL;
|
|
|
|
wc.lpszMenuName = 0;
|
|
|
|
wc.lpszClassName = "QuakeForge";
|
|
|
|
|
|
|
|
if (!RegisterClass (&wc))
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Couldn't register window class (%lx)", GetLastError());
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
modelist[0].type = MS_WINDOWED;
|
|
|
|
|
|
|
|
if (COM_CheckParm ("-width"))
|
|
|
|
modelist[0].width = atoi (com_argv[COM_CheckParm ("-width") + 1]);
|
|
|
|
else
|
|
|
|
modelist[0].width = 640;
|
|
|
|
|
|
|
|
if (modelist[0].width < 320)
|
|
|
|
modelist[0].width = 320;
|
|
|
|
|
|
|
|
if (COM_CheckParm ("-height"))
|
|
|
|
modelist[0].height = atoi (com_argv[COM_CheckParm ("-height") + 1]);
|
|
|
|
else
|
|
|
|
modelist[0].height = modelist[0].width * 240 / 320;
|
|
|
|
|
|
|
|
if (modelist[0].height < 240)
|
|
|
|
modelist[0].height = 240;
|
|
|
|
|
|
|
|
snprintf (modelist[0].modedesc, sizeof (modelist[0].modedesc), "%dx%d",
|
|
|
|
modelist[0].width, modelist[0].height);
|
|
|
|
|
|
|
|
modelist[0].modenum = MODE_WINDOWED;
|
|
|
|
modelist[0].dib = 1;
|
|
|
|
modelist[0].fullscreen = 0;
|
|
|
|
modelist[0].halfscreen = 0;
|
|
|
|
modelist[0].bpp = 0;
|
|
|
|
|
|
|
|
nummodes = 1;
|
|
|
|
}
|
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static void
|
2001-04-15 04:18:22 +00:00
|
|
|
VID_InitFullDIB (HINSTANCE hInstance)
|
|
|
|
{
|
2002-06-27 18:50:26 +00:00
|
|
|
DEVMODE devmode;
|
|
|
|
int i, modenum, originalnummodes, existingmode, numlowresmodes;
|
|
|
|
int j, bpp, done;
|
|
|
|
BOOL stat;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
// enumerate >8 bpp modes
|
2001-04-15 04:18:22 +00:00
|
|
|
originalnummodes = nummodes;
|
|
|
|
modenum = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
stat = EnumDisplaySettings (NULL, modenum, &devmode);
|
|
|
|
|
|
|
|
if ((devmode.dmBitsPerPel >= 15) &&
|
|
|
|
(devmode.dmPelsWidth <= MAXWIDTH) &&
|
2001-08-25 02:47:11 +00:00
|
|
|
(devmode.dmPelsHeight <= MAXHEIGHT) &&
|
|
|
|
(nummodes < MAX_MODE_LIST)) {
|
2001-04-15 04:18:22 +00:00
|
|
|
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
|
|
|
|
|
|
|
if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) ==
|
|
|
|
DISP_CHANGE_SUCCESSFUL) {
|
|
|
|
modelist[nummodes].type = MS_FULLDIB;
|
|
|
|
modelist[nummodes].width = devmode.dmPelsWidth;
|
|
|
|
modelist[nummodes].height = devmode.dmPelsHeight;
|
|
|
|
modelist[nummodes].modenum = 0;
|
|
|
|
modelist[nummodes].halfscreen = 0;
|
|
|
|
modelist[nummodes].dib = 1;
|
|
|
|
modelist[nummodes].fullscreen = 1;
|
|
|
|
modelist[nummodes].bpp = devmode.dmBitsPerPel;
|
|
|
|
snprintf (modelist[nummodes].modedesc,
|
2002-01-19 20:45:45 +00:00
|
|
|
sizeof (modelist[nummodes].modedesc), "%ldx%ldx%ld",
|
2001-04-15 04:18:22 +00:00
|
|
|
devmode.dmPelsWidth, devmode.dmPelsHeight,
|
|
|
|
devmode.dmBitsPerPel);
|
|
|
|
|
|
|
|
// if the width is more than twice the height, reduce it by
|
2001-08-25 02:47:11 +00:00
|
|
|
// half because this is probably a dual-screen monitor
|
2001-04-15 04:18:22 +00:00
|
|
|
if (!COM_CheckParm ("-noadjustaspect")) {
|
|
|
|
if (modelist[nummodes].width >
|
|
|
|
(modelist[nummodes].height << 1)) {
|
|
|
|
modelist[nummodes].width >>= 1;
|
|
|
|
modelist[nummodes].halfscreen = 1;
|
|
|
|
snprintf (modelist[nummodes].modedesc,
|
|
|
|
sizeof (modelist[nummodes].modedesc),
|
|
|
|
"%dx%dx%d", modelist[nummodes].width,
|
|
|
|
modelist[nummodes].height,
|
|
|
|
modelist[nummodes].bpp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
for (i = originalnummodes, existingmode = 0; i < nummodes;
|
|
|
|
i++) {
|
2001-04-15 04:18:22 +00:00
|
|
|
if ((modelist[nummodes].width == modelist[i].width) &&
|
|
|
|
(modelist[nummodes].height == modelist[i].height) &&
|
|
|
|
(modelist[nummodes].bpp == modelist[i].bpp)) {
|
|
|
|
existingmode = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!existingmode) {
|
|
|
|
nummodes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
modenum++;
|
|
|
|
} while (stat);
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
// see if there are any low-res modes that aren't being reported
|
2001-04-15 04:18:22 +00:00
|
|
|
numlowresmodes = sizeof (lowresmodes) / sizeof (lowresmodes[0]);
|
|
|
|
bpp = 16;
|
|
|
|
done = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
for (j = 0; (j < numlowresmodes) && (nummodes < MAX_MODE_LIST); j++) {
|
|
|
|
devmode.dmBitsPerPel = bpp;
|
|
|
|
devmode.dmPelsWidth = lowresmodes[j].width;
|
|
|
|
devmode.dmPelsHeight = lowresmodes[j].height;
|
|
|
|
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
|
|
|
|
|
|
|
if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) ==
|
|
|
|
DISP_CHANGE_SUCCESSFUL) {
|
|
|
|
modelist[nummodes].type = MS_FULLDIB;
|
|
|
|
modelist[nummodes].width = devmode.dmPelsWidth;
|
|
|
|
modelist[nummodes].height = devmode.dmPelsHeight;
|
|
|
|
modelist[nummodes].modenum = 0;
|
|
|
|
modelist[nummodes].halfscreen = 0;
|
|
|
|
modelist[nummodes].dib = 1;
|
|
|
|
modelist[nummodes].fullscreen = 1;
|
|
|
|
modelist[nummodes].bpp = devmode.dmBitsPerPel;
|
|
|
|
snprintf (modelist[nummodes].modedesc,
|
2002-01-19 20:45:45 +00:00
|
|
|
sizeof (modelist[nummodes].modedesc), "%ldx%ldx%ld",
|
2001-04-15 04:18:22 +00:00
|
|
|
devmode.dmPelsWidth, devmode.dmPelsHeight,
|
|
|
|
devmode.dmBitsPerPel);
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
for (i = originalnummodes, existingmode = 0; i < nummodes;
|
|
|
|
i++) {
|
2001-04-15 04:18:22 +00:00
|
|
|
if ((modelist[nummodes].width == modelist[i].width) &&
|
|
|
|
(modelist[nummodes].height == modelist[i].height) &&
|
|
|
|
(modelist[nummodes].bpp == modelist[i].bpp)) {
|
|
|
|
existingmode = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!existingmode) {
|
|
|
|
nummodes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (bpp) {
|
|
|
|
case 16:
|
|
|
|
bpp = 32;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
bpp = 24;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
done = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (!done);
|
|
|
|
|
|
|
|
if (nummodes == originalnummodes)
|
|
|
|
Con_Printf ("No fullscreen DIB modes found\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_Init (unsigned char *palette)
|
|
|
|
{
|
2002-06-27 18:50:26 +00:00
|
|
|
int i, existingmode;
|
|
|
|
int basenummodes, width, height=480, bpp, findbpp, done;
|
|
|
|
HDC hdc;
|
|
|
|
DEVMODE devmode;
|
|
|
|
HGLRC baseRC;
|
|
|
|
DWORD lasterror;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2001-10-15 19:06:22 +00:00
|
|
|
GL_Pre_Init ();
|
2001-07-05 17:28:19 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
qf_wglCreateContext = QFGL_ProcAddress (libgl_handle, "wglCreateContext",
|
|
|
|
true);
|
|
|
|
qf_wglDeleteContext = QFGL_ProcAddress (libgl_handle, "wglDeleteContext",
|
|
|
|
true);
|
|
|
|
qf_wglGetCurrentContext = QFGL_ProcAddress (libgl_handle,
|
|
|
|
"wglGetCurrentContext", true);
|
|
|
|
qf_wglGetCurrentDC = QFGL_ProcAddress (libgl_handle, "wglGetCurrentDC",
|
|
|
|
true);
|
|
|
|
qf_wglMakeCurrent = QFGL_ProcAddress (libgl_handle, "wglMakeCurrent",
|
|
|
|
true);
|
2001-07-05 17:28:19 +00:00
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
memset (&devmode, 0, sizeof (devmode));
|
|
|
|
|
|
|
|
hIcon = LoadIcon (global_hInstance, MAKEINTRESOURCE (IDI_ICON1));
|
|
|
|
|
|
|
|
VID_InitDIB (global_hInstance);
|
|
|
|
basenummodes = nummodes = 1;
|
|
|
|
|
|
|
|
VID_InitFullDIB (global_hInstance);
|
|
|
|
|
|
|
|
if (COM_CheckParm ("-window")) {
|
|
|
|
hdc = GetDC (NULL);
|
|
|
|
|
|
|
|
if (GetDeviceCaps (hdc, RASTERCAPS) & RC_PALETTE) {
|
|
|
|
Sys_Error ("Can't run in non-RGB mode");
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseDC (NULL, hdc);
|
|
|
|
|
|
|
|
windowed = true;
|
|
|
|
|
|
|
|
vid_default = MODE_WINDOWED;
|
|
|
|
} else {
|
|
|
|
if (nummodes == 1)
|
|
|
|
Sys_Error ("No RGB fullscreen modes available");
|
|
|
|
|
|
|
|
windowed = false;
|
|
|
|
|
|
|
|
if (COM_CheckParm ("-mode")) {
|
|
|
|
vid_default = atoi (com_argv[COM_CheckParm ("-mode") + 1]);
|
|
|
|
} else {
|
|
|
|
if (COM_CheckParm ("-current")) {
|
|
|
|
modelist[MODE_FULLSCREEN_DEFAULT].width =
|
|
|
|
GetSystemMetrics (SM_CXSCREEN);
|
|
|
|
modelist[MODE_FULLSCREEN_DEFAULT].height =
|
|
|
|
GetSystemMetrics (SM_CYSCREEN);
|
|
|
|
vid_default = MODE_FULLSCREEN_DEFAULT;
|
|
|
|
leavecurrentmode = 1;
|
|
|
|
} else {
|
|
|
|
if (COM_CheckParm ("-width")) {
|
|
|
|
width = atoi (com_argv[COM_CheckParm ("-width") + 1]);
|
|
|
|
} else {
|
|
|
|
width = 640;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (COM_CheckParm ("-bpp")) {
|
|
|
|
bpp = atoi (com_argv[COM_CheckParm ("-bpp") + 1]);
|
|
|
|
findbpp = 0;
|
|
|
|
} else {
|
|
|
|
bpp = 15;
|
|
|
|
findbpp = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (COM_CheckParm ("-height"))
|
|
|
|
height = atoi (com_argv[COM_CheckParm ("-height") + 1]);
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
// if they want to force it, add the specified mode to the list
|
2001-04-15 04:18:22 +00:00
|
|
|
if (COM_CheckParm ("-force") && (nummodes < MAX_MODE_LIST)) {
|
|
|
|
modelist[nummodes].type = MS_FULLDIB;
|
|
|
|
modelist[nummodes].width = width;
|
|
|
|
modelist[nummodes].height = height;
|
|
|
|
modelist[nummodes].modenum = 0;
|
|
|
|
modelist[nummodes].halfscreen = 0;
|
|
|
|
modelist[nummodes].dib = 1;
|
|
|
|
modelist[nummodes].fullscreen = 1;
|
|
|
|
modelist[nummodes].bpp = bpp;
|
|
|
|
snprintf (modelist[nummodes].modedesc,
|
2002-01-19 20:45:45 +00:00
|
|
|
sizeof (modelist[nummodes].modedesc),
|
2002-06-27 18:50:26 +00:00
|
|
|
"%ldx%ldx%ld", devmode.dmPelsWidth,
|
|
|
|
devmode.dmPelsHeight, devmode.dmBitsPerPel);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
for (i = nummodes, existingmode = 0; i < nummodes; i++) {
|
|
|
|
if ((modelist[nummodes].width == modelist[i].width) &&
|
2001-08-25 02:47:11 +00:00
|
|
|
(modelist[nummodes].height == modelist[i].height)
|
|
|
|
&& (modelist[nummodes].bpp == modelist[i].bpp)) {
|
2001-04-15 04:18:22 +00:00
|
|
|
existingmode = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!existingmode) {
|
|
|
|
nummodes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (COM_CheckParm ("-height")) {
|
2002-06-27 18:50:26 +00:00
|
|
|
height = atoi
|
|
|
|
(com_argv[COM_CheckParm ("-height") + 1]);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
for (i = 1, vid_default = 0; i < nummodes; i++) {
|
|
|
|
if ((modelist[i].width == width) &&
|
|
|
|
(modelist[i].height == height) &&
|
|
|
|
(modelist[i].bpp == bpp)) {
|
|
|
|
vid_default = i;
|
|
|
|
done = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 1, vid_default = 0; i < nummodes; i++) {
|
|
|
|
if ((modelist[i].width == width)
|
|
|
|
&& (modelist[i].bpp == bpp)) {
|
|
|
|
vid_default = i;
|
|
|
|
done = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!done) {
|
|
|
|
if (findbpp) {
|
|
|
|
switch (bpp) {
|
|
|
|
case 15:
|
|
|
|
bpp = 16;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
bpp = 32;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
bpp = 24;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
done = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
done = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (!done);
|
|
|
|
|
|
|
|
if (!vid_default) {
|
|
|
|
Sys_Error ("Specified video mode not available");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((i = COM_CheckParm ("-conwidth")) != 0)
|
|
|
|
vid.conwidth = atoi (com_argv[i + 1]);
|
|
|
|
else
|
|
|
|
vid.conwidth = 640;
|
|
|
|
|
|
|
|
vid.conwidth &= 0xfff8; // make it a multiple of eight
|
|
|
|
|
|
|
|
if (vid.conwidth < 320)
|
|
|
|
vid.conwidth = 320;
|
|
|
|
|
|
|
|
// pick a conheight that matches with correct aspect
|
2003-05-07 07:10:15 +00:00
|
|
|
vid.conheight = (vid.conwidth * 3) / 4;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
if ((i = COM_CheckParm ("-conheight")) != 0)
|
|
|
|
vid.conheight = atoi (com_argv[i + 1]);
|
|
|
|
if (vid.conheight < 200)
|
|
|
|
vid.conheight = 200;
|
|
|
|
|
|
|
|
vid.maxwarpwidth = WARP_WIDTH;
|
|
|
|
vid.maxwarpheight = WARP_HEIGHT;
|
2001-08-25 02:47:11 +00:00
|
|
|
vid.colormap8 = vid_colormap;
|
|
|
|
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap8 + 2048));
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
#ifdef SPLASH_SCREEN
|
2001-10-22 02:15:30 +00:00
|
|
|
if(hwnd_dialog)
|
2002-06-27 18:50:26 +00:00
|
|
|
DestroyWindow (hwnd_dialog);
|
2001-04-15 04:18:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
VID_SetMode (vid_default, palette);
|
|
|
|
|
|
|
|
maindc = GetDC (mainwindow);
|
|
|
|
bSetupPixelFormat (maindc);
|
|
|
|
|
2001-07-05 17:28:19 +00:00
|
|
|
baseRC = qf_wglCreateContext (maindc);
|
2001-04-15 04:18:22 +00:00
|
|
|
if (!baseRC) {
|
|
|
|
lasterror=GetLastError();
|
|
|
|
if (maindc && mainwindow)
|
|
|
|
ReleaseDC (mainwindow, maindc);
|
2001-08-25 02:47:11 +00:00
|
|
|
Sys_Error("Could not initialize GL (wglCreateContext failed).\n\nMake "
|
|
|
|
"sure you in are 65535 color mode, and try running -window. "
|
2002-05-14 06:12:29 +00:00
|
|
|
"\nError code: (%lx)", lasterror);
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
2001-07-05 17:28:19 +00:00
|
|
|
if (!qf_wglMakeCurrent (maindc, baseRC)) {
|
2001-04-15 04:18:22 +00:00
|
|
|
lasterror=GetLastError();
|
|
|
|
if (baseRC)
|
2001-07-05 17:28:19 +00:00
|
|
|
qf_wglDeleteContext (baseRC);
|
2002-06-27 18:50:26 +00:00
|
|
|
if (maindc && mainwindow)
|
|
|
|
ReleaseDC (mainwindow, maindc);
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("wglMakeCurrent failed (%lx)", lasterror);
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GL_Init ();
|
|
|
|
|
2001-10-22 02:15:30 +00:00
|
|
|
VID_InitGamma (palette);
|
|
|
|
VID_Init8bitPalette ();
|
2002-09-10 06:35:32 +00:00
|
|
|
VID_SetPalette (vid.palette);
|
2001-10-22 02:15:30 +00:00
|
|
|
|
|
|
|
vid.initialized = true;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
vid_realmode = vid_modenum;
|
|
|
|
|
|
|
|
strcpy (badmode.modedesc, "Bad mode");
|
2001-10-22 04:13:56 +00:00
|
|
|
win_canalttab = true;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
if (COM_CheckParm ("-nofullsbar"))
|
|
|
|
fullsbardraw = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_Init_Cvars ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-07-15 07:04:17 +00:00
|
|
|
VID_SetCaption (const char *text)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
|
|
|
if (text && *text) {
|
|
|
|
char *temp = strdup (text);
|
|
|
|
|
|
|
|
SetWindowText (mainwindow,
|
2002-06-27 18:50:26 +00:00
|
|
|
(LPSTR) va ("%s %s: %s", PROGRAM, VERSION, temp));
|
2001-04-15 04:18:22 +00:00
|
|
|
free (temp);
|
|
|
|
} else {
|
|
|
|
SetWindowText (mainwindow, (LPSTR) va ("%s %s", PROGRAM, VERSION));
|
|
|
|
}
|
|
|
|
}
|
2001-04-17 06:55:50 +00:00
|
|
|
|
2002-02-26 00:14:16 +00:00
|
|
|
static WORD systemgammaramps[3][256];
|
|
|
|
static WORD currentgammaramps[3][256];
|
|
|
|
|
2001-04-17 06:55:50 +00:00
|
|
|
qboolean
|
|
|
|
VID_SetGamma (double gamma)
|
|
|
|
{
|
2002-06-27 18:50:26 +00:00
|
|
|
int i;
|
|
|
|
HDC hdc = GetDC (NULL);
|
2002-02-26 00:14:16 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 256; i++) {
|
2002-06-27 18:50:26 +00:00
|
|
|
currentgammaramps[2][i] = currentgammaramps[1][i] =
|
2002-02-26 00:14:16 +00:00
|
|
|
currentgammaramps[0][i] = gammatable[i] * 256;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = SetDeviceGammaRamp (hdc, ¤tgammaramps[0][0]);
|
|
|
|
ReleaseDC (NULL, hdc);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static void
|
2002-02-26 00:14:16 +00:00
|
|
|
VID_SaveGamma (void)
|
|
|
|
{
|
2002-06-27 18:50:26 +00:00
|
|
|
HDC hdc = GetDC (NULL);
|
2002-02-26 00:14:16 +00:00
|
|
|
|
|
|
|
GetDeviceGammaRamp (hdc, &systemgammaramps[0][0]);
|
|
|
|
ReleaseDC (NULL, hdc);
|
|
|
|
}
|
|
|
|
|
2002-12-16 23:26:14 +00:00
|
|
|
static void
|
2002-02-26 00:14:16 +00:00
|
|
|
VID_RestoreGamma (void)
|
|
|
|
{
|
2002-06-27 18:50:26 +00:00
|
|
|
HDC hdc = GetDC (NULL);
|
2002-02-26 00:14:16 +00:00
|
|
|
|
|
|
|
SetDeviceGammaRamp (hdc, &systemgammaramps[0][0]);
|
|
|
|
ReleaseDC (NULL, hdc);
|
2001-04-17 06:55:50 +00:00
|
|
|
}
|