]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_wgl.c
Reworked v_isometric code significantly, it now defaults to a proper isometric view...
[xonotic/darkplaces.git] / vid_wgl.c
index 544d24ba27a6f1395abae691f953a7b9241f0b34..7a4840886f0165fae39591890a582419c42a50a7 100644 (file)
--- a/vid_wgl.c
+++ b/vid_wgl.c
@@ -216,7 +216,7 @@ static HINSTANCE hInstDI;
 
 // forward-referenced functions
 static void IN_StartupMouse (void);
-
+static void AdjustWindowBounds(int fullscreen, int *width, int *height, viddef_mode_t *mode, DWORD WindowStyle, RECT *rect);
 
 //====================================
 
@@ -321,7 +321,7 @@ void VID_Finish (void)
        // without this help
        Sleep(0);
 
-       VID_UpdateGamma(false, 256);
+       VID_UpdateGamma();
 }
 
 //==========================================================================
@@ -429,7 +429,7 @@ ClearAllStates
 */
 static void ClearAllStates (void)
 {
-       Key_ClearStates ();
+       Key_ReleaseAll();
        if (vid_usingmouse)
                mouse_oldbuttonstate = 0;
 }
@@ -498,7 +498,6 @@ void AppActivate(BOOL fActive, BOOL minimize)
                                ChangeDisplaySettings (NULL, CDS_FULLSCREEN);
                        vid_wassuspended = true;
                }
-               VID_RestoreSystemGamma();
        }
 }
 
@@ -567,8 +566,8 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM  wParam, LPARAM lParam)
                        break;
 
                case WM_MOVE:
-                       window_x = (int) LOWORD(lParam);
-                       window_y = (int) HIWORD(lParam);
+                       window_x = (short) LOWORD(lParam);
+                       window_y = (short) HIWORD(lParam);
                        VID_SetMouse(false, false, false);
                        break;
 
@@ -711,32 +710,6 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM  wParam, LPARAM lParam)
        return lRet;
 }
 
-int VID_SetGamma(unsigned short *ramps, int rampsize)
-{
-       if (qwglMakeCurrent)
-       {
-               HDC hdc = GetDC (NULL);
-               int i = SetDeviceGammaRamp(hdc, ramps);
-               ReleaseDC (NULL, hdc);
-               return i; // return success or failure
-       }
-       else
-               return 0;
-}
-
-int VID_GetGamma(unsigned short *ramps, int rampsize)
-{
-       if (qwglMakeCurrent)
-       {
-               HDC hdc = GetDC (NULL);
-               int i = GetDeviceGammaRamp(hdc, ramps);
-               ReleaseDC (NULL, hdc);
-               return i; // return success or failure
-       }
-       else
-               return 0;
-}
-
 static void GL_CloseLibrary(void)
 {
        if (gldll)
@@ -913,7 +886,6 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
        int pixelformat, newpixelformat;
        UINT numpixelformats;
        DWORD WindowStyle, ExWindowStyle;
-       int CenterX, CenterY;
        const char *gldrivername;
        int depth;
        DEVMODE thismode;
@@ -1167,32 +1139,7 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
                ExWindowStyle = 0;
        }
 
-       rect.top = 0;
-       rect.left = 0;
-       rect.right = width;
-       rect.bottom = height;
-       AdjustWindowRectEx(&rect, WindowStyle, false, 0);
-
-       if (fullscreen)
-       {
-               CenterX = 0;
-               CenterY = 0;
-       }
-       else
-       {
-               CenterX = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2;
-               CenterY = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2;
-       }
-       CenterX = max(0, CenterX);
-       CenterY = max(0, CenterY);
-
-       // x and y may be changed by WM_MOVE messages
-       window_x = CenterX;
-       window_y = CenterY;
-       rect.left += CenterX;
-       rect.right += CenterX;
-       rect.top += CenterY;
-       rect.bottom += CenterY;
+       AdjustWindowBounds(fullscreen, &width, &height, mode, WindowStyle, &rect);
 
        pixelformat = 0;
        newpixelformat = 0;
@@ -1350,6 +1297,56 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
        return true;
 }
 
