Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-// gl_vidnt.c -- NT GL vid component
+// vid_wgl.c -- NT GL vid component
-// we don't need a very new dinput
-#define DIRECTINPUT_VERSION 0x0300
+#ifdef SUPPORTDIRECTX
+// Include DX libs
+#pragma comment(lib, "dinput8.lib")
+#pragma comment(lib, "dxguid.lib")
+#ifndef DIRECTINPUT_VERSION
+# define DIRECTINPUT_VERSION 0x0500 /* Version 5.0 */
+#endif
+#endif
#include "quakedef.h"
#include <windows.h>
static qboolean vid_initialized = false;
static qboolean vid_wassuspended = false;
static qboolean vid_usingmouse = false;
+static qboolean vid_usinghidecursor = false;
static qboolean vid_usingvsync = false;
static qboolean vid_usevsync = false;
static HICON hIcon;
void VID_Finish (void)
{
- qboolean vid_usemouse;
-
- vid_usevsync = vid_vsync.integer && !cls.timedemo && gl_videosyncavailable;
- if (vid_usingvsync != vid_usevsync && gl_videosyncavailable)
+ vid_usevsync = vid_vsync.integer && !cls.timedemo && qwglSwapIntervalEXT;
+ if (vid_usingvsync != vid_usevsync)
{
vid_usingvsync = vid_usevsync;
qwglSwapIntervalEXT (vid_usevsync);
}
- if (r_render.integer && !vid_hidden)
+ if (!vid_hidden)
{
CHECKGLERROR
- if (r_speeds.integer || gl_finish.integer)
+ if (r_speeds.integer == 2 || gl_finish.integer)
{
qglFinish();CHECKGLERROR
}
{
static qboolean sound_active = false; // initially blocked by Sys_InitConsole()
- vid_activewindow = fActive;
- vid_hidden = minimize;
+ vid_activewindow = fActive != FALSE;
+ vid_hidden = minimize != FALSE;
// enable/disable sound on focus gain/loss
- if (!vid_hidden && (vid_activewindow || !snd_mutewhenidle.integer))
+ if ((!vid_hidden && vid_activewindow) || !snd_mutewhenidle.integer)
{
if (!sound_active)
{
if (!fActive)
{
- VID_GrabMouse(false);
+ VID_SetMouse(false, false, false);
if (vid_isfullscreen)
{
ChangeDisplaySettings (NULL, 0);
{
LONG lRet = 1;
int fActive, fMinimized, temp;
- char state[256];
- char asciichar[4];
+ unsigned char state[256];
+ unsigned char asciichar[4];
int vkey;
int charlength;
qboolean down = false;
case WM_MOVE:
window_x = (int) LOWORD(lParam);
window_y = (int) HIWORD(lParam);
- VID_GrabMouse(false);
+ VID_SetMouse(false, false, false);
break;
case WM_KEYDOWN:
temp |= 512;
#ifdef SUPPORTDIRECTX
- if (vid_usingmouse && !dinput_acquired)
-#else
- if (vid_usingmouse)
+ if (!dinput_acquired)
#endif
{
// perform button actions
IN_Init();
}
-int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrate, int stereobuffer, int samples)
+qboolean VID_InitMode(viddef_mode_t *mode)
{
int i;
HDC hdc;
};
int windowpass;
int pixelformat, newpixelformat;
- int numpixelformats;
+ UINT numpixelformats;
DWORD WindowStyle, ExWindowStyle;
int CenterX, CenterY;
const char *gldrivername;
float *af;
int attribs[128];
float attribsf[16];
+ int bpp = mode->bitsperpixel;
+ int width = mode->width;
+ int height = mode->height;
+ int refreshrate = (int)floor(mode->refreshrate+0.5);
+ int stereobuffer = mode->stereobuffer;
+ int samples = mode->samples;
+ int fullscreen = mode->fullscreen;
if (vid_initialized)
Sys_Error("VID_InitMode called when video is already initialised");
Con_DPrintf("enumerating modes yielded a bogus item... please debug this\n");
continue;
}
- if(developer.integer >= 100)
- Con_Printf("Found mode %dx%dx%dbpp %dHz... ", (int)thismode.dmPelsWidth, (int)thismode.dmPelsHeight, (int)thismode.dmBitsPerPel, (int)thismode.dmDisplayFrequency);
+ if(developer_extra.integer)
+ Con_DPrintf("Found mode %dx%dx%dbpp %dHz... ", (int)thismode.dmPelsWidth, (int)thismode.dmPelsHeight, (int)thismode.dmBitsPerPel, (int)thismode.dmDisplayFrequency);
if(thismode.dmBitsPerPel != (DWORD)bpp)
{
- if(developer.integer >= 100)
- Con_Printf("wrong bpp\n");
+ if(developer_extra.integer)
+ Con_DPrintf("wrong bpp\n");
continue;
}
if(thismode.dmPelsWidth != (DWORD)width)
{
- if(developer.integer >= 100)
- Con_Printf("wrong width\n");
+ if(developer_extra.integer)
+ Con_DPrintf("wrong width\n");
continue;
}
if(thismode.dmPelsHeight != (DWORD)height)
{
- if(developer.integer >= 100)
- Con_Printf("wrong height\n");
+ if(developer_extra.integer)
+ Con_DPrintf("wrong height\n");
continue;
}
// if we have a good mode, make sure this mode is better than the previous one, and allowed by the refreshrate
if(thismode.dmDisplayFrequency > (DWORD)refreshrate)
{
- if(developer.integer >= 100)
- Con_Printf("too high refresh rate\n");
+ if(developer_extra.integer)
+ Con_DPrintf("too high refresh rate\n");
continue;
}
else if(thismode.dmDisplayFrequency <= gdevmode.dmDisplayFrequency)
{
- if(developer.integer >= 100)
- Con_Printf("doesn't beat previous best match (too low)\n");
+ if(developer_extra.integer)
+ Con_DPrintf("doesn't beat previous best match (too low)\n");
continue;
}
}
// we do have one, but it isn't good... make sure it has a lower frequency than the previous one
if(thismode.dmDisplayFrequency >= gdevmode.dmDisplayFrequency)
{
- if(developer.integer >= 100)
- Con_Printf("doesn't beat previous best match (too high)\n");
+ if(developer_extra.integer)
+ Con_DPrintf("doesn't beat previous best match (too high)\n");
continue;
}
}
foundgoodmode = true;
else
{
- if(developer.integer >= 100)
- Con_Printf("(out of range)\n");
+ if(developer_extra.integer)
+ Con_DPrintf("(out of range)\n");
}
foundmode = true;
- if(developer.integer >= 100)
- Con_Printf("accepted\n");
+ if(developer_extra.integer)
+ Con_DPrintf("accepted\n");
}
}
mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
if (!mainwindow)
{
- Con_Printf("CreateWindowEx(%d, %s, %s, %d, %d, %d, %d, %d, %p, %p, %d, %p) failed\n", (int)ExWindowStyle, "DarkPlacesWindowClass", gamename, (int)WindowStyle, (int)(rect.left), (int)(rect.top), (int)(rect.right - rect.left), (int)(rect.bottom - rect.top), NULL, NULL, (int)global_hInstance, NULL);
+ Con_Printf("CreateWindowEx(%d, %s, %s, %d, %d, %d, %d, %d, %p, %p, %p, %p) failed\n", (int)ExWindowStyle, "DarkPlacesWindowClass", gamename, (int)WindowStyle, (int)(rect.left), (int)(rect.top), (int)(rect.right - rect.left), (int)(rect.bottom - rect.top), NULL, NULL, global_hInstance, NULL);
VID_Shutdown();
return false;
}
if (!pixelformat)
{
VID_Shutdown();
- Con_Printf("ChoosePixelFormat(%d, %p) failed\n", (int)baseDC, &pfd);
+ Con_Printf("ChoosePixelFormat(%p, %p) failed\n", baseDC, &pfd);
return false;
}
if (SetPixelFormat(baseDC, pixelformat, &pfd) == false)
{
VID_Shutdown();
- Con_Printf("SetPixelFormat(%d, %d, %p) failed\n", (int)baseDC, pixelformat, &pfd);
+ Con_Printf("SetPixelFormat(%p, %d, %p) failed\n", baseDC, pixelformat, &pfd);
return false;
}
if (!qwglMakeCurrent(baseDC, baseRC))
{
VID_Shutdown();
- Con_Printf("wglMakeCurrent(%d, %d) failed\n", (int)baseDC, (int)baseRC);
+ Con_Printf("wglMakeCurrent(%p, %p) failed\n", baseDC, baseRC);
return false;
}
// fix the leftover Alt from any Alt-Tab or the like that switched us away
ClearAllStates ();
- gl_videosyncavailable = false;
-
// COMMANDLINEOPTION: Windows WGL: -novideosync disables WGL_EXT_swap_control
- gl_videosyncavailable = GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, "-novideosync", false);
+ GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, "-novideosync", false);
GL_Init ();
//vid_menudrawfn = VID_MenuDraw;
//vid_menukeyfn = VID_MenuKey;
vid_usingmouse = false;
+ vid_usinghidecursor = false;
vid_usingvsync = false;
vid_hidden = false;
vid_initialized = true;
IN_StartupMouse ();
IN_StartupJoystick ();
- if (gl_videosyncavailable)
+ if (qwglSwapIntervalEXT)
{
- vid_usevsync = vid_vsync.integer;
- vid_usingvsync = vid_vsync.integer;
+ vid_usevsync = vid_vsync.integer != 0;
+ vid_usingvsync = vid_vsync.integer != 0;
qwglSwapIntervalEXT (vid_usevsync);
}
if(vid_initialized == false)
return;
- VID_GrabMouse(false);
+ VID_SetMouse(false, false, false);
VID_RestoreSystemGamma();
vid_initialized = false;
vid_isfullscreen = false;
}
-void VID_GrabMouse(qboolean grab)
+void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor)
{
static qboolean restore_spi;
static int originalmouseparms[3];
if (!mouseinitialized)
return;
- if (grab)
+ if (relative)
{
if (!vid_usingmouse)
{
newmouseparms[0] = 0; // threshold to double movement (only if accel level is >= 1)
newmouseparms[1] = 0; // threshold to quadruple movement (only if accel level is >= 2)
newmouseparms[2] = 0; // maximum level of acceleration (0 = off)
- restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
+ restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0) != FALSE;
}
else
restore_spi = false;
SetCapture (mainwindow);
ClipCursor (&window_rect);
}
- ShowCursor (false);
}
}
else
ClipCursor (NULL);
ReleaseCapture ();
}
- ShowCursor (true);
}
}
+
+ if (vid_usinghidecursor != hidecursor)
+ {
+ vid_usinghidecursor = hidecursor;
+ ShowCursor (!hidecursor);
+ }
}
if (!pDirectInputCreate)
{
- pDirectInputCreate = (void *)GetProcAddress(hInstDI,"DirectInputCreateA");
+ pDirectInputCreate = (HRESULT (__stdcall *)(HINSTANCE,DWORD,LPDIRECTINPUT *,LPUNKNOWN))GetProcAddress(hInstDI,"DirectInputCreateA");
if (!pDirectInputCreate)
{
}
// obtain an interface to the system mouse device.
+#ifdef __cplusplus
+ hr = IDirectInput_CreateDevice(g_pdi, GUID_SysMouse, &g_pMouse, NULL);
+#else
hr = IDirectInput_CreateDevice(g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
+#endif
if (FAILED(hr))
{
// save the joystick's number of buttons and POV status
joy_numbuttons = jc.wNumButtons;
- joy_haspov = jc.wCaps & JOYCAPS_HASPOV;
+ joy_haspov = (jc.wCaps & JOYCAPS_HASPOV) != 0;
// old button and POV states default to no buttons pressed
joy_oldbuttonstate = joy_oldpovstate = 0;
g_pdi = NULL;
#endif
}
+
+size_t VID_ListModes(vid_mode_t *modes, size_t maxcount)
+{
+ int i;
+ size_t k;
+ DEVMODE thismode;
+
+ thismode.dmSize = sizeof(thismode);
+ thismode.dmDriverExtra = 0;
+ k = 0;
+ for(i = 0; EnumDisplaySettings(NULL, i, &thismode); ++i)
+ {
+ if(~thismode.dmFields & (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY))
+ {
+ Con_DPrintf("enumerating modes yielded a bogus item... please debug this\n");
+ continue;
+ }
+ if(k >= maxcount)
+ break;
+ modes[k].width = thismode.dmPelsWidth;
+ modes[k].height = thismode.dmPelsHeight;
+ modes[k].bpp = thismode.dmBitsPerPel;
+ modes[k].refreshrate = thismode.dmDisplayFrequency;
+ modes[k].pixelheight_num = 1;
+ modes[k].pixelheight_denom = 1; // Win32 apparently does not provide this (FIXME)
+ ++k;
+ }
+ return k;
+}