2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
// GLFW - An OpenGL framework
|
|
|
|
// Platform: Any
|
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"
|
|
|
|
|
|
|
|
#include <limits.h>
|
2010-09-08 15:01:39 +00:00
|
|
|
#include <string.h>
|
2010-09-09 16:15:32 +00:00
|
|
|
#include <stdlib.h>
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
//**** GLFW internal functions ****
|
|
|
|
//************************************************************************
|
|
|
|
|
|
|
|
static int Max(int a, int b)
|
|
|
|
{
|
|
|
|
return (a > b) ? a : b;
|
|
|
|
}
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Clear all open window hints
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
void _glfwClearWindowHints(void)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
memset(&_glfwLibrary.hints, 0, sizeof(_glfwLibrary.hints));
|
2010-09-07 15:34:51 +00:00
|
|
|
_glfwLibrary.hints.glMajor = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Handle the input tracking part of window deactivation
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
void _glfwInputDeactivation(_GLFWwindow* window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// Release all keyboard keys
|
2010-09-08 12:45:52 +00:00
|
|
|
for (i = 0; i <= GLFW_KEY_LAST; i++)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (window->key[i] == GLFW_PRESS)
|
|
|
|
_glfwInputKey(window, i, GLFW_RELEASE);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Release all mouse buttons
|
2010-09-08 12:45:52 +00:00
|
|
|
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (window->mouseButton[i] == GLFW_PRESS)
|
|
|
|
_glfwInputMouseClick(window, i, GLFW_RELEASE);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Clear all input state
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
void _glfwClearInput(_GLFWwindow* window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// Release all keyboard keys
|
2010-09-08 12:45:52 +00:00
|
|
|
for (i = 0; i <= GLFW_KEY_LAST; i++)
|
2010-09-09 16:15:32 +00:00
|
|
|
window->key[i] = GLFW_RELEASE;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Clear last character
|
2010-09-09 16:15:32 +00:00
|
|
|
window->lastChar = 0;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Release all mouse buttons
|
2010-09-08 12:45:52 +00:00
|
|
|
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
|
2010-09-09 16:15:32 +00:00
|
|
|
window->mouseButton[i] = GLFW_RELEASE;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Set mouse position to (0,0)
|
2010-09-09 16:15:32 +00:00
|
|
|
window->mousePosX = 0;
|
|
|
|
window->mousePosY = 0;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Set mouse wheel position to 0
|
2010-09-09 16:15:32 +00:00
|
|
|
window->wheelPos = 0;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// The default is to use non sticky keys and mouse buttons
|
2010-09-09 16:15:32 +00:00
|
|
|
window->stickyKeys = GL_FALSE;
|
|
|
|
window->stickyMouseButtons = GL_FALSE;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// The default is to disable key repeat
|
2010-09-09 16:15:32 +00:00
|
|
|
window->keyRepeat = GL_FALSE;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Register keyboard activity
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
GLboolean keyrepeat = GL_FALSE;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (key < 0 || key > GLFW_KEY_LAST)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Are we trying to release an already released key?
|
2010-09-09 16:15:32 +00:00
|
|
|
if (action == GLFW_RELEASE && window->key[key] != GLFW_PRESS)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Register key action
|
2010-09-09 16:15:32 +00:00
|
|
|
if(action == GLFW_RELEASE && window->stickyKeys)
|
|
|
|
window->key[key] = GLFW_STICK;
|
2010-09-07 15:34:51 +00:00
|
|
|
else
|
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
keyrepeat = (window->key[key] == GLFW_PRESS) &&
|
2010-09-07 15:34:51 +00:00
|
|
|
(action == GLFW_PRESS);
|
2010-09-09 16:15:32 +00:00
|
|
|
window->key[key] = (char) action;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call user callback function
|
2010-09-09 16:15:32 +00:00
|
|
|
if (window->keyCallback && (window->keyRepeat || !keyrepeat) )
|
2010-09-09 17:01:16 +00:00
|
|
|
window->keyCallback(window, key, action);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Register (keyboard) character activity
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 17:33:37 +00:00
|
|
|
void _glfwInputChar(_GLFWwindow* window, int character)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
int keyrepeat = 0;
|
|
|
|
|
|
|
|
// Valid Unicode (ISO 10646) character?
|
2010-09-08 12:45:52 +00:00
|
|
|
if (!((character >= 32 && character <= 126) || character >= 160))
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
if (window->charCallback && (window->keyRepeat || !keyrepeat))
|
2010-09-09 17:33:37 +00:00
|
|
|
window->charCallback(window, character);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Register mouse button clicks
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Register mouse button action
|
|
|
|
if (action == GLFW_RELEASE && window->stickyMouseButtons)
|
|
|
|
window->mouseButton[button] = GLFW_STICK;
|
|
|
|
else
|
|
|
|
window->mouseButton[button] = (char) action;
|
|
|
|
|
|
|
|
if (window->mouseButtonCallback)
|
2010-09-09 17:01:16 +00:00
|
|
|
window->mouseButtonCallback(window, button, action);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Return the available framebuffer config closest to the desired values
|
|
|
|
// This is based on the manual GLX Visual selection from 2.6
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 13:58:43 +00:00
|
|
|
const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
|
|
|
|
const _GLFWfbconfig* alternatives,
|
2010-09-08 12:45:52 +00:00
|
|
|
unsigned int count)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
unsigned int missing, leastMissing = UINT_MAX;
|
|
|
|
unsigned int colorDiff, leastColorDiff = UINT_MAX;
|
|
|
|
unsigned int extraDiff, leastExtraDiff = UINT_MAX;
|
|
|
|
GLboolean desiresColor = GL_FALSE;
|
2010-09-08 13:58:43 +00:00
|
|
|
const _GLFWfbconfig* current;
|
|
|
|
const _GLFWfbconfig* closest = NULL;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Cache some long-winded preferences
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->redBits || desired->greenBits || desired->blueBits ||
|
|
|
|
desired->alphaBits)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
desiresColor = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
for (i = 0; i < count; i++)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
current = alternatives + i;
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->stereo > 0 && current->stereo == 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// Stereo is a hard constraint
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Count number of missing buffers
|
|
|
|
{
|
|
|
|
missing = 0;
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->alphaBits > 0 && current->alphaBits == 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
missing++;
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->depthBits > 0 && current->depthBits == 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
missing++;
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->stencilBits > 0 && current->stencilBits == 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
missing++;
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->auxBuffers > 0 && current->auxBuffers < desired->auxBuffers)
|
2010-09-07 15:34:51 +00:00
|
|
|
missing += desired->auxBuffers - current->auxBuffers;
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->samples > 0 && current->samples == 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// Technically, several multisampling buffers could be
|
|
|
|
// involved, but that's a lower level implementation detail and
|
|
|
|
// not important to us here, so we count them as one
|
|
|
|
missing++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// These polynomials make many small channel size differences matter
|
|
|
|
// less than one large channel size difference
|
|
|
|
|
|
|
|
// Calculate color channel size difference value
|
|
|
|
{
|
|
|
|
colorDiff = 0;
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->redBits > 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
colorDiff += (desired->redBits - current->redBits) *
|
|
|
|
(desired->redBits - current->redBits);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->greenBits > 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
colorDiff += (desired->greenBits - current->greenBits) *
|
|
|
|
(desired->greenBits - current->greenBits);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->blueBits > 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
colorDiff += (desired->blueBits - current->blueBits) *
|
|
|
|
(desired->blueBits - current->blueBits);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate non-color channel size difference value
|
|
|
|
{
|
|
|
|
extraDiff = 0;
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->alphaBits > 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
extraDiff += (desired->alphaBits - current->alphaBits) *
|
|
|
|
(desired->alphaBits - current->alphaBits);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->depthBits > 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
extraDiff += (desired->depthBits - current->depthBits) *
|
|
|
|
(desired->depthBits - current->depthBits);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->stencilBits > 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
extraDiff += (desired->stencilBits - current->stencilBits) *
|
|
|
|
(desired->stencilBits - current->stencilBits);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->accumRedBits > 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
extraDiff += (desired->accumRedBits - current->accumRedBits) *
|
|
|
|
(desired->accumRedBits - current->accumRedBits);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->accumGreenBits > 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
extraDiff += (desired->accumGreenBits - current->accumGreenBits) *
|
|
|
|
(desired->accumGreenBits - current->accumGreenBits);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->accumBlueBits > 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
extraDiff += (desired->accumBlueBits - current->accumBlueBits) *
|
|
|
|
(desired->accumBlueBits - current->accumBlueBits);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->accumAlphaBits > 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
extraDiff += (desired->accumAlphaBits - current->accumAlphaBits) *
|
|
|
|
(desired->accumAlphaBits - current->accumAlphaBits);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desired->samples > 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
extraDiff += (desired->samples - current->samples) *
|
|
|
|
(desired->samples - current->samples);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Figure out if the current one is better than the best one found so far
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (missing < leastMissing)
|
2010-09-07 15:34:51 +00:00
|
|
|
closest = current;
|
2010-09-08 12:45:52 +00:00
|
|
|
else if (missing == leastMissing)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
if (desiresColor)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
if ((colorDiff < leastColorDiff) ||
|
|
|
|
(colorDiff == leastColorDiff && extraDiff < leastExtraDiff))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
closest = current;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
if ((extraDiff < leastExtraDiff) ||
|
|
|
|
(extraDiff == leastExtraDiff && colorDiff < leastColorDiff))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
closest = current;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (current == closest)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
leastMissing = missing;
|
|
|
|
leastColorDiff = colorDiff;
|
|
|
|
leastExtraDiff = extraDiff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return closest;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
//**** GLFW user functions ****
|
|
|
|
//************************************************************************
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Create the GLFW window and its associated context
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 17:58:51 +00:00
|
|
|
GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
_GLFWfbconfig fbconfig;
|
|
|
|
_GLFWwndconfig wndconfig;
|
2010-09-09 16:15:32 +00:00
|
|
|
_GLFWwindow* window;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
if (!_glfwInitialized || _glfwLibrary.window)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
window = (_GLFWwindow*) malloc(sizeof(_GLFWwindow));
|
|
|
|
if (!window)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
_glfwLibrary.window = window;
|
|
|
|
|
|
|
|
memset(window, 0, sizeof(_GLFWwindow));
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Set up desired framebuffer config
|
2010-09-09 17:58:51 +00: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 12:45:52 +00: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 15:34:51 +00:00
|
|
|
fbconfig.stereo = _glfwLibrary.hints.stereo ? GL_TRUE : GL_FALSE;
|
2010-09-08 12:45:52 +00:00
|
|
|
fbconfig.samples = Max(_glfwLibrary.hints.samples, 0);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Set up desired window config
|
|
|
|
wndconfig.mode = mode;
|
2010-09-08 12:45:52 +00:00
|
|
|
wndconfig.refreshRate = Max(_glfwLibrary.hints.refreshRate, 0);
|
2010-09-07 15:34:51 +00:00
|
|
|
wndconfig.windowNoResize = _glfwLibrary.hints.windowNoResize ? GL_TRUE : GL_FALSE;
|
2010-09-08 12:45:52 +00:00
|
|
|
wndconfig.glMajor = Max(_glfwLibrary.hints.glMajor, 1);
|
|
|
|
wndconfig.glMinor = Max(_glfwLibrary.hints.glMinor, 0);
|
2010-09-07 15:34:51 +00:00
|
|
|
wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE;
|
|
|
|
wndconfig.glDebug = _glfwLibrary.hints.glDebug ? GL_TRUE : GL_FALSE;
|
|
|
|
wndconfig.glProfile = _glfwLibrary.hints.glProfile;
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
// Clear for next open call
|
|
|
|
_glfwClearWindowHints();
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (wndconfig.glMajor == 1 && wndconfig.glMinor > 5)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// OpenGL 1.x series ended with version 1.5
|
2010-09-09 16:15:32 +00:00
|
|
|
glfwCloseWindow(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2010-09-08 12:45:52 +00:00
|
|
|
else if (wndconfig.glMajor == 2 && wndconfig.glMinor > 1)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// OpenGL 2.x series ended with version 2.1
|
2010-09-09 16:15:32 +00:00
|
|
|
glfwCloseWindow(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2010-09-08 12:45:52 +00:00
|
|
|
else if (wndconfig.glMajor == 3 && wndconfig.glMinor > 3)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// OpenGL 3.x series ended with version 3.3
|
2010-09-09 16:15:32 +00:00
|
|
|
glfwCloseWindow(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// For now, let everything else through
|
|
|
|
}
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (wndconfig.glProfile &&
|
|
|
|
(wndconfig.glMajor < 3 || (wndconfig.glMajor == 3 && wndconfig.glMinor < 2)))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// Context profiles are only defined for OpenGL version 3.2 and above
|
2010-09-09 16:15:32 +00:00
|
|
|
glfwCloseWindow(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (wndconfig.glForward && wndconfig.glMajor < 3)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// Forward-compatible contexts are only defined for OpenGL version 3.0 and above
|
2010-09-09 16:15:32 +00:00
|
|
|
glfwCloseWindow(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (mode != GLFW_WINDOW && mode != GLFW_FULLSCREEN)
|
2010-09-09 16:15:32 +00:00
|
|
|
{
|
|
|
|
// Invalid window mode
|
|
|
|
glfwCloseWindow(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
2010-09-09 16:15:32 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Clear GLFW window state
|
2010-09-09 16:15:32 +00:00
|
|
|
_glfwClearInput(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Check width & height
|
2010-09-08 12:45:52 +00:00
|
|
|
if (width > 0 && height <= 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// Set the window aspect ratio to 4:3
|
|
|
|
height = (width * 3) / 4;
|
|
|
|
}
|
2010-09-08 12:45:52 +00:00
|
|
|
else if (width <= 0 && height > 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// Set the window aspect ratio to 4:3
|
|
|
|
width = (height * 4) / 3;
|
|
|
|
}
|
2010-09-08 12:45:52 +00:00
|
|
|
else if (width <= 0 && height <= 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// Default window size
|
|
|
|
width = 640;
|
|
|
|
height = 480;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remember window settings
|
2010-09-09 16:15:32 +00:00
|
|
|
window->width = width;
|
|
|
|
window->height = height;
|
|
|
|
window->mode = mode;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Platform specific window opening routine
|
2010-09-09 16:15:32 +00:00
|
|
|
if (!_glfwPlatformOpenWindow(window, width, height, &wndconfig, &fbconfig))
|
|
|
|
{
|
|
|
|
glfwCloseWindow(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
2010-09-09 16:15:32 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Get window parameters (such as color buffer bits etc)
|
2010-09-09 16:15:32 +00:00
|
|
|
glfwMakeWindowCurrent(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
_glfwPlatformRefreshWindowParams();
|
|
|
|
|
|
|
|
// Get OpenGL version
|
2010-09-09 16:15:32 +00:00
|
|
|
_glfwParseGLVersion(&window->glMajor, &window->glMinor, &window->glRevision);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
if (window->glMajor < wndconfig.glMajor ||
|
|
|
|
(window->glMajor == wndconfig.glMajor &&
|
|
|
|
window->glMinor < wndconfig.glMinor))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
// The desired OpenGL version is greater than the actual version
|
|
|
|
// This only happens if the machine lacks {GLX|WGL}_ARB_create_context
|
|
|
|
glfwCloseWindow(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
if (window->glMajor > 2)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
window->GetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi");
|
|
|
|
if (!window->GetStringi)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
glfwCloseWindow(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If full-screen mode was requested, disable mouse cursor
|
2010-09-08 12:45:52 +00:00
|
|
|
if (mode == GLFW_FULLSCREEN)
|
2010-09-09 16:15:32 +00:00
|
|
|
glfwDisable(window, GLFW_MOUSE_CURSOR);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Start by clearing the front buffer to black (avoid ugly desktop
|
|
|
|
// remains in our OpenGL window)
|
2010-09-08 12:45:52 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2010-09-07 15:34:51 +00:00
|
|
|
_glfwPlatformSwapBuffers();
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Make the OpenGL context associated with the specified window current
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
GLFWAPI void glfwMakeWindowCurrent(GLFWwindow window)
|
|
|
|
{
|
2010-09-09 16:42:41 +00:00
|
|
|
if (!_glfwInitialized || _glfwLibrary.currentWindow == window)
|
2010-09-09 16:15:32 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
_glfwPlatformMakeWindowCurrent(window);
|
|
|
|
_glfwLibrary.currentWindow = window;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-09 16:42:41 +00:00
|
|
|
//========================================================================
|
|
|
|
// Returns GL_TRUE if the specified window handle is an actual window
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
GLFWAPI int glfwIsWindow(GLFWwindow window)
|
|
|
|
{
|
|
|
|
if (!_glfwInitialized)
|
2010-09-09 17:01:16 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
|
|
|
|
if (window == NULL)
|
|
|
|
return GL_FALSE;
|
2010-09-09 16:42:41 +00:00
|
|
|
|
2010-09-09 17:01:16 +00:00
|
|
|
return (window == _glfwLibrary.window) ? GL_TRUE : GL_FALSE;
|
2010-09-09 16:42:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
// Set hints for opening the window
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
GLFWAPI void glfwOpenWindowHint(int target, int hint)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
if (!_glfwInitialized)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
switch (target)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 17:58:51 +00: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 15:34:51 +00: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;
|
|
|
|
case GLFW_WINDOW_NO_RESIZE:
|
|
|
|
_glfwLibrary.hints.windowNoResize = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_FSAA_SAMPLES:
|
|
|
|
_glfwLibrary.hints.samples = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_OPENGL_VERSION_MAJOR:
|
|
|
|
_glfwLibrary.hints.glMajor = hint;
|
|
|
|
break;
|
|
|
|
case GLFW_OPENGL_VERSION_MINOR:
|
|
|
|
_glfwLibrary.hints.glMinor = hint;
|
|
|
|
break;
|
|
|
|
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:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Properly kill the window / video display
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
GLFWAPI void glfwCloseWindow(GLFWwindow window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
if (!_glfwInitialized)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Show mouse pointer again (if hidden)
|
2010-09-09 16:15:32 +00:00
|
|
|
if (window == _glfwLibrary.cursorLockWindow)
|
|
|
|
glfwEnable(window, GLFW_MOUSE_CURSOR);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
if (window == _glfwLibrary.currentWindow)
|
|
|
|
glfwMakeWindowCurrent(NULL);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
_glfwPlatformCloseWindow(window);
|
|
|
|
|
|
|
|
free(window);
|
|
|
|
|
|
|
|
// Yuck
|
|
|
|
_glfwLibrary.window = NULL;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Set the window title
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
GLFWAPI void glfwSetWindowTitle(GLFWwindow window, const char* title)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (!_glfwInitialized)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
_glfwPlatformSetWindowTitle(window, title);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Get the window size
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
GLFWAPI void glfwGetWindowSize(GLFWwindow window, int* width, int* height)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (!_glfwInitialized)
|
|
|
|
return;
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (width != NULL)
|
2010-09-09 16:15:32 +00:00
|
|
|
*width = window->width;
|
2010-09-07 23:57:24 +00:00
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
if (height != NULL)
|
2010-09-09 16:15:32 +00:00
|
|
|
*height = window->height;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Set the window size
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
GLFWAPI void glfwSetWindowSize(GLFWwindow window, int width, int height)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (!_glfwInitialized || window->iconified)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Don't do anything if the window size did not change
|
2010-09-09 16:15:32 +00:00
|
|
|
if (width == window->width && height == window->height)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
_glfwPlatformSetWindowSize(window, width, height);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
if (window->mode == GLFW_FULLSCREEN)
|
|
|
|
{
|
|
|
|
// Refresh window parameters (may have changed due to changed video
|
|
|
|
// modes)
|
|
|
|
_glfwPlatformRefreshWindowParams();
|
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Set the window position
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
GLFWAPI void glfwSetWindowPos(GLFWwindow window, int x, int y)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (!_glfwInitialized || window->mode == GLFW_FULLSCREEN || window->iconified)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
_glfwPlatformSetWindowPos(window, x, y);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Window iconification
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
GLFWAPI void glfwIconifyWindow(GLFWwindow window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (!_glfwInitialized || window->iconified)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
_glfwPlatformIconifyWindow(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Window un-iconification
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
GLFWAPI void glfwRestoreWindow(GLFWwindow window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (!_glfwInitialized || !window->iconified)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Restore iconified window
|
2010-09-09 16:15:32 +00:00
|
|
|
_glfwPlatformRestoreWindow(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
if (window->mode == GLFW_FULLSCREEN)
|
|
|
|
_glfwPlatformRefreshWindowParams();
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-09 16:15:32 +00:00
|
|
|
// Swap buffers (double-buffering)
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
GLFWAPI void glfwSwapBuffers(void)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (!_glfwInitialized)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
if (_glfwLibrary.currentWindow)
|
2010-09-07 15:34:51 +00:00
|
|
|
_glfwPlatformSwapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Set double buffering swap interval (0 = vsync off)
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
GLFWAPI void glfwSwapInterval(int interval)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (!_glfwInitialized)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
_glfwPlatformSwapInterval(interval);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Get window parameter
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
if (!_glfwInitialized)
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
switch (param)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
case GLFW_ACTIVE:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->active;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_ICONIFIED:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->iconified;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_ACCELERATED:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->accelerated;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_RED_BITS:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->redBits;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_GREEN_BITS:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->greenBits;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_BLUE_BITS:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->blueBits;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_ALPHA_BITS:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->alphaBits;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_DEPTH_BITS:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->depthBits;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_STENCIL_BITS:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->stencilBits;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_ACCUM_RED_BITS:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->accumRedBits;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_ACCUM_GREEN_BITS:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->accumGreenBits;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_ACCUM_BLUE_BITS:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->accumBlueBits;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_ACCUM_ALPHA_BITS:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->accumAlphaBits;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_AUX_BUFFERS:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->auxBuffers;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_STEREO:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->stereo;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_REFRESH_RATE:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->refreshRate;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_WINDOW_NO_RESIZE:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->windowNoResize;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_FSAA_SAMPLES:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->samples;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_OPENGL_VERSION_MAJOR:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->glMajor;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_OPENGL_VERSION_MINOR:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->glMinor;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_OPENGL_FORWARD_COMPAT:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->glForward;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_OPENGL_DEBUG_CONTEXT:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->glDebug;
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_OPENGL_PROFILE:
|
2010-09-09 16:15:32 +00:00
|
|
|
return window->glProfile;
|
2010-09-07 15:34:51 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Set callback function for window size changes
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfun)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (!_glfwInitialized)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
window->windowSizeCallback = cbfun;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Call the callback function to let the application know the current
|
|
|
|
// window size
|
2010-09-08 12:45:52 +00:00
|
|
|
if (cbfun)
|
2010-09-09 17:01:16 +00:00
|
|
|
cbfun(window, window->width, window->height);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Set callback function for window close events
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cbfun)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (!_glfwInitialized)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
window->windowCloseCallback = cbfun;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Set callback function for window refresh events
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfun cbfun)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (!_glfwInitialized)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
window->windowRefreshCallback = cbfun;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Poll for new window and input events
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
GLFWAPI void glfwPollEvents(void)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (!_glfwInitialized)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
_glfwPlatformPollEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-07 15:50:43 +00:00
|
|
|
// Wait for new window and input events
|
2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
GLFWAPI void glfwWaitEvents(void)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (!_glfwInitialized)
|
2010-09-07 15:34:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
_glfwPlatformWaitEvents();
|
|
|
|
}
|
|
|
|
|