1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-30 05:58:52 -05:00
glfw/src/win32_init.c

234 lines
7.9 KiB
C
Raw Normal View History

2010-09-07 11:34:51 -04:00
//========================================================================
// GLFW - An OpenGL library
2010-09-07 11:34:51 -04:00
// Platform: Win32/WGL
2010-09-07 11:41:26 -04:00
// API version: 3.0
2010-09-07 11:34:51 -04:00
// 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 <stdlib.h>
2010-09-07 11:34:51 -04:00
#ifdef __BORLANDC__
2010-09-13 17:50:04 -04:00
// With the Borland C++ compiler, we want to disable FPU exceptions
2010-09-07 11:34:51 -04:00
#include <float.h>
#endif // __BORLANDC__
//========================================================================
2010-09-07 11:50:43 -04:00
// Load necessary libraries (DLLs)
2010-09-07 11:34:51 -04:00
//========================================================================
2010-09-10 16:03:36 -04:00
static GLboolean initLibraries(void)
2010-09-07 11:34:51 -04:00
{
#ifndef _GLFW_NO_DLOAD_GDI32
2010-09-13 17:50:04 -04:00
// gdi32.dll (OpenGL pixel format functions & SwapBuffers)
2010-09-13 22:27:02 -04:00
_glfwLibrary.Win32.gdi.instance = LoadLibrary("gdi32.dll");
if (!_glfwLibrary.Win32.gdi.instance)
return GL_FALSE;
_glfwLibrary.Win32.gdi.ChoosePixelFormat = (CHOOSEPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Win32.gdi.instance, "ChoosePixelFormat");
_glfwLibrary.Win32.gdi.DescribePixelFormat = (DESCRIBEPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Win32.gdi.instance, "DescribePixelFormat");
_glfwLibrary.Win32.gdi.GetPixelFormat = (GETPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Win32.gdi.instance, "GetPixelFormat");
_glfwLibrary.Win32.gdi.SetPixelFormat = (SETPIXELFORMAT_T)
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");
2010-09-13 22:27:02 -04:00
if (!_glfwLibrary.Win32.gdi.ChoosePixelFormat ||
!_glfwLibrary.Win32.gdi.DescribePixelFormat ||
!_glfwLibrary.Win32.gdi.GetPixelFormat ||
!_glfwLibrary.Win32.gdi.SetPixelFormat ||
!_glfwLibrary.Win32.gdi.SwapBuffers ||
!_glfwLibrary.Win32.gdi.GetDeviceGammaRamp ||
!_glfwLibrary.Win32.gdi.SetDeviceGammaRamp)
2010-09-07 11:34:51 -04:00
{
return GL_FALSE;
2010-09-13 22:27:02 -04:00
}
2010-09-07 11:34:51 -04:00
#endif // _GLFW_NO_DLOAD_GDI32
#ifndef _GLFW_NO_DLOAD_WINMM
2010-09-13 17:50:04 -04:00
// winmm.dll (for joystick and timer support)
2010-09-13 22:27:02 -04:00
_glfwLibrary.Win32.winmm.instance = LoadLibrary("winmm.dll");
if (!_glfwLibrary.Win32.winmm.instance)
return GL_FALSE;
_glfwLibrary.Win32.winmm.joyGetDevCapsA = (JOYGETDEVCAPSA_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetDevCapsA");
_glfwLibrary.Win32.winmm.joyGetPos = (JOYGETPOS_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetPos");
_glfwLibrary.Win32.winmm.joyGetPosEx = (JOYGETPOSEX_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetPosEx");
_glfwLibrary.Win32.winmm.timeGetTime = (TIMEGETTIME_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "timeGetTime");
if (!_glfwLibrary.Win32.winmm.joyGetDevCapsA ||
!_glfwLibrary.Win32.winmm.joyGetPos ||
!_glfwLibrary.Win32.winmm.joyGetPosEx ||
!_glfwLibrary.Win32.winmm.timeGetTime)
2010-09-07 11:34:51 -04:00
{
return GL_FALSE;
2010-09-13 22:27:02 -04:00
}
2010-09-07 11:34:51 -04:00
#endif // _GLFW_NO_DLOAD_WINMM
return GL_TRUE;
}
//========================================================================
2010-09-07 11:50:43 -04:00
// Unload used libraries (DLLs)
2010-09-07 11:34:51 -04:00
//========================================================================
2010-09-10 16:03:36 -04:00
static void freeLibraries(void)
2010-09-07 11:34:51 -04:00
{
#ifndef _GLFW_NO_DLOAD_GDI32
2010-09-13 22:27:02 -04:00
if (_glfwLibrary.Win32.gdi.instance != NULL)
2010-09-07 11:34:51 -04:00
{
2010-09-13 22:27:02 -04:00
FreeLibrary(_glfwLibrary.Win32.gdi.instance);
_glfwLibrary.Win32.gdi.instance = NULL;
2010-09-07 11:34:51 -04:00
}
#endif // _GLFW_NO_DLOAD_GDI32
#ifndef _GLFW_NO_DLOAD_WINMM
2010-09-13 22:30:18 -04:00
if (_glfwLibrary.Win32.winmm.instance != NULL)
2010-09-07 11:34:51 -04:00
{
2010-09-13 22:30:18 -04:00
FreeLibrary(_glfwLibrary.Win32.winmm.instance);
_glfwLibrary.Win32.winmm.instance = NULL;
2010-09-07 11:34:51 -04:00
}
#endif // _GLFW_NO_DLOAD_WINMM
}
2010-09-10 16:03:36 -04:00
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
2010-09-07 11:34:51 -04:00
//========================================================================
2010-09-07 11:50:43 -04:00
// Initialize various GLFW state
2010-09-07 11:34:51 -04:00
//========================================================================
2010-09-10 16:03:36 -04:00
int _glfwPlatformInit(void)
2010-09-07 11:34:51 -04:00
{
2010-09-13 17:50:04 -04:00
// To make SetForegroundWindow work as we want, we need to fiddle
2010-09-07 11:34:51 -04:00
// with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early
// as possible in the hope of still being the foreground process)
2010-09-10 16:03:36 -04:00
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0,
2010-09-12 10:26:00 -04:00
&_glfwLibrary.Win32.foregroundLockTimeout, 0);
2010-09-10 16:03:36 -04:00
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0,
SPIF_SENDCHANGE);
2010-09-07 11:34:51 -04:00
2010-09-13 19:05:03 -04:00
if (!initLibraries())
2010-09-07 11:34:51 -04:00
return GL_FALSE;
2010-09-13 17:50:04 -04:00
#ifdef __BORLANDC__
2010-09-07 11:34:51 -04:00
// With the Borland C++ compiler, we want to disable FPU exceptions
// (this is recommended for OpenGL applications under Windows)
2010-09-10 16:03:36 -04:00
_control87(MCW_EM, MCW_EM);
2010-09-07 11:34:51 -04:00
#endif
2010-09-12 10:26:00 -04:00
_glfwLibrary.Win32.instance = GetModuleHandle(NULL);
2010-09-07 11:34:51 -04:00
// Save the original gamma ramp
_glfwLibrary.originalRampSize = 256;
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp;
2010-09-07 11:34:51 -04:00
_glfwInitTimer();
return GL_TRUE;
}
//========================================================================
// Close window and shut down library
//========================================================================
2010-09-10 16:03:36 -04:00
int _glfwPlatformTerminate(void)
2010-09-07 11:34:51 -04:00
{
// Restore the original gamma ramp
_glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp);
2010-09-13 20:17:18 -04:00
if (_glfwLibrary.Win32.classAtom)
{
UnregisterClass(_GLFW_WNDCLASSNAME, _glfwLibrary.Win32.instance);
_glfwLibrary.Win32.classAtom = 0;
}
2010-09-13 17:50:04 -04:00
// TODO: Remove keyboard hook
2010-09-07 11:34:51 -04:00
2010-09-13 19:05:03 -04:00
freeLibraries();
2010-09-07 11:34:51 -04:00
2010-09-13 17:50:04 -04:00
// Restore previous FOREGROUNDLOCKTIMEOUT system setting
2010-09-10 16:03:36 -04:00
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
2010-09-12 10:26:00 -04:00
(LPVOID) _glfwLibrary.Win32.foregroundLockTimeout,
2010-09-10 16:03:36 -04:00
SPIF_SENDCHANGE);
2010-09-07 11:34:51 -04:00
return GL_TRUE;
}
2010-09-13 19:05:03 -04:00
//========================================================================
// Get the GLFW version string
//========================================================================
const char* _glfwPlatformGetVersionString(void)
{
const char* version = _GLFW_VERSION_FULL
2010-09-13 19:05:03 -04:00
#if defined(__MINGW32__)
" MinGW"
#elif defined(__CYGWIN__)
" Cygwin"
#elif defined(_MSC_VER)
2010-09-20 15:03:00 -04:00
" Visual C++ "
2010-09-13 19:05:03 -04:00
#elif defined(__BORLANDC__)
" Borland C"
#else
" (unknown compiler)"
#endif
#if defined(GLFW_BUILD_DLL)
" DLL"
#endif
#if !defined(_GLFW_NO_DLOAD_GDI32)
" load(gdi32)"
#endif
#if !defined(_GLFW_NO_DLOAD_WINMM)
" load(winmm)"
#endif
;
return version;
}