2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
2011-03-06 00:46:39 +00:00
|
|
|
// GLFW - An OpenGL library
|
2010-09-07 15:34:51 +00:00
|
|
|
// Platform: Win32/WGL
|
2010-09-07 15:41:26 +00:00
|
|
|
// API version: 3.0
|
2010-09-07 15:34:51 +00:00
|
|
|
// WWW: http://www.glfw.org/
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2002-2006 Marcus Geelnard
|
|
|
|
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
|
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would
|
|
|
|
// be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not
|
|
|
|
// be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
#include <stdio.h>
|
2010-09-13 23:05:03 +00:00
|
|
|
#include <stdlib.h>
|
2010-09-13 21:50:04 +00:00
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Enable/disable minimize/restore animations
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
static int setMinMaxAnimations(int enable)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
ANIMATIONINFO AI;
|
|
|
|
int old_enable;
|
|
|
|
|
|
|
|
// Get old animation setting
|
2010-09-10 20:03:36 +00:00
|
|
|
AI.cbSize = sizeof(ANIMATIONINFO);
|
|
|
|
SystemParametersInfo(SPI_GETANIMATION, AI.cbSize, &AI, 0);
|
2010-09-07 15:34:51 +00:00
|
|
|
old_enable = AI.iMinAnimate;
|
|
|
|
|
|
|
|
// If requested, change setting
|
2010-09-10 20:03:36 +00:00
|
|
|
if (old_enable != enable)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
AI.iMinAnimate = enable;
|
2010-09-10 20:03:36 +00:00
|
|
|
SystemParametersInfo(SPI_SETANIMATION, AI.cbSize, &AI,
|
|
|
|
SPIF_SENDCHANGE);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return old_enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Focus the window and bring it to the top of the stack
|
2011-03-30 13:18:02 +00:00
|
|
|
// Due to some nastiness with how XP handles SetForegroundWindow we have
|
|
|
|
// to go through some really bizarre measures to achieve this
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
static void setForegroundWindow(HWND hWnd)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
int try_count = 0;
|
|
|
|
int old_animate;
|
|
|
|
|
|
|
|
// Try the standard approach first...
|
2010-09-10 20:03:36 +00:00
|
|
|
BringWindowToTop(hWnd);
|
|
|
|
SetForegroundWindow(hWnd);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// If it worked, return now
|
2010-09-10 20:03:36 +00:00
|
|
|
if (hWnd == GetForegroundWindow())
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// Try to modify the system settings (since this is the foreground
|
|
|
|
// process, we are allowed to do this)
|
2010-09-10 20:03:36 +00:00
|
|
|
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0,
|
|
|
|
SPIF_SENDCHANGE);
|
2010-09-07 15:34:51 +00:00
|
|
|
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
|
2010-09-10 20:03:36 +00:00
|
|
|
old_animate = setMinMaxAnimations(0);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// We try this a few times, just to be on the safe side of things...
|
|
|
|
do
|
|
|
|
{
|
|
|
|
// Iconify & restore
|
2010-09-10 20:03:36 +00:00
|
|
|
ShowWindow(hWnd, SW_HIDE);
|
|
|
|
ShowWindow(hWnd, SW_SHOWMINIMIZED);
|
|
|
|
ShowWindow(hWnd, SW_SHOWNORMAL);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Try to get focus
|
2010-09-10 20:03:36 +00:00
|
|
|
BringWindowToTop(hWnd);
|
|
|
|
SetForegroundWindow(hWnd);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// We do not want to keep going on forever, so we keep track of
|
|
|
|
// how many times we tried
|
2010-09-10 20:03:36 +00:00
|
|
|
try_count++;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
2010-09-10 20:03:36 +00:00
|
|
|
while (hWnd != GetForegroundWindow() && try_count <= 3);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Restore the system minimize/restore animation setting
|
2010-09-10 20:03:36 +00:00
|
|
|
setMinMaxAnimations(old_animate);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Try to modify the system settings (since this is now hopefully the
|
|
|
|
// foreground process, we are probably allowed to do this)
|
2010-09-10 20:03:36 +00:00
|
|
|
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0,
|
|
|
|
SPIF_SENDCHANGE);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Returns the specified attribute of the specified pixel format
|
|
|
|
// NOTE: Do not call this unless we have found WGL_ARB_pixel_format
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
static int getPixelFormatAttrib(_GLFWwindow* window, int pixelFormat, int attrib)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
int value = 0;
|
|
|
|
|
2011-05-21 21:13:48 +00:00
|
|
|
if (!window->WGL.GetPixelFormatAttribivARB(window->WGL.DC,
|
|
|
|
pixelFormat,
|
|
|
|
0, 1, &attrib, &value))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// NOTE: We should probably handle this error somehow
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Return a list of available and usable framebuffer configs
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2012-05-06 22:11:51 +00:00
|
|
|
_GLFWfbconfig* fbconfigs;
|
2010-09-07 15:34:51 +00:00
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
2012-05-06 22:11:51 +00:00
|
|
|
int i, available;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
*found = 0;
|
|
|
|
|
2011-09-06 12:51:03 +00:00
|
|
|
if (window->WGL.ARB_pixel_format)
|
2012-05-06 22:11:51 +00:00
|
|
|
{
|
|
|
|
available = getPixelFormatAttrib(window,
|
|
|
|
1,
|
|
|
|
WGL_NUMBER_PIXEL_FORMATS_ARB);
|
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
else
|
2011-05-21 21:13:48 +00:00
|
|
|
{
|
2012-05-06 22:11:51 +00:00
|
|
|
available = DescribePixelFormat(window->WGL.DC,
|
|
|
|
1,
|
|
|
|
sizeof(PIXELFORMATDESCRIPTOR),
|
|
|
|
NULL);
|
2011-05-21 21:13:48 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-05-06 22:11:51 +00:00
|
|
|
if (!available)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-11-23 16:45:23 +00:00
|
|
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "Win32/WGL: No pixel formats found");
|
2010-09-07 15:34:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfigs = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * available);
|
|
|
|
if (!fbconfigs)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2011-05-21 21:13:48 +00:00
|
|
|
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
|
|
|
"Win32/WGL: Failed to allocate _GLFWfbconfig array");
|
2010-09-07 15:34:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-05-06 22:11:51 +00:00
|
|
|
for (i = 1; i <= available; i++)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2012-05-06 22:11:51 +00:00
|
|
|
_GLFWfbconfig* fbconfig = fbconfigs + *found;
|
|
|
|
|
2011-09-06 12:51:03 +00:00
|
|
|
if (window->WGL.ARB_pixel_format)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// Get pixel format attributes through WGL_ARB_pixel_format
|
2010-09-13 21:50:04 +00:00
|
|
|
if (!getPixelFormatAttrib(window, i, WGL_SUPPORT_OPENGL_ARB) ||
|
|
|
|
!getPixelFormatAttrib(window, i, WGL_DRAW_TO_WINDOW_ARB) ||
|
|
|
|
!getPixelFormatAttrib(window, i, WGL_DOUBLE_BUFFER_ARB))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
if (getPixelFormatAttrib(window, i, WGL_PIXEL_TYPE_ARB) !=
|
|
|
|
WGL_TYPE_RGBA_ARB)
|
|
|
|
{
|
2010-09-07 15:34:51 +00:00
|
|
|
continue;
|
2010-09-13 21:50:04 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2011-02-08 18:50:06 +00:00
|
|
|
if (getPixelFormatAttrib(window, i, WGL_ACCELERATION_ARB) ==
|
|
|
|
WGL_NO_ACCELERATION_ARB)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->redBits =
|
2010-09-13 21:50:04 +00:00
|
|
|
getPixelFormatAttrib(window, i, WGL_RED_BITS_ARB);
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->greenBits =
|
2010-09-13 21:50:04 +00:00
|
|
|
getPixelFormatAttrib(window, i, WGL_GREEN_BITS_ARB);
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->blueBits =
|
2010-09-13 21:50:04 +00:00
|
|
|
getPixelFormatAttrib(window, i, WGL_BLUE_BITS_ARB);
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->alphaBits =
|
2010-09-13 21:50:04 +00:00
|
|
|
getPixelFormatAttrib(window, i, WGL_ALPHA_BITS_ARB);
|
|
|
|
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->depthBits =
|
2010-09-13 21:50:04 +00:00
|
|
|
getPixelFormatAttrib(window, i, WGL_DEPTH_BITS_ARB);
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->stencilBits =
|
2010-09-13 21:50:04 +00:00
|
|
|
getPixelFormatAttrib(window, i, WGL_STENCIL_BITS_ARB);
|
|
|
|
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->accumRedBits =
|
2010-09-13 21:50:04 +00:00
|
|
|
getPixelFormatAttrib(window, i, WGL_ACCUM_RED_BITS_ARB);
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->accumGreenBits =
|
2010-09-13 21:50:04 +00:00
|
|
|
getPixelFormatAttrib(window, i, WGL_ACCUM_GREEN_BITS_ARB);
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->accumBlueBits =
|
2010-09-13 21:50:04 +00:00
|
|
|
getPixelFormatAttrib(window, i, WGL_ACCUM_BLUE_BITS_ARB);
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->accumAlphaBits =
|
2010-09-13 21:50:04 +00:00
|
|
|
getPixelFormatAttrib(window, i, WGL_ACCUM_ALPHA_BITS_ARB);
|
|
|
|
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->auxBuffers =
|
2010-09-13 21:50:04 +00:00
|
|
|
getPixelFormatAttrib(window, i, WGL_AUX_BUFFERS_ARB);
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->stereo =
|
2010-09-13 21:50:04 +00:00
|
|
|
getPixelFormatAttrib(window, i, WGL_STEREO_ARB);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2011-09-06 12:51:03 +00:00
|
|
|
if (window->WGL.ARB_multisample)
|
2010-09-13 21:50:04 +00:00
|
|
|
{
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->samples =
|
2010-09-13 21:50:04 +00:00
|
|
|
getPixelFormatAttrib(window, i, WGL_SAMPLES_ARB);
|
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
else
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->samples = 0;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Get pixel format attributes through old-fashioned PFDs
|
|
|
|
|
2012-03-30 00:28:15 +00:00
|
|
|
if (!DescribePixelFormat(window->WGL.DC,
|
|
|
|
i,
|
|
|
|
sizeof(PIXELFORMATDESCRIPTOR),
|
|
|
|
&pfd))
|
2011-05-21 21:13:48 +00:00
|
|
|
{
|
2010-09-07 15:34:51 +00:00
|
|
|
continue;
|
2011-05-21 21:13:48 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
if (!(pfd.dwFlags & PFD_DRAW_TO_WINDOW) ||
|
|
|
|
!(pfd.dwFlags & PFD_SUPPORT_OPENGL) ||
|
|
|
|
!(pfd.dwFlags & PFD_DOUBLEBUFFER))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
if (!(pfd.dwFlags & PFD_GENERIC_ACCELERATED) &&
|
|
|
|
(pfd.dwFlags & PFD_GENERIC_FORMAT))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
if (pfd.iPixelType != PFD_TYPE_RGBA)
|
2010-09-07 15:34:51 +00:00
|
|
|
continue;
|
|
|
|
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->redBits = pfd.cRedBits;
|
|
|
|
fbconfig->greenBits = pfd.cGreenBits;
|
|
|
|
fbconfig->blueBits = pfd.cBlueBits;
|
|
|
|
fbconfig->alphaBits = pfd.cAlphaBits;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->depthBits = pfd.cDepthBits;
|
|
|
|
fbconfig->stencilBits = pfd.cStencilBits;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->accumRedBits = pfd.cAccumRedBits;
|
|
|
|
fbconfig->accumGreenBits = pfd.cAccumGreenBits;
|
|
|
|
fbconfig->accumBlueBits = pfd.cAccumBlueBits;
|
|
|
|
fbconfig->accumAlphaBits = pfd.cAccumAlphaBits;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->auxBuffers = pfd.cAuxBuffers;
|
|
|
|
fbconfig->stereo = (pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2011-01-01 23:11:47 +00:00
|
|
|
// PFD pixel formats do not support FSAA
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->samples = 0;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-05-06 22:11:51 +00:00
|
|
|
fbconfig->platformID = i;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
(*found)++;
|
|
|
|
}
|
|
|
|
|
2012-05-06 22:11:51 +00:00
|
|
|
return fbconfigs;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Creates an OpenGL context on the specified device context
|
|
|
|
//========================================================================
|
|
|
|
|
2010-10-04 16:26:34 +00:00
|
|
|
static GLboolean createContext(_GLFWwindow* window,
|
|
|
|
const _GLFWwndconfig* wndconfig,
|
|
|
|
int pixelFormat)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
2011-03-07 19:51:34 +00:00
|
|
|
int i = 0, attribs[40];
|
2010-10-04 16:17:53 +00:00
|
|
|
HGLRC share = NULL;
|
|
|
|
|
|
|
|
if (wndconfig->share)
|
|
|
|
share = wndconfig->share->WGL.context;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-03-30 00:28:15 +00:00
|
|
|
if (!DescribePixelFormat(window->WGL.DC, pixelFormat, sizeof(pfd), &pfd))
|
2010-09-14 00:17:18 +00:00
|
|
|
{
|
2011-05-21 21:13:48 +00:00
|
|
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
|
|
|
|
"Win32/WGL: Failed to retrieve PFD for selected pixel format");
|
2010-10-04 16:17:53 +00:00
|
|
|
return GL_FALSE;
|
2010-09-14 00:17:18 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-03-30 00:28:15 +00:00
|
|
|
if (!SetPixelFormat(window->WGL.DC, pixelFormat, &pfd))
|
2010-09-14 00:17:18 +00:00
|
|
|
{
|
2011-05-21 21:13:48 +00:00
|
|
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
|
|
|
|
"Win32/WGL: Failed to set selected pixel format");
|
2010-10-04 16:17:53 +00:00
|
|
|
return GL_FALSE;
|
2010-09-14 00:17:18 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2011-09-06 12:51:03 +00:00
|
|
|
if (window->WGL.ARB_create_context)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-14 00:17:18 +00:00
|
|
|
// Use the newer wglCreateContextAttribsARB creation method
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
if (wndconfig->glMajor != 1 || wndconfig->glMinor != 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// Request an explicitly versioned context
|
|
|
|
|
|
|
|
attribs[i++] = WGL_CONTEXT_MAJOR_VERSION_ARB;
|
|
|
|
attribs[i++] = wndconfig->glMajor;
|
|
|
|
attribs[i++] = WGL_CONTEXT_MINOR_VERSION_ARB;
|
|
|
|
attribs[i++] = wndconfig->glMinor;
|
|
|
|
}
|
|
|
|
|
2011-03-07 19:51:34 +00:00
|
|
|
if (wndconfig->glForward || wndconfig->glDebug || wndconfig->glRobustness)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-11-15 18:28:06 +00:00
|
|
|
int flags = 0;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
if (wndconfig->glForward)
|
2010-09-07 15:34:51 +00:00
|
|
|
flags |= WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
if (wndconfig->glDebug)
|
2010-09-07 15:34:51 +00:00
|
|
|
flags |= WGL_CONTEXT_DEBUG_BIT_ARB;
|
|
|
|
|
2011-03-07 19:51:34 +00:00
|
|
|
if (wndconfig->glRobustness)
|
|
|
|
flags |= WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB;
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
attribs[i++] = WGL_CONTEXT_FLAGS_ARB;
|
|
|
|
attribs[i++] = flags;
|
|
|
|
}
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
if (wndconfig->glProfile)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-11-15 18:28:06 +00:00
|
|
|
int flags = 0;
|
|
|
|
|
2011-09-06 12:51:03 +00:00
|
|
|
if (!window->WGL.ARB_create_context_profile)
|
2010-11-15 18:28:06 +00:00
|
|
|
{
|
2011-05-21 21:13:48 +00:00
|
|
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"Win32/WGL: OpenGL profile requested but "
|
|
|
|
"WGL_ARB_create_context_profile is unavailable");
|
2010-11-15 18:28:06 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE &&
|
2011-09-06 12:51:03 +00:00
|
|
|
!window->WGL.EXT_create_context_es2_profile)
|
2010-11-15 18:28:06 +00:00
|
|
|
{
|
2011-05-21 21:13:48 +00:00
|
|
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"Win32/WGL: OpenGL ES 2.x profile requested but "
|
|
|
|
"WGL_EXT_create_context_es2_profile is unavailable");
|
2010-11-15 18:28:06 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
if (wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE)
|
2010-09-07 15:34:51 +00:00
|
|
|
flags = WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
|
2010-11-15 18:28:06 +00:00
|
|
|
else if (wndconfig->glProfile == GLFW_OPENGL_COMPAT_PROFILE)
|
2010-09-07 15:34:51 +00:00
|
|
|
flags = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
|
2010-11-15 18:28:06 +00:00
|
|
|
else if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE)
|
|
|
|
flags = WGL_CONTEXT_ES2_PROFILE_BIT_EXT;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
attribs[i++] = WGL_CONTEXT_PROFILE_MASK_ARB;
|
|
|
|
attribs[i++] = flags;
|
|
|
|
}
|
|
|
|
|
2011-03-07 19:51:34 +00:00
|
|
|
if (wndconfig->glRobustness)
|
|
|
|
{
|
|
|
|
int strategy;
|
|
|
|
|
2011-09-06 12:51:03 +00:00
|
|
|
if (!window->WGL.ARB_create_context_robustness)
|
2011-03-07 19:51:34 +00:00
|
|
|
{
|
2011-05-21 21:13:48 +00:00
|
|
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"Win32/WGL: An OpenGL robustness strategy was "
|
|
|
|
"requested but WGL_ARB_create_context_robustness "
|
|
|
|
"is unavailable");
|
2011-03-07 19:51:34 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wndconfig->glRobustness == GLFW_OPENGL_NO_RESET_NOTIFICATION)
|
|
|
|
strategy = WGL_NO_RESET_NOTIFICATION_ARB;
|
|
|
|
else if (wndconfig->glRobustness == GLFW_OPENGL_LOSE_CONTEXT_ON_RESET)
|
|
|
|
strategy = WGL_LOSE_CONTEXT_ON_RESET_ARB;
|
|
|
|
|
|
|
|
attribs[i++] = WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB;
|
|
|
|
attribs[i++] = strategy;
|
|
|
|
}
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
attribs[i++] = 0;
|
|
|
|
|
2010-10-04 16:17:53 +00:00
|
|
|
window->WGL.context = window->WGL.CreateContextAttribsARB(window->WGL.DC,
|
|
|
|
share,
|
|
|
|
attribs);
|
|
|
|
if (!window->WGL.context)
|
2010-09-14 00:17:18 +00:00
|
|
|
{
|
2011-05-21 21:13:48 +00:00
|
|
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"Win32/WGL: Failed to create OpenGL context");
|
2010-10-04 16:17:53 +00:00
|
|
|
return GL_FALSE;
|
2010-09-14 00:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-04 16:17:53 +00:00
|
|
|
window->WGL.context = wglCreateContext(window->WGL.DC);
|
|
|
|
if (!window->WGL.context)
|
2010-09-14 00:17:18 +00:00
|
|
|
{
|
2011-05-21 21:13:48 +00:00
|
|
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32/WGL: Failed to create OpenGL context");
|
2010-10-04 16:17:53 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (share)
|
|
|
|
{
|
|
|
|
if (!wglShareLists(share, window->WGL.context))
|
|
|
|
{
|
2011-05-21 21:13:48 +00:00
|
|
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32/WGL: Failed to enable sharing with "
|
|
|
|
"specified OpenGL context");
|
2010-10-04 16:17:53 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2010-09-14 00:17:18 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-10-04 16:17:53 +00:00
|
|
|
return GL_TRUE;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-04 22:47:39 +00:00
|
|
|
//========================================================================
|
|
|
|
// Hide mouse cursor
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
static void hideMouseCursor(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Capture mouse cursor
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
static void captureMouseCursor(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
RECT ClipWindowRect;
|
|
|
|
|
|
|
|
ShowCursor(FALSE);
|
|
|
|
|
|
|
|
// Clip cursor to the window
|
|
|
|
if (GetWindowRect(window->Win32.handle, &ClipWindowRect))
|
|
|
|
ClipCursor(&ClipWindowRect);
|
|
|
|
|
|
|
|
// Capture cursor to user window
|
|
|
|
SetCapture(window->Win32.handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Show mouse cursor
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
static void showMouseCursor(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
// Un-capture cursor
|
|
|
|
ReleaseCapture();
|
|
|
|
|
|
|
|
// Release the cursor from the window
|
|
|
|
ClipCursor(NULL);
|
|
|
|
|
|
|
|
ShowCursor(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
// Translates a Windows key to the corresponding GLFW key
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
static int translateKey(WPARAM wParam, LPARAM lParam)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
MSG next_msg;
|
|
|
|
DWORD msg_time;
|
|
|
|
DWORD scan_code;
|
|
|
|
|
2011-01-10 20:19:27 +00:00
|
|
|
// Check for numeric keypad keys.
|
|
|
|
// Note: This way we always force "NumLock = ON", which is intentional
|
|
|
|
// since the returned key code should correspond to a physical
|
|
|
|
// location.
|
2010-09-10 20:03:36 +00:00
|
|
|
int hiFlags = HIWORD(lParam);
|
|
|
|
if (!(hiFlags & 0x100))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-10 20:03:36 +00:00
|
|
|
switch (MapVirtualKey(hiFlags & 0xFF, 1))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
case VK_INSERT: return GLFW_KEY_KP_0;
|
|
|
|
case VK_END: return GLFW_KEY_KP_1;
|
|
|
|
case VK_DOWN: return GLFW_KEY_KP_2;
|
|
|
|
case VK_NEXT: return GLFW_KEY_KP_3;
|
|
|
|
case VK_LEFT: return GLFW_KEY_KP_4;
|
|
|
|
case VK_CLEAR: return GLFW_KEY_KP_5;
|
|
|
|
case VK_RIGHT: return GLFW_KEY_KP_6;
|
|
|
|
case VK_HOME: return GLFW_KEY_KP_7;
|
|
|
|
case VK_UP: return GLFW_KEY_KP_8;
|
|
|
|
case VK_PRIOR: 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_DELETE: return GLFW_KEY_KP_DECIMAL;
|
2011-01-10 20:19:27 +00:00
|
|
|
default: break;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check which key was pressed or released
|
2010-09-10 20:03:36 +00:00
|
|
|
switch (wParam)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// 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)
|
2010-09-10 20:03:36 +00:00
|
|
|
scan_code = MapVirtualKey(VK_RSHIFT, 0);
|
|
|
|
if (((lParam & 0x01ff0000) >> 16) == scan_code)
|
2011-01-10 20:19:27 +00:00
|
|
|
return GLFW_KEY_RIGHT_SHIFT;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2011-01-10 20:19:27 +00:00
|
|
|
return GLFW_KEY_LEFT_SHIFT;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The CTRL keys require special handling
|
|
|
|
case VK_CONTROL:
|
|
|
|
{
|
|
|
|
// Is this an extended key (i.e. right key)?
|
2010-09-10 20:03:36 +00:00
|
|
|
if (lParam & 0x01000000)
|
2011-01-10 20:38:08 +00:00
|
|
|
return GLFW_KEY_RIGHT_CONTROL;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// 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();
|
2010-09-10 20:03:36 +00:00
|
|
|
if (PeekMessage(&next_msg, NULL, 0, 0, PM_NOREMOVE))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-10 20:03:36 +00:00
|
|
|
if (next_msg.message == WM_KEYDOWN ||
|
|
|
|
next_msg.message == WM_SYSKEYDOWN)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-10 20:03:36 +00:00
|
|
|
if (next_msg.wParam == VK_MENU &&
|
2010-09-07 15:34:51 +00:00
|
|
|
(next_msg.lParam & 0x01000000) &&
|
2010-09-10 20:03:36 +00:00
|
|
|
next_msg.time == msg_time)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// Next message is a RALT down message, which
|
|
|
|
// means that this is NOT a proper LCTRL message!
|
2011-01-10 20:19:27 +00:00
|
|
|
return -1;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 20:38:08 +00:00
|
|
|
return GLFW_KEY_LEFT_CONTROL;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The ALT keys require special handling
|
|
|
|
case VK_MENU:
|
|
|
|
{
|
|
|
|
// Is this an extended key (i.e. right key)?
|
2010-09-10 20:03:36 +00:00
|
|
|
if (lParam & 0x01000000)
|
2011-01-10 20:19:27 +00:00
|
|
|
return GLFW_KEY_RIGHT_ALT;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2011-01-10 20:19:27 +00:00
|
|
|
return GLFW_KEY_LEFT_ALT;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The ENTER keys require special handling
|
|
|
|
case VK_RETURN:
|
|
|
|
{
|
|
|
|
// Is this an extended key (i.e. right key)?
|
2010-09-10 20:03:36 +00:00
|
|
|
if (lParam & 0x01000000)
|
2010-09-07 15:34:51 +00:00
|
|
|
return GLFW_KEY_KP_ENTER;
|
|
|
|
|
|
|
|
return GLFW_KEY_ENTER;
|
|
|
|
}
|
|
|
|
|
2011-01-10 20:19:27 +00:00
|
|
|
// Funcion keys (non-printable keys)
|
|
|
|
case VK_ESCAPE: return GLFW_KEY_ESCAPE;
|
2010-09-07 15:34:51 +00:00
|
|
|
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;
|
2011-01-10 20:19:27 +00:00
|
|
|
case VK_PRIOR: return GLFW_KEY_PAGE_UP;
|
|
|
|
case VK_NEXT: return GLFW_KEY_PAGE_DOWN;
|
2010-09-07 15:34:51 +00:00
|
|
|
case VK_INSERT: return GLFW_KEY_INSERT;
|
2011-01-10 20:19:27 +00:00
|
|
|
case VK_DELETE: return GLFW_KEY_DELETE;
|
2010-09-07 15:34:51 +00:00
|
|
|
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;
|
2011-01-10 20:19:27 +00:00
|
|
|
case VK_NUMLOCK: return GLFW_KEY_NUM_LOCK;
|
|
|
|
case VK_CAPITAL: return GLFW_KEY_CAPS_LOCK;
|
|
|
|
case VK_SCROLL: return GLFW_KEY_SCROLL_LOCK;
|
|
|
|
case VK_PAUSE: return GLFW_KEY_PAUSE;
|
|
|
|
case VK_LWIN: return GLFW_KEY_LEFT_SUPER;
|
|
|
|
case VK_RWIN: return GLFW_KEY_RIGHT_SUPER;
|
|
|
|
case VK_APPS: return GLFW_KEY_MENU;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2011-01-10 20:19:27 +00:00
|
|
|
// Printable keys are mapped according to US layout
|
|
|
|
case VK_SPACE: return GLFW_KEY_SPACE;
|
|
|
|
case 0x30: return GLFW_KEY_0;
|
|
|
|
case 0x31: return GLFW_KEY_1;
|
|
|
|
case 0x32: return GLFW_KEY_2;
|
|
|
|
case 0x33: return GLFW_KEY_3;
|
|
|
|
case 0x34: return GLFW_KEY_4;
|
|
|
|
case 0x35: return GLFW_KEY_5;
|
|
|
|
case 0x36: return GLFW_KEY_6;
|
|
|
|
case 0x37: return GLFW_KEY_7;
|
|
|
|
case 0x38: return GLFW_KEY_8;
|
|
|
|
case 0x39: return GLFW_KEY_9;
|
|
|
|
case 0x41: return GLFW_KEY_A;
|
|
|
|
case 0x42: return GLFW_KEY_B;
|
|
|
|
case 0x43: return GLFW_KEY_C;
|
|
|
|
case 0x44: return GLFW_KEY_D;
|
|
|
|
case 0x45: return GLFW_KEY_E;
|
|
|
|
case 0x46: return GLFW_KEY_F;
|
|
|
|
case 0x47: return GLFW_KEY_G;
|
|
|
|
case 0x48: return GLFW_KEY_H;
|
|
|
|
case 0x49: return GLFW_KEY_I;
|
|
|
|
case 0x4A: return GLFW_KEY_J;
|
|
|
|
case 0x4B: return GLFW_KEY_K;
|
|
|
|
case 0x4C: return GLFW_KEY_L;
|
|
|
|
case 0x4D: return GLFW_KEY_M;
|
|
|
|
case 0x4E: return GLFW_KEY_N;
|
|
|
|
case 0x4F: return GLFW_KEY_O;
|
|
|
|
case 0x50: return GLFW_KEY_P;
|
|
|
|
case 0x51: return GLFW_KEY_Q;
|
|
|
|
case 0x52: return GLFW_KEY_R;
|
|
|
|
case 0x53: return GLFW_KEY_S;
|
|
|
|
case 0x54: return GLFW_KEY_T;
|
|
|
|
case 0x55: return GLFW_KEY_U;
|
|
|
|
case 0x56: return GLFW_KEY_V;
|
|
|
|
case 0x57: return GLFW_KEY_W;
|
|
|
|
case 0x58: return GLFW_KEY_X;
|
|
|
|
case 0x59: return GLFW_KEY_Y;
|
|
|
|
case 0x5A: return GLFW_KEY_Z;
|
|
|
|
case 0xBD: return GLFW_KEY_MINUS;
|
|
|
|
case 0xBB: return GLFW_KEY_EQUAL;
|
|
|
|
case 0xDB: return GLFW_KEY_LEFT_BRACKET;
|
|
|
|
case 0xDD: return GLFW_KEY_RIGHT_BRACKET;
|
|
|
|
case 0xDC: return GLFW_KEY_BACKSLASH;
|
|
|
|
case 0xBA: return GLFW_KEY_SEMICOLON;
|
|
|
|
case 0xDE: return GLFW_KEY_APOSTROPHE;
|
|
|
|
case 0xC0: return GLFW_KEY_GRAVE_ACCENT;
|
|
|
|
case 0xBC: return GLFW_KEY_COMMA;
|
|
|
|
case 0xBE: return GLFW_KEY_PERIOD;
|
|
|
|
case 0xBF: return GLFW_KEY_SLASH;
|
|
|
|
case 0xDF: return GLFW_KEY_WORLD_1;
|
|
|
|
case 0xE2: return GLFW_KEY_WORLD_2;
|
|
|
|
default: break;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
2011-01-10 20:19:27 +00:00
|
|
|
|
|
|
|
// No matching translation was found, so return -1
|
|
|
|
return -1;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Translates a Windows key to Unicode
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
static void translateChar(_GLFWwindow* window, DWORD wParam, DWORD lParam)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-10 20:03:36 +00:00
|
|
|
BYTE keyboard_state[256];
|
|
|
|
WCHAR unicode_buf[10];
|
|
|
|
UINT scan_code;
|
2010-09-13 21:50:04 +00:00
|
|
|
int i, num_chars;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
GetKeyboardState(keyboard_state);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Derive scan code from lParam and action
|
|
|
|
scan_code = (lParam & 0x01ff0000) >> 16;
|
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
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
|
|
|
|
);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Report characters
|
2010-09-10 20:03:36 +00:00
|
|
|
for (i = 0; i < num_chars; i++)
|
2010-09-13 21:50:04 +00:00
|
|
|
_glfwInputChar(window, (int) unicode_buf[i]);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Window callback function (handles window events)
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|
|
|
WPARAM wParam, LPARAM lParam)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-12 14:26:00 +00:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) GetWindowLongPtr(hWnd, 0);
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
switch (uMsg)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-13 23:05:03 +00:00
|
|
|
case WM_CREATE:
|
|
|
|
{
|
|
|
|
CREATESTRUCT* cs = (CREATESTRUCT*) lParam;
|
2010-09-14 00:17:18 +00:00
|
|
|
SetWindowLongPtr(hWnd, 0, (LONG_PTR) cs->lpCreateParams);
|
2010-09-13 23:05:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
case WM_ACTIVATE:
|
|
|
|
{
|
2010-09-18 23:24:51 +00:00
|
|
|
// Window was (de)activated and/or (de)iconified
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-18 23:24:51 +00:00
|
|
|
BOOL active = LOWORD(wParam) != WA_INACTIVE;
|
|
|
|
BOOL iconified = HIWORD(wParam) ? TRUE : FALSE;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-19 00:49:42 +00:00
|
|
|
if (active && iconified)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-19 00:49:42 +00:00
|
|
|
// This is a workaround for window iconification using the
|
|
|
|
// taskbar leading to windows being told they're active and
|
|
|
|
// iconified and then never told they're deactivated
|
|
|
|
active = FALSE;
|
|
|
|
}
|
2010-09-18 23:24:51 +00:00
|
|
|
|
2010-09-19 00:49:42 +00:00
|
|
|
if (!active && _glfwLibrary.activeWindow == window)
|
|
|
|
{
|
|
|
|
// The window was deactivated (or iconified, see above)
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2011-09-06 11:55:29 +00:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
|
|
|
showMouseCursor(window);
|
2010-09-18 23:24:51 +00:00
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
if (window->mode == GLFW_FULLSCREEN)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-10 20:03:36 +00:00
|
|
|
if (!iconified)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-18 23:24:51 +00:00
|
|
|
// Iconify the (on top, borderless, oddly positioned)
|
|
|
|
// window or the user will be annoyed
|
2010-09-19 23:57:50 +00:00
|
|
|
_glfwPlatformIconifyWindow(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-18 23:24:51 +00:00
|
|
|
if (_glfwLibrary.Win32.monitor.modeChanged)
|
|
|
|
{
|
|
|
|
_glfwRestoreVideoMode();
|
|
|
|
_glfwLibrary.Win32.monitor.modeChanged = GL_FALSE;
|
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-19 00:49:42 +00:00
|
|
|
else if (active && _glfwLibrary.activeWindow != window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-19 00:49:42 +00:00
|
|
|
// The window was activated
|
|
|
|
|
2011-09-06 11:55:29 +00:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
|
|
|
captureMouseCursor(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-18 23:24:51 +00:00
|
|
|
if (window->mode == GLFW_FULLSCREEN)
|
|
|
|
{
|
|
|
|
if (!_glfwLibrary.Win32.monitor.modeChanged)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-18 23:24:51 +00:00
|
|
|
_glfwSetVideoMode(&_glfwLibrary.Win32.monitor.width,
|
|
|
|
&_glfwLibrary.Win32.monitor.height,
|
|
|
|
&_glfwLibrary.Win32.monitor.bitsPerPixel,
|
|
|
|
&_glfwLibrary.Win32.monitor.refreshRate,
|
|
|
|
GL_TRUE);
|
|
|
|
|
|
|
|
_glfwLibrary.Win32.monitor.modeChanged = GL_TRUE;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-18 23:24:51 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-19 00:49:42 +00:00
|
|
|
_glfwInputWindowFocus(window, active);
|
2011-10-09 15:10:40 +00:00
|
|
|
_glfwInputWindowIconify(window, iconified);
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
{
|
2010-09-10 20:03:36 +00:00
|
|
|
switch (wParam & 0xfff0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
case SC_SCREENSAVE:
|
|
|
|
case SC_MONITORPOWER:
|
|
|
|
{
|
2010-09-12 14:26:00 +00:00
|
|
|
if (window->mode == GLFW_FULLSCREEN)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-10 20:03:36 +00:00
|
|
|
// We are running in fullscreen mode, so disallow
|
|
|
|
// screen saver and screen blanking
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// User trying to access application menu using ALT?
|
|
|
|
case SC_KEYMENU:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_CLOSE:
|
|
|
|
{
|
2010-09-14 00:17:18 +00:00
|
|
|
// Flag this window for closing (handled in glfwPollEvents)
|
2010-09-16 04:02:44 +00:00
|
|
|
window->closeRequested = GL_TRUE;
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
{
|
2010-09-13 21:50:04 +00:00
|
|
|
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_PRESS);
|
2010-09-10 20:03:36 +00:00
|
|
|
|
2010-10-24 16:28:55 +00:00
|
|
|
if (_glfwLibrary.charCallback)
|
2010-09-13 21:50:04 +00:00
|
|
|
translateChar(window, (DWORD) wParam, (DWORD) lParam);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-02-07 15:44:22 +00:00
|
|
|
break;
|
2010-11-15 19:21:09 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_SYSKEYUP:
|
|
|
|
{
|
|
|
|
// Special trick: release both shift keys on SHIFT up event
|
2010-09-10 20:03:36 +00:00
|
|
|
if (wParam == VK_SHIFT)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2011-01-10 20:19:27 +00:00
|
|
|
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, GLFW_RELEASE);
|
|
|
|
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, GLFW_RELEASE);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
2010-09-13 21:50:04 +00:00
|
|
|
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_RELEASE);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-02-07 15:44:22 +00:00
|
|
|
break;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case WM_LBUTTONDOWN:
|
2010-09-10 20:03:36 +00:00
|
|
|
{
|
2010-09-07 15:34:51 +00:00
|
|
|
SetCapture(hWnd);
|
2010-09-13 21:50:04 +00:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS);
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
2010-09-10 20:03:36 +00:00
|
|
|
}
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
case WM_RBUTTONDOWN:
|
2010-09-10 20:03:36 +00:00
|
|
|
{
|
2010-09-07 15:34:51 +00:00
|
|
|
SetCapture(hWnd);
|
2010-09-13 21:50:04 +00:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS);
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
2010-09-10 20:03:36 +00:00
|
|
|
}
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
case WM_MBUTTONDOWN:
|
2010-09-10 20:03:36 +00:00
|
|
|
{
|
2010-09-07 15:34:51 +00:00
|
|
|
SetCapture(hWnd);
|
2010-09-13 21:50:04 +00:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_MIDDLE, GLFW_PRESS);
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
2010-09-10 20:03:36 +00:00
|
|
|
}
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
case WM_XBUTTONDOWN:
|
|
|
|
{
|
2010-09-10 20:03:36 +00:00
|
|
|
if (HIWORD(wParam) == XBUTTON1)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
SetCapture(hWnd);
|
2010-09-13 21:50:04 +00:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_4, GLFW_PRESS);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
2010-09-10 20:03:36 +00:00
|
|
|
else if (HIWORD(wParam) == XBUTTON2)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
SetCapture(hWnd);
|
2010-09-13 21:50:04 +00:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_5, GLFW_PRESS);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
2010-09-10 20:03:36 +00:00
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_LBUTTONUP:
|
2010-09-10 20:03:36 +00:00
|
|
|
{
|
2010-09-07 15:34:51 +00:00
|
|
|
ReleaseCapture();
|
2010-09-13 21:50:04 +00:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE);
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
2010-09-10 20:03:36 +00:00
|
|
|
}
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
case WM_RBUTTONUP:
|
2010-09-10 20:03:36 +00:00
|
|
|
{
|
2010-09-07 15:34:51 +00:00
|
|
|
ReleaseCapture();
|
2010-09-13 21:50:04 +00:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE);
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
2010-09-10 20:03:36 +00:00
|
|
|
}
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
case WM_MBUTTONUP:
|
2010-09-10 20:03:36 +00:00
|
|
|
{
|
2010-09-07 15:34:51 +00:00
|
|
|
ReleaseCapture();
|
2010-09-13 21:50:04 +00:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_MIDDLE, GLFW_RELEASE);
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
2010-09-10 20:03:36 +00:00
|
|
|
}
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
case WM_XBUTTONUP:
|
|
|
|
{
|
2010-09-10 20:03:36 +00:00
|
|
|
if (HIWORD(wParam) == XBUTTON1)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
ReleaseCapture();
|
2010-09-13 21:50:04 +00:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_4, GLFW_RELEASE);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
2010-09-10 20:03:36 +00:00
|
|
|
else if (HIWORD(wParam) == XBUTTON2)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
ReleaseCapture();
|
2010-09-13 21:50:04 +00:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_5, GLFW_RELEASE);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
2010-09-10 20:03:36 +00:00
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
{
|
2010-09-12 14:26:00 +00:00
|
|
|
int newMouseX, newMouseY;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Get signed (!) mouse position
|
2010-09-12 14:26:00 +00:00
|
|
|
newMouseX = (int)((short)LOWORD(lParam));
|
|
|
|
newMouseY = (int)((short)HIWORD(lParam));
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
if (newMouseX != window->Win32.oldMouseX ||
|
|
|
|
newMouseY != window->Win32.oldMouseY)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2011-10-09 15:10:40 +00:00
|
|
|
int x, y;
|
|
|
|
|
2011-09-06 11:55:29 +00:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2011-09-06 11:55:29 +00:00
|
|
|
if (_glfwLibrary.activeWindow != window)
|
|
|
|
return 0;
|
|
|
|
|
2011-10-09 15:40:29 +00:00
|
|
|
x = newMouseX - window->Win32.oldMouseX;
|
|
|
|
y = newMouseY - window->Win32.oldMouseY;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-09 15:10:40 +00:00
|
|
|
x = newMouseX;
|
2011-10-09 15:40:29 +00:00
|
|
|
y = newMouseY;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
2010-09-10 20:03:36 +00:00
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
window->Win32.oldMouseX = newMouseX;
|
|
|
|
window->Win32.oldMouseY = newMouseY;
|
2011-09-06 11:55:29 +00:00
|
|
|
window->Win32.cursorCentered = GL_FALSE;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2011-10-09 15:10:40 +00:00
|
|
|
_glfwInputCursorMotion(window, x, y);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
2010-09-10 20:03:36 +00:00
|
|
|
|
2012-03-22 12:17:44 +00:00
|
|
|
if (!window->Win32.cursorInside)
|
|
|
|
{
|
|
|
|
TRACKMOUSEEVENT tme;
|
|
|
|
ZeroMemory(&tme, sizeof(tme));
|
|
|
|
tme.cbSize = sizeof(tme);
|
|
|
|
tme.dwFlags = TME_LEAVE;
|
|
|
|
tme.hwndTrack = window->Win32.handle;
|
|
|
|
TrackMouseEvent(&tme);
|
|
|
|
|
|
|
|
window->Win32.cursorInside = GL_TRUE;
|
|
|
|
_glfwInputCursorEnter(window, GL_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
{
|
|
|
|
window->Win32.cursorInside = GL_FALSE;
|
|
|
|
_glfwInputCursorEnter(window, GL_FALSE);
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
{
|
2012-03-28 19:54:09 +00:00
|
|
|
_glfwInputScroll(window, 0.0, (SHORT) HIWORD(wParam) / (double) WHEEL_DELTA);
|
2010-09-27 00:32:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-09-10 20:03:36 +00:00
|
|
|
|
2010-09-27 00:32:41 +00:00
|
|
|
case WM_MOUSEHWHEEL:
|
|
|
|
{
|
|
|
|
// This message is only sent on Windows Vista and later
|
2010-09-10 20:03:36 +00:00
|
|
|
|
2012-03-28 19:54:09 +00:00
|
|
|
_glfwInputScroll(window, (SHORT) HIWORD(wParam) / (double) WHEEL_DELTA, 0.0);
|
2010-09-12 14:26:00 +00:00
|
|
|
return 0;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case WM_SIZE:
|
|
|
|
{
|
2011-09-06 11:55:29 +00:00
|
|
|
// If window is in cursor capture mode, update clipping rect
|
|
|
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
RECT ClipWindowRect;
|
2010-09-12 14:26:00 +00:00
|
|
|
if (GetWindowRect(window->Win32.handle, &ClipWindowRect))
|
2010-09-10 20:03:36 +00:00
|
|
|
ClipCursor(&ClipWindowRect);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2011-10-09 15:10:40 +00:00
|
|
|
_glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam));
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOVE:
|
|
|
|
{
|
2011-09-06 11:55:29 +00:00
|
|
|
// If window is in cursor capture mode, update clipping rect
|
|
|
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
RECT ClipWindowRect;
|
2010-09-12 14:26:00 +00:00
|
|
|
if (GetWindowRect(window->Win32.handle, &ClipWindowRect))
|
2010-09-10 20:03:36 +00:00
|
|
|
ClipCursor(&ClipWindowRect);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
2011-10-09 15:10:40 +00:00
|
|
|
|
|
|
|
_glfwInputWindowPos(window, LOWORD(lParam), HIWORD(lParam));
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Was the window contents damaged?
|
|
|
|
case WM_PAINT:
|
|
|
|
{
|
2011-10-09 19:12:13 +00:00
|
|
|
_glfwInputWindowDamage(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_DISPLAYCHANGE:
|
|
|
|
{
|
|
|
|
// TODO: Do stuff here.
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass all unhandled messages to DefWindowProc
|
2010-09-10 20:03:36 +00:00
|
|
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Translate client window size to full window size (including window borders)
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
static void getFullWindowSize(_GLFWwindow* window,
|
|
|
|
int clientWidth, int clientHeight,
|
2010-09-10 20:03:36 +00:00
|
|
|
int* fullWidth, int* fullHeight)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
RECT rect;
|
|
|
|
|
|
|
|
// Create a window rectangle
|
2010-09-10 20:03:36 +00:00
|
|
|
rect.left = (long) 0;
|
|
|
|
rect.right = (long) clientWidth - 1;
|
|
|
|
rect.top = (long) 0;
|
|
|
|
rect.bottom = (long) clientHeight - 1;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Adjust according to window styles
|
2010-09-12 14:26:00 +00:00
|
|
|
AdjustWindowRectEx(&rect, window->Win32.dwStyle, FALSE, window->Win32.dwExStyle);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Calculate width and height of full window
|
|
|
|
*fullWidth = rect.right - rect.left + 1;
|
|
|
|
*fullHeight = rect.bottom - rect.top + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Initialize WGL-specific extensions
|
|
|
|
// This function is called once before initial context creation, i.e. before
|
|
|
|
// any WGL extensions could be present. This is done in order to have both
|
|
|
|
// extension variable clearing and loading in the same place, hopefully
|
|
|
|
// decreasing the possibility of forgetting to add one without the other.
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
static void initWGLExtensions(_GLFWwindow* window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// This needs to include every function pointer loaded below
|
2010-09-12 14:26:00 +00:00
|
|
|
window->WGL.SwapIntervalEXT = NULL;
|
|
|
|
window->WGL.GetPixelFormatAttribivARB = NULL;
|
|
|
|
window->WGL.GetExtensionsStringARB = NULL;
|
|
|
|
window->WGL.GetExtensionsStringEXT = NULL;
|
|
|
|
window->WGL.CreateContextAttribsARB = NULL;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// This needs to include every extension used below except for
|
|
|
|
// WGL_ARB_extensions_string and WGL_EXT_extensions_string
|
2011-09-06 12:51:03 +00:00
|
|
|
window->WGL.ARB_multisample = GL_FALSE;
|
|
|
|
window->WGL.ARB_create_context = GL_FALSE;
|
|
|
|
window->WGL.ARB_create_context_profile = GL_FALSE;
|
|
|
|
window->WGL.EXT_create_context_es2_profile = GL_FALSE;
|
|
|
|
window->WGL.ARB_create_context_robustness = GL_FALSE;
|
|
|
|
window->WGL.EXT_swap_control = GL_FALSE;
|
|
|
|
window->WGL.ARB_pixel_format = GL_FALSE;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-20 18:39:44 +00:00
|
|
|
window->WGL.GetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)
|
2010-09-10 20:03:36 +00:00
|
|
|
wglGetProcAddress("wglGetExtensionsStringEXT");
|
2010-09-12 14:26:00 +00:00
|
|
|
if (!window->WGL.GetExtensionsStringEXT)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-20 18:39:44 +00:00
|
|
|
window->WGL.GetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)
|
2010-09-10 20:03:36 +00:00
|
|
|
wglGetProcAddress("wglGetExtensionsStringARB");
|
2010-09-12 14:26:00 +00:00
|
|
|
if (!window->WGL.GetExtensionsStringARB)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("WGL_ARB_multisample"))
|
2011-09-06 12:51:03 +00:00
|
|
|
window->WGL.ARB_multisample = GL_TRUE;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("WGL_ARB_create_context"))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-12 14:26:00 +00:00
|
|
|
window->WGL.CreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)
|
2010-09-10 20:03:36 +00:00
|
|
|
wglGetProcAddress("wglCreateContextAttribsARB");
|
2010-09-12 14:26:00 +00:00
|
|
|
|
|
|
|
if (window->WGL.CreateContextAttribsARB)
|
2011-09-06 12:51:03 +00:00
|
|
|
window->WGL.ARB_create_context = GL_TRUE;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2011-09-06 12:51:03 +00:00
|
|
|
if (window->WGL.ARB_create_context)
|
2010-11-15 18:28:06 +00:00
|
|
|
{
|
|
|
|
if (_glfwPlatformExtensionSupported("WGL_ARB_create_context_profile"))
|
2011-09-06 12:51:03 +00:00
|
|
|
window->WGL.ARB_create_context_profile = GL_TRUE;
|
2010-11-15 18:28:06 +00:00
|
|
|
}
|
|
|
|
|
2011-09-06 12:51:03 +00:00
|
|
|
if (window->WGL.ARB_create_context &&
|
|
|
|
window->WGL.ARB_create_context_profile)
|
2010-11-15 18:28:06 +00:00
|
|
|
{
|
|
|
|
if (_glfwPlatformExtensionSupported("WGL_EXT_create_context_es2_profile"))
|
2011-09-06 12:51:03 +00:00
|
|
|
window->WGL.EXT_create_context_es2_profile = GL_TRUE;
|
2010-11-15 18:28:06 +00:00
|
|
|
}
|
|
|
|
|
2011-09-06 12:51:03 +00:00
|
|
|
if (window->WGL.ARB_create_context)
|
2011-03-07 19:51:34 +00:00
|
|
|
{
|
|
|
|
if (_glfwPlatformExtensionSupported("WGL_ARB_create_context_robustness"))
|
2011-09-06 12:51:03 +00:00
|
|
|
window->WGL.ARB_create_context_robustness = GL_TRUE;
|
2011-03-07 19:51:34 +00:00
|
|
|
}
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("WGL_EXT_swap_control"))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-20 18:55:31 +00:00
|
|
|
window->WGL.SwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)
|
2010-09-10 20:03:36 +00:00
|
|
|
wglGetProcAddress("wglSwapIntervalEXT");
|
2010-09-12 14:26:00 +00:00
|
|
|
|
|
|
|
if (window->WGL.SwapIntervalEXT)
|
2011-09-06 12:51:03 +00:00
|
|
|
window->WGL.EXT_swap_control = GL_TRUE;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("WGL_ARB_pixel_format"))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-20 18:39:44 +00:00
|
|
|
window->WGL.GetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
|
2010-09-10 20:03:36 +00:00
|
|
|
wglGetProcAddress("wglGetPixelFormatAttribivARB");
|
2010-09-12 14:26:00 +00:00
|
|
|
|
|
|
|
if (window->WGL.GetPixelFormatAttribivARB)
|
2011-09-06 12:51:03 +00:00
|
|
|
window->WGL.ARB_pixel_format = GL_TRUE;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Registers the GLFW window class
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
static ATOM registerWindowClass(void)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
WNDCLASS wc;
|
2010-09-14 00:17:18 +00:00
|
|
|
ATOM classAtom;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Set window class parameters
|
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw on...
|
2010-09-12 14:26:00 +00:00
|
|
|
wc.lpfnWndProc = (WNDPROC) windowProc; // Message handler
|
2010-09-07 15:34:51 +00:00
|
|
|
wc.cbClsExtra = 0; // No extra class data
|
2010-09-12 14:26:00 +00:00
|
|
|
wc.cbWndExtra = sizeof(void*) + sizeof(int); // Make room for one pointer
|
|
|
|
wc.hInstance = _glfwLibrary.Win32.instance; // Set instance
|
|
|
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load arrow pointer
|
2010-09-07 15:34:51 +00:00
|
|
|
wc.hbrBackground = NULL; // No background
|
|
|
|
wc.lpszMenuName = NULL; // No menu
|
|
|
|
wc.lpszClassName = _GLFW_WNDCLASSNAME; // Set class name
|
|
|
|
|
|
|
|
// Load user-provided icon if available
|
2012-02-03 19:34:24 +00:00
|
|
|
wc.hIcon = LoadIcon(_glfwLibrary.Win32.instance, L"GLFW_ICON");
|
2010-09-10 20:03:36 +00:00
|
|
|
if (!wc.hIcon)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// Load default icon
|
2010-09-10 20:03:36 +00:00
|
|
|
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-14 00:17:18 +00:00
|
|
|
classAtom = RegisterClass(&wc);
|
|
|
|
if (!classAtom)
|
|
|
|
{
|
2011-05-21 21:13:48 +00:00
|
|
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32/WGL: Failed to register window class");
|
2010-09-14 00:17:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return classAtom;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Returns the closest matching pixel format, or zero on error
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
static int choosePixelFormat(_GLFWwindow* window, const _GLFWfbconfig* fbconfig)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
unsigned int fbcount;
|
|
|
|
int pixelFormat;
|
2010-09-10 20:03:36 +00:00
|
|
|
_GLFWfbconfig* fbconfigs;
|
|
|
|
const _GLFWfbconfig* closest;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
fbconfigs = getFBConfigs(window, &fbcount);
|
2010-09-10 20:03:36 +00:00
|
|
|
if (!fbconfigs)
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
closest = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
|
|
|
|
if (!closest)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2012-02-07 13:58:58 +00:00
|
|
|
free(fbconfigs);
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pixelFormat = (int) closest->platformID;
|
|
|
|
|
2012-02-07 13:58:58 +00:00
|
|
|
free(fbconfigs);
|
2010-09-07 15:34:51 +00:00
|
|
|
fbconfigs = NULL;
|
|
|
|
closest = NULL;
|
|
|
|
|
|
|
|
return pixelFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Creates the GLFW window and rendering context
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
static int createWindow(_GLFWwindow* window,
|
|
|
|
const _GLFWwndconfig* wndconfig,
|
2010-09-10 20:03:36 +00:00
|
|
|
const _GLFWfbconfig* fbconfig)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
DWORD dwStyle, dwExStyle;
|
2012-02-07 15:21:37 +00:00
|
|
|
int pixelFormat, fullWidth, fullHeight;
|
2010-09-07 15:34:51 +00:00
|
|
|
RECT wa;
|
|
|
|
POINT pos;
|
2012-02-03 19:34:24 +00:00
|
|
|
WCHAR* wideTitle;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Set common window styles
|
2010-09-10 20:03:36 +00:00
|
|
|
dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
|
2010-09-07 15:34:51 +00:00
|
|
|
dwExStyle = WS_EX_APPWINDOW;
|
|
|
|
|
|
|
|
// Set window style, depending on fullscreen mode
|
2010-09-12 14:26:00 +00:00
|
|
|
if (window->mode == GLFW_FULLSCREEN)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
dwStyle |= WS_POPUP;
|
|
|
|
|
|
|
|
// Here's a trick for helping us getting window focus
|
|
|
|
// (SetForegroundWindow doesn't work properly under
|
|
|
|
// Win98/ME/2K/.NET/+)
|
|
|
|
/*
|
2010-09-10 20:03:36 +00:00
|
|
|
if (_glfwLibrary.Sys.WinVer != _GLFW_WIN_95 &&
|
2010-09-07 15:34:51 +00:00
|
|
|
_glfwLibrary.Sys.WinVer != _GLFW_WIN_NT4 &&
|
2010-09-10 20:03:36 +00:00
|
|
|
_glfwLibrary.Sys.WinVer != _GLFW_WIN_XP)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
dwStyle |= WS_MINIMIZE;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dwStyle |= WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
|
|
|
|
|
2011-11-02 15:56:34 +00:00
|
|
|
if (wndconfig->resizable)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-10 20:03:36 +00:00
|
|
|
dwStyle |= (WS_MAXIMIZEBOX | WS_SIZEBOX);
|
2010-09-07 15:34:51 +00:00
|
|
|
dwExStyle |= WS_EX_WINDOWEDGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remember window styles (used by getFullWindowSize)
|
2010-09-12 14:26:00 +00:00
|
|
|
window->Win32.dwStyle = dwStyle;
|
|
|
|
window->Win32.dwExStyle = dwExStyle;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Adjust window size for frame and title bar
|
2010-09-13 21:50:04 +00:00
|
|
|
getFullWindowSize(window, window->width, window->height, &fullWidth, &fullHeight);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// 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.
|
2010-09-12 14:26:00 +00:00
|
|
|
if (window->mode == GLFW_FULLSCREEN)
|
2010-09-07 15:34:51 +00:00
|
|
|
wa.left = wa.top = 0;
|
|
|
|
else
|
2010-09-10 20:03:36 +00:00
|
|
|
SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0);
|
|
|
|
|
2012-02-05 01:07:50 +00:00
|
|
|
wideTitle = _glfwCreateWideStringFromUTF8(wndconfig->title);
|
2012-02-03 19:34:24 +00:00
|
|
|
if (!wideTitle)
|
|
|
|
{
|
|
|
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
|
|
|
"glfwOpenWindow: Failed to convert title to wide string");
|
2012-02-07 15:21:19 +00:00
|
|
|
return GL_FALSE;
|
2012-02-03 19:34:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
window->Win32.handle = CreateWindowEx(window->Win32.dwExStyle,
|
|
|
|
_GLFW_WNDCLASSNAME,
|
2012-02-03 19:34:24 +00:00
|
|
|
wideTitle,
|
2010-09-12 14:26:00 +00:00
|
|
|
window->Win32.dwStyle,
|
|
|
|
wa.left, wa.top, // Window position
|
|
|
|
fullWidth, // Decorated window width
|
|
|
|
fullHeight, // Decorated window height
|
|
|
|
NULL, // No parent window
|
|
|
|
NULL, // No menu
|
|
|
|
_glfwLibrary.Win32.instance,
|
2010-09-13 23:05:03 +00:00
|
|
|
window); // Pass GLFW window to WM_CREATE
|
2010-09-12 14:26:00 +00:00
|
|
|
|
|
|
|
if (!window->Win32.handle)
|
2010-09-10 20:03:36 +00:00
|
|
|
{
|
2010-11-23 16:45:23 +00:00
|
|
|
_glfwSetError(GLFW_PLATFORM_ERROR, "Win32/WGL: Failed to create window");
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-02-07 13:58:58 +00:00
|
|
|
free(wideTitle);
|
2012-02-03 19:34:24 +00:00
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
window->WGL.DC = GetDC(window->Win32.handle);
|
|
|
|
if (!window->WGL.DC)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2011-05-21 21:13:48 +00:00
|
|
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32/WGL: Failed to retrieve DC for window");
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
pixelFormat = choosePixelFormat(window, fbconfig);
|
2010-09-10 20:03:36 +00:00
|
|
|
if (!pixelFormat)
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
|
2010-10-04 16:17:53 +00:00
|
|
|
if (!createContext(window, wndconfig, pixelFormat))
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
|
2011-07-27 14:01:27 +00:00
|
|
|
glfwMakeContextCurrent(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
initWGLExtensions(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Initialize mouse position data
|
2010-09-10 20:03:36 +00:00
|
|
|
GetCursorPos(&pos);
|
2010-09-12 14:26:00 +00:00
|
|
|
ScreenToClient(window->Win32.handle, &pos);
|
2011-10-13 13:20:59 +00:00
|
|
|
window->Win32.oldMouseX = window->cursorPosX = pos.x;
|
|
|
|
window->Win32.oldMouseY = window->cursorPosY = pos.y;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Destroys the GLFW window and rendering context
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
static void destroyWindow(_GLFWwindow* window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-14 00:54:05 +00:00
|
|
|
// This is duplicated from glfwCloseWindow
|
|
|
|
// TODO: Stop duplicating code
|
|
|
|
if (window == _glfwLibrary.currentWindow)
|
2011-07-27 14:01:27 +00:00
|
|
|
glfwMakeContextCurrent(NULL);
|
2010-09-14 00:54:05 +00:00
|
|
|
|
|
|
|
// This is duplicated from glfwCloseWindow
|
|
|
|
// TODO: Stop duplicating code
|
|
|
|
if (window == _glfwLibrary.activeWindow)
|
|
|
|
_glfwLibrary.activeWindow = NULL;
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
if (window->WGL.context)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-12 14:26:00 +00:00
|
|
|
wglDeleteContext(window->WGL.context);
|
|
|
|
window->WGL.context = NULL;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
if (window->WGL.DC)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-12 14:26:00 +00:00
|
|
|
ReleaseDC(window->Win32.handle, window->WGL.DC);
|
|
|
|
window->WGL.DC = NULL;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
if (window->Win32.handle)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-12 14:26:00 +00:00
|
|
|
DestroyWindow(window->Win32.handle);
|
|
|
|
window->Win32.handle = NULL;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Here is where the window is created, and the OpenGL rendering context is
|
|
|
|
// created
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
2010-09-10 20:03:36 +00:00
|
|
|
const _GLFWwndconfig* wndconfig,
|
|
|
|
const _GLFWfbconfig* fbconfig)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
GLboolean recreateContext = GL_FALSE;
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
window->Win32.desiredRefreshRate = wndconfig->refreshRate;
|
2012-02-27 01:21:26 +00:00
|
|
|
window->resizable = wndconfig->resizable;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-14 00:17:18 +00:00
|
|
|
if (!_glfwLibrary.Win32.classAtom)
|
|
|
|
{
|
|
|
|
_glfwLibrary.Win32.classAtom = registerWindowClass();
|
|
|
|
if (!_glfwLibrary.Win32.classAtom)
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
if (window->mode == GLFW_FULLSCREEN)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-13 21:50:04 +00:00
|
|
|
int bpp = fbconfig->redBits + fbconfig->greenBits + fbconfig->blueBits;
|
|
|
|
if (bpp < 15 || bpp >= 24)
|
|
|
|
bpp = 32;
|
|
|
|
|
2010-09-18 23:24:51 +00:00
|
|
|
_glfwLibrary.Win32.monitor.width = window->width;
|
|
|
|
_glfwLibrary.Win32.monitor.height = window->height;
|
|
|
|
_glfwLibrary.Win32.monitor.refreshRate = wndconfig->refreshRate;
|
|
|
|
_glfwLibrary.Win32.monitor.bitsPerPixel = bpp;
|
|
|
|
|
|
|
|
_glfwSetVideoMode(&_glfwLibrary.Win32.monitor.width,
|
|
|
|
&_glfwLibrary.Win32.monitor.height,
|
|
|
|
&_glfwLibrary.Win32.monitor.bitsPerPixel,
|
|
|
|
&_glfwLibrary.Win32.monitor.refreshRate,
|
|
|
|
GL_FALSE);
|
|
|
|
|
|
|
|
_glfwLibrary.Win32.monitor.modeChanged = GL_TRUE;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
if (!createWindow(window, wndconfig, fbconfig))
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
|
2010-11-15 19:19:29 +00:00
|
|
|
if (wndconfig->glMajor != 1 || wndconfig->glMinor != 0)
|
|
|
|
{
|
2011-09-06 12:51:03 +00:00
|
|
|
if (window->WGL.ARB_create_context)
|
2010-11-15 19:19:29 +00:00
|
|
|
recreateContext = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wndconfig->glForward || wndconfig->glDebug)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2011-09-06 12:51:03 +00:00
|
|
|
if (!window->WGL.ARB_create_context)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2011-05-21 21:13:48 +00:00
|
|
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"Win32/WGL: A forward compatible or debug OpenGL "
|
|
|
|
"context requested but WGL_ARB_create_context is "
|
|
|
|
"unavailable");
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
recreateContext = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-11-15 19:19:29 +00:00
|
|
|
if (wndconfig->glProfile)
|
|
|
|
{
|
2011-09-06 12:51:03 +00:00
|
|
|
if (!window->WGL.ARB_create_context_profile)
|
2010-11-15 19:19:29 +00:00
|
|
|
{
|
2011-05-21 21:13:48 +00:00
|
|
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"Win32/WGL: OpenGL profile requested but "
|
|
|
|
"WGL_ARB_create_context_profile is unavailable");
|
2010-11-15 19:19:29 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
recreateContext = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
if (fbconfig->samples > 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// We want FSAA, but can we get it?
|
|
|
|
// FSAA is not a hard constraint, so otherwise we just don't care
|
|
|
|
|
2011-09-06 12:51:03 +00:00
|
|
|
if (window->WGL.ARB_multisample && window->WGL.ARB_pixel_format)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// We appear to have both the FSAA extension and the means to ask for it
|
|
|
|
recreateContext = GL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
if (recreateContext)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// Some window hints require us to re-create the context using WGL
|
|
|
|
// extensions retrieved through the current context, as we cannot check
|
|
|
|
// for WGL extensions or retrieve WGL entry points before we have a
|
|
|
|
// current context (actually until we have implicitly loaded the ICD)
|
|
|
|
|
|
|
|
// Yes, this is strange, and yes, this is the proper way on Win32
|
|
|
|
|
|
|
|
// As Windows only allows you to set the pixel format once for a
|
|
|
|
// window, we need to destroy the current window and create a new one
|
|
|
|
// to be able to use the new pixel format
|
|
|
|
|
|
|
|
// Technically, it may be possible to keep the old window around if
|
|
|
|
// we're just creating an OpenGL 3.0+ context with the same pixel
|
2011-09-06 12:52:42 +00:00
|
|
|
// format, but it's not worth the added code complexity
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
destroyWindow(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
if (!createWindow(window, wndconfig, fbconfig))
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
if (window->mode == GLFW_FULLSCREEN)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// Place the window above all topmost windows
|
2010-09-12 14:26:00 +00:00
|
|
|
SetWindowPos(window->Win32.handle, HWND_TOPMOST, 0,0,0,0,
|
2010-09-10 20:03:36 +00:00
|
|
|
SWP_NOMOVE | SWP_NOSIZE);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
setForegroundWindow(window->Win32.handle);
|
|
|
|
SetFocus(window->Win32.handle);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Properly kill the window / video display
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
void _glfwPlatformCloseWindow(_GLFWwindow* window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-13 21:50:04 +00:00
|
|
|
destroyWindow(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
if (window->mode == GLFW_FULLSCREEN)
|
2010-09-18 23:24:51 +00:00
|
|
|
{
|
|
|
|
if (_glfwLibrary.Win32.monitor.modeChanged)
|
|
|
|
{
|
|
|
|
_glfwRestoreVideoMode();
|
|
|
|
_glfwLibrary.Win32.monitor.modeChanged = GL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Set the window title
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2012-02-05 01:07:50 +00:00
|
|
|
WCHAR* wideTitle = _glfwCreateWideStringFromUTF8(title);
|
2012-02-03 19:34:24 +00:00
|
|
|
if (!wideTitle)
|
|
|
|
{
|
|
|
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
|
|
|
"glfwSetWindowTitle: Failed to convert title to wide string");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetWindowText(window->Win32.handle, wideTitle);
|
|
|
|
|
2012-02-07 13:58:58 +00:00
|
|
|
free(wideTitle);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Set the window size.
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-13 21:50:04 +00:00
|
|
|
GLboolean sizeChanged = GL_FALSE;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
if (window->mode == GLFW_FULLSCREEN)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-13 21:50:04 +00:00
|
|
|
if (width > window->width || height > window->height)
|
|
|
|
{
|
|
|
|
// The new video mode is larger than the current one, so we resize
|
|
|
|
// the window before switch modes to avoid exposing whatever is
|
|
|
|
// underneath
|
|
|
|
|
|
|
|
SetWindowPos(window->Win32.handle, HWND_TOP, 0, 0, width, height,
|
|
|
|
SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER);
|
|
|
|
sizeChanged = GL_TRUE;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
2010-09-13 21:50:04 +00:00
|
|
|
|
2012-03-25 18:45:06 +00:00
|
|
|
// TODO: Change video mode
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If we are in windowed mode, adjust the window size to
|
|
|
|
// compensate for window decorations
|
2010-09-13 21:50:04 +00:00
|
|
|
getFullWindowSize(window, width, height, &width, &height);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
// Set window size (if we haven't already)
|
|
|
|
if (!sizeChanged)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-12 14:26:00 +00:00
|
|
|
SetWindowPos(window->Win32.handle, HWND_TOP, 0, 0, width, height,
|
|
|
|
SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Set the window position
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-12 14:26:00 +00:00
|
|
|
SetWindowPos(window->Win32.handle, HWND_TOP, x, y, 0, 0,
|
|
|
|
SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Window iconification
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-18 23:24:51 +00:00
|
|
|
ShowWindow(window->Win32.handle, SW_MINIMIZE);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Window un-iconification
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-18 23:24:51 +00:00
|
|
|
ShowWindow(window->Win32.handle, SW_RESTORE);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Write back window parameters into GLFW window structure
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
void _glfwPlatformRefreshWindowParams(void)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
DEVMODE dm;
|
2011-07-27 15:09:17 +00:00
|
|
|
int pixelFormat;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
_GLFWwindow* window = _glfwLibrary.currentWindow;
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
// Obtain a detailed description of current pixel format
|
2012-03-30 00:28:15 +00:00
|
|
|
pixelFormat = GetPixelFormat(window->WGL.DC);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2011-09-06 12:51:03 +00:00
|
|
|
if (window->WGL.ARB_pixel_format)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-13 21:50:04 +00:00
|
|
|
if (getPixelFormatAttrib(window, pixelFormat, WGL_ACCELERATION_ARB) !=
|
2010-09-10 20:03:36 +00:00
|
|
|
WGL_NO_ACCELERATION_ARB)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-12 14:26:00 +00:00
|
|
|
window->accelerated = GL_TRUE;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
2010-09-12 14:26:00 +00:00
|
|
|
window->accelerated = GL_FALSE;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
window->redBits =
|
|
|
|
getPixelFormatAttrib(window, pixelFormat, WGL_RED_BITS_ARB);
|
|
|
|
window->greenBits =
|
|
|
|
getPixelFormatAttrib(window, pixelFormat, WGL_GREEN_BITS_ARB);
|
|
|
|
window->blueBits =
|
|
|
|
getPixelFormatAttrib(window, pixelFormat, WGL_BLUE_BITS_ARB);
|
|
|
|
|
|
|
|
window->alphaBits =
|
|
|
|
getPixelFormatAttrib(window, pixelFormat, WGL_ALPHA_BITS_ARB);
|
|
|
|
window->depthBits =
|
|
|
|
getPixelFormatAttrib(window, pixelFormat, WGL_DEPTH_BITS_ARB);
|
|
|
|
window->stencilBits =
|
|
|
|
getPixelFormatAttrib(window, pixelFormat, WGL_STENCIL_BITS_ARB);
|
|
|
|
|
|
|
|
window->accumRedBits =
|
|
|
|
getPixelFormatAttrib(window, pixelFormat, WGL_ACCUM_RED_BITS_ARB);
|
|
|
|
window->accumGreenBits =
|
|
|
|
getPixelFormatAttrib(window, pixelFormat, WGL_ACCUM_GREEN_BITS_ARB);
|
|
|
|
window->accumBlueBits =
|
|
|
|
getPixelFormatAttrib(window, pixelFormat, WGL_ACCUM_BLUE_BITS_ARB);
|
|
|
|
window->accumAlphaBits =
|
|
|
|
getPixelFormatAttrib(window, pixelFormat, WGL_ACCUM_ALPHA_BITS_ARB);
|
|
|
|
|
|
|
|
window->auxBuffers =
|
|
|
|
getPixelFormatAttrib(window, pixelFormat, WGL_AUX_BUFFERS_ARB);
|
|
|
|
window->stereo =
|
|
|
|
getPixelFormatAttrib(window, pixelFormat, WGL_STEREO_ARB) ? GL_TRUE : GL_FALSE;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2011-09-06 12:51:03 +00:00
|
|
|
if (window->WGL.ARB_multisample)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-13 21:50:04 +00:00
|
|
|
window->samples = getPixelFormatAttrib(window, pixelFormat, WGL_SAMPLES_ARB);
|
2010-09-18 23:31:23 +00:00
|
|
|
|
|
|
|
// We force 1 to zero here because all the other APIs say zero when
|
|
|
|
// they really mean 1
|
|
|
|
if (window->samples == 1)
|
|
|
|
window->samples = 0;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
2010-09-12 14:26:00 +00:00
|
|
|
window->samples = 0;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-30 00:28:15 +00:00
|
|
|
DescribePixelFormat(window->WGL.DC, pixelFormat,
|
|
|
|
sizeof(PIXELFORMATDESCRIPTOR), &pfd);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Is current OpenGL context accelerated?
|
2010-09-12 14:26:00 +00:00
|
|
|
window->accelerated = (pfd.dwFlags & PFD_GENERIC_ACCELERATED) ||
|
|
|
|
!(pfd.dwFlags & PFD_GENERIC_FORMAT) ? 1 : 0;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// "Standard" window parameters
|
2010-09-12 14:26:00 +00:00
|
|
|
window->redBits = pfd.cRedBits;
|
|
|
|
window->greenBits = pfd.cGreenBits;
|
|
|
|
window->blueBits = pfd.cBlueBits;
|
|
|
|
window->alphaBits = pfd.cAlphaBits;
|
|
|
|
window->depthBits = pfd.cDepthBits;
|
|
|
|
window->stencilBits = pfd.cStencilBits;
|
|
|
|
window->accumRedBits = pfd.cAccumRedBits;
|
|
|
|
window->accumGreenBits = pfd.cAccumGreenBits;
|
|
|
|
window->accumBlueBits = pfd.cAccumBlueBits;
|
|
|
|
window->accumAlphaBits = pfd.cAccumAlphaBits;
|
|
|
|
window->auxBuffers = pfd.cAuxBuffers;
|
|
|
|
window->stereo = (pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// If we don't have WGL_ARB_pixel_format then we can't have created a
|
|
|
|
// multisampling context, so it's safe to hardcode zero here
|
2010-09-12 14:26:00 +00:00
|
|
|
window->samples = 0;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
dm.dmSize = sizeof(DEVMODE);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-13 21:50:04 +00:00
|
|
|
if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-12 14:26:00 +00:00
|
|
|
window->refreshRate = dm.dmDisplayFrequency;
|
|
|
|
if (window->refreshRate <= 1)
|
|
|
|
window->refreshRate = 0;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
2010-09-12 14:26:00 +00:00
|
|
|
window->refreshRate = 0;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Poll for new window and input events
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
void _glfwPlatformPollEvents(void)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
MSG msg;
|
2010-09-13 21:50:04 +00:00
|
|
|
_GLFWwindow* window;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2011-09-06 11:55:29 +00:00
|
|
|
window = _glfwLibrary.activeWindow;
|
2010-09-13 21:50:04 +00:00
|
|
|
if (window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2011-10-04 22:47:39 +00:00
|
|
|
window->Win32.cursorCentered = GL_FALSE;
|
2010-09-13 21:50:04 +00:00
|
|
|
window->Win32.oldMouseX = window->width / 2;
|
|
|
|
window->Win32.oldMouseY = window->height / 2;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-13 13:20:59 +00:00
|
|
|
//window->Win32.oldMouseX = window->cursorPosX;
|
|
|
|
//window->Win32.oldMouseY = window->cursorPosY;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-10 20:03:36 +00:00
|
|
|
switch (msg.message)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
case WM_QUIT:
|
2010-09-10 20:03:36 +00:00
|
|
|
{
|
2010-09-13 21:50:04 +00:00
|
|
|
// Treat WM_QUIT as a close on all windows
|
|
|
|
|
|
|
|
window = _glfwLibrary.windowListHead;
|
|
|
|
while (window)
|
|
|
|
{
|
2010-09-16 04:02:44 +00:00
|
|
|
window->closeRequested = GL_TRUE;
|
2010-09-13 21:50:04 +00:00
|
|
|
window = window->next;
|
|
|
|
}
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
break;
|
2010-09-10 20:03:36 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
default:
|
2010-09-10 20:03:36 +00:00
|
|
|
{
|
|
|
|
DispatchMessage(&msg);
|
2010-09-07 15:34:51 +00:00
|
|
|
break;
|
2010-09-10 20:03:36 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2010-09-13 21:50:04 +00:00
|
|
|
window = _glfwLibrary.activeWindow;
|
|
|
|
if (window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
int lshift_down, rshift_down;
|
|
|
|
|
|
|
|
// Get current state of left and right shift keys
|
2010-09-10 20:03:36 +00:00
|
|
|
lshift_down = (GetAsyncKeyState(VK_LSHIFT) >> 15) & 1;
|
|
|
|
rshift_down = (GetAsyncKeyState(VK_RSHIFT) >> 15) & 1;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// See if this differs from our belief of what has happened
|
|
|
|
// (we only have to check for lost key up events)
|
2011-01-10 20:38:08 +00:00
|
|
|
if (!lshift_down && window->key[GLFW_KEY_LEFT_SHIFT] == 1)
|
|
|
|
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, GLFW_RELEASE);
|
2010-09-10 20:03:36 +00:00
|
|
|
|
2011-01-10 20:38:08 +00:00
|
|
|
if (!rshift_down && window->key[GLFW_KEY_RIGHT_SHIFT] == 1)
|
|
|
|
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, GLFW_RELEASE);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2011-09-06 11:55:29 +00:00
|
|
|
// Did the cursor move in an active window that has captured the cursor
|
|
|
|
window = _glfwLibrary.activeWindow;
|
|
|
|
if (window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2011-09-06 11:55:29 +00:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED &&
|
|
|
|
!window->Win32.cursorCentered)
|
|
|
|
{
|
|
|
|
_glfwPlatformSetMouseCursorPos(window,
|
|
|
|
window->width / 2,
|
|
|
|
window->height / 2);
|
|
|
|
window->Win32.cursorCentered = GL_TRUE;
|
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-12 14:26:00 +00:00
|
|
|
// Wait for new window and input events
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
void _glfwPlatformWaitEvents(void)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
WaitMessage();
|
|
|
|
|
|
|
|
_glfwPlatformPollEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Set physical mouse cursor position
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
POINT pos;
|
|
|
|
|
|
|
|
// Convert client coordinates to screen coordinates
|
|
|
|
pos.x = x;
|
|
|
|
pos.y = y;
|
2010-09-12 14:26:00 +00:00
|
|
|
ClientToScreen(window->Win32.handle, &pos);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
SetCursorPos(pos.x, pos.y);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2011-10-04 22:47:39 +00:00
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Set physical mouse cursor mode
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
|
|
|
{
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case GLFW_CURSOR_NORMAL:
|
|
|
|
showMouseCursor(window);
|
|
|
|
break;
|
|
|
|
case GLFW_CURSOR_HIDDEN:
|
|
|
|
hideMouseCursor(window);
|
|
|
|
break;
|
|
|
|
case GLFW_CURSOR_CAPTURED:
|
|
|
|
captureMouseCursor(window);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|