about summary refs log tree commit diff
path: root/src/engine/external/glfw/lib/win32
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/external/glfw/lib/win32')
-rw-r--r--src/engine/external/glfw/lib/win32/glfwdll.def67
-rw-r--r--src/engine/external/glfw/lib/win32/glfwdll_mgw1.def67
-rw-r--r--src/engine/external/glfw/lib/win32/glfwdll_mgw2.def67
-rw-r--r--src/engine/external/glfw/lib/win32/glfwdll_pellesc.def65
-rw-r--r--src/engine/external/glfw/lib/win32/platform.h468
-rw-r--r--src/engine/external/glfw/lib/win32/win32_dllmain.c60
-rw-r--r--src/engine/external/glfw/lib/win32/win32_enable.c155
-rw-r--r--src/engine/external/glfw/lib/win32/win32_fullscreen.c317
-rw-r--r--src/engine/external/glfw/lib/win32/win32_glext.c101
-rw-r--r--src/engine/external/glfw/lib/win32/win32_init.c356
-rw-r--r--src/engine/external/glfw/lib/win32/win32_joystick.c234
-rw-r--r--src/engine/external/glfw/lib/win32/win32_thread.c511
-rw-r--r--src/engine/external/glfw/lib/win32/win32_time.c146
-rw-r--r--src/engine/external/glfw/lib/win32/win32_window.c1697
14 files changed, 4311 insertions, 0 deletions
diff --git a/src/engine/external/glfw/lib/win32/glfwdll.def b/src/engine/external/glfw/lib/win32/glfwdll.def
new file mode 100644
index 00000000..1b40765a
--- /dev/null
+++ b/src/engine/external/glfw/lib/win32/glfwdll.def
@@ -0,0 +1,67 @@
+LIBRARY GLFW.DLL
+
+EXPORTS
+glfwBroadcastCond
+glfwCloseWindow
+glfwCreateCond
+glfwCreateMutex
+glfwCreateThread
+glfwDestroyCond
+glfwDestroyMutex
+glfwDestroyThread
+glfwDisable
+glfwEnable
+glfwExtensionSupported
+glfwFreeImage
+glfwGetDesktopMode
+glfwGetGLVersion
+glfwGetJoystickButtons
+glfwGetJoystickParam
+glfwGetJoystickPos
+glfwGetKey
+glfwGetMouseButton
+glfwGetMousePos
+glfwGetMouseWheel
+glfwGetNumberOfProcessors
+glfwGetProcAddress
+glfwGetThreadID
+glfwGetTime
+glfwGetVersion
+glfwGetVideoModes
+glfwGetWindowParam
+glfwGetWindowSize
+glfwIconifyWindow
+glfwInit
+glfwLoadMemoryTexture2D
+glfwLoadTexture2D
+glfwLoadTextureImage2D
+glfwLockMutex
+glfwOpenWindow
+glfwOpenWindowHint
+glfwPollEvents
+glfwReadImage
+glfwReadMemoryImage
+glfwRestoreWindow
+glfwSetCharCallback
+glfwSetKeyCallback
+glfwSetMouseButtonCallback
+glfwSetMousePos
+glfwSetMousePosCallback
+glfwSetMouseWheel
+glfwSetMouseWheelCallback
+glfwSetTime
+glfwSetWindowCloseCallback
+glfwSetWindowRefreshCallback
+glfwSetWindowPos
+glfwSetWindowSize
+glfwSetWindowSizeCallback
+glfwSetWindowTitle
+glfwSignalCond
+glfwSleep
+glfwSwapBuffers
+glfwSwapInterval
+glfwTerminate
+glfwUnlockMutex
+glfwWaitCond
+glfwWaitEvents
+glfwWaitThread
diff --git a/src/engine/external/glfw/lib/win32/glfwdll_mgw1.def b/src/engine/external/glfw/lib/win32/glfwdll_mgw1.def
new file mode 100644
index 00000000..b193aa95
--- /dev/null
+++ b/src/engine/external/glfw/lib/win32/glfwdll_mgw1.def
@@ -0,0 +1,67 @@
+LIBRARY GLFW.DLL
+
+EXPORTS
+glfwBroadcastCond = glfwBroadcastCond@4
+glfwCloseWindow = glfwCloseWindow@0
+glfwCreateCond = glfwCreateCond@0
+glfwCreateMutex = glfwCreateMutex@0
+glfwCreateThread = glfwCreateThread@8
+glfwDestroyCond = glfwDestroyCond@4
+glfwDestroyMutex = glfwDestroyMutex@4
+glfwDestroyThread = glfwDestroyThread@4
+glfwDisable = glfwDisable@4
+glfwEnable = glfwEnable@4
+glfwExtensionSupported = glfwExtensionSupported@4
+glfwFreeImage = glfwFreeImage@4
+glfwGetDesktopMode = glfwGetDesktopMode@4
+glfwGetGLVersion = glfwGetGLVersion@12
+glfwGetJoystickButtons = glfwGetJoystickButtons@12
+glfwGetJoystickParam = glfwGetJoystickParam@8
+glfwGetJoystickPos = glfwGetJoystickPos@12
+glfwGetKey = glfwGetKey@4
+glfwGetMouseButton = glfwGetMouseButton@4
+glfwGetMousePos = glfwGetMousePos@8
+glfwGetMouseWheel = glfwGetMouseWheel@0
+glfwGetNumberOfProcessors = glfwGetNumberOfProcessors@0
+glfwGetProcAddress = glfwGetProcAddress@4
+glfwGetThreadID = glfwGetThreadID@0
+glfwGetTime = glfwGetTime@0
+glfwGetVersion = glfwGetVersion@12
+glfwGetVideoModes = glfwGetVideoModes@8
+glfwGetWindowParam = glfwGetWindowParam@4
+glfwGetWindowSize = glfwGetWindowSize@8
+glfwIconifyWindow = glfwIconifyWindow@0
+glfwInit = glfwInit@0
+glfwLoadMemoryTexture2D = glfwLoadMemoryTexture2D@12
+glfwLoadTexture2D = glfwLoadTexture2D@8
+glfwLoadTextureImage2D = glfwLoadTextureImage2D@8
+glfwLockMutex = glfwLockMutex@4
+glfwOpenWindow = glfwOpenWindow@36
+glfwOpenWindowHint = glfwOpenWindowHint@8
+glfwPollEvents = glfwPollEvents@0
+glfwReadImage = glfwReadImage@12
+glfwReadMemoryImage = glfwReadMemoryImage@16
+glfwRestoreWindow = glfwRestoreWindow@0
+glfwSetCharCallback = glfwSetCharCallback@4
+glfwSetKeyCallback = glfwSetKeyCallback@4
+glfwSetMouseButtonCallback = glfwSetMouseButtonCallback@4
+glfwSetMousePos = glfwSetMousePos@8
+glfwSetMousePosCallback = glfwSetMousePosCallback@4
+glfwSetMouseWheel = glfwSetMouseWheel@4
+glfwSetMouseWheelCallback = glfwSetMouseWheelCallback@4
+glfwSetTime = glfwSetTime@8
+glfwSetWindowCloseCallback = glfwSetWindowCloseCallback@4
+glfwSetWindowRefreshCallback = glfwSetWindowRefreshCallback@4
+glfwSetWindowPos = glfwSetWindowPos@8
+glfwSetWindowSize = glfwSetWindowSize@8
+glfwSetWindowSizeCallback = glfwSetWindowSizeCallback@4
+glfwSetWindowTitle = glfwSetWindowTitle@4
+glfwSignalCond = glfwSignalCond@4
+glfwSleep = glfwSleep@8
+glfwSwapBuffers = glfwSwapBuffers@0
+glfwSwapInterval = glfwSwapInterval@4
+glfwTerminate = glfwTerminate@0
+glfwUnlockMutex = glfwUnlockMutex@4
+glfwWaitCond = glfwWaitCond@16
+glfwWaitEvents = glfwWaitEvents@0
+glfwWaitThread = glfwWaitThread@8
diff --git a/src/engine/external/glfw/lib/win32/glfwdll_mgw2.def b/src/engine/external/glfw/lib/win32/glfwdll_mgw2.def
new file mode 100644
index 00000000..e42f664e
--- /dev/null
+++ b/src/engine/external/glfw/lib/win32/glfwdll_mgw2.def
@@ -0,0 +1,67 @@
+LIBRARY GLFW.DLL
+
+EXPORTS
+glfwBroadcastCond@4
+glfwCloseWindow@0
+glfwCreateCond@0
+glfwCreateMutex@0
+glfwCreateThread@8
+glfwDestroyCond@4
+glfwDestroyMutex@4
+glfwDestroyThread@4
+glfwDisable@4
+glfwEnable@4
+glfwExtensionSupported@4
+glfwFreeImage@4
+glfwGetDesktopMode@4
+glfwGetGLVersion@12
+glfwGetJoystickButtons@12
+glfwGetJoystickParam@8
+glfwGetJoystickPos@12
+glfwGetKey@4
+glfwGetMouseButton@4
+glfwGetMousePos@8
+glfwGetMouseWheel@0
+glfwGetNumberOfProcessors@0
+glfwGetProcAddress@4
+glfwGetThreadID@0
+glfwGetTime@0
+glfwGetVersion@12
+glfwGetVideoModes@8
+glfwGetWindowParam@4
+glfwGetWindowSize@8
+glfwIconifyWindow@0
+glfwInit@0
+glfwLoadMemoryTexture2D@12
+glfwLoadTexture2D@8
+glfwLoadTextureImage2D@8
+glfwLockMutex@4
+glfwOpenWindow@36
+glfwOpenWindowHint@8
+glfwPollEvents@0
+glfwReadImage@12
+glfwReadMemoryImage@16
+glfwRestoreWindow@0
+glfwSetCharCallback@4
+glfwSetKeyCallback@4
+glfwSetMouseButtonCallback@4
+glfwSetMousePos@8
+glfwSetMousePosCallback@4
+glfwSetMouseWheel@4
+glfwSetMouseWheelCallback@4
+glfwSetTime@8
+glfwSetWindowCloseCallback@4
+glfwSetWindowRefreshCallback@4
+glfwSetWindowPos@8
+glfwSetWindowSize@8
+glfwSetWindowSizeCallback@4
+glfwSetWindowTitle@4
+glfwSignalCond@4
+glfwSleep@8
+glfwSwapBuffers@0
+glfwSwapInterval@4
+glfwTerminate@0
+glfwUnlockMutex@4
+glfwWaitCond@16
+glfwWaitEvents@0
+glfwWaitThread@8
diff --git a/src/engine/external/glfw/lib/win32/glfwdll_pellesc.def b/src/engine/external/glfw/lib/win32/glfwdll_pellesc.def
new file mode 100644
index 00000000..cbb214c8
--- /dev/null
+++ b/src/engine/external/glfw/lib/win32/glfwdll_pellesc.def
@@ -0,0 +1,65 @@
+LIBRARY GLFW
+
+EXPORTS
+glfwBroadcastCond = glfwBroadcastCond@4
+glfwCloseWindow = glfwCloseWindow@0
+glfwCreateCond = glfwCreateCond@0
+glfwCreateMutex = glfwCreateMutex@0
+glfwCreateThread = glfwCreateThread@8
+glfwDestroyCond = glfwDestroyCond@4
+glfwDestroyMutex = glfwDestroyMutex@4
+glfwDestroyThread = glfwDestroyThread@4
+glfwDisable = glfwDisable@4
+glfwEnable = glfwEnable@4
+glfwExtensionSupported = glfwExtensionSupported@4
+glfwFreeImage = glfwFreeImage@4
+glfwGetDesktopMode = glfwGetDesktopMode@4
+glfwGetGLVersion = glfwGetGLVersion@12
+glfwGetJoystickButtons = glfwGetJoystickButtons@12
+glfwGetJoystickParam = glfwGetJoystickParam@8
+glfwGetJoystickPos = glfwGetJoystickPos@12
+glfwGetKey = glfwGetKey@4
+glfwGetMouseButton = glfwGetMouseButton@4
+glfwGetMousePos = glfwGetMousePos@8
+glfwGetMouseWheel = glfwGetMouseWheel@0
+glfwGetNumberOfProcessors = glfwGetNumberOfProcessors@0
+glfwGetProcAddress = glfwGetProcAddress@4
+glfwGetThreadID = glfwGetThreadID@0
+glfwGetTime = glfwGetTime@0
+glfwGetVersion = glfwGetVersion@12
+glfwGetVideoModes = glfwGetVideoModes@8
+glfwGetWindowParam = glfwGetWindowParam@4
+glfwGetWindowSize = glfwGetWindowSize@8
+glfwIconifyWindow = glfwIconifyWindow@0
+glfwInit = glfwInit@0
+glfwLoadTexture2D = glfwLoadTexture2D@8
+glfwLockMutex = glfwLockMutex@4
+glfwOpenWindow = glfwOpenWindow@36
+glfwOpenWindowHint = glfwOpenWindowHint@8
+glfwPollEvents = glfwPollEvents@0
+glfwReadImage = glfwReadImage@12
+glfwReadMemoryImage = glfwReadMemoryImage@16
+glfwRestoreWindow = glfwRestoreWindow@0
+glfwSetCharCallback = glfwSetCharCallback@4
+glfwSetKeyCallback = glfwSetKeyCallback@4
+glfwSetMouseButtonCallback = glfwSetMouseButtonCallback@4
+glfwSetMousePos = glfwSetMousePos@8
+glfwSetMousePosCallback = glfwSetMousePosCallback@4
+glfwSetMouseWheel = glfwSetMouseWheel@4
+glfwSetMouseWheelCallback = glfwSetMouseWheelCallback@4
+glfwSetTime = glfwSetTime@8
+glfwSetWindowCloseCallback = glfwSetWindowCloseCallback@4
+glfwSetWindowRefreshCallback = glfwSetWindowRefreshCallback@4
+glfwSetWindowPos = glfwSetWindowPos@8
+glfwSetWindowSize = glfwSetWindowSize@8
+glfwSetWindowSizeCallback = glfwSetWindowSizeCallback@4
+glfwSetWindowTitle = glfwSetWindowTitle@4
+glfwSignalCond = glfwSignalCond@4
+glfwSleep = glfwSleep@8
+glfwSwapBuffers = glfwSwapBuffers@0
+glfwSwapInterval = glfwSwapInterval@4
+glfwTerminate = glfwTerminate@0
+glfwUnlockMutex = glfwUnlockMutex@4
+glfwWaitCond = glfwWaitCond@16
+glfwWaitEvents = glfwWaitEvents@0
+glfwWaitThread = glfwWaitThread@8
diff --git a/src/engine/external/glfw/lib/win32/platform.h b/src/engine/external/glfw/lib/win32/platform.h
new file mode 100644
index 00000000..25ada3b0
--- /dev/null
+++ b/src/engine/external/glfw/lib/win32/platform.h
@@ -0,0 +1,468 @@
+//========================================================================

+// GLFW - An OpenGL framework

+// File:        platform.h

+// Platform:    Windows

+// API version: 2.6

+// WWW:         http://glfw.sourceforge.net

+//------------------------------------------------------------------------

+// Copyright (c) 2002-2006 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.

+//

+//========================================================================

+

+#ifndef _platform_h_

+#define _platform_h_

+

+

+// This is the Windows version of GLFW

+#define _GLFW_WIN32

+

+

+// Include files

+#include <windows.h>

+#include <mmsystem.h>

+#include "../../include/GL/glfw.h"

+

+

+//========================================================================

+// Hack: Define things that some <windows.h>'s do not define

+//========================================================================

+

+// Some old versions of w32api (used by MinGW and Cygwin) define

+// WH_KEYBOARD_LL without typedef:ing KBDLLHOOKSTRUCT (!)

+#if defined(__MINGW32__) || defined(__CYGWIN__)

+#include <w32api.h>

+#if defined(WH_KEYBOARD_LL) && (__W32API_MAJOR_VERSION == 1) && (__W32API_MINOR_VERSION <= 2)

+#undef WH_KEYBOARD_LL

+#endif

+#endif

+

+//------------------------------------------------------------------------

+// ** NOTE **  If this gives you compiler errors and you are using MinGW

+// (or Dev-C++), update to w32api version 1.3 or later:

+// http://sourceforge.net/project/showfiles.php?group_id=2435

+//------------------------------------------------------------------------

+#ifndef WH_KEYBOARD_LL

+#define WH_KEYBOARD_LL 13

+typedef struct tagKBDLLHOOKSTRUCT {

+  DWORD   vkCode;

+  DWORD   scanCode;

+  DWORD   flags;

+  DWORD   time;

+  DWORD   dwExtraInfo;

+} KBDLLHOOKSTRUCT, FAR *LPKBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;

+#endif // WH_KEYBOARD_LL

+

+#ifndef LLKHF_ALTDOWN

+#define LLKHF_ALTDOWN  0x00000020

+#endif

+

+#ifndef SPI_SETSCREENSAVERRUNNING

+#define SPI_SETSCREENSAVERRUNNING 97

+#endif

+#ifndef SPI_GETANIMATION

+#define SPI_GETANIMATION 72

+#endif

+#ifndef SPI_SETANIMATION

+#define SPI_SETANIMATION 73

+#endif

+#ifndef SPI_GETFOREGROUNDLOCKTIMEOUT

+#define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000

+#endif

+#ifndef SPI_SETFOREGROUNDLOCKTIMEOUT

+#define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001

+#endif

+

+#ifndef CDS_FULLSCREEN

+#define CDS_FULLSCREEN 4

+#endif

+

+#ifndef PFD_GENERIC_ACCELERATED

+#define PFD_GENERIC_ACCELERATED 0x00001000

+#endif

+#ifndef PFD_DEPTH_DONTCARE

+#define PFD_DEPTH_DONTCARE 0x20000000

+#endif

+

+#ifndef ENUM_CURRENT_SETTINGS

+#define ENUM_CURRENT_SETTINGS -1

+#endif

+#ifndef ENUM_REGISTRY_SETTINGS

+#define ENUM_REGISTRY_SETTINGS -2

+#endif

+

+#ifndef WM_MOUSEWHEEL

+#define WM_MOUSEWHEEL 0x020A

+#endif

+#ifndef WHEEL_DELTA

+#define WHEEL_DELTA 120

+#endif

+