+static void AdjustWindowBounds(int fullscreen, int *width, int *height, viddef_mode_t *mode, DWORD WindowStyle, RECT *rect)
+{
+       int CenterX, CenterY;
+
+       rect->top = 0;
+       rect->left = 0;
+       rect->right = *width;
+       rect->bottom = *height;
+       AdjustWindowRectEx(rect, WindowStyle, false, 0);
+
+       if (fullscreen)
+       {
+               CenterX = 0;
+               CenterY = 0;
+       }
+       else
+       {
+               RECT workArea;
+               SystemParametersInfo(SPI_GETWORKAREA, NULL, &workArea, 0);
+               int workWidth = workArea.right - workArea.left;
+               int workHeight = workArea.bottom - workArea.top;
+
+               // if height/width matches physical screen height/width, adjust it to available desktop size
+               // and allow 2 pixels on top for the title bar so the window can be moved
+               const int titleBarPixels = 2;
+               if (*width == GetSystemMetrics(SM_CXSCREEN) && (*height == GetSystemMetrics(SM_CYSCREEN) || *height == workHeight - titleBarPixels))
+               {
+                       rect->right -= *width - workWidth;
+                       *width = mode->width = workWidth;
+                       rect->bottom -= *height - (workHeight - titleBarPixels);
+                       *height = mode->height = workHeight - titleBarPixels;
+                       CenterX = 0;
+                       CenterY = titleBarPixels;
+               }
+               else
+               {
+                       CenterX = max(0, (workWidth - *width) / 2);
+                       CenterY = max(0, (workHeight - *height) / 2);
+               }
+       }
+
+       // x and y may be changed by WM_MOVE messages
+       window_x = CenterX;
+       window_y = CenterY;
+       rect->left += CenterX;
+       rect->right += CenterX;
+       rect->top += CenterY;
+       rect->bottom += CenterY;
+}
+
 #ifdef SUPPORTD3D
 static D3DADAPTER_IDENTIFIER9 d3d9adapteridentifier;
 
@@ -1365,7 +1362,6 @@ qboolean VID_InitModeDX(viddef_mode_t *mode, int version)
        RECT rect;
        MSG msg;
        DWORD WindowStyle, ExWindowStyle;
-       int CenterX, CenterY;
        int bpp = mode->bitsperpixel;
        int width = mode->width;
        int height = mode->height;
@@ -1390,32 +1386,7 @@ qboolean VID_InitModeDX(viddef_mode_t *mode, int version)
                ExWindowStyle = 0;
        }
 
-       rect.top = 0;
-       rect.left = 0;
-       rect.right = width;
-       rect.bottom = height;
-       AdjustWindowRectEx(&rect, WindowStyle, false, 0);
-
-       if (fullscreen)
-       {
-               CenterX = 0;
-               CenterY = 0;
-       }
-       else
-       {
-               CenterX = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2;
-               CenterY = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2;
-       }
-       CenterX = max(0, CenterX);
-       CenterY = max(0, CenterY);
-
-       // x and y may be changed by WM_MOVE messages
-       window_x = CenterX;
-       window_y = CenterY;
-       rect.left += CenterX;
-       rect.right += CenterX;
-       rect.top += CenterY;
-       rect.bottom += CenterY;
+       AdjustWindowBounds(fullscreen, &width, &height, mode, WindowStyle, &rect);
 
        gl_extensions = "";
        gl_platformextensions = "";
@@ -1525,6 +1496,7 @@ qboolean VID_InitModeDX(viddef_mode_t *mode, int version)
        vid.support.arb_depth_texture = true;
        vid.support.arb_draw_buffers = vid_d3d9caps.NumSimultaneousRTs > 1;
        vid.support.arb_occlusion_query = true; // can't find a cap for this
+       vid.support.arb_query_buffer_object = true;
        vid.support.arb_shadow = true;
        vid.support.arb_texture_compression = true;
        vid.support.arb_texture_cube_map = true;
@@ -1598,7 +1570,6 @@ qboolean VID_InitModeSOFT(viddef_mode_t *mode)
        MSG msg;
        int pixelformat, newpixelformat;
        DWORD WindowStyle, ExWindowStyle;
-       int CenterX, CenterY;
        int depth;
        DEVMODE thismode;
        qboolean foundmode, foundgoodmode;
@@ -1750,32 +1721,7 @@ qboolean VID_InitModeSOFT(viddef_mode_t *mode)
                ExWindowStyle = 0;
        }
 
-       rect.top = 0;
-       rect.left = 0;
-       rect.right = width;
-       rect.bottom = height;
-       AdjustWindowRectEx(&rect, WindowStyle, false, 0);
-
-       if (fullscreen)
-       {
-               CenterX = 0;
-               CenterY = 0;
-       }
-       else
-       {
-               CenterX = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2;
-               CenterY = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2;
-       }
-       CenterX = max(0, CenterX);
-       CenterY = max(0, CenterY);
-
-       // x and y may be changed by WM_MOVE messages
-       window_x = CenterX;
-       window_y = CenterY;
-       rect.left += CenterX;
-       rect.right += CenterX;
-       rect.top += CenterY;
-       rect.bottom += CenterY;
+       AdjustWindowBounds(fullscreen, &width, &height, mode, WindowStyle, &rect);
 
        pixelformat = 0;
        newpixelformat = 0;
@@ -1897,7 +1843,6 @@ void VID_Shutdown (void)
 
        VID_EnableJoystick(false);
        VID_SetMouse(false, false, false);
-       VID_RestoreSystemGamma();
 
        vid_initialized = false;
        isgl = gldll != NULL;