mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-23 02:38:52 -05:00
Merge branch 'master' into joystickname
Conflicts: src/x11_joystick.c
This commit is contained in:
commit
85cfc6bdd0
|
@ -12,11 +12,15 @@ set(LIB_SUFFIX "" CACHE STRING "Takes an empty string or 64. Directory where lib
|
|||
|
||||
option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ON)
|
||||
option(GLFW_BUILD_TESTS "Build the GLFW test programs" ON)
|
||||
option(GLFW_NATIVE_API "Build the GLFW native API" OFF)
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
|
||||
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
||||
set(CMAKE_THREAD_PREFER_PTHREADS YES)
|
||||
if (NOT WIN32)
|
||||
set(CMAKE_THREAD_PREFER_PTHREADS YES)
|
||||
endif()
|
||||
|
||||
find_package(Threads)
|
||||
if (CMAKE_THREAD_LIBS_INIT)
|
||||
list(APPEND glfw_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
@ -183,7 +187,7 @@ if (_GLFW_X11_GLX)
|
|||
endif()
|
||||
|
||||
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
set(_GLFW_USE_LINUX_JOYSTICKS 1)
|
||||
set(_GLFW_HAS_LINUX_JOYSTICKS 1)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
@ -259,7 +263,12 @@ configure_file(${GLFW_SOURCE_DIR}/src/config.h.in
|
|||
# The src directory's CMakeLists.txt file installs the library
|
||||
#--------------------------------------------------------------------
|
||||
install(DIRECTORY include/GL DESTINATION include
|
||||
FILES_MATCHING PATTERN glfw3.h PATTERN glfw3native.h)
|
||||
FILES_MATCHING PATTERN glfw3.h)
|
||||
|
||||
if (GLFW_NATIVE_API)
|
||||
install(DIRECTORY include/GL DESTINATION include
|
||||
FILES_MATCHING PATTERN glfw3native.h)
|
||||
endif()
|
||||
|
||||
install(FILES COPYING.txt readme.html
|
||||
DESTINATION share/doc/glfw-${GLFW_VERSION_FULL})
|
||||
|
|
|
@ -581,7 +581,7 @@ int main(int argc, char** argv)
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_WINDOW_RESIZABLE, GL_FALSE);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||
glfwWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
|
|
@ -399,18 +399,19 @@ extern "C" {
|
|||
#define GLFW_ACCUM_ALPHA_BITS 0x0002100A
|
||||
#define GLFW_AUX_BUFFERS 0x0002100B
|
||||
#define GLFW_STEREO 0x0002100C
|
||||
#define GLFW_WINDOW_RESIZABLE 0x0002100D
|
||||
#define GLFW_FSAA_SAMPLES 0x0002100E
|
||||
|
||||
/* The following constants are used with both glfwGetWindowParam
|
||||
* and glfwWindowHint
|
||||
*/
|
||||
#define GLFW_OPENGL_VERSION_MAJOR 0x0002100F
|
||||
#define GLFW_OPENGL_VERSION_MINOR 0x00021010
|
||||
#define GLFW_OPENGL_FORWARD_COMPAT 0x00021011
|
||||
#define GLFW_OPENGL_DEBUG_CONTEXT 0x00021012
|
||||
#define GLFW_OPENGL_PROFILE 0x00021013
|
||||
#define GLFW_OPENGL_ROBUSTNESS 0x00021014
|
||||
#define GLFW_OPENGL_VERSION_MAJOR 0x00022000
|
||||
#define GLFW_OPENGL_VERSION_MINOR 0x00022001
|
||||
#define GLFW_OPENGL_FORWARD_COMPAT 0x00022002
|
||||
#define GLFW_OPENGL_DEBUG_CONTEXT 0x00022003
|
||||
#define GLFW_OPENGL_PROFILE 0x00022004
|
||||
#define GLFW_OPENGL_ROBUSTNESS 0x00022005
|
||||
#define GLFW_RESIZABLE 0x00022006
|
||||
#define GLFW_VISIBLE 0x00022007
|
||||
|
||||
/* GLFW_OPENGL_ROBUSTNESS mode tokens */
|
||||
#define GLFW_OPENGL_NO_ROBUSTNESS 0x00000000
|
||||
|
@ -534,6 +535,8 @@ GLFWAPI void glfwGetWindowPos(GLFWwindow window, int* xpos, int* ypos);
|
|||
GLFWAPI void glfwSetWindowPos(GLFWwindow window, int xpos, int ypos);
|
||||
GLFWAPI void glfwIconifyWindow(GLFWwindow window);
|
||||
GLFWAPI void glfwRestoreWindow(GLFWwindow window);
|
||||
GLFWAPI void glfwShowWindow(GLFWwindow window);
|
||||
GLFWAPI void glfwHideWindow(GLFWwindow window);
|
||||
GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param);
|
||||
GLFWAPI void glfwSetWindowUserPointer(GLFWwindow window, void* pointer);
|
||||
GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow window);
|
||||
|
|
11
readme.html
11
readme.html
|
@ -283,6 +283,7 @@ version of GLFW.</p>
|
|||
<li>Added <code>GLFW_OPENGL_ROBUSTNESS</code> window hint and associated strategy tokens for <code>GL_ARB_robustness</code> support</li>
|
||||
<li>Added <code>GLFW_OPENGL_REVISION</code> window parameter to make up for removal of <code>glfwGetGLVersion</code></li>
|
||||
<li>Added <code>GLFW_INCLUDE_GL3</code> macro for telling the GLFW header to include <code>gl3.h</code> header instead of <code>gl.h</code></li>
|
||||
<li>Added <code>GLFW_VISIBLE</code> window hint and parameter for controlling and polling window visibility</li>
|
||||
<li>Added <code>windows</code> simple multi-window test program</li>
|
||||
<li>Added <code>sharing</code> simple OpenGL object sharing test program</li>
|
||||
<li>Added <code>modes</code> video mode enumeration and setting test program</li>
|
||||
|
@ -297,7 +298,7 @@ version of GLFW.</p>
|
|||
<li>Renamed <code>glfw.h</code> to <code>glfw3.h</code> to avoid conflicts with 2.x series</li>
|
||||
<li>Renamed <code>glfwOpenWindowHint</code> to <code>glfwWindowHint</code></li>
|
||||
<li>Renamed <code>GLFW_WINDOW</code> token to <code>GLFW_WINDOWED</code></li>
|
||||
<li>Renamed <code>GLFW_WINDOW_NO_RESIZE</code> to <code>GLFW_WINDOW_RESIZABLE</code></li>
|
||||
<li>Renamed <code>GLFW_WINDOW_NO_RESIZE</code> to <code>GLFW_RESIZABLE</code></li>
|
||||
<li>Renamed <code>GLFW_BUILD_DLL</code> to <code>_GLFW_BUILD_DLL</code></li>
|
||||
<li>Renamed <code>version</code> test to <code>glfwinfo</code></li>
|
||||
<li>Renamed <code>GLFW_NO_GLU</code> to <code>GLFW_INCLUDE_GLU</code> and made it disabled by default</li>
|
||||
|
@ -349,6 +350,7 @@ version of GLFW.</p>
|
|||
<li>[X11] Bugfix: Some window properties required by the ICCCM were not set</li>
|
||||
<li>[X11] Bugfix: Calling <code>glXCreateContextAttribsARB</code> with an unavailable OpenGL version caused the application to terminate with a <code>BadMatch</code> Xlib error</li>
|
||||
<li>[X11] Bugfix: A synchronization point necessary for jitter-free locked cursor mode was incorrectly removed</li>
|
||||
<li>[X11] Bugfix: The window size hints were not updated when calling <code>glfwSetWindowSize</code> on a non-resizable window</li>
|
||||
<li>[Win32] Changed port to use Unicode mode only</li>
|
||||
<li>[Win32] Removed explicit support for versions of Windows older than Windows XP</li>
|
||||
<li>[Win32] Bugfix: Window activation and iconification did not work as expected</li>
|
||||
|
@ -924,11 +926,14 @@ their skills. Special thanks go out to:</p>
|
|||
Much of the Windows code of GLFW was originally based on Jeff's
|
||||
code</li>
|
||||
|
||||
<li>Julian Møller, for reporting a bug in the Cocoa joystick code</li>
|
||||
|
||||
<li>Arturo J. Pérez, for a bug fix for cursor tracking on Mac OS X 10.6 Snow
|
||||
Leopard</li>
|
||||
|
||||
<li>Riku Salminen, for making the X11 event processing able to support
|
||||
multi-threaded rendering</li>
|
||||
<li>Riku Salminen, for the initial implementation of
|
||||
<code>glfwShowWindow</code> and <code>glfwHideWindow</code>, and for making
|
||||
the X11 event processing able to support multi-threaded rendering</li>
|
||||
|
||||
<li>Douglas C. Schmidt and Irfan Pyarali, for their excellent article
|
||||
<a href="http://www.cs.wustl.edu/~schmidt/win32-cv-1.html">Strategies for Implementing POSIX Condition Variables on Win32</a></li>
|
||||
|
|
|
@ -10,7 +10,11 @@ if (_GLFW_COCOA_NSGL)
|
|||
set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h)
|
||||
set(glfw_SOURCES ${common_SOURCES} cocoa_clipboard.m cocoa_fullscreen.m
|
||||
cocoa_gamma.c cocoa_init.m cocoa_input.m cocoa_joystick.m
|
||||
cocoa_native.m cocoa_opengl.m cocoa_time.c cocoa_window.m)
|
||||
cocoa_opengl.m cocoa_time.c cocoa_window.m)
|
||||
|
||||
if (GLFW_NATIVE_API)
|
||||
list(APPEND glfw_SOURCES cocoa_native.m)
|
||||
endif()
|
||||
|
||||
# For some reason, CMake doesn't know about .m
|
||||
set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C)
|
||||
|
@ -18,14 +22,20 @@ elseif (_GLFW_WIN32_WGL)
|
|||
set(glfw_HEADERS ${common_HEADERS} win32_platform.h)
|
||||
set(glfw_SOURCES ${common_SOURCES} win32_clipboard.c win32_fullscreen.c
|
||||
win32_gamma.c win32_init.c win32_input.c win32_joystick.c
|
||||
win32_native.c win32_opengl.c win32_time.c win32_window.c
|
||||
win32_dllmain.c)
|
||||
win32_opengl.c win32_time.c win32_window.c)
|
||||
|
||||
if (GLFW_NATIVE_API)
|
||||
list(APPEND glfw_SOURCES win32_native.c)
|
||||
endif()
|
||||
elseif (_GLFW_X11_GLX)
|
||||
set(glfw_HEADERS ${common_HEADERS} x11_platform.h)
|
||||
set(glfw_SOURCES ${common_SOURCES} x11_clipboard.c x11_fullscreen.c
|
||||
x11_gamma.c x11_init.c x11_input.c x11_joystick.c
|
||||
x11_keysym2unicode.c x11_native.c x11_opengl.c x11_time.c
|
||||
x11_window.c)
|
||||
x11_keysym2unicode.c x11_opengl.c x11_time.c x11_window.c)
|
||||
|
||||
if (GLFW_NATIVE_API)
|
||||
list(APPEND glfw_SOURCES x11_native.c)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS})
|
||||
|
|
|
@ -550,15 +550,15 @@ int _glfwPlatformGetJoystickAxes(int joy, float* axes, int numaxes)
|
|||
|
||||
for (i = 0; i < numaxes; i++)
|
||||
{
|
||||
_glfwJoystickElement* axes =
|
||||
_glfwJoystickElement* elements =
|
||||
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick.axes, i);
|
||||
|
||||
long readScale = axes->maxReport - axes->minReport;
|
||||
long readScale = elements->maxReport - elements->minReport;
|
||||
|
||||
if (readScale == 0)
|
||||
axes[i] = axes->value;
|
||||
axes[i] = elements->value;
|
||||
else
|
||||
axes[i] = (2.0f * (axes->value - axes->minReport) / readScale) - 1.0f;
|
||||
axes[i] = (2.0f * (elements->value - elements->minReport) / readScale) - 1.0f;
|
||||
|
||||
if (i & 1)
|
||||
axes[i] = -axes[i];
|
||||
|
|
|
@ -131,6 +131,25 @@
|
|||
return NSTerminateCancel;
|
||||
}
|
||||
|
||||
- (void)applicationDidHide:(NSNotification *)notification
|
||||
{
|
||||
_GLFWwindow* window;
|
||||
|
||||
for (window = _glfwLibrary.windowListHead; window; window = window->next)
|
||||
_glfwInputWindowVisibility(window, GL_FALSE);
|
||||
}
|
||||
|
||||
- (void)applicationDidUnhide:(NSNotification *)notification
|
||||
{
|
||||
_GLFWwindow* window;
|
||||
|
||||
for (window = _glfwLibrary.windowListHead; window; window = window->next)
|
||||
{
|
||||
if ([window->NS.object isVisible])
|
||||
_glfwInputWindowVisibility(window, GL_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
@ -898,7 +917,6 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
|||
if (!createContext(window, wndconfig, fbconfig))
|
||||
return GL_FALSE;
|
||||
|
||||
[window->NS.object makeKeyAndOrderFront:nil];
|
||||
[window->NSGL.context setView:[window->NS.object contentView]];
|
||||
|
||||
if (wndconfig->mode == GLFW_FULLSCREEN)
|
||||
|
@ -913,6 +931,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
|||
return GL_FALSE;
|
||||
}
|
||||
|
||||
_glfwPlatformShowWindow(window);
|
||||
[[window->NS.object contentView] enterFullScreenMode:[NSScreen mainScreen]
|
||||
withOptions:nil];
|
||||
}
|
||||
|
@ -1022,6 +1041,27 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
|||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Show window
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformShowWindow(_GLFWwindow* window)
|
||||
{
|
||||
[window->NS.object makeKeyAndOrderFront:nil];
|
||||
_glfwInputWindowVisibility(window, GL_TRUE);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Hide window
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformHideWindow(_GLFWwindow* window)
|
||||
{
|
||||
[window->NS.object orderOut:nil];
|
||||
_glfwInputWindowVisibility(window, GL_FALSE);
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
// Write back window parameters into GLFW window structure
|
||||
//========================================================================
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
#cmakedefine _GLFW_HAS_GLXGETPROCADDRESSEXT
|
||||
|
||||
// Define this to 1 if the Linux joystick API is available
|
||||
#cmakedefine _GLFW_USE_LINUX_JOYSTICKS
|
||||
#cmakedefine _GLFW_HAS_LINUX_JOYSTICKS
|
||||
|
||||
// The GLFW version as used by glfwGetVersionString
|
||||
#define _GLFW_VERSION_FULL "@GLFW_VERSION_FULL@"
|
||||
|
|
|
@ -32,10 +32,8 @@
|
|||
#include "internal.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#ifdef __APPLE__
|
||||
#include <sys/malloc.h>
|
||||
#else
|
||||
#include <malloc.h>
|
||||
#if defined(_MSC_VER)
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
|
15
src/gamma.c
15
src/gamma.c
|
@ -61,18 +61,15 @@ GLFWAPI void glfwSetGamma(float gamma)
|
|||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
float value = (float) i / ((float) (size - 1));
|
||||
float value;
|
||||
|
||||
// Apply gamma
|
||||
// Calculate intensity
|
||||
value = (float) i / (float) (size - 1);
|
||||
// Apply gamma curve
|
||||
value = (float) pow(value, 1.f / gamma) * 65535.f + 0.5f;
|
||||
// Clamp to value range
|
||||
value = (float) fmax(fmin(value, 65535.f), 0.f);
|
||||
|
||||
// Clamp values
|
||||
if (value < 0.f)
|
||||
value = 0.f;
|
||||
else if (value > 65535.f)
|
||||
value = 65535.f;
|
||||
|
||||
// Set the gamma ramp values
|
||||
ramp.red[i] = (unsigned short) value;
|
||||
ramp.green[i] = (unsigned short) value;
|
||||
ramp.blue[i] = (unsigned short) value;
|
||||
|
|
|
@ -98,6 +98,7 @@ struct _GLFWhints
|
|||
int auxBuffers;
|
||||
GLboolean stereo;
|
||||
GLboolean resizable;
|
||||
GLboolean visible;
|
||||
int samples;
|
||||
int glMajor;
|
||||
int glMinor;
|
||||
|
@ -120,6 +121,7 @@ struct _GLFWwndconfig
|
|||
const char* title;
|
||||
int refreshRate;
|
||||
GLboolean resizable;
|
||||
GLboolean visible;
|
||||
int glMajor;
|
||||
int glMinor;
|
||||
GLboolean glForward;
|
||||
|
@ -170,6 +172,7 @@ struct _GLFWwindow
|
|||
int positionX, positionY;
|
||||
int mode; // GLFW_WINDOW or GLFW_FULLSCREEN
|
||||
GLboolean resizable; // GL_TRUE if user may resize this window
|
||||
GLboolean visible; // GL_TRUE if this window is visible
|
||||
int refreshRate; // monitor refresh rate
|
||||
void* userPointer;
|
||||
|
||||
|
@ -288,6 +291,8 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height);
|
|||
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y);
|
||||
void _glfwPlatformIconifyWindow(_GLFWwindow* window);
|
||||
void _glfwPlatformRestoreWindow(_GLFWwindow* window);
|
||||
void _glfwPlatformShowWindow(_GLFWwindow* window);
|
||||
void _glfwPlatformHideWindow(_GLFWwindow* window);
|
||||
|
||||
// Event processing
|
||||
void _glfwPlatformPollEvents(void);
|
||||
|
@ -316,6 +321,7 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated);
|
|||
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y);
|
||||
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
|
||||
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified);
|
||||
void _glfwInputWindowVisibility(_GLFWwindow* window, int visible);
|
||||
void _glfwInputWindowDamage(_GLFWwindow* window);
|
||||
void _glfwInputWindowCloseRequest(_GLFWwindow* window);
|
||||
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
//========================================================================
|
||||
// GLFW - An OpenGL library
|
||||
// Platform: Win32
|
||||
// API version: 3.0
|
||||
// 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"
|
||||
|
||||
|
||||
#if defined(_GLFW_BUILD_DLL)
|
||||
|
||||
//========================================================================
|
||||
// GLFW DLL entry point
|
||||
//========================================================================
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
|
||||
{
|
||||
// NOTE: Some compilers complains about instance and x never being used -
|
||||
// never mind that (we don't want to use them)!
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif // _GLFW_BUILD_DLL
|
||||
|
|
@ -39,6 +39,18 @@
|
|||
#endif // __BORLANDC__
|
||||
|
||||
|
||||
//========================================================================
|
||||
// GLFW DLL entry point
|
||||
//========================================================================
|
||||
|
||||
#if defined(_GLFW_BUILD_DLL)
|
||||
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
#endif // _GLFW_BUILD_DLL
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Load necessary libraries (DLLs)
|
||||
//========================================================================
|
||||
|
|
|
@ -33,95 +33,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Enable/disable minimize/restore animations
|
||||
//========================================================================
|
||||
|
||||
static int setMinMaxAnimations(int enable)
|
||||
{
|
||||
ANIMATIONINFO AI;
|
||||
int old_enable;
|
||||
|
||||
// Get old animation setting
|
||||
AI.cbSize = sizeof(ANIMATIONINFO);
|
||||
SystemParametersInfo(SPI_GETANIMATION, AI.cbSize, &AI, 0);
|
||||
old_enable = AI.iMinAnimate;
|
||||
|
||||
// If requested, change setting
|
||||
if (old_enable != enable)
|
||||
{
|
||||
AI.iMinAnimate = enable;
|
||||
SystemParametersInfo(SPI_SETANIMATION, AI.cbSize, &AI,
|
||||
SPIF_SENDCHANGE);
|
||||
}
|
||||
|
||||
return old_enable;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Focus the window and bring it to the top of the stack
|
||||
// Due to some nastiness with how XP handles SetForegroundWindow we have
|
||||
// to go through some really bizarre measures to achieve this
|
||||
//========================================================================
|
||||
|
||||
static void setForegroundWindow(HWND hWnd)
|
||||
{
|
||||
int try_count = 0;
|
||||
int old_animate;
|
||||
|
||||
// Try the standard approach first...
|
||||
BringWindowToTop(hWnd);
|
||||
SetForegroundWindow(hWnd);
|
||||
|
||||
// If it worked, return now
|
||||
if (hWnd == GetForegroundWindow())
|
||||
{
|
||||
// Try to modify the system settings (since this is the foreground
|
||||
// process, we are allowed to do this)
|
||||
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0,
|
||||
SPIF_SENDCHANGE);
|
||||
return;
|
||||
}
|
||||
|
||||
// For other Windows versions than 95 & NT4.0, the standard approach
|
||||
// may not work, so if we failed we have to "trick" Windows into
|
||||
// making our window the foureground window: Iconify and restore
|
||||
// again. It is ugly, but it seems to work (we turn off those annoying
|
||||
// zoom animations to make it look a bit better at least).
|
||||
|
||||
// Turn off minimize/restore animations
|
||||
old_animate = setMinMaxAnimations(0);
|
||||
|
||||
// We try this a few times, just to be on the safe side of things...
|
||||
do
|
||||
{
|
||||
// Iconify & restore
|
||||
ShowWindow(hWnd, SW_HIDE);
|
||||
ShowWindow(hWnd, SW_SHOWMINIMIZED);
|
||||
ShowWindow(hWnd, SW_SHOWNORMAL);
|
||||
|
||||
// Try to get focus
|
||||
BringWindowToTop(hWnd);
|
||||
SetForegroundWindow(hWnd);
|
||||
|
||||
// We do not want to keep going on forever, so we keep track of
|
||||
// how many times we tried
|
||||
try_count++;
|
||||
}
|
||||
while (hWnd != GetForegroundWindow() && try_count <= 3);
|
||||
|
||||
// Restore the system minimize/restore animation setting
|
||||
setMinMaxAnimations(old_animate);
|
||||
|
||||
// Try to modify the system settings (since this is now hopefully the
|
||||
// foreground process, we are probably allowed to do this)
|
||||
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0,
|
||||
SPIF_SENDCHANGE);
|
||||
}
|
||||
|
||||
#include <windowsx.h>
|
||||
|
||||
//========================================================================
|
||||
// Hide mouse cursor
|
||||
|
@ -393,37 +305,6 @@ static int translateKey(WPARAM wParam, LPARAM lParam)
|
|||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Translates a Windows key to Unicode
|
||||
//========================================================================
|
||||
|
||||
static void translateChar(_GLFWwindow* window, DWORD wParam, DWORD lParam)
|
||||
{
|
||||
BYTE keyboard_state[256];
|
||||
WCHAR unicode_buf[10];
|
||||
UINT scan_code;
|
||||
int i, num_chars;
|
||||
|
||||
GetKeyboardState(keyboard_state);
|
||||
|
||||
// Derive scan code from lParam and action
|
||||
scan_code = (lParam & 0x01ff0000) >> 16;
|
||||
|
||||
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
|
||||
);
|
||||
|
||||
// Report characters
|
||||
for (i = 0; i < num_chars; i++)
|
||||
_glfwInputChar(window, (int) unicode_buf[i]);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Window callback function (handles window events)
|
||||
//========================================================================
|
||||
|
@ -507,6 +388,12 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||
return 0;
|
||||
}
|
||||
|
||||
case WM_SHOWWINDOW:
|
||||
{
|
||||
_glfwInputWindowVisibility(window, wParam ? GL_TRUE : GL_FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_SYSCOMMAND:
|
||||
{
|
||||
switch (wParam & 0xfff0)
|
||||
|
@ -541,13 +428,15 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||
case WM_SYSKEYDOWN:
|
||||
{
|
||||
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_PRESS);
|
||||
|
||||
if (_glfwLibrary.charCallback)
|
||||
translateChar(window, (DWORD) wParam, (DWORD) lParam);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_CHAR:
|
||||
{
|
||||
_glfwInputChar(window, wParam);
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_KEYUP:
|
||||
case WM_SYSKEYUP:
|
||||
{
|
||||
|
@ -642,8 +531,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||
int newCursorX, newCursorY;
|
||||
|
||||
// Get signed (!) cursor position
|
||||
newCursorX = (int)((short)LOWORD(lParam));
|
||||
newCursorY = (int)((short)HIWORD(lParam));
|
||||
newCursorX = GET_X_LPARAM(lParam);
|
||||
newCursorY = GET_Y_LPARAM(lParam);
|
||||
|
||||
if (newCursorX != window->Win32.oldCursorX ||
|
||||
newCursorY != window->Win32.oldCursorY)
|
||||
|
@ -836,7 +725,7 @@ static int createWindow(_GLFWwindow* window,
|
|||
WCHAR* wideTitle;
|
||||
|
||||
// Set common window styles
|
||||
dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
|
||||
dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
|
||||
dwExStyle = WS_EX_APPWINDOW;
|
||||
|
||||
// Set window style, depending on fullscreen mode
|
||||
|
@ -1067,13 +956,11 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
|||
if (window->mode == GLFW_FULLSCREEN)
|
||||
{
|
||||
// Place the window above all topmost windows
|
||||
_glfwPlatformShowWindow(window);
|
||||
SetWindowPos(window->Win32.handle, HWND_TOPMOST, 0,0,0,0,
|
||||
SWP_NOMOVE | SWP_NOSIZE);
|
||||
}
|
||||
|
||||
setForegroundWindow(window->Win32.handle);
|
||||
SetFocus(window->Win32.handle);
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
@ -1193,6 +1080,29 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
|||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Show or hide window
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformShowWindow(_GLFWwindow* window)
|
||||
{
|
||||
ShowWindow(window->Win32.handle, SW_SHOWNORMAL);
|
||||
BringWindowToTop(window->Win32.handle);
|
||||
SetForegroundWindow(window->Win32.handle);
|
||||
SetFocus(window->Win32.handle);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Show or hide window
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformHideWindow(_GLFWwindow* window)
|
||||
{
|
||||
ShowWindow(window->Win32.handle, SW_HIDE);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Write back window parameters into GLFW window structure
|
||||
//========================================================================
|
||||
|
@ -1239,28 +1149,22 @@ void _glfwPlatformPollEvents(void)
|
|||
|
||||
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||
{
|
||||
switch (msg.message)
|
||||
if (msg.message == WM_QUIT)
|
||||
{
|
||||
case WM_QUIT:
|
||||
// Treat WM_QUIT as a close on all windows
|
||||
|
||||
window = _glfwLibrary.windowListHead;
|
||||
while (window)
|
||||
{
|
||||
// Treat WM_QUIT as a close on all windows
|
||||
|
||||
window = _glfwLibrary.windowListHead;
|
||||
while (window)
|
||||
{
|
||||
_glfwInputWindowCloseRequest(window);
|
||||
window = window->next;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
DispatchMessage(&msg);
|
||||
break;
|
||||
_glfwInputWindowCloseRequest(window);
|
||||
window = window->next;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
// LSHIFT/RSHIFT fixup (keys tend to "stick" without this fix)
|
||||
|
|
87
src/window.c
87
src/window.c
|
@ -33,10 +33,8 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef __APPLE__
|
||||
#include <sys/malloc.h>
|
||||
#else
|
||||
#include <malloc.h>
|
||||
#if defined(_MSC_VER)
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -82,8 +80,9 @@ void _glfwSetDefaultWindowHints(void)
|
|||
_glfwLibrary.hints.glMajor = 1;
|
||||
_glfwLibrary.hints.glMinor = 0;
|
||||
|
||||
// The default is to allow window resizing
|
||||
// The default is to show the window and allow window resizing
|
||||
_glfwLibrary.hints.resizable = GL_TRUE;
|
||||
_glfwLibrary.hints.visible = GL_TRUE;
|
||||
|
||||
// The default is 24 bits of depth, 8 bits of color
|
||||
_glfwLibrary.hints.depthBits = 24;
|
||||
|
@ -182,6 +181,16 @@ void _glfwInputWindowIconify(_GLFWwindow* window, int iconified)
|
|||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Register window visibility events
|
||||
//========================================================================
|
||||
|
||||
void _glfwInputWindowVisibility(_GLFWwindow* window, int visible)
|
||||
{
|
||||
window->visible = visible;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Register window damage events
|
||||
//========================================================================
|
||||
|
@ -252,6 +261,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
|
|||
wndconfig.title = title;
|
||||
wndconfig.refreshRate = Max(_glfwLibrary.hints.refreshRate, 0);
|
||||
wndconfig.resizable = _glfwLibrary.hints.resizable ? GL_TRUE : GL_FALSE;
|
||||
wndconfig.visible = _glfwLibrary.hints.visible ? GL_TRUE : GL_FALSE;
|
||||
wndconfig.glMajor = _glfwLibrary.hints.glMajor;
|
||||
wndconfig.glMinor = _glfwLibrary.hints.glMinor;
|
||||
wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE;
|
||||
|
@ -326,8 +336,9 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
|
|||
// Cache the actual (as opposed to requested) window parameters
|
||||
_glfwPlatformRefreshWindowParams(window);
|
||||
|
||||
// Cache the actual (as opposed to requested) context parameters
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
// Cache the actual (as opposed to requested) context parameters
|
||||
if (!_glfwRefreshContextParams())
|
||||
{
|
||||
glfwDestroyWindow(window);
|
||||
|
@ -343,6 +354,11 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
|
|||
return GL_FALSE;
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// Restore the previously current context (or NULL)
|
||||
glfwMakeContextCurrent(previous);
|
||||
|
||||
|
@ -351,10 +367,8 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
|
|||
if (mode == GLFW_FULLSCREEN)
|
||||
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED);
|
||||
|
||||
// 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);
|
||||
if (mode == GLFW_WINDOWED && wndconfig.visible)
|
||||
glfwShowWindow(window);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
@ -413,9 +427,12 @@ GLFWAPI void glfwWindowHint(int target, int hint)
|
|||
case GLFW_STEREO:
|
||||
_glfwLibrary.hints.stereo = hint;
|
||||
break;
|
||||
case GLFW_WINDOW_RESIZABLE:
|
||||
case GLFW_RESIZABLE:
|
||||
_glfwLibrary.hints.resizable = hint;
|
||||
break;
|
||||
case GLFW_VISIBLE:
|
||||
_glfwLibrary.hints.visible = hint;
|
||||
break;
|
||||
case GLFW_FSAA_SAMPLES:
|
||||
_glfwLibrary.hints.samples = hint;
|
||||
break;
|
||||
|
@ -653,6 +670,48 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow handle)
|
|||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Window show
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwShowWindow(GLFWwindow handle)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (window->mode == GLFW_FULLSCREEN)
|
||||
return;
|
||||
|
||||
_glfwPlatformShowWindow(window);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Window hide
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwHideWindow(GLFWwindow handle)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (window->mode == GLFW_FULLSCREEN)
|
||||
return;
|
||||
|
||||
_glfwPlatformHideWindow(window);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Get window parameter
|
||||
//========================================================================
|
||||
|
@ -677,8 +736,10 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param)
|
|||
return window->closeRequested;
|
||||
case GLFW_REFRESH_RATE:
|
||||
return window->refreshRate;
|
||||
case GLFW_WINDOW_RESIZABLE:
|
||||
case GLFW_RESIZABLE:
|
||||
return window->resizable;
|
||||
case GLFW_VISIBLE:
|
||||
return window->visible;
|
||||
case GLFW_OPENGL_VERSION_MAJOR:
|
||||
return window->glMajor;
|
||||
case GLFW_OPENGL_VERSION_MINOR:
|
||||
|
@ -817,7 +878,7 @@ GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindowiconifyfun cbfun)
|
|||
|
||||
|
||||
//========================================================================
|
||||
// Poll for new window and input events and close any flagged windows
|
||||
// Poll for new window and input events
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwPollEvents(void)
|
||||
|
|
|
@ -648,7 +648,8 @@ int _glfwPlatformInit(void)
|
|||
|
||||
_glfwLibrary.X11.cursor = createNULLCursor();
|
||||
|
||||
_glfwInitJoysticks();
|
||||
if (!_glfwInitJoysticks())
|
||||
return GL_FALSE;
|
||||
|
||||
// Start the timer
|
||||
_glfwInitTimer();
|
||||
|
@ -671,12 +672,12 @@ int _glfwPlatformTerminate(void)
|
|||
|
||||
_glfwTerminateGammaRamp();
|
||||
|
||||
terminateDisplay();
|
||||
|
||||
_glfwTerminateJoysticks();
|
||||
|
||||
_glfwTerminateOpenGL();
|
||||
|
||||
terminateDisplay();
|
||||
|
||||
// Free clipboard memory
|
||||
if (_glfwLibrary.X11.selection.string)
|
||||
free(_glfwLibrary.X11.selection.string);
|
||||
|
@ -718,7 +719,7 @@ const char* _glfwPlatformGetVersionString(void)
|
|||
#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
|
||||
" clock_gettime"
|
||||
#endif
|
||||
#if defined(_GLFW_USE_LINUX_JOYSTICKS)
|
||||
#if defined(_GLFW_HAS_LINUX_JOYSTICKS)
|
||||
" Linux-joystick-API"
|
||||
#else
|
||||
" no-joystick-support"
|
||||
|
|
|
@ -30,18 +30,19 @@
|
|||
|
||||
#include "internal.h"
|
||||
|
||||
#ifdef _GLFW_USE_LINUX_JOYSTICKS
|
||||
#ifdef _GLFW_HAS_LINUX_JOYSTICKS
|
||||
#include <linux/joystick.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <regex.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#endif // _GLFW_USE_LINUX_JOYSTICKS
|
||||
#endif // _GLFW_HAS_LINUX_JOYSTICKS
|
||||
|
||||
|
||||
//========================================================================
|
||||
|
@ -50,7 +51,7 @@
|
|||
|
||||
static int openJoystickDevice(int joy, const char* path)
|
||||
{
|
||||
#ifdef _GLFW_USE_LINUX_JOYSTICKS
|
||||
#ifdef _GLFW_HAS_LINUX_JOYSTICKS
|
||||
char numAxes, numButtons;
|
||||
char name[256];
|
||||
int fd, version;
|
||||
|
@ -103,7 +104,7 @@ static int openJoystickDevice(int joy, const char* path)
|
|||
}
|
||||
|
||||
_glfwLibrary.X11.joystick[joy].present = GL_TRUE;
|
||||
#endif // _GLFW_USE_LINUX_JOYSTICKS
|
||||
#endif // _GLFW_HAS_LINUX_JOYSTICKS
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
@ -115,7 +116,7 @@ static int openJoystickDevice(int joy, const char* path)
|
|||
|
||||
static void pollJoystickEvents(void)
|
||||
{
|
||||
#ifdef _GLFW_USE_LINUX_JOYSTICKS
|
||||
#ifdef _GLFW_HAS_LINUX_JOYSTICKS
|
||||
int i;
|
||||
ssize_t result;
|
||||
struct js_event e;
|
||||
|
@ -166,7 +167,7 @@ static void pollJoystickEvents(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif // _GLFW_USE_LINUX_JOYSTICKS
|
||||
#endif // _GLFW_HAS_LINUX_JOYSTICKS
|
||||
}
|
||||
|
||||
|
||||
|
@ -178,30 +179,52 @@ static void pollJoystickEvents(void)
|
|||
// Initialize joystick interface
|
||||
//========================================================================
|
||||
|
||||
void _glfwInitJoysticks(void)
|
||||
int _glfwInitJoysticks(void)
|
||||
{
|
||||
#ifdef _GLFW_USE_LINUX_JOYSTICKS
|
||||
int i, j, joy = 0;
|
||||
char path[20];
|
||||
const char* bases[] =
|
||||
#ifdef _GLFW_HAS_LINUX_JOYSTICKS
|
||||
int i, joy = 0;
|
||||
regex_t regex;
|
||||
DIR* dir;
|
||||
const char* dirs[] =
|
||||
{
|
||||
"/dev/input/js",
|
||||
"/dev/js"
|
||||
"/dev/input",
|
||||
"/dev"
|
||||
};
|
||||
|
||||
for (i = 0; i < sizeof(bases) / sizeof(bases[0]); i++)
|
||||
if (regcomp(®ex, "^js[0-9]\\+$", 0) != 0)
|
||||
{
|
||||
for (j = 0; j < 50; j++)
|
||||
{
|
||||
if (joy > GLFW_JOYSTICK_LAST)
|
||||
break;
|
||||
_glfwSetError(GLFW_PLATFORM_ERROR, "X11: Failed to compile regex");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
sprintf(path, "%s%i", bases[i], j);
|
||||
for (i = 0; i < sizeof(dirs) / sizeof(dirs[0]); i++)
|
||||
{
|
||||
struct dirent* entry;
|
||||
|
||||
dir = opendir(dirs[i]);
|
||||
if (!dir)
|
||||
continue;
|
||||
|
||||
while ((entry = readdir(dir)))
|
||||
{
|
||||
char path[20];
|
||||
regmatch_t match;
|
||||
|
||||
if (regexec(®ex, entry->d_name, 1, &match, 0) != 0)
|
||||
continue;
|
||||
|
||||
snprintf(path, sizeof(path), "%s/%s", dirs[i], entry->d_name);
|
||||
if (openJoystickDevice(joy, path))
|
||||
joy++;
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
}
|
||||
#endif // _GLFW_USE_LINUX_JOYSTICKS
|
||||
|
||||
regfree(®ex);
|
||||
#endif // _GLFW_HAS_LINUX_JOYSTICKS
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -211,7 +234,7 @@ void _glfwInitJoysticks(void)
|
|||
|
||||
void _glfwTerminateJoysticks(void)
|
||||
{
|
||||
#ifdef _GLFW_USE_LINUX_JOYSTICKS
|
||||
#ifdef _GLFW_HAS_LINUX_JOYSTICKS
|
||||
int i;
|
||||
|
||||
for (i = 0; i <= GLFW_JOYSTICK_LAST; i++)
|
||||
|
@ -226,7 +249,7 @@ void _glfwTerminateJoysticks(void)
|
|||
_glfwLibrary.X11.joystick[i].present = GL_FALSE;
|
||||
}
|
||||
}
|
||||
#endif // _GLFW_USE_LINUX_JOYSTICKS
|
||||
#endif // _GLFW_HAS_LINUX_JOYSTICKS
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -306,7 +306,7 @@ void _glfwSetVideoMode(int* width, int* height, int* rate);
|
|||
void _glfwRestoreVideoMode(void);
|
||||
|
||||
// Joystick input
|
||||
void _glfwInitJoysticks(void);
|
||||
int _glfwInitJoysticks(void);
|
||||
void _glfwTerminateJoysticks(void);
|
||||
|
||||
// Unicode support
|
||||
|
|
|
@ -228,10 +228,6 @@ static GLboolean createWindow(_GLFWwindow* window,
|
|||
|
||||
_glfwPlatformSetWindowTitle(window, wndconfig->title);
|
||||
|
||||
// Make sure the window is mapped before proceeding
|
||||
XMapWindow(_glfwLibrary.X11.display, window->X11.handle);
|
||||
XFlush(_glfwLibrary.X11.display);
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
@ -699,6 +695,7 @@ static void processEvent(XEvent *event)
|
|||
if (window == NULL)
|
||||
return;
|
||||
|
||||
_glfwInputWindowVisibility(window, GL_TRUE);
|
||||
_glfwInputWindowIconify(window, GL_FALSE);
|
||||
break;
|
||||
}
|
||||
|
@ -710,6 +707,7 @@ static void processEvent(XEvent *event)
|
|||
if (window == NULL)
|
||||
return;
|
||||
|
||||
_glfwInputWindowVisibility(window, GL_FALSE);
|
||||
_glfwInputWindowIconify(window, GL_TRUE);
|
||||
break;
|
||||
}
|
||||
|
@ -854,6 +852,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
|||
}
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
|
||||
_glfwPlatformShowWindow(window);
|
||||
enterFullscreenMode(window);
|
||||
}
|
||||
|
||||
|
@ -956,7 +955,6 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
|||
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
||||
{
|
||||
int mode = 0, rate, sizeChanged = GL_FALSE;
|
||||
XSizeHints* sizehints;
|
||||
|
||||
rate = window->refreshRate;
|
||||
|
||||
|
@ -970,14 +968,14 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
|||
{
|
||||
// Update window size restrictions to match new window size
|
||||
|
||||
sizehints = XAllocSizeHints();
|
||||
sizehints->flags = 0;
|
||||
XSizeHints* hints = XAllocSizeHints();
|
||||
|
||||
sizehints->min_width = sizehints->max_width = width;
|
||||
sizehints->min_height = sizehints->max_height = height;
|
||||
hints->flags |= (PMinSize | PMaxSize);
|
||||
hints->min_width = hints->max_width = width;
|
||||
hints->min_height = hints->max_height = height;
|
||||
|
||||
XSetWMNormalHints(_glfwLibrary.X11.display, window->X11.handle, sizehints);
|
||||
XFree(sizehints);
|
||||
XSetWMNormalHints(_glfwLibrary.X11.display, window->X11.handle, hints);
|
||||
XFree(hints);
|
||||
}
|
||||
|
||||
// Change window size before changing fullscreen mode?
|
||||
|
@ -1045,6 +1043,28 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
|||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Show window
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformShowWindow(_GLFWwindow* window)
|
||||
{
|
||||
XMapRaised(_glfwLibrary.X11.display, window->X11.handle);
|
||||
XFlush(_glfwLibrary.X11.display);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Hide window
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformHideWindow(_GLFWwindow* window)
|
||||
{
|
||||
XUnmapWindow(_glfwLibrary.X11.display, window->X11.handle);
|
||||
XFlush(_glfwLibrary.X11.display);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Read back framebuffer parameters from the context
|
||||
//========================================================================
|
||||
|
|
|
@ -21,13 +21,6 @@ freely, subject to the following restrictions:
|
|||
distribution.
|
||||
*/
|
||||
|
||||
/* Activate some POSIX functionality (e.g. recursive mutexes) */
|
||||
#define _GNU_SOURCE
|
||||
#if !defined(_XOPEN_SOURCE) || (_XOPEN_SOURCE < 500)
|
||||
#undef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 500
|
||||
#endif
|
||||
|
||||
#include "tinycthread.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -99,9 +92,11 @@ int mtx_lock(mtx_t *mtx)
|
|||
#endif
|
||||
}
|
||||
|
||||
int mtx_timedlock(mtx_t *mtx, const xtime *xt)
|
||||
int mtx_timedlock(mtx_t *mtx, const struct timespec *ts)
|
||||
{
|
||||
/* FIXME! */
|
||||
(void)mtx;
|
||||
(void)ts;
|
||||
return thrd_error;
|
||||
}
|
||||
|
||||
|
@ -290,21 +285,21 @@ int cnd_wait(cnd_t *cond, mtx_t *mtx)
|
|||
#endif
|
||||
}
|
||||
|
||||
int cnd_timedwait(cnd_t *cond, mtx_t *mtx, const xtime *xt)
|
||||
int cnd_timedwait(cnd_t *cond, mtx_t *mtx, const struct timespec *ts)
|
||||
{
|
||||
#if defined(_TTHREAD_WIN32_)
|
||||
xtime now;
|
||||
DWORD delta;
|
||||
xtime_get(&now, TIME_UTC);
|
||||
delta = (xt->sec - now.sec) * 1000 +
|
||||
(xt->nsec - now.nsec + 500000) / 1000000;
|
||||
return _cnd_timedwait_win32(cond, mtx, delta);
|
||||
struct timespec now;
|
||||
if (clock_gettime(TIME_UTC, &now) == 0)
|
||||
{
|
||||
DWORD delta = (ts->tv_sec - now.tv_sec) * 1000 +
|
||||
(ts->tv_nsec - now.tv_nsec + 500000) / 1000000;
|
||||
return _cnd_timedwait_win32(cond, mtx, delta);
|
||||
}
|
||||
else
|
||||
return thrd_error;
|
||||
#else
|
||||
struct timespec ts;
|
||||
int ret;
|
||||
ts.tv_sec = xt->sec;
|
||||
ts.tv_nsec = xt->nsec;
|
||||
ret = pthread_cond_timedwait(cond, mtx, &ts);
|
||||
ret = pthread_cond_timedwait(cond, mtx, ts);
|
||||
if (ret == ETIMEDOUT)
|
||||
{
|
||||
return thrd_timeout;
|
||||
|
@ -322,9 +317,9 @@ typedef struct {
|
|||
|
||||
/* Thread wrapper function. */
|
||||
#if defined(_TTHREAD_WIN32_)
|
||||
unsigned WINAPI _thrd_wrapper_function(void * aArg)
|
||||
static unsigned WINAPI _thrd_wrapper_function(void * aArg)
|
||||
#elif defined(_TTHREAD_POSIX_)
|
||||
void * _thrd_wrapper_function(void * aArg)
|
||||
static void * _thrd_wrapper_function(void * aArg)
|
||||
#endif
|
||||
{
|
||||
thrd_start_t fun;
|
||||
|
@ -401,6 +396,7 @@ thrd_t thrd_current(void)
|
|||
int thrd_detach(thrd_t thr)
|
||||
{
|
||||
/* FIXME! */
|
||||
(void)thr;
|
||||
return thrd_error;
|
||||
}
|
||||
|
||||
|
@ -460,9 +456,9 @@ int thrd_join(thrd_t thr, int *res)
|
|||
return thrd_success;
|
||||
}
|
||||
|
||||
void thrd_sleep(const xtime *xt)
|
||||
int thrd_sleep(const struct timespec *time_point, struct timespec *remaining)
|
||||
{
|
||||
xtime now;
|
||||
struct timespec now;
|
||||
#if defined(_TTHREAD_WIN32_)
|
||||
DWORD delta;
|
||||
#else
|
||||
|
@ -470,20 +466,21 @@ void thrd_sleep(const xtime *xt)
|
|||
#endif
|
||||
|
||||
/* Get the current time */
|
||||
xtime_get(&now, TIME_UTC);
|
||||
if (clock_gettime(TIME_UTC, &now) != 0)
|
||||
return -2; // FIXME: Some specific error code?
|
||||
|
||||
#if defined(_TTHREAD_WIN32_)
|
||||
/* Delta in milliseconds */
|
||||
delta = (xt->sec - now.sec) * 1000 +
|
||||
(xt->nsec - now.nsec + 500000) / 1000000;
|
||||
delta = (time_point->tv_sec - now.tv_sec) * 1000 +
|
||||
(time_point->tv_nsec - now.tv_nsec + 500000) / 1000000;
|
||||
if (delta > 0)
|
||||
{
|
||||
Sleep(delta);
|
||||
}
|
||||
#else
|
||||
/* Delta in microseconds */
|
||||
delta = (xt->sec - now.sec) * 1000000L +
|
||||
(xt->nsec - now.nsec + 500L) / 1000L;
|
||||
delta = (time_point->tv_sec - now.tv_sec) * 1000000L +
|
||||
(time_point->tv_nsec - now.tv_nsec + 500L) / 1000L;
|
||||
|
||||
/* On some systems, the usleep argument must be < 1000000 */
|
||||
while (delta > 999999L)
|
||||
|
@ -496,6 +493,14 @@ void thrd_sleep(const xtime *xt)
|
|||
usleep((useconds_t)delta);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* We don't support waking up prematurely (yet) */
|
||||
if (remaining)
|
||||
{
|
||||
remaining->tv_sec = 0;
|
||||
remaining->tv_nsec = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void thrd_yield(void)
|
||||
|
@ -563,26 +568,21 @@ int tss_set(tss_t key, void *val)
|
|||
return thrd_success;
|
||||
}
|
||||
|
||||
int xtime_get(xtime *xt, int base)
|
||||
#if defined(_TTHREAD_EMULATE_CLOCK_GETTIME_)
|
||||
int _tthread_clock_gettime(clockid_t clk_id, struct timespec *ts)
|
||||
{
|
||||
if (base == TIME_UTC)
|
||||
{
|
||||
#if defined(_TTHREAD_WIN32_)
|
||||
struct _timeb tb;
|
||||
_ftime(&tb);
|
||||
xt->sec = (time_t)tb.time;
|
||||
xt->nsec = 1000000 * (long)tb.millitm;
|
||||
struct _timeb tb;
|
||||
_ftime(&tb);
|
||||
ts->tv_sec = (time_t)tb.time;
|
||||
ts->tv_nsec = 1000000L * (long)tb.millitm;
|
||||
#else
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
xt->sec = (time_t)tv.tv_sec;
|
||||
xt->nsec = 1000 * (long)tv.tv_usec;
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
ts->tv_sec = (time_t)tv.tv_sec;
|
||||
ts->tv_nsec = 1000L * (long)tv.tv_usec;
|
||||
#endif
|
||||
return base;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif // _TTHREAD_EMULATE_CLOCK_GETTIME_
|
||||
|
||||
|
|
|
@ -57,6 +57,22 @@ freely, subject to the following restrictions:
|
|||
#define _TTHREAD_PLATFORM_DEFINED_
|
||||
#endif
|
||||
|
||||
/* Activate some POSIX functionality (e.g. clock_gettime and recursive mutexes) */
|
||||
#if defined(_TTHREAD_POSIX_)
|
||||
#undef _FEATURES_H
|
||||
#if !defined(_GNU_SOURCE)
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#if !defined(_POSIX_C_SOURCE) || ((_POSIX_C_SOURCE - 0) < 199309L)
|
||||
#undef _POSIX_C_SOURCE
|
||||
#define _POSIX_C_SOURCE 199309L
|
||||
#endif
|
||||
#if !defined(_XOPEN_SOURCE) || ((_XOPEN_SOURCE - 0) < 500)
|
||||
#undef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 500
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Generic includes */
|
||||
#include <time.h>
|
||||
|
||||
|
@ -75,10 +91,44 @@ freely, subject to the following restrictions:
|
|||
#endif
|
||||
#endif
|
||||
|
||||
/* Workaround for missing TIME_UTC: If time.h doesn't provide TIME_UTC,
|
||||
it's quite likely that libc does not support it either. Hence, fall back to
|
||||
the only other supported time specifier: CLOCK_REALTIME (and if that fails,
|
||||
we're probably emulating clock_gettime anyway, so anything goes). */
|
||||
#ifndef TIME_UTC
|
||||
#ifdef CLOCK_REALTIME
|
||||
#define TIME_UTC CLOCK_REALTIME
|
||||
#else
|
||||
#define TIME_UTC 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Workaround for missing clock_gettime (most Windows compilers, afaik) */
|
||||
#if defined(_TTHREAD_WIN32_) || defined(__APPLE_CC__)
|
||||
#define _TTHREAD_EMULATE_CLOCK_GETTIME_
|
||||
/* Emulate struct timespec */
|
||||
#if defined(_TTHREAD_WIN32_)
|
||||
struct _ttherad_timespec {
|
||||
time_t tv_sec;
|
||||
long tv_nsec;
|
||||
};
|
||||
#define timespec _ttherad_timespec
|
||||
#endif
|
||||
|
||||
/* Emulate clockid_t */
|
||||
typedef int _tthread_clockid_t;
|
||||
#define clockid_t _tthread_clockid_t
|
||||
|
||||
/* Emulate clock_gettime */
|
||||
int _tthread_clock_gettime(clockid_t clk_id, struct timespec *ts);
|
||||
#define clock_gettime _tthread_clock_gettime
|
||||
#endif
|
||||
|
||||
|
||||
/** TinyCThread version (major number). */
|
||||
#define TINYCTHREAD_VERSION_MAJOR 1
|
||||
/** TinyCThread version (minor number). */
|
||||
#define TINYCTHREAD_VERSION_MINOR 0
|
||||
#define TINYCTHREAD_VERSION_MINOR 1
|
||||
/** TinyCThread version (full version). */
|
||||
#define TINYCTHREAD_VERSION (TINYCTHREAD_VERSION_MAJOR * 100 + TINYCTHREAD_VERSION_MINOR)
|
||||
|
||||
|
@ -101,7 +151,7 @@ freely, subject to the following restrictions:
|
|||
* @hideinitializer
|
||||
*/
|
||||
|
||||
/* FIXME: Check for a PROPER value of __STDC_VERSION__ to know if we have C11 or */
|
||||
/* FIXME: Check for a PROPER value of __STDC_VERSION__ to know if we have C11 */
|
||||
#if !(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201102L)) && !defined(_Thread_local)
|
||||
#if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_CC) || defined(__IBMCPP__)
|
||||
#define _Thread_local __thread
|
||||
|
@ -126,12 +176,6 @@ freely, subject to the following restrictions:
|
|||
#define mtx_try 4
|
||||
#define mtx_recursive 8
|
||||
|
||||
/** Time specification */
|
||||
typedef struct {
|
||||
time_t sec; /**< Seconds */
|
||||
long nsec; /**< Nanoseconds */
|
||||
} xtime;
|
||||
|
||||
/* Mutex */
|
||||
#if defined(_TTHREAD_WIN32_)
|
||||
typedef struct {
|
||||
|
@ -174,7 +218,7 @@ int mtx_lock(mtx_t *mtx);
|
|||
|
||||
/** NOT YET IMPLEMENTED.
|
||||
*/
|
||||
int mtx_timedlock(mtx_t *mtx, const xtime *xt);
|
||||
int mtx_timedlock(mtx_t *mtx, const struct timespec *ts);
|
||||
|
||||
/** Try to lock the given mutex.
|
||||
* The specified mutex shall support either test and return or timeout. If the
|
||||
|
@ -260,7 +304,7 @@ int cnd_wait(cnd_t *cond, mtx_t *mtx);
|
|||
* specified in the call was reached without acquiring the requested resource, or
|
||||
* @ref thrd_error if the request could not be honored.
|
||||
*/
|
||||
int cnd_timedwait(cnd_t *cond, mtx_t *mtx, const xtime *xt);
|
||||
int cnd_timedwait(cnd_t *cond, mtx_t *mtx, const struct timespec *ts);
|
||||
|
||||
/* Thread */
|
||||
#if defined(_TTHREAD_WIN32_)
|
||||
|
@ -326,11 +370,16 @@ void thrd_exit(int res);
|
|||
int thrd_join(thrd_t thr, int *res);
|
||||
|
||||
/** Put the calling thread to sleep.
|
||||
* Suspend execution of the calling thread until after the time specified by the
|
||||
* xtime object.
|
||||
* @param xt A point in time at which the thread will resume (absolute time).
|
||||
* Suspend execution of the calling thread.
|
||||
* @param time_point A point in time at which the thread will resume (absolute time).
|
||||
* @param remaining If non-NULL, this parameter will hold the remaining time until
|
||||
* time_point upon return. This will typically be zero, but if
|
||||
* the thread was woken up by a signal that is not ignored before
|
||||
* time_point was reached @c remaining will hold a positive
|
||||
* time.
|
||||
* @return 0 (zero) on successful sleep, or -1 if an interrupt occurred.
|
||||
*/
|
||||
void thrd_sleep(const xtime *xt);
|
||||
int thrd_sleep(const struct timespec *time_point, struct timespec *remaining);
|
||||
|
||||
/** Yield execution to another thread.
|
||||
* Permit other threads to run, even if the current thread would ordinarily
|
||||
|
@ -385,20 +434,6 @@ void *tss_get(tss_t key);
|
|||
*/
|
||||
int tss_set(tss_t key, void *val);
|
||||
|
||||
/* Timing */
|
||||
enum
|
||||
{
|
||||
TIME_UTC = 1
|
||||
};
|
||||
|
||||
/** Get the current time.
|
||||
* Set the xtime object to hold the current time based on the given time base.
|
||||
* @param xt Will be filled out with the current time.
|
||||
* @param base Time base (must be @c TIME_UTC).
|
||||
* @return The non-zero value @c base if the function is successful, otherwise
|
||||
* it returns zero.
|
||||
*/
|
||||
int xtime_get(xtime *xt, int base);
|
||||
|
||||
#endif /* _TINYTHREAD_H_ */
|
||||
|
||||
|
|
|
@ -8,6 +8,11 @@ else()
|
|||
link_libraries(${glfw_LIBRARIES})
|
||||
endif()
|
||||
|
||||
list(APPEND thread_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
|
||||
if (UNIX AND NOT APPLE)
|
||||
list(APPEND thread_LIBRARIES ${RT_LIBRARY})
|
||||
endif()
|
||||
|
||||
include_directories(${GLFW_SOURCE_DIR}/include
|
||||
${GLFW_SOURCE_DIR}/support
|
||||
${OPENGL_INCLUDE_DIR})
|
||||
|
@ -49,7 +54,7 @@ add_executable(windows WIN32 MACOSX_BUNDLE windows.c)
|
|||
set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows")
|
||||
|
||||
if (BUILD_SHARED_LIBS)
|
||||
target_link_libraries(threads ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(threads ${thread_LIBRARIES})
|
||||
endif()
|
||||
|
||||
set(WINDOWS_BINARIES accuracy sharing tearing threads title windows)
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
|
||||
#include "getopt.h"
|
||||
|
||||
static GLboolean closed = GL_FALSE;
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Usage: clipboard [-h]\n");
|
||||
|
@ -45,6 +47,12 @@ static GLboolean control_is_down(GLFWwindow window)
|
|||
glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL);
|
||||
}
|
||||
|
||||
static int window_close_callback(GLFWwindow window)
|
||||
{
|
||||
closed = GL_TRUE;
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow window, int key, int action)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
|
@ -53,7 +61,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
|||
switch (key)
|
||||
{
|
||||
case GLFW_KEY_ESCAPE:
|
||||
glfwDestroyWindow(window);
|
||||
closed = GL_TRUE;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_V:
|
||||
|
@ -80,7 +88,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
|||
}
|
||||
}
|
||||
|
||||
static void size_callback(GLFWwindow window, int width, int height)
|
||||
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
@ -130,7 +138,8 @@ int main(int argc, char** argv)
|
|||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetKeyCallback(key_callback);
|
||||
glfwSetWindowSizeCallback(size_callback);
|
||||
glfwSetWindowSizeCallback(window_size_callback);
|
||||
glfwSetWindowCloseCallback(window_close_callback);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f);
|
||||
|
@ -138,7 +147,7 @@ int main(int argc, char** argv)
|
|||
|
||||
glClearColor(0.5f, 0.5f, 0.5f, 0);
|
||||
|
||||
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
while (!closed)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
|
|
@ -83,6 +83,8 @@ int main(void)
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
|
||||
|
||||
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Defaults", NULL);
|
||||
if (!window)
|
||||
{
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
|
||||
#define STEP_SIZE 0.1f
|
||||
|
||||
static GLboolean closed = GL_FALSE;
|
||||
static GLfloat gamma_value = 1.0f;
|
||||
|
||||
static void usage(void)
|
||||
|
@ -51,6 +52,12 @@ static void set_gamma(float value)
|
|||
glfwSetGamma(gamma_value);
|
||||
}
|
||||
|
||||
static int window_close_callback(GLFWwindow window)
|
||||
{
|
||||
closed = GL_TRUE;
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow window, int key, int action)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
|
@ -60,7 +67,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
|||
{
|
||||
case GLFW_KEY_ESCAPE:
|
||||
{
|
||||
glfwDestroyWindow(window);
|
||||
closed = GL_TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -145,6 +152,7 @@ int main(int argc, char** argv)
|
|||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetKeyCallback(key_callback);
|
||||
glfwSetWindowCloseCallback(window_close_callback);
|
||||
glfwSetWindowSizeCallback(size_callback);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
|
@ -153,7 +161,7 @@ int main(int argc, char** argv)
|
|||
|
||||
glClearColor(0.5f, 0.5f, 0.5f, 0);
|
||||
|
||||
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
while (!closed)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
|
|
@ -238,6 +238,8 @@ int main(int argc, char** argv)
|
|||
if (strategy)
|
||||
glfwWindowHint(GLFW_OPENGL_ROBUSTNESS, strategy);
|
||||
|
||||
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
|
||||
|
||||
// We assume here that we stand a better chance of success by leaving all
|
||||
// possible details of pixel format selection to GLFW
|
||||
|
||||
|
|
|
@ -35,11 +35,19 @@
|
|||
|
||||
#include "getopt.h"
|
||||
|
||||
static GLboolean closed = GL_FALSE;
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Usage: iconify [-h] [-f]\n");
|
||||
}
|
||||
|
||||
static int window_close_callback(GLFWwindow window)
|
||||
{
|
||||
closed = GL_TRUE;
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow window, int key, int action)
|
||||
{
|
||||
printf("%0.2f Key %s\n",
|
||||
|
@ -55,12 +63,12 @@ static void key_callback(GLFWwindow window, int key, int action)
|
|||
glfwIconifyWindow(window);
|
||||
break;
|
||||
case GLFW_KEY_ESCAPE:
|
||||
glfwDestroyWindow(window);
|
||||
closed = GL_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void size_callback(GLFWwindow window, int width, int height)
|
||||
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||
{
|
||||
printf("%0.2f Size %ix%i\n", glfwGetTime(), width, height);
|
||||
|
||||
|
@ -124,11 +132,12 @@ int main(int argc, char** argv)
|
|||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetKeyCallback(key_callback);
|
||||
glfwSetWindowSizeCallback(size_callback);
|
||||
glfwSetWindowSizeCallback(window_size_callback);
|
||||
glfwSetWindowCloseCallback(window_close_callback);
|
||||
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
|
||||
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
while (!closed)
|
||||
{
|
||||
if (iconified != glfwGetWindowParam(window, GLFW_ICONIFIED) ||
|
||||
active != glfwGetWindowParam(window, GLFW_ACTIVE))
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
#include "getopt.h"
|
||||
|
||||
static GLFWwindow window = NULL;
|
||||
static GLFWwindow window_handle = NULL;
|
||||
|
||||
enum Mode
|
||||
{
|
||||
|
@ -68,25 +68,25 @@ static void error_callback(int error, const char* description)
|
|||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void window_size_callback(GLFWwindow in_window, int width, int height)
|
||||
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||
{
|
||||
printf("Window resized to %ix%i\n", width, height);
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static int window_close_callback(GLFWwindow dummy)
|
||||
static int window_close_callback(GLFWwindow window)
|
||||
{
|
||||
window = NULL;
|
||||
window_handle = NULL;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow dummy, int key, int action)
|
||||
static void key_callback(GLFWwindow window, int key, int action)
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE)
|
||||
{
|
||||
glfwDestroyWindow(window);
|
||||
window = NULL;
|
||||
window_handle = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,10 +132,10 @@ static void test_modes(void)
|
|||
|
||||
printf("Testing mode %u: %s", (unsigned int) i, format_mode(mode));
|
||||
|
||||
window = glfwCreateWindow(mode->width, mode->height,
|
||||
GLFW_FULLSCREEN, "Video Mode Test",
|
||||
NULL);
|
||||
if (!window)
|
||||
window_handle = glfwCreateWindow(mode->width, mode->height,
|
||||
GLFW_FULLSCREEN, "Video Mode Test",
|
||||
NULL);
|
||||
if (!window_handle)
|
||||
{
|
||||
printf("Failed to enter mode %u: %s\n",
|
||||
(unsigned int) i,
|
||||
|
@ -143,7 +143,7 @@ static void test_modes(void)
|
|||
continue;
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwMakeContextCurrent(window_handle);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetTime(0.0);
|
||||
|
@ -151,10 +151,10 @@ static void test_modes(void)
|
|||
while (glfwGetTime() < 5.0)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glfwSwapBuffers(window);
|
||||
glfwSwapBuffers(window_handle);
|
||||
glfwPollEvents();
|
||||
|
||||
if (!window)
|
||||
if (!window_handle)
|
||||
{
|
||||
printf("User terminated program\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
|
@ -165,7 +165,7 @@ static void test_modes(void)
|
|||
glGetIntegerv(GL_GREEN_BITS, ¤t.greenBits);
|
||||
glGetIntegerv(GL_BLUE_BITS, ¤t.blueBits);
|
||||
|
||||
glfwGetWindowSize(window, ¤t.width, ¤t.height);
|
||||
glfwGetWindowSize(window_handle, ¤t.width, ¤t.height);
|
||||
|
||||
if (current.redBits != mode->redBits ||
|
||||
current.greenBits != mode->greenBits ||
|
||||
|
@ -185,9 +185,9 @@ static void test_modes(void)
|
|||
|
||||
printf("Closing window\n");
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
glfwDestroyWindow(window_handle);
|
||||
window_handle = NULL;
|
||||
glfwPollEvents();
|
||||
window = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static GLboolean reopen = GL_FALSE;
|
||||
static GLFWwindow window_handle = NULL;
|
||||
static int cursor_x;
|
||||
static int cursor_y;
|
||||
|
@ -77,10 +78,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
|||
case GLFW_KEY_R:
|
||||
{
|
||||
if (action == GLFW_PRESS)
|
||||
{
|
||||
glfwDestroyWindow(window);
|
||||
open_window();
|
||||
}
|
||||
reopen = GL_TRUE;
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -121,8 +119,6 @@ int main(void)
|
|||
|
||||
if (!open_window())
|
||||
{
|
||||
glfwTerminate();
|
||||
|
||||
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -135,6 +131,18 @@ int main(void)
|
|||
|
||||
glfwSwapBuffers(window_handle);
|
||||
glfwWaitEvents();
|
||||
|
||||
if (reopen)
|
||||
{
|
||||
glfwDestroyWindow(window_handle);
|
||||
if (!open_window())
|
||||
{
|
||||
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
reopen = GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
|
|
|
@ -37,27 +37,18 @@
|
|||
#define HEIGHT 400
|
||||
|
||||
static GLFWwindow windows[2];
|
||||
static GLboolean closed = GL_FALSE;
|
||||
|
||||
static void key_callback(GLFWwindow window, int key, int action)
|
||||
{
|
||||
if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE)
|
||||
glfwDestroyWindow(window);
|
||||
closed = GL_TRUE;
|
||||
}
|
||||
|
||||
static int window_close_callback(GLFWwindow window)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
if (windows[i] == window)
|
||||
{
|
||||
windows[i] = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return GL_TRUE;
|
||||
closed = GL_TRUE;
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
static GLFWwindow open_window(const char* title, GLFWwindow share)
|
||||
|
@ -170,7 +161,7 @@ int main(int argc, char** argv)
|
|||
glfwGetWindowPos(windows[0], &x, &y);
|
||||
glfwSetWindowPos(windows[1], x + WIDTH + 50, y);
|
||||
|
||||
while (windows[0] && windows[1])
|
||||
while (!closed)
|
||||
{
|
||||
glfwMakeContextCurrent(windows[0]);
|
||||
draw_quad(texture);
|
||||
|
|
Loading…
Reference in New Issue
Block a user