+#ifndef WM_XBUTTONDOWN

+#define WM_XBUTTONDOWN 0x020B

+#endif

+#ifndef WM_XBUTTONUP

+#define WM_XBUTTONUP 0x020C

+#endif

+#ifndef XBUTTON1

+#define XBUTTON1 1

+#endif

+#ifndef XBUTTON2

+#define XBUTTON2 2

+#endif

+

+// wglSwapIntervalEXT typedef (Win32 buffer-swap interval control)

+typedef int (APIENTRY * WGLSWAPINTERVALEXT_T) (int interval);

+// wglChoosePixelFormatARB typedef

+typedef BOOL (WINAPI * WGLCHOOSEPIXELFORMATARB_T) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);

+// wglGetPixelFormatAttribivARB typedef

+typedef BOOL (WINAPI * WGLGETPIXELFORMATATTRIBIVARB_T) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);

+

+#define WGL_DRAW_TO_WINDOW_ARB    0x2001

+#define WGL_SUPPORT_OPENGL_ARB    0x2010

+#define WGL_ACCELERATION_ARB      0x2003

+#define WGL_FULL_ACCELERATION_ARB 0x2027

+#define WGL_DOUBLE_BUFFER_ARB     0x2011

+#define WGL_STEREO_ARB            0x2012

+#define WGL_COLOR_BITS_ARB        0x2014

+#define WGL_RED_BITS_ARB          0x2015

+#define WGL_GREEN_BITS_ARB        0x2017

+#define WGL_BLUE_BITS_ARB         0x2019

+#define WGL_ALPHA_BITS_ARB        0x201B

+#define WGL_ACCUM_BITS_ARB        0x201D 

+#define WGL_ACCUM_RED_BITS_ARB    0x201E 

+#define WGL_ACCUM_GREEN_BITS_ARB  0x201F 

+#define WGL_ACCUM_BLUE_BITS_ARB   0x2020 

+#define WGL_ACCUM_ALPHA_BITS_ARB  0x2021 

+#define WGL_DEPTH_BITS_ARB        0x2022

+#define WGL_STENCIL_BITS_ARB      0x2023

+#define WGL_AUX_BUFFERS_ARB       0x2024 

+#define WGL_SAMPLE_BUFFERS_ARB    0x2041

+#define WGL_SAMPLES_ARB           0x2042

+

+

+//========================================================================

+// DLLs that are loaded at glfwInit()

+//========================================================================

+

+// gdi32.dll function pointer typedefs

+#ifndef _GLFW_NO_DLOAD_GDI32

+typedef int  (WINAPI * CHOOSEPIXELFORMAT_T) (HDC,CONST PIXELFORMATDESCRIPTOR*);

+typedef int  (WINAPI * DESCRIBEPIXELFORMAT_T) (HDC,int,UINT,LPPIXELFORMATDESCRIPTOR);

+typedef int  (WINAPI * GETPIXELFORMAT_T) (HDC);

+typedef BOOL (WINAPI * SETPIXELFORMAT_T) (HDC,int,const PIXELFORMATDESCRIPTOR*);

+typedef BOOL (WINAPI * SWAPBUFFERS_T) (HDC);

+#endif // _GLFW_NO_DLOAD_GDI32

+

+// winmm.dll function pointer typedefs

+#ifndef _GLFW_NO_DLOAD_WINMM

+typedef MMRESULT (WINAPI * JOYGETDEVCAPSA_T) (UINT,LPJOYCAPSA,UINT);

+typedef MMRESULT (WINAPI * JOYGETPOS_T) (UINT,LPJOYINFO);

+typedef MMRESULT (WINAPI * JOYGETPOSEX_T) (UINT,LPJOYINFOEX);

+typedef DWORD (WINAPI * TIMEGETTIME_T) (void);

+#endif // _GLFW_NO_DLOAD_WINMM

+

+

+// gdi32.dll shortcuts

+#ifndef _GLFW_NO_DLOAD_GDI32

+#define _glfw_ChoosePixelFormat   _glfwLibrary.Libs.ChoosePixelFormat

+#define _glfw_DescribePixelFormat _glfwLibrary.Libs.DescribePixelFormat

+#define _glfw_GetPixelFormat      _glfwLibrary.Libs.GetPixelFormat

+#define _glfw_SetPixelFormat      _glfwLibrary.Libs.SetPixelFormat

+#define _glfw_SwapBuffers         _glfwLibrary.Libs.SwapBuffers

+#else

+#define _glfw_ChoosePixelFormat   ChoosePixelFormat

+#define _glfw_DescribePixelFormat DescribePixelFormat

+#define _glfw_GetPixelFormat      GetPixelFormat

+#define _glfw_SetPixelFormat      SetPixelFormat

+#define _glfw_SwapBuffers         SwapBuffers

+#endif // _GLFW_NO_DLOAD_GDI32

+

+// winmm.dll shortcuts

+#ifndef _GLFW_NO_DLOAD_WINMM

+#define _glfw_joyGetDevCaps _glfwLibrary.Libs.joyGetDevCapsA

+#define _glfw_joyGetPos     _glfwLibrary.Libs.joyGetPos

+#define _glfw_joyGetPosEx   _glfwLibrary.Libs.joyGetPosEx

+#define _glfw_timeGetTime   _glfwLibrary.Libs.timeGetTime

+#else

+#define _glfw_joyGetDevCaps joyGetDevCapsA

+#define _glfw_joyGetPos     joyGetPos

+#define _glfw_joyGetPosEx   joyGetPosEx

+#define _glfw_timeGetTime   timeGetTime

+#endif // _GLFW_NO_DLOAD_WINMM

+

+

+//========================================================================

+// Global variables (GLFW internals)

+//========================================================================

+

+//------------------------------------------------------------------------

+// Window structure

+//------------------------------------------------------------------------

+typedef struct _GLFWwin_struct _GLFWwin;

+

+struct _GLFWwin_struct {

+

+// ========= PLATFORM INDEPENDENT MANDATORY PART =========================

+

+    // User callback functions

+    GLFWwindowsizefun    WindowSizeCallback;

+    GLFWwindowclosefun   WindowCloseCallback;

+    GLFWwindowrefreshfun WindowRefreshCallback;

+    GLFWmousebuttonfun   MouseButtonCallback;

+    GLFWmouseposfun      MousePosCallback;

+    GLFWmousewheelfun    MouseWheelCallback;

+    GLFWkeyfun           KeyCallback;

+    GLFWcharfun          CharCallback;

+

+    // User selected window settings

+    int       Fullscreen;      // Fullscreen flag

+    int       MouseLock;       // Mouse-lock flag

+    int       AutoPollEvents;  // Auto polling flag

+    int       SysKeysDisabled; // System keys disabled flag

+    int       WindowNoResize;  // Resize- and maximize gadgets disabled flag

+

+    // Window status & parameters

+    int       Opened;          // Flag telling if window is opened or not

+    int       Active;          // Application active flag

+    int       Iconified;       // Window iconified flag

+    int       Width, Height;   // Window width and heigth

+    int       Accelerated;     // GL_TRUE if window is HW accelerated

+    int       RedBits;

+    int       GreenBits;

+    int       BlueBits;

+    int       AlphaBits;

+    int       DepthBits;

+    int       StencilBits;

+    int       AccumRedBits;

+    int       AccumGreenBits;

+    int       AccumBlueBits;

+    int       AccumAlphaBits;

+    int       AuxBuffers;

+    int       Stereo;

+    int       RefreshRate;     // Vertical monitor refresh rate

+    int       Samples;

+

+    // Extensions & OpenGL version

+    int       Has_GL_SGIS_generate_mipmap;

+    int       Has_GL_ARB_texture_non_power_of_two;

+    int       GLVerMajor,GLVerMinor;

+

+

+// ========= PLATFORM SPECIFIC PART ======================================

+

+    // Platform specific window resources

+    HDC       DC;              // Private GDI device context

+    HGLRC     RC;              // Permanent rendering context

+    HWND      Wnd;             // Window handle

+    ATOM      ClassAtom;       // Window class atom

+    int       ModeID;          // Mode ID for fullscreen mode

+    HHOOK     KeyboardHook;    // Keyboard hook handle

+    DWORD     dwStyle;         // Window styles used for window creation

+    DWORD     dwExStyle;       // --"--

+

+    // Platform specific extensions (context specific)

+    WGLSWAPINTERVALEXT_T SwapInterval;

+    WGLCHOOSEPIXELFORMATARB_T ChoosePixelFormat;

+    WGLGETPIXELFORMATATTRIBIVARB_T GetPixelFormatAttribiv;

+

+    // Various platform specific internal variables

+    int       OldMouseLock;    // Old mouse-lock flag (used for remembering

+                               // mouse-lock state when iconifying)

+    int       OldMouseLockValid;

+    int       DesiredRefreshRate; // Desired vertical monitor refresh rate

+

+};

+

+GLFWGLOBAL _GLFWwin _glfwWin;

+

+

+//------------------------------------------------------------------------

+// User input status (most of this should go in _GLFWwin)

+//------------------------------------------------------------------------

+GLFWGLOBAL struct {

+

+// ========= PLATFORM INDEPENDENT MANDATORY PART =========================

+

+    // Mouse status

+    int  MousePosX, MousePosY;

+    int  WheelPos;

+    char MouseButton[ GLFW_MOUSE_BUTTON_LAST+1 ];

+

+    // Keyboard status

+    char Key[ GLFW_KEY_LAST+1 ];

+    int  LastChar;

+

+    // User selected settings

+    int  StickyKeys;

+    int  StickyMouseButtons;

+    int  KeyRepeat;

+

+

+// ========= PLATFORM SPECIFIC PART ======================================

+

+    // Platform specific internal variables

+    int  MouseMoved, OldMouseX, OldMouseY;

+

+} _glfwInput;

+

+

+//------------------------------------------------------------------------

+// Library global data

+//------------------------------------------------------------------------

+GLFWGLOBAL struct {

+

+// ========= PLATFORM SPECIFIC PART ======================================

+

+  HINSTANCE Instance;        // Instance of the application

+

+  // Timer data

+  struct {

+      int          HasPerformanceCounter;

+      double       Resolution;

+      unsigned int t0_32;

+      __int64      t0_64;

+  } Timer;

+

+  // System information

+  struct {

+      int     WinVer;

+      int     HasUnicode;

+      DWORD   ForegroundLockTimeout;

+  } Sys;

+

+#if !defined(_GLFW_NO_DLOAD_WINMM) || !defined(_GLFW_NO_DLOAD_GDI32)

+  // Library handles and function pointers

+  struct {

+#ifndef _GLFW_NO_DLOAD_GDI32

+      // gdi32.dll

+      HINSTANCE             gdi32;

+      CHOOSEPIXELFORMAT_T   ChoosePixelFormat;

+      DESCRIBEPIXELFORMAT_T DescribePixelFormat;

+      GETPIXELFORMAT_T      GetPixelFormat;

+      SETPIXELFORMAT_T      SetPixelFormat;

+      SWAPBUFFERS_T         SwapBuffers;

+#endif // _GLFW_NO_DLOAD_GDI32

+

+      // winmm.dll

+#ifndef _GLFW_NO_DLOAD_WINMM

+      HINSTANCE             winmm;

+      JOYGETDEVCAPSA_T      joyGetDevCapsA;

+      JOYGETPOS_T           joyGetPos;

+      JOYGETPOSEX_T         joyGetPosEx;

+      TIMEGETTIME_T         timeGetTime;

+#endif // _GLFW_NO_DLOAD_WINMM

+  } Libs;

+#endif

+

+} _glfwLibrary;

+

+

+//------------------------------------------------------------------------

+// Thread record (one for each thread)

+//------------------------------------------------------------------------

+typedef struct _GLFWthread_struct _GLFWthread;

+

+struct _GLFWthread_struct {

+

+// ========= PLATFORM INDEPENDENT MANDATORY PART =========================

+

+    // Pointer to previous and next threads in linked list

+    _GLFWthread   *Previous, *Next;

+

+    // GLFW user side thread information

+    GLFWthread    ID;

+    GLFWthreadfun Function;

+

+// ========= PLATFORM SPECIFIC PART ======================================

+

+    // System side thread information

+    HANDLE        Handle;

+    DWORD         WinID;

+

+};

+

+

+//------------------------------------------------------------------------

+// General thread information

+//------------------------------------------------------------------------

+GLFWGLOBAL struct {

+

+// ========= PLATFORM INDEPENDENT MANDATORY PART =========================

+

+    // Next thread ID to use (increments for every created thread)

+    GLFWthread       NextID;

+

+    // First thread in linked list (always the main thread)

+    _GLFWthread      First;

+

+// ========= PLATFORM SPECIFIC PART ======================================

+

+    // Critical section lock

+    CRITICAL_SECTION CriticalSection;

+

+} _glfwThrd;

+

+

+

+//========================================================================

+// Macros for encapsulating critical code sections (i.e. making parts

+// of GLFW thread safe)

+//========================================================================

+

+// Thread list management

+#define ENTER_THREAD_CRITICAL_SECTION \

+        EnterCriticalSection( &_glfwThrd.CriticalSection );

+#define LEAVE_THREAD_CRITICAL_SECTION \

+        LeaveCriticalSection( &_glfwThrd.CriticalSection );

+

+

+//========================================================================

+// Various Windows version constants

+//========================================================================

+

+#define _GLFW_WIN_UNKNOWN    0x0000  // Earlier than 95 or NT4

+#define _GLFW_WIN_95         0x0001

+#define _GLFW_WIN_98         0x0002

+#define _GLFW_WIN_ME         0x0003

+#define _GLFW_WIN_UNKNOWN_9x 0x0004  // Later than ME

+#define _GLFW_WIN_NT4        0x0101

+#define _GLFW_WIN_2K         0x0102

+#define _GLFW_WIN_XP         0x0103

+#define _GLFW_WIN_NET_SERVER 0x0104

+#define _GLFW_WIN_UNKNOWN_NT 0x0105  // Later than .NET Server

+

+

+//========================================================================

+// Prototypes for platform specific internal functions

+//========================================================================

+

+// Time

+void _glfwInitTimer( void );

+

+// Fullscreen support

+int _glfwGetClosestVideoModeBPP( int *w, int *h, int *bpp, int *refresh );

+int _glfwGetClosestVideoMode( int *w, int *h, int *r, int *g, int *b, int *refresh );

+void _glfwSetVideoModeMODE( int mode );

+void _glfwSetVideoMode( int *w, int *h, int r, int g, int b, int refresh );

+

+

+#endif // _platform_h_

diff --git a/src/engine/external/glfw/lib/win32/win32_dllmain.c b/src/engine/external/glfw/lib/win32/win32_dllmain.c
new file mode 100644
index 00000000..0cfed043
--- /dev/null
+++ b/src/engine/external/glfw/lib/win32/win32_dllmain.c
@@ -0,0 +1,60 @@
+//========================================================================

+// GLFW - An OpenGL framework

+// File:        win32_dllmain.c

+// Platform:    Windows

+// API version: 2.6

+// WWW:         http://glfw.sourceforge.net

+//------------------------------------------------------------------------

+// Copyright (c) 2002-2006 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"

+

+

+#if defined(GLFW_BUILD_DLL)

+

+//========================================================================

+// DllMain()

+//========================================================================

+

+int WINAPI DllMain( HINSTANCE hinst, unsigned long reason, void *x )

+{

+    // NOTE: Some compilers complains about hinst and x never being used -

+    // never mind that (we don't want to use them)!

+

+    switch( reason )

+    {

+    case DLL_PROCESS_ATTACH:

+        // Initializations

+        //glfwInit();   // We don't want to do that now!

+        break;

+    case DLL_PROCESS_DETACH:

+        // Do some cleanup

+        glfwTerminate();

+        break;

+    };

+

+    return 1;

+}

+

+#endif // GLFW_BUILD_DLL

diff --git a/src/engine/external/glfw/lib/win32/win32_enable.c b/src/engine/external/glfw/lib/win32/win32_enable.c
new file mode 100644
index 00000000..5b0d3294
--- /dev/null
+++ b/src/engine/external/glfw/lib/win32/win32_enable.c
@@ -0,0 +1,155 @@
+//========================================================================

+// GLFW - An OpenGL framework

+// File:        win32_enable.c

+// Platform:    Windows

+// API version: 2.6

+// WWW:         http://glfw.sourceforge.net

+//------------------------------------------------------------------------

+// Copyright (c) 2002-2006 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"

+

+

+//************************************************************************

+//****                  GLFW internal functions                       ****

+//************************************************************************

+

+//========================================================================

+// _glfwLLKeyboardProc() - Low level keyboard callback function (used to

+// disable system keys under Windows NT).

+//========================================================================

+

+LRESULT CALLBACK _glfwLLKeyboardProc( int nCode, WPARAM wParam,

+    LPARAM lParam )

+{

+    BOOL syskeys = 0;

+    PKBDLLHOOKSTRUCT p;

+

+    // We are only looking for keyboard events - interpret lParam as a

+    // pointer to a KBDLLHOOKSTRUCT

+    p = (PKBDLLHOOKSTRUCT) lParam;

+

+    // If nCode == HC_ACTION, then we have a keyboard event

+    if( nCode == HC_ACTION )

+    {

+        switch( wParam )

+        {

+            case WM_KEYDOWN:

+            case WM_SYSKEYDOWN:

+            case WM_KEYUP:

+            case WM_SYSKEYUP:

+                // Detect: ALT+TAB, ALT+ESC, ALT+F4, CTRL+ESC,

+                // LWIN, RWIN, APPS (mysterious menu key)

+                syskeys = ( p->vkCode == VK_TAB &&

+                            p->flags & LLKHF_ALTDOWN ) ||

+                          ( p->vkCode == VK_ESCAPE &&

+                            p->flags & LLKHF_ALTDOWN ) ||

+                          ( p->vkCode == VK_F4 &&

+                            p->flags & LLKHF_ALTDOWN ) ||

+                          ( p->vkCode == VK_ESCAPE &&

+                            (GetKeyState(VK_CONTROL) & 0x8000)) ||

+                          p->vkCode == VK_LWIN ||

+                          p->vkCode == VK_RWIN ||

+                          p->vkCode == VK_APPS;

+                break;

+

+            default:

+                break;

+        }

+    }

+

+    // Was it a system key combination (e.g. ALT+TAB)?

+    if( syskeys )

+    {

+        // Pass the key event to our window message loop

+        if( _glfwWin.Opened )

+        {

+            PostMessage( _glfwWin.Wnd, (UINT) wParam, p->vkCode, 0 );

+        }

+

+        // We've taken care of it - don't let the system know about this

+        // key event

+        return 1;

+    }

+    else

+    {

+        // It's a harmless key press, let the system deal with it

+        return CallNextHookEx( _glfwWin.KeyboardHook, nCode, wParam,

+                               lParam );

+    }

+}

