mirror of
https://github.com/glfw/glfw.git
synced 2026-09-21 08:39:45 +00:00
Initial implementation of experimental gamma ramp API.
This commit is contained in:
@@ -23,6 +23,7 @@ set(libglfw_SOURCES
|
||||
${common_SOURCES}
|
||||
win32_enable.c
|
||||
win32_fullscreen.c
|
||||
win32_gamma.c
|
||||
win32_glext.c
|
||||
win32_init.c
|
||||
win32_joystick.c
|
||||
|
||||
@@ -156,6 +156,8 @@ typedef int (WINAPI * DESCRIBEPIXELFORMAT_T) (HDC,int,UINT,LPPIXELFORMATDESCRIP
|
||||
typedef int (WINAPI * GETPIXELFORMAT_T) (HDC);
|
||||
typedef BOOL (WINAPI * SETPIXELFORMAT_T) (HDC,int,const PIXELFORMATDESCRIPTOR*);
|
||||
typedef BOOL (WINAPI * SWAPBUFFERS_T) (HDC);
|
||||
typedef BOOL (WINAPI * GETDEVICEGAMMARAMP_T) (HDC,PVOID);
|
||||
typedef BOOL (WINAPI * SETDEVICEGAMMARAMP_T) (HDC,PVOID);
|
||||
#endif // _GLFW_NO_DLOAD_GDI32
|
||||
|
||||
// winmm.dll function pointer typedefs
|
||||
@@ -174,12 +176,16 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
|
||||
#define _glfw_GetPixelFormat _glfwLibrary.Win32.gdi.GetPixelFormat
|
||||
#define _glfw_SetPixelFormat _glfwLibrary.Win32.gdi.SetPixelFormat
|
||||
#define _glfw_SwapBuffers _glfwLibrary.Win32.gdi.SwapBuffers
|
||||
#define _glfw_GetDeviceGammaRamp _glfwLibrary.Win32.gdi.GetDeviceGammaRamp
|
||||
#define _glfw_SetDeviceGammaRamp _glfwLibrary.Win32.gdi.SetDeviceGammaRamp
|
||||
#else
|
||||
#define _glfw_ChoosePixelFormat ChoosePixelFormat
|
||||
#define _glfw_DescribePixelFormat DescribePixelFormat
|
||||
#define _glfw_GetPixelFormat GetPixelFormat
|
||||
#define _glfw_SetPixelFormat SetPixelFormat
|
||||
#define _glfw_SwapBuffers SwapBuffers
|
||||
#define _glfw_GetDeviceGammaRamp GetDeviceGammaRamp
|
||||
#define _glfw_SetDeviceGammaRamp SetDeviceGammaRamp
|
||||
#endif // _GLFW_NO_DLOAD_GDI32
|
||||
|
||||
// winmm.dll shortcuts
|
||||
@@ -264,6 +270,7 @@ typedef struct _GLFWlibraryWin32
|
||||
ATOM classAtom; // Window class atom
|
||||
HHOOK keyboardHook; // Keyboard hook handle
|
||||
DWORD foregroundLockTimeout;
|
||||
HDC desktopDC;
|
||||
|
||||
// Default monitor
|
||||
struct {
|
||||
@@ -291,6 +298,8 @@ typedef struct _GLFWlibraryWin32
|
||||
GETPIXELFORMAT_T GetPixelFormat;
|
||||
SETPIXELFORMAT_T SetPixelFormat;
|
||||
SWAPBUFFERS_T SwapBuffers;
|
||||
GETDEVICEGAMMARAMP_T GetDeviceGammaRamp;
|
||||
SETDEVICEGAMMARAMP_T SetDeviceGammaRamp;
|
||||
} gdi;
|
||||
#endif // _GLFW_NO_DLOAD_GDI32
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
//========================================================================
|
||||
// GLFW - An OpenGL framework
|
||||
// Platform: Win32/WGL
|
||||
// API version: 2.7
|
||||
// WWW: http://www.glfw.org/
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2002-2006 Marcus Geelnard
|
||||
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
//************************************************************************
|
||||
//**** GLFW internal functions ****
|
||||
//************************************************************************
|
||||
|
||||
//========================================================================
|
||||
// Save the gamma ramp to our internal copy
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformSaveGammaRamp(int ramp)
|
||||
{
|
||||
if (!_glfwLibrary.gammaSize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_glfw_GetDeviceGammaRamp(_glfwLibrary.Win32.desktopDC,
|
||||
_glfwLibrary.gammaRamp[ramp]);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Restore the gamma ramp to our internal copy of the gamma ramp
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformRestoreGammaRamp(int ramp)
|
||||
{
|
||||
if (!_glfwLibrary.gammaSize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_glfw_SetDeviceGammaRamp(_glfwLibrary.Win32.desktopDC,
|
||||
_glfwLibrary.gammaRamp[ramp]);
|
||||
}
|
||||
+29
-1
@@ -30,6 +30,8 @@
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
// With the Borland C++ compiler, we want to disable FPU exceptions
|
||||
#include <float.h>
|
||||
@@ -59,12 +61,18 @@ static GLboolean initLibraries(void)
|
||||
GetProcAddress(_glfwLibrary.Win32.gdi.instance, "SetPixelFormat");
|
||||
_glfwLibrary.Win32.gdi.SwapBuffers = (SWAPBUFFERS_T)
|
||||
GetProcAddress(_glfwLibrary.Win32.gdi.instance, "SwapBuffers");
|
||||
_glfwLibrary.Win32.gdi.GetDeviceGammaRamp = (GETDEVICEGAMMARAMP_T)
|
||||
GetProcAddress(_glfwLibrary.Win32.gdi.instance, "GetDeviceGammaRamp");
|
||||
_glfwLibrary.Win32.gdi.SetDeviceGammaRamp = (SETDEVICEGAMMARAMP_T)
|
||||
GetProcAddress(_glfwLibrary.Win32.gdi.instance, "SetDeviceGammaRamp");
|
||||
|
||||
if (!_glfwLibrary.Win32.gdi.ChoosePixelFormat ||
|
||||
!_glfwLibrary.Win32.gdi.DescribePixelFormat ||
|
||||
!_glfwLibrary.Win32.gdi.GetPixelFormat ||
|
||||
!_glfwLibrary.Win32.gdi.SetPixelFormat ||
|
||||
!_glfwLibrary.Win32.gdi.SwapBuffers)
|
||||
!_glfwLibrary.Win32.gdi.SwapBuffers ||
|
||||
!_glfwLibrary.Win32.gdi.GetDeviceGammaRamp ||
|
||||
!_glfwLibrary.Win32.gdi.SetDeviceGammaRamp)
|
||||
{
|
||||
return GL_FALSE;
|
||||
}
|
||||
@@ -152,6 +160,19 @@ int _glfwPlatformInit(void)
|
||||
|
||||
_glfwLibrary.Win32.instance = GetModuleHandle(NULL);
|
||||
|
||||
// Initialise the internal gamma ramp
|
||||
_glfwLibrary.gammaSize = 256;
|
||||
_glfwLibrary.gammaRamp[GLFW_GAMMA_ORIG] =
|
||||
malloc(256 * sizeof(unsigned short) * 3);
|
||||
_glfwLibrary.gammaRamp[GLFW_GAMMA_CURR] =
|
||||
malloc(256 * sizeof(unsigned short) * 3);
|
||||
|
||||
// Get the desktop DC
|
||||
_glfwLibrary.Win32.desktopDC = GetDC(GetDesktopWindow());
|
||||
|
||||
// Save the original gamma ramp
|
||||
_glfwPlatformSaveGammaRamp(GLFW_GAMMA_ORIG);
|
||||
|
||||
_glfwInitTimer();
|
||||
|
||||
return GL_TRUE;
|
||||
@@ -164,6 +185,13 @@ int _glfwPlatformInit(void)
|
||||
|
||||
int _glfwPlatformTerminate(void)
|
||||
{
|
||||
// Restore the original gamma ramp
|
||||
_glfwPlatformRestoreGammaRamp(GLFW_GAMMA_ORIG);
|
||||
|
||||
// Free the gamma ramps
|
||||
free(_glfwLibrary.gammaRamp[GLFW_GAMMA_ORIG]);
|
||||
free(_glfwLibrary.gammaRamp[GLFW_GAMMA_CURR]);
|
||||
|
||||
if (_glfwLibrary.Win32.classAtom)
|
||||
{
|
||||
UnregisterClass(_GLFW_WNDCLASSNAME, _glfwLibrary.Win32.instance);
|
||||
|
||||
Reference in New Issue
Block a user