2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
2011-03-06 00:46:39 +00:00
|
|
|
// GLFW - An OpenGL library
|
2010-09-07 15:34:51 +00:00
|
|
|
// Platform: Win32/WGL
|
2010-09-07 15:41:26 +00:00
|
|
|
// API version: 3.0
|
2010-09-07 15:34:51 +00: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"
|
|
|
|
|
2010-10-13 02:04:43 +00:00
|
|
|
#include <stdlib.h>
|
2012-08-14 11:51:39 +00:00
|
|
|
#include <malloc.h>
|
2010-10-13 02:04:43 +00:00
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
#ifdef __BORLANDC__
|
2010-09-13 21:50:04 +00:00
|
|
|
// With the Borland C++ compiler, we want to disable FPU exceptions
|
2010-09-07 15:34:51 +00:00
|
|
|
#include <float.h>
|
|
|
|
#endif // __BORLANDC__
|
|
|
|
|
|
|
|
|
2012-09-12 19:23:04 +00:00
|
|
|
//========================================================================
|
|
|
|
// GLFW DLL entry point
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
#if defined(_GLFW_BUILD_DLL)
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif // _GLFW_BUILD_DLL
|
|
|
|
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Load necessary libraries (DLLs)
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
static GLboolean initLibraries(void)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
#ifndef _GLFW_NO_DLOAD_WINMM
|
2010-09-13 21:50:04 +00:00
|
|
|
// winmm.dll (for joystick and timer support)
|
|
|
|
|
2012-02-03 19:34:24 +00:00
|
|
|
_glfwLibrary.Win32.winmm.instance = LoadLibrary(L"winmm.dll");
|
2010-09-14 02:27:02 +00:00
|
|
|
if (!_glfwLibrary.Win32.winmm.instance)
|
|
|
|
return GL_FALSE;
|
|
|
|
|
2012-02-03 19:34:24 +00:00
|
|
|
_glfwLibrary.Win32.winmm.joyGetDevCaps = (JOYGETDEVCAPS_T)
|
|
|
|
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetDevCapsW");
|
2010-09-14 02:27:02 +00:00
|
|
|
_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");
|
|
|
|
|
2012-02-03 19:34:24 +00:00
|
|
|
if (!_glfwLibrary.Win32.winmm.joyGetDevCaps ||
|
2010-09-14 02:27:02 +00:00
|
|
|
!_glfwLibrary.Win32.winmm.joyGetPos ||
|
|
|
|
!_glfwLibrary.Win32.winmm.joyGetPosEx ||
|
|
|
|
!_glfwLibrary.Win32.winmm.timeGetTime)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
return GL_FALSE;
|
2010-09-14 02:27:02 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
#endif // _GLFW_NO_DLOAD_WINMM
|
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Unload used libraries (DLLs)
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
static void freeLibraries(void)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
#ifndef _GLFW_NO_DLOAD_WINMM
|
2010-09-14 02:30:18 +00:00
|
|
|
if (_glfwLibrary.Win32.winmm.instance != NULL)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-14 02:30:18 +00:00
|
|
|
FreeLibrary(_glfwLibrary.Win32.winmm.instance);
|
|
|
|
_glfwLibrary.Win32.winmm.instance = NULL;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
#endif // _GLFW_NO_DLOAD_WINMM
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-05 01:07:50 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Returns a wide string version of the specified UTF-8 string
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
WCHAR* _glfwCreateWideStringFromUTF8(const char* source)
|
|
|
|
{
|
|
|
|
WCHAR* target;
|
|
|
|
int length;
|
|
|
|
|
|
|
|
length = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0);
|
|
|
|
if (!length)
|
|
|
|
return NULL;
|
|
|
|
|
2012-02-07 14:40:47 +00:00
|
|
|
target = (WCHAR*) malloc(sizeof(WCHAR) * (length + 1));
|
2012-02-05 01:07:50 +00:00
|
|
|
|
|
|
|
if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length + 1))
|
|
|
|
{
|
2012-02-07 14:40:47 +00:00
|
|
|
free(target);
|
2012-02-05 01:07:50 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Returns a UTF-8 string version of the specified wide string
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
char* _glfwCreateUTF8FromWideString(const WCHAR* source)
|
|
|
|
{
|
|
|
|
char* target;
|
|
|
|
int length;
|
|
|
|
|
|
|
|
length = WideCharToMultiByte(CP_UTF8, 0, source, -1, NULL, 0, NULL, NULL);
|
|
|
|
if (!length)
|
|
|
|
return NULL;
|
|
|
|
|
2012-02-07 14:40:47 +00:00
|
|
|
target = (char*) malloc(length + 1);
|
2012-02-05 01:07:50 +00:00
|
|
|
|
|
|
|
if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, length + 1, NULL, NULL))
|
|
|
|
{
|
2012-02-07 14:40:47 +00:00
|
|
|
free(target);
|
2012-02-05 01:07:50 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Initialize various GLFW state
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
int _glfwPlatformInit(void)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-13 21:50:04 +00:00
|
|
|
// To make SetForegroundWindow work as we want, we need to fiddle
|
2010-09-07 15:34:51 +00: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 20:03:36 +00:00
|
|
|
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0,
|
2010-09-12 14:26:00 +00:00
|
|
|
&_glfwLibrary.Win32.foregroundLockTimeout, 0);
|
2012-03-22 13:58:14 +00:00
|
|
|
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, UIntToPtr(0),
|
2010-09-10 20:03:36 +00:00
|
|
|
SPIF_SENDCHANGE);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-13 23:05:03 +00:00
|
|
|
if (!initLibraries())
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
#ifdef __BORLANDC__
|
2010-09-07 15:34:51 +00:00
|
|
|
// With the Borland C++ compiler, we want to disable FPU exceptions
|
|
|
|
// (this is recommended for OpenGL applications under Windows)
|
2010-09-10 20:03:36 +00:00
|
|
|
_control87(MCW_EM, MCW_EM);
|
2010-09-07 15:34:51 +00:00
|
|
|
#endif
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
_glfwLibrary.Win32.instance = GetModuleHandle(NULL);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-10-13 02:04:43 +00:00
|
|
|
// Save the original gamma ramp
|
2010-10-14 11:54:19 +00:00
|
|
|
_glfwLibrary.originalRampSize = 256;
|
|
|
|
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
|
2011-09-25 14:00:08 +00:00
|
|
|
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp;
|
2010-10-13 02:04:43 +00:00
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
_glfwInitTimer();
|
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Close window and shut down library
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
int _glfwPlatformTerminate(void)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-10-13 02:04:43 +00:00
|
|
|
// Restore the original gamma ramp
|
2012-05-24 09:46:51 +00:00
|
|
|
if (_glfwLibrary.rampChanged)
|
|
|
|
_glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp);
|
2010-10-13 02:04:43 +00:00
|
|
|
|
2010-09-14 00:17:18 +00:00
|
|
|
if (_glfwLibrary.Win32.classAtom)
|
|
|
|
{
|
|
|
|
UnregisterClass(_GLFW_WNDCLASSNAME, _glfwLibrary.Win32.instance);
|
|
|
|
_glfwLibrary.Win32.classAtom = 0;
|
|
|
|
}
|
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
// TODO: Remove keyboard hook
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-13 23:05:03 +00:00
|
|
|
freeLibraries();
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
// Restore previous FOREGROUNDLOCKTIMEOUT system setting
|
2010-09-10 20:03:36 +00:00
|
|
|
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
|
2012-03-22 13:58:14 +00:00
|
|
|
UIntToPtr(_glfwLibrary.Win32.foregroundLockTimeout),
|
2010-09-10 20:03:36 +00:00
|
|
|
SPIF_SENDCHANGE);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-13 23:05:03 +00:00
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Get the GLFW version string
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
const char* _glfwPlatformGetVersionString(void)
|
|
|
|
{
|
2012-01-18 17:15:28 +00:00
|
|
|
const char* version = _GLFW_VERSION_FULL
|
2012-11-27 14:02:26 +00:00
|
|
|
#if defined(_GLFW_WGL)
|
|
|
|
" WGL"
|
|
|
|
#elif defined(_GLFW_EGL)
|
|
|
|
" EGL"
|
|
|
|
#endif
|
2010-09-13 23:05:03 +00:00
|
|
|
#if defined(__MINGW32__)
|
|
|
|
" MinGW"
|
|
|
|
#elif defined(_MSC_VER)
|
2010-09-20 19:03:00 +00:00
|
|
|
" Visual C++ "
|
2010-09-13 23:05:03 +00:00
|
|
|
#elif defined(__BORLANDC__)
|
|
|
|
" Borland C"
|
|
|
|
#else
|
|
|
|
" (unknown compiler)"
|
|
|
|
#endif
|
2012-03-25 15:40:30 +00:00
|
|
|
#if defined(_GLFW_BUILD_DLL)
|
2010-09-13 23:05:03 +00:00
|
|
|
" DLL"
|
|
|
|
#endif
|
|
|
|
#if !defined(_GLFW_NO_DLOAD_WINMM)
|
|
|
|
" load(winmm)"
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|