+

+

+

+//************************************************************************

+//****               Platform implementation functions                ****

+//************************************************************************

+

+//========================================================================

+// _glfwPlatformEnableSystemKeys() - Enable system keys

+// _glfwPlatformDisableSystemKeys() - Disable system keys

+//========================================================================

+

+void _glfwPlatformEnableSystemKeys( void )

+{

+    BOOL bOld;

+

+    // Use different methods depending on operating system version

+    if( _glfwLibrary.Sys.WinVer >= _GLFW_WIN_NT4 )

+    {

+        if( _glfwWin.KeyboardHook != NULL )

+        {

+            UnhookWindowsHookEx( _glfwWin.KeyboardHook );

+            _glfwWin.KeyboardHook = NULL;

+        }

+    }

+    else

+    {

+        (void) SystemParametersInfo( SPI_SETSCREENSAVERRUNNING, FALSE,

+                                     &bOld, 0 );

+    }

+}

+

+void _glfwPlatformDisableSystemKeys( void )

+{

+    BOOL bOld;

+

+    // Use different methods depending on operating system version

+    if( _glfwLibrary.Sys.WinVer >= _GLFW_WIN_NT4 )

+    {

+        // Under Windows NT, install a low level keyboard hook

+        _glfwWin.KeyboardHook = SetWindowsHookEx( WH_KEYBOARD_LL,

+                                    _glfwLLKeyboardProc,

+                                    _glfwLibrary.Instance,

+                                    0 );

+    }

+    else

+    {

+        // Under Windows 95/98/ME, fool Windows that a screensaver

+        // is running => prevents ALT+TAB, CTRL+ESC and CTRL+ALT+DEL

+        (void) SystemParametersInfo( SPI_SETSCREENSAVERRUNNING, TRUE,

+                                     &bOld, 0 );

+    }

+}

+

diff --git a/src/engine/external/glfw/lib/win32/win32_fullscreen.c b/src/engine/external/glfw/lib/win32/win32_fullscreen.c
new file mode 100644
index 00000000..fcecee67
--- /dev/null
+++ b/src/engine/external/glfw/lib/win32/win32_fullscreen.c
@@ -0,0 +1,317 @@
+//========================================================================

+// GLFW - An OpenGL framework

+// File:        win32_fullscreen.c

+// Platform:    Windows

+// API version: 2.6

+// WWW:         http://glfw.sourceforge.net

+//------------------------------------------------------------------------

+// Copyright (c) 2002-2006 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"

+

+

+//************************************************************************

+//****                  GLFW internal functions                       ****

+//************************************************************************

+

+//========================================================================

+// _glfwBPP2RGB() - Convert BPP to RGB bits (based on "best guess")

+//========================================================================

+

+static void _glfwBPP2RGB( int bpp, int *r, int *g, int *b )

+{

+    int delta;

+

+    // Special case: BPP = 32

+    if( bpp == 32 ) bpp = 24;

+

+    // Convert "bits per pixel" to red, green & blue sizes

+    *r = *g = *b = bpp / 3;

+    delta = bpp - (*r * 3);

+    if( delta >= 1 )

+    {

+        *g = *g + 1;

+    }

+    if( delta == 2 )

+    {

+        *r = *r + 1;

+    }

+}

+

+

+//========================================================================

+// _glfwGetClosestVideoModeBPP()

+//========================================================================

+

+int _glfwGetClosestVideoModeBPP( int *w, int *h, int *bpp, int *refresh )

+{

+    int     mode, bestmode, match, bestmatch, rr, bestrr, success;

+    DEVMODE dm;

+

+    // Find best match

+    bestmatch = 0x7fffffff;

+    bestrr    = 0x7fffffff;

+    mode = bestmode = 0;

+    do

+    {

+        dm.dmSize = sizeof( DEVMODE );

+        success = EnumDisplaySettings( NULL, mode, &dm );

+        if( success )

+        {

+            match = dm.dmBitsPerPel - *bpp;

+            if( match < 0 ) match = -match;

+            match = ( match << 25 ) |

+                    ( (dm.dmPelsWidth - *w) *

+                      (dm.dmPelsWidth - *w) +

+                      (dm.dmPelsHeight - *h) *

+                      (dm.dmPelsHeight - *h) );

+            if( match < bestmatch )

+            {

+                bestmatch = match;

+                bestmode  = mode;

+                bestrr = (dm.dmDisplayFrequency - *refresh) *

+                         (dm.dmDisplayFrequency - *refresh);

+            }

+            else if( match == bestmatch && *refresh > 0 )

+            {

+                rr = (dm.dmDisplayFrequency - *refresh) *

+                     (dm.dmDisplayFrequency - *refresh);

+                if( rr < bestrr )

+                {

+                    bestmatch = match;

+                    bestmode  = mode;

+                    bestrr    = rr;

+                }

+            }

+        }

+        mode ++;

+    }

+    while( success );

+

+    // Get the parameters for the best matching display mode

+    dm.dmSize = sizeof( DEVMODE );

+    (void) EnumDisplaySettings( NULL, bestmode, &dm );

+

+    // Fill out actual width and height

+    *w = dm.dmPelsWidth;

+    *h = dm.dmPelsHeight;

+

+    // Return bits per pixel

+    *bpp = dm.dmBitsPerPel;

+

+    // Return vertical refresh rate

+    *refresh = dm.dmDisplayFrequency;

+

+    return bestmode;

+}

+

+

+//========================================================================

+// _glfwGetClosestVideoMode()

+//========================================================================

+

+int _glfwGetClosestVideoMode( int *w, int *h, int *r, int *g, int *b,

+    int *refresh )

+{

+    int     bpp, bestmode;

+

+    // Colorbits = sum of red/green/blue bits

+    bpp = *r + *g + *b;

+

+    // If colorbits < 15 (e.g. 0) or >= 24, default to 32 bpp

+    if( bpp < 15 || bpp >= 24 )

+    {

+        bpp = 32;

+    }

+

+    // Find best match

+    bestmode = _glfwGetClosestVideoModeBPP( w, h, &bpp, refresh );

+

+    // Convert "bits per pixel" to red, green & blue sizes

+    _glfwBPP2RGB( bpp, r, g, b );

+

+    return bestmode;

+}

+

+

+//========================================================================

+// Change the current video mode

+//========================================================================

+

+void _glfwSetVideoModeMODE( int mode )

+{

+    DEVMODE dm;

+    int     success;

+

+    // Get the parameters for the best matching display mode

+    dm.dmSize = sizeof( DEVMODE );

+    (void) EnumDisplaySettings( NULL, mode, &dm );

+

+    // Set which fields we want to specify

+    dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;

+

+    // Do we have a prefered refresh rate?

+    if( _glfwWin.DesiredRefreshRate > 0 )

+    {

+        dm.dmFields = dm.dmFields | DM_DISPLAYFREQUENCY;

+	dm.dmDisplayFrequency = _glfwWin.DesiredRefreshRate;

+    }

+

+    // Change display setting

+    dm.dmSize = sizeof( DEVMODE );

+    success = ChangeDisplaySettings( &dm, CDS_FULLSCREEN );

+

+    // If the mode change was not possible, query the current display

+    // settings (we'll use the desktop resolution for fullscreen mode)

+    if( success == DISP_CHANGE_SUCCESSFUL )

+    {

+        _glfwWin.ModeID = mode;

+    }

+    else

+    {

+        _glfwWin.ModeID = ENUM_REGISTRY_SETTINGS;

+        EnumDisplaySettings( NULL, ENUM_REGISTRY_SETTINGS, &dm );

+    }

+

+    // Set the window size to that of the display mode

+    _glfwWin.Width  = dm.dmPelsWidth;

+    _glfwWin.Height = dm.dmPelsHeight;

+}

+

+

+//========================================================================

+// _glfwSetVideoMode() - Change the current video mode

+//========================================================================

+

+void _glfwSetVideoMode( int *w, int *h, int r, int g, int b, int refresh )

+{

+    int     bestmode;

+

+    // Find a best match mode

+    bestmode = _glfwGetClosestVideoMode( w, h, &r, &g, &b, &refresh );

+

+    // Change mode

+    _glfwSetVideoModeMODE( bestmode );

+}

+

+

+//************************************************************************

+//****                    GLFW user functions                         ****

+//************************************************************************

+

+//========================================================================

+// _glfwPlatformGetVideoModes() - Get a list of available video modes

+//========================================================================

+

+int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )

+{

+    int count, success, mode, i, j;

+    int m1, m2, bpp, r, g, b;

+    DEVMODE dm;

+

+    // Loop through all video modes and extract all the UNIQUE modes

+    count = 0;

+    mode  = 0;

+    do

+    {

+        // Get video mode properties

+        dm.dmSize = sizeof( DEVMODE );

+        success = EnumDisplaySettings( NULL, mode, &dm );

+

+        // Is it a valid mode? (only list depths >= 15 bpp)

+        if( success && dm.dmBitsPerPel >= 15 )

+        {

+            // Convert to RGB, and back to bpp ("mask out" alpha bits etc)

+            _glfwBPP2RGB( dm.dmBitsPerPel, &r, &g, &b );

+            bpp = r + g + b;

+

+            // Mode "code" for this mode

+            m1 = (bpp << 25) | (dm.dmPelsWidth * dm.dmPelsHeight);

+

+            // Insert mode in list (sorted), and avoid duplicates

+            for( i = 0; i < count; i ++ )

+            {

+                // Mode "code" for already listed mode

+                bpp = list[i].RedBits + list[i].GreenBits +

+                      list[i].BlueBits;

+                m2 = (bpp << 25) | (list[i].Width * list[i].Height);

+                if( m1 <= m2 )

+                {

+                    break;

+                }

+            }

+

+            // New entry at the end of the list?

+            if( i >= count )

+            {

+                list[count].Width     = dm.dmPelsWidth;

+                list[count].Height    = dm.dmPelsHeight;

+                list[count].RedBits   = r;

+                list[count].GreenBits = g;

+                list[count].BlueBits  = b;

+                count ++;

+            }

+            // Insert new entry in the list?

+            else if( m1 < m2 )

+            {

+                for( j = count; j > i; j -- )

+                {

+                    list[j] = list[j-1];

+                }

+                list[i].Width     = dm.dmPelsWidth;

+                list[i].Height    = dm.dmPelsHeight;

+                list[i].RedBits   = r;

+                list[i].GreenBits = g;

+                list[i].BlueBits  = b;

+                count ++;

+            }

+        }

+        mode ++;

+    }

+    while( success && (count < maxcount) );

+

+    return count;

+}

+

+

+//========================================================================

+// _glfwPlatformGetDesktopMode() - Get the desktop video mode

+//========================================================================

+

+void _glfwPlatformGetDesktopMode( GLFWvidmode *mode )

+{

+    DEVMODE dm;

+

+    // Get desktop display mode

+    dm.dmSize = sizeof( DEVMODE );

+    (void) EnumDisplaySettings( NULL, ENUM_REGISTRY_SETTINGS, &dm );

+

+    // Return desktop mode parameters

+    mode->Width  = dm.dmPelsWidth;

+    mode->Height = dm.dmPelsHeight;

+    _glfwBPP2RGB( dm.dmBitsPerPel, &mode->RedBits, &mode->GreenBits,

+                  &mode->BlueBits );

+}

+

+

diff --git a/src/engine/external/glfw/lib/win32/win32_glext.c b/src/engine/external/glfw/lib/win32/win32_glext.c
new file mode 100644
index 00000000..00d2767d
--- /dev/null
+++ b/src/engine/external/glfw/lib/win32/win32_glext.c
@@ -0,0 +1,101 @@
+//========================================================================

+// GLFW - An OpenGL framework

+// File:        win32_glext.c

+// Platform:    Windows

+// API version: 2.6

+// WWW:         http://glfw.sourceforge.net

+//------------------------------------------------------------------------

+// Copyright (c) 2002-2006 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"

+

+

+//========================================================================

+// We use the WGL_EXT_extensions_string if it is available, or

+// WGL_ARB_extensions_string if it is available.

+//========================================================================

+

+typedef const char *(APIENTRY * WGLGETEXTENSIONSSTRINGEXT_T)( void );

+typedef const char *(APIENTRY * WGLGETEXTENSIONSSTRINGARB_T)( HDC hdc );

+

+

+

+//************************************************************************

+//****               Platform implementation functions                ****

+//************************************************************************

+

+//========================================================================

+// Check if an OpenGL extension is available at runtime (Windows version checks

+// for WGL extensions)

+//========================================================================

+

+int _glfwPlatformExtensionSupported( const char *extension )

+{

+    const GLubyte *extensions;

+    WGLGETEXTENSIONSSTRINGEXT_T _wglGetExtensionsStringEXT;

+    WGLGETEXTENSIONSSTRINGARB_T _wglGetExtensionsStringARB;

+

+    // Try wglGetExtensionsStringEXT

+    _wglGetExtensionsStringEXT = (WGLGETEXTENSIONSSTRINGEXT_T)

+        wglGetProcAddress( "wglGetExtensionsStringEXT" );

+    if( _wglGetExtensionsStringEXT != NULL )

+    {

+        extensions = (GLubyte *) _wglGetExtensionsStringEXT();

+        if( extensions != NULL )

+        {

+            if( _glfwStringInExtensionString( extension, extensions ) )

+            {

+                return GL_TRUE;

+            }

+        }

+    }

+

+    // Try wglGetExtensionsStringARB

+    _wglGetExtensionsStringARB = (WGLGETEXTENSIONSSTRINGARB_T)

+        wglGetProcAddress( "wglGetExtensionsStringARB" );

+    if( _wglGetExtensionsStringARB != NULL )

+    {

+        extensions = (GLubyte *) _wglGetExtensionsStringARB(_glfwWin.DC);

+        if( extensions != NULL )

+        {

+            if( _glfwStringInExtensionString( extension, extensions ) )

+            {

+                return GL_TRUE;

+            }

+        }

+    }

+

+    return GL_FALSE;

+}

+

+

+//========================================================================

+// Get the function pointer to an OpenGL function

+//========================================================================

+

+void * _glfwPlatformGetProcAddress( const char *procname )

+{

+    return (void *) wglGetProcAddress( procname );

+}

+

diff --git a/src/engine/external/glfw/lib/win32/win32_init.c b/src/engine/external/glfw/lib/win32/win32_init.c
new file mode 100644
index 00000000..41d7150a
--- /dev/null
+++ b/src/engine/external/glfw/lib/win32/win32_init.c
@@ -0,0 +1,356 @@
+//========================================================================

+// GLFW - An OpenGL framework

+// File:        win32_init.c

+// Platform:    Windows

+// API version: 2.6

+// WWW:         http://glfw.sourceforge.net

+//------------------------------------------------------------------------

+// Copyright (c) 2002-2006 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 <float.h>

+#endif // __BORLANDC__

+

+

+

+//************************************************************************

+//****                  GLFW internal functions                       ****

+//************************************************************************

+

+//========================================================================

+// _glfwInitLibraries() - Load necessary libraries (DLLs)

+//========================================================================

+

+static int _glfwInitLibraries( void )

