2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
2011-03-06 01:46:39 +01:00
|
|
|
// GLFW - An OpenGL library
|
2010-09-07 17:34:51 +02:00
|
|
|
// Platform: Any
|
2010-09-07 17:41:26 +02:00
|
|
|
// API version: 3.0
|
2010-09-07 17:34:51 +02:00
|
|
|
// WWW: http://www.glfw.org/
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2002-2006 Marcus Geelnard
|
|
|
|
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
|
2012-08-14 23:34:26 +02:00
|
|
|
// Copyright (c) 2012 Torsten Walluhn <tw@mad-cad.net>
|
2010-09-07 17:34:51 +02:00
|
|
|
//
|
|
|
|
// 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-08 17:01:39 +02:00
|
|
|
#include <string.h>
|
2010-09-09 18:15:32 +02:00
|
|
|
#include <stdlib.h>
|
2012-09-12 21:18:37 +02:00
|
|
|
#if defined(_MSC_VER)
|
2012-09-09 14:22:14 +02:00
|
|
|
#include <malloc.h>
|
2012-08-14 23:34:26 +02:00
|
|
|
#endif
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
|
2010-09-09 20:59:50 +02:00
|
|
|
//========================================================================
|
|
|
|
// Return the maxiumum of the specified values
|
|
|
|
//========================================================================
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
static int Max(int a, int b)
|
|
|
|
{
|
|
|
|
return (a > b) ? a : b;
|
|
|
|
}
|
|
|
|
|
2010-09-14 01:43:31 +02:00
|
|
|
|
2010-11-17 14:24:25 +01:00
|
|
|
//========================================================================
|
|
|
|
// Clear scroll offsets for all windows
|
|
|
|
//========================================================================
|
|
|
|
|
2011-03-04 14:52:12 +01:00
|
|
|
static void clearScrollOffsets(void)
|
2010-11-17 14:24:25 +01:00
|
|
|
{
|
|
|
|
_GLFWwindow* window;
|
|
|
|
|
|
|
|
for (window = _glfwLibrary.windowListHead; window; window = window->next)
|
|
|
|
{
|
|
|
|
window->scrollX = 0;
|
|
|
|
window->scrollY = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-09 20:59:50 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-09-19 02:49:42 +02:00
|
|
|
//========================================================================
|
|
|
|
// Register window focus events
|
|
|
|
//========================================================================
|
|
|
|
|
2012-11-22 17:04:44 +01:00
|
|
|
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean focused)
|
2010-09-19 02:49:42 +02:00
|
|
|
{
|
2012-11-22 17:04:44 +01:00
|
|
|
if (focused)
|
2010-09-19 02:49:42 +02:00
|
|
|
{
|
2012-11-22 17:04:44 +01:00
|
|
|
if (_glfwLibrary.focusedWindow != window)
|
2010-09-19 02:49:42 +02:00
|
|
|
{
|
2012-11-22 17:04:44 +01:00
|
|
|
_glfwLibrary.focusedWindow = window;
|
2010-09-19 02:49:42 +02:00
|
|
|
|
2012-10-28 13:45:11 +01:00
|
|
|
if (window->windowFocusCallback)
|
2012-11-22 17:04:44 +01:00
|
|
|
window->windowFocusCallback(window, focused);
|
2010-09-19 02:49:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-22 17:04:44 +01:00
|
|
|
if (_glfwLibrary.focusedWindow == window)
|
2010-09-19 02:49:42 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// Release all pressed keyboard keys
|
|
|
|
for (i = 0; i <= GLFW_KEY_LAST; i++)
|
|
|
|
{
|
|
|
|
if (window->key[i] == GLFW_PRESS)
|
|
|
|
_glfwInputKey(window, i, GLFW_RELEASE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release all pressed mouse buttons
|
|
|
|
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
|
|
|
|
{
|
|
|
|
if (window->mouseButton[i] == GLFW_PRESS)
|
|
|
|
_glfwInputMouseClick(window, i, GLFW_RELEASE);
|
|
|
|
}
|
|
|
|
|
2012-11-22 17:04:44 +01:00
|
|
|
_glfwLibrary.focusedWindow = NULL;
|
2010-09-19 02:49:42 +02:00
|
|
|
|
2012-10-28 13:45:11 +01:00
|
|
|
if (window->windowFocusCallback)
|
2012-11-22 17:04:44 +01:00
|
|
|
window->windowFocusCallback(window, focused);
|
2010-09-19 02:49:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-09 17:10:40 +02:00
|
|
|
//========================================================================
|
|
|
|
// Register window position events
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
|
|
|
|
{
|
2012-11-30 13:56:42 +01:00
|
|
|
if (window->positionX == x && window->positionY == y)
|
|
|
|
return;
|
|
|
|
|
2011-10-09 17:10:40 +02:00
|
|
|
window->positionX = x;
|
|
|
|
window->positionY = y;
|
2012-11-30 13:56:42 +01:00
|
|
|
|
|
|
|
if (window->windowPosCallback)
|
|
|
|
window->windowPosCallback(window, x, y);
|
2011-10-09 17:10:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Register window size events
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height)
|
|
|
|
{
|
|
|
|
if (window->width == width && window->height == height)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window->width = width;
|
|
|
|
window->height = height;
|
|
|
|
|
2012-10-28 13:45:11 +01:00
|
|
|
if (window->windowSizeCallback)
|
|
|
|
window->windowSizeCallback(window, width, height);
|
2011-10-09 17:10:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Register window size events
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified)
|
|
|
|
{
|
|
|
|
if (window->iconified == iconified)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window->iconified = iconified;
|
|
|
|
|
2012-10-28 13:45:11 +01:00
|
|
|
if (window->windowIconifyCallback)
|
|
|
|
window->windowIconifyCallback(window, iconified);
|
2011-10-09 17:10:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-21 21:18:09 +02:00
|
|
|
//========================================================================
|
|
|
|
// Register window visibility events
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
void _glfwInputWindowVisibility(_GLFWwindow* window, int visible)
|
|
|
|
{
|
|
|
|
window->visible = visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-09 21:12:13 +02:00
|
|
|
//========================================================================
|
|
|
|
// Register window damage events
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
void _glfwInputWindowDamage(_GLFWwindow* window)
|
|
|
|
{
|
2012-10-28 13:45:11 +01:00
|
|
|
if (window->windowRefreshCallback)
|
|
|
|
window->windowRefreshCallback(window);
|
2011-10-09 21:12:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-10 13:31:15 +02:00
|
|
|
//========================================================================
|
|
|
|
// Register window close request events
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
void _glfwInputWindowCloseRequest(_GLFWwindow* window)
|
|
|
|
{
|
2012-10-28 13:45:11 +01:00
|
|
|
if (window->windowCloseCallback)
|
|
|
|
window->closeRequested = window->windowCloseCallback(window);
|
2012-08-10 13:31:15 +02:00
|
|
|
else
|
|
|
|
window->closeRequested = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-09 20:59:50 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW public API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Create the GLFW window and its associated context
|
|
|
|
//========================================================================
|
|
|
|
|
2012-08-06 17:56:41 +02:00
|
|
|
GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
|
|
|
|
int mode, const char* title,
|
|
|
|
GLFWwindow share)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
_GLFWfbconfig fbconfig;
|
|
|
|
_GLFWwndconfig wndconfig;
|
2010-09-09 18:15:32 +02:00
|
|
|
_GLFWwindow* window;
|
2012-08-10 15:29:45 +02:00
|
|
|
_GLFWwindow* previous;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2010-09-09 21:34:42 +02:00
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-09 18:15:32 +02:00
|
|
|
return NULL;
|
2010-09-09 21:34:42 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 14:30:23 +01:00
|
|
|
// We need to copy these values before doing anything that can fail, as the
|
|
|
|
// window hints should be cleared after each call even if it fails
|
2010-09-09 18:15:32 +02:00
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
// Set up desired framebuffer config
|
2010-09-09 19:58:51 +02:00
|
|
|
fbconfig.redBits = Max(_glfwLibrary.hints.redBits, 0);
|
|
|
|
fbconfig.greenBits = Max(_glfwLibrary.hints.greenBits, 0);
|
|
|
|
fbconfig.blueBits = Max(_glfwLibrary.hints.blueBits, 0);
|
|
|
|
fbconfig.alphaBits = Max(_glfwLibrary.hints.alphaBits, 0);
|
|
|
|
fbconfig.depthBits = Max(_glfwLibrary.hints.depthBits, 0);
|
|
|
|
fbconfig.stencilBits = Max(_glfwLibrary.hints.stencilBits, 0);
|
2010-09-08 14:45:52 +02:00
|
|
|
fbconfig.accumRedBits = Max(_glfwLibrary.hints.accumRedBits, 0);
|
|
|
|
fbconfig.accumGreenBits = Max(_glfwLibrary.hints.accumGreenBits, 0);
|
|
|
|
fbconfig.accumBlueBits = Max(_glfwLibrary.hints.accumBlueBits, 0);
|
|
|
|
fbconfig.accumAlphaBits = Max(_glfwLibrary.hints.accumAlphaBits, 0);
|
|
|
|
fbconfig.auxBuffers = Max(_glfwLibrary.hints.auxBuffers, 0);
|
2010-09-07 17:34:51 +02:00
|
|
|
fbconfig.stereo = _glfwLibrary.hints.stereo ? GL_TRUE : GL_FALSE;
|
2010-09-08 14:45:52 +02:00
|
|
|
fbconfig.samples = Max(_glfwLibrary.hints.samples, 0);
|
2012-12-02 16:10:00 +01:00
|
|
|
fbconfig.sRGB = _glfwLibrary.hints.sRGB ? GL_TRUE : GL_FALSE;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
// Set up desired window config
|
|
|
|
wndconfig.mode = mode;
|
2010-09-14 03:10:45 +02:00
|
|
|
wndconfig.title = title;
|
2010-09-08 14:45:52 +02:00
|
|
|
wndconfig.refreshRate = Max(_glfwLibrary.hints.refreshRate, 0);
|
2011-11-02 16:56:34 +01:00
|
|
|
wndconfig.resizable = _glfwLibrary.hints.resizable ? GL_TRUE : GL_FALSE;
|
2012-08-21 21:18:09 +02:00
|
|
|
wndconfig.visible = _glfwLibrary.hints.visible ? GL_TRUE : GL_FALSE;
|
2012-10-28 00:23:28 +02:00
|
|
|
wndconfig.positionX = _glfwLibrary.hints.positionX;
|
|
|
|
wndconfig.positionY = _glfwLibrary.hints.positionY;
|
2012-09-30 15:32:50 +02:00
|
|
|
wndconfig.clientAPI = _glfwLibrary.hints.clientAPI;
|
2011-03-04 17:51:12 +01:00
|
|
|
wndconfig.glMajor = _glfwLibrary.hints.glMajor;
|
|
|
|
wndconfig.glMinor = _glfwLibrary.hints.glMinor;
|
2010-09-07 17:34:51 +02:00
|
|
|
wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE;
|
|
|
|
wndconfig.glDebug = _glfwLibrary.hints.glDebug ? GL_TRUE : GL_FALSE;
|
|
|
|
wndconfig.glProfile = _glfwLibrary.hints.glProfile;
|
2011-03-07 20:51:34 +01:00
|
|
|
wndconfig.glRobustness = _glfwLibrary.hints.glRobustness ? GL_TRUE : GL_FALSE;
|
2012-09-27 15:18:57 +02:00
|
|
|
wndconfig.share = (_GLFWwindow*) share;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2011-03-04 15:00:19 +01:00
|
|
|
// Check the OpenGL bits of the window config
|
2011-03-07 14:55:11 +01:00
|
|
|
if (!_glfwIsValidContextConfig(&wndconfig))
|
2010-09-07 17:34:51 +02:00
|
|
|
return GL_FALSE;
|
|
|
|
|
2012-08-10 15:29:45 +02:00
|
|
|
// Save the currently current context so it can be restored later
|
|
|
|
previous = glfwGetCurrentContext();
|
|
|
|
|
2010-09-10 13:24:19 +02:00
|
|
|
if (mode != GLFW_WINDOWED && mode != GLFW_FULLSCREEN)
|
2010-09-09 18:15:32 +02:00
|
|
|
{
|
2011-07-27 17:48:56 +02:00
|
|
|
_glfwSetError(GLFW_INVALID_ENUM,
|
2012-08-28 15:03:57 +02:00
|
|
|
"glfwCreateWindow: Invalid window mode");
|
2010-09-07 17:34:51 +02:00
|
|
|
return GL_FALSE;
|
2010-09-09 18:15:32 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-11-22 17:04:54 +01:00
|
|
|
if (width <= 0 || height <= 0)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2012-11-22 17:04:54 +01:00
|
|
|
_glfwSetError(GLFW_INVALID_VALUE,
|
|
|
|
"glfwCreateWindow: Invalid window size");
|
|
|
|
return GL_FALSE;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2012-10-02 17:07:59 +02:00
|
|
|
window = (_GLFWwindow*) calloc(1, sizeof(_GLFWwindow));
|
2011-03-07 14:30:23 +01:00
|
|
|
if (!window)
|
|
|
|
{
|
2012-08-28 15:03:57 +02:00
|
|
|
_glfwSetError(GLFW_OUT_OF_MEMORY, NULL);
|
2011-03-07 14:30:23 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
window->next = _glfwLibrary.windowListHead;
|
|
|
|
_glfwLibrary.windowListHead = window;
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
// Remember window settings
|
2011-09-06 13:55:29 +02:00
|
|
|
window->width = width;
|
|
|
|
window->height = height;
|
|
|
|
window->mode = mode;
|
2012-08-12 14:15:39 +02:00
|
|
|
window->resizable = wndconfig.resizable;
|
2011-09-06 13:55:29 +02:00
|
|
|
window->cursorMode = GLFW_CURSOR_NORMAL;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2011-03-04 17:49:36 +01:00
|
|
|
// Open the actual window and create its context
|
2012-08-06 17:56:41 +02:00
|
|
|
if (!_glfwPlatformCreateWindow(window, &wndconfig, &fbconfig))
|
2010-09-09 18:15:32 +02:00
|
|
|
{
|
2012-08-06 17:56:41 +02:00
|
|
|
glfwDestroyWindow(window);
|
2012-08-10 15:29:45 +02:00
|
|
|
glfwMakeContextCurrent(previous);
|
2010-09-07 17:34:51 +02:00
|
|
|
return GL_FALSE;
|
2010-09-09 18:15:32 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-08-03 15:21:49 +02:00
|
|
|
// Cache the actual (as opposed to requested) window parameters
|
|
|
|
_glfwPlatformRefreshWindowParams(window);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-08-02 14:42:24 +02:00
|
|
|
glfwMakeContextCurrent(window);
|
2012-09-23 14:08:36 +02:00
|
|
|
|
|
|
|
// Cache the actual (as opposed to requested) context parameters
|
2012-08-02 14:42:24 +02:00
|
|
|
if (!_glfwRefreshContextParams())
|
|
|
|
{
|
2012-08-06 17:56:41 +02:00
|
|
|
glfwDestroyWindow(window);
|
2012-08-10 15:29:45 +02:00
|
|
|
glfwMakeContextCurrent(previous);
|
2012-08-02 14:42:24 +02:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-03 15:21:49 +02:00
|
|
|
// Verify the context against the requested parameters
|
2012-08-02 14:42:24 +02:00
|
|
|
if (!_glfwIsValidContext(&wndconfig))
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2012-08-06 17:56:41 +02:00
|
|
|
glfwDestroyWindow(window);
|
2012-08-10 15:29:45 +02:00
|
|
|
glfwMakeContextCurrent(previous);
|
2010-09-07 17:34:51 +02:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-09-23 14:08:36 +02:00
|
|
|
// Clearing the front buffer to black to avoid garbage pixels left over
|
|
|
|
// from previous uses of our bit of VRAM
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
_glfwPlatformSwapBuffers(window);
|
|
|
|
|
2012-08-10 15:29:45 +02:00
|
|
|
// Restore the previously current context (or NULL)
|
|
|
|
glfwMakeContextCurrent(previous);
|
|
|
|
|
2011-03-04 17:49:36 +01:00
|
|
|
// The GLFW specification states that fullscreen windows have the cursor
|
2011-09-06 13:55:29 +02:00
|
|
|
// captured by default
|
2010-09-08 14:45:52 +02:00
|
|
|
if (mode == GLFW_FULLSCREEN)
|
2012-02-04 00:51:35 +01:00
|
|
|
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-09-23 15:08:43 +02:00
|
|
|
if (mode == GLFW_WINDOWED && wndconfig.visible)
|
2012-08-21 21:18:09 +02:00
|
|
|
glfwShowWindow(window);
|
|
|
|
|
2010-09-09 18:15:32 +02:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-22 02:59:05 +02:00
|
|
|
//========================================================================
|
|
|
|
// Reset all window hints to their default values
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
void glfwDefaultWindowHints(void)
|
|
|
|
{
|
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&_glfwLibrary.hints, 0, sizeof(_glfwLibrary.hints));
|
|
|
|
|
|
|
|
// The default is OpenGL with minimum version 1.0
|
|
|
|
_glfwLibrary.hints.clientAPI = GLFW_OPENGL_API;
|
|
|
|
_glfwLibrary.hints.glMajor = 1;
|
|
|
|
_glfwLibrary.hints.glMinor = 0;
|
|
|
|
|
|
|
|
// The default is to show the window and allow window resizing
|
|
|
|
_glfwLibrary.hints.resizable = GL_TRUE;
|
|
|
|
_glfwLibrary.hints.visible = GL_TRUE;
|
|
|
|
|
2012-10-28 00:23:28 +02:00
|
|
|
// The default window position is the upper left corner of the screen
|
|
|
|
_glfwLibrary.hints.positionX = 0;
|
|
|
|
_glfwLibrary.hints.positionY = 0;
|
|
|
|
|
2012-10-22 02:59:05 +02:00
|
|
|
// The default is 24 bits of color, 24 bits of depth and 8 bits of stencil
|
|
|
|
_glfwLibrary.hints.redBits = 8;
|
|
|
|
_glfwLibrary.hints.greenBits = 8;
|
|
|
|
_glfwLibrary.hints.blueBits = 8;
|
|
|
|
_glfwLibrary.hints.depthBits = 24;
|
|
|
|
_glfwLibrary.hints.stencilBits = 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
2012-08-06 17:56:41 +02:00
|
|
|
// Set hints for creating the window
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
|
|
|
|
2012-08-06 17:56:41 +02:00
|
|
|
GLFWAPI void glfwWindowHint(int target, int hint)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-08 14:45:52 +02:00
|
|
|
if (!_glfwInitialized)
|
2010-09-09 21:34:42 +02:00
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-07 17:34:51 +02:00
|
|
|
return;
|
2010-09-09 21:34:42 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2010-09-08 14:45:52 +02:00
|
|
|
switch (target)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-09 19:58:51 +02:00
|
|
|
case GLFW_RED_BITS:
|
|
|
|
_glfwLibrary.hints.redBits = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_GREEN_BITS:
|
|
|
|
_glfwLibrary.hints.greenBits = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_BLUE_BITS:
|
|
|
|
_glfwLibrary.hints.blueBits = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_ALPHA_BITS:
|
|
|
|
_glfwLibrary.hints.alphaBits = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_DEPTH_BITS:
|
|
|
|
_glfwLibrary.hints.depthBits = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_STENCIL_BITS:
|
|
|
|
_glfwLibrary.hints.stencilBits = hint;
|
|
|
|
break;
|
2010-09-07 17:34:51 +02:00
|
|
|
case GLFW_REFRESH_RATE:
|
|
|
|
_glfwLibrary.hints.refreshRate = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_ACCUM_RED_BITS:
|
|
|
|
_glfwLibrary.hints.accumRedBits = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_ACCUM_GREEN_BITS:
|
|
|
|
_glfwLibrary.hints.accumGreenBits = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_ACCUM_BLUE_BITS:
|
|
|
|
_glfwLibrary.hints.accumBlueBits = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_ACCUM_ALPHA_BITS:
|
|
|
|
_glfwLibrary.hints.accumAlphaBits = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_AUX_BUFFERS:
|
|
|
|
_glfwLibrary.hints.auxBuffers = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_STEREO:
|
|
|
|
_glfwLibrary.hints.stereo = hint;
|
|
|
|
break;
|
2012-08-21 20:28:36 +02:00
|
|
|
case GLFW_RESIZABLE:
|
2011-11-02 16:56:34 +01:00
|
|
|
_glfwLibrary.hints.resizable = hint;
|
2010-09-07 17:34:51 +02:00
|
|
|
break;
|
2012-08-21 21:18:09 +02:00
|
|
|
case GLFW_VISIBLE:
|
|
|
|
_glfwLibrary.hints.visible = hint;
|
|
|
|
break;
|
2012-10-28 00:23:28 +02:00
|
|
|
case GLFW_POSITION_X:
|
|
|
|
_glfwLibrary.hints.positionX = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_POSITION_Y:
|
|
|
|
_glfwLibrary.hints.positionY = hint;
|
|
|
|
break;
|
2010-09-07 17:34:51 +02:00
|
|
|
case GLFW_FSAA_SAMPLES:
|
|
|
|
_glfwLibrary.hints.samples = hint;
|
|
|
|
break;
|
2012-12-02 16:10:00 +01:00
|
|
|
case GLFW_SRGB_CAPABLE:
|
|
|
|
_glfwLibrary.hints.sRGB = hint;
|
|
|
|
break;
|
2012-09-30 15:32:50 +02:00
|
|
|
case GLFW_CLIENT_API:
|
|
|
|
_glfwLibrary.hints.clientAPI = hint;
|
|
|
|
break;
|
2012-12-13 02:22:39 +01:00
|
|
|
case GLFW_CONTEXT_VERSION_MAJOR:
|
2010-09-07 17:34:51 +02:00
|
|
|
_glfwLibrary.hints.glMajor = hint;
|
|
|
|
break;
|
2012-12-13 02:22:39 +01:00
|
|
|
case GLFW_CONTEXT_VERSION_MINOR:
|
2010-09-07 17:34:51 +02:00
|
|
|
_glfwLibrary.hints.glMinor = hint;
|
|
|
|
break;
|
2012-12-13 02:22:39 +01:00
|
|
|
case GLFW_CONTEXT_ROBUSTNESS:
|
|
|
|
_glfwLibrary.hints.glRobustness = hint;
|
|
|
|
break;
|
2010-09-07 17:34:51 +02:00
|
|
|
case GLFW_OPENGL_FORWARD_COMPAT:
|
|
|
|
_glfwLibrary.hints.glForward = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_OPENGL_DEBUG_CONTEXT:
|
|
|
|
_glfwLibrary.hints.glDebug = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_OPENGL_PROFILE:
|
|
|
|
_glfwLibrary.hints.glProfile = hint;
|
|
|
|
break;
|
|
|
|
default:
|
2011-10-08 23:41:30 +02:00
|
|
|
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
2010-09-07 17:34:51 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Properly kill the window / video display
|
|
|
|
//========================================================================
|
|
|
|
|
2012-08-06 17:56:41 +02:00
|
|
|
GLFWAPI void glfwDestroyWindow(GLFWwindow handle)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2011-04-06 20:38:55 +02:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2010-09-08 14:45:52 +02:00
|
|
|
if (!_glfwInitialized)
|
2010-09-09 21:34:42 +02:00
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-07 17:34:51 +02:00
|
|
|
return;
|
2010-09-09 21:34:42 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2011-03-08 23:14:42 +01:00
|
|
|
// Allow closing of NULL (to match the behavior of free)
|
|
|
|
if (window == NULL)
|
|
|
|
return;
|
|
|
|
|
2012-10-21 21:57:29 +02:00
|
|
|
// The window's context must not be current on another thread when the
|
|
|
|
// window is destroyed
|
2012-08-12 14:13:18 +02:00
|
|
|
if (window == _glfwPlatformGetCurrentContext())
|
|
|
|
_glfwPlatformMakeContextCurrent(NULL);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-11-22 17:04:44 +01:00
|
|
|
// Clear the focused window pointer if this is the focused window
|
|
|
|
if (window == _glfwLibrary.focusedWindow)
|
|
|
|
_glfwLibrary.focusedWindow = NULL;
|
2010-09-11 15:14:57 +02:00
|
|
|
|
2012-08-06 17:56:41 +02:00
|
|
|
_glfwPlatformDestroyWindow(window);
|
2010-09-09 18:15:32 +02:00
|
|
|
|
2010-09-16 02:05:01 +02:00
|
|
|
// Unlink window from global linked list
|
|
|
|
{
|
|
|
|
_GLFWwindow** prev = &_glfwLibrary.windowListHead;
|
|
|
|
|
|
|
|
while (*prev != window)
|
|
|
|
prev = &((*prev)->next);
|
2010-09-10 00:06:23 +02:00
|
|
|
|
2010-09-16 02:05:01 +02:00
|
|
|
*prev = window->next;
|
|
|
|
}
|
2010-09-10 00:30:10 +02:00
|
|
|
|
2012-02-07 14:58:58 +01:00
|
|
|
free(window);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 17:50:43 +02:00
|
|
|
// Set the window title
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
|
|
|
|
2011-02-09 12:44:24 +01:00
|
|
|
GLFWAPI void glfwSetWindowTitle(GLFWwindow handle, const char* title)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2011-04-06 20:38:55 +02:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2010-09-09 18:15:32 +02:00
|
|
|
if (!_glfwInitialized)
|
2010-09-09 21:34:42 +02:00
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-07 17:34:51 +02:00
|
|
|
return;
|
2010-09-09 21:34:42 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2010-09-09 18:15:32 +02:00
|
|
|
_glfwPlatformSetWindowTitle(window, title);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 17:50:43 +02:00
|
|
|
// Get the window size
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
|
|
|
|
2011-02-09 12:37:42 +01:00
|
|
|
GLFWAPI void glfwGetWindowSize(GLFWwindow handle, int* width, int* height)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2011-04-06 20:38:55 +02:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2010-09-09 18:15:32 +02:00
|
|
|
if (!_glfwInitialized)
|
2010-09-09 21:34:42 +02:00
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-09 18:15:32 +02:00
|
|
|
return;
|
2010-09-09 21:34:42 +02:00
|
|
|
}
|
2010-09-09 18:15:32 +02:00
|
|
|
|
2010-09-08 14:45:52 +02:00
|
|
|
if (width != NULL)
|
2010-09-09 18:15:32 +02:00
|
|
|
*width = window->width;
|
2010-09-08 01:57:24 +02:00
|
|
|
|
2010-09-08 14:45:52 +02:00
|
|
|
if (height != NULL)
|
2010-09-09 18:15:32 +02:00
|
|
|
*height = window->height;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 17:50:43 +02:00
|
|
|
// Set the window size
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
|
|
|
|
2011-02-09 12:37:42 +01:00
|
|
|
GLFWAPI void glfwSetWindowSize(GLFWwindow handle, int width, int height)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2011-04-06 20:38:55 +02:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2010-09-09 21:34:42 +02:00
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-09 21:34:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->iconified)
|
|
|
|
{
|
|
|
|
// TODO: Figure out if this is an error
|
2010-09-07 17:34:51 +02:00
|
|
|
return;
|
2010-09-09 21:34:42 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
// Don't do anything if the window size did not change
|
2010-09-09 18:15:32 +02:00
|
|
|
if (width == window->width && height == window->height)
|
2010-09-07 17:34:51 +02:00
|
|
|
return;
|
|
|
|
|
2010-09-09 18:15:32 +02:00
|
|
|
_glfwPlatformSetWindowSize(window, width, height);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2010-09-09 18:15:32 +02:00
|
|
|
if (window->mode == GLFW_FULLSCREEN)
|
|
|
|
{
|
|
|
|
// Refresh window parameters (may have changed due to changed video
|
|
|
|
// modes)
|
2012-08-03 15:21:49 +02:00
|
|
|
_glfwPlatformRefreshWindowParams(window);
|
2010-09-09 18:15:32 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 17:50:43 +02:00
|
|
|
// Window iconification
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
|
|
|
|
2011-02-09 12:37:42 +01:00
|
|
|
GLFWAPI void glfwIconifyWindow(GLFWwindow handle)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2011-04-06 20:38:55 +02:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2010-09-09 21:34:42 +02:00
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-09 21:34:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->iconified)
|
2010-09-07 17:34:51 +02:00
|
|
|
return;
|
|
|
|
|
2010-09-09 18:15:32 +02:00
|
|
|
_glfwPlatformIconifyWindow(window);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-21 20:01:57 +02:00
|
|
|
//========================================================================
|
2012-09-11 23:56:44 +02:00
|
|
|
// Window un-iconification
|
2012-08-21 20:01:57 +02:00
|
|
|
//========================================================================
|
|
|
|
|
2012-09-11 23:56:44 +02:00
|
|
|
GLFWAPI void glfwRestoreWindow(GLFWwindow handle)
|
2012-08-21 20:01:57 +02:00
|
|
|
{
|
2012-09-11 23:51:45 +02:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2012-08-21 20:01:57 +02:00
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-11 23:56:44 +02:00
|
|
|
if (!window->iconified)
|
2012-09-11 23:51:45 +02:00
|
|
|
return;
|
|
|
|
|
2012-09-11 23:56:44 +02:00
|
|
|
_glfwPlatformRestoreWindow(window);
|
|
|
|
|
|
|
|
if (window->mode == GLFW_FULLSCREEN)
|
|
|
|
_glfwPlatformRefreshWindowParams(window);
|
2012-08-21 20:01:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2012-09-11 23:56:44 +02:00
|
|
|
// Window show
|
2012-08-21 20:01:57 +02:00
|
|
|
//========================================================================
|
|
|
|
|
2012-09-11 23:56:44 +02:00
|
|
|
GLFWAPI void glfwShowWindow(GLFWwindow handle)
|
2012-08-21 20:01:57 +02:00
|
|
|
{
|
2012-09-11 23:51:45 +02:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2012-08-21 20:01:57 +02:00
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-11 23:51:45 +02:00
|
|
|
if (window->mode == GLFW_FULLSCREEN)
|
|
|
|
return;
|
|
|
|
|
2012-09-11 23:56:44 +02:00
|
|
|
_glfwPlatformShowWindow(window);
|
2012-08-21 20:01:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
2012-09-11 23:56:44 +02:00
|
|
|
// Window hide
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
|
|
|
|
2012-09-11 23:56:44 +02:00
|
|
|
GLFWAPI void glfwHideWindow(GLFWwindow handle)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2011-04-06 20:38:55 +02:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2010-09-09 21:34:42 +02:00
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-09 21:34:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-11 23:56:44 +02:00
|
|
|
if (window->mode == GLFW_FULLSCREEN)
|
2010-09-07 17:34:51 +02:00
|
|
|
return;
|
|
|
|
|
2012-09-11 23:56:44 +02:00
|
|
|
_glfwPlatformHideWindow(window);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 17:50:43 +02:00
|
|
|
// Get window parameter
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
|
|
|
|
2011-02-09 12:37:42 +01:00
|
|
|
GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2011-04-06 20:38:55 +02:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2010-09-08 14:45:52 +02:00
|
|
|
if (!_glfwInitialized)
|
2010-09-09 21:34:42 +02:00
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-07 17:34:51 +02:00
|
|
|
return 0;
|
2010-09-09 21:34:42 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2010-09-08 14:45:52 +02:00
|
|
|
switch (param)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2012-11-22 17:04:44 +01:00
|
|
|
case GLFW_FOCUSED:
|
|
|
|
return window == _glfwLibrary.focusedWindow;
|
2010-09-07 17:34:51 +02:00
|
|
|
case GLFW_ICONIFIED:
|
2010-09-09 18:15:32 +02:00
|
|
|
return window->iconified;
|
2012-08-10 13:31:15 +02:00
|
|
|
case GLFW_CLOSE_REQUESTED:
|
|
|
|
return window->closeRequested;
|
2010-09-07 17:34:51 +02:00
|
|
|
case GLFW_REFRESH_RATE:
|
2010-09-09 18:15:32 +02:00
|
|
|
return window->refreshRate;
|
2012-08-21 20:28:36 +02:00
|
|
|
case GLFW_RESIZABLE:
|
2011-11-02 16:56:34 +01:00
|
|
|
return window->resizable;
|
2012-08-21 21:57:13 +02:00
|
|
|
case GLFW_VISIBLE:
|
|
|
|
return window->visible;
|
2012-10-28 00:23:28 +02:00
|
|
|
case GLFW_POSITION_X:
|
|
|
|
return window->positionX;
|
|
|
|
case GLFW_POSITION_Y:
|
|
|
|
return window->positionY;
|
2012-09-30 15:43:26 +02:00
|
|
|
case GLFW_CLIENT_API:
|
|
|
|
return window->clientAPI;
|
2012-12-13 02:22:39 +01:00
|
|
|
case GLFW_CONTEXT_VERSION_MAJOR:
|
2010-09-09 18:15:32 +02:00
|
|
|
return window->glMajor;
|
2012-12-13 02:22:39 +01:00
|
|
|
case GLFW_CONTEXT_VERSION_MINOR:
|
2010-09-09 18:15:32 +02:00
|
|
|
return window->glMinor;
|
2012-12-13 02:22:39 +01:00
|
|
|
case GLFW_CONTEXT_REVISION:
|
2011-05-21 17:16:32 +02:00
|
|
|
return window->glRevision;
|
2012-12-13 02:22:39 +01:00
|
|
|
case GLFW_CONTEXT_ROBUSTNESS:
|
|
|
|
return window->glRobustness;
|
2010-09-07 17:34:51 +02:00
|
|
|
case GLFW_OPENGL_FORWARD_COMPAT:
|
2010-09-09 18:15:32 +02:00
|
|
|
return window->glForward;
|
2010-09-07 17:34:51 +02:00
|
|
|
case GLFW_OPENGL_DEBUG_CONTEXT:
|
2010-09-09 18:15:32 +02:00
|
|
|
return window->glDebug;
|
2010-09-07 17:34:51 +02:00
|
|
|
case GLFW_OPENGL_PROFILE:
|
2010-09-09 18:15:32 +02:00
|
|
|
return window->glProfile;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
2011-10-08 23:41:30 +02:00
|
|
|
|
|
|
|
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
|
|
|
return 0;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-09 22:44:38 +02:00
|
|
|
//========================================================================
|
|
|
|
// Set the user pointer for the specified window
|
|
|
|
//========================================================================
|
|
|
|
|
2011-02-09 12:37:42 +01:00
|
|
|
GLFWAPI void glfwSetWindowUserPointer(GLFWwindow handle, void* pointer)
|
2010-09-09 22:44:38 +02:00
|
|
|
{
|
2011-04-06 20:38:55 +02:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2010-09-09 22:44:38 +02:00
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-09 22:44:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window->userPointer = pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Get the user pointer for the specified window
|
|
|
|
//========================================================================
|
|
|
|
|
2011-02-09 12:37:42 +01:00
|
|
|
GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow handle)
|
2010-09-09 22:44:38 +02:00
|
|
|
{
|
2011-04-06 20:38:55 +02:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2010-09-09 22:44:38 +02:00
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-14 00:15:01 +02:00
|
|
|
return NULL;
|
2010-09-09 22:44:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return window->userPointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-30 13:56:42 +01:00
|
|
|
//========================================================================
|
|
|
|
// Set callback function for window position changes
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
GLFWAPI void glfwSetWindowPosCallback(GLFWwindow handle, GLFWwindowposfun cbfun)
|
|
|
|
{
|
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window->windowPosCallback = cbfun;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
2010-09-07 17:50:43 +02:00
|
|
|
// Set callback function for window size changes
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
|
|
|
|
2012-10-28 13:45:11 +01:00
|
|
|
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow handle, GLFWwindowsizefun cbfun)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2012-10-28 13:45:11 +01:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2010-09-09 18:15:32 +02:00
|
|
|
if (!_glfwInitialized)
|
2010-09-09 21:34:42 +02:00
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-07 17:34:51 +02:00
|
|
|
return;
|
2010-09-09 21:34:42 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-10-28 13:45:11 +01:00
|
|
|
window->windowSizeCallback = cbfun;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2011-10-08 23:57:03 +02:00
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
2010-09-07 17:50:43 +02:00
|
|
|
// Set callback function for window close events
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
|
|
|
|
2012-10-28 13:45:11 +01:00
|
|
|
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow handle, GLFWwindowclosefun cbfun)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2012-10-28 13:45:11 +01:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2010-09-09 18:15:32 +02:00
|
|
|
if (!_glfwInitialized)
|
2010-09-09 21:34:42 +02:00
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-07 17:34:51 +02:00
|
|
|
return;
|
2010-09-09 21:34:42 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-10-28 13:45:11 +01:00
|
|
|
window->windowCloseCallback = cbfun;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 17:50:43 +02:00
|
|
|
// Set callback function for window refresh events
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
|
|
|
|
2012-10-28 13:45:11 +01:00
|
|
|
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow handle, GLFWwindowrefreshfun cbfun)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2012-10-28 13:45:11 +01:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2010-09-09 18:15:32 +02:00
|
|
|
if (!_glfwInitialized)
|
2010-09-09 21:34:42 +02:00
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-07 17:34:51 +02:00
|
|
|
return;
|
2010-09-09 21:34:42 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-10-28 13:45:11 +01:00
|
|
|
window->windowRefreshCallback = cbfun;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-19 02:49:42 +02:00
|
|
|
//========================================================================
|
|
|
|
// Set callback function for window focus events
|
|
|
|
//========================================================================
|
|
|
|
|
2012-10-28 13:45:11 +01:00
|
|
|
GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow handle, GLFWwindowfocusfun cbfun)
|
2010-09-19 02:49:42 +02:00
|
|
|
{
|
2012-10-28 13:45:11 +01:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2010-09-19 02:49:42 +02:00
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-19 02:49:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-28 13:45:11 +01:00
|
|
|
window->windowFocusCallback = cbfun;
|
2010-09-19 02:49:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-20 02:22:35 +02:00
|
|
|
//========================================================================
|
|
|
|
// Set callback function for window iconification events
|
|
|
|
//========================================================================
|
|
|
|
|
2012-10-28 13:45:11 +01:00
|
|
|
GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindow handle, GLFWwindowiconifyfun cbfun)
|
2010-09-20 02:22:35 +02:00
|
|
|
{
|
2012-10-28 13:45:11 +01:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2010-09-20 02:22:35 +02:00
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-20 02:22:35 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-28 13:45:11 +01:00
|
|
|
window->windowIconifyCallback = cbfun;
|
2010-09-20 02:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
2012-09-11 23:53:10 +02:00
|
|
|
// Poll for new window and input events
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 14:45:52 +02:00
|
|
|
GLFWAPI void glfwPollEvents(void)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-09 18:15:32 +02:00
|
|
|
if (!_glfwInitialized)
|
2010-09-09 21:34:42 +02:00
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-07 17:34:51 +02:00
|
|
|
return;
|
2010-09-09 21:34:42 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2010-11-17 14:24:25 +01:00
|
|
|
clearScrollOffsets();
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
_glfwPlatformPollEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 17:50:43 +02:00
|
|
|
// Wait for new window and input events
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 14:45:52 +02:00
|
|
|
GLFWAPI void glfwWaitEvents(void)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-09 18:15:32 +02:00
|
|
|
if (!_glfwInitialized)
|
2010-09-09 21:34:42 +02:00
|
|
|
{
|
2010-11-23 17:45:23 +01:00
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-07 17:34:51 +02:00
|
|
|
return;
|
2010-09-09 21:34:42 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2010-11-17 14:24:25 +01:00
|
|
|
clearScrollOffsets();
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
_glfwPlatformWaitEvents();
|
|
|
|
}
|
|
|
|
|