//======================================================================== // GLFW - An OpenGL framework // Platform: Win32/WGL // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard // Copyright (c) 2006-2010 Camilla Berglund // // 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" // With the Borland C++ compiler, we want to disable FPU exceptions #ifdef __BORLANDC__ #include #endif // __BORLANDC__ //======================================================================== // Load necessary libraries (DLLs) //======================================================================== static GLboolean initLibraries(void) { // gdi32.dll (OpenGL pixel format functions & SwapBuffers) #ifndef _GLFW_NO_DLOAD_GDI32 _glfwLibrary.Win32.libs.gdi32 = LoadLibrary("gdi32.dll"); if (_glfwLibrary.Win32.libs.gdi32 != NULL) { _glfwLibrary.Win32.libs.ChoosePixelFormat = (CHOOSEPIXELFORMAT_T) GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "ChoosePixelFormat"); _glfwLibrary.Win32.libs.DescribePixelFormat = (DESCRIBEPIXELFORMAT_T) GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "DescribePixelFormat"); _glfwLibrary.Win32.libs.GetPixelFormat = (GETPIXELFORMAT_T) GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "GetPixelFormat"); _glfwLibrary.Win32.libs.SetPixelFormat = (SETPIXELFORMAT_T) GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "SetPixelFormat"); _glfwLibrary.Win32.libs.SwapBuffers = (SWAPBUFFERS_T) GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "SwapBuffers"); if (_glfwLibrary.Win32.libs.ChoosePixelFormat && _glfwLibrary.Win32.libs.DescribePixelFormat && _glfwLibrary.Win32.libs.GetPixelFormat && _glfwLibrary.Win32.libs.SetPixelFormat && _glfwLibrary.Win32.libs.SwapBuffers) { FreeLibrary(_glfwLibrary.Win32.libs.gdi32); _glfwLibrary.Win32.libs.gdi32 = NULL; return GL_FALSE; } } else return GL_FALSE; #endif // _GLFW_NO_DLOAD_GDI32 // winmm.dll (for joystick and timer support) #ifndef _GLFW_NO_DLOAD_WINMM _glfwLibrary.Win32.libs.winmm = LoadLibrary("winmm.dll"); if (_glfwLibrary.Win32.libs.winmm != NULL) { _glfwLibrary.Win32.libs.joyGetDevCapsA = (JOYGETDEVCAPSA_T) GetProcAddress(_glfwLibrary.Win32.libs.winmm, "joyGetDevCapsA"); _glfwLibrary.Win32.libs.joyGetPos = (JOYGETPOS_T) GetProcAddress(_glfwLibrary.Win32.libs.winmm, "joyGetPos"); _glfwLibrary.Win32.libs.joyGetPosEx = (JOYGETPOSEX_T) GetProcAddress(_glfwLibrary.Win32.libs.winmm, "joyGetPosEx"); _glfwLibrary.Win32.libs.timeGetTime = (TIMEGETTIME_T) GetProcAddress(_glfwLibrary.Win32.libs.winmm, "timeGetTime"); if (_glfwLibrary.Win32.libs.joyGetDevCapsA && _glfwLibrary.Win32.libs.joyGetPos && _glfwLibrary.Win32.libs.joyGetPosEx && _glfwLibrary.Win32.libs.timeGetTime) { FreeLibrary(_glfwLibrary.Win32.libs.winmm); _glfwLibrary.Win32.libs.winmm = NULL; return GL_FALSE; } } else return GL_FALSE; #endif // _GLFW_NO_DLOAD_WINMM return GL_TRUE; } //======================================================================== // Unload used libraries (DLLs) //======================================================================== static void freeLibraries(void) { // gdi32.dll #ifndef _GLFW_NO_DLOAD_GDI32 if (_glfwLibrary.Win32.libs.gdi32 != NULL) { FreeLibrary(_glfwLibrary.Win32.libs.gdi32); _glfwLibrary.Win32.libs.gdi32 = NULL; } #endif // _GLFW_NO_DLOAD_GDI32 // winmm.dll #ifndef _GLFW_NO_DLOAD_WINMM if (_glfwLibrary.Win32.libs.winmm != NULL) { FreeLibrary(_glfwLibrary.Win32.libs.winmm); _glfwLibrary.Win32.libs.winmm = NULL; } #endif // _GLFW_NO_DLOAD_WINMM } //======================================================================== // Terminate GLFW when exiting application //======================================================================== static void glfw_atexit(void) { glfwTerminate(); } ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// //======================================================================== // Initialize various GLFW state //======================================================================== int _glfwPlatformInit(void) { OSVERSIONINFO osi; // To make SetForegroundWindow() work as we want, we need to fiddle // with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early // as possible in the hope of still being the foreground process) SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, &_glfwLibrary.Win32.foregroundLockTimeout, 0); SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0, SPIF_SENDCHANGE); // Check which OS version we are running osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osi); _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_UNKNOWN; if (osi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { if (osi.dwMajorVersion == 4 && osi.dwMinorVersion < 10) _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_95; else if (osi.dwMajorVersion == 4 && osi.dwMinorVersion < 90) _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_98; else if (osi.dwMajorVersion == 4 && osi.dwMinorVersion == 90) _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_ME; else if (osi.dwMajorVersion >= 4) _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_UNKNOWN_9x; } else if (osi.dwPlatformId == VER_PLATFORM_WIN32_NT) { if (osi.dwMajorVersion == 4 && osi.dwMinorVersion == 0) _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_NT4; else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 0) _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_2K; else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 1) _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_XP; else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 2) _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_NET_SERVER; else if (osi.dwMajorVersion >= 5) _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_UNKNOWN_NT; } // Load libraries (DLLs) if (!_glfwInitLibraries()) return GL_FALSE; // With the Borland C++ compiler, we want to disable FPU exceptions // (this is recommended for OpenGL applications under Windows) #ifdef __BORLANDC__ _control87(MCW_EM, MCW_EM); #endif // Retrieve GLFW instance handle _glfwLibrary.Win32.instance = GetModuleHandle(NULL); // System keys are not disabled _glfwLibrary.Win32.keyboardHook = NULL; // Install atexit() routine atexit(glfw_atexit); // Start the timer _glfwInitTimer(); return GL_TRUE; } //======================================================================== // Close window and shut down library //======================================================================== int _glfwPlatformTerminate(void) { // Close OpenGL window glfwCloseWindow(); // Enable system keys again (if they were disabled) glfwEnable(GLFW_SYSTEM_KEYS); // Unload libraries (DLLs) _glfwFreeLibraries(); // Restore FOREGROUNDLOCKTIMEOUT system setting SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) _glfwLibrary.Win32.foregroundLockTimeout, SPIF_SENDCHANGE); return GL_TRUE; }