+{

+    // gdi32.dll (OpenGL pixel format functions & SwapBuffers)

+#ifndef _GLFW_NO_DLOAD_GDI32

+    _glfwLibrary.Libs.gdi32 = LoadLibrary( "gdi32.dll" );

+    if( _glfwLibrary.Libs.gdi32 != NULL )

+    {

+        _glfwLibrary.Libs.ChoosePixelFormat   = (CHOOSEPIXELFORMAT_T)

+            GetProcAddress( _glfwLibrary.Libs.gdi32, "ChoosePixelFormat" );

+        _glfwLibrary.Libs.DescribePixelFormat = (DESCRIBEPIXELFORMAT_T)

+            GetProcAddress( _glfwLibrary.Libs.gdi32, "DescribePixelFormat" );

+        _glfwLibrary.Libs.GetPixelFormat      = (GETPIXELFORMAT_T)

+            GetProcAddress( _glfwLibrary.Libs.gdi32, "GetPixelFormat" );

+        _glfwLibrary.Libs.SetPixelFormat      = (SETPIXELFORMAT_T)

+            GetProcAddress( _glfwLibrary.Libs.gdi32, "SetPixelFormat" );

+        _glfwLibrary.Libs.SwapBuffers         = (SWAPBUFFERS_T)

+            GetProcAddress( _glfwLibrary.Libs.gdi32, "SwapBuffers" );

+        if( _glfwLibrary.Libs.ChoosePixelFormat   == NULL ||

+            _glfwLibrary.Libs.DescribePixelFormat == NULL ||

+            _glfwLibrary.Libs.GetPixelFormat      == NULL ||

+            _glfwLibrary.Libs.SetPixelFormat      == NULL ||

+            _glfwLibrary.Libs.SwapBuffers         == NULL )

+        {

+            FreeLibrary( _glfwLibrary.Libs.gdi32 );

+            _glfwLibrary.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.Libs.winmm = LoadLibrary( "winmm.dll" );

+    if( _glfwLibrary.Libs.winmm != NULL )

+    {

+        _glfwLibrary.Libs.joyGetDevCapsA = (JOYGETDEVCAPSA_T)

+            GetProcAddress( _glfwLibrary.Libs.winmm, "joyGetDevCapsA" );

+        _glfwLibrary.Libs.joyGetPos      = (JOYGETPOS_T)

+            GetProcAddress( _glfwLibrary.Libs.winmm, "joyGetPos" );

+        _glfwLibrary.Libs.joyGetPosEx    = (JOYGETPOSEX_T)

+            GetProcAddress( _glfwLibrary.Libs.winmm, "joyGetPosEx" );

+        _glfwLibrary.Libs.timeGetTime    = (TIMEGETTIME_T)

+            GetProcAddress( _glfwLibrary.Libs.winmm, "timeGetTime" );

+        if( _glfwLibrary.Libs.joyGetDevCapsA == NULL ||

+            _glfwLibrary.Libs.joyGetPos      == NULL ||

+            _glfwLibrary.Libs.joyGetPosEx    == NULL ||

+            _glfwLibrary.Libs.timeGetTime    == NULL )

+        {

+            FreeLibrary( _glfwLibrary.Libs.winmm );

+            _glfwLibrary.Libs.winmm = NULL;

+            return GL_FALSE;

+        }

+    }

+    else

+    {

+        return GL_FALSE;

+    }

+#endif // _GLFW_NO_DLOAD_WINMM

+

+    return GL_TRUE;

+}

+

+

+//========================================================================

+// _glfwFreeLibraries() - Unload used libraries (DLLs)

+//========================================================================

+

+static void _glfwFreeLibraries( void )

+{

+    // gdi32.dll

+#ifndef _GLFW_NO_DLOAD_GDI32

+    if( _glfwLibrary.Libs.gdi32 != NULL )

+    {

+        FreeLibrary( _glfwLibrary.Libs.gdi32 );

+        _glfwLibrary.Libs.gdi32 = NULL;

+    }

+#endif // _GLFW_NO_DLOAD_GDI32

+

+    // winmm.dll

+#ifndef _GLFW_NO_DLOAD_WINMM

+    if( _glfwLibrary.Libs.winmm != NULL )

+    {

+        FreeLibrary( _glfwLibrary.Libs.winmm );

+        _glfwLibrary.Libs.winmm = NULL;

+    }

+#endif // _GLFW_NO_DLOAD_WINMM

+}

+

+

+//========================================================================

+// _glfwInitThreads() - Initialize GLFW thread package

+//========================================================================

+

+static void _glfwInitThreads( void )

+{

+    // Initialize critical section handle

+    InitializeCriticalSection( &_glfwThrd.CriticalSection );

+

+    // The first thread (the main thread) has ID 0

+    _glfwThrd.NextID = 0;

+

+    // Fill out information about the main thread (this thread)

+    _glfwThrd.First.ID       = _glfwThrd.NextID ++;

+    _glfwThrd.First.Function = NULL;

+    _glfwThrd.First.Handle   = GetCurrentThread();

+    _glfwThrd.First.WinID    = GetCurrentThreadId();

+    _glfwThrd.First.Previous = NULL;

+    _glfwThrd.First.Next     = NULL;

+}

+

+

+//========================================================================

+// _glfwTerminateThreads() - Terminate GLFW thread package

+//========================================================================

+

+static void _glfwTerminateThreads( void )

+{

+    _GLFWthread *t, *t_next;

+

+    // Enter critical section

+    ENTER_THREAD_CRITICAL_SECTION

+

+    // Kill all threads (NOTE: THE USER SHOULD WAIT FOR ALL THREADS TO

+    // DIE, _BEFORE_ CALLING glfwTerminate()!!!)

+    t = _glfwThrd.First.Next;

+    while( t != NULL )

+    {

+        // Get pointer to next thread

+        t_next = t->Next;

+

+        // Simply murder the process, no mercy!

+        if( TerminateThread( t->Handle, 0 ) )

+        {

+            // Close thread handle

+            CloseHandle( t->Handle );

+

+            // Free memory allocated for this thread

+            free( (void *) t );

+        }

+

+        // Select next thread in list

+        t = t_next;

+    }

+

+    // Leave critical section

+    LEAVE_THREAD_CRITICAL_SECTION

+

+    // Delete critical section handle

+    DeleteCriticalSection( &_glfwThrd.CriticalSection );

+}

+

+

+//========================================================================

+// _glfwTerminate_atexit() - Terminate GLFW when exiting application

+//========================================================================

+

+void _glfwTerminate_atexit( void )

+{

+    glfwTerminate();

+}

+

+

+

+//************************************************************************

+//****               Platform implementation functions                ****

+//************************************************************************

+

+//========================================================================

+// _glfwPlatformInit() - 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.Sys.ForegroundLockTimeout, 0 );

+    SystemParametersInfo( SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID)0,

+                          SPIF_SENDCHANGE );

+

+    // Check which OS version we are running

+    osi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );

+    GetVersionEx( &osi );

+    _glfwLibrary.Sys.WinVer = _GLFW_WIN_UNKNOWN;

+    if( osi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )

+    {

+        if( osi.dwMajorVersion == 4 && osi.dwMinorVersion < 10 )

+        {

+            _glfwLibrary.Sys.WinVer = _GLFW_WIN_95;

+        }

+        else if( osi.dwMajorVersion == 4 && osi.dwMinorVersion < 90 )

+        {

+            _glfwLibrary.Sys.WinVer = _GLFW_WIN_98;

+        }

+        else if( osi.dwMajorVersion == 4 && osi.dwMinorVersion == 90 )

+        {

+            _glfwLibrary.Sys.WinVer = _GLFW_WIN_ME;

+        }

+        else if( osi.dwMajorVersion >= 4 )

+        {

+            _glfwLibrary.Sys.WinVer = _GLFW_WIN_UNKNOWN_9x;

+        }

+    }

+    else if( osi.dwPlatformId == VER_PLATFORM_WIN32_NT )

+    {

+        if( osi.dwMajorVersion == 4 && osi.dwMinorVersion == 0 )

+        {

+            _glfwLibrary.Sys.WinVer = _GLFW_WIN_NT4;

+        }

+        else if( osi.dwMajorVersion == 5 && osi.dwMinorVersion == 0 )

+        {

+            _glfwLibrary.Sys.WinVer = _GLFW_WIN_2K;

+        }

+        else if( osi.dwMajorVersion == 5 && osi.dwMinorVersion == 1 )

+        {

+            _glfwLibrary.Sys.WinVer = _GLFW_WIN_XP;

+        }

+        else if( osi.dwMajorVersion == 5 && osi.dwMinorVersion == 2 )

+        {

+            _glfwLibrary.Sys.WinVer = _GLFW_WIN_NET_SERVER;

+        }

+        else if( osi.dwMajorVersion >= 5 )

+        {

+            _glfwLibrary.Sys.WinVer = _GLFW_WIN_UNKNOWN_NT;

+        }

+    }

+

+    // Do we have Unicode support?

+    if( _glfwLibrary.Sys.WinVer >= _GLFW_WIN_NT4 )

+    {

+        // Windows NT/2000/XP/.NET has Unicode support

+        _glfwLibrary.Sys.HasUnicode = GL_TRUE;

+    }

+    else

+    {

+        // Windows 9x/ME does not have Unicode support

+        _glfwLibrary.Sys.HasUnicode = GL_FALSE;

+    }

+

+    // 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.Instance = GetModuleHandle( NULL );

+

+    // System keys are not disabled

+    _glfwWin.KeyboardHook = NULL;

+

+    // Initialise thread package

+    _glfwInitThreads();

+

+    // Install atexit() routine

+    atexit( _glfwTerminate_atexit );

+

+    // Start the timer

+    _glfwInitTimer();

+

+    return GL_TRUE;

+}

+

+

+//========================================================================

+// _glfwPlatformTerminate() - Close window and kill all threads

+//========================================================================

+

+int _glfwPlatformTerminate( void )

+{

+    // Only the main thread is allowed to do this...

+    if( GetCurrentThreadId() != _glfwThrd.First.WinID )

+    {

+        return GL_FALSE;

+    }

+

+    // Close OpenGL window

+    glfwCloseWindow();

+

+    // Kill thread package

+    _glfwTerminateThreads();

+

+    // 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.Sys.ForegroundLockTimeout,

+                          SPIF_SENDCHANGE );

+

+    return GL_TRUE;

+}

+

diff --git a/src/engine/external/glfw/lib/win32/win32_joystick.c b/src/engine/external/glfw/lib/win32/win32_joystick.c
new file mode 100644
index 00000000..5ab00319
--- /dev/null
+++ b/src/engine/external/glfw/lib/win32/win32_joystick.c
@@ -0,0 +1,234 @@
+//========================================================================

+// GLFW - An OpenGL framework

+// File:        win32_joystick.c

+// Platform:    Windows

+// API version: 2.6

+// WWW:         http://glfw.sourceforge.net

+//------------------------------------------------------------------------

+// Copyright (c) 2002-2006 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"

+

+

+//************************************************************************

+//****                  GLFW internal functions                       ****

+//************************************************************************

+

+//========================================================================

+// _glfwJoystickPresent() - Return GL_TRUE if joystick is present,

+// else return GL_FALSE.

+//========================================================================

+

+static int _glfwJoystickPresent( int joy )

+{

+    JOYINFO ji;

+

+    // Windows NT 4.0 MMSYSTEM only supports 2 sticks (other Windows

+    // versions support 16 sticks)

+    if( _glfwLibrary.Sys.WinVer == _GLFW_WIN_NT4 && joy > GLFW_JOYSTICK_2 )

+    {

+        return GL_FALSE;

+    }

+

+    // Is it a valid stick ID (Windows don't support more than 16 sticks)?

+    if( joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_16 )

+    {

+        return GL_FALSE;

+    }

+

+    // Is the joystick present?

+    if( _glfw_joyGetPos( joy - GLFW_JOYSTICK_1, &ji ) != JOYERR_NOERROR )

+    {

+        return GL_FALSE;

+    }

+

+    return GL_TRUE;

+}

+

+

+//========================================================================

+// _glfwCalcJoystickPos() - Calculate joystick position

+//========================================================================

+

+static float _glfwCalcJoystickPos( DWORD pos, DWORD min, DWORD max )

+{

+    float fpos = (float) pos;

+    float fmin = (float) min;

+    float fmax = (float) max;

+    return (2.0f*(fpos - fmin) / (fmax - fmin)) - 1.0f;

+}

+

+

+

+//************************************************************************

+//****               Platform implementation functions                ****

+//************************************************************************

+

+//========================================================================

+// _glfwPlatformGetJoystickParam() - Determine joystick capabilities

+//========================================================================

+

+int _glfwPlatformGetJoystickParam( int joy, int param )

+{

+    JOYCAPS jc;

+

+//  return 0;

+

+    // Is joystick present?

+    if( !_glfwJoystickPresent( joy ) )

+    {

+        return 0;

+    }

+

+    // We got this far, the joystick is present

+    if( param == GLFW_PRESENT )

+    {

+        return GL_TRUE;

+    }

+

+    // Get joystick capabilities

+    _glfw_joyGetDevCaps( joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS) );

+

+    switch( param )

+    {

+    case GLFW_AXES:

+        // Return number of joystick axes

+        return jc.wNumAxes;

+

+    case GLFW_BUTTONS:

+        // Return number of joystick axes

+        return jc.wNumButtons;

+

+    default:

+        break;

+    }

+

+    return 0;

+}

+

+

+//========================================================================

+// _glfwPlatformGetJoystickPos() - Get joystick axis positions

+//========================================================================

+

+int _glfwPlatformGetJoystickPos( int joy, float *pos, int numaxes )

+{

+    JOYCAPS   jc;

+    JOYINFOEX ji;

+    int       axis;

+

+//  return 0;

+

+    // Is joystick present?

+    if( !_glfwJoystickPresent( joy ) )

+    {

+        return 0;

+    }

+

+    // Get joystick capabilities

+    _glfw_joyGetDevCaps( joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS) );

+

+    // Get joystick state

+    ji.dwSize = sizeof( JOYINFOEX );

+    ji.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ |

+                 JOY_RETURNR | JOY_RETURNU | JOY_RETURNV;

+    _glfw_joyGetPosEx( joy - GLFW_JOYSTICK_1, &ji );

+

+    // Get position values for all axes

+    axis = 0;

+    if( axis < numaxes )

+    {

+        pos[ axis++ ] = _glfwCalcJoystickPos( ji.dwXpos, jc.wXmin,

+                                              jc.wXmax );

+    }

+    if( axis < numaxes )

+    {

+        pos[ axis++ ] = -_glfwCalcJoystickPos( ji.dwYpos, jc.wYmin,

+                                               jc.wYmax );

+    }

+    if( axis < numaxes && jc.wCaps & JOYCAPS_HASZ )

+    {

+        pos[ axis++ ] = _glfwCalcJoystickPos( ji.dwZpos, jc.wZmin,

+                                              jc.wZmax );

+    }

+    if( axis < numaxes && jc.wCaps & JOYCAPS_HASR )

+    {

+        pos[ axis++ ] = _glfwCalcJoystickPos( ji.dwRpos, jc.wRmin,

+                                              jc.wRmax );

+    }

+    if( axis < numaxes && jc.wCaps & JOYCAPS_HASU )

+    {

+        pos[ axis++ ] = _glfwCalcJoystickPos( ji.dwUpos, jc.wUmin,

+                                              jc.wUmax );

+    }

+    if( axis < numaxes && jc.wCaps & JOYCAPS_HASV )

+    {

+        pos[ axis++ ] = -_glfwCalcJoystickPos( ji.dwVpos, jc.wVmin,

+                                               jc.wVmax );

+    }

+

+    // Return number of returned axes

+    return axis;

+}

+

+

+//========================================================================

+// _glfwPlatformGetJoystickButtons() - Get joystick button states

+//========================================================================

+

+int _glfwPlatformGetJoystickButtons( int joy, unsigned char *buttons,

+    int numbuttons )

+{

+    JOYCAPS   jc;

+    JOYINFOEX ji;

+    int       button;

+

+//  return 0;

+

+    // Is joystick present?

+    if( !_glfwJoystickPresent( joy ) )

+    {

+        return 0;

+    }

+

+    // Get joystick capabilities

+    _glfw_joyGetDevCaps( joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS) );

+

+    // Get joystick state

+    ji.dwSize = sizeof( JOYINFOEX );

+    ji.dwFlags = JOY_RETURNBUTTONS;

+    _glfw_joyGetPosEx( joy - GLFW_JOYSTICK_1, &ji );

+

+    // Get states of all requested buttons

+    button = 0;

+    while( button < numbuttons && button < (int) jc.wNumButtons )

+    {

+        buttons[ button ] = (unsigned char)

+            (ji.dwButtons & (1UL << button) ? GLFW_PRESS : GLFW_RELEASE);

+        button ++;

+    }

+

+    return button;

+}

+

diff --git a/src/engine/external/glfw/lib/win32/win32_thread.c b/src/engine/external/glfw/lib/win32/win32_thread.c
new file mode 100644
index 00000000..159347a7
--- /dev/null
+++ b/src/engine/external/glfw/lib/win32/win32_thread.c
@@ -0,0 +1,511 @@
+//========================================================================

+// GLFW - An OpenGL framework

+// File:        win32_thread.c

+// Platform:    Windows

+// API version: 2.6

+// WWW:         http://glfw.sourceforge.net

+//------------------------------------------------------------------------

+// Copyright (c) 2002-2006 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"

+

+

+//************************************************************************

+// This is an implementation of POSIX "compatible" condition variables for

+// Win32, as described by Douglas C. Schmidt and Irfan Pyarali:

+// http://www.cs.wustl.edu/~schmidt/win32-cv-1.html

+//************************************************************************

+

+enum {

+    _GLFW_COND_SIGNAL     = 0,

+    _GLFW_COND_BROADCAST  = 1

+};

+

+typedef struct {

+    // Signal and broadcast event HANDLEs

+    HANDLE events[ 2 ];

+

+    // Count of the number of waiters

+    unsigned int waiters_count;

+

+    // Serialize access to <waiters_count>

+    CRITICAL_SECTION waiters_count_lock;

+} _GLFWcond;

+

+

+

+//************************************************************************

+//****                  GLFW internal functions                       ****

+//************************************************************************

+

+//========================================================================

+// _glfwNewThread() - This is simply a "wrapper" for calling the user

+// thread function.

+//========================================================================

+

+DWORD WINAPI _glfwNewThread( LPVOID lpParam )

+{

+    GLFWthreadfun threadfun;

+    _GLFWthread   *t;

+

+    // Get pointer to thread information for current thread

+    t = _glfwGetThreadPointer( _glfwPlatformGetThreadID() );

+    if( t == NULL )

+    {

+        return 0;

+    }

+

+    // Get user thread function pointer

+    threadfun = t->Function;

+

+    // Call the user thread function

+    threadfun( (void *) lpParam );

+

+    // Remove thread from thread list

+    ENTER_THREAD_CRITICAL_SECTION

+    _glfwRemoveThread( t );

+    LEAVE_THREAD_CRITICAL_SECTION

+

+    // When the thread function returns, the thread will die...

+    return 0;

+}

+

+

+

+//************************************************************************

+//****                     GLFW user functions                        ****

+//************************************************************************

+

+//========================================================================

+// _glfwPlatformCreateThread() - Create a new thread

+//========================================================================

+

+GLFWthread _glfwPlatformCreateThread( GLFWthreadfun fun, void *arg )

+{

+    GLFWthread  ID;

+    _GLFWthread *t, *t_tmp;

+    HANDLE      hThread;

+    DWORD       dwThreadId;

+

+    // Enter critical section

+    ENTER_THREAD_CRITICAL_SECTION

+

+    // Create a new thread information memory area

+    t = (_GLFWthread *) malloc( sizeof(_GLFWthread) );

+    if( t == NULL )

+    {

+        // Leave critical section

+        LEAVE_THREAD_CRITICAL_SECTION

+        return -1;

+    }

+

+    // Get a new unique thread id

+    ID = _glfwThrd.NextID ++;

+

+    // Store thread information in the thread list

+    t->Function = fun;

+    t->ID       = ID;

+

+    // Create thread

+    hThread = CreateThread(

+        NULL,              // Default security attributes

+        0,                 // Default stack size (1 MB)

+        _glfwNewThread,    // Thread function (a wrapper function)

+        (LPVOID)arg,       // Argument to thread is the user argument

+        0,                 // Default creation flags

+        &dwThreadId        // Returned thread identifier

+    );

+

+    // Did the thread creation fail?

+    if( hThread == NULL )

+    {

+        free( (void *) t );

+        LEAVE_THREAD_CRITICAL_SECTION

+        return -1;

+    }

+

+    // Store more thread information in the thread list

+    t->Handle = hThread;

+    t->WinID  = dwThreadId;

+

+    // Append thread to thread list

+    t_tmp = &_glfwThrd.First;

+    while( t_tmp->Next != NULL )

+    {

+        t_tmp = t_tmp->Next;

+    }

+    t_tmp->Next = t;

+    t->Previous = t_tmp;

+    t->Next     = NULL;

+

+    // Leave critical section

+    LEAVE_THREAD_CRITICAL_SECTION

+

+    // Return the GLFW thread ID

+    return ID;

+}

