X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=vid_wgl.c;h=7c7a49e4410669b77be5f607d19283ac5d51413a;hb=0dc77d61cf349a3fbe2994cce57f07faa99aab27;hp=0adee1c6c485435294a29aa1f71e51fd0923d8de;hpb=6f079ecb90e1e6b7597d4da1a98f95c5822aad8d;p=xonotic%2Fdarkplaces.git diff --git a/vid_wgl.c b/vid_wgl.c index 0adee1c6..7c7a49e4 100644 --- a/vid_wgl.c +++ b/vid_wgl.c @@ -19,14 +19,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // gl_vidnt.c -- NT GL vid component +// we don't need a very new dinput +#define DIRECTINPUT_VERSION 0x0300 + #include "quakedef.h" #include +#include #include #include "resource.h" #include +#include -extern void S_BlockSound (void); -extern void S_UnblockSound (void); extern HINSTANCE global_hInstance; @@ -37,6 +40,8 @@ extern HINSTANCE global_hInstance; // Tell startup code that we have a client int cl_available = true; +qboolean vid_supportrefreshrate = true; + static int (WINAPI *qwglChoosePixelFormat)(HDC, CONST PIXELFORMATDESCRIPTOR *); static int (WINAPI *qwglDescribePixelFormat)(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR); //static int (WINAPI *qwglGetPixelFormat)(HDC); @@ -110,8 +115,6 @@ static qboolean dinput; // input code -#include - #define DINPUT_BUFFERSIZE 16 #define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d) @@ -141,11 +144,7 @@ static HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion, LP static int mouse_buttons; static int mouse_oldbuttonstate; -static qboolean restore_spi; -static int originalmouseparms[3], newmouseparms[3] = {0, 0, 1}; - static unsigned int uiWheelMessage; -static qboolean mouseparmsvalid; static qboolean dinput_acquired; static unsigned int mstate_di; @@ -181,25 +180,25 @@ static PDWORD pdwRawValue[JOY_MAX_AXES]; // each time. this avoids any problems with getting back to a default usage // or when changing from one controller to another. this way at least something // works. -static cvar_t in_joystick = {CVAR_SAVE, "joystick","0"}; -static cvar_t joy_name = {0, "joyname", "joystick"}; -static cvar_t joy_advanced = {0, "joyadvanced", "0"}; -static cvar_t joy_advaxisx = {0, "joyadvaxisx", "0"}; -static cvar_t joy_advaxisy = {0, "joyadvaxisy", "0"}; -static cvar_t joy_advaxisz = {0, "joyadvaxisz", "0"}; -static cvar_t joy_advaxisr = {0, "joyadvaxisr", "0"}; -static cvar_t joy_advaxisu = {0, "joyadvaxisu", "0"}; -static cvar_t joy_advaxisv = {0, "joyadvaxisv", "0"}; -static cvar_t joy_forwardthreshold = {0, "joyforwardthreshold", "0.15"}; -static cvar_t joy_sidethreshold = {0, "joysidethreshold", "0.15"}; -static cvar_t joy_pitchthreshold = {0, "joypitchthreshold", "0.15"}; -static cvar_t joy_yawthreshold = {0, "joyyawthreshold", "0.15"}; -static cvar_t joy_forwardsensitivity = {0, "joyforwardsensitivity", "-1.0"}; -static cvar_t joy_sidesensitivity = {0, "joysidesensitivity", "-1.0"}; -static cvar_t joy_pitchsensitivity = {0, "joypitchsensitivity", "1.0"}; -static cvar_t joy_yawsensitivity = {0, "joyyawsensitivity", "-1.0"}; -static cvar_t joy_wwhack1 = {0, "joywwhack1", "0.0"}; -static cvar_t joy_wwhack2 = {0, "joywwhack2", "0.0"}; +static cvar_t in_joystick = {CVAR_SAVE, "joystick","0", "enables joysticks"}; +static cvar_t joy_name = {0, "joyname", "joystick", "name of joystick to use (informational only, used only by joyadvanced 1 mode)"}; +static cvar_t joy_advanced = {0, "joyadvanced", "0", "use more than 2 axis joysticks (configuring this is very technical)"}; +static cvar_t joy_advaxisx = {0, "joyadvaxisx", "0", "axis mapping for joyadvanced 1 mode"}; +static cvar_t joy_advaxisy = {0, "joyadvaxisy", "0", "axis mapping for joyadvanced 1 mode"}; +static cvar_t joy_advaxisz = {0, "joyadvaxisz", "0", "axis mapping for joyadvanced 1 mode"}; +static cvar_t joy_advaxisr = {0, "joyadvaxisr", "0", "axis mapping for joyadvanced 1 mode"}; +static cvar_t joy_advaxisu = {0, "joyadvaxisu", "0", "axis mapping for joyadvanced 1 mode"}; +static cvar_t joy_advaxisv = {0, "joyadvaxisv", "0", "axis mapping for joyadvanced 1 mode"}; +static cvar_t joy_forwardthreshold = {0, "joyforwardthreshold", "0.15", "minimum joystick movement necessary to move forward"}; +static cvar_t joy_sidethreshold = {0, "joysidethreshold", "0.15", "minimum joystick movement necessary to move sideways (strafing)"}; +static cvar_t joy_pitchthreshold = {0, "joypitchthreshold", "0.15", "minimum joystick movement necessary to look up/down"}; +static cvar_t joy_yawthreshold = {0, "joyyawthreshold", "0.15", "minimum joystick movement necessary to turn left/right"}; +static cvar_t joy_forwardsensitivity = {0, "joyforwardsensitivity", "-1.0", "how fast the joystick moves forward"}; +static cvar_t joy_sidesensitivity = {0, "joysidesensitivity", "-1.0", "how fast the joystick moves sideways (strafing)"}; +static cvar_t joy_pitchsensitivity = {0, "joypitchsensitivity", "1.0", "how fast the joystick looks up/down"}; +static cvar_t joy_yawsensitivity = {0, "joyyawsensitivity", "-1.0", "how fast the joystick turns left/right"}; +static cvar_t joy_wwhack1 = {0, "joywwhack1", "0.0", "special hack for wingman warrior"}; +static cvar_t joy_wwhack2 = {0, "joywwhack2", "0.0", "special hack for wingman warrior"}; static qboolean joy_avail, joy_advancedinit, joy_haspov; static DWORD joy_oldbuttonstate, joy_oldpovstate; @@ -257,7 +256,7 @@ static void IN_StartupMouse (void); //==================================== -void VID_Finish (void) +void VID_Finish (qboolean allowmousegrab) { qboolean vid_usemouse; @@ -270,7 +269,7 @@ void VID_Finish (void) // handle the mouse state when windowed if that's changed vid_usemouse = false; - if (vid_mouse.integer && !key_consoleactive && !cls.demoplayback) + if (allowmousegrab && vid_mouse.integer && !key_consoleactive && (key_dest != key_game || !cls.demoplayback)) vid_usemouse = true; if (vid_isfullscreen) vid_usemouse = true; @@ -280,10 +279,15 @@ void VID_Finish (void) if (r_render.integer && !vid_hidden) { + CHECKGLERROR if (r_speeds.integer || gl_finish.integer) - qglFinish(); + { + qglFinish();CHECKGLERROR + } SwapBuffers(baseDC); } + + VID_UpdateGamma(false, 256); } //========================================================================== @@ -291,7 +295,7 @@ void VID_Finish (void) -static qbyte scantokey[128] = +static unsigned char scantokey[128] = { // 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 ,27 ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,K_BACKSPACE,9 ,//0 @@ -404,7 +408,7 @@ void AppActivate(BOOL fActive, BOOL minimize) * ****************************************************************************/ { - static BOOL sound_active; + static qboolean sound_active = false; // initially blocked by Sys_InitConsole() vid_activewindow = fActive; vid_hidden = minimize; @@ -457,7 +461,7 @@ void Sys_SendKeyEvents (void) while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!GetMessage (&msg, NULL, 0, 0)) - Sys_Quit (); + Sys_Quit (1); TranslateMessage (&msg); DispatchMessage (&msg); @@ -466,6 +470,26 @@ void Sys_SendKeyEvents (void) LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); +static keynum_t buttonremap[16] = +{ + K_MOUSE1, + K_MOUSE2, + K_MOUSE3, + K_MOUSE4, + K_MOUSE5, + K_MOUSE6, + K_MOUSE7, + K_MOUSE8, + K_MOUSE9, + K_MOUSE10, + K_MOUSE11, + K_MOUSE12, + K_MOUSE13, + K_MOUSE14, + K_MOUSE15, + K_MOUSE16, +}; + /* main window procedure */ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { @@ -564,9 +588,9 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { // perform button actions int i; - for (i=0 ; i= 32) @@ -748,6 +772,9 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp) pfd.cAlphaBits = 0; } + if (stereobuffer) + pfd.dwFlags |= PFD_STEREO; + gldrivername = "opengl32.dll"; // COMMANDLINEOPTION: Windows WGL: -gl_driver selects a GL driver library, default is opengl32.dll, useful only for 3dfxogl.dll or 3dfxvgl.dll, if you don't know what this is for, you don't need it i = COM_CheckParm("-gl_driver"); @@ -764,10 +791,11 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp) vid_isfullscreen = false; if (fullscreen) { - gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; + gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY; gdevmode.dmBitsPerPel = bpp; gdevmode.dmPelsWidth = width; gdevmode.dmPelsHeight = height; + gdevmode.dmDisplayFrequency = refreshrate; gdevmode.dmSize = sizeof (gdevmode); if (ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { @@ -833,7 +861,7 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp) 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", ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL); + 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); VID_Shutdown(); return false; } @@ -874,14 +902,14 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp) if ((pixelformat = ChoosePixelFormat(baseDC, &pfd)) == 0) { VID_Shutdown(); - Con_Printf("ChoosePixelFormat(%d, %p) failed\n", baseDC, &pfd); + Con_Printf("ChoosePixelFormat(%d, %p) failed\n", (int)baseDC, &pfd); return false; } if (SetPixelFormat(baseDC, pixelformat, &pfd) == false) { VID_Shutdown(); - Con_Printf("SetPixelFormat(%d, %d, %p) failed\n", baseDC, pixelformat, &pfd); + Con_Printf("SetPixelFormat(%d, %d, %p) failed\n", (int)baseDC, pixelformat, &pfd); return false; } @@ -902,18 +930,18 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp) if (!qwglMakeCurrent(baseDC, baseRC)) { VID_Shutdown(); - Con_Printf("wglMakeCurrent(%d, %d) failed\n", baseDC, baseRC); + Con_Printf("wglMakeCurrent(%d, %d) failed\n", (int)baseDC, (int)baseRC); return false; } - qglGetString = GL_GetProcAddress("glGetString"); - qwglGetExtensionsStringARB = GL_GetProcAddress("wglGetExtensionsStringARB"); - if (qglGetString == NULL) + if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL) { VID_Shutdown(); Con_Print("glGetString not found\n"); return false; } + if ((qwglGetExtensionsStringARB = (const char *(WINAPI *)(HDC hdc))GL_GetProcAddress("wglGetExtensionsStringARB")) == NULL) + Con_Print("wglGetExtensionsStringARB not found\n"); gl_renderer = qglGetString(GL_RENDERER); gl_vendor = qglGetString(GL_VENDOR); gl_version = qglGetString(GL_VERSION); @@ -951,6 +979,13 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp) IN_StartupMouse (); IN_StartupJoystick (); + if (gl_videosyncavailable) + { + vid_usevsync = vid_vsync.integer; + vid_usingvsync = vid_vsync.integer; + qwglSwapIntervalEXT (vid_usevsync); + } + return true; } @@ -983,6 +1018,9 @@ void VID_Shutdown (void) static void IN_Activate (qboolean grab) { + static qboolean restore_spi; + static int originalmouseparms[3]; + if (!mouseinitialized) return; @@ -1004,9 +1042,21 @@ static void IN_Activate (qboolean grab) window_rect.top = window_y; window_rect.right = window_x + vid.width; window_rect.bottom = window_y + vid.height; - if (mouseparmsvalid) + + // change mouse settings to turn off acceleration +// COMMANDLINEOPTION: Windows GDI Input: -noforcemparms disables setting of mouse parameters (not used with -dinput, windows only) + if (!COM_CheckParm ("-noforcemparms") && SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0)) + { + int newmouseparms[3]; + 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); + } + else + restore_spi = false; SetCursorPos ((window_x + vid.width / 2), (window_y + vid.height / 2)); + SetCapture (mainwindow); ClipCursor (&window_rect); } @@ -1026,8 +1076,10 @@ static void IN_Activate (qboolean grab) } else { + // restore system mouseparms if we changed them if (restore_spi) SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0); + restore_spi = false; ClipCursor (NULL); ReleaseCapture (); } @@ -1135,7 +1187,7 @@ IN_StartupMouse */ static void IN_StartupMouse (void) { - if (COM_CheckParm ("-nomouse") || COM_CheckParm("-safe")) + if (COM_CheckParm ("-nomouse")) return; mouseinitialized = true; @@ -1149,30 +1201,6 @@ static void IN_StartupMouse (void) else Con_Print("DirectInput not initialized\n"); - mouseparmsvalid = SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0); - - if (mouseparmsvalid) - { -// COMMANDLINEOPTION: Windows GDI Input: -noforcemspd disables setting of mouse speed (not used with -dinput, windows only) - if ( COM_CheckParm ("-noforcemspd") ) - newmouseparms[2] = originalmouseparms[2]; - -// COMMANDLINEOPTION: Windows GDI Input: -noforcemaccel disables setting of mouse acceleration (not used with -dinput, windows only) - if ( COM_CheckParm ("-noforcemaccel") ) - { - newmouseparms[0] = originalmouseparms[0]; - newmouseparms[1] = originalmouseparms[1]; - } - -// COMMANDLINEOPTION: Windows GDI Input: -noforcemparms disables setting of mouse parameters (not used with -dinput, windows only) - if ( COM_CheckParm ("-noforcemparms") ) - { - newmouseparms[0] = originalmouseparms[0]; - newmouseparms[1] = originalmouseparms[1]; - newmouseparms[2] = originalmouseparms[2]; - } - } - mouse_buttons = 10; } @@ -1255,9 +1283,9 @@ static void IN_MouseMove (void) } // perform button actions - for (i=0 ; i