2010-05-25 10:56:00 +00:00
|
|
|
// Windows DIB/DirectDraw interface layer for the Build Engine
|
2012-03-12 04:47:04 +00:00
|
|
|
// Originally by Jonathon Fowler (jf@jonof.id.au)
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2017-02-25 08:15:36 +00:00
|
|
|
#include "compat.h"
|
2016-11-18 05:29:51 +00:00
|
|
|
|
|
|
|
#include "build.h"
|
2017-02-19 22:15:44 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
#ifdef USE_OPENGL
|
|
|
|
#include "glbuild.h"
|
|
|
|
#include "glad/glad_wgl.h"
|
|
|
|
#endif
|
|
|
|
|
2017-02-19 22:15:44 +00:00
|
|
|
#define NEED_DINPUT_H
|
|
|
|
#define NEED_DDRAW_H
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
# define NEED_CRTDBG_H
|
|
|
|
#endif
|
|
|
|
#include "windows_inc.h"
|
|
|
|
|
2016-11-18 05:29:51 +00:00
|
|
|
#include "winlayer.h"
|
|
|
|
#include "rawinput.h"
|
|
|
|
#include "mutex.h"
|
|
|
|
|
|
|
|
#include "winbits.h"
|
|
|
|
#include "engine_priv.h"
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#include "dxdidf.h" // comment this out if c_dfDI* is being reported as multiply defined
|
2016-11-18 05:29:51 +00:00
|
|
|
|
|
|
|
#include <signal.h>
|
2012-11-25 04:26:37 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
// undefine to restrict windowed resolutions to conventional sizes
|
|
|
|
#define ANY_WINDOWED_SIZE
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
static mutex_t m_initprintf;
|
2011-10-27 13:14:22 +00:00
|
|
|
static int32_t winlayer_have_ATI = 0;
|
2010-06-22 21:50:01 +00:00
|
|
|
|
2013-03-18 22:05:21 +00:00
|
|
|
static int32_t _buildargc = 0;
|
|
|
|
static const char **_buildargv = NULL;
|
2006-04-13 20:47:06 +00:00
|
|
|
static char *argvbuf = NULL;
|
|
|
|
|
|
|
|
// Windows crud
|
|
|
|
static HINSTANCE hInstance = 0;
|
|
|
|
static HWND hWindow = 0;
|
|
|
|
#define WINDOW_STYLE (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX)
|
|
|
|
static BOOL window_class_registered = FALSE;
|
|
|
|
|
2013-04-13 03:50:19 +00:00
|
|
|
static DDGAMMARAMP sysgamma;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2006-04-13 20:47:06 +00:00
|
|
|
// OpenGL stuff
|
|
|
|
static HGLRC hGLRC = 0;
|
2015-01-11 04:56:58 +00:00
|
|
|
int32_t nofog=0;
|
2008-08-26 19:50:34 +00:00
|
|
|
char nogl=0;
|
|
|
|
char forcegl=0;
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
static const char *GetDDrawError(HRESULT code);
|
|
|
|
static const char *GetDInputError(HRESULT code);
|
2006-04-13 20:47:06 +00:00
|
|
|
static void ShowDDrawErrorBox(const char *m, HRESULT r);
|
|
|
|
static void ShowDInputErrorBox(const char *m, HRESULT r);
|
|
|
|
static LRESULT CALLBACK WndProcCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
|
|
|
static BOOL InitDirectDraw(void);
|
|
|
|
static void UninitDirectDraw(void);
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t RestoreDirectDrawMode(void);
|
2006-04-13 20:47:06 +00:00
|
|
|
static void ReleaseDirectDrawSurfaces(void);
|
|
|
|
static BOOL InitDirectInput(void);
|
|
|
|
static void UninitDirectInput(void);
|
|
|
|
static void GetKeyNames(void);
|
2010-05-18 00:30:30 +00:00
|
|
|
static void AcquireInputDevices(char acquire);
|
2010-05-07 20:45:40 +00:00
|
|
|
static inline void DI_PollJoysticks(void);
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t SetupDirectDraw(int32_t width, int32_t height);
|
2006-04-13 20:47:06 +00:00
|
|
|
static void UninitDIB(void);
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t SetupDIB(int32_t width, int32_t height);
|
2013-01-08 06:17:10 +00:00
|
|
|
#ifdef USE_OPENGL
|
2006-04-13 20:47:06 +00:00
|
|
|
static void ReleaseOpenGL(void);
|
|
|
|
static void UninitOpenGL(void);
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t SetupOpenGL(int32_t width, int32_t height, int32_t bitspp);
|
2013-01-08 06:17:10 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
static BOOL RegisterWindowClass(void);
|
2009-01-09 09:29:17 +00:00
|
|
|
static BOOL CreateAppWindow(int32_t modenum);
|
2006-04-13 20:47:06 +00:00
|
|
|
static void DestroyAppWindow(void);
|
|
|
|
|
|
|
|
// video
|
2010-05-25 10:56:00 +00:00
|
|
|
static int32_t desktopxdim=0;
|
|
|
|
static int32_t desktopydim=0;
|
|
|
|
static int32_t desktopbpp=0;
|
|
|
|
static int32_t modesetusing=-1;
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t curvidmode = -1;
|
2010-05-25 10:56:00 +00:00
|
|
|
static int32_t customxdim = 640;
|
|
|
|
static int32_t customydim = 480;
|
|
|
|
static int32_t custombpp = 8;
|
|
|
|
static int32_t customfs = 0;
|
2009-01-10 07:38:50 +00:00
|
|
|
static uint32_t modeschecked=0;
|
2010-05-25 10:56:00 +00:00
|
|
|
int32_t xres=-1;
|
|
|
|
int32_t yres=-1;
|
|
|
|
int32_t fullscreen=0;
|
|
|
|
int32_t bpp=0;
|
|
|
|
int32_t bytesperline=0;
|
|
|
|
int32_t lockcount=0;
|
|
|
|
int32_t glcolourdepth=32;
|
2016-12-26 06:01:36 +00:00
|
|
|
static int32_t vsync_renderlayer;
|
2009-01-10 07:38:50 +00:00
|
|
|
uint32_t maxrefreshfreq=60;
|
2010-05-25 10:56:00 +00:00
|
|
|
intptr_t frameplace=0;
|
|
|
|
char modechange=1;
|
|
|
|
char repaintneeded=0;
|
2006-04-13 20:47:06 +00:00
|
|
|
char offscreenrendering=0;
|
|
|
|
char videomodereset = 0;
|
2010-05-25 10:56:00 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
// input and events
|
2010-05-25 10:56:00 +00:00
|
|
|
char quitevent=0;
|
|
|
|
char appactive=1;
|
|
|
|
char realfs=0;
|
|
|
|
char regrabmouse=0;
|
2013-12-20 07:24:09 +00:00
|
|
|
int32_t inputchecked = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-19 10:02:35 +00:00
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
// DINPUT (JOYSTICK)
|
|
|
|
//=================================================================================================
|
|
|
|
|
|
|
|
#define JOYSTICK 0
|
|
|
|
|
|
|
|
static HMODULE hDInputDLL = NULL;
|
|
|
|
static LPDIRECTINPUT7A lpDI = NULL;
|
|
|
|
static LPDIRECTINPUTDEVICE7A lpDID = NULL;
|
|
|
|
#define INPUT_BUFFER_SIZE 32
|
|
|
|
static GUID guidDevs;
|
|
|
|
|
2010-11-23 22:30:27 +00:00
|
|
|
char di_disabled = 0;
|
2010-05-19 10:02:35 +00:00
|
|
|
static char di_devacquired;
|
2010-11-23 22:30:27 +00:00
|
|
|
static HANDLE di_inputevt = 0;
|
2018-06-13 19:15:22 +00:00
|
|
|
//static int32_t joyblast=0;
|
2010-05-19 10:02:35 +00:00
|
|
|
|
|
|
|
static struct
|
|
|
|
{
|
2016-01-12 10:30:48 +00:00
|
|
|
char const *name;
|
2010-05-19 10:02:35 +00:00
|
|
|
LPDIRECTINPUTDEVICE7A *did;
|
2012-12-16 05:46:20 +00:00
|
|
|
LPCDIDATAFORMAT df;
|
2010-05-19 10:02:35 +00:00
|
|
|
} devicedef = { "joystick", &lpDID, &c_dfDIJoystick };
|
|
|
|
|
|
|
|
static struct _joydef
|
|
|
|
{
|
2015-09-27 21:18:19 +00:00
|
|
|
char *name;
|
2010-05-19 10:02:35 +00:00
|
|
|
uint32_t ofs; // directinput 'dwOfs' value
|
|
|
|
} *axisdefs = NULL, *buttondefs = NULL, *hatdefs = NULL;
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
// MAIN CRAP
|
|
|
|
//=================================================================================================
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// win_gethwnd() -- gets the window handle
|
|
|
|
//
|
Win64 support! (Meaning it works, not that we recommend it for everyday use.)
This includes a complete Windows header and library refresh, including the addition of 64-bit compiled libs:
*libogg 1.3.0
*libvorbis 1.3.3
*zlib 1.2.7
*libpng 1.5.13
*libvpx 9a3de881c0e681ba1a79a166a86308bbc84b4acd
*SDL_mixer 1.2.12 (for RENDERTYPE=SDL)
*DirectX import libraries: dsound and dxguid (now included)
To build in 64-bit, you essentially need MinGW's MSYS (but not MinGW itself) and MinGW-w64 at the top of your PATH. The target is automatically detected using `$(CC) -dumpmachine`. The EDukeWiki will get detailed instrucitons.
All compiler and linker warnings when building in 64-bit mode have been fixed.
Remaining 64-bit to-do:
- The ebacktrace dll does not build under 64-bit. It uses code specific to the format of 32-bit executables and will have to be ported to work with 64-bit executables. A future 64-bit version will be named ebacktrace1-64.dll.
- RENDERTYPE=SDL crashes in SDL_mixer's Mix_Linked_Version().
- DirectInput gives an error and does not function. This only affects joysticks, and the error never happens without any plugged in.
- Port the classic renderer ASM to 64-bit. (Just kidding, this is way out of my league.)
This commit includes a fair bit of Makefile development spanning all platforms, including simplifying the SDLCONFIG code, fixing build on Mac OS X (thanks rhoenie!), globally factoring Apple brew/port inclusion, enforcing that all -L come before all -l, and ensuring that $(shell ) is always :='d.
In addition, I have resurrected the old GCC_MAJOR and GCC_MINOR detection using `$(CC) -dumpversion`, but I have made it failsafe in case the command fails or the version is manually specified. I have applied this new fine-grained detection where applicable, including allowing LTO, and restraining -W's to versions that support them.
git-svn-id: https://svn.eduke32.com/eduke32@3278 1a8010ca-5511-0410-912e-c29ae57300e0
2012-12-13 02:37:20 +00:00
|
|
|
HWND win_gethwnd(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
Win64 support! (Meaning it works, not that we recommend it for everyday use.)
This includes a complete Windows header and library refresh, including the addition of 64-bit compiled libs:
*libogg 1.3.0
*libvorbis 1.3.3
*zlib 1.2.7
*libpng 1.5.13
*libvpx 9a3de881c0e681ba1a79a166a86308bbc84b4acd
*SDL_mixer 1.2.12 (for RENDERTYPE=SDL)
*DirectX import libraries: dsound and dxguid (now included)
To build in 64-bit, you essentially need MinGW's MSYS (but not MinGW itself) and MinGW-w64 at the top of your PATH. The target is automatically detected using `$(CC) -dumpmachine`. The EDukeWiki will get detailed instrucitons.
All compiler and linker warnings when building in 64-bit mode have been fixed.
Remaining 64-bit to-do:
- The ebacktrace dll does not build under 64-bit. It uses code specific to the format of 32-bit executables and will have to be ported to work with 64-bit executables. A future 64-bit version will be named ebacktrace1-64.dll.
- RENDERTYPE=SDL crashes in SDL_mixer's Mix_Linked_Version().
- DirectInput gives an error and does not function. This only affects joysticks, and the error never happens without any plugged in.
- Port the classic renderer ASM to 64-bit. (Just kidding, this is way out of my league.)
This commit includes a fair bit of Makefile development spanning all platforms, including simplifying the SDLCONFIG code, fixing build on Mac OS X (thanks rhoenie!), globally factoring Apple brew/port inclusion, enforcing that all -L come before all -l, and ensuring that $(shell ) is always :='d.
In addition, I have resurrected the old GCC_MAJOR and GCC_MINOR detection using `$(CC) -dumpversion`, but I have made it failsafe in case the command fails or the version is manually specified. I have applied this new fine-grained detection where applicable, including allowing LTO, and restraining -W's to versions that support them.
git-svn-id: https://svn.eduke32.com/eduke32@3278 1a8010ca-5511-0410-912e-c29ae57300e0
2012-12-13 02:37:20 +00:00
|
|
|
return hWindow;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// win_gethinstance() -- gets the application instance
|
|
|
|
//
|
Win64 support! (Meaning it works, not that we recommend it for everyday use.)
This includes a complete Windows header and library refresh, including the addition of 64-bit compiled libs:
*libogg 1.3.0
*libvorbis 1.3.3
*zlib 1.2.7
*libpng 1.5.13
*libvpx 9a3de881c0e681ba1a79a166a86308bbc84b4acd
*SDL_mixer 1.2.12 (for RENDERTYPE=SDL)
*DirectX import libraries: dsound and dxguid (now included)
To build in 64-bit, you essentially need MinGW's MSYS (but not MinGW itself) and MinGW-w64 at the top of your PATH. The target is automatically detected using `$(CC) -dumpmachine`. The EDukeWiki will get detailed instrucitons.
All compiler and linker warnings when building in 64-bit mode have been fixed.
Remaining 64-bit to-do:
- The ebacktrace dll does not build under 64-bit. It uses code specific to the format of 32-bit executables and will have to be ported to work with 64-bit executables. A future 64-bit version will be named ebacktrace1-64.dll.
- RENDERTYPE=SDL crashes in SDL_mixer's Mix_Linked_Version().
- DirectInput gives an error and does not function. This only affects joysticks, and the error never happens without any plugged in.
- Port the classic renderer ASM to 64-bit. (Just kidding, this is way out of my league.)
This commit includes a fair bit of Makefile development spanning all platforms, including simplifying the SDLCONFIG code, fixing build on Mac OS X (thanks rhoenie!), globally factoring Apple brew/port inclusion, enforcing that all -L come before all -l, and ensuring that $(shell ) is always :='d.
In addition, I have resurrected the old GCC_MAJOR and GCC_MINOR detection using `$(CC) -dumpversion`, but I have made it failsafe in case the command fails or the version is manually specified. I have applied this new fine-grained detection where applicable, including allowing LTO, and restraining -W's to versions that support them.
git-svn-id: https://svn.eduke32.com/eduke32@3278 1a8010ca-5511-0410-912e-c29ae57300e0
2012-12-13 02:37:20 +00:00
|
|
|
HINSTANCE win_gethinstance(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
Win64 support! (Meaning it works, not that we recommend it for everyday use.)
This includes a complete Windows header and library refresh, including the addition of 64-bit compiled libs:
*libogg 1.3.0
*libvorbis 1.3.3
*zlib 1.2.7
*libpng 1.5.13
*libvpx 9a3de881c0e681ba1a79a166a86308bbc84b4acd
*SDL_mixer 1.2.12 (for RENDERTYPE=SDL)
*DirectX import libraries: dsound and dxguid (now included)
To build in 64-bit, you essentially need MinGW's MSYS (but not MinGW itself) and MinGW-w64 at the top of your PATH. The target is automatically detected using `$(CC) -dumpmachine`. The EDukeWiki will get detailed instrucitons.
All compiler and linker warnings when building in 64-bit mode have been fixed.
Remaining 64-bit to-do:
- The ebacktrace dll does not build under 64-bit. It uses code specific to the format of 32-bit executables and will have to be ported to work with 64-bit executables. A future 64-bit version will be named ebacktrace1-64.dll.
- RENDERTYPE=SDL crashes in SDL_mixer's Mix_Linked_Version().
- DirectInput gives an error and does not function. This only affects joysticks, and the error never happens without any plugged in.
- Port the classic renderer ASM to 64-bit. (Just kidding, this is way out of my league.)
This commit includes a fair bit of Makefile development spanning all platforms, including simplifying the SDLCONFIG code, fixing build on Mac OS X (thanks rhoenie!), globally factoring Apple brew/port inclusion, enforcing that all -L come before all -l, and ensuring that $(shell ) is always :='d.
In addition, I have resurrected the old GCC_MAJOR and GCC_MINOR detection using `$(CC) -dumpversion`, but I have made it failsafe in case the command fails or the version is manually specified. I have applied this new fine-grained detection where applicable, including allowing LTO, and restraining -W's to versions that support them.
git-svn-id: https://svn.eduke32.com/eduke32@3278 1a8010ca-5511-0410-912e-c29ae57300e0
2012-12-13 02:37:20 +00:00
|
|
|
return hInstance;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// wm_msgbox/wm_ynbox() -- window-manager-provided message boxes
|
|
|
|
//
|
2014-07-28 06:43:16 +00:00
|
|
|
int32_t wm_msgbox(const char *name, const char *fmt, ...)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-21 20:10:51 +00:00
|
|
|
char buf[2048];
|
2006-04-24 19:04:22 +00:00
|
|
|
va_list va;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
va_start(va,fmt);
|
|
|
|
vsprintf(buf,fmt,va);
|
|
|
|
va_end(va);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
MessageBox(hWindow,buf,name,MB_OK|MB_TASKMODAL);
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2010-05-25 10:56:00 +00:00
|
|
|
|
|
|
|
|
2014-07-28 06:43:16 +00:00
|
|
|
int32_t wm_ynbox(const char *name, const char *fmt, ...)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-21 20:10:51 +00:00
|
|
|
char buf[2048];
|
2006-04-24 19:04:22 +00:00
|
|
|
va_list va;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t r;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
va_start(va,fmt);
|
|
|
|
vsprintf(buf,fmt,va);
|
|
|
|
va_end(va);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-12-10 11:36:53 +00:00
|
|
|
r = MessageBox((HWND)win_gethwnd(),buf,name,MB_YESNO|MB_ICONQUESTION|MB_TASKMODAL);
|
2006-04-24 19:04:22 +00:00
|
|
|
if (r==IDYES) return 1;
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// wm_setapptitle() -- changes the window title
|
|
|
|
//
|
2014-07-28 06:43:16 +00:00
|
|
|
void wm_setapptitle(const char *name)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
if (name)
|
2013-11-08 18:08:47 +00:00
|
|
|
Bstrncpyz(apptitle, name, sizeof(apptitle));
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (hWindow) SetWindowText(hWindow, apptitle);
|
2006-07-01 01:40:18 +00:00
|
|
|
startwin_settitle(apptitle);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2013-04-13 03:50:19 +00:00
|
|
|
static int32_t setgammaramp(LPDDGAMMARAMP gt);
|
2008-11-16 00:48:02 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
|
|
|
// SignalHandler() -- called when we've sprung a leak
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
static void SignalHandler(int32_t signum)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
switch (signum)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
case SIGSEGV:
|
2010-05-21 05:53:21 +00:00
|
|
|
OSD_Printf("Fatal Signal caught: SIGSEGV. Bailing out.\n");
|
2008-11-16 00:48:02 +00:00
|
|
|
if (gammabrightness)
|
2013-04-13 03:50:19 +00:00
|
|
|
setgammaramp(&sysgamma);
|
2008-11-16 00:48:02 +00:00
|
|
|
gammabrightness = 0;
|
2008-05-10 01:29:37 +00:00
|
|
|
app_crashhandler();
|
2006-04-24 19:04:22 +00:00
|
|
|
uninitsystem();
|
|
|
|
if (stdout) fclose(stdout);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2012-04-09 19:22:00 +00:00
|
|
|
static void divcommon(int32_t *ap, int32_t *bp)
|
|
|
|
{
|
|
|
|
const int32_t p[] = {2,3,5,7,11,13,17,19};
|
2014-03-22 09:25:15 +00:00
|
|
|
const int32_t N = (int32_t)ARRAY_SIZE(p);
|
2012-04-09 19:22:00 +00:00
|
|
|
int32_t a=*ap, b=*bp;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
for (i=0; i<N; i++)
|
|
|
|
if (a%p[i] == 0 && b%p[i]==0)
|
|
|
|
{
|
|
|
|
a /= p[i];
|
|
|
|
b /= p[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == N)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ap = a;
|
|
|
|
*bp = b;
|
|
|
|
}
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
|
|
|
// WinMain() -- main Windows entry point
|
|
|
|
//
|
2017-01-01 13:23:35 +00:00
|
|
|
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t r;
|
2013-01-08 06:17:10 +00:00
|
|
|
#ifdef USE_OPENGL
|
2006-04-24 19:04:22 +00:00
|
|
|
char *argp;
|
2013-01-08 06:17:10 +00:00
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
HDC hdc;
|
|
|
|
|
2010-01-16 20:17:33 +00:00
|
|
|
UNREFERENCED_PARAMETER(lpCmdLine);
|
|
|
|
UNREFERENCED_PARAMETER(nCmdShow);
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
hInstance = hInst;
|
|
|
|
|
2010-06-07 09:03:16 +00:00
|
|
|
#ifdef _MSC_VER
|
2011-01-16 02:45:54 +00:00
|
|
|
_CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF);
|
2010-06-07 09:03:16 +00:00
|
|
|
#endif
|
|
|
|
|
2010-01-16 20:17:33 +00:00
|
|
|
if (!CheckWinVersion() || hPrevInst)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2016-02-29 06:34:08 +00:00
|
|
|
MessageBox(0, "This application requires a newer Windows version to run.",
|
2009-10-15 23:08:47 +00:00
|
|
|
apptitle, MB_OK|MB_ICONSTOP);
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
win_open();
|
2010-10-19 05:42:21 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
hdc = GetDC(NULL);
|
|
|
|
r = GetDeviceCaps(hdc, BITSPIXEL);
|
|
|
|
ReleaseDC(NULL, hdc);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (r < 8)
|
|
|
|
{
|
2010-05-25 10:56:00 +00:00
|
|
|
MessageBox(0, "This application requires a desktop color depth of 256-colors or better.",
|
2006-04-24 19:04:22 +00:00
|
|
|
apptitle, MB_OK|MB_ICONSTOP);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-10-30 16:06:18 +00:00
|
|
|
// carve up the command line into more recognizable pieces
|
2018-10-25 23:28:56 +00:00
|
|
|
argvbuf = Xstrdup(GetCommandLine());
|
2006-04-24 19:04:22 +00:00
|
|
|
_buildargc = 0;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (argvbuf)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
char quoted = 0, instring = 0, swallownext = 0;
|
2009-01-09 09:29:17 +00:00
|
|
|
char *p,*wp; int32_t i;
|
2007-12-12 17:42:14 +00:00
|
|
|
for (p=wp=argvbuf; *p; p++)
|
|
|
|
{
|
|
|
|
if (*p == ' ')
|
|
|
|
{
|
|
|
|
if (instring && !quoted)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// end of a string
|
|
|
|
*(wp++) = 0;
|
|
|
|
instring = 0;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (instring)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
*(wp++) = *p;
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (*p == '"' && !swallownext)
|
|
|
|
{
|
|
|
|
if (instring && quoted)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// end of a string
|
2007-12-12 17:42:14 +00:00
|
|
|
if (p[1] == ' ')
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
*(wp++) = 0;
|
|
|
|
instring = 0;
|
|
|
|
quoted = 0;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
quoted = 0;
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (instring && !quoted)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
quoted = 1;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (!instring)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
instring = 1;
|
|
|
|
quoted = 1;
|
|
|
|
_buildargc++;
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (*p == '\\' && p[1] == '"' && !swallownext)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
swallownext = 1;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!instring) _buildargc++;
|
|
|
|
instring = 1;
|
|
|
|
*(wp++) = *p;
|
|
|
|
swallownext = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*wp = 0;
|
|
|
|
|
2018-10-25 23:28:56 +00:00
|
|
|
_buildargv = (const char **)Xmalloc(sizeof(char *)*(_buildargc+1));
|
2006-04-24 19:04:22 +00:00
|
|
|
wp = argvbuf;
|
2007-12-12 17:42:14 +00:00
|
|
|
for (i=0; i<_buildargc; i++,wp++)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
_buildargv[i] = wp;
|
|
|
|
while (*wp) wp++;
|
|
|
|
}
|
2013-03-18 22:05:21 +00:00
|
|
|
_buildargv[_buildargc] = NULL;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2013-01-06 18:56:29 +00:00
|
|
|
maybe_redirect_outputs();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2006-04-24 19:04:22 +00:00
|
|
|
if ((argp = Bgetenv("BUILD_NOFOG")) != NULL)
|
|
|
|
nofog = Batol(argp);
|
2008-08-26 19:50:34 +00:00
|
|
|
if (Bgetenv("BUILD_FORCEGL") != NULL)
|
|
|
|
forcegl = 1;
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
// install signal handlers
|
2008-12-28 23:27:24 +00:00
|
|
|
#if !defined(_MSC_VER) || !defined(DEBUGGINGAIDS)
|
2006-04-24 19:04:22 +00:00
|
|
|
signal(SIGSEGV, SignalHandler);
|
2008-12-28 23:27:24 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (RegisterWindowClass()) return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#ifdef DISCLAIMER
|
2006-04-24 19:04:22 +00:00
|
|
|
MessageBox(0,
|
|
|
|
DISCLAIMER,
|
|
|
|
"Notice",
|
|
|
|
MB_OK|MB_ICONINFORMATION);
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
// atexit(uninitsystem);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-07-01 01:40:18 +00:00
|
|
|
startwin_open();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
r = app_main(_buildargc, _buildargv);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
fclose(stdout);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-08-12 21:06:51 +00:00
|
|
|
if (r) Sleep(3000);
|
|
|
|
|
2006-07-01 01:40:18 +00:00
|
|
|
startwin_close();
|
2012-11-25 04:26:37 +00:00
|
|
|
|
|
|
|
win_close();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(argvbuf);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
return r;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-18 18:06:15 +00:00
|
|
|
static int32_t set_maxrefreshfreq(osdcmdptr_t parm)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t freq;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (parm->numparms == 0)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (maxrefreshfreq == 0)
|
2007-04-23 23:36:21 +00:00
|
|
|
OSD_Printf("\"maxrefreshfreq\" is \"No maximum\"\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
else
|
2007-04-23 23:36:21 +00:00
|
|
|
OSD_Printf("\"maxrefreshfreq\" is \"%d\"\n",maxrefreshfreq);
|
2006-04-24 19:04:22 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
if (parm->numparms != 1) return OSDCMD_SHOWHELP;
|
|
|
|
|
|
|
|
freq = Batol(parm->parms[0]);
|
|
|
|
if (freq < 0) return OSDCMD_SHOWHELP;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
maxrefreshfreq = (unsigned)freq;
|
|
|
|
modeschecked = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return OSDCMD_OK;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// initsystem() -- init systems
|
|
|
|
//
|
2007-03-04 19:52:57 +00:00
|
|
|
|
2012-05-05 22:21:49 +00:00
|
|
|
// http://www.gamedev.net/topic/47021-how-to-determine-video-card-with-win32-api
|
|
|
|
static void determine_ATI(void)
|
|
|
|
{
|
|
|
|
DISPLAY_DEVICE DevInfo;
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
ZeroMemory(&DevInfo, sizeof(DevInfo));
|
|
|
|
DevInfo.cb = sizeof(DISPLAY_DEVICE);
|
|
|
|
|
|
|
|
for (i=0; EnumDisplayDevices(NULL, i, &DevInfo, 0); i++)
|
|
|
|
{
|
|
|
|
if ((DevInfo.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)==0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
#ifdef UNICODE
|
|
|
|
#error Not implemented: UNICODE defined, DevInfo.DeviceString is a WCHAR
|
|
|
|
#endif
|
|
|
|
// initprintf("%s *** %s\n", DevInfo.DeviceName, DevInfo.DeviceString);
|
|
|
|
if (!Bmemcmp(DevInfo.DeviceString, "ATI ", 4) || !Bmemcmp(DevInfo.DeviceString, "AMD ", 4))
|
|
|
|
winlayer_have_ATI = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t initsystem(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
DEVMODE desktopmode;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf("Initializing Windows DirectX/GDI system interface\n");
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
mutex_init(&m_initprintf);
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
// get the desktop dimensions before anything changes them
|
|
|
|
ZeroMemory(&desktopmode, sizeof(DEVMODE));
|
|
|
|
desktopmode.dmSize = sizeof(DEVMODE);
|
|
|
|
EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&desktopmode);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
desktopxdim = desktopmode.dmPelsWidth;
|
|
|
|
desktopydim = desktopmode.dmPelsHeight;
|
|
|
|
desktopbpp = desktopmode.dmBitsPerPel;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
memset(curpalette, 0, sizeof(palette_t) * 256);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
atexit(uninitsystem);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
frameplace=0;
|
|
|
|
lockcount=0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
win_init();
|
2012-10-30 16:06:18 +00:00
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2018-02-16 06:38:21 +00:00
|
|
|
if (loadwgl(getenv("BUILD_GLDRV")))
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2009-10-07 06:47:35 +00:00
|
|
|
initprintf("Failure loading OpenGL. GL modes are unavailable.\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
nogl = 1;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2012-10-14 22:22:03 +00:00
|
|
|
// determine physical screen size
|
|
|
|
{
|
|
|
|
const int32_t oscreenx = GetSystemMetrics(SM_CXSCREEN);
|
|
|
|
const int32_t oscreeny = GetSystemMetrics(SM_CYSCREEN);
|
|
|
|
int32_t screenx=oscreenx, screeny=oscreeny, good=0;
|
|
|
|
|
|
|
|
divcommon(&screenx, &screeny);
|
|
|
|
|
|
|
|
if (screenx >= 1 && screenx <= 99 && screeny >= 1 && screeny <= 99)
|
|
|
|
r_screenxy = screenx*100 + screeny, good=1;
|
|
|
|
|
|
|
|
if (!good)
|
|
|
|
initprintf("Automatic fullscreen size determination failed! %d %d -> %d %d.\n",
|
|
|
|
oscreenx, oscreeny, screenx, screeny);
|
|
|
|
}
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
// try and start DirectDraw
|
|
|
|
if (InitDirectDraw())
|
2008-02-24 00:46:57 +00:00
|
|
|
initprintf("DirectDraw initialization failed. Fullscreen modes will be unavailable.\n");
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
OSD_RegisterFunction("maxrefreshfreq", "maxrefreshfreq: maximum display frequency to set for OpenGL Polymost modes (0=no maximum)", set_maxrefreshfreq);
|
2012-05-05 22:21:49 +00:00
|
|
|
|
|
|
|
// See if we're on an ATI card...
|
|
|
|
determine_ATI();
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// uninitsystem() -- uninit systems
|
|
|
|
//
|
|
|
|
void uninitsystem(void)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
DestroyAppWindow();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-07-01 01:40:18 +00:00
|
|
|
startwin_close();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
uninitinput();
|
2018-04-12 21:02:51 +00:00
|
|
|
timerUninit();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
win_uninit();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2018-02-16 06:38:21 +00:00
|
|
|
//POGO: there is no equivalent to unloadgldriver() with GLAD's loader, but this shouldn't be a problem.
|
|
|
|
//unloadgldriver();
|
|
|
|
unloadwgl();
|
|
|
|
#ifdef POLYMER
|
|
|
|
unloadglulibrary();
|
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-08 10:00:25 +00:00
|
|
|
//
|
|
|
|
// system_getcvars() -- propagate any cvars that are read post-initialization
|
|
|
|
//
|
|
|
|
void system_getcvars(void)
|
|
|
|
{
|
2018-04-12 21:02:51 +00:00
|
|
|
vsync = videoSetVsync(vsync);
|
2013-10-08 10:00:25 +00:00
|
|
|
}
|
|
|
|
|
2014-07-24 14:01:44 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
2014-07-24 14:01:44 +00:00
|
|
|
// initprintf() -- prints a formatted string to the intitialization window
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
|
|
|
void initprintf(const char *f, ...)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
va_list va;
|
2010-06-27 10:08:58 +00:00
|
|
|
char buf[2048];
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
va_start(va, f);
|
2010-06-27 10:08:58 +00:00
|
|
|
Bvsnprintf(buf, sizeof(buf), f, va);
|
2006-04-24 19:04:22 +00:00
|
|
|
va_end(va);
|
2009-01-06 06:59:18 +00:00
|
|
|
|
2014-07-24 14:01:44 +00:00
|
|
|
initputs(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// initputs() -- prints a string to the intitialization window
|
|
|
|
//
|
|
|
|
void initputs(const char *buf)
|
|
|
|
{
|
2014-07-28 09:00:28 +00:00
|
|
|
static char dabuf[2048];
|
|
|
|
|
2014-07-24 14:01:44 +00:00
|
|
|
OSD_Puts(buf);
|
2009-01-06 06:59:18 +00:00
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
mutex_lock(&m_initprintf);
|
2009-06-24 08:20:10 +00:00
|
|
|
if ((Bstrlen(dabuf) + Bstrlen(buf) + 2) > sizeof(dabuf))
|
|
|
|
{
|
|
|
|
startwin_puts(dabuf);
|
|
|
|
Bmemset(dabuf, 0, sizeof(dabuf));
|
|
|
|
}
|
2009-01-06 06:59:18 +00:00
|
|
|
|
|
|
|
Bstrcat(dabuf,buf);
|
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
if (g_logFlushWindow || Bstrlen(dabuf) > 768)
|
2009-01-06 06:59:18 +00:00
|
|
|
{
|
|
|
|
startwin_puts(dabuf);
|
|
|
|
handleevents();
|
|
|
|
Bmemset(dabuf, 0, sizeof(dabuf));
|
|
|
|
}
|
2010-06-22 21:50:01 +00:00
|
|
|
mutex_unlock(&m_initprintf);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2014-07-24 14:01:44 +00:00
|
|
|
// debugprintf() -- sends a formatted debug string to the debugger
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
|
|
|
void debugprintf(const char *f, ...)
|
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
#if 0 // def DEBUGGINGAIDS
|
2006-04-24 19:04:22 +00:00
|
|
|
va_list va;
|
|
|
|
char buf[1024];
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!IsDebuggerPresent()) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
va_start(va,f);
|
|
|
|
Bvsnprintf(buf, 1024, f, va);
|
|
|
|
va_end(va);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
OutputDebugString(buf);
|
2008-03-23 00:41:08 +00:00
|
|
|
#else
|
|
|
|
UNREFERENCED_PARAMETER(f);
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-15 15:28:30 +00:00
|
|
|
int32_t handleevents_peekkeys(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
|
|
|
// handleevents() -- process the Windows message queue
|
|
|
|
// returns !0 if there was an important event worth checking (like quitting)
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t handleevents(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t rv=0;
|
2006-04-24 19:04:22 +00:00
|
|
|
MSG msg;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//if (frameplace && fullscreen) printf("Offscreen buffer is locked!\n");
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-16 22:53:08 +00:00
|
|
|
RI_PollDevices(TRUE);
|
2010-05-07 20:45:40 +00:00
|
|
|
|
2010-05-19 10:02:35 +00:00
|
|
|
if (hDInputDLL)
|
2010-05-07 20:45:40 +00:00
|
|
|
DI_PollJoysticks();
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
switch (msg.message)
|
2010-05-16 22:53:08 +00:00
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
case WM_QUIT:
|
|
|
|
quitevent = 1;
|
|
|
|
continue;
|
|
|
|
case WM_INPUT:
|
|
|
|
// this call to RI_PollDevices() probably isn't necessary
|
|
|
|
// RI_PollDevices(FALSE);
|
2010-05-16 22:53:08 +00:00
|
|
|
RI_ProcessMessage(&msg);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
if (startwin_idle((void *)&msg) > 0) continue;
|
2010-05-18 00:30:30 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
TranslateMessage(&msg);
|
2012-05-17 17:19:52 +00:00
|
|
|
// DispatchMessage(&msg);
|
2012-05-20 05:36:32 +00:00
|
|
|
WndProcCallback(msg.hwnd, msg.message, msg.wParam, msg.lParam);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 07:24:09 +00:00
|
|
|
inputchecked = 0;
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!appactive || quitevent) rv = -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
timerUpdate();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return rv;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// initinput() -- init input system
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t initinput(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2016-12-26 06:02:45 +00:00
|
|
|
Win_GetOriginalLayoutName();
|
|
|
|
Win_SetKeyboardLayoutUS(1);
|
2010-05-18 00:30:30 +00:00
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
g_mouseEnabled=0;
|
2006-04-24 19:04:22 +00:00
|
|
|
memset(keystatus, 0, sizeof(keystatus));
|
2010-05-18 00:30:30 +00:00
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
g_keyFIFOend = g_keyAsciiPos = g_keyAsciiEnd = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
inputdevices = 1|2;
|
2018-04-12 21:02:31 +00:00
|
|
|
joystick.numAxes = joystick.numButtons = joystick.numHats=0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
GetKeyNames();
|
|
|
|
InitDirectInput();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// uninitinput() -- uninit input system
|
|
|
|
//
|
|
|
|
void uninitinput(void)
|
|
|
|
{
|
2016-12-26 06:02:45 +00:00
|
|
|
Win_SetKeyboardLayoutUS(0);
|
2013-08-10 23:09:14 +00:00
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
mouseUninit();
|
2006-04-24 19:04:22 +00:00
|
|
|
UninitDirectInput();
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-05 02:49:08 +00:00
|
|
|
void idle_waitevent_timeout(uint32_t timeout)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2010-05-19 10:02:35 +00:00
|
|
|
// timeout becomes a completion deadline
|
2018-04-12 21:02:51 +00:00
|
|
|
timeout += timerGetTicks();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
MSG msg;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if (PeekMessage(&msg, 0, WM_INPUT, WM_INPUT, PM_QS_INPUT))
|
|
|
|
{
|
2010-05-16 22:53:08 +00:00
|
|
|
RI_PollDevices(TRUE);
|
2013-12-20 07:24:09 +00:00
|
|
|
|
|
|
|
inputchecked = 0;
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-05-16 22:53:08 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
Sleep(10);
|
|
|
|
}
|
2018-04-12 21:02:51 +00:00
|
|
|
while (timeout > (timerGetTicks() + 10));
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// setjoydeadzone() -- sets the dead and saturation zones for the joystick
|
|
|
|
//
|
2018-04-12 21:02:31 +00:00
|
|
|
void joySetDeadZone(int32_t axis, uint16_t dead, uint16_t satur)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
DIPROPDWORD dipdw;
|
|
|
|
HRESULT result;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if (!lpDID) return;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
if (dead > 10000) dead = 10000;
|
|
|
|
if (satur > 10000) satur = 10000;
|
|
|
|
if (dead >= satur) dead = satur-100;
|
2018-04-12 21:02:31 +00:00
|
|
|
if (axis >= joystick.numAxes) return;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
memset(&dipdw, 0, sizeof(dipdw));
|
|
|
|
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
|
|
|
|
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (axis < 0)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
dipdw.diph.dwObj = 0;
|
|
|
|
dipdw.diph.dwHow = DIPH_DEVICE;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
dipdw.diph.dwObj = axisdefs[axis].ofs;
|
|
|
|
dipdw.diph.dwHow = DIPH_BYOFFSET;
|
|
|
|
}
|
|
|
|
dipdw.dwData = dead;
|
|
|
|
|
2012-11-05 02:49:08 +00:00
|
|
|
result = IDirectInputDevice7_SetProperty(lpDID, bDIPROP_DEADZONE, &dipdw.diph);
|
2010-05-18 00:30:30 +00:00
|
|
|
if (FAILED(result))
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
//ShowDInputErrorBox("Failed setting joystick dead zone", result);
|
|
|
|
initprintf("Failed setting joystick dead zone: %s\n", GetDInputError(result));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dipdw.dwData = satur;
|
|
|
|
|
2012-11-05 02:49:08 +00:00
|
|
|
result = IDirectInputDevice7_SetProperty(lpDID, bDIPROP_SATURATION, &dipdw.diph);
|
2010-05-18 00:30:30 +00:00
|
|
|
if (FAILED(result))
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
//ShowDInputErrorBox("Failed setting joystick saturation point", result);
|
|
|
|
initprintf("Failed setting joystick saturation point: %s\n", GetDInputError(result));
|
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// getjoydeadzone() -- gets the dead and saturation zones for the joystick
|
|
|
|
//
|
2018-04-12 21:02:31 +00:00
|
|
|
void joyGetDeadZone(int32_t axis, uint16_t *dead, uint16_t *satur)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
DIPROPDWORD dipdw;
|
|
|
|
HRESULT result;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!dead || !satur) return;
|
2010-05-18 00:30:30 +00:00
|
|
|
if (!lpDID) { *dead = *satur = 0; return; }
|
2018-04-12 21:02:31 +00:00
|
|
|
if (axis >= joystick.numAxes) { *dead = *satur = 0; return; }
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
memset(&dipdw, 0, sizeof(dipdw));
|
|
|
|
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
|
|
|
|
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (axis < 0)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
dipdw.diph.dwObj = 0;
|
|
|
|
dipdw.diph.dwHow = DIPH_DEVICE;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
dipdw.diph.dwObj = axisdefs[axis].ofs;
|
|
|
|
dipdw.diph.dwHow = DIPH_BYOFFSET;
|
|
|
|
}
|
|
|
|
|
2012-11-15 14:27:57 +00:00
|
|
|
result = IDirectInputDevice7_GetProperty(lpDID, bDIPROP_DEADZONE, (LPDIPROPHEADER)&dipdw.diph);
|
2010-05-18 00:30:30 +00:00
|
|
|
if (FAILED(result))
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
//ShowDInputErrorBox("Failed getting joystick dead zone", result);
|
|
|
|
initprintf("Failed getting joystick dead zone: %s\n", GetDInputError(result));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dead = dipdw.dwData;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-11-05 02:49:08 +00:00
|
|
|
result = IDirectInputDevice7_GetProperty(lpDID, bDIPROP_SATURATION, &dipdw.diph);
|
2010-05-18 00:30:30 +00:00
|
|
|
if (FAILED(result))
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
//ShowDInputErrorBox("Failed getting joystick saturation point", result);
|
|
|
|
initprintf("Failed getting joystick saturation point: %s\n", GetDInputError(result));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*satur = dipdw.dwData;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
#if 0
|
2006-04-13 20:47:06 +00:00
|
|
|
void releaseallbuttons(void)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
if (g_mouseCallback)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2018-04-12 21:02:31 +00:00
|
|
|
if (g_mouseBits & 1) g_mouseCallback(1, 0);
|
|
|
|
if (g_mouseBits & 2) g_mouseCallback(2, 0);
|
|
|
|
if (g_mouseBits & 4) g_mouseCallback(3, 0);
|
|
|
|
if (g_mouseBits & 8) g_mouseCallback(4, 0);
|
|
|
|
if (g_mouseBits & 16) g_mouseCallback(5, 0);
|
|
|
|
if (g_mouseBits & 32) g_mouseCallback(6, 0);
|
|
|
|
if (g_mouseBits & 64) g_mouseCallback(7, 0);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2018-04-12 21:02:31 +00:00
|
|
|
g_mouseBits = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
if (joystick.pCallback)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<32; i++)
|
2018-04-12 21:02:31 +00:00
|
|
|
if (joystick.bits & (1<<i)) joystick.pCallback(i+1, 0);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2018-06-13 19:15:22 +00:00
|
|
|
joystick.bits = 0;
|
|
|
|
//joyblast = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
for (i=0; i<NUMKEYS; i++)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
//if (!keystatus[i]) continue;
|
|
|
|
//if (OSD_HandleKey(i, 0) != 0) {
|
2008-07-02 01:32:53 +00:00
|
|
|
OSD_HandleScanCode(i, 0);
|
2018-04-12 21:02:31 +00:00
|
|
|
keySetState(i, 0);
|
2008-10-24 09:20:38 +00:00
|
|
|
if (keypresscallback) keypresscallback(i, 0);
|
2006-04-24 19:04:22 +00:00
|
|
|
//}
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2018-04-12 21:02:31 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// InitDirectInput() -- get DirectInput started
|
|
|
|
//
|
|
|
|
|
|
|
|
// device enumerator
|
|
|
|
static BOOL CALLBACK InitDirectInput_enum(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
const char *d;
|
2008-03-23 00:14:22 +00:00
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(pvRef);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if ((lpddi->dwDevType&0xff) != DIDEVTYPE_JOYSTICK)
|
2010-02-23 18:13:46 +00:00
|
|
|
return DIENUM_CONTINUE;
|
2010-05-18 00:30:30 +00:00
|
|
|
|
|
|
|
inputdevices |= 4;
|
2018-06-13 19:15:22 +00:00
|
|
|
d = "CONTROLLER";
|
2010-05-18 00:30:30 +00:00
|
|
|
Bmemcpy(&guidDevs, &lpddi->guidInstance, sizeof(GUID));
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
initprintf(" * %s: %s\n", d, lpddi->tszProductName);
|
|
|
|
|
|
|
|
return DIENUM_CONTINUE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL CALLBACK InitDirectInput_enumobjects(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef)
|
|
|
|
{
|
2011-01-16 02:50:27 +00:00
|
|
|
int32_t *typecounts = (int32_t *)pvRef;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (lpddoi->dwType & DIDFT_AXIS)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
//initprintf(" Axis: %s (dwOfs=%d)\n", lpddoi->tszName, lpddoi->dwOfs);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-10-25 23:28:56 +00:00
|
|
|
axisdefs[ typecounts[0] ].name = Xstrdup(lpddoi->tszName);
|
2006-04-24 19:04:22 +00:00
|
|
|
axisdefs[ typecounts[0] ].ofs = lpddoi->dwOfs;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
typecounts[0]++;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (lpddoi->dwType & DIDFT_BUTTON)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
//initprintf(" Button: %s (dwOfs=%d)\n", lpddoi->tszName, lpddoi->dwOfs);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-10-25 23:28:56 +00:00
|
|
|
buttondefs[ typecounts[1] ].name = Xstrdup(lpddoi->tszName);
|
2006-04-24 19:04:22 +00:00
|
|
|
buttondefs[ typecounts[1] ].ofs = lpddoi->dwOfs;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
typecounts[1]++;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (lpddoi->dwType & DIDFT_POV)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
//initprintf(" POV: %s (dwOfs=%d)\n", lpddoi->tszName, lpddoi->dwOfs);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-10-25 23:28:56 +00:00
|
|
|
hatdefs[ typecounts[2] ].name = Xstrdup(lpddoi->tszName);
|
2006-04-24 19:04:22 +00:00
|
|
|
hatdefs[ typecounts[2] ].ofs = lpddoi->dwOfs;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
typecounts[2]++;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return DIENUM_CONTINUE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define HorribleDInputDeath( x, y ) \
|
2010-05-02 23:27:30 +00:00
|
|
|
ShowDInputErrorBox(x,y); \
|
|
|
|
UninitDirectInput(); \
|
|
|
|
return TRUE
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
static BOOL InitDirectInput(void)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
HRESULT result;
|
2008-10-05 09:23:55 +00:00
|
|
|
HRESULT(WINAPI *aDirectInputCreateA)(HINSTANCE, DWORD, LPDIRECTINPUT7A *, LPUNKNOWN);
|
2006-04-24 19:04:22 +00:00
|
|
|
DIPROPDWORD dipdw;
|
2008-10-05 09:23:55 +00:00
|
|
|
LPDIRECTINPUTDEVICE7A dev;
|
|
|
|
LPDIRECTINPUTDEVICE7A dev2;
|
2006-04-24 19:04:22 +00:00
|
|
|
DIDEVCAPS didc;
|
|
|
|
|
2010-11-23 22:30:27 +00:00
|
|
|
if (hDInputDLL || di_disabled) return FALSE;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2008-02-24 00:46:57 +00:00
|
|
|
initprintf("Initializing DirectInput...\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hDInputDLL)
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" - Loading DINPUT.DLL\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
hDInputDLL = LoadLibrary("DINPUT.DLL");
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hDInputDLL)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowErrorBox("Error loading DINPUT.DLL");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-15 14:27:57 +00:00
|
|
|
aDirectInputCreateA = (HRESULT(WINAPI *)(HINSTANCE, DWORD, LPDIRECTINPUT7A *, LPUNKNOWN))GetProcAddress(hDInputDLL, "DirectInputCreateA");
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!aDirectInputCreateA) ShowErrorBox("Error fetching DirectInputCreateA()");
|
|
|
|
|
|
|
|
result = aDirectInputCreateA(hInstance, DIRECTINPUT_VERSION, &lpDI, NULL);
|
2010-05-18 00:30:30 +00:00
|
|
|
if (FAILED(result)) { HorribleDInputDeath("DirectInputCreateA() failed", result); }
|
2006-04-24 19:04:22 +00:00
|
|
|
else if (result != DI_OK) initprintf(" Created DirectInput object with warning: %s\n",GetDInputError(result));
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
initprintf(" - Enumerating attached game controllers\n");
|
|
|
|
inputdevices = 1|2;
|
2010-11-23 22:30:27 +00:00
|
|
|
result = IDirectInput7_EnumDevices(lpDI, DIDEVTYPE_JOYSTICK, InitDirectInput_enum, NULL, DIEDFL_ATTACHEDONLY);
|
2010-05-18 00:30:30 +00:00
|
|
|
if (FAILED(result)) { HorribleDInputDeath("Failed enumerating attached game controllers", result); }
|
2010-05-02 23:27:30 +00:00
|
|
|
else if (result != DI_OK) initprintf(" Enumerated game controllers with warning: %s\n",GetDInputError(result));
|
|
|
|
|
|
|
|
if (inputdevices == (1|2))
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
initprintf(" - No game controllers found\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
UninitDirectInput();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
*devicedef.did = NULL;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" - Creating %s device\n", devicedef.name);
|
2012-11-15 14:27:57 +00:00
|
|
|
result = IDirectInput7_CreateDeviceEx(lpDI, bREFGUID guidDevs, bREFIID IID_IDirectInputDevice7, (LPVOID *)&dev, NULL);
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if (FAILED(result)) { HorribleDInputDeath("Failed creating device", result); }
|
|
|
|
else if (result != DI_OK) initprintf(" Created device with warning: %s\n",GetDInputError(result));
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2012-11-15 14:27:57 +00:00
|
|
|
result = IDirectInputDevice7_QueryInterface(dev, bREFIID IID_IDirectInputDevice7, (LPVOID *)&dev2);
|
2010-05-18 00:30:30 +00:00
|
|
|
IDirectInputDevice7_Release(dev);
|
|
|
|
if (FAILED(result)) { HorribleDInputDeath("Failed querying DirectInput7 interface for device", result); }
|
|
|
|
else if (result != DI_OK) initprintf(" Queried IDirectInputDevice7 interface with warning: %s\n",GetDInputError(result));
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
result = IDirectInputDevice7_SetDataFormat(dev2, devicedef.df);
|
|
|
|
if (FAILED(result)) { IDirectInputDevice7_Release(dev2); HorribleDInputDeath("Failed setting data format", result); }
|
|
|
|
else if (result != DI_OK) initprintf(" Set data format with warning: %s\n",GetDInputError(result));
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
di_inputevt = CreateEvent(NULL, FALSE, FALSE, NULL);
|
2010-11-23 22:30:27 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if (di_inputevt == NULL)
|
|
|
|
{
|
|
|
|
IDirectInputDevice7_Release(dev2);
|
|
|
|
ShowErrorBox("Couldn't create event object");
|
|
|
|
UninitDirectInput();
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
result = IDirectInputDevice7_SetEventNotification(dev2, di_inputevt);
|
|
|
|
if (FAILED(result)) { IDirectInputDevice7_Release(dev2); HorribleDInputDeath("Failed setting event object", result); }
|
|
|
|
else if (result != DI_OK) initprintf(" Set event object with warning: %s\n",GetDInputError(result));
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
IDirectInputDevice7_Unacquire(dev2);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
memset(&dipdw, 0, sizeof(dipdw));
|
|
|
|
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
|
|
|
|
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
|
|
dipdw.diph.dwObj = 0;
|
|
|
|
dipdw.diph.dwHow = DIPH_DEVICE;
|
|
|
|
dipdw.dwData = INPUT_BUFFER_SIZE;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2012-11-05 02:49:08 +00:00
|
|
|
result = IDirectInputDevice7_SetProperty(dev2, bDIPROP_BUFFERSIZE, &dipdw.diph);
|
2010-05-18 00:30:30 +00:00
|
|
|
if (FAILED(result)) { IDirectInputDevice7_Release(dev2); HorribleDInputDeath("Failed setting buffering", result); }
|
|
|
|
else if (result != DI_OK) initprintf(" Set buffering with warning: %s\n",GetDInputError(result));
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
// set up device
|
|
|
|
{
|
|
|
|
int32_t typecounts[3] = {0,0,0};
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
memset(&didc, 0, sizeof(didc));
|
|
|
|
didc.dwSize = sizeof(didc);
|
|
|
|
result = IDirectInputDevice7_GetCapabilities(dev2, &didc);
|
|
|
|
if (FAILED(result)) { IDirectInputDevice7_Release(dev2); HorribleDInputDeath("Failed getting controller capabilities", result); }
|
|
|
|
else if (result != DI_OK) initprintf(" Fetched controller capabilities with warning: %s\n",GetDInputError(result));
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
joystick.numAxes = (uint8_t)didc.dwAxes;
|
2019-03-04 23:48:50 +00:00
|
|
|
joystick.numButtons = min<uint8_t>(32,didc.dwButtons);
|
2018-04-12 21:02:31 +00:00
|
|
|
joystick.numHats = (uint8_t)didc.dwPOVs;
|
|
|
|
initprintf("Controller has %d axes, %d buttons, and %d hat(s).\n",joystick.numAxes,joystick.numButtons,joystick.numHats);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-10-25 23:28:56 +00:00
|
|
|
axisdefs = (struct _joydef *)Xcalloc(didc.dwAxes, sizeof(struct _joydef));
|
|
|
|
buttondefs = (struct _joydef *)Xcalloc(didc.dwButtons, sizeof(struct _joydef));
|
2012-02-09 22:43:21 +00:00
|
|
|
if (didc.dwPOVs)
|
2018-10-25 23:28:56 +00:00
|
|
|
hatdefs = (struct _joydef *)Xcalloc(didc.dwPOVs, sizeof(struct _joydef));
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-10-25 23:28:56 +00:00
|
|
|
joystick.pAxis = (int32_t *)Xcalloc(didc.dwAxes, sizeof(int32_t));
|
2012-02-09 22:43:21 +00:00
|
|
|
if (didc.dwPOVs)
|
2018-10-25 23:28:56 +00:00
|
|
|
joystick.pHat = (int32_t *)Xcalloc(didc.dwPOVs, sizeof(int32_t));
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
result = IDirectInputDevice7_EnumObjects(dev2, InitDirectInput_enumobjects, (LPVOID)typecounts, DIDFT_ALL);
|
|
|
|
if (FAILED(result)) { IDirectInputDevice7_Release(dev2); HorribleDInputDeath("Failed getting controller features", result); }
|
|
|
|
else if (result != DI_OK) initprintf(" Fetched controller features with warning: %s\n",GetDInputError(result));
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
*devicedef.did = dev2;
|
|
|
|
|
|
|
|
di_devacquired = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// UninitDirectInput() -- clean up DirectInput
|
|
|
|
//
|
|
|
|
static void UninitDirectInput(void)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-19 10:02:35 +00:00
|
|
|
if (hDInputDLL) initprintf("Uninitializing DirectInput...\n");
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
AcquireInputDevices(0);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (axisdefs)
|
|
|
|
{
|
2019-06-25 11:29:08 +00:00
|
|
|
for (i=joystick.numAxes-1; i>=0; i--) Xfree(axisdefs[i].name);
|
2015-09-23 17:55:31 +00:00
|
|
|
DO_FREE_AND_NULL(axisdefs);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
if (buttondefs)
|
|
|
|
{
|
2019-06-25 11:29:08 +00:00
|
|
|
for (i=joystick.numButtons-1; i>=0; i--) Xfree(buttondefs[i].name);
|
2015-09-23 17:55:31 +00:00
|
|
|
DO_FREE_AND_NULL(buttondefs);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hatdefs)
|
|
|
|
{
|
2019-06-25 11:29:08 +00:00
|
|
|
for (i=joystick.numHats-1; i>=0; i--) Xfree(hatdefs[i].name);
|
2015-09-23 17:55:31 +00:00
|
|
|
DO_FREE_AND_NULL(hatdefs);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if (di_inputevt)
|
|
|
|
{
|
|
|
|
CloseHandle(di_inputevt);
|
|
|
|
di_inputevt = NULL;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-11-23 22:30:27 +00:00
|
|
|
if (*devicedef.did)
|
|
|
|
{
|
|
|
|
IDirectInputDevice7_Release(*devicedef.did);
|
|
|
|
*devicedef.did = NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (lpDI)
|
|
|
|
{
|
2008-10-05 09:23:55 +00:00
|
|
|
IDirectInput7_Release(lpDI);
|
2006-04-24 19:04:22 +00:00
|
|
|
lpDI = NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hDInputDLL)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
FreeLibrary(hDInputDLL);
|
|
|
|
hDInputDLL = NULL;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// GetKeyNames() -- retrieves the names for all the keys on the keyboard
|
|
|
|
//
|
|
|
|
static void GetKeyNames(void)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2011-07-30 20:36:04 +00:00
|
|
|
char tbuf[MAX_PATH], *cp;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
memset(g_keyNameTable,0,sizeof(g_keyNameTable));
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<256; i++)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2008-08-23 18:59:49 +00:00
|
|
|
tbuf[0] = 0;
|
2018-04-12 21:02:31 +00:00
|
|
|
GetKeyNameText((i>128?(i+128):i)<<16, tbuf, sizeof(g_keyNameTable[i])-1);
|
|
|
|
Bstrncpy(&g_keyNameTable[i][0], tbuf, sizeof(g_keyNameTable[i])-1);
|
|
|
|
for (cp=g_keyNameTable[i]; *cp; cp++)
|
2011-07-30 20:36:04 +00:00
|
|
|
if (!(*cp>=32 && *cp<127))
|
|
|
|
*cp = '?';
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
const char *joyGetName(int32_t what, int32_t num)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
switch (what)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
case 0: // axis
|
2018-04-12 21:02:31 +00:00
|
|
|
return ((unsigned)num > (unsigned)joystick.numAxes) ? NULL : (char *)axisdefs[num].name;
|
2006-04-24 19:04:22 +00:00
|
|
|
case 1: // button
|
2018-04-12 21:02:31 +00:00
|
|
|
return ((unsigned)num > (unsigned)joystick.numButtons) ? NULL : (char *)buttondefs[num].name;
|
2006-04-24 19:04:22 +00:00
|
|
|
case 2: // hat
|
2018-04-12 21:02:31 +00:00
|
|
|
return ((unsigned)num > (unsigned)joystick.numHats) ? NULL : (char *)hatdefs[num].name;
|
2006-04-24 19:04:22 +00:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// AcquireInputDevices() -- (un)acquires the input devices
|
|
|
|
//
|
2010-05-18 00:30:30 +00:00
|
|
|
static void AcquireInputDevices(char acquire)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
DWORD flags;
|
|
|
|
HRESULT result;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-19 10:02:35 +00:00
|
|
|
if (!hDInputDLL) return;
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!hWindow) return;
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (acquire)
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
// if (!appactive) return; // why acquire when inactive?
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if (! *devicedef.did) return;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
IDirectInputDevice7_Unacquire(*devicedef.did);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
flags = DISCL_FOREGROUND|DISCL_NONEXCLUSIVE;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
result = IDirectInputDevice7_SetCooperativeLevel(*devicedef.did, hWindow, flags);
|
|
|
|
if (FAILED(result))
|
|
|
|
initprintf("IDirectInputDevice7_SetCooperativeLevel(%s): %s\n",
|
|
|
|
devicedef.name, GetDInputError(result));
|
|
|
|
|
|
|
|
if (SUCCEEDED(IDirectInputDevice7_Acquire(*devicedef.did)))
|
|
|
|
di_devacquired = 1;
|
|
|
|
else
|
|
|
|
di_devacquired = 0;
|
|
|
|
|
|
|
|
return;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
di_devacquired = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
// releaseallbuttons();
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if (! *devicedef.did) return;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
IDirectInputDevice7_Unacquire(*devicedef.did);
|
|
|
|
|
|
|
|
result = IDirectInputDevice7_SetCooperativeLevel(*devicedef.did, hWindow, DISCL_FOREGROUND|DISCL_NONEXCLUSIVE);
|
|
|
|
if (FAILED(result))
|
|
|
|
initprintf("IDirectInputDevice7_SetCooperativeLevel(%s): %s\n",
|
|
|
|
devicedef.name, GetDInputError(result));
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// ProcessInputDevices() -- processes the input devices
|
|
|
|
//
|
2010-05-07 20:45:40 +00:00
|
|
|
static inline void DI_PollJoysticks(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2010-05-09 22:12:29 +00:00
|
|
|
DWORD dwElements = INPUT_BUFFER_SIZE;
|
2006-04-24 19:04:22 +00:00
|
|
|
HRESULT result;
|
|
|
|
DIDEVICEOBJECTDATA didod[INPUT_BUFFER_SIZE];
|
2010-05-09 22:12:29 +00:00
|
|
|
int32_t i, ev;
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if (*devicedef.did)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
result = IDirectInputDevice7_Poll(*devicedef.did);
|
2010-05-07 20:45:40 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED)
|
|
|
|
{
|
|
|
|
if (SUCCEEDED(IDirectInputDevice7_Acquire(*devicedef.did)))
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
di_devacquired = 1;
|
|
|
|
IDirectInputDevice7_Poll(*devicedef.did);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2010-05-18 00:30:30 +00:00
|
|
|
else di_devacquired = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2010-05-07 20:45:40 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if (di_devacquired)
|
|
|
|
{
|
|
|
|
// use event objects so that we can quickly get indication of when data is ready
|
|
|
|
// to be read and input events processed
|
|
|
|
ev = WaitForSingleObject(di_inputevt, 0);
|
2010-05-07 20:45:40 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if (ev != WAIT_OBJECT_0 || !lpDID)
|
|
|
|
return;
|
2010-05-07 20:45:40 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
result = IDirectInputDevice7_GetDeviceData(lpDID, sizeof(DIDEVICEOBJECTDATA),
|
|
|
|
(LPDIDEVICEOBJECTDATA)&didod, &dwElements, 0);
|
2010-05-07 20:45:40 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if (result != DI_OK || !dwElements) return;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
for (i=dwElements-1; i>=0; i--)
|
2010-05-07 20:45:40 +00:00
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
int32_t j;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
// check axes
|
2018-04-12 21:02:31 +00:00
|
|
|
for (j=0; j<joystick.numAxes; j++)
|
2010-05-18 00:30:30 +00:00
|
|
|
{
|
|
|
|
if (axisdefs[j].ofs != didod[i].dwOfs) continue;
|
2018-04-12 21:02:31 +00:00
|
|
|
joystick.pAxis[j] = didod[i].dwData - 32767;
|
2010-05-18 00:30:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-04-12 21:02:31 +00:00
|
|
|
if (j<joystick.numAxes) continue;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
// check buttons
|
2018-04-12 21:02:31 +00:00
|
|
|
for (j=0; j<joystick.numButtons; j++)
|
2010-05-18 00:30:30 +00:00
|
|
|
{
|
|
|
|
if (buttondefs[j].ofs != didod[i].dwOfs) continue;
|
2018-04-12 21:02:31 +00:00
|
|
|
if (didod[i].dwData & 0x80) joystick.bits |= (1<<j);
|
|
|
|
else joystick.bits &= ~(1<<j);
|
|
|
|
if (joystick.pCallback)
|
|
|
|
joystick.pCallback(j+1, (didod[i].dwData & 0x80)==0x80);
|
2010-05-18 00:30:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-04-12 21:02:31 +00:00
|
|
|
if (j<joystick.numButtons) continue;
|
2010-05-18 00:30:30 +00:00
|
|
|
|
|
|
|
// check hats
|
2018-04-12 21:02:31 +00:00
|
|
|
for (j=0; j<joystick.numHats; j++)
|
2010-05-18 00:30:30 +00:00
|
|
|
{
|
|
|
|
if (hatdefs[j].ofs != didod[i].dwOfs) continue;
|
2018-04-12 21:02:31 +00:00
|
|
|
joystick.pHat[j] = didod[i].dwData;
|
2010-05-18 00:30:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// ShowDInputErrorBox() -- shows an error message box for a DirectInput error
|
|
|
|
//
|
|
|
|
static void ShowDInputErrorBox(const char *m, HRESULT r)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
TCHAR msg[1024];
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
wsprintf(msg, "%s: %s", m, GetDInputError(r));
|
|
|
|
MessageBox(0, msg, apptitle, MB_OK|MB_ICONSTOP);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// GetDInputError() -- stinking huge list of error messages since MS didn't want to include
|
|
|
|
// them in the DLL
|
|
|
|
//
|
2011-01-16 02:50:27 +00:00
|
|
|
static const char *GetDInputError(HRESULT code)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
switch (code)
|
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
case DI_OK:
|
|
|
|
return "DI_OK";
|
|
|
|
case DI_BUFFEROVERFLOW:
|
|
|
|
return "DI_BUFFEROVERFLOW";
|
|
|
|
case DI_DOWNLOADSKIPPED:
|
|
|
|
return "DI_DOWNLOADSKIPPED";
|
|
|
|
case DI_EFFECTRESTARTED:
|
|
|
|
return "DI_EFFECTRESTARTED";
|
|
|
|
case DI_POLLEDDEVICE:
|
|
|
|
return "DI_POLLEDDEVICE";
|
|
|
|
case DI_TRUNCATED:
|
|
|
|
return "DI_TRUNCATED";
|
|
|
|
case DI_TRUNCATEDANDRESTARTED:
|
|
|
|
return "DI_TRUNCATEDANDRESTARTED";
|
|
|
|
case DIERR_ACQUIRED:
|
|
|
|
return "DIERR_ACQUIRED";
|
|
|
|
case DIERR_ALREADYINITIALIZED:
|
|
|
|
return "DIERR_ALREADYINITIALIZED";
|
|
|
|
case DIERR_BADDRIVERVER:
|
|
|
|
return "DIERR_BADDRIVERVER";
|
|
|
|
case DIERR_BETADIRECTINPUTVERSION:
|
|
|
|
return "DIERR_BETADIRECTINPUTVERSION";
|
|
|
|
case DIERR_DEVICEFULL:
|
|
|
|
return "DIERR_DEVICEFULL";
|
|
|
|
case DIERR_DEVICENOTREG:
|
|
|
|
return "DIERR_DEVICENOTREG";
|
|
|
|
case DIERR_EFFECTPLAYING:
|
|
|
|
return "DIERR_EFFECTPLAYING";
|
|
|
|
case DIERR_HASEFFECTS:
|
|
|
|
return "DIERR_HASEFFECTS";
|
|
|
|
case DIERR_GENERIC:
|
|
|
|
return "DIERR_GENERIC";
|
|
|
|
case DIERR_HANDLEEXISTS:
|
|
|
|
return "DIERR_HANDLEEXISTS";
|
|
|
|
case DIERR_INCOMPLETEEFFECT:
|
|
|
|
return "DIERR_INCOMPLETEEFFECT";
|
|
|
|
case DIERR_INPUTLOST:
|
|
|
|
return "DIERR_INPUTLOST";
|
|
|
|
case DIERR_INVALIDPARAM:
|
|
|
|
return "DIERR_INVALIDPARAM";
|
|
|
|
case DIERR_MOREDATA:
|
|
|
|
return "DIERR_MOREDATA";
|
|
|
|
case DIERR_NOAGGREGATION:
|
|
|
|
return "DIERR_NOAGGREGATION";
|
|
|
|
case DIERR_NOINTERFACE:
|
|
|
|
return "DIERR_NOINTERFACE";
|
|
|
|
case DIERR_NOTACQUIRED:
|
|
|
|
return "DIERR_NOTACQUIRED";
|
|
|
|
case DIERR_NOTBUFFERED:
|
|
|
|
return "DIERR_NOTBUFFERED";
|
|
|
|
case DIERR_NOTDOWNLOADED:
|
|
|
|
return "DIERR_NOTDOWNLOADED";
|
|
|
|
case DIERR_NOTEXCLUSIVEACQUIRED:
|
|
|
|
return "DIERR_NOTEXCLUSIVEACQUIRED";
|
|
|
|
case DIERR_NOTFOUND:
|
|
|
|
return "DIERR_NOTFOUND";
|
|
|
|
case DIERR_NOTINITIALIZED:
|
|
|
|
return "DIERR_NOTINITIALIZED";
|
|
|
|
case DIERR_OLDDIRECTINPUTVERSION:
|
|
|
|
return "DIERR_OLDDIRECTINPUTVERSION";
|
|
|
|
case DIERR_OUTOFMEMORY:
|
|
|
|
return "DIERR_OUTOFMEMORY";
|
|
|
|
case DIERR_UNSUPPORTED:
|
|
|
|
return "DIERR_UNSUPPORTED";
|
|
|
|
case E_PENDING:
|
|
|
|
return "E_PENDING";
|
|
|
|
default:
|
|
|
|
break;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
return "Unknown error";
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
// TIMER
|
|
|
|
//=================================================================================================
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t timerlastsample=0;
|
|
|
|
int32_t timerticspersec=0;
|
2013-07-07 20:59:00 +00:00
|
|
|
static double msperu64tick = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
static void (*usertimercallback)(void) = NULL;
|
|
|
|
|
|
|
|
// This timer stuff is all Ken's idea.
|
|
|
|
|
|
|
|
//
|
|
|
|
// installusertimercallback() -- set up a callback function to be called when the timer is fired
|
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
void (*timerSetCallback(void (*callback)(void)))(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
void (*oldtimercallback)(void);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
oldtimercallback = usertimercallback;
|
|
|
|
usertimercallback = callback;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return oldtimercallback;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2008-02-24 00:46:57 +00:00
|
|
|
// inittimer() -- initialize timer
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
int32_t timerInit(int32_t tickspersecond)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-09-09 07:19:14 +00:00
|
|
|
int64_t t;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
if (win_timerfreq) return 0; // already installed
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf("Initializing timer\n");
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
t = win_inittimer();
|
|
|
|
if (t < 0)
|
|
|
|
return t;
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
timerticspersec = tickspersecond;
|
2011-01-16 02:50:27 +00:00
|
|
|
QueryPerformanceCounter((LARGE_INTEGER *)&t);
|
2012-11-25 04:26:37 +00:00
|
|
|
timerlastsample = (int32_t)(t*timerticspersec / win_timerfreq);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
usertimercallback = NULL;
|
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
msperu64tick = 1000.0 / (double)timerGetFreqU64();
|
2012-07-25 18:56:15 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// uninittimer() -- shut down timer
|
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
void timerUninit(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2012-11-25 04:26:37 +00:00
|
|
|
if (!win_timerfreq) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
win_timerfreq=0;
|
2006-04-24 19:04:22 +00:00
|
|
|
timerticspersec = 0;
|
2012-07-25 18:56:15 +00:00
|
|
|
|
2013-07-07 20:59:00 +00:00
|
|
|
msperu64tick = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// sampletimer() -- update totalclock
|
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
void timerUpdate(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-09-09 07:19:14 +00:00
|
|
|
int64_t i;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t n;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
if (!win_timerfreq) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
QueryPerformanceCounter((LARGE_INTEGER *)&i);
|
2012-11-25 04:26:37 +00:00
|
|
|
n = (int32_t)((i*timerticspersec / win_timerfreq) - timerlastsample);
|
2010-05-09 08:51:25 +00:00
|
|
|
|
|
|
|
if (n <= 0) return;
|
|
|
|
|
|
|
|
totalclock += n;
|
|
|
|
timerlastsample += n;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
if (usertimercallback) for (; n>0; n--) usertimercallback();
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// getticks() -- returns the windows ticks count
|
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
uint32_t timerGetTicks(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-09-09 07:19:14 +00:00
|
|
|
int64_t i;
|
2012-11-25 04:26:37 +00:00
|
|
|
if (win_timerfreq == 0) return 0;
|
2011-01-16 02:50:27 +00:00
|
|
|
QueryPerformanceCounter((LARGE_INTEGER *)&i);
|
2012-11-25 04:26:37 +00:00
|
|
|
return (uint32_t)(i*longlong(1000)/win_timerfreq);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2011-09-15 17:05:00 +00:00
|
|
|
// high-resolution timers for profiling
|
2018-04-12 21:02:51 +00:00
|
|
|
uint64_t timerGetTicksU64(void)
|
2011-09-15 17:05:00 +00:00
|
|
|
{
|
2013-07-07 20:59:00 +00:00
|
|
|
return win_getu64ticks();
|
2011-09-15 17:05:00 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
uint64_t timerGetFreqU64(void)
|
2011-09-15 17:05:00 +00:00
|
|
|
{
|
2012-11-25 04:26:37 +00:00
|
|
|
return win_timerfreq;
|
2011-09-15 17:05:00 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-07-25 18:56:15 +00:00
|
|
|
// Returns the time since an unspecified starting time in milliseconds.
|
|
|
|
ATTRIBUTE((flatten))
|
2018-04-12 21:02:51 +00:00
|
|
|
double timerGetHiTicks(void)
|
2012-07-25 18:56:15 +00:00
|
|
|
{
|
2018-04-12 21:02:51 +00:00
|
|
|
return (double)timerGetTicksU64() * msperu64tick;
|
2012-07-25 18:56:15 +00:00
|
|
|
}
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
|
|
|
// gettimerfreq() -- returns the number of ticks per second the timer is configured to generate
|
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
int32_t timerGetFreq(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
return timerticspersec;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
// VIDEO
|
|
|
|
//=================================================================================================
|
|
|
|
|
|
|
|
// DirectDraw objects
|
|
|
|
static HMODULE hDDrawDLL = NULL;
|
|
|
|
static LPDIRECTDRAW lpDD = NULL;
|
|
|
|
static LPDIRECTDRAWSURFACE lpDDSPrimary = NULL;
|
|
|
|
static LPDIRECTDRAWSURFACE lpDDSBack = NULL;
|
2011-01-16 02:50:27 +00:00
|
|
|
static char *lpOffscreen = NULL;
|
2006-04-13 20:47:06 +00:00
|
|
|
static LPDIRECTDRAWPALETTE lpDDPalette = NULL;
|
|
|
|
static BOOL bDDrawInited = FALSE;
|
|
|
|
static DWORD DDdwCaps = 0, DDdwCaps2 = 0;
|
|
|
|
|
|
|
|
// DIB stuff
|
|
|
|
static HDC hDC = NULL; // opengl shares this
|
|
|
|
static HDC hDCSection = NULL;
|
|
|
|
static HBITMAP hDIBSection = NULL;
|
|
|
|
static HPALETTE hPalette = NULL;
|
|
|
|
static VOID *lpPixels = NULL;
|
|
|
|
|
2013-04-13 03:50:19 +00:00
|
|
|
static int32_t setgammaramp(LPDDGAMMARAMP gt);
|
|
|
|
static int32_t getgammaramp(LPDDGAMMARAMP gt);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// checkvideomode() -- makes sure the video mode passed is legal
|
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
int32_t videoCheckMode(int32_t *x, int32_t *y, int32_t c, int32_t fs, int32_t forced)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, nearest=-1, dx, dy, odx=9999, ody=9999;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
videoGetModes();
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
// fix up the passed resolution values to be multiples of 8
|
|
|
|
// and at least 320x200 or at most MAXXDIMxMAXYDIM
|
|
|
|
if (*x < 320) *x = 320;
|
|
|
|
if (*y < 200) *y = 200;
|
|
|
|
if (*x > MAXXDIM) *x = MAXXDIM;
|
|
|
|
if (*y > MAXYDIM) *y = MAXYDIM;
|
2010-05-18 00:30:30 +00:00
|
|
|
// *x &= 0xfffffff8l;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
for (i=0; i<validmodecnt; i++)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (validmode[i].bpp != c) continue;
|
|
|
|
if (validmode[i].fs != fs) continue;
|
|
|
|
dx = klabs(validmode[i].xdim - *x);
|
|
|
|
dy = klabs(validmode[i].ydim - *y);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!(dx | dy)) // perfect match
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
nearest = i;
|
|
|
|
break;
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
if ((dx <= odx) && (dy <= ody))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
nearest = i;
|
|
|
|
odx = dx; ody = dy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#ifdef ANY_WINDOWED_SIZE
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!forced && (fs&1) == 0 && (nearest < 0 || validmode[nearest].xdim!=*x || validmode[nearest].ydim!=*y))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// check the colour depth is recognised at the very least
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<validmodecnt; i++)
|
2006-04-24 19:04:22 +00:00
|
|
|
if (validmode[i].bpp == c)
|
|
|
|
return 0x7fffffffl;
|
|
|
|
return -1; // strange colour depth
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (nearest < 0)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// no mode that will match (eg. if no fullscreen modes)
|
|
|
|
return -1;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
*x = validmode[nearest].xdim;
|
|
|
|
*y = validmode[nearest].ydim;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return nearest; // JBF 20031206: Returns the mode number
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// setvideomode() -- set the video mode
|
|
|
|
//
|
2008-07-22 21:03:09 +00:00
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2008-07-22 21:03:09 +00:00
|
|
|
static HWND hGLWindow = NULL;
|
|
|
|
#endif
|
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
char inp;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t modenum;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-05-16 04:07:09 +00:00
|
|
|
if ((fs == fullscreen) && (x == xres) && (y == yres) && (c == bpp) && !videomodereset)
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
modenum = videoCheckMode(&x,&y,c,fs,0);
|
2006-04-24 19:04:22 +00:00
|
|
|
if (modenum < 0) return -1;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (modenum == 0x7fffffff)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
customxdim = x;
|
|
|
|
customydim = y;
|
|
|
|
custombpp = c;
|
|
|
|
customfs = fs;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
inp = di_devacquired;
|
|
|
|
AcquireInputDevices(0);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hWindow && gammabrightness)
|
|
|
|
{
|
2013-04-13 03:50:19 +00:00
|
|
|
setgammaramp(&sysgamma);
|
2006-04-24 19:04:22 +00:00
|
|
|
gammabrightness = 0;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
win_setvideomode(c);
|
2010-01-04 06:01:34 +00:00
|
|
|
|
2008-06-11 18:52:39 +00:00
|
|
|
if (!silentvideomodeswitch)
|
|
|
|
initprintf("Setting video mode %dx%d (%d-bit %s)\n",
|
|
|
|
x,y,c, ((fs&1) ? "fullscreen" : "windowed"));
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-08-31 01:56:43 +00:00
|
|
|
if (CreateAppWindow(modenum)) return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!gammabrightness)
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
// float f = 1.0 + ((float)curbrightness / 10.0);
|
2013-04-13 03:50:19 +00:00
|
|
|
if (getgammaramp(&sysgamma) >= 0) gammabrightness = 1;
|
2018-04-12 21:02:51 +00:00
|
|
|
if (gammabrightness && videoSetGamma() < 0) gammabrightness = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2016-01-12 10:30:40 +00:00
|
|
|
#if defined USE_OPENGL && defined USE_GLEXT
|
2018-02-16 06:38:21 +00:00
|
|
|
if (hGLWindow && glinfo.vsync) wglSwapIntervalEXT(vsync_renderlayer);
|
2008-07-22 21:03:09 +00:00
|
|
|
#endif
|
2010-05-18 00:30:30 +00:00
|
|
|
if (inp) AcquireInputDevices(1);
|
2006-04-24 19:04:22 +00:00
|
|
|
modechange=1;
|
|
|
|
videomodereset = 0;
|
|
|
|
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// getvalidmodes() -- figure out what video modes are available
|
|
|
|
//
|
2018-02-26 02:48:06 +00:00
|
|
|
#define ADDMODE(x,y,c,f,n) \
|
|
|
|
{ \
|
|
|
|
int fullscreen; \
|
|
|
|
for (fullscreen = f; fullscreen >= 0; --fullscreen) \
|
|
|
|
{ \
|
|
|
|
if (validmodecnt<MAXVALIDMODES) \
|
|
|
|
{ \
|
|
|
|
validmode[validmodecnt].xdim=x; \
|
|
|
|
validmode[validmodecnt].ydim=y; \
|
|
|
|
validmode[validmodecnt].bpp=c; \
|
|
|
|
validmode[validmodecnt].fs=fullscreen; \
|
|
|
|
validmode[validmodecnt].extra=n; \
|
|
|
|
validmodecnt++; \
|
|
|
|
/* initprintf(" - %dx%d %d-bit %s\n", x, y, c, (fullscreen&1)?"fullscreen":"windowed");*/\
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#define CHECK(w,h) if ((w < maxx) && (h < maxy))
|
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
int32_t videoSetVsync(int32_t newSync)
|
2008-07-22 21:03:09 +00:00
|
|
|
{
|
2016-12-26 06:01:40 +00:00
|
|
|
#ifdef USE_OPENGL
|
2008-07-22 21:03:09 +00:00
|
|
|
if (!glinfo.vsync)
|
|
|
|
{
|
2016-12-26 06:01:36 +00:00
|
|
|
vsync_renderlayer = 0;
|
2016-11-18 05:29:51 +00:00
|
|
|
return 0;
|
2008-07-22 21:03:09 +00:00
|
|
|
}
|
2016-01-12 10:30:40 +00:00
|
|
|
# ifdef USE_GLEXT
|
2018-02-16 06:38:21 +00:00
|
|
|
wglSwapIntervalEXT(newSync);
|
2016-01-12 10:30:40 +00:00
|
|
|
# endif
|
2016-12-26 06:01:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
vsync_renderlayer = newSync;
|
2016-11-18 05:29:51 +00:00
|
|
|
|
|
|
|
return newSync;
|
2008-07-22 21:03:09 +00:00
|
|
|
}
|
|
|
|
|
2016-12-26 06:01:40 +00:00
|
|
|
#ifdef USE_OPENGL
|
2006-04-13 20:47:06 +00:00
|
|
|
static void cdsenummodes(void)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
DEVMODE dm;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i = 0, j = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
struct { uint32_t x,y,bpp,freq; } modes[MAXVALIDMODES];
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t nmodes=0;
|
2009-01-10 07:38:50 +00:00
|
|
|
uint32_t maxx = MAXXDIM, maxy = MAXYDIM;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
ZeroMemory(&dm,sizeof(DEVMODE));
|
|
|
|
dm.dmSize = sizeof(DEVMODE);
|
2007-12-12 17:42:14 +00:00
|
|
|
while (EnumDisplaySettings(NULL, j, &dm))
|
|
|
|
{
|
|
|
|
if (dm.dmBitsPerPel > 8)
|
|
|
|
{
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<nmodes; i++)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (modes[i].x == dm.dmPelsWidth
|
|
|
|
&& modes[i].y == dm.dmPelsHeight
|
|
|
|
&& modes[i].bpp == dm.dmBitsPerPel)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((i==nmodes) ||
|
|
|
|
(dm.dmDisplayFrequency <= maxrefreshfreq && dm.dmDisplayFrequency > modes[i].freq && maxrefreshfreq > 0) ||
|
2007-12-12 17:42:14 +00:00
|
|
|
(dm.dmDisplayFrequency > modes[i].freq && maxrefreshfreq == 0))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (i==nmodes) nmodes++;
|
|
|
|
|
|
|
|
modes[i].x = dm.dmPelsWidth;
|
|
|
|
modes[i].y = dm.dmPelsHeight;
|
|
|
|
modes[i].bpp = dm.dmBitsPerPel;
|
|
|
|
modes[i].freq = dm.dmDisplayFrequency;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
j++;
|
|
|
|
ZeroMemory(&dm,sizeof(DEVMODE));
|
|
|
|
dm.dmSize = sizeof(DEVMODE);
|
|
|
|
}
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<nmodes; i++)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
CHECK(modes[i].x, modes[i].y)
|
|
|
|
ADDMODE(modes[i].x, modes[i].y, modes[i].bpp, 1, modes[i].freq);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// mode enumerator
|
|
|
|
static HRESULT WINAPI getvalidmodes_enum(DDSURFACEDESC *ddsd, VOID *udata)
|
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
uint32_t maxx = MAXXDIM, maxy = MAXYDIM;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2008-03-23 00:14:22 +00:00
|
|
|
UNREFERENCED_PARAMETER(udata);
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (ddsd->ddpfPixelFormat.dwRGBBitCount == 8)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
CHECK(ddsd->dwWidth, ddsd->dwHeight)
|
|
|
|
ADDMODE(ddsd->dwWidth, ddsd->dwHeight, ddsd->ddpfPixelFormat.dwRGBBitCount, 1,-1);
|
|
|
|
}
|
|
|
|
|
2016-06-21 00:34:41 +00:00
|
|
|
return DDENUMRET_OK;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2013-09-21 13:38:44 +00:00
|
|
|
static int sortmodes(const void *a_, const void *b_)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t x;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2013-09-21 13:38:44 +00:00
|
|
|
const struct validmode_t *a = (const struct validmode_t *)a_;
|
|
|
|
const struct validmode_t *b = (const struct validmode_t *)b_;
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if ((x = a->fs - b->fs) != 0) return x;
|
|
|
|
if ((x = a->bpp - b->bpp) != 0) return x;
|
|
|
|
if ((x = a->xdim - b->xdim) != 0) return x;
|
|
|
|
if ((x = a->ydim - b->ydim) != 0) return x;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2018-04-12 21:02:51 +00:00
|
|
|
void videoGetModes(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t cdepths[2] = { 8, 0 };
|
|
|
|
int32_t i, j, maxx=0, maxy=0;
|
2006-04-24 19:04:22 +00:00
|
|
|
HRESULT result;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2008-08-26 19:50:34 +00:00
|
|
|
if (desktopbpp > 8 && !nogl) cdepths[1] = desktopbpp;
|
|
|
|
else cdepths[1] = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (modeschecked) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
validmodecnt=0;
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf("Detecting video modes:\n");
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (bDDrawInited)
|
|
|
|
{
|
2008-02-24 00:46:57 +00:00
|
|
|
// if DirectDraw initialization didn't fail enumerate fullscreen modes
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
result = IDirectDraw_EnumDisplayModes(lpDD, 0, NULL, 0, getvalidmodes_enum);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (result != DD_OK)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
initprintf("Unable to enumerate fullscreen modes. Using default list.\n");
|
2007-12-12 17:42:14 +00:00
|
|
|
for (j=0; j < 2; j++)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (cdepths[j] == 0) continue;
|
2018-04-12 21:02:31 +00:00
|
|
|
for (i=0; g_defaultVideoModes[i].x; i++)
|
|
|
|
ADDMODE(g_defaultVideoModes[i].x,g_defaultVideoModes[i].y,cdepths[j],1,-1)
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2006-04-24 19:04:22 +00:00
|
|
|
cdsenummodes();
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2013-05-20 19:31:18 +00:00
|
|
|
// Windowed modes can be as big as the current desktop resolution, but not bigger.
|
|
|
|
maxx = desktopxdim+1;
|
|
|
|
maxy = desktopydim+1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
// add windowed modes next
|
2007-12-12 17:42:14 +00:00
|
|
|
for (j=0; j < 2; j++)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (cdepths[j] == 0) continue;
|
2018-04-12 21:02:31 +00:00
|
|
|
for (i=0; g_defaultVideoModes[i].x; i++)
|
|
|
|
CHECK(g_defaultVideoModes[i].x,g_defaultVideoModes[i].y)
|
|
|
|
ADDMODE(g_defaultVideoModes[i].x,g_defaultVideoModes[i].y,cdepths[j],0,-1)
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2013-09-21 13:38:44 +00:00
|
|
|
qsort((void *)validmode, validmodecnt, sizeof(struct validmode_t), &sortmodes);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
modeschecked=1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef CHECK
|
|
|
|
#undef ADDMODE
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// resetvideomode() -- resets the video system
|
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
void videoResetMode(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
videomodereset = 1;
|
|
|
|
modeschecked = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// begindrawing() -- locks the framebuffer for drawing
|
|
|
|
//
|
2015-07-25 17:23:21 +00:00
|
|
|
#ifdef DEBUG_FRAME_LOCKING
|
|
|
|
uint32_t begindrawing_line[BEGINDRAWING_SIZE];
|
|
|
|
const char *begindrawing_file[BEGINDRAWING_SIZE];
|
|
|
|
void begindrawing_real(void)
|
|
|
|
#else
|
2018-04-12 21:02:51 +00:00
|
|
|
void videoBeginDrawing(void)
|
2015-07-25 17:23:21 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
if (bpp > 8)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (offscreenrendering) return;
|
|
|
|
frameplace = 0;
|
|
|
|
bytesperline = 0;
|
|
|
|
modechange = 0;
|
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (lockcount++ > 0)
|
|
|
|
return; // already locked
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (offscreenrendering) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2019-06-25 18:35:11 +00:00
|
|
|
if (inpreparemirror)
|
|
|
|
{
|
|
|
|
frameplace = (intptr_t)mirrorBuffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
frameplace = fullscreen ? (intptr_t)lpOffscreen : (intptr_t)lpPixels;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!modechange) return;
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
modechange=0;
|
|
|
|
|
2012-12-18 18:07:28 +00:00
|
|
|
if (!fullscreen)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
bytesperline = xres|4;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
bytesperline = xres|1;
|
|
|
|
}
|
|
|
|
|
2012-12-14 19:28:17 +00:00
|
|
|
calc_ylookup(bytesperline, ydim);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// enddrawing() -- unlocks the framebuffer
|
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
void videoEndDrawing(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
if (bpp > 8)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!offscreenrendering) frameplace = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!frameplace) return;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (lockcount > 1) { lockcount--; return; }
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!offscreenrendering) frameplace = 0;
|
|
|
|
lockcount = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// showframe() -- update the display
|
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
void videoShowFrame(int32_t w)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
HRESULT result;
|
|
|
|
DDSURFACEDESC ddsd;
|
|
|
|
char *p,*q;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i,j;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2007-12-12 17:42:14 +00:00
|
|
|
if (bpp > 8)
|
|
|
|
{
|
|
|
|
if (palfadedelta)
|
2012-12-10 18:17:44 +00:00
|
|
|
fullscreen_tint_gl(palfadergb.r, palfadergb.g, palfadergb.b, palfadedelta);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
SwapBuffers(hDC);
|
2006-04-24 19:04:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
// w = 1; // wait regardless. ken thinks it's better to do so.
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
if (offscreenrendering) return;
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (lockcount)
|
|
|
|
{
|
|
|
|
initprintf("Frame still locked %d times when showframe() called.\n", lockcount);
|
2018-04-12 21:02:51 +00:00
|
|
|
while (lockcount) videoEndDrawing();
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2012-12-18 18:07:28 +00:00
|
|
|
if (!fullscreen)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
BitBlt(hDC, 0, 0, xres, yres, hDCSection, 0, 0, SRCCOPY);
|
2010-05-02 23:27:30 +00:00
|
|
|
return;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2016-11-18 05:29:51 +00:00
|
|
|
/*
|
|
|
|
else
|
|
|
|
IDirectDraw_WaitForVerticalBlank(lpDD, DDWAITVB_BLOCKBEGIN, NULL);
|
|
|
|
*/
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if (!w && (IDirectDrawSurface_GetBltStatus(lpDDSBack, DDGBS_CANBLT) == DDERR_WASSTILLDRAWING ||
|
2010-05-18 00:30:30 +00:00
|
|
|
IDirectDrawSurface_GetFlipStatus(lpDDSPrimary, DDGFS_CANFLIP) == DDERR_WASSTILLDRAWING))
|
|
|
|
return;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
// lock the backbuffer surface
|
|
|
|
Bmemset(&ddsd, 0, sizeof(ddsd));
|
|
|
|
ddsd.dwSize = sizeof(ddsd);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
result = IDirectDrawSurface_Lock(lpDDSBack, NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if (result == DDERR_SURFACELOST)
|
|
|
|
{
|
|
|
|
if (!appactive)
|
|
|
|
return; // not in a position to restore display anyway
|
|
|
|
|
|
|
|
IDirectDrawSurface_Restore(lpDDSPrimary);
|
|
|
|
result = IDirectDrawSurface_Lock(lpDDSBack, NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL);
|
|
|
|
}
|
|
|
|
if (result != DD_OK)
|
|
|
|
{
|
|
|
|
if (result != DDERR_WASSTILLDRAWING)
|
|
|
|
initprintf("Failed locking back-buffer surface: %s\n", GetDDrawError(result));
|
|
|
|
return;
|
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
// copy each scanline
|
|
|
|
p = (char *)ddsd.lpSurface;
|
|
|
|
q = (char *)lpOffscreen;
|
|
|
|
j = xres >> 2;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
for (i=0; i<yres; i++, p+=ddsd.lPitch, q+=bytesperline)
|
|
|
|
copybuf(q,p,j);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
// unlock the backbuffer surface
|
|
|
|
result = IDirectDrawSurface_Unlock(lpDDSBack, NULL);
|
|
|
|
if (result != DD_OK)
|
|
|
|
{
|
|
|
|
initprintf("Failed unlocking back-buffer surface: %s\n", GetDDrawError(result));
|
|
|
|
return;
|
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
// flip the chain
|
|
|
|
result = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, w?DDFLIP_WAIT:0);
|
|
|
|
if (result == DDERR_SURFACELOST)
|
|
|
|
{
|
|
|
|
if (!appactive)
|
|
|
|
return; // not in a position to restore display anyway
|
|
|
|
IDirectDrawSurface_Restore(lpDDSPrimary);
|
2006-04-24 19:04:22 +00:00
|
|
|
result = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, w?DDFLIP_WAIT:0);
|
2010-05-02 23:27:30 +00:00
|
|
|
}
|
|
|
|
if (result != DD_OK)
|
|
|
|
{
|
|
|
|
if (result != DDERR_WASSTILLDRAWING)
|
|
|
|
initprintf("IDirectDrawSurface_Flip(): %s\n", GetDDrawError(result));
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// setpalette() -- set palette values
|
|
|
|
// New behaviour: curpalettefaded is the live palette, and any changes this function
|
|
|
|
// makes are done to it and not the base palette.
|
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
int32_t videoUpdatePalette(int32_t start, int32_t num)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, n;
|
2006-04-24 19:04:22 +00:00
|
|
|
HRESULT result;
|
|
|
|
RGBQUAD *rgb;
|
|
|
|
//HPALETTE hPalPrev;
|
|
|
|
|
2008-07-25 13:42:37 +00:00
|
|
|
static struct logpal
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
WORD palVersion;
|
|
|
|
WORD palNumEntries;
|
|
|
|
PALETTEENTRY palPalEntry[256];
|
|
|
|
} lpal;
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if (bpp > 8) return 0; // no palette in opengl
|
|
|
|
|
2008-07-25 13:42:37 +00:00
|
|
|
Bmemcpy(lpal.palPalEntry, curpalettefaded, sizeof(lpal.palPalEntry));
|
|
|
|
for (i=start, n=num-1; n>0; i++, n--)
|
|
|
|
curpalettefaded[i].f = lpal.palPalEntry[i].peFlags = PC_NOCOLLAPSE;
|
2012-12-18 18:07:28 +00:00
|
|
|
|
|
|
|
if (fullscreen)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if (!lpDDPalette) return -1;
|
|
|
|
result = IDirectDrawPalette_SetEntries(lpDDPalette, 0, 0, 256, (LPPALETTEENTRY)lpal.palPalEntry);
|
|
|
|
if (result != DD_OK)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
initprintf("Palette set failed: %s\n", GetDDrawError(result));
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
|
|
|
|
if (num > 0)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2018-10-25 23:28:56 +00:00
|
|
|
rgb = (RGBQUAD *)Xmalloc(sizeof(RGBQUAD)*num);
|
2010-05-02 23:27:30 +00:00
|
|
|
for (i=start, n=0; n<num; i++, n++)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
rgb[n].rgbBlue = lpal.palPalEntry[i].peBlue;
|
|
|
|
rgb[n].rgbGreen = lpal.palPalEntry[i].peGreen;
|
|
|
|
rgb[n].rgbRed = lpal.palPalEntry[i].peRed;
|
|
|
|
rgb[n].rgbReserved = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
|
|
|
|
SetDIBColorTable(hDCSection, start, num, rgb);
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(rgb);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// getpalette() -- get palette values
|
|
|
|
//
|
|
|
|
/*
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t getpalette(int32_t start, int32_t num, char *dapal)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
int32_t i;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
for (i=num; i>0; i--, start++) {
|
|
|
|
dapal[0] = curpalette[start].b >> 2;
|
|
|
|
dapal[1] = curpalette[start].g >> 2;
|
|
|
|
dapal[2] = curpalette[start].r >> 2;
|
|
|
|
dapal += 4;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// setgamma
|
|
|
|
//
|
2013-04-13 03:50:19 +00:00
|
|
|
static int32_t setgammaramp(LPDDGAMMARAMP gt)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2012-12-18 18:07:28 +00:00
|
|
|
if (!fullscreen || bpp > 8)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// GL and windowed mode use DIB method
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2006-04-24 19:04:22 +00:00
|
|
|
HDC hDC = GetDC(hWindow);
|
|
|
|
i = SetDeviceGammaRamp(hDC, gt) ? 0 : -1;
|
|
|
|
ReleaseDC(hWindow, hDC);
|
|
|
|
return i;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2008-10-02 17:45:44 +00:00
|
|
|
else if (appactive)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// fullscreen uses DirectX
|
|
|
|
LPDIRECTDRAWGAMMACONTROL gam;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!(DDdwCaps2 & DDCAPS2_PRIMARYGAMMA)) return -1;
|
|
|
|
|
2012-11-15 14:27:57 +00:00
|
|
|
hr = IDirectDrawSurface_QueryInterface(lpDDSPrimary, bREFIID IID_IDirectDrawGammaControl, (LPVOID *)&gam);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hr != DD_OK)
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
// ShowDDrawErrorBox("Error querying gamma control", hr);
|
2008-10-02 17:45:44 +00:00
|
|
|
initprintf("Error querying gamma control: %s\n",GetDDrawError(hr));
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-04-13 03:50:19 +00:00
|
|
|
hr = IDirectDrawGammaControl_SetGammaRamp(gam, 0, gt);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hr != DD_OK)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
IDirectDrawGammaControl_Release(gam);
|
2008-10-02 17:45:44 +00:00
|
|
|
initprintf("Error setting gamma ramp: %s\n",GetDDrawError(hr));
|
2010-05-18 00:30:30 +00:00
|
|
|
// ShowDDrawErrorBox("Error setting gamma ramp", hr);
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDirectDrawGammaControl_Release(gam);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-10-27 13:14:22 +00:00
|
|
|
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
int32_t videoSetGamma(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2013-04-13 03:50:19 +00:00
|
|
|
static DDGAMMARAMP gammaTable;
|
2018-04-12 21:02:51 +00:00
|
|
|
float gamma = max(0.1f,min(4.f,g_videoGamma));
|
|
|
|
float contrast = max(0.1f,min(3.f,g_videoContrast));
|
|
|
|
float bright = max(-0.8f,min(0.8f,g_videoBrightness));
|
2008-07-20 00:39:06 +00:00
|
|
|
|
|
|
|
double invgamma = 1 / gamma;
|
|
|
|
double norm = pow(255., invgamma - 1);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
if (!hWindow) return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-10-27 13:14:22 +00:00
|
|
|
if (winlayer_have_ATI && bpp==8 && fullscreen)
|
|
|
|
return -1;
|
|
|
|
|
2008-07-20 00:39:06 +00:00
|
|
|
// This formula is taken from Doomsday
|
|
|
|
|
2012-05-05 22:22:05 +00:00
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
double val = i * contrast - (contrast - 1) * 127;
|
|
|
|
if (gamma != 1) val = pow(val, invgamma) / norm;
|
|
|
|
val += bright * 128;
|
|
|
|
|
2019-03-04 23:48:50 +00:00
|
|
|
gammaTable.red[i] = gammaTable.green[i] = gammaTable.blue[i] = (uint16_t)max(0.f, min<float>(65535.f, val * 256.f));
|
2012-05-05 22:22:05 +00:00
|
|
|
}
|
2008-07-20 00:39:06 +00:00
|
|
|
|
2013-04-13 03:50:19 +00:00
|
|
|
return setgammaramp(&gammaTable);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2013-04-13 03:50:19 +00:00
|
|
|
static int32_t getgammaramp(LPDDGAMMARAMP gt)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!hWindow) return -1;
|
2012-12-18 18:07:28 +00:00
|
|
|
if (!fullscreen || bpp > 8)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2006-04-24 19:04:22 +00:00
|
|
|
HDC hDC = GetDC(hWindow);
|
|
|
|
i = GetDeviceGammaRamp(hDC, gt) ? 0 : -1;
|
|
|
|
ReleaseDC(hWindow, hDC);
|
|
|
|
return i;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
LPDIRECTDRAWGAMMACONTROL gam;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!(DDdwCaps2 & DDCAPS2_PRIMARYGAMMA)) return -1;
|
|
|
|
|
2012-11-15 14:27:57 +00:00
|
|
|
hr = IDirectDrawSurface_QueryInterface(lpDDSPrimary, bREFIID IID_IDirectDrawGammaControl, (LPVOID *)&gam);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hr != DD_OK)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowDDrawErrorBox("Error querying gamma control", hr);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-04-13 03:50:19 +00:00
|
|
|
hr = IDirectDrawGammaControl_GetGammaRamp(gam, 0, gt);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hr != DD_OK)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
IDirectDrawGammaControl_Release(gam);
|
|
|
|
ShowDDrawErrorBox("Error getting gamma ramp", hr);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDirectDrawGammaControl_Release(gam);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// InitDirectDraw() -- get DirectDraw started
|
|
|
|
//
|
|
|
|
|
|
|
|
// device enumerator
|
|
|
|
static BOOL WINAPI InitDirectDraw_enum(GUID *lpGUID, LPSTR lpDesc, LPSTR lpName, LPVOID lpContext)
|
|
|
|
{
|
2008-03-23 00:14:22 +00:00
|
|
|
UNREFERENCED_PARAMETER(lpGUID);
|
|
|
|
UNREFERENCED_PARAMETER(lpName);
|
|
|
|
UNREFERENCED_PARAMETER(lpContext);
|
2009-05-05 16:21:33 +00:00
|
|
|
UNREFERENCED_PARAMETER(lpDesc);
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" * %s\n", lpDesc);
|
2006-04-24 19:04:22 +00:00
|
|
|
return 1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL InitDirectDraw(void)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
HRESULT result;
|
2007-12-12 17:42:14 +00:00
|
|
|
HRESULT(WINAPI *aDirectDrawCreate)(GUID *, LPDIRECTDRAW *, IUnknown *);
|
|
|
|
HRESULT(WINAPI *aDirectDrawEnumerate)(LPDDENUMCALLBACK, LPVOID);
|
2006-04-24 19:04:22 +00:00
|
|
|
DDCAPS ddcaps;
|
|
|
|
|
|
|
|
if (bDDrawInited) return FALSE;
|
|
|
|
|
2008-02-24 00:46:57 +00:00
|
|
|
initprintf("Initializing DirectDraw...\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
// load up the DirectDraw DLL
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hDDrawDLL)
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" - Loading DDRAW.DLL\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
hDDrawDLL = LoadLibrary("DDRAW.DLL");
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hDDrawDLL)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowErrorBox("Error loading DDRAW.DLL");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the pointer to DirectDrawEnumerate
|
2019-03-04 23:48:50 +00:00
|
|
|
aDirectDrawEnumerate = (decltype(aDirectDrawEnumerate))GetProcAddress(hDDrawDLL, "DirectDrawEnumerateA");
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!aDirectDrawEnumerate)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowErrorBox("Error fetching DirectDrawEnumerate()");
|
|
|
|
UninitDirectDraw();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// enumerate the devices to make us look fancy
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" - Enumerating display devices\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
aDirectDrawEnumerate(InitDirectDraw_enum, NULL);
|
|
|
|
|
|
|
|
// get the pointer to DirectDrawCreate
|
2019-03-04 23:48:50 +00:00
|
|
|
aDirectDrawCreate = (decltype(aDirectDrawCreate))GetProcAddress(hDDrawDLL, "DirectDrawCreate");
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!aDirectDrawCreate)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowErrorBox("Error fetching DirectDrawCreate()");
|
|
|
|
UninitDirectDraw();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a new DirectDraw object
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" - Creating DirectDraw object\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
result = aDirectDrawCreate(NULL, &lpDD, NULL);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (result != DD_OK)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowDDrawErrorBox("DirectDrawCreate() failed", result);
|
|
|
|
UninitDirectDraw();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// fetch capabilities
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" - Checking capabilities\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
ddcaps.dwSize = sizeof(DDCAPS);
|
|
|
|
result = IDirectDraw_GetCaps(lpDD, &ddcaps, NULL);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (result != DD_OK)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
initprintf(" Unable to get capabilities.\n");
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
DDdwCaps = ddcaps.dwCaps;
|
|
|
|
DDdwCaps2 = ddcaps.dwCaps2;
|
|
|
|
}
|
|
|
|
|
|
|
|
bDDrawInited = TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// UninitDirectDraw() -- clean up DirectDraw
|
|
|
|
//
|
|
|
|
static void UninitDirectDraw(void)
|
|
|
|
{
|
2008-02-24 00:46:57 +00:00
|
|
|
if (bDDrawInited) initprintf("Uninitializing DirectDraw...\n");
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
ReleaseDirectDrawSurfaces();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
RestoreDirectDrawMode();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (lpDD)
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" - Releasing DirectDraw object\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
IDirectDraw_Release(lpDD);
|
|
|
|
lpDD = NULL;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hDDrawDLL)
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" - Unloading DDRAW.DLL\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
FreeLibrary(hDDrawDLL);
|
|
|
|
hDDrawDLL = NULL;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
bDDrawInited = FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// RestoreDirectDrawMode() -- resets the screen mode
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t RestoreDirectDrawMode(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
HRESULT result;
|
|
|
|
|
|
|
|
if (fullscreen == 0 || /*bpp > 8 ||*/ !bDDrawInited) return FALSE;
|
|
|
|
|
|
|
|
if (modesetusing == 1) ChangeDisplaySettings(NULL,0);
|
2007-12-12 17:42:14 +00:00
|
|
|
else if (modesetusing == 0)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// restore previous display mode and set to normal cooperative level
|
|
|
|
result = IDirectDraw_RestoreDisplayMode(lpDD);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (result != DD_OK)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowDDrawErrorBox("Error restoring display mode", result);
|
|
|
|
UninitDirectDraw();
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
result = IDirectDraw_SetCooperativeLevel(lpDD, hWindow, DDSCL_NORMAL);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (result != DD_OK)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowDDrawErrorBox("Error setting cooperative level", result);
|
|
|
|
UninitDirectDraw();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
modesetusing = -1;
|
|
|
|
|
|
|
|
return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// ReleaseDirectDrawSurfaces() -- release the front and back buffers
|
|
|
|
//
|
|
|
|
static void ReleaseDirectDrawSurfaces(void)
|
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
if (lpDDPalette)
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" - Releasing palette\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
IDirectDrawPalette_Release(lpDDPalette);
|
|
|
|
lpDDPalette = NULL;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (lpDDSBack)
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" - Releasing back-buffer surface\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
IDirectDrawSurface_Release(lpDDSBack);
|
|
|
|
lpDDSBack = NULL;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (lpDDSPrimary)
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" - Releasing primary surface\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
IDirectDrawSurface_Release(lpDDSPrimary);
|
|
|
|
lpDDSPrimary = NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-23 17:55:31 +00:00
|
|
|
// if (lpOffscreen)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" - Freeing offscreen buffer\n");
|
2015-09-23 17:55:31 +00:00
|
|
|
DO_FREE_AND_NULL(lpOffscreen);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// SetupDirectDraw() -- sets up DirectDraw rendering
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t SetupDirectDraw(int32_t width, int32_t height)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
HRESULT result;
|
|
|
|
DDSURFACEDESC ddsd;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
// now create the DirectDraw surfaces
|
|
|
|
ZeroMemory(&ddsd, sizeof(ddsd));
|
|
|
|
ddsd.dwSize = sizeof(ddsd);
|
|
|
|
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
|
|
|
|
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
|
|
|
|
ddsd.dwBackBufferCount = 2; // triple-buffer
|
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" - Creating primary surface\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
result = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSPrimary, NULL);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (result != DD_OK)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowDDrawErrorBox("Failure creating primary surface", result);
|
|
|
|
UninitDirectDraw();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZeroMemory(&ddsd.ddsCaps, sizeof(ddsd.ddsCaps));
|
|
|
|
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
|
|
|
|
numpages = 1; // KJS 20031225
|
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" - Getting back buffer\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
result = IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary, &ddsd.ddsCaps, &lpDDSBack);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (result != DD_OK)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowDDrawErrorBox("Failure fetching back-buffer surface", result);
|
|
|
|
UninitDirectDraw();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" - Allocating offscreen buffer\n");
|
2018-10-25 23:28:56 +00:00
|
|
|
lpOffscreen = (char *)Xmalloc((width|1)*height);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!lpOffscreen)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowErrorBox("Failure allocating offscreen buffer");
|
|
|
|
UninitDirectDraw();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// attach a palette to the primary surface
|
2010-05-18 00:30:30 +00:00
|
|
|
// initprintf(" - Creating palette\n");
|
2008-07-25 13:42:37 +00:00
|
|
|
for (i=0; i<256; i++)
|
|
|
|
curpalettefaded[i].f = PC_NOCOLLAPSE;
|
2012-05-05 22:23:44 +00:00
|
|
|
|
|
|
|
result = IDirectDraw_CreatePalette(lpDD, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
|
|
|
|
(LPPALETTEENTRY)curpalettefaded, &lpDDPalette, NULL);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (result != DD_OK)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowDDrawErrorBox("Failure creating palette", result);
|
|
|
|
UninitDirectDraw();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = IDirectDrawSurface_SetPalette(lpDDSPrimary, lpDDPalette);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (result != DD_OK)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowDDrawErrorBox("Failure setting palette", result);
|
|
|
|
UninitDirectDraw();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// UninitDIB() -- clean up the DIB renderer
|
|
|
|
//
|
|
|
|
static void UninitDIB(void)
|
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hPalette)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
DeleteObject(hPalette);
|
|
|
|
hPalette = NULL;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hDCSection)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
DeleteDC(hDCSection);
|
|
|
|
hDCSection = NULL;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hDIBSection)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
DeleteObject(hDIBSection);
|
|
|
|
hDIBSection = NULL;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hDC)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ReleaseDC(hWindow, hDC);
|
|
|
|
hDC = NULL;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// SetupDIB() -- sets up DIB rendering
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t SetupDIB(int32_t width, int32_t height)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
struct binfo
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
BITMAPINFOHEADER header;
|
|
|
|
RGBQUAD colours[256];
|
|
|
|
} dibsect;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hDC)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
hDC = GetDC(hWindow);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hDC)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowErrorBox("Error getting device context");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hDCSection)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
DeleteDC(hDCSection);
|
|
|
|
hDCSection = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// destroy the previous DIB section if it existed
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hDIBSection)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
DeleteObject(hDIBSection);
|
|
|
|
hDIBSection = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create the new DIB section
|
|
|
|
memset(&dibsect, 0, sizeof(dibsect));
|
|
|
|
numpages = 1; // KJS 20031225
|
|
|
|
dibsect.header.biSize = sizeof(dibsect.header);
|
|
|
|
dibsect.header.biWidth = width|1; // Ken did this
|
|
|
|
dibsect.header.biHeight = -height;
|
|
|
|
dibsect.header.biPlanes = 1;
|
|
|
|
dibsect.header.biBitCount = 8;
|
|
|
|
dibsect.header.biCompression = BI_RGB;
|
|
|
|
dibsect.header.biClrUsed = 256;
|
|
|
|
dibsect.header.biClrImportant = 256;
|
2007-12-12 17:42:14 +00:00
|
|
|
for (i=0; i<256; i++)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
dibsect.colours[i].rgbBlue = curpalette[i].b;
|
|
|
|
dibsect.colours[i].rgbGreen = curpalette[i].g;
|
|
|
|
dibsect.colours[i].rgbRed = curpalette[i].r;
|
|
|
|
}
|
|
|
|
|
|
|
|
hDIBSection = CreateDIBSection(hDC, (BITMAPINFO *)&dibsect, DIB_RGB_COLORS, &lpPixels, NULL, 0);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hDIBSection)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ReleaseDC(hWindow, hDC);
|
|
|
|
hDC = NULL;
|
|
|
|
|
|
|
|
ShowErrorBox("Error creating DIB section");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(lpPixels, 0, width*height);
|
|
|
|
|
|
|
|
// create a compatible memory DC
|
|
|
|
hDCSection = CreateCompatibleDC(hDC);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hDCSection)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ReleaseDC(hWindow, hDC);
|
|
|
|
hDC = NULL;
|
|
|
|
|
|
|
|
ShowErrorBox("Error creating compatible DC");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// select the DIB section into the memory DC
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!SelectObject(hDCSection, hDIBSection))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ReleaseDC(hWindow, hDC);
|
|
|
|
hDC = NULL;
|
|
|
|
DeleteDC(hDCSection);
|
|
|
|
hDCSection = NULL;
|
|
|
|
|
|
|
|
ShowErrorBox("Error creating compatible DC");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
|
|
|
// ReleaseOpenGL() -- cleans up OpenGL rendering stuff
|
|
|
|
//
|
|
|
|
|
|
|
|
static void ReleaseOpenGL(void)
|
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hGLRC)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
polymost_glreset();
|
2018-02-16 06:38:21 +00:00
|
|
|
if (!wglMakeCurrent(0,0)) { }
|
|
|
|
if (!wglDeleteContext(hGLRC)) { }
|
2006-04-24 19:04:22 +00:00
|
|
|
hGLRC = NULL;
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hGLWindow)
|
|
|
|
{
|
|
|
|
if (hDC)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ReleaseDC(hGLWindow, hDC);
|
|
|
|
hDC = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DestroyWindow(hGLWindow);
|
|
|
|
hGLWindow = NULL;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2008-02-24 00:46:57 +00:00
|
|
|
// UninitOpenGL() -- unitializes any openGL libraries
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
|
|
|
static void UninitOpenGL(void)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ReleaseOpenGL();
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// SetupOpenGL() -- sets up opengl rendering
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t SetupOpenGL(int32_t width, int32_t height, int32_t bitspp)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
PIXELFORMATDESCRIPTOR pfd =
|
|
|
|
{
|
|
|
|
sizeof(PIXELFORMATDESCRIPTOR),
|
|
|
|
1, //Version Number
|
|
|
|
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, //Must Support these
|
|
|
|
PFD_TYPE_RGBA, //Request An RGBA Format
|
|
|
|
0, //Select Our Color Depth
|
|
|
|
0,0,0,0,0,0, //Color Bits Ignored
|
|
|
|
0, //No Alpha Buffer
|
|
|
|
0, //Shift Bit Ignored
|
|
|
|
0, //No Accumulation Buffer
|
|
|
|
0,0,0,0, //Accumulation Bits Ignored
|
2019-06-25 18:35:16 +00:00
|
|
|
24, //16/24/32 Z-Buffer depth
|
|
|
|
8, //8-bit Stencil Buffer
|
2007-12-12 17:42:14 +00:00
|
|
|
0, //No Auxiliary Buffer
|
|
|
|
PFD_MAIN_PLANE, //Main Drawing Layer
|
|
|
|
0, //Reserved
|
|
|
|
0,0,0 //Layer Masks Ignored
|
|
|
|
};
|
2006-04-24 19:04:22 +00:00
|
|
|
GLuint PixelFormat;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t minidriver;
|
|
|
|
int32_t err;
|
2006-04-24 19:04:22 +00:00
|
|
|
pfd.cColorBits = bitspp;
|
|
|
|
|
|
|
|
hGLWindow = CreateWindow(
|
|
|
|
WindowClass,
|
|
|
|
"OpenGL Window",
|
|
|
|
WS_CHILD|WS_VISIBLE,
|
|
|
|
0,0,
|
|
|
|
width,height,
|
|
|
|
hWindow,
|
2007-09-10 23:38:42 +00:00
|
|
|
(HMENU)0,
|
2006-04-24 19:04:22 +00:00
|
|
|
hInstance,
|
|
|
|
NULL);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hGLWindow)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowErrorBox("Error creating OpenGL child window.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hDC = GetDC(hGLWindow);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hDC)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ReleaseOpenGL();
|
|
|
|
ShowErrorBox("Error getting device context");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
minidriver = Bstrcasecmp(gldriver,"opengl32.dll");
|
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
if (minidriver) PixelFormat = wglChoosePixelFormat(hDC,&pfd);
|
2006-04-24 19:04:22 +00:00
|
|
|
else PixelFormat = ChoosePixelFormat(hDC,&pfd);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!PixelFormat)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ReleaseOpenGL();
|
|
|
|
ShowErrorBox("Can't choose pixel format");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
if (minidriver) err = wglSetPixelFormat(hDC, PixelFormat, &pfd);
|
2006-04-24 19:04:22 +00:00
|
|
|
else err = SetPixelFormat(hDC, PixelFormat, &pfd);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!err)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ReleaseOpenGL();
|
|
|
|
ShowErrorBox("Can't set pixel format");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
hGLRC = wglCreateContext(hDC);
|
2011-10-03 00:14:56 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hGLRC)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ReleaseOpenGL();
|
|
|
|
ShowErrorBox("Can't create GL RC");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
if (!wglMakeCurrent(hDC, hGLRC))
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ReleaseOpenGL();
|
|
|
|
ShowErrorBox("Can't activate GL RC");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2018-02-26 14:46:36 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
static int32_t glLoaded = 0;
|
|
|
|
if (!glLoaded)
|
|
|
|
{
|
|
|
|
if (!gladLoadWGL(hDC) || !gladLoadGL())
|
|
|
|
{
|
|
|
|
initprintf("Failure loading OpenGL. GL modes are unavailable.\n");
|
|
|
|
nogl = 1;
|
|
|
|
ReleaseOpenGL();
|
|
|
|
return TRUE;
|
|
|
|
#ifdef POLYMER
|
2018-06-13 19:15:22 +00:00
|
|
|
}
|
|
|
|
else if (loadglulibrary(getenv("BUILD_GLULIB")))
|
2018-02-16 06:38:21 +00:00
|
|
|
{
|
|
|
|
initprintf("Failure loading GLU. GL modes are unavailable.\n");
|
|
|
|
nogl = 1;
|
|
|
|
ReleaseOpenGL();
|
|
|
|
return TRUE;
|
|
|
|
#endif
|
2018-06-13 19:15:22 +00:00
|
|
|
}
|
|
|
|
else if (GLVersion.major < 2)
|
|
|
|
{
|
|
|
|
initprintf("Your computer does not support OpenGL version 2 or greater. GL modes are unavailable.\n");
|
|
|
|
nogl = 1;
|
|
|
|
ReleaseOpenGL();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
2018-02-16 06:38:21 +00:00
|
|
|
{
|
|
|
|
glLoaded = 1;
|
|
|
|
}
|
|
|
|
}
|
2011-10-03 00:14:56 +00:00
|
|
|
|
2016-01-12 10:30:40 +00:00
|
|
|
# if defined DEBUGGINGAIDS && defined USE_GLEXT
|
2011-10-03 00:14:56 +00:00
|
|
|
// We should really be checking for the new WGL extension string instead
|
|
|
|
// Enable this to leverage ARB_debug_output
|
2018-02-16 06:38:21 +00:00
|
|
|
if (wglCreateContextAttribsARB) {
|
2011-10-03 00:14:56 +00:00
|
|
|
HGLRC debuggingContext = hGLRC;
|
|
|
|
|
|
|
|
// This corresponds to WGL_CONTEXT_FLAGS_ARB set to WGL_CONTEXT_DEBUG_BIT_ARB
|
|
|
|
// I'm too lazy to get a new wglext.h
|
|
|
|
int attribs[] = {
|
|
|
|
0x2094, 0x1,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
debuggingContext = wglCreateContextAttribsARB(hDC, NULL, attribs);
|
2011-10-03 00:14:56 +00:00
|
|
|
|
|
|
|
if (debuggingContext) {
|
2018-02-16 06:38:21 +00:00
|
|
|
wglDeleteContext(hGLRC);
|
|
|
|
wglMakeCurrent(hDC, debuggingContext);
|
2011-10-03 00:14:56 +00:00
|
|
|
hGLRC = debuggingContext;
|
|
|
|
}
|
|
|
|
}
|
2016-01-12 10:30:40 +00:00
|
|
|
# endif
|
2011-10-03 00:14:56 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
polymost_glreset();
|
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glShadeModel(GL_SMOOTH); //GL_FLAT
|
|
|
|
glClearColor(0,0,0,0.5); //Black Background
|
|
|
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); //Use FASTEST for ortho!
|
|
|
|
glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
|
|
|
|
glHint(GL_TEXTURE_COMPRESSION_HINT, GL_NICEST);
|
|
|
|
glDisable(GL_DITHER);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
GLubyte *p,*p2,*p3;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t err = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glinfo.vendor = (char const *)glGetString(GL_VENDOR);
|
|
|
|
glinfo.renderer = (char const *)glGetString(GL_RENDERER);
|
|
|
|
glinfo.version = (char const *)glGetString(GL_VERSION);
|
|
|
|
glinfo.extensions = (char const *)glGetString(GL_EXTENSIONS);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2008-08-26 19:50:34 +00:00
|
|
|
// GL driver blacklist
|
2009-06-24 08:20:10 +00:00
|
|
|
|
|
|
|
if (!Bstrcmp(glinfo.vendor,"Microsoft Corporation")) err = 1;
|
|
|
|
else if (!Bstrcmp(glinfo.vendor,"SiS")) err = 1;
|
|
|
|
else if (!Bstrcmp(glinfo.vendor,"3Dfx Interactive Inc.")) err = 1;
|
2014-11-28 08:14:00 +00:00
|
|
|
#ifdef POLYMER
|
2013-08-07 14:29:22 +00:00
|
|
|
else if (!Bstrcmp(glinfo.vendor, "Intel"))
|
|
|
|
pr_ati_fboworkaround = 1;
|
2014-11-28 08:14:00 +00:00
|
|
|
#endif
|
2009-06-24 08:20:10 +00:00
|
|
|
else
|
|
|
|
{
|
2009-10-15 23:08:47 +00:00
|
|
|
if (!Bstrcmp(glinfo.vendor,"ATI Technologies Inc."))
|
|
|
|
{
|
2011-10-27 13:14:22 +00:00
|
|
|
winlayer_have_ATI = 1;
|
2010-03-01 09:13:25 +00:00
|
|
|
#ifdef POLYMER
|
2009-06-28 21:03:50 +00:00
|
|
|
pr_ati_fboworkaround = 1;
|
2010-03-01 09:13:25 +00:00
|
|
|
#endif
|
2011-01-16 02:45:54 +00:00
|
|
|
if (Bstrstr(glinfo.renderer,"Radeon X1"))
|
2009-10-15 23:08:47 +00:00
|
|
|
{
|
2010-03-01 09:13:25 +00:00
|
|
|
#ifdef POLYMER
|
2009-06-28 21:16:11 +00:00
|
|
|
pr_ati_nodepthoffset = 1;
|
|
|
|
initprintf("Enabling ATI R520 polygon offset workaround.\n");
|
2010-03-01 09:13:25 +00:00
|
|
|
#endif
|
2009-10-15 23:08:47 +00:00
|
|
|
}
|
2010-03-01 09:13:25 +00:00
|
|
|
#ifdef POLYMER
|
2009-10-15 23:08:47 +00:00
|
|
|
else
|
2009-06-28 21:16:11 +00:00
|
|
|
pr_ati_nodepthoffset = 0;
|
2010-03-01 09:13:25 +00:00
|
|
|
#endif
|
2009-10-15 23:08:47 +00:00
|
|
|
}
|
2010-03-01 09:13:25 +00:00
|
|
|
#ifdef POLYMER
|
2009-10-15 23:08:47 +00:00
|
|
|
else
|
2009-06-28 21:16:11 +00:00
|
|
|
pr_ati_fboworkaround = 0;
|
2009-06-07 06:23:33 +00:00
|
|
|
#endif
|
2010-03-01 09:13:25 +00:00
|
|
|
}
|
2010-03-02 22:44:12 +00:00
|
|
|
|
2014-11-28 08:14:00 +00:00
|
|
|
#ifdef POLYMER
|
2013-08-07 14:29:22 +00:00
|
|
|
if (pr_ati_fboworkaround)
|
|
|
|
initprintf("Enabling Intel/ATI FBO color attachment workaround.\n");
|
2014-11-28 08:14:00 +00:00
|
|
|
#endif
|
2013-08-07 14:29:22 +00:00
|
|
|
|
2009-06-24 08:20:10 +00:00
|
|
|
if (!forcegl && err)
|
|
|
|
{
|
|
|
|
OSD_Printf("Unsupported OpenGL driver detected. GL modes will be unavailable. Use -forcegl to override.\n");
|
|
|
|
wm_msgbox("Unsupported OpenGL driver", "Unsupported OpenGL driver detected. GL modes will be unavailable.");
|
|
|
|
ReleaseOpenGL();
|
2018-02-16 06:38:21 +00:00
|
|
|
//POGO: there is no equivalent to unloadgldriver() with GLAD's loader, but this shouldn't be a problem.
|
|
|
|
//unloadgldriver();
|
|
|
|
unloadwgl();
|
2009-06-24 08:20:10 +00:00
|
|
|
nogl = 1;
|
|
|
|
modeschecked = 0;
|
2018-04-12 21:02:51 +00:00
|
|
|
videoGetModes();
|
2009-06-24 08:20:10 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2008-08-26 19:50:34 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
glinfo.maxanisotropy = 1.0;
|
|
|
|
glinfo.bgra = 0;
|
|
|
|
glinfo.texcompr = 0;
|
|
|
|
|
|
|
|
// process the extensions string and flag stuff we recognize
|
2018-10-25 23:28:56 +00:00
|
|
|
p = (GLubyte *)Xstrdup(glinfo.extensions);
|
2006-04-24 19:04:22 +00:00
|
|
|
p3 = p;
|
2011-01-16 02:50:27 +00:00
|
|
|
while ((p2 = (GLubyte *)Bstrtoken(p3==p?(char *)p:NULL, " ", (char **)&p3, 1)) != NULL)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
|
|
|
if (!Bstrcmp((char *)p2, "GL_EXT_texture_filter_anisotropic"))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// supports anisotropy. get the maximum anisotropy level
|
2018-02-16 06:38:21 +00:00
|
|
|
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glinfo.maxanisotropy);
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (!Bstrcmp((char *)p2, "GL_EXT_texture_edge_clamp") ||
|
|
|
|
!Bstrcmp((char *)p2, "GL_SGIS_texture_edge_clamp"))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// supports GL_CLAMP_TO_EDGE or GL_CLAMP_TO_EDGE_SGIS
|
|
|
|
glinfo.clamptoedge = 1;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2019-09-18 18:44:21 +00:00
|
|
|
/*
|
2007-12-12 17:42:14 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "GL_EXT_bgra"))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// support bgra textures
|
|
|
|
glinfo.bgra = 1;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2019-09-18 18:44:21 +00:00
|
|
|
*/
|
2011-03-12 16:37:45 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_texture_compression") && Bstrcmp(glinfo.vendor,"ATI Technologies Inc."))
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// support texture compression
|
|
|
|
glinfo.texcompr = 1;
|
2016-03-28 05:15:10 +00:00
|
|
|
|
|
|
|
#ifdef DYNAMIC_GLEXT
|
2018-02-16 06:38:21 +00:00
|
|
|
if (!glCompressedTexImage2D || !glGetCompressedTexImage)
|
2016-03-28 05:15:10 +00:00
|
|
|
{
|
|
|
|
// lacking the necessary extensions to do this
|
|
|
|
initprintf("Warning: the GL driver lacks necessary functions to use caching\n");
|
|
|
|
glinfo.texcompr = 0;
|
|
|
|
}
|
|
|
|
#endif
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_texture_non_power_of_two"))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// support non-power-of-two texture sizes
|
|
|
|
glinfo.texnpot = 1;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_fragment_program"))
|
|
|
|
{
|
2007-01-06 01:29:45 +00:00
|
|
|
glinfo.arbfp = 1;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_depth_texture"))
|
|
|
|
{
|
2007-01-06 01:29:45 +00:00
|
|
|
glinfo.depthtex = 1;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_shadow"))
|
|
|
|
{
|
2007-01-06 01:29:45 +00:00
|
|
|
glinfo.shadow = 1;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (!Bstrcmp((char *)p2, "GL_EXT_framebuffer_object"))
|
|
|
|
{
|
2007-01-06 01:29:45 +00:00
|
|
|
glinfo.fbos = 1;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (!Bstrcmp((char *)p2, "GL_NV_texture_rectangle") ||
|
|
|
|
!Bstrcmp((char *)p2, "GL_EXT_texture_rectangle"))
|
|
|
|
{
|
2007-01-06 01:29:45 +00:00
|
|
|
glinfo.rect = 1;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2007-01-15 09:08:57 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_multitexture"))
|
|
|
|
{
|
|
|
|
glinfo.multitex = 1;
|
|
|
|
}
|
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_texture_env_combine"))
|
|
|
|
{
|
|
|
|
glinfo.envcombine = 1;
|
|
|
|
}
|
2007-03-08 03:07:10 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_vertex_buffer_object"))
|
|
|
|
{
|
|
|
|
glinfo.vbos = 1;
|
|
|
|
}
|
2008-07-22 21:03:09 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "WGL_EXT_swap_control"))
|
|
|
|
{
|
|
|
|
glinfo.vsync = 1;
|
|
|
|
}
|
2009-02-05 08:56:59 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "GL_EXT_gpu_shader4"))
|
|
|
|
{
|
|
|
|
glinfo.sm4 = 1;
|
|
|
|
}
|
2009-09-30 01:26:13 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_occlusion_query"))
|
|
|
|
{
|
|
|
|
glinfo.occlusionqueries = 1;
|
|
|
|
}
|
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_shader_objects"))
|
|
|
|
{
|
|
|
|
glinfo.glsl = 1;
|
|
|
|
}
|
2011-10-02 05:56:35 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_debug_output"))
|
|
|
|
{
|
|
|
|
glinfo.debugoutput = 1;
|
|
|
|
}
|
2015-07-15 08:23:00 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_buffer_storage"))
|
|
|
|
{
|
|
|
|
glinfo.bufferstorage = 1;
|
|
|
|
}
|
2018-02-16 06:38:48 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_sync"))
|
|
|
|
{
|
|
|
|
glinfo.sync = 1;
|
|
|
|
}
|
2019-07-05 21:17:52 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_depth_clamp"))
|
|
|
|
{
|
|
|
|
glinfo.depthclamp = 1;
|
|
|
|
}
|
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_clipcontrol"))
|
|
|
|
{
|
|
|
|
glinfo.clipcontrol = 1;
|
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(p);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
numpages = 2; // KJS 20031225: tell rotatesprite that it's double buffered!
|
|
|
|
|
2008-02-24 00:46:57 +00:00
|
|
|
if (!glinfo.dumped)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t oldbpp = bpp;
|
2008-05-31 03:53:53 +00:00
|
|
|
bpp = 32;
|
2008-02-24 00:46:57 +00:00
|
|
|
osdcmd_glinfo(NULL);
|
|
|
|
glinfo.dumped = TRUE;
|
2008-05-31 03:53:53 +00:00
|
|
|
bpp = oldbpp;
|
2008-02-24 00:46:57 +00:00
|
|
|
}
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
// CreateAppWindow() -- create the application window
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
static BOOL CreateAppWindow(int32_t modenum)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
RECT rect;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t w, h, x, y, stylebits = 0, stylebitsex = 0;
|
|
|
|
int32_t width, height, fs, bitspp;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
HRESULT result;
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (modenum == 0x7fffffff)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
width = customxdim;
|
|
|
|
height = customydim;
|
|
|
|
fs = customfs;
|
|
|
|
bitspp = custombpp;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
width = validmode[modenum].xdim;
|
|
|
|
height = validmode[modenum].ydim;
|
|
|
|
fs = validmode[modenum].fs;
|
|
|
|
bitspp = validmode[modenum].bpp;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (width == xres && height == yres && fs == fullscreen && bitspp == bpp && !videomodereset) return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hWindow)
|
|
|
|
{
|
|
|
|
if (bpp > 8)
|
|
|
|
{
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2010-05-02 23:27:30 +00:00
|
|
|
ReleaseOpenGL();
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
ReleaseDirectDrawSurfaces();
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!fs && fullscreen)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// restore previous display mode and set to normal cooperative level
|
|
|
|
RestoreDirectDrawMode();
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (fs && fullscreen)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// using CDS for GL modes, so restore from DirectDraw
|
|
|
|
if (bpp != bitspp) RestoreDirectDrawMode();
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ShowWindow(hWindow, SW_HIDE); // so Windows redraws what's behind if the window shrinks
|
|
|
|
}
|
2012-12-18 18:07:28 +00:00
|
|
|
|
|
|
|
if (fs)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
stylebitsex = WS_EX_TOPMOST;
|
|
|
|
stylebits = WS_POPUP;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
stylebitsex = 0;
|
|
|
|
stylebits = WINDOW_STYLE;
|
|
|
|
}
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hWindow)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
hWindow = CreateWindowEx(
|
|
|
|
stylebitsex,
|
2010-05-02 23:27:30 +00:00
|
|
|
WindowClass,
|
2006-04-24 19:04:22 +00:00
|
|
|
apptitle,
|
|
|
|
stylebits,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
320,
|
|
|
|
200,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
hInstance,
|
|
|
|
0);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hWindow)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowErrorBox("Unable to create window");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-07-01 01:40:18 +00:00
|
|
|
startwin_close();
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
SetWindowLong(hWindow,GWL_EXSTYLE,stylebitsex);
|
|
|
|
SetWindowLong(hWindow,GWL_STYLE,stylebits);
|
|
|
|
}
|
|
|
|
|
|
|
|
// resize the window
|
2012-12-18 18:07:28 +00:00
|
|
|
if (!fs)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
rect.left = 0;
|
|
|
|
rect.top = 0;
|
|
|
|
rect.right = width-1;
|
|
|
|
rect.bottom = height-1;
|
|
|
|
AdjustWindowRect(&rect, stylebits, FALSE);
|
|
|
|
|
|
|
|
w = (rect.right - rect.left);
|
|
|
|
h = (rect.bottom - rect.top);
|
|
|
|
x = (desktopxdim - w) / 2;
|
|
|
|
y = (desktopydim - h) / 2;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
x=y=0;
|
|
|
|
w=width;
|
|
|
|
h=height;
|
|
|
|
}
|
2007-04-22 03:44:54 +00:00
|
|
|
|
|
|
|
if (windowx == -1)
|
|
|
|
windowx = x;
|
|
|
|
|
|
|
|
if (windowy == -1)
|
|
|
|
windowy = y;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2006-08-31 01:56:43 +00:00
|
|
|
SetWindowText(hWindow, apptitle);
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowWindow(hWindow, SW_SHOWNORMAL);
|
|
|
|
SetForegroundWindow(hWindow);
|
|
|
|
SetFocus(hWindow);
|
|
|
|
|
2007-04-22 03:44:54 +00:00
|
|
|
SetWindowPos(hWindow, HWND_TOP, windowpos?windowx:x, windowpos?windowy:y, w, h, 0);
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
// fullscreen?
|
2012-12-18 18:07:28 +00:00
|
|
|
if (!fs)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
|
|
|
if (bitspp > 8)
|
|
|
|
{
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2006-04-24 19:04:22 +00:00
|
|
|
// yes, start up opengl
|
2007-12-12 17:42:14 +00:00
|
|
|
if (SetupOpenGL(width,height,bitspp))
|
2006-04-24 19:04:22 +00:00
|
|
|
return TRUE;
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
else if (SetupDIB(width,height)) // use DIB section
|
|
|
|
return TRUE;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
modesetusing = -1;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// yes, set up DirectDraw
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
// clean up after the DIB renderer if it was being used
|
|
|
|
UninitDIB();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!bDDrawInited)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
DestroyWindow(hWindow);
|
|
|
|
hWindow = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2007-12-12 17:42:14 +00:00
|
|
|
if (bitspp > 8)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
DEVMODE dmScreenSettings;
|
|
|
|
|
|
|
|
ZeroMemory(&dmScreenSettings, sizeof(DEVMODE));
|
|
|
|
dmScreenSettings.dmSize = sizeof(DEVMODE);
|
|
|
|
dmScreenSettings.dmPelsWidth = width;
|
|
|
|
dmScreenSettings.dmPelsHeight = height;
|
|
|
|
dmScreenSettings.dmBitsPerPel = bitspp;
|
|
|
|
dmScreenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (modenum != 0x7fffffff)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
dmScreenSettings.dmDisplayFrequency = validmode[modenum].extra;
|
|
|
|
dmScreenSettings.dmFields |= DM_DISPLAYFREQUENCY;
|
|
|
|
}
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowErrorBox("Video mode not supported");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowWindow(hWindow, SW_SHOWNORMAL);
|
|
|
|
SetForegroundWindow(hWindow);
|
|
|
|
SetFocus(hWindow);
|
|
|
|
|
|
|
|
modesetusing = 1;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
// set exclusive cooperative level
|
2008-11-16 00:48:02 +00:00
|
|
|
result = IDirectDraw_SetCooperativeLevel(lpDD, hWindow, DDSCL_ALLOWMODEX|DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (result != DD_OK)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowDDrawErrorBox("Error setting cooperative level", result);
|
|
|
|
UninitDirectDraw();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = IDirectDraw_SetDisplayMode(lpDD, width, height, bitspp);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (result != DD_OK)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowDDrawErrorBox("Error setting display mode", result);
|
|
|
|
UninitDirectDraw();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
modesetusing = 0;
|
|
|
|
}
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (bitspp > 8)
|
|
|
|
{
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2006-04-24 19:04:22 +00:00
|
|
|
// we want an opengl mode
|
2007-12-12 17:42:14 +00:00
|
|
|
if (SetupOpenGL(width,height,bitspp))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// we want software
|
2007-12-12 17:42:14 +00:00
|
|
|
if (SetupDirectDraw(width,height))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xres = width;
|
|
|
|
yres = height;
|
|
|
|
bpp = bitspp;
|
|
|
|
fullscreen = fs;
|
|
|
|
curvidmode = modenum;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
frameplace = 0;
|
|
|
|
lockcount = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
// bytesperline is set when framebuffer is locked
|
|
|
|
//bytesperline = width;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
modechange = 1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
UpdateWindow(hWindow);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// DestroyAppWindow() -- destroys the application window
|
|
|
|
//
|
|
|
|
static void DestroyAppWindow(void)
|
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hWindow && gammabrightness)
|
|
|
|
{
|
2013-04-13 03:50:19 +00:00
|
|
|
setgammaramp(&sysgamma);
|
2006-04-24 19:04:22 +00:00
|
|
|
gammabrightness = 0;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2006-04-24 19:04:22 +00:00
|
|
|
UninitOpenGL();
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
UninitDirectDraw();
|
|
|
|
UninitDIB();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hWindow)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
DestroyWindow(hWindow);
|
|
|
|
hWindow = NULL;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// ShowDDrawErrorBox() -- shows an error message box for a DirectDraw error
|
|
|
|
//
|
|
|
|
static void ShowDDrawErrorBox(const char *m, HRESULT r)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
TCHAR msg[1024];
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
wsprintf(msg, "%s: %s", m, GetDDrawError(r));
|
|
|
|
MessageBox(0, msg, apptitle, MB_OK|MB_ICONSTOP);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// GetDDrawError() -- stinking huge list of error messages since MS didn't want to include
|
|
|
|
// them in the DLL
|
|
|
|
//
|
2011-01-16 02:50:27 +00:00
|
|
|
static const char *GetDDrawError(HRESULT code)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
switch (code)
|
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
case DD_OK:
|
|
|
|
return "DD_OK";
|
|
|
|
case DDERR_ALREADYINITIALIZED:
|
|
|
|
return "DDERR_ALREADYINITIALIZED";
|
|
|
|
case DDERR_BLTFASTCANTCLIP:
|
|
|
|
return "DDERR_BLTFASTCANTCLIP";
|
|
|
|
case DDERR_CANNOTATTACHSURFACE:
|
|
|
|
return "DDERR_CANNOTATTACHSURFACE";
|
|
|
|
case DDERR_CANNOTDETACHSURFACE:
|
|
|
|
return "DDERR_CANNOTDETACHSURFACE";
|
|
|
|
case DDERR_CANTCREATEDC:
|
|
|
|
return "DDERR_CANTCREATEDC";
|
|
|
|
case DDERR_CANTDUPLICATE:
|
|
|
|
return "DDERR_CANTDUPLICATE";
|
|
|
|
case DDERR_CANTLOCKSURFACE:
|
|
|
|
return "DDERR_CANTLOCKSURFACE";
|
|
|
|
case DDERR_CANTPAGELOCK:
|
|
|
|
return "DDERR_CANTPAGELOCK";
|
|
|
|
case DDERR_CANTPAGEUNLOCK:
|
|
|
|
return "DDERR_CANTPAGEUNLOCK";
|
|
|
|
case DDERR_CLIPPERISUSINGHWND:
|
|
|
|
return "DDERR_CLIPPERISUSINGHWND";
|
|
|
|
case DDERR_COLORKEYNOTSET:
|
|
|
|
return "DDERR_COLORKEYNOTSET";
|
|
|
|
case DDERR_CURRENTLYNOTAVAIL:
|
|
|
|
return "DDERR_CURRENTLYNOTAVAIL";
|
|
|
|
case DDERR_DCALREADYCREATED:
|
|
|
|
return "DDERR_DCALREADYCREATED";
|
|
|
|
case DDERR_DEVICEDOESNTOWNSURFACE:
|
|
|
|
return "DDERR_DEVICEDOESNTOWNSURFACE";
|
|
|
|
case DDERR_DIRECTDRAWALREADYCREATED:
|
|
|
|
return "DDERR_DIRECTDRAWALREADYCREATED";
|
|
|
|
case DDERR_EXCEPTION:
|
|
|
|
return "DDERR_EXCEPTION";
|
|
|
|
case DDERR_EXCLUSIVEMODEALREADYSET:
|
|
|
|
return "DDERR_EXCLUSIVEMODEALREADYSET";
|
|
|
|
case DDERR_EXPIRED:
|
|
|
|
return "DDERR_EXPIRED";
|
|
|
|
case DDERR_GENERIC:
|
|
|
|
return "DDERR_GENERIC";
|
|
|
|
case DDERR_HEIGHTALIGN:
|
|
|
|
return "DDERR_HEIGHTALIGN";
|
|
|
|
case DDERR_HWNDALREADYSET:
|
|
|
|
return "DDERR_HWNDALREADYSET";
|
|
|
|
case DDERR_HWNDSUBCLASSED:
|
|
|
|
return "DDERR_HWNDSUBCLASSED";
|
|
|
|
case DDERR_IMPLICITLYCREATED:
|
|
|
|
return "DDERR_IMPLICITLYCREATED";
|
|
|
|
case DDERR_INCOMPATIBLEPRIMARY:
|
|
|
|
return "DDERR_INCOMPATIBLEPRIMARY";
|
|
|
|
case DDERR_INVALIDCAPS:
|
|
|
|
return "DDERR_INVALIDCAPS";
|
|
|
|
case DDERR_INVALIDCLIPLIST:
|
|
|
|
return "DDERR_INVALIDCLIPLIST";
|
|
|
|
case DDERR_INVALIDDIRECTDRAWGUID:
|
|
|
|
return "DDERR_INVALIDDIRECTDRAWGUID";
|
|
|
|
case DDERR_INVALIDMODE:
|
|
|
|
return "DDERR_INVALIDMODE";
|
|
|
|
case DDERR_INVALIDOBJECT:
|
|
|
|
return "DDERR_INVALIDOBJECT";
|
|
|
|
case DDERR_INVALIDPARAMS:
|
|
|
|
return "DDERR_INVALIDPARAMS";
|
|
|
|
case DDERR_INVALIDPIXELFORMAT:
|
|
|
|
return "DDERR_INVALIDPIXELFORMAT";
|
|
|
|
case DDERR_INVALIDPOSITION:
|
|
|
|
return "DDERR_INVALIDPOSITION";
|
|
|
|
case DDERR_INVALIDRECT:
|
|
|
|
return "DDERR_INVALIDRECT";
|
|
|
|
case DDERR_INVALIDSTREAM:
|
|
|
|
return "DDERR_INVALIDSTREAM";
|
|
|
|
case DDERR_INVALIDSURFACETYPE:
|
|
|
|
return "DDERR_INVALIDSURFACETYPE";
|
|
|
|
case DDERR_LOCKEDSURFACES:
|
|
|
|
return "DDERR_LOCKEDSURFACES";
|
|
|
|
case DDERR_MOREDATA:
|
|
|
|
return "DDERR_MOREDATA";
|
|
|
|
case DDERR_NO3D:
|
|
|
|
return "DDERR_NO3D";
|
|
|
|
case DDERR_NOALPHAHW:
|
|
|
|
return "DDERR_NOALPHAHW";
|
|
|
|
case DDERR_NOBLTHW:
|
|
|
|
return "DDERR_NOBLTHW";
|
|
|
|
case DDERR_NOCLIPLIST:
|
|
|
|
return "DDERR_NOCLIPLIST";
|
|
|
|
case DDERR_NOCLIPPERATTACHED:
|
|
|
|
return "DDERR_NOCLIPPERATTACHED";
|
|
|
|
case DDERR_NOCOLORCONVHW:
|
|
|
|
return "DDERR_NOCOLORCONVHW";
|
|
|
|
case DDERR_NOCOLORKEY:
|
|
|
|
return "DDERR_NOCOLORKEY";
|
|
|
|
case DDERR_NOCOLORKEYHW:
|
|
|
|
return "DDERR_NOCOLORKEYHW";
|
|
|
|
case DDERR_NOCOOPERATIVELEVELSET:
|
|
|
|
return "DDERR_NOCOOPERATIVELEVELSET";
|
|
|
|
case DDERR_NODC:
|
|
|
|
return "DDERR_NODC";
|
|
|
|
case DDERR_NODDROPSHW:
|
|
|
|
return "DDERR_NODDROPSHW";
|
|
|
|
case DDERR_NODIRECTDRAWHW:
|
|
|
|
return "DDERR_NODIRECTDRAWHW";
|
|
|
|
case DDERR_NODIRECTDRAWSUPPORT:
|
|
|
|
return "DDERR_NODIRECTDRAWSUPPORT";
|
|
|
|
case DDERR_NOEMULATION:
|
|
|
|
return "DDERR_NOEMULATION";
|
|
|
|
case DDERR_NOEXCLUSIVEMODE:
|
|
|
|
return "DDERR_NOEXCLUSIVEMODE";
|
|
|
|
case DDERR_NOFLIPHW:
|
|
|
|
return "DDERR_NOFLIPHW";
|
|
|
|
case DDERR_NOFOCUSWINDOW:
|
|
|
|
return "DDERR_NOFOCUSWINDOW";
|
|
|
|
case DDERR_NOGDI:
|
|
|
|
return "DDERR_NOGDI";
|
|
|
|
case DDERR_NOHWND:
|
|
|
|
return "DDERR_NOHWND";
|
|
|
|
case DDERR_NOMIPMAPHW:
|
|
|
|
return "DDERR_NOMIPMAPHW";
|
|
|
|
case DDERR_NOMIRRORHW:
|
|
|
|
return "DDERR_NOMIRRORHW";
|
|
|
|
case DDERR_NONONLOCALVIDMEM:
|
|
|
|
return "DDERR_NONONLOCALVIDMEM";
|
|
|
|
case DDERR_NOOPTIMIZEHW:
|
|
|
|
return "DDERR_NOOPTIMIZEHW";
|
|
|
|
case DDERR_NOOVERLAYDEST:
|
|
|
|
return "DDERR_NOOVERLAYDEST";
|
|
|
|
case DDERR_NOOVERLAYHW:
|
|
|
|
return "DDERR_NOOVERLAYHW";
|
|
|
|
case DDERR_NOPALETTEATTACHED:
|
|
|
|
return "DDERR_NOPALETTEATTACHED";
|
|
|
|
case DDERR_NOPALETTEHW:
|
|
|
|
return "DDERR_NOPALETTEHW";
|
|
|
|
case DDERR_NORASTEROPHW:
|
|
|
|
return "DDERR_NORASTEROPHW";
|
|
|
|
case DDERR_NOROTATIONHW:
|
|
|
|
return "DDERR_NOROTATIONHW";
|
|
|
|
case DDERR_NOSTRETCHHW:
|
|
|
|
return "DDERR_NOSTRETCHHW";
|
|
|
|
case DDERR_NOT4BITCOLOR:
|
|
|
|
return "DDERR_NOT4BITCOLOR";
|
|
|
|
case DDERR_NOT4BITCOLORINDEX:
|
|
|
|
return "DDERR_NOT4BITCOLORINDEX";
|
|
|
|
case DDERR_NOT8BITCOLOR:
|
|
|
|
return "DDERR_NOT8BITCOLOR";
|
|
|
|
case DDERR_NOTAOVERLAYSURFACE:
|
|
|
|
return "DDERR_NOTAOVERLAYSURFACE";
|
|
|
|
case DDERR_NOTEXTUREHW:
|
|
|
|
return "DDERR_NOTEXTUREHW";
|
|
|
|
case DDERR_NOTFLIPPABLE:
|
|
|
|
return "DDERR_NOTFLIPPABLE";
|
|
|
|
case DDERR_NOTFOUND:
|
|
|
|
return "DDERR_NOTFOUND";
|
|
|
|
case DDERR_NOTINITIALIZED:
|
|
|
|
return "DDERR_NOTINITIALIZED";
|
|
|
|
case DDERR_NOTLOADED:
|
|
|
|
return "DDERR_NOTLOADED";
|
|
|
|
case DDERR_NOTLOCKED:
|
|
|
|
return "DDERR_NOTLOCKED";
|
|
|
|
case DDERR_NOTPAGELOCKED:
|
|
|
|
return "DDERR_NOTPAGELOCKED";
|
|
|
|
case DDERR_NOTPALETTIZED:
|
|
|
|
return "DDERR_NOTPALETTIZED";
|
|
|
|
case DDERR_NOVSYNCHW:
|
|
|
|
return "DDERR_NOVSYNCHW";
|
|
|
|
case DDERR_NOZBUFFERHW:
|
|
|
|
return "DDERR_NOZBUFFERHW";
|
|
|
|
case DDERR_NOZOVERLAYHW:
|
|
|
|
return "DDERR_NOZOVERLAYHW";
|
|
|
|
case DDERR_OUTOFCAPS:
|
|
|
|
return "DDERR_OUTOFCAPS";
|
|
|
|
case DDERR_OUTOFMEMORY:
|
|
|
|
return "DDERR_OUTOFMEMORY";
|
|
|
|
case DDERR_OUTOFVIDEOMEMORY:
|
|
|
|
return "DDERR_OUTOFVIDEOMEMORY";
|
|
|
|
case DDERR_OVERLAPPINGRECTS:
|
|
|
|
return "DDERR_OVERLAPPINGRECTS";
|
|
|
|
case DDERR_OVERLAYCANTCLIP:
|
|
|
|
return "DDERR_OVERLAYCANTCLIP";
|
|
|
|
case DDERR_OVERLAYCOLORKEYONLYONEACTIVE:
|
|
|
|
return "DDERR_OVERLAYCOLORKEYONLYONEACTIVE";
|
|
|
|
case DDERR_OVERLAYNOTVISIBLE:
|
|
|
|
return "DDERR_OVERLAYNOTVISIBLE";
|
|
|
|
case DDERR_PALETTEBUSY:
|
|
|
|
return "DDERR_PALETTEBUSY";
|
|
|
|
case DDERR_PRIMARYSURFACEALREADYEXISTS:
|
|
|
|
return "DDERR_PRIMARYSURFACEALREADYEXISTS";
|
|
|
|
case DDERR_REGIONTOOSMALL:
|
|
|
|
return "DDERR_REGIONTOOSMALL";
|
|
|
|
case DDERR_SURFACEALREADYATTACHED:
|
|
|
|
return "DDERR_SURFACEALREADYATTACHED";
|
|
|
|
case DDERR_SURFACEALREADYDEPENDENT:
|
|
|
|
return "DDERR_SURFACEALREADYDEPENDENT";
|
|
|
|
case DDERR_SURFACEBUSY:
|
|
|
|
return "DDERR_SURFACEBUSY";
|
|
|
|
case DDERR_SURFACEISOBSCURED:
|
|
|
|
return "DDERR_SURFACEISOBSCURED";
|
|
|
|
case DDERR_SURFACELOST:
|
|
|
|
return "DDERR_SURFACELOST";
|
|
|
|
case DDERR_SURFACENOTATTACHED:
|
|
|
|
return "DDERR_SURFACENOTATTACHED";
|
|
|
|
case DDERR_TOOBIGHEIGHT:
|
|
|
|
return "DDERR_TOOBIGHEIGHT";
|
|
|
|
case DDERR_TOOBIGSIZE:
|
|
|
|
return "DDERR_TOOBIGSIZE";
|
|
|
|
case DDERR_TOOBIGWIDTH:
|
|
|
|
return "DDERR_TOOBIGWIDTH";
|
|
|
|
case DDERR_UNSUPPORTED:
|
|
|
|
return "DDERR_UNSUPPORTED";
|
|
|
|
case DDERR_UNSUPPORTEDFORMAT:
|
|
|
|
return "DDERR_UNSUPPORTEDFORMAT";
|
|
|
|
case DDERR_UNSUPPORTEDMASK:
|
|
|
|
return "DDERR_UNSUPPORTEDMASK";
|
|
|
|
case DDERR_UNSUPPORTEDMODE:
|
|
|
|
return "DDERR_UNSUPPORTEDMODE";
|
|
|
|
case DDERR_VERTICALBLANKINPROGRESS:
|
|
|
|
return "DDERR_VERTICALBLANKINPROGRESS";
|
|
|
|
case DDERR_VIDEONOTACTIVE:
|
|
|
|
return "DDERR_VIDEONOTACTIVE";
|
|
|
|
case DDERR_WASSTILLDRAWING:
|
|
|
|
return "DDERR_WASSTILLDRAWING";
|
|
|
|
case DDERR_WRONGMODE:
|
|
|
|
return "DDERR_WRONGMODE";
|
|
|
|
case DDERR_XALIGN:
|
|
|
|
return "DDERR_XALIGN";
|
|
|
|
default:
|
|
|
|
break;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
return "Unknown error";
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
// MOSTLY STATIC INTERNAL WINDOWS THINGS
|
|
|
|
//=================================================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// WndProcCallback() -- the Windows window callback
|
|
|
|
//
|
|
|
|
static LRESULT CALLBACK WndProcCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2008-03-23 00:14:22 +00:00
|
|
|
/* RECT rect;
|
2010-05-18 00:30:30 +00:00
|
|
|
POINT pt;
|
|
|
|
HRESULT result; */
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2006-04-24 19:04:22 +00:00
|
|
|
if (hWnd == hGLWindow) return DefWindowProc(hWnd,uMsg,wParam,lParam);
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
switch (uMsg)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
// don't let the monitor fall asleep or let the screensaver activate
|
|
|
|
if (wParam == SC_SCREENSAVE || wParam == SC_MONITORPOWER) return 0;
|
|
|
|
|
|
|
|
// Since DirectInput won't let me set an exclusive-foreground
|
|
|
|
// keyboard for some unknown reason I just have to tell Windows to
|
|
|
|
// rack off with its keyboard accelerators.
|
|
|
|
if (wParam == SC_KEYMENU || wParam == SC_HOTKEY) return 0;
|
|
|
|
break;
|
|
|
|
|
2012-05-17 17:19:52 +00:00
|
|
|
case WM_ACTIVATE:
|
2006-12-08 16:45:12 +00:00
|
|
|
{
|
2012-05-17 17:19:52 +00:00
|
|
|
appactive = (LOWORD(wParam) != 0);
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2006-12-08 16:45:12 +00:00
|
|
|
if (hGLWindow)
|
|
|
|
{
|
|
|
|
if (!appactive && fullscreen)
|
|
|
|
{
|
2018-04-12 21:02:31 +00:00
|
|
|
if (g_mouseGrabbed)
|
2008-06-11 09:25:58 +00:00
|
|
|
{
|
2018-04-12 21:02:31 +00:00
|
|
|
mouseGrabInput(0);
|
2008-06-11 09:25:58 +00:00
|
|
|
regrabmouse = 1;
|
|
|
|
}
|
2006-12-08 16:45:12 +00:00
|
|
|
realfs = fullscreen;
|
2008-06-11 18:52:39 +00:00
|
|
|
silentvideomodeswitch = 1;
|
2018-07-14 21:36:44 +00:00
|
|
|
videoSetGameMode(!fullscreen,xres,yres,bpp,upscalefactor);
|
2006-12-08 16:45:12 +00:00
|
|
|
ShowWindow(hWindow, SW_MINIMIZE);
|
|
|
|
}
|
|
|
|
else if (appactive && realfs)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2008-06-11 09:25:58 +00:00
|
|
|
if (regrabmouse)
|
|
|
|
{
|
2018-04-12 21:02:31 +00:00
|
|
|
mouseGrabInput(g_mouseLockedToWindow);
|
2008-06-11 09:25:58 +00:00
|
|
|
regrabmouse = 0;
|
|
|
|
}
|
2008-12-31 09:07:49 +00:00
|
|
|
ShowWindow(hWindow, SW_RESTORE);
|
2006-12-08 16:45:12 +00:00
|
|
|
SetForegroundWindow(hWindow);
|
|
|
|
SetFocus(hWindow);
|
2018-07-14 21:36:44 +00:00
|
|
|
videoSetGameMode(realfs,xres,yres,bpp,upscalefactor);
|
2008-06-11 18:52:39 +00:00
|
|
|
silentvideomodeswitch = 0;
|
2006-12-08 16:45:12 +00:00
|
|
|
realfs = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2009-05-16 04:07:09 +00:00
|
|
|
|
2018-02-26 20:27:58 +00:00
|
|
|
// Win_SetKeyboardLayoutUS(appactive);
|
2016-12-26 06:02:53 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (backgroundidle)
|
2007-12-12 17:42:14 +00:00
|
|
|
SetPriorityClass(GetCurrentProcess(),
|
|
|
|
appactive ? NORMAL_PRIORITY_CLASS : IDLE_PRIORITY_CLASS);
|
2009-05-16 04:07:09 +00:00
|
|
|
|
|
|
|
if (appactive)
|
|
|
|
{
|
|
|
|
SetForegroundWindow(hWindow);
|
|
|
|
SetFocus(hWindow);
|
|
|
|
}
|
2010-05-09 22:12:29 +00:00
|
|
|
|
|
|
|
Bmemset(keystatus, 0, sizeof(keystatus));
|
2010-05-18 00:30:30 +00:00
|
|
|
AcquireInputDevices(appactive);
|
2012-05-17 17:19:52 +00:00
|
|
|
return 0;
|
2006-12-08 16:45:12 +00:00
|
|
|
}
|
2010-05-09 22:12:29 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
case WM_PALETTECHANGED:
|
|
|
|
// someone stole the palette so try and steal it back
|
2008-07-25 13:42:37 +00:00
|
|
|
if (bDDrawInited && bpp == 8 && fullscreen)
|
|
|
|
{
|
2012-01-12 20:49:50 +00:00
|
|
|
int32_t result;
|
|
|
|
|
|
|
|
// PK: for me, happens on Vista when changing from fullscreen 8-bit to 32-bit
|
|
|
|
if (!lpDDSPrimary || !lpDDPalette)
|
|
|
|
break;
|
|
|
|
|
|
|
|
result = IDirectDrawSurface_SetPalette(lpDDSPrimary, lpDDPalette);
|
|
|
|
|
2008-10-20 04:00:00 +00:00
|
|
|
if (result != DD_OK)
|
|
|
|
{
|
|
|
|
initprintf("Palette set failed: %s\n", GetDDrawError(result));
|
2008-07-25 23:39:41 +00:00
|
|
|
break;
|
2008-10-20 04:00:00 +00:00
|
|
|
}
|
2018-04-12 21:02:51 +00:00
|
|
|
videoUpdatePalette(0,256);
|
2008-10-20 04:00:00 +00:00
|
|
|
break;
|
2008-07-25 13:42:37 +00:00
|
|
|
}
|
2018-04-12 21:02:51 +00:00
|
|
|
if (appactive && (HWND)wParam != hWindow) videoUpdatePalette(0,256);
|
2006-04-24 19:04:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_DISPLAYCHANGE:
|
|
|
|
// desktop settings changed so adjust our world-view accordingly
|
|
|
|
desktopxdim = LOWORD(lParam);
|
|
|
|
desktopydim = HIWORD(lParam);
|
|
|
|
desktopbpp = wParam;
|
2018-04-12 21:02:51 +00:00
|
|
|
videoGetModes();
|
2006-04-24 19:04:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_PAINT:
|
|
|
|
repaintneeded=1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// don't draw the frame if fullscreen
|
|
|
|
//case WM_NCPAINT:
|
|
|
|
//if (!fullscreen) break;
|
|
|
|
//return 0;
|
|
|
|
|
|
|
|
case WM_ERASEBKGND:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_MOVE:
|
2010-05-18 00:30:30 +00:00
|
|
|
// windowx = LOWORD(lParam);
|
|
|
|
// windowy = HIWORD(lParam);
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
|
|
|
|
2007-04-22 03:44:54 +00:00
|
|
|
case WM_MOVING:
|
|
|
|
{
|
|
|
|
RECT *RECTYMcRECT = (LPRECT)lParam;
|
|
|
|
|
|
|
|
windowx = RECTYMcRECT->left;
|
|
|
|
windowy = RECTYMcRECT->top;
|
|
|
|
return 0;
|
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
case WM_CLOSE:
|
|
|
|
quitevent = 1;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WM_ENTERMENULOOP:
|
|
|
|
case WM_ENTERSIZEMOVE:
|
2010-05-18 00:30:30 +00:00
|
|
|
AcquireInputDevices(0);
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
|
|
|
case WM_EXITMENULOOP:
|
|
|
|
case WM_EXITSIZEMOVE:
|
2010-05-18 00:30:30 +00:00
|
|
|
AcquireInputDevices(1);
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WM_DESTROY:
|
|
|
|
hWindow = 0;
|
|
|
|
//PostQuitMessage(0); // JBF 20040115: not anymore
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// RegisterWindowClass() -- register the window class
|
|
|
|
//
|
|
|
|
static BOOL RegisterWindowClass(void)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
WNDCLASSEX wcx;
|
|
|
|
|
|
|
|
if (window_class_registered) return FALSE;
|
|
|
|
|
|
|
|
//initprintf("Registering window class\n");
|
|
|
|
|
|
|
|
wcx.cbSize = sizeof(wcx);
|
|
|
|
wcx.style = CS_OWNDC;
|
|
|
|
wcx.lpfnWndProc = WndProcCallback;
|
|
|
|
wcx.cbClsExtra = 0;
|
|
|
|
wcx.cbWndExtra = 0;
|
|
|
|
wcx.hInstance = hInstance;
|
2012-11-15 14:27:57 +00:00
|
|
|
wcx.hIcon = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(100), IMAGE_ICON,
|
2010-05-18 00:30:30 +00:00
|
|
|
GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
|
2006-04-24 19:04:22 +00:00
|
|
|
wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
|
|
|
|
wcx.hbrBackground = (HBRUSH)COLOR_GRAYTEXT;
|
|
|
|
wcx.lpszMenuName = NULL;
|
|
|
|
wcx.lpszClassName = WindowClass;
|
2012-11-15 14:27:57 +00:00
|
|
|
wcx.hIconSm = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(100), IMAGE_ICON,
|
2006-04-24 19:04:22 +00:00
|
|
|
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!RegisterClassEx(&wcx))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
ShowErrorBox("Failed to register window class");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
window_class_registered = TRUE;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|