+

+

+//========================================================================

+// _glfwPlatformDestroyThread() - Kill a thread. NOTE: THIS IS A VERY

+// DANGEROUS OPERATION, AND SHOULD NOT BE USED EXCEPT IN EXTREME

+// SITUATIONS!

+//========================================================================

+

+void _glfwPlatformDestroyThread( GLFWthread ID )

+{

+    _GLFWthread *t;

+

+    // Enter critical section

+    ENTER_THREAD_CRITICAL_SECTION

+

+    // Get thread information pointer

+    t = _glfwGetThreadPointer( ID );

+    if( t == NULL )

+    {

+        LEAVE_THREAD_CRITICAL_SECTION

+        return;

+    }

+

+    // Simply murder the process, no mercy!

+    if( TerminateThread( t->Handle, 0 ) )

+    {

+        // Close thread handle

+        CloseHandle( t->Handle );

+

+        // Remove thread from thread list

+        _glfwRemoveThread( t );

+    }

+

+    // Leave critical section

+    LEAVE_THREAD_CRITICAL_SECTION

+}

+

+

+//========================================================================

+// _glfwPlatformWaitThread() - Wait for a thread to die

+//========================================================================

+

+int _glfwPlatformWaitThread( GLFWthread ID, int waitmode )

+{

+    DWORD       result;

+    HANDLE      hThread;

+    _GLFWthread *t;

+

+    // Enter critical section

+    ENTER_THREAD_CRITICAL_SECTION

+

+    // Get thread information pointer

+    t = _glfwGetThreadPointer( ID );

+

+    // Is the thread already dead?

+    if( t == NULL )

+    {

+        LEAVE_THREAD_CRITICAL_SECTION

+        return GL_TRUE;

+    }

+

+    // Get thread handle

+    hThread = t->Handle;

+

+    // Leave critical section

+    LEAVE_THREAD_CRITICAL_SECTION

+

+    // Wait for thread to die

+    if( waitmode == GLFW_WAIT )

+    {

+        result = WaitForSingleObject( hThread, INFINITE );

+    }

+    else if( waitmode == GLFW_NOWAIT )

+    {

+        result = WaitForSingleObject( hThread, 0 );

+    }

+    else

+    {

+        return GL_FALSE;

+    }

+

+    // Did we have a time-out?

+    if( result == WAIT_TIMEOUT )

+    {

+        return GL_FALSE;

+    }

+    return GL_TRUE;

+}

+

+

+//========================================================================

+// _glfwPlatformGetThreadID() - Return the thread ID for the current

+// thread

+//========================================================================

+

+GLFWthread _glfwPlatformGetThreadID( void )

+{

+    _GLFWthread *t;

+    GLFWthread  ID = -1;

+    DWORD       WinID;

+

+    // Get Windows thread ID

+    WinID = GetCurrentThreadId();

+

+    // Enter critical section (to avoid an inconsistent thread list)

+    ENTER_THREAD_CRITICAL_SECTION

+

+    // Loop through entire list of threads to find the matching Windows

+    // thread ID

+    for( t = &_glfwThrd.First; t != NULL; t = t->Next )

+    {

+        if( t->WinID == WinID )

+        {

+            ID = t->ID;

+            break;

+        }

+    }

+

+    // Leave critical section

+    LEAVE_THREAD_CRITICAL_SECTION

+

+    // Return the found GLFW thread identifier

+    return ID;

+}

+

+

+//========================================================================

+// _glfwPlatformCreateMutex() - Create a mutual exclusion object

+//========================================================================

+

+GLFWmutex _glfwPlatformCreateMutex( void )

+{

+    CRITICAL_SECTION *mutex;

+

+    // Allocate memory for mutex

+    mutex = (CRITICAL_SECTION *) malloc( sizeof(CRITICAL_SECTION) );

+    if( !mutex )

+    {

+        return NULL;

+    }

+

+    // Initialize mutex

+    InitializeCriticalSection( mutex );

+

+    // Cast to GLFWmutex and return

+    return (GLFWmutex) mutex;

+}

+

+

+//========================================================================

+// glfwDestroyMutex() - Destroy a mutual exclusion object

+//========================================================================

+

+void _glfwPlatformDestroyMutex( GLFWmutex mutex )

+{

+    // Destroy mutex

+    DeleteCriticalSection( (CRITICAL_SECTION *) mutex );

+    free( mutex );

+}

+

+

+//========================================================================

+// _glfwPlatformLockMutex() - Request access to a mutex

+//========================================================================

+

+void _glfwPlatformLockMutex( GLFWmutex mutex )

+{

+    // Wait for mutex to be released

+    EnterCriticalSection( (CRITICAL_SECTION *) mutex );

+}

+

+

+//========================================================================

+// _glfwPlatformUnlockMutex() - Release a mutex

+//========================================================================

+

+void _glfwPlatformUnlockMutex( GLFWmutex mutex )

+{

+    // Release mutex

+    LeaveCriticalSection( (CRITICAL_SECTION *) mutex );

+}

+

+

+//========================================================================

+// _glfwPlatformCreateCond() - Create a new condition variable object

+//========================================================================

+

+GLFWcond _glfwPlatformCreateCond( void )

+{

+    _GLFWcond   *cond;

+

+    // Allocate memory for condition variable

+    cond = (_GLFWcond *) malloc( sizeof(_GLFWcond) );

+    if( !cond )

+    {

+        return NULL;

+    }

+

+    // Initialize condition variable

+    cond->waiters_count = 0;

+    cond->events[ _GLFW_COND_SIGNAL ]    = CreateEvent( NULL, FALSE,

+                                                        FALSE, NULL );

+    cond->events[ _GLFW_COND_BROADCAST ] = CreateEvent( NULL, TRUE,

+                                                        FALSE, NULL );

+    InitializeCriticalSection( &cond->waiters_count_lock );

+

+    // Cast to GLFWcond and return

+    return (GLFWcond) cond;

+}

+

+

+//========================================================================

+// _glfwPlatformDestroyCond() - Destroy a condition variable object

+//========================================================================

+

+void _glfwPlatformDestroyCond( GLFWcond cond )

+{

+    // Close the condition variable handles

+    CloseHandle( ((_GLFWcond *)cond)->events[ _GLFW_COND_SIGNAL ] );

+    CloseHandle( ((_GLFWcond *)cond)->events[ _GLFW_COND_BROADCAST ] );

+

+    // Delete critical section

+    DeleteCriticalSection( &((_GLFWcond *)cond)->waiters_count_lock );

+

+    // Free memory for condition variable

+    free( (void *) cond );

+}

+

+

+//========================================================================

+// _glfwPlatformWaitCond() - Wait for a condition to be raised

+//========================================================================

+

+void _glfwPlatformWaitCond( GLFWcond cond, GLFWmutex mutex,

+    double timeout )

+{

+    _GLFWcond *cv = (_GLFWcond *) cond;

+    int       result, last_waiter;

+    DWORD     timeout_ms;

+

+    // Avoid race conditions

+    EnterCriticalSection( &cv->waiters_count_lock );

+    cv->waiters_count ++;

+    LeaveCriticalSection( &cv->waiters_count_lock );

+

+    // It's ok to release the mutex here since Win32 manual-reset events

+    // maintain state when used with SetEvent()

+    LeaveCriticalSection( (CRITICAL_SECTION *) mutex );

+

+    // Translate timeout into milliseconds

+    if( timeout >= GLFW_INFINITY )

+    {

+        timeout_ms = INFINITE;

+    }

+    else

+    {

+        timeout_ms = (DWORD) (1000.0 * timeout + 0.5);

+        if( timeout_ms <= 0 )

+        {

+            timeout_ms = 1;

+        }

+    }

+

+    // Wait for either event to become signaled due to glfwSignalCond or

+    // glfwBroadcastCond being called

+    result = WaitForMultipleObjects( 2, cv->events, FALSE, timeout_ms );

+

+    // Check if we are the last waiter

+    EnterCriticalSection( &cv->waiters_count_lock );

+    cv->waiters_count --;

+    last_waiter = (result == WAIT_OBJECT_0 + _GLFW_COND_BROADCAST) &&

+                  (cv->waiters_count == 0);

+    LeaveCriticalSection( &cv->waiters_count_lock );

+

+    // Some thread called glfwBroadcastCond

+    if( last_waiter )

+    {

+        // We're the last waiter to be notified or to stop waiting, so

+        // reset the manual event

+        ResetEvent( cv->events[ _GLFW_COND_BROADCAST ] );

+    }

+

+    // Reacquire the mutex

+    EnterCriticalSection( (CRITICAL_SECTION *) mutex );

+}

+

+

+//========================================================================

+// _glfwPlatformSignalCond() - Signal a condition to one waiting thread

+//========================================================================

+

+void _glfwPlatformSignalCond( GLFWcond cond )

+{

+    _GLFWcond *cv = (_GLFWcond *) cond;

+    int       have_waiters;

+

+    // Avoid race conditions

+    EnterCriticalSection( &cv->waiters_count_lock );

+    have_waiters = cv->waiters_count > 0;

+    LeaveCriticalSection( &cv->waiters_count_lock );

+

+    if( have_waiters )

+    {

+        SetEvent( cv->events[ _GLFW_COND_SIGNAL ] );

+    }

+}

+

+

+//========================================================================

+// _glfwPlatformBroadcastCond() - Broadcast a condition to all waiting

+// threads

+//========================================================================

+

+void _glfwPlatformBroadcastCond( GLFWcond cond )

+{

+    _GLFWcond *cv = (_GLFWcond *) cond;

+    int       have_waiters;

+

+    // Avoid race conditions

+    EnterCriticalSection( &cv->waiters_count_lock );

+    have_waiters = cv->waiters_count > 0;

+    LeaveCriticalSection( &cv->waiters_count_lock );

+

+    if( have_waiters )

+    {

+        SetEvent( cv->events[ _GLFW_COND_BROADCAST ] );

+    }

+}

+

+

+//========================================================================

+// _glfwPlatformGetNumberOfProcessors() - Return the number of processors

+// in the system.

+//========================================================================

+

+int _glfwPlatformGetNumberOfProcessors( void )

+{

+    SYSTEM_INFO si;

+

+    // Get hardware system information

+    GetSystemInfo( &si );

+

+    return (int) si.dwNumberOfProcessors;

+}

diff --git a/src/engine/external/glfw/lib/win32/win32_time.c b/src/engine/external/glfw/lib/win32/win32_time.c
new file mode 100644
index 00000000..ea35a8e5
--- /dev/null
+++ b/src/engine/external/glfw/lib/win32/win32_time.c
@@ -0,0 +1,146 @@
+//========================================================================

+// GLFW - An OpenGL framework

+// File:        win32_time.c

+// Platform:    Windows

+// API version: 2.6

+// WWW:         http://glfw.sourceforge.net

+//------------------------------------------------------------------------

+// Copyright (c) 2002-2006 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"

+

+

+//************************************************************************

+//****                  GLFW internal functions                       ****

+//************************************************************************

+

+//========================================================================

+// _glfwInitTimer() - Initialise timer

+//========================================================================

+

+void _glfwInitTimer( void )

+{

+    __int64 freq;

+

+    // Check if we have a performance counter

+    if( QueryPerformanceFrequency( (LARGE_INTEGER *)&freq ) )

+    {

+        // Performance counter is available => use it!

+        _glfwLibrary.Timer.HasPerformanceCounter = GL_TRUE;

+

+        // Counter resolution is 1 / counter frequency

+        _glfwLibrary.Timer.Resolution = 1.0 / (double)freq;

+

+        // Set start time for timer

+        QueryPerformanceCounter( (LARGE_INTEGER *)&_glfwLibrary.Timer.t0_64 );

+    }

+    else

+    {

+        // No performace counter available => use the tick counter

+        _glfwLibrary.Timer.HasPerformanceCounter = GL_FALSE;

+

+        // Counter resolution is 1 ms

+        _glfwLibrary.Timer.Resolution = 0.001;

+

+        // Set start time for timer

+        _glfwLibrary.Timer.t0_32 = _glfw_timeGetTime();

+    }

+}

+

+

+//************************************************************************

+//****               Platform implementation functions                ****

+//************************************************************************

+

+//========================================================================

+// Return timer value in seconds

+//========================================================================

+

+double _glfwPlatformGetTime( void )

+{

+    double  t;

+    __int64 t_64;

+

+    if( _glfwLibrary.Timer.HasPerformanceCounter )

+    {

+        QueryPerformanceCounter( (LARGE_INTEGER *)&t_64 );

+        t =  (double)(t_64 - _glfwLibrary.Timer.t0_64);

+    }

+    else

+    {

+        t = (double)(_glfw_timeGetTime() - _glfwLibrary.Timer.t0_32);

+    }

+

+    // Calculate the current time in seconds

+    return t * _glfwLibrary.Timer.Resolution;

+}

+

+

+//========================================================================

+// Set timer value in seconds

+//========================================================================

+

+void _glfwPlatformSetTime( double t )

+{

+    __int64 t_64;

+

+    if( _glfwLibrary.Timer.HasPerformanceCounter )

+    {

+        QueryPerformanceCounter( (LARGE_INTEGER *)&t_64 );

+        _glfwLibrary.Timer.t0_64 = t_64 - (__int64)(t/_glfwLibrary.Timer.Resolution);

+    }

+    else

+    {

+        _glfwLibrary.Timer.t0_32 = _glfw_timeGetTime() - (int)(t*1000.0);

+    }

+}

+

+

+//========================================================================

+// Put a thread to sleep for a specified amount of time

+//========================================================================

+

+void _glfwPlatformSleep( double time )

+{

+    DWORD t;

+

+    if( time == 0.0 )

+    {

+	t = 0;

+    }

+    else if( time < 0.001 )

+    {

+        t = 1;

+    }

+    else if( time > 2147483647.0 )

+    {

+        t = 2147483647;

+    }

+    else

+    {

+        t = (DWORD)(time*1000.0 + 0.5);

+    }

+    Sleep( t );

+}

+

diff --git a/src/engine/external/glfw/lib/win32/win32_window.c b/src/engine/external/glfw/lib/win32/win32_window.c
new file mode 100644
index 00000000..83c0eeae
--- /dev/null
+++ b/src/engine/external/glfw/lib/win32/win32_window.c
@@ -0,0 +1,1697 @@
+//========================================================================

+// GLFW - An OpenGL framework

+// File:        win32_window.c

+// Platform:    Windows

+// API version: 2.6

+// WWW:         http://glfw.sourceforge.net

+//------------------------------------------------------------------------

+// Copyright (c) 2002-2006 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"

+

+

+

+//************************************************************************

+//****                  GLFW internal functions                       ****

+//************************************************************************

+

+#define _GLFW_WNDCLASSNAME "GLFW26"

+

+

+//========================================================================

+// Enable/disable minimize/restore animations

+//========================================================================

+

+static int _glfwMinMaxAnimations( int enable )

+{

+    ANIMATIONINFO AI;

+    int old_enable;

+

+    // Get old animation setting

+    AI.cbSize = sizeof( ANIMATIONINFO );

+    SystemParametersInfo( SPI_GETANIMATION, AI.cbSize, &AI, 0 );

+    old_enable = AI.iMinAnimate;

+

+    // If requested, change setting

+    if( old_enable != enable )

+    {

+        AI.iMinAnimate = enable;

+        SystemParametersInfo( SPI_SETANIMATION, AI.cbSize, &AI,

+                              SPIF_SENDCHANGE );

+    }

+

+    return old_enable;

+}

+

+

+//========================================================================

+// Function for bringing a window into focus and placing it on top of the

+// window z stack. Due to some nastiness with how Win98/ME/2k/XP handles

+// SetForegroundWindow, we have to go through some really bizarre measures to

+// achieve this (thanks again, MS, for making life so much easier)!

+//========================================================================

+

+static void _glfwSetForegroundWindow( HWND hWnd )

+{

+    int try_count = 0;

+    int old_animate;

+

+    // Try the standard approach first...

+    BringWindowToTop( hWnd );

+    SetForegroundWindow( hWnd );

+

+    // If it worked, return now

+    if( hWnd == GetForegroundWindow() )

+    {

+        // Try to modify the system settings (since this is the foreground

+        // process, we are allowed to do this)

+        SystemParametersInfo( SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID)0,

+                              SPIF_SENDCHANGE );

+        return;

+    }

+

+    // For other Windows versions than 95 & NT4.0, the standard approach

+    // may not work, so if we failed we have to "trick" Windows into

+    // making our window the foureground window: Iconify and restore

+    // again. It is ugly, but it seems to work (we turn off those annoying

+    // zoom animations to make it look a bit better at least).

+

+    // Turn off minimize/restore animations

+    old_animate = _glfwMinMaxAnimations( 0 );

+

+    // We try this a few times, just to be on the safe side of things...

+    do

+    {

+        // Iconify & restore

+        ShowWindow( hWnd, SW_HIDE );

+        ShowWindow( hWnd, SW_SHOWMINIMIZED );

+        ShowWindow( hWnd, SW_SHOWNORMAL );

+

+        // Try to get focus

+        BringWindowToTop( hWnd );

+        SetForegroundWindow( hWnd );

+

+        // We do not want to keep going on forever, so we keep track of

+        // how many times we tried

+        try_count ++;

+    }

+    while( hWnd != GetForegroundWindow() && try_count <= 3 );

+

+    // Restore the system minimize/restore animation setting

+    (void) _glfwMinMaxAnimations( old_animate );

+

+    // Try to modify the system settings (since this is now hopefully the

+    // foreground process, we are probably allowed to do this)

+    SystemParametersInfo( SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID)0,

+                          SPIF_SENDCHANGE );

+}

+

+

+//========================================================================

+// Sets the device context pixel format using a PFD

+//========================================================================

+

+static int _glfwSetPixelFormatPFD( int redbits, int greenbits, int bluebits,

+                                   int alphabits, int depthbits, int stencilbits,

+                                   int mode, _GLFWhints* hints )

+{

+    int PixelFormat;

+    PIXELFORMATDESCRIPTOR pfd;

+

+    // Set required pixel format

+    pfd.nSize           = sizeof(PIXELFORMATDESCRIPTOR);

+    pfd.nVersion        = 1;

+    pfd.dwFlags         = PFD_DRAW_TO_WINDOW | // Draw to window

+                          PFD_SUPPORT_OPENGL | // Support OpenGL

+                          PFD_DOUBLEBUFFER;    // Double buffered window

+    pfd.iPixelType      = PFD_TYPE_RGBA;       // Request an RGBA format

+    pfd.cColorBits      = (BYTE) (redbits +

+                                  greenbits +

+                                  bluebits);   // Color bits (ex. alpha)

+    pfd.cRedBits        = (BYTE) redbits;      // Red bits

+    pfd.cRedShift       = 0;                   // Red shift ignored

+    pfd.cGreenBits      = (BYTE) greenbits;    // Green bits

+    pfd.cGreenShift     = 0;                   // Green shift ignored

+    pfd.cBlueBits       = (BYTE) bluebits;     // Blue bits

+    pfd.cBlueShift      = 0;                   // Blue shift ignored

+    pfd.cAlphaBits      = (BYTE) alphabits;    // Alpha bits

+    pfd.cAlphaShift     = 0;                   // Alpha shift ignored

+    pfd.cAccumBits      = (BYTE) (hints->AccumRedBits +

+                                  hints->AccumGreenBits +

+                                  hints->AccumBlueBits +

+                                  hints->AccumAlphaBits); // Accum. bits

+    pfd.cAccumRedBits   = (BYTE) hints->AccumRedBits;   // Accum. red bits

+    pfd.cAccumGreenBits = (BYTE) hints->AccumGreenBits; // Accum. green bits

+    pfd.cAccumBlueBits  = (BYTE) hints->AccumBlueBits;  // Accum. blue bits

+    pfd.cAccumAlphaBits = (BYTE) hints->AccumAlphaBits; // Accum. alpha bits

+    pfd.cDepthBits      = (BYTE) depthbits;    // Depth buffer bits

+    pfd.cStencilBits    = (BYTE) stencilbits;  // Stencil buffer bits

+    pfd.cAuxBuffers     = (BYTE) hints->AuxBuffers;   // No. of aux buffers

+    pfd.iLayerType      = PFD_MAIN_PLANE;      // Drawing layer: main

+    pfd.bReserved       = 0;                   // (reserved)

+    pfd.dwLayerMask     = 0;                   // Ignored

+    pfd.dwVisibleMask   = 0;                   // "

+    pfd.dwDamageMask    = 0;                   // "

+

+    if( depthbits <= 0 )

+    {

+        // We do not need a depth buffer

+        pfd.dwFlags |= PFD_DEPTH_DONTCARE;

+    }

+

+    if( hints->Stereo )

+    {

+        // Request a stereo mode

+        pfd.dwFlags |= PFD_STEREO;

+    }

+

+    // Find a matching pixel format

+    PixelFormat = _glfw_ChoosePixelFormat( _glfwWin.DC, &pfd );

+    if( !PixelFormat )

+    {

+        return GL_FALSE;

+    }

+

+    // Get actual pixel format description

+    if( !_glfw_DescribePixelFormat( _glfwWin.DC, PixelFormat, sizeof(pfd), &pfd ) )

+    {

+        return GL_FALSE;

+    }

+

+    // "stereo" is a strict requirement

+    if( hints->Stereo && !(pfd.dwFlags & PFD_STEREO) )

+    {

+        return GL_FALSE;

+    }

+

+    // Set the pixel-format

+    if( !_glfw_SetPixelFormat( _glfwWin.DC, PixelFormat, &pfd ) )

+    {

+        return GL_FALSE;

+    }

+

+    return GL_TRUE;

+}

+

+

+//========================================================================

+// Sets the device context pixel format using attributes

+//========================================================================

+

+#define _glfwSetWGLAttribute( _glfwName, _glfwValue ) \

+    attribs[ count++ ] = _glfwName; \

+    attribs[ count++ ] = _glfwValue;

+

+static int _glfwSetPixelFormatAttrib( int redbits, int greenbits, int bluebits,

+                                      int alphabits, int depthbits, int stencilbits,

+                                      int mode, _GLFWhints* hints )

+{

+    int PixelFormat, dummy, count = 0;

+    int attribs[128];

+    PIXELFORMATDESCRIPTOR pfd;

+

+    int accumredbits = hints->AccumRedBits;

+    int accumgreenbits = hints->AccumGreenBits;

+    int accumbluebits = hints->AccumBlueBits;

+    int accumalphabits = hints->AccumAlphaBits;

+    

+    _glfwSetWGLAttribute( WGL_DRAW_TO_WINDOW_ARB, GL_TRUE );

+    _glfwSetWGLAttribute( WGL_ACCELERATION_ARB,   WGL_FULL_ACCELERATION_ARB );

+    _glfwSetWGLAttribute( WGL_SUPPORT_OPENGL_ARB, GL_TRUE );

+    _glfwSetWGLAttribute( WGL_DOUBLE_BUFFER_ARB,  GL_TRUE );

+    _glfwSetWGLAttribute( WGL_COLOR_BITS_ARB,     redbits + greenbits + bluebits );

+    _glfwSetWGLAttribute( WGL_RED_BITS_ARB,       redbits );

+    _glfwSetWGLAttribute( WGL_GREEN_BITS_ARB,     greenbits );

+    _glfwSetWGLAttribute( WGL_BLUE_BITS_ARB,      bluebits );

+    _glfwSetWGLAttribute( WGL_ALPHA_BITS_ARB,     alphabits );

+    _glfwSetWGLAttribute( WGL_DEPTH_BITS_ARB,     depthbits );

+    _glfwSetWGLAttribute( WGL_STENCIL_BITS_ARB,   stencilbits );

+    _glfwSetWGLAttribute( WGL_AUX_BUFFERS_ARB,    hints->AuxBuffers );

+

+    if( accumredbits || accumgreenbits || accumbluebits || accumalphabits )

+    {

+        _glfwSetWGLAttribute( WGL_ACCUM_BITS_ARB, accumredbits +

+                                                  accumgreenbits +

+                                                  accumbluebits +

+                                                  accumalphabits );

+

+        _glfwSetWGLAttribute( WGL_ACCUM_RED_BITS_ARB, accumredbits );

+        _glfwSetWGLAttribute( WGL_ACCUM_GREEN_BITS_ARB, accumgreenbits );

+        _glfwSetWGLAttribute( WGL_ACCUM_BLUE_BITS_ARB, accumbluebits );

+        _glfwSetWGLAttribute( WGL_ACCUM_ALPHA_BITS_ARB, accumalphabits );

+    }

+

+    if( hints->Stereo )

+    {

+        _glfwSetWGLAttribute( WGL_STEREO_ARB, GL_TRUE );

+    }

+

+    if( hints->Samples > 0 )

+    {

+        _glfwSetWGLAttribute( WGL_SAMPLE_BUFFERS_ARB, 1 );

+        _glfwSetWGLAttribute( WGL_SAMPLES_ARB, hints->Samples );

+    }

+

+    _glfwSetWGLAttribute( 0, 0 );

+

+    if( !_glfwWin.ChoosePixelFormat( _glfwWin.DC, attribs, NULL, 1, &PixelFormat, &dummy ) )

+    {

+        return GL_FALSE;

+    }

+

+    if( !_glfw_DescribePixelFormat( _glfwWin.DC, PixelFormat, sizeof(pfd), &pfd ) )

+    {

+        return GL_FALSE;

+    }

+

+    // Set the pixel-format

+    if( !_glfw_SetPixelFormat( _glfwWin.DC, PixelFormat, &pfd ) )

+    {

+        return GL_FALSE;

+    }

+

+    return GL_TRUE; 

+}

+

+#undef _glfwSetWGLAttribute

+

+

+//========================================================================

+// Translates a Windows key to the corresponding GLFW key

+//========================================================================

+

+static int _glfwTranslateKey( WPARAM wParam, LPARAM lParam )

+{

+    MSG next_msg;

+    DWORD msg_time;

+    DWORD scan_code;

+

+    // Check which key was pressed or released

+    switch( wParam )

+    {

+        // The SHIFT keys require special handling

+        case VK_SHIFT:

+            // Compare scan code for this key with that of VK_RSHIFT in

+            // order to determine which shift key was pressed (left or

+            // right)

+            scan_code = MapVirtualKey( VK_RSHIFT, 0 );

+            if( ((lParam & 0x01ff0000) >> 16) == scan_code )

+            {

+                return GLFW_KEY_RSHIFT;

+            }

+            return GLFW_KEY_LSHIFT;

+

+        // The CTRL keys require special handling

+        case VK_CONTROL:

+            // Is this an extended key (i.e. right key)?

+            if( lParam & 0x01000000 )

+            {

+                return GLFW_KEY_RCTRL;

+            }

+            // Here is a trick: "Alt Gr" sends LCTRL, then RALT. We only

+            // want the RALT message, so we try to see if the next message

+            // is a RALT message. In that case, this is a false LCTRL!

+            msg_time = GetMessageTime();

+            if( PeekMessage( &next_msg, NULL, 0, 0, PM_NOREMOVE ) )

+            {

+                if( next_msg.message == WM_KEYDOWN ||

+                    next_msg.message == WM_SYSKEYDOWN )

+                {

+                    if( next_msg.wParam == VK_MENU &&

+                        (next_msg.lParam & 0x01000000) &&

+                        next_msg.time == msg_time )

+                    {

+                        // Next message is a RALT down message, which

+                        // means that this is NOT a proper LCTRL message!

+                        return GLFW_KEY_UNKNOWN;

+                    }

+                }

+            }

+            return GLFW_KEY_LCTRL;

+

+        // The ALT keys require special handling

+        case VK_MENU:

+            // Is this an extended key (i.e. right key)?

+            if( lParam & 0x01000000 )

+            {

+                return GLFW_KEY_RALT;

+            }

+            return GLFW_KEY_LALT;

+

+        // The ENTER keys require special handling

+        case VK_RETURN:

+            // Is this an extended key (i.e. right key)?

+            if( lParam & 0x01000000 )

+            {

+                return GLFW_KEY_KP_ENTER;

+            }

+            return GLFW_KEY_ENTER;

+

+        // Special keys (non character keys)

+        case VK_ESCAPE:        return GLFW_KEY_ESC;

+        case VK_TAB:           return GLFW_KEY_TAB;

+        case VK_BACK:          return GLFW_KEY_BACKSPACE;

+        case VK_HOME:          return GLFW_KEY_HOME;

+        case VK_END:           return GLFW_KEY_END;

+        case VK_PRIOR:         return GLFW_KEY_PAGEUP;

+        case VK_NEXT:          return GLFW_KEY_PAGEDOWN;

+        case VK_INSERT:        return GLFW_KEY_INSERT;

+        case VK_DELETE:        return GLFW_KEY_DEL;

+        case VK_LEFT:          return GLFW_KEY_LEFT;

+        case VK_UP:            return GLFW_KEY_UP;

+        case VK_RIGHT:         return GLFW_KEY_RIGHT;

+        case VK_DOWN:          return GLFW_KEY_DOWN;

+        case VK_F1:            return GLFW_KEY_F1;

+        case VK_F2:            return GLFW_KEY_F2;

+        case VK_F3:            return GLFW_KEY_F3;

+        case VK_F4:            return GLFW_KEY_F4;

+        case VK_F5:            return GLFW_KEY_F5;

+        case VK_F6:            return GLFW_KEY_F6;

+        case VK_F7:            return GLFW_KEY_F7;

+        case VK_F8:            return GLFW_KEY_F8;

+        case VK_F9:            return GLFW_KEY_F9;

+        case VK_F10:           return GLFW_KEY_F10;

+        case VK_F11:           return GLFW_KEY_F11;

+        case VK_F12:           return GLFW_KEY_F12;

+        case VK_F13:           return GLFW_KEY_F13;

+        case VK_F14:           return GLFW_KEY_F14;

+        case VK_F15:           return GLFW_KEY_F15;

+        case VK_F16:           return GLFW_KEY_F16;

+        case VK_F17:           return GLFW_KEY_F17;

+        case VK_F18:           return GLFW_KEY_F18;

+        case VK_F19:           return GLFW_KEY_F19;

+        case VK_F20:           return GLFW_KEY_F20;

+        case VK_F21:           return GLFW_KEY_F21;

+        case VK_F22:           return GLFW_KEY_F22;

+        case VK_F23:           return GLFW_KEY_F23;

+        case VK_F24:           return GLFW_KEY_F24;

+        case VK_SPACE:         return GLFW_KEY_SPACE;

+

+        // Numeric keypad

+        case VK_NUMPAD0:       return GLFW_KEY_KP_0;

+        case VK_NUMPAD1:       return GLFW_KEY_KP_1;

+        case VK_NUMPAD2:       return GLFW_KEY_KP_2;

+        case VK_NUMPAD3:       return GLFW_KEY_KP_3;

+        case VK_NUMPAD4:       return GLFW_KEY_KP_4;

+        case VK_NUMPAD5:       return GLFW_KEY_KP_5;

+        case VK_NUMPAD6:       return GLFW_KEY_KP_6;

+        case VK_NUMPAD7:       return GLFW_KEY_KP_7;

+        case VK_NUMPAD8:       return GLFW_KEY_KP_8;

+        case VK_NUMPAD9:       return GLFW_KEY_KP_9;

+        case VK_DIVIDE:        return GLFW_KEY_KP_DIVIDE;

+        case VK_MULTIPLY:      return GLFW_KEY_KP_MULTIPLY;

+        case VK_SUBTRACT:      return GLFW_KEY_KP_SUBTRACT;

+        case VK_ADD:           return GLFW_KEY_KP_ADD;

+        case VK_DECIMAL:       return GLFW_KEY_KP_DECIMAL;

+

+        // The rest (should be printable keys)

+        default:

+            // Convert to printable character (ISO-8859-1 or Unicode)

+            wParam = MapVirtualKey( (UINT) wParam, 2 ) & 0x0000FFFF;

+

+            // Make sure that the character is uppercase

+            if( _glfwLibrary.Sys.HasUnicode )

+            {

+                wParam = (WPARAM) CharUpperW( (LPWSTR) wParam );

+            }

+            else

+            {

+                wParam = (WPARAM) CharUpperA( (LPSTR) wParam );

+            }

+

+            // Valid ISO-8859-1 character?

+            if( (wParam >=  32 && wParam <= 126) ||

+                (wParam >= 160 && wParam <= 255) )

+            {

+                return (int) wParam;

+            }

+            return GLFW_KEY_UNKNOWN;

+    }

+}

+

+

+//========================================================================

+// Translates a windows key to Unicode

+//========================================================================

+

+static void _glfwTranslateChar( DWORD wParam, DWORD lParam, int action )

+{

+    BYTE  keyboard_state[ 256 ];

+    UCHAR char_buf[ 10 ];

+    WCHAR unicode_buf[ 10 ];

+    UINT  scan_code;

+    int   i, num_chars, unicode;

+

+    // Get keyboard state

+    GetKeyboardState( keyboard_state );

+

+    // Derive scan code from lParam and action

+    scan_code = (lParam & 0x01ff0000) >> 16;

+    if( action == GLFW_RELEASE )

+    {

+        scan_code |= 0x8000000;

+    }

+

+    // Do we have Unicode support?

+    if( _glfwLibrary.Sys.HasUnicode )

+    {

+        // Convert to Unicode

+        num_chars = ToUnicode(

+            wParam,          // virtual-key code

+            scan_code,       // scan code

+            keyboard_state,  // key-state array

+            unicode_buf,     // buffer for translated key

+            10,              // size of translated key buffer

+            0                // active-menu flag

+        );

+        unicode = 1;

+    }

+    else

+    {

+        // Convert to ISO-8859-1

+        num_chars = ToAscii(

+            wParam,            // virtual-key code

+            scan_code,         // scan code

+            keyboard_state,    // key-state array

+            (LPWORD) char_buf, // buffer for translated key

+            0                  // active-menu flag

+        );

+        unicode = 0;

+    }

+

+    // Report characters

+    for( i = 0;  i < num_chars;  i++ )

+    {

+        // Get next character from buffer

+        if( unicode )

+        {

+            _glfwInputChar( (int) unicode_buf[ i ], action );

+        }

+        else

+        {

+            _glfwInputChar( (int) char_buf[ i ], action );

+        }

+    }

+}

+

+

+//========================================================================

+// Window callback function (handles window events)

+//========================================================================

+

+static LRESULT CALLBACK _glfwWindowCallback( HWND hWnd, UINT uMsg,

+                                             WPARAM wParam, LPARAM lParam )

+{

+    int WheelDelta, Iconified;

+

+    // Handle certain window messages

+    switch( uMsg )

+    {

+        // Window activate message? (iconification?)

+        case WM_ACTIVATE:

+        {

+            _glfwWin.Active = LOWORD(wParam) != WA_INACTIVE ? GL_TRUE : GL_FALSE;

+

+            Iconified = HIWORD(wParam) ? GL_TRUE : GL_FALSE;

+

+            // Were we deactivated/iconified?

+            if( (!_glfwWin.Active || Iconified) && !_glfwWin.Iconified )

+            {

+                _glfwInputDeactivation();

+

+                // If we are in fullscreen mode we need to iconify

+                if( _glfwWin.Opened && _glfwWin.Fullscreen )

+                {

+                    // Do we need to manually iconify?

+                    if( !Iconified )

+                    {

+                        // Minimize window

+                        CloseWindow( _glfwWin.Wnd );

+

+                        // The window is now iconified

+                        Iconified = GL_TRUE;

+                    }

+

+                    // Change display settings to the desktop resolution

+                    ChangeDisplaySettings( NULL, CDS_FULLSCREEN );

+                }

+

+                // Unlock mouse

+                if( !_glfwWin.OldMouseLockValid )

+                {

+                    _glfwWin.OldMouseLock = _glfwWin.MouseLock;

+                    _glfwWin.OldMouseLockValid = GL_TRUE;

+                    glfwEnable( GLFW_MOUSE_CURSOR );

+                }

+            }

+            else if( _glfwWin.Active || !Iconified )

+            {

+                // If we are in fullscreen mode we need to maximize

+                if( _glfwWin.Opened && _glfwWin.Fullscreen && _glfwWin.Iconified )

+                {

+                    // Change display settings to the user selected mode

+                    _glfwSetVideoModeMODE( _glfwWin.ModeID );

+

+                    // Do we need to manually restore window?

+                    if( Iconified )

+                    {

+                        // Restore window

+                        OpenIcon( _glfwWin.Wnd );

+

+                        // The window is no longer iconified

+                        Iconified = GL_FALSE;

+

+                        // Activate window

+                        ShowWindow( hWnd, SW_SHOW );

+                        _glfwSetForegroundWindow( _glfwWin.Wnd );

+                        SetFocus( _glfwWin.Wnd );

+                    }

+                }

+

+                // Lock mouse, if necessary

+                if( _glfwWin.OldMouseLockValid && _glfwWin.OldMouseLock )

+                {

+                    glfwDisable( GLFW_MOUSE_CURSOR );

+                }

+                _glfwWin.OldMouseLockValid = GL_FALSE;

+            }

+

+            _glfwWin.Iconified = Iconified;

+            return 0;

+        }

+

+        // Intercept system commands (forbid certain actions/events)

+        case WM_SYSCOMMAND:

+        {

+            switch( wParam )

+            {

+                // Screensaver trying to start or monitor trying to enter

+                // powersave?

+                case SC_SCREENSAVE:

+                case SC_MONITORPOWER:

+                    if( _glfwWin.Fullscreen )

+                    {

+                        return 0;

+                    }

+                    else

+                    {

+                        break;

+                    }

+

+                // User trying to access application menu using ALT?

+                case SC_KEYMENU:

+                    return 0;

+            }

+            break;

+        }

+

+        // Did we receive a close message?

+        case WM_CLOSE:

+            PostQuitMessage( 0 );

+            return 0;

+

+        // Is a key being pressed?

+        case WM_KEYDOWN:

+        case WM_SYSKEYDOWN:

+        {

+            // Translate and report key press

+            _glfwInputKey( _glfwTranslateKey( wParam, lParam ),

+                           GLFW_PRESS );

+

+            // Translate and report character input

+            if( _glfwWin.CharCallback )

+            {

+                _glfwTranslateChar( (DWORD) wParam, (DWORD) lParam, GLFW_PRESS );

+            }

+            return 0;

+          }  

+

+        // Is a key being released?

+        case WM_KEYUP:

+        case WM_SYSKEYUP:

+        {

+            // Special trick: release both shift keys on SHIFT up event

+            if( wParam == VK_SHIFT )

+            {

+                _glfwInputKey( GLFW_KEY_LSHIFT, GLFW_RELEASE );

+                _glfwInputKey( GLFW_KEY_RSHIFT, GLFW_RELEASE );

+            }

+            else

+            {

+                // Translate and report key release

+                _glfwInputKey( _glfwTranslateKey( wParam, lParam ),

+                               GLFW_RELEASE );

+            }

+

+            // Translate and report character input

+            if( _glfwWin.CharCallback )

+            {

+                _glfwTranslateChar( (DWORD) wParam, (DWORD) lParam, GLFW_RELEASE );

+            }

+

+            return 0;

+        }

+

+        // Were any of the mouse-buttons pressed?

+        case WM_LBUTTONDOWN:

+            SetCapture(hWnd);

+            _glfwInputMouseClick( GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS );

+            return 0;

+        case WM_RBUTTONDOWN:

+            SetCapture(hWnd);

+            _glfwInputMouseClick( GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS );

+            return 0;

+        case WM_MBUTTONDOWN:

+            SetCapture(hWnd);

+            _glfwInputMouseClick( GLFW_MOUSE_BUTTON_MIDDLE, GLFW_PRESS );

+            return 0;

+        case WM_XBUTTONDOWN:

+        {

+            if( HIWORD(wParam) == XBUTTON1 )

+            {

+                SetCapture(hWnd);

+                _glfwInputMouseClick( GLFW_MOUSE_BUTTON_4, GLFW_PRESS );

+            }

+            else if( HIWORD(wParam) == XBUTTON2 )

+            {

+                SetCapture(hWnd);

+                _glfwInputMouseClick( GLFW_MOUSE_BUTTON_5, GLFW_PRESS );

+            }

+            return 1;

+        }

+

+        // Were any of the mouse-buttons released?

+        case WM_LBUTTONUP:

+            ReleaseCapture();

+            _glfwInputMouseClick( GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE );

+            return 0;

+        case WM_RBUTTONUP:

+            ReleaseCapture();

+            _glfwInputMouseClick( GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE );

+            return 0;

+        case WM_MBUTTONUP:

+            ReleaseCapture();

+            _glfwInputMouseClick( GLFW_MOUSE_BUTTON_MIDDLE, GLFW_RELEASE );

+            return 0;

+        case WM_XBUTTONUP:

+        {

+            if( HIWORD(wParam) == XBUTTON1 )

+            {

+                ReleaseCapture();

+                _glfwInputMouseClick( GLFW_MOUSE_BUTTON_4, GLFW_RELEASE );

+            }

+            else if( HIWORD(wParam) == XBUTTON2 )

+            {

+                ReleaseCapture();

+                _glfwInputMouseClick( GLFW_MOUSE_BUTTON_5, GLFW_RELEASE );

+            }

+            return 1;

+        }

+

+        // Did the mouse move?

+        case WM_MOUSEMOVE:

+        {

+            {

+                int NewMouseX, NewMouseY;

+

+                // Get signed (!) mouse position

+                NewMouseX = (int)((short)LOWORD(lParam));

+                NewMouseY = (int)((short)HIWORD(lParam));

+

+                if( NewMouseX != _glfwInput.OldMouseX ||

+                    NewMouseY != _glfwInput.OldMouseY )

+                {

+                    if( _glfwWin.MouseLock )

+                    {

+                        _glfwInput.MousePosX += NewMouseX -

+                                                _glfwInput.OldMouseX;

+                        _glfwInput.MousePosY += NewMouseY -

+                                                _glfwInput.OldMouseY;

+                    }

+                    else

+                    {

+                        _glfwInput.MousePosX = NewMouseX;

+                        _glfwInput.MousePosY = NewMouseY;

+                    }

+                    _glfwInput.OldMouseX = NewMouseX;

+                    _glfwInput.OldMouseY = NewMouseY;

+                    _glfwInput.MouseMoved = GL_TRUE;

+    

+                    // Call user callback function

+                    if( _glfwWin.MousePosCallback )

+                    {

+                        _glfwWin.MousePosCallback( _glfwInput.MousePosX,

+                                                   _glfwInput.MousePosY );

+                    }

+                }

+            }

+            return 0;

+        }

+

+        // Mouse wheel action?

+        case WM_MOUSEWHEEL:

+        {

+            // WM_MOUSEWHEEL is not supported under Windows 95

+            if( _glfwLibrary.Sys.WinVer != _GLFW_WIN_95 )

+            {

+                WheelDelta = (((int)wParam) >> 16) / WHEEL_DELTA;

+                _glfwInput.WheelPos += WheelDelta;

+                if( _glfwWin.MouseWheelCallback )

+                {

+                    _glfwWin.MouseWheelCallback( _glfwInput.WheelPos );

+                }

+                return 0;

+            }

+            break;

+        }

+

+        // Resize the window?

+        case WM_SIZE:

+        {

+            // get the new size

+            _glfwWin.Width  = LOWORD(lParam);

+            _glfwWin.Height = HIWORD(lParam);

+

+            // If the mouse is locked, update the clipping rect

+            if( _glfwWin.MouseLock )

+            {

+                RECT ClipWindowRect;

+                if( GetWindowRect( _glfwWin.Wnd, &ClipWindowRect ) )

+                {

+                    ClipCursor( &ClipWindowRect );

+                }

+            }

+

+            // Call the user-supplied callback, if it exists

+            if( _glfwWin.WindowSizeCallback )

+            {

+                _glfwWin.WindowSizeCallback( LOWORD(lParam),

+                                             HIWORD(lParam) );

+            }

+            return 0;

+        }

+

+        // Move the window?

+        case WM_MOVE:

+        {

+            // If the mouse is locked, update the clipping rect

+            if( _glfwWin.MouseLock )

+            {

+                RECT ClipWindowRect;

+                if( GetWindowRect( _glfwWin.Wnd, &ClipWindowRect ) )

+                {

+                    ClipCursor( &ClipWindowRect );

+                }

+            }

+            return 0;

+        }

+

+        // Was the window contents damaged?

+        case WM_PAINT:

+        {

+            // Call user callback function

+            if( _glfwWin.WindowRefreshCallback )

+            {

+                _glfwWin.WindowRefreshCallback();

+            }

+            break;

+        }

+

+	case WM_DISPLAYCHANGE:

+	{

+	    // TODO: Do stuff here.

+

+	    break;

+	}

+    }

+

+    // Pass all unhandled messages to DefWindowProc

+    return DefWindowProc( hWnd, uMsg, wParam, lParam );

+}

+

+

+//========================================================================

+// Translate client window size to full window size (including window borders)

+//========================================================================

+

+static void _glfwGetFullWindowSize( int w, int h, int *w2, int *h2 )

+{

+    RECT rect;

+

+    // Create a window rectangle

+    rect.left   = (long)0;

+    rect.right  = (long)w-1;

+    rect.top    = (long)0;

+    rect.bottom = (long)h-1;

+

+    // Adjust according to window styles

+    AdjustWindowRectEx( &rect, _glfwWin.dwStyle, FALSE,

+                        _glfwWin.dwExStyle );

+

+    // Calculate width and height of full window

+    *w2 = rect.right-rect.left+1;

+    *h2 = rect.bottom-rect.top+1;

+}

+

+

+//========================================================================

+// Initialize WGL-specific extensions

+//========================================================================

+

+static void _glfwInitWGLExtensions( void )

+{

+    GLubyte *extensions;

+    int     has_swap_control, has_pixel_format;

+

+    // Initialize OpenGL extension: WGL_EXT_swap_control

+    has_swap_control = GL_FALSE;

+    has_pixel_format = GL_FALSE;

+    extensions = (GLubyte *) glGetString( GL_EXTENSIONS );

+

+    if( extensions != NULL )

+    {

+        has_swap_control = _glfwStringInExtensionString(

+                               "WGL_EXT_swap_control",

+                               extensions

+                           );

+        has_pixel_format = _glfwStringInExtensionString(

+                               "WGL_ARB_pixel_format",

+                               extensions

+                           );

+    }

+

+    if( !has_swap_control )

+    {

+        has_swap_control = _glfwPlatformExtensionSupported(

+                               "WGL_EXT_swap_control"

+                           );

+    }

+

+    if( !has_pixel_format )

+    {

+        has_pixel_format = _glfwPlatformExtensionSupported(

+                               "WGL_ARB_pixel_format"

+                           );

+    }

+

+    if( has_swap_control )

+    {

+        _glfwWin.SwapInterval = (WGLSWAPINTERVALEXT_T)

+            wglGetProcAddress( "wglSwapIntervalEXT" );

+    }

+    else

+    {

+        _glfwWin.SwapInterval = NULL;

+    }

+    

+    if( has_pixel_format )

+    {

+        _glfwWin.ChoosePixelFormat = (WGLCHOOSEPIXELFORMATARB_T)

+            wglGetProcAddress( "wglChoosePixelFormatARB" );

+        _glfwWin.GetPixelFormatAttribiv = (WGLGETPIXELFORMATATTRIBIVARB_T)

+            wglGetProcAddress( "wglGetPixelFormatAttribivARB" );

+    }

+    else

+    {

+        _glfwWin.ChoosePixelFormat = NULL;

+        _glfwWin.GetPixelFormatAttribiv = NULL;

+    }  

+}

+

+

+//========================================================================

+// Creates the GLFW window and rendering context

+//========================================================================

+

+static int _glfwCreateWindow( int redbits, int greenbits, int bluebits,

+                              int alphabits, int depthbits, int stencilbits,

+                              int mode, _GLFWhints* hints )

+{

+    int    full_width, full_height;

+    RECT   wa;

+

+    _glfwWin.DC  = NULL;

+    _glfwWin.RC  = NULL;

+    _glfwWin.Wnd = NULL;

+

+    // Set window size to true requested size (adjust for window borders)

+    _glfwGetFullWindowSize( _glfwWin.Width, _glfwWin.Height, &full_width,

+                            &full_height );

+

+    // Adjust window position to working area (e.g. if the task bar is at

+    // the top of the display). Fullscreen windows are always opened in

+    // the upper left corner regardless of the desktop working area. 

+    if( _glfwWin.Fullscreen )

+    {

+        wa.left = wa.top = 0;

+    }

+    else

+    {

+        SystemParametersInfo( SPI_GETWORKAREA, 0, &wa, 0 );

+    }

+

+    // Create window

+    _glfwWin.Wnd = CreateWindowEx(

+               _glfwWin.dwExStyle,        // Extended style

+               _GLFW_WNDCLASSNAME,        // Class name

+               "GLFW Window",             // Window title

+               _glfwWin.dwStyle,          // Defined window style

+               wa.left, wa.top,           // Window position

+               full_width,                // Decorated window width

+               full_height,               // Decorated window height

+               NULL,                      // No parent window

+               NULL,                      // No menu

+               _glfwLibrary.Instance,     // Instance

+               NULL );                    // Nothing to WM_CREATE

+

+    if( !_glfwWin.Wnd )

+    {

+        return GL_FALSE;

+    }

+

+    // Get a device context

+    _glfwWin.DC = GetDC( _glfwWin.Wnd );

+    if( !_glfwWin.DC )

+    {

+        return GL_FALSE;

+    }

+

+    if( _glfwWin.ChoosePixelFormat )

+    {

+        if( !_glfwSetPixelFormatAttrib( redbits, greenbits, bluebits, alphabits,

+                                        depthbits, stencilbits, mode, hints ) )

+        {

+            return GL_FALSE;

+        }

+    }

+    else

+    {

+        if( !_glfwSetPixelFormatPFD( redbits, greenbits, bluebits, alphabits,

+                                     depthbits, stencilbits, mode, hints ) )

+        {

+            return GL_FALSE;

+        }

+    }

+

+    // Get a rendering context

+    _glfwWin.RC = wglCreateContext( _glfwWin.DC );

+    if( !_glfwWin.RC )

+    {

+        return GL_FALSE;

+    }

+

+    // Activate the OpenGL rendering context

+    if( !wglMakeCurrent( _glfwWin.DC, _glfwWin.RC ) )

+    {

+        return GL_FALSE;

+    }

+

+    // Initialize WGL-specific OpenGL extensions

+    _glfwInitWGLExtensions();

+

+    return GL_TRUE;

+}

+

+

+//========================================================================

+// Destroys the GLFW window and rendering context

+//========================================================================

+

+static void _glfwDestroyWindow( void )

+{

+    // Do we have a rendering context?

+    if( _glfwWin.RC )

+    {

+        // Release the DC and RC contexts

+        wglMakeCurrent( NULL, NULL );

+

+        // Delete the rendering context

+        wglDeleteContext( _glfwWin.RC );

+        _glfwWin.RC = NULL;

+    }

+

+    // Do we have a device context?

+    if( _glfwWin.DC )

+    {

+        // Release the device context

+        ReleaseDC( _glfwWin.Wnd, _glfwWin.DC );

+        _glfwWin.DC = NULL;

+    }

+

+    // Do we have a window?

+    if( _glfwWin.Wnd )

+    {

+        // Destroy the window

+        if( _glfwLibrary.Sys.WinVer <= _GLFW_WIN_NT4 )

+        {

+            // Note: Hiding the window first fixes an annoying W98/NT4

+            // remaining icon bug for fullscreen displays

+            ShowWindow( _glfwWin.Wnd, SW_HIDE );

+        }

+

+        DestroyWindow( _glfwWin.Wnd );

+        _glfwWin.Wnd = NULL;

+    }

+}

+

+

+

+//************************************************************************

+//****               Platform implementation functions                ****

+//************************************************************************

+

+//========================================================================

+// Here is where the window is created, and the OpenGL rendering context is

+// created

+//========================================================================

+

+int _glfwPlatformOpenWindow( int width, int height,

+                             int redbits, int greenbits, int bluebits,

+                             int alphabits, int depthbits, int stencilbits,

+                             int mode, _GLFWhints* hints )

+{

+    WNDCLASS    wc;

+    DWORD  dwStyle, dwExStyle;

+

+    // Clear platform specific GLFW window state

+    _glfwWin.ClassAtom         = 0;

+    _glfwWin.OldMouseLockValid = GL_FALSE;

+    _glfwWin.ChoosePixelFormat = NULL;

+    _glfwWin.GetPixelFormatAttribiv = NULL;

+

+    // Remember desired refresh rate for this window (used only in

+    // fullscreen mode)

+    _glfwWin.DesiredRefreshRate = hints->RefreshRate;

+

+    // Set window class parameters

+    wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw on...

+    wc.lpfnWndProc   = (WNDPROC)_glfwWindowCallback;  // Message handler

+    wc.cbClsExtra    = 0;                             // No extra class data

+    wc.cbWndExtra    = 0;                             // No extra window data

+    wc.hInstance     = _glfwLibrary.Instance;         // Set instance

+    wc.hCursor       = LoadCursor( NULL, IDC_ARROW ); // Load arrow pointer

+    wc.hbrBackground = NULL;                          // No background

+    wc.lpszMenuName  = NULL;                          // No menu

+    wc.lpszClassName = _GLFW_WNDCLASSNAME;            // Set class name

+

+    // Load user-provided icon if available

+    wc.hIcon = LoadIcon( _glfwLibrary.Instance, "GLFW_ICON" );

+    if( !wc.hIcon )

+    {

+        // Load default icon

+        wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); 

+    }

+

+    // Register the window class

+    _glfwWin.ClassAtom = RegisterClass( &wc );

+    if( !_glfwWin.ClassAtom )

+    {

+        _glfwPlatformCloseWindow();

+        return GL_FALSE;

+    }

+

+    // Do we want full-screen mode?

+    if( _glfwWin.Fullscreen )

+    {

+        _glfwSetVideoMode( &_glfwWin.Width, &_glfwWin.Height,

+                           redbits, greenbits, bluebits,

+                           hints->RefreshRate );

+    }

+

+    // Set common window styles

+    dwStyle   = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;

+    dwExStyle = WS_EX_APPWINDOW;

+

+    // Set window style, depending on fullscreen mode

+    if( _glfwWin.Fullscreen )

+    {

+        dwStyle |= WS_POPUP;

+

+        // Here's a trick for helping us getting window focus

+        // (SetForegroundWindow doesn't work properly under

+        // Win98/ME/2K/XP/.NET/+)

+		

+		/*

+        if( _glfwLibrary.Sys.WinVer == _GLFW_WIN_95 ||

+            _glfwLibrary.Sys.WinVer == _GLFW_WIN_NT4 || 

+            _glfwLibrary.Sys.WinVer == _GLFW_WIN_XP )

+        {

+            dwStyle |= WS_VISIBLE;

+        }

+        else

+        {

+            dwStyle |= WS_MINIMIZE;

+        }

+		*/

+    }

+    else

+    {

+        dwStyle |= WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;

+

+        if( !hints->WindowNoResize )

+        {

+            dwStyle |= ( WS_MAXIMIZEBOX | WS_SIZEBOX );

+            dwExStyle |= WS_EX_WINDOWEDGE;

+        }

+    }

+

+    // Remember window styles (used by _glfwGetFullWindowSize)

+    _glfwWin.dwStyle   = dwStyle;

+    _glfwWin.dwExStyle = dwExStyle;

+

+    if( !_glfwCreateWindow( redbits, greenbits, bluebits, alphabits,

+                            depthbits, stencilbits, mode, hints ) )

+    {

+        _glfwPlatformCloseWindow();

+        return GL_FALSE;

+    }

+

+    if( _glfwWin.ChoosePixelFormat && hints->Samples > 0 )

+    {

+        for (;;)

+        {

+            _glfwDestroyWindow();

+

+            if( _glfwCreateWindow( redbits, greenbits, bluebits, alphabits,

+                                   depthbits, stencilbits, mode, hints ) )

+            {

+                break;

+            }

+

+            if( hints->Samples > 0 )

+            {

+                hints->Samples--;

+            }

+            else

+            {

+                _glfwPlatformCloseWindow();

+                return GL_FALSE;

+            }

+        }

+    }

+

+    // Make sure that our window ends up on top of things

+    if( _glfwWin.Fullscreen )

+    {

+        // Place the window above all topmost windows

+        SetWindowPos( _glfwWin.Wnd, HWND_TOPMOST, 0,0,0,0,

+                      SWP_NOMOVE | SWP_NOSIZE );

+    }

+    _glfwSetForegroundWindow( _glfwWin.Wnd );

+    SetFocus( _glfwWin.Wnd );

+

+    // Start by clearing the front buffer to black (avoid ugly desktop

+    // remains in our OpenGL window)

+    glClear( GL_COLOR_BUFFER_BIT );

+    _glfw_SwapBuffers( _glfwWin.DC );

+

+    return GL_TRUE;

+}

+

+

+//========================================================================

+// Properly kill the window / video display

+//========================================================================

+

+void _glfwPlatformCloseWindow( void )

+{

+    _glfwDestroyWindow();

+

+    // Do we have an instance?

+    if( _glfwWin.ClassAtom )

+    {

+        // Unregister class

+        UnregisterClass( _GLFW_WNDCLASSNAME, _glfwLibrary.Instance );

+        _glfwWin.ClassAtom = 0;

+    }

+

+    // Are we in fullscreen mode?

+    if( _glfwWin.Fullscreen )

+    {

+        // Switch back to desktop resolution

+        ChangeDisplaySettings( NULL, CDS_FULLSCREEN );

+    }

+

+}

+

+

+//========================================================================

+// Set the window title

+//========================================================================

+

+void _glfwPlatformSetWindowTitle( const char *title )

+{

+    // Set window title

+    (void) SetWindowText( _glfwWin.Wnd, title );

+}

+

+

+//========================================================================

+// Set the window size.

+//========================================================================

+

+void _glfwPlatformSetWindowSize( int width, int height )

+{

+    int     bpp, mode = 0, refresh;

+    int     sizechanged = GL_FALSE;

+    GLint   drawbuffer;

+    GLfloat clearcolor[4];

+

+    // If we are in fullscreen mode, get some info about the current mode

+    if( _glfwWin.Fullscreen )

+    {

+        DEVMODE dm;

+

+        // Get current BPP settings

+        dm.dmSize = sizeof( DEVMODE );

+        if( EnumDisplaySettings( NULL, _glfwWin.ModeID, &dm ) )

+        {

+            // Get bpp

+            bpp = dm.dmBitsPerPel;

+

+            // Get closest match for target video mode

+            refresh = _glfwWin.DesiredRefreshRate;

+            mode = _glfwGetClosestVideoModeBPP( &width, &height, &bpp,

+                                                &refresh );

+        }

+        else

+        {

+            mode = _glfwWin.ModeID;

+        }

+    }

+    else

+    {

+        // If we are in windowed mode, adjust the window size to

+        // compensate for window decorations

+        _glfwGetFullWindowSize( width, height, &width, &height );

+    }

+

+    // Change window size before changing fullscreen mode?

+    if( _glfwWin.Fullscreen && (width > _glfwWin.Width) )

+    {

+        SetWindowPos( _glfwWin.Wnd, HWND_TOP, 0, 0, width, height,

+                      SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER );

+        sizechanged = GL_TRUE;

+    }

+

+    // Change fullscreen video mode?

+    if( _glfwWin.Fullscreen && mode != _glfwWin.ModeID )

+    {

+        // Change video mode

+        _glfwSetVideoModeMODE( mode );

+

+        // Clear the front buffer to black (avoid ugly desktop remains in

+        // our OpenGL window)

+        glGetIntegerv( GL_DRAW_BUFFER, &drawbuffer );

+        glGetFloatv( GL_COLOR_CLEAR_VALUE, clearcolor );

+        glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );

+        glClear( GL_COLOR_BUFFER_BIT );

+        if( drawbuffer == GL_BACK )

+        {

+            _glfw_SwapBuffers( _glfwWin.DC );

+        }

+        glClearColor( clearcolor[0], clearcolor[1], clearcolor[2],

+                      clearcolor[3] );

+    }

+

+    // Set window size (if not already changed)

+    if( !sizechanged )

+    {

+        SetWindowPos( _glfwWin.Wnd, HWND_TOP, 0, 0, width, height,

+                      SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER );

+    }

+}

+

+

+//========================================================================

+// Set the window position

+//========================================================================

+

+void _glfwPlatformSetWindowPos( int x, int y )

+{

+    // Set window position

+    (void) SetWindowPos( _glfwWin.Wnd, HWND_TOP, x, y, 0, 0,

+                         SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER );

+}

+

+

+//========================================================================

+// Window iconification

+//========================================================================

+

+void _glfwPlatformIconifyWindow( void )

+{

+    // Iconify window

+    CloseWindow( _glfwWin.Wnd );

+

+    // Window is now iconified

+    _glfwWin.Iconified = GL_TRUE;

+

+    // If we are in fullscreen mode we need to change video modes

+    if( _glfwWin.Fullscreen )

+    {

+        // Change display settings to the desktop resolution

+        ChangeDisplaySettings( NULL, CDS_FULLSCREEN );

+    }

+

+    // Unlock mouse

+    if( !_glfwWin.OldMouseLockValid )

+    {

+        _glfwWin.OldMouseLock = _glfwWin.MouseLock;

+        _glfwWin.OldMouseLockValid = GL_TRUE;

+        glfwEnable( GLFW_MOUSE_CURSOR );

+    }

+}

+

+

+//========================================================================

+// Window un-iconification

+//========================================================================

+

+void _glfwPlatformRestoreWindow( void )

+{

+    // If we are in fullscreen mode we need to change video modes

+    if( _glfwWin.Fullscreen )

+    {

+        // Change display settings to the user selected mode

+        _glfwSetVideoModeMODE( _glfwWin.ModeID );

+    }

+

+    // Un-iconify window

+    OpenIcon( _glfwWin.Wnd );

+

+    // Make sure that our window ends up on top of things

+    ShowWindow( _glfwWin.Wnd, SW_SHOW );

+    _glfwSetForegroundWindow( _glfwWin.Wnd );

+    SetFocus( _glfwWin.Wnd );

+

+    // Window is no longer iconified

+    _glfwWin.Iconified = GL_FALSE;

+

+    // Lock mouse, if necessary

+    if( _glfwWin.OldMouseLockValid && _glfwWin.OldMouseLock )

+    {

+        glfwDisable( GLFW_MOUSE_CURSOR );

+    }

+    _glfwWin.OldMouseLockValid = GL_FALSE;

+}

+

+

+//========================================================================

+// Swap buffers (double-buffering)

+//========================================================================

+

+void _glfwPlatformSwapBuffers( void )

+{

+    _glfw_SwapBuffers( _glfwWin.DC );

+}

+

+

+//========================================================================

+// Set double buffering swap interval

+//========================================================================

+

+void _glfwPlatformSwapInterval( int interval )

+{

+    if( _glfwWin.SwapInterval )

+    {

+        _glfwWin.SwapInterval( interval );

+    }

+}

+

+

+//========================================================================

+// Write back window parameters into GLFW window structure

+//========================================================================

+

+void _glfwPlatformRefreshWindowParams( void )

+{

+    PIXELFORMATDESCRIPTOR pfd;

+    DEVMODE dm;

+    int     PixelFormat, mode;

+

+    // Obtain a detailed description of current pixel format

+    PixelFormat = _glfw_GetPixelFormat( _glfwWin.DC );

+

+    if( !_glfwWin.GetPixelFormatAttribiv )

+    {

+        _glfw_DescribePixelFormat( _glfwWin.DC, PixelFormat,

+                                   sizeof(PIXELFORMATDESCRIPTOR), &pfd );

+

+        // Is current OpenGL context accelerated?

+        _glfwWin.Accelerated = (pfd.dwFlags & PFD_GENERIC_ACCELERATED) ||

+                               !(pfd.dwFlags & PFD_GENERIC_FORMAT) ? 1 : 0;

+

+        // "Standard" window parameters

+        _glfwWin.RedBits        = pfd.cRedBits;

+        _glfwWin.GreenBits      = pfd.cGreenBits;

+        _glfwWin.BlueBits       = pfd.cBlueBits;

+        _glfwWin.AlphaBits      = pfd.cAlphaBits;

+        _glfwWin.DepthBits      = pfd.cDepthBits;

+        _glfwWin.StencilBits    = pfd.cStencilBits;

+        _glfwWin.AccumRedBits   = pfd.cAccumRedBits;

+        _glfwWin.AccumGreenBits = pfd.cAccumGreenBits;

+        _glfwWin.AccumBlueBits  = pfd.cAccumBlueBits;

+        _glfwWin.AccumAlphaBits = pfd.cAccumAlphaBits;

+        _glfwWin.AuxBuffers     = pfd.cAuxBuffers;

+        _glfwWin.Stereo         = pfd.dwFlags & PFD_STEREO ? 1 : 0;

+        _glfwWin.Samples        = 0;

+    }

+    else

+    {

+        const int attribs[] = {

+            WGL_ACCELERATION_ARB,

+            WGL_RED_BITS_ARB,

+            WGL_GREEN_BITS_ARB,

+            WGL_BLUE_BITS_ARB,

+            WGL_ALPHA_BITS_ARB,

+            WGL_DEPTH_BITS_ARB,

+            WGL_STENCIL_BITS_ARB,

+            WGL_ACCUM_RED_BITS_ARB,

+            WGL_ACCUM_GREEN_BITS_ARB,

+            WGL_ACCUM_BLUE_BITS_ARB,

+            WGL_ACCUM_ALPHA_BITS_ARB,

+            WGL_AUX_BUFFERS_ARB,

+            WGL_STEREO_ARB,

+            WGL_SAMPLES_ARB

+        };

+

+        int values[sizeof(attribs) / sizeof(attribs[0])];

+

+        _glfwWin.GetPixelFormatAttribiv( _glfwWin.DC, PixelFormat, 0, 

+                                         sizeof(attribs) / sizeof(attribs[0]), 

+                                         attribs, values);

+

+        // Is current OpenGL context accelerated?

+        _glfwWin.Accelerated = (values[0] == WGL_FULL_ACCELERATION_ARB);

+

+        // "Standard" window parameters

+        _glfwWin.RedBits        = values[1];

+        _glfwWin.GreenBits      = values[2];

+        _glfwWin.BlueBits       = values[3];

+        _glfwWin.AlphaBits      = values[4];

+        _glfwWin.DepthBits      = values[5];

+        _glfwWin.StencilBits    = values[6];

+        _glfwWin.AccumRedBits   = values[7];

+        _glfwWin.AccumGreenBits = values[8]; 

+        _glfwWin.AccumBlueBits  = values[9];

+        _glfwWin.AccumAlphaBits = values[10];

+        _glfwWin.AuxBuffers     = values[11];

+        _glfwWin.Stereo         = values[12];

+        _glfwWin.Samples        = values[13];

+    }

+

+    // Get refresh rate

+    mode = _glfwWin.Fullscreen ? _glfwWin.ModeID : ENUM_CURRENT_SETTINGS;

+    dm.dmSize = sizeof( DEVMODE );

+

+    if( EnumDisplaySettings( NULL, mode, &dm ) )

+    {

+        _glfwWin.RefreshRate = dm.dmDisplayFrequency;

+        if( _glfwWin.RefreshRate <= 1 )

+        {

+            _glfwWin.RefreshRate = 0;

+        }

+    }

+    else

+    {

+        _glfwWin.RefreshRate = 0;

+    }

+}

+

+

+//========================================================================

+// Poll for new window and input events

+//========================================================================

+

+void _glfwPlatformPollEvents( void )

+{

+    MSG msg;

+    int winclosed = GL_FALSE;

+

+    // Flag: mouse was not moved (will be changed by _glfwGetNextEvent if

+    // there was a mouse move event)

+    _glfwInput.MouseMoved = GL_FALSE;

+    if( _glfwWin.MouseLock )

+    {

+        _glfwInput.OldMouseX = _glfwWin.Width/2;

+        _glfwInput.OldMouseY = _glfwWin.Height/2;

+    }

+    else

+    {

+        _glfwInput.OldMouseX = _glfwInput.MousePosX;

+        _glfwInput.OldMouseY = _glfwInput.MousePosY;

+    }

+

+    // Check for new window messages

+    while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )

+    {

+        switch( msg.message )

+        {

+            // QUIT-message (from close window)?

+            case WM_QUIT:

+                winclosed = GL_TRUE;

+                break;

+

+            // Ok, send it to the window message handler

+            default:

+                DispatchMessage( &msg );

+                break;

+        }

+    }

+

+    // LSHIFT/RSHIFT fixup (keys tend to "stick" without this fix)

+    // This is the only async event handling in GLFW, but it solves some

+    // nasty problems.

+    // Caveat: Does not work under Win 9x/ME.

+    if( _glfwLibrary.Sys.WinVer >= _GLFW_WIN_NT4 )

+    {

+        int lshift_down, rshift_down;

+

+        // Get current state of left and right shift keys

+        lshift_down = (GetAsyncKeyState( VK_LSHIFT ) >> 15) & 1;

+        rshift_down = (GetAsyncKeyState( VK_RSHIFT ) >> 15) & 1;

+

+        // See if this differs from our belief of what has happened

+        // (we only have to check for lost key up events)

+        if( !lshift_down && _glfwInput.Key[ GLFW_KEY_LSHIFT ] == 1 )

+        {

+            _glfwInputKey( GLFW_KEY_LSHIFT, GLFW_RELEASE );

+        }

+        if( !rshift_down && _glfwInput.Key[ GLFW_KEY_RSHIFT ] == 1 )

+        {

+            _glfwInputKey( GLFW_KEY_RSHIFT, GLFW_RELEASE );

+        }

+    }

+

+    // Did we have mouse movement in locked cursor mode?

+    if( _glfwInput.MouseMoved && _glfwWin.MouseLock )

+    {

+        _glfwPlatformSetMouseCursorPos( _glfwWin.Width / 2,

+                                        _glfwWin.Height / 2 );

+    }

+

+    // Was there a window close request?

+    if( winclosed && _glfwWin.WindowCloseCallback )

+    {

+        // Check if the program wants us to close the window

+        winclosed = _glfwWin.WindowCloseCallback();

+    }

+    if( winclosed )

+    {

+        glfwCloseWindow();

+    }

+}

+

+

+//========================================================================

+// _glfwPlatformWaitEvents() - Wait for new window and input events

+//========================================================================

+

+void _glfwPlatformWaitEvents( void )

+{

+    // Wait for new events

+    WaitMessage();

+

+    // Poll new events

+    _glfwPlatformPollEvents();

+}

+

+

+//========================================================================

+// Hide mouse cursor (lock it)

+//========================================================================

+

+void _glfwPlatformHideMouseCursor( void )

+{

+    RECT ClipWindowRect;

+

+    // Hide cursor

+    ShowCursor( FALSE );

+

+    // Clip cursor to the window

+    if( GetWindowRect( _glfwWin.Wnd, &ClipWindowRect ) )

+    {

+        ClipCursor( &ClipWindowRect );

+    }

+

+    // Capture cursor to user window

+    SetCapture( _glfwWin.Wnd );

+}

+

+

+//========================================================================

+// Show mouse cursor (unlock it)

+//========================================================================

+

+void _glfwPlatformShowMouseCursor( void )

+{

+    // Un-capture cursor

+    ReleaseCapture();

+

+    // Disable cursor clipping

+    ClipCursor( NULL );

+

+    // Show cursor

+    ShowCursor( TRUE );

+}

+

+

+//========================================================================

+// Set physical mouse cursor position

+//========================================================================

+

+void _glfwPlatformSetMouseCursorPos( int x, int y )

+{

+    POINT pos;

+

+    // Convert client coordinates to screen coordinates

+    pos.x = x;

+    pos.y = y;

+    ClientToScreen( _glfwWin.Wnd, &pos );

+

+    // Change cursor position

+    SetCursorPos( pos.x, pos.y );

+}

+