1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 02:38:52 -05:00

Merge branch 'master' into cursor-enter-leave

This commit is contained in:
Camilla Berglund 2012-03-22 12:06:00 +01:00
commit 8109470e72
53 changed files with 3420 additions and 1179 deletions

2
.gitignore vendored
View File

@ -4,6 +4,7 @@ CMakeCache.txt
Makefile
cmake_uninstall.cmake
.DS_Store
docs/Doxyfile
src/config.h
src/libglfw.pc
src/libglfw.so
@ -32,6 +33,7 @@ tests/peter
tests/reopen
tests/sharing
tests/tearing
tests/title
tests/windows
tests/*.app
tests/*.exe

View File

@ -1,88 +0,0 @@
# - Check if X11 RandR extension is available
# Check if the X11 extension RandR is available.
# This macro defines :
# - X11_RANDR_FOUND, If set to NO RandR is not available.
# - X11_RANDR_INCLUDE_DIR, includes directory containing the RandR header.
# - X11_RANDR_LIBRARIES, libraries to link in the library to use RandR.
#
# Created by Olivier Delannoy.
macro(CHECK_X11_XRANDR)
message(STATUS "Checking for X11 extension XRandR")
set(X11_XRANDR_FOUND "NO")
find_path(X11_XRANDR_INCLUDE_DIR "X11/extensions/Xrandr.h"
PATHS
/usr/local/include
/usr/local/X11/include
/usr/local/X11R6/include
/usr/include
/usr/X11/include
/usr/X11R6/include)
find_library(X11_XRANDR_LIBRARIES NAMES Xrandr
PATHS
/usr/local/lib
/usr/local/X11/lib
/usr/local/X11R6/lib
/usr/lib
/usr/X11/lib
/usr/X11R6/lib)
# Create check if file compiles with randr
if (X11_XRANDR_LIBRARIES AND X11_XRANDR_INCLUDE_DIR)
set(X11_XRANDR_FOUND "YES")
endif (X11_XRANDR_LIBRARIES AND X11_XRANDR_INCLUDE_DIR)
if (X11_XRANDR_FOUND)
message(STATUS "Checking for X11 extension XRandR -- found")
else (X11_XRANDR_FOUND)
message(STATUS "Checking for X11 extension XRandR -- not found")
endif (X11_XRANDR_FOUND)
mark_as_advanced(X11_XRANDR_LIBRARIES X11_XRANDR_INCLUDE_DIR)
endmacro(CHECK_X11_XRANDR)
# - Check if X11 VidMod extension is available
# Check if the X11 extension VidMod is available.
# This macro defines :
# - X11_VIDMOD_FOUND, If set to NO VidMod is not available.
# - X11_VIDMOD_INCLUDE_DIR, includes directory containing the headers.
# - X11_VIDMOD_LIBRARIES, libraries to link in the libraries.
#
# Created by Olivier Delannoy.
macro(CHECK_X11_XF86VIDMODE)
message(STATUS "Checking for X11 extension xf86vidmode")
set(X11_XF86VIDMODE_FOUND "NO")
find_path(X11_XF86VIDMODE_INCLUDE_DIR "X11/extensions/xf86vmode.h"
PATHS
/usr/local/include
/usr/local/X11/include
/usr/local/X11R6/include
/usr/include
/usr/X11/include
/usr/X11R6/include)
find_library(X11_XF86VIDMODE_LIBRARIES NAMES Xxf86vm PATHS
/usr/local/lib
/usr/local/X11/lib
/usr/local/X11R6/lib
/usr/lib
/usr/X11/lib
/usr/X11R6/lib)
# Add a test case here
if (X11_XF86VIDMODE_LIBRARIES AND X11_XF86VIDMODE_INCLUDE_DIR)
set(X11_XF86VIDMODE_FOUND "YES")
endif (X11_XF86VIDMODE_LIBRARIES AND X11_XF86VIDMODE_INCLUDE_DIR)
if (X11_XF86VIDMODE_FOUND)
message(STATUS "Checking for X11 extension xf86vidmode -- found")
else (X11_XF86VIDMODE_FOUND)
message(STATUS "Checking for X11 extension xf86vidmode -- not found")
endif(X11_XF86VIDMODE_FOUND)
mark_as_advanced(
X11_XF86VIDMODE_LIBRARIES
X11_XF86VIDMODE_INCLUDE_DIR
)
endmacro(CHECK_X11_XF86VIDMODE)

View File

@ -1,10 +1,19 @@
This folder contains a collection of toolchains definition in order to
support cross compilation. The naming scheme is the following:
This directory contains a collection of toolchain definitions for cross
compilation, currently limited to compiling Win32 binaries on Linux.
The toolchain file naming scheme is as follows:
host-system-compiler.cmake
to use this at the time you run the initial cmake command use the
following parameter
-DCMAKE_TOOLCHAIN_FILE=./toolchains/XXX-XXX-XXX.cmake
which maps to file in this folder.
To use these files you add a special parameter when configuring the source tree:
cmake -DCMAKE_TOOLCHAIN_FILE=<toolchain-file> .
For example, to use the Debian GNU/Linux MinGW package, run CMake like this:
cmake -DCMAKE_TOOLCHAIN_FILE=CMake/linux-i586-mingw32msvc.cmake .
For more details see this article:
http://www.paraview.org/Wiki/CMake_Cross_Compiling
For more details see: http://www.paraview.org/Wiki/CMake_Cross_Compiling

View File

@ -1,7 +1,6 @@
project(GLFW C)
cmake_minimum_required(VERSION 2.4)
cmake_policy(VERSION 2.4)
cmake_minimum_required(VERSION 2.8)
set(GLFW_VERSION_MAJOR "3")
set(GLFW_VERSION_MINOR "0")
@ -27,7 +26,7 @@ if (WIN32)
# Set up library and include paths
list(APPEND GLFW_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
list(APPEND GLFW_LIBRARIES ${OPENGL_gl_LIBRARY})
endif (WIN32)
endif()
#--------------------------------------------------------------------
# Set up GLFW for Xlib and GLX on Unix-like systems with X Windows
@ -38,6 +37,8 @@ if (UNIX AND NOT APPLE)
# Define the platform identifier
set(_GLFW_X11_GLX 1)
find_package(X11 REQUIRED)
# Set up library and include paths
list(APPEND GLFW_INCLUDE_DIR ${X11_X11_INCLUDE_PATH} ${OPENGL_INCLUDE_DIR})
list(APPEND GLFW_LIBRARIES ${X11_X11_LIB} ${OPENGL_gl_LIBRARY})
@ -45,61 +46,58 @@ if (UNIX AND NOT APPLE)
find_library(MATH_LIBRARY m)
if (MATH_LIBRARY)
list(APPEND GLFW_LIBRARIES ${MATH_LIBRARY})
endif(MATH_LIBRARY)
endif()
find_library(RT_LIBRARY rt)
if (RT_LIBRARY)
list(APPEND GLFW_LIBRARIES ${RT_LIBRARY})
endif(RT_LIBRARY)
endif()
include(CheckFunctionExists)
include(CheckSymbolExists)
include(${GLFW_SOURCE_DIR}/CMake/CheckX11Extensions.cmake)
set(CMAKE_REQUIRED_LIBRARIES ${GLFW_LIBRARIES})
# Check for XRandR (modern resolution switching extension)
check_x11_xrandr()
if (X11_XRANDR_FOUND)
if (X11_Xrandr_FOUND)
set(_GLFW_HAS_XRANDR 1)
list(APPEND GLFW_INCLUDE_DIR ${X11_XRANDR_INCLUDE_DIR})
list(APPEND GLFW_LIBRARIES ${X11_XRANDR_LIBRARIES})
endif(X11_XRANDR_FOUND)
list(APPEND GLFW_INCLUDE_DIR ${X11_Xrandr_INCLUDE_PATH})
list(APPEND GLFW_LIBRARIES ${X11_Xrandr_LIB})
endif()
# Check for Xf86VidMode (fallback legacy resolution switching extension)
check_x11_xf86vidmode()
if (X11_XF86VIDMODE_FOUND)
if (X11_xf86vmode_FOUND)
set(_GLFW_HAS_XF86VIDMODE 1)
list(APPEND GLFW_INCLUDE_DIR ${X11_XF86VIDMODE_INCLUDE_DIR})
list(APPEND GLFW_LIBRARIES ${X11_XF86VIDMODE_LIBRARIES})
endif(X11_XF86VIDMODE_FOUND)
list(APPEND GLFW_INCLUDE_DIR ${X11_xf86vmode_INCLUDE_PATH})
endif()
# Check for Xkb (X keyboard extension)
check_function_exists(XkbQueryExtension _GLFW_HAS_XKB)
if (X11_Xkb_FOUND)
set(_GLFW_HAS_XKB 1)
list(APPEND GLFW_INCLUDE_DIR ${X11_Xkb_INCLUDE_PATH})
endif()
# Check for glXGetProcAddress
check_function_exists(glXGetProcAddress _GLFW_HAS_GLXGETPROCADDRESS)
if (NOT _GLFW_HAS_GLXGETPROCADDRESS)
check_function_exists(glXGetProcAddressARB _GLFW_HAS_GLXGETPROCADDRESSARB)
endif (NOT _GLFW_HAS_GLXGETPROCADDRESS)
endif()
if (NOT _GLFW_HAS_GLXGETPROCADDRESS AND NOT _GLFW_HAS_GLXGETPROCADDRESSARB)
check_function_exists(glXGetProcAddressEXT _GLFW_HAS_GLXGETPROCADDRESSEXT)
endif (NOT _GLFW_HAS_GLXGETPROCADDRESS AND NOT _GLFW_HAS_GLXGETPROCADDRESSARB)
endif()
if (NOT _GLFW_HAS_GLXGETPROCADDRESS AND
NOT _GLFW_HAS_GLXGETPROCADDRESSARB AND
NOT _GLFW_HAS_GLXGETPROCADDRESSEXT)
message(WARNING "No glXGetProcAddressXXX variant found")
endif (NOT _GLFW_HAS_GLXGETPROCADDRESS AND
NOT _GLFW_HAS_GLXGETPROCADDRESSARB AND
NOT _GLFW_HAS_GLXGETPROCADDRESSEXT)
endif()
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(_GLFW_USE_LINUX_JOYSTICKS 1)
endif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
endif(UNIX AND NOT APPLE)
endif()
endif()
#--------------------------------------------------------------------
# Set up GLFW for Cocoa and NSOpenGL on Mac OS X
@ -120,7 +118,7 @@ if (UNIX AND APPLE)
set(CMAKE_C_FLAGS "-mmacosx-version-min=10.5")
else(GLFW_BUILD_UNIVERSAL)
message(STATUS "Building GLFW only for the native architecture")
endif(GLFW_BUILD_UNIVERSAL)
endif()
# Set up library and include paths
find_library(COCOA_FRAMEWORK Cocoa)
@ -130,7 +128,7 @@ if (UNIX AND APPLE)
list(APPEND GLFW_LIBRARIES ${OPENGL_gl_LIBRARY})
list(APPEND GLFW_LIBRARIES ${IOKIT_FRAMEWORK})
list(APPEND GLFW_LIBRARIES ${CORE_FOUNDATION_FRAMEWORK})
endif(UNIX AND APPLE)
endif()
#--------------------------------------------------------------------
# Add subdirectories
@ -139,11 +137,11 @@ add_subdirectory(src)
if (GLFW_BUILD_EXAMPLES)
add_subdirectory(examples)
endif(GLFW_BUILD_EXAMPLES)
endif()
if (GLFW_BUILD_TESTS)
add_subdirectory(tests)
endif(GLFW_BUILD_TESTS)
endif()
#--------------------------------------------------------------------
# Create shared configuration header
@ -161,23 +159,20 @@ install(DIRECTORY include/GL DESTINATION include
install(FILES COPYING.txt readme.html
DESTINATION share/doc/glfw-${GLFW_VERSION_FULL}/)
# The respective port's CMakeLists.txt file installs the library
# The src directory's CMakeLists.txt file installs the library
#--------------------------------------------------------------------
# -- Documentation generation
#--------------------------------------------------------------------
#include("${GLFW_SOURCE_DIR}/documentation.cmake")
#configure_file("${GLFW_SOURCE_DIR}/Doxyfile.in"
# "${GLFW_BINARY_DIR}/Doxyfile"
# IMMEDIATE @ONLY)
#add_doxygen_target("${GLFW_BINARY_DIR}/Doxyfile")
#add_subdirectory(docs)
configure_file("${GLFW_SOURCE_DIR}/docs/Doxyfile.in"
"${GLFW_BINARY_DIR}/docs/Doxyfile"
@ONLY)
#--------------------------------------------------------------------
# Uninstall operation
# Don't generate this target if a higher-level project already has
#--------------------------------------------------------------------
if(NOT TARGET uninstall)
if (NOT TARGET uninstall)
configure_file(${GLFW_SOURCE_DIR}/cmake_uninstall.cmake.in
${GLFW_BINARY_DIR}/cmake_uninstall.cmake IMMEDIATE @ONLY)

1687
docs/Doxyfile.in Normal file

File diff suppressed because it is too large Load Diff

View File

@ -7,14 +7,20 @@ include_directories(${GLFW_SOURCE_DIR}/include
${GLFW_SOURCE_DIR}/support
${OPENGL_INCLUDE_DIR})
if(APPLE)
if (APPLE)
# Set fancy names for bundles
add_executable(Boing MACOSX_BUNDLE boing.c)
add_executable(Gears MACOSX_BUNDLE gears.c)
add_executable("Split View" MACOSX_BUNDLE splitview.c)
add_executable(Triangle MACOSX_BUNDLE triangle.c)
add_executable(Wave MACOSX_BUNDLE wave.c)
else(APPLE)
set_target_properties(Boing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Boing")
set_target_properties(Gears PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gears")
set_target_properties("Split View" PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Split View")
set_target_properties(Triangle PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Triangle")
set_target_properties(Wave PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Wave")
else()
# Set boring names for executables
add_executable(boing WIN32 boing.c)
add_executable(gears WIN32 gears.c)
@ -22,13 +28,21 @@ else(APPLE)
add_executable(splitview WIN32 splitview.c)
add_executable(triangle WIN32 triangle.c)
add_executable(wave WIN32 wave.c)
endif(APPLE)
endif()
set(WINDOWS_BINARIES boing gears heightmap splitview triangle wave)
if (MSVC)
set(WINDOWS_BINARIES boing gears heightmap splitview triangle wave)
if(MSVC)
# Tell MSVC to use main instead of WinMain for Windows subsystem executables
set_target_properties(${WINDOWS_BINARIES} PROPERTIES
LINK_FLAGS "/ENTRY:mainCRTStartup")
endif(MSVC)
endif()
if (APPLE)
set(BUNDLE_BINARIES Boing Gears "Split View" Triangle Wave)
set_target_properties(${BUNDLE_BINARIES} PROPERTIES
MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION}
MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL})
endif()

View File

@ -586,7 +586,7 @@ int main( void )
}
glfwSetWindowSizeCallback( reshape );
glfwEnable( window, GLFW_STICKY_KEYS );
glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE );
glfwSwapInterval( 1 );
glfwSetTime( 0.0 );

View File

@ -339,7 +339,7 @@ int main(int argc, char *argv[])
exit( EXIT_FAILURE );
}
glfwEnable( window, GLFW_KEY_REPEAT );
glfwSetInputMode( window, GLFW_KEY_REPEAT, GL_TRUE );
glfwSwapInterval( 1 );
// Parse command-line options

View File

@ -573,7 +573,7 @@ int main(int argc, char** argv)
}
}
if (GL_TRUE != glfwInit())
if (!glfwInit())
{
fprintf(stderr, "ERROR: Unable to initialize GLFW\n");
usage();

View File

@ -462,10 +462,10 @@ int main(void)
glfwSwapInterval(1);
// Enable sticky keys
glfwEnable(window, GLFW_STICKY_KEYS);
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
// Enable mouse cursor (only needed for fullscreen mode)
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
// Set callback functions
glfwSetWindowSizeCallback(windowSizeFun);

View File

@ -30,7 +30,7 @@ int main(void)
}
// Ensure we can capture the escape key being pressed below
glfwEnable(window, GLFW_STICKY_KEYS);
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
// Enable vertical sync (on cards that support it)
glfwSwapInterval(1);

View File

@ -309,13 +309,13 @@ void mouse_button_callback(GLFWwindow window, int button, int action)
if (action == GLFW_PRESS)
{
glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED);
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED);
locked = GL_TRUE;
}
else
{
locked = GL_FALSE;
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
}
}
@ -396,7 +396,7 @@ int main(int argc, char* argv[])
// Keyboard handler
glfwSetKeyCallback(key_callback);
glfwEnable(window, GLFW_KEY_REPEAT);
glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE);
// Window resize handler
glfwSetWindowSizeCallback(window_resize_callback);

View File

@ -136,10 +136,6 @@ extern "C" {
/* -------------------- END SYSTEM/COMPILER SPECIFIC --------------------- */
/* Include the declaration of the size_t type used below.
*/
#include <stddef.h>
/* Include standard OpenGL headers: GLFW uses GL_FALSE/GL_TRUE, and it is
* convenient for the user to only have to include <GL/glfw.h>. This also
* solves the problem with Windows <GL/gl.h> and <GL/glu.h> needing some
@ -427,13 +423,14 @@ extern "C" {
#define GLFW_OPENGL_COMPAT_PROFILE 0x00000002
#define GLFW_OPENGL_ES2_PROFILE 0x00000004
/* glfwEnable/glfwDisable tokens */
/* glfwGetInputMode/glfwSetInputMode tokens */
#define GLFW_CURSOR_MODE 0x00030001
#define GLFW_STICKY_KEYS 0x00030002
#define GLFW_STICKY_MOUSE_BUTTONS 0x00030003
#define GLFW_SYSTEM_KEYS 0x00030004
#define GLFW_KEY_REPEAT 0x00030005
/* glfwSetCursorMode tokens */
/* GLFW_CURSOR_MODE values */
#define GLFW_CURSOR_NORMAL 0x00040001
#define GLFW_CURSOR_HIDDEN 0x00040002
#define GLFW_CURSOR_CAPTURED 0x00040003
@ -478,8 +475,6 @@ typedef void (* GLFWcursorenterfun)(GLFWwindow,int);
typedef void (* GLFWscrollfun)(GLFWwindow,int,int);
typedef void (* GLFWkeyfun)(GLFWwindow,int,int);
typedef void (* GLFWcharfun)(GLFWwindow,int);
typedef void* (* GLFWmallocfun)(size_t);
typedef void (* GLFWfreefun)(void*);
/* The video mode structure used by glfwGetVideoModes */
typedef struct
@ -499,19 +494,6 @@ typedef struct
unsigned short blue[GLFW_GAMMA_RAMP_SIZE];
} GLFWgammaramp;
/* Custom memory allocator interface */
typedef struct
{
GLFWmallocfun malloc;
GLFWfreefun free;
} GLFWallocator;
/* Custom threading model interface */
typedef struct
{
int dummy;
} GLFWthreadmodel;
/*************************************************************************
* Prototypes
@ -519,7 +501,6 @@ typedef struct
/* Initialization, termination and version querying */
GLFWAPI int glfwInit(void);
GLFWAPI int glfwInitWithModels(GLFWthreadmodel* threading, GLFWallocator* allocator);
GLFWAPI void glfwTerminate(void);
GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev);
GLFWAPI const char* glfwGetVersionString(void);
@ -564,11 +545,12 @@ GLFWAPI void glfwPollEvents(void);
GLFWAPI void glfwWaitEvents(void);
/* Input handling */
GLFWAPI int glfwGetInputMode(GLFWwindow window, int mode);
GLFWAPI void glfwSetInputMode(GLFWwindow window, int mode, int value);
GLFWAPI int glfwGetKey(GLFWwindow window, int key);
GLFWAPI int glfwGetMouseButton(GLFWwindow window, int button);
GLFWAPI void glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos);
GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos);
GLFWAPI void glfwSetCursorMode(GLFWwindow window, int mode);
GLFWAPI void glfwGetScrollOffset(GLFWwindow window, int* xoffset, int* yoffset);
GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun);
GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun);
@ -595,10 +577,6 @@ GLFWAPI int glfwExtensionSupported(const char* extension);
GLFWAPI void* glfwGetProcAddress(const char* procname);
GLFWAPI void glfwCopyContext(GLFWwindow src, GLFWwindow dst, unsigned long mask);
/* Enable/disable functions */
GLFWAPI void glfwEnable(GLFWwindow window, int token);
GLFWAPI void glfwDisable(GLFWwindow window, int token);
/*************************************************************************
* Global definition cleanup

View File

@ -272,9 +272,7 @@ version of GLFW.</p>
<li>Added <code>glfwSetWindowFocusCallback</code> function and <code>GLFWwindowfocusfun</code> type for receiving window focus events</li>
<li>Added <code>glfwSetWindowIconifyCallback</code> function and <code>GLFWwindowiconifyfun</code> type for receiving window iconification events</li>
<li>Added <code>glfwGetCurrentContext</code> function for retrieving the window whose OpenGL context is current</li>
<li>Added <code>glfwInitWithModels</code> function and <code>GLFWallocator</code> and <code>GLFWthreadmodel</code> types for pluggable memory allocation and threading models</li>
<li>Added <code>glfwCopyContext</code> function for copying OpenGL state categories between contexts</li>
<li>Added <code>glfwSetCursorMode</code> function for controlling per-window cursor mode, replacing <code>GLFW_MOUSE_CURSOR</code></li>
<li>Added <code>GLFW_OPENGL_ES2_PROFILE</code> profile for creating OpenGL ES 2.0 contexts using the <code>GLX_EXT_create_context_es2_profile</code> and <code>WGL_EXT_create_context_es2_profile</code> extensions</li>
<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>
@ -282,10 +280,12 @@ version of GLFW.</p>
<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>dynamic</code> simple dynamic linking test program</li>
<li>Added <code>modes</code> video mode enumeration and setting test program</li>
<li>Added a parameter to <code>glfwOpenWindow</code> for specifying a context the new window's context will share objects with</li>
<li>Added initial window title parameter to <code>glfwOpenWindow</code></li>
<li>Added <code>glfwSetGamma</code>, <code>glfwSetGammaRamp</code> and <code>glfwGetGammaRamp</code> functions and <code>GLFWgammaramp</code> type for monitor gamma ramp control</li>
<li>Changed buffer bit depth parameters of <code>glfwOpenWindow</code> to window hints</li>
<li>Changed <code>glfwOpenWindow</code> and <code>glfwSetWindowTitle</code> to use UTF-8 encoded strings</li>
<li>Renamed <code>glfw.h</code> to <code>glfw3.h</code> to avoid conflicts with 2.x series</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>
@ -293,6 +293,7 @@ version of GLFW.</p>
<li>Replaced ad hoc build system with CMake</li>
<li>Replaced layout-dependent key codes with single, platform-independent set based on US layout</li>
<li>Replaced mouse wheel interface with two-dimensional scrolling interface</li>
<li>Replaced <code>glfwEnable</code> and <code>glfwDisable</code> with <code>glfwGetInputMode</code> and <code>glfwSetInputMode</code></li>
<li>Made Unicode character input unaffected by <code>GLFW_KEY_REPEAT</code></li>
<li>Removed event auto-polling and the <code>GLFW_AUTO_POLL_EVENTS</code> window enable</li>
<li>Removed the Win32 port .def files</li>
@ -310,17 +311,29 @@ version of GLFW.</p>
<li>Bugfix: The FSAA test did not check for the availability of <code>GL_ARB_multisample</code></li>
<li>[Cocoa] Added support for OpenGL 3.2 core profile in 10.7 Lion and above</li>
<li>[Cocoa] Added support for joysticks</li>
<li>[Cocoa] Postponed menu creation to first window creation</li>
<li>[Cocoa] Replaced <code>NSDate</code> time source with <code>mach_absolute_time</code></li>
<li>[Cocoa] Replaced all deprecated CoreGraphics calls with non-deprecated counterparts</li>
<li>[Cocoa] Bugfix: The <code>NSOpenGLPFAFullScreen</code> pixel format attribute caused creation to fail on some machines</li>
<li>[Cocoa] Bugfix: <code>glfwOpenWindow</code> did not properly enforce the forward-compatible and context profile hints</li>
<li>[Cocoa] Bugfix: The loop condition for saving video modes used the wrong index variable</li>
<li>[Cocoa] Bugfix: The OpenGL framework was not retrieved, making glfwGetProcAddress crash</li>
<li>[Cocoa] Bugfix: <code>glfwInit</code> changed the current directory for unbundled executables</li>
<li>[Cocoa] Bugfix: The <code>GLFW_WINDOW_NO_RESIZE</code> window parameter was always zero</li>
<li>[X11] Added support for the <code>GLX_EXT_swap_control</code> extension as an alternative to <code>GLX_SGI_swap_control</code></li>
<li>[X11] Added the POSIX <code>CLOCK_MONOTONIC</code> time source as the preferred method</li>
<li>[X11] Added dependency on libm, where present</li>
<li>[X11] Added support for the <code>_NET_WM_NAME</code> and <code>_NET_WM_ICON_NAME</code> EWMH window properties</li>
<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>[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>
<li>[Win32] Bugfix: Software rasterizer pixel formats were not discarded by the WGL_ARB_pixel_format code path</li>
<li>[Win32] Bugfix: The array for WGL context attributes was too small and could overflow</li>
<li>[Win32] Bugfix: Alt+F4 hot key was not translated into <code>WM_CLOSE</code></li>
<li>[Win32] Bugfix: The <code>GLFW_WINDOW_NO_RESIZE</code> window parameter was always zero</li>
</ul>
<h3>v2.7</h3>
@ -810,6 +823,8 @@ their skills. Special thanks go out to:</p>
<ul>
<li>artblanc, for a patch replacing a deprecated Core Graphics call</li>
<li>Bobyshev Alexander and Martins Mozeiko, for the original proposal of
an FSAA hint and their work on the Win32 implementation of FSAA</li>
@ -865,6 +880,9 @@ their skills. Special thanks go out to:</p>
<li>Tristam MacDonald, for his bug reports and feedback on the Cocoa port</li>
<li>Hans 'Hanmac' Mackowiak, for adding UTF-8 window title support on X11 and
a fix for the Xkb support</li>
<li>David Medlock, for doing the initial Lua port</li>
<li>Kenneth Miller, for his many and detailed bug reports on Win32</li>

View File

@ -1,43 +1,43 @@
if(UNIX)
if(_GLFW_HAS_XRANDR)
if (_GLFW_HAS_XRANDR)
set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xrandr")
endif(_GLFW_HAS_XRANDR)
if(_GLFW_HAS_XF86VIDMODE)
endif()
if (_GLFW_HAS_XF86VIDMODE)
set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xxf86vm")
endif(_GLFW_HAS_XF86VIDMODE)
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake
${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc DESTINATION lib/pkgconfig)
endif(UNIX)
endif()
include_directories(${GLFW_SOURCE_DIR}/src
${GLFW_BINARY_DIR}/src
${GLFW_INCLUDE_DIR})
set(common_SOURCES enable.c error.c fullscreen.c gamma.c init.c input.c
set(common_SOURCES error.c fullscreen.c gamma.c init.c input.c
joystick.c opengl.c time.c window.c)
if(_GLFW_COCOA_NSGL)
set(libglfw_SOURCES ${common_SOURCES} cocoa_enable.m cocoa_fullscreen.m
cocoa_gamma.m cocoa_init.m cocoa_joystick.m
cocoa_opengl.m cocoa_time.m cocoa_window.m)
set(libglfw_SOURCES ${common_SOURCES} cocoa_fullscreen.m cocoa_gamma.c
cocoa_init.m cocoa_input.m cocoa_joystick.m
cocoa_opengl.m cocoa_time.c cocoa_window.m)
# For some reason, CMake doesn't know about .m
set_source_files_properties(${libglfw_SOURCES} PROPERTIES LANGUAGE C)
elseif(_GLFW_WIN32_WGL)
set(libglfw_SOURCES ${common_SOURCES} win32_enable.c win32_fullscreen.c
win32_gamma.c win32_init.c win32_joystick.c
set(libglfw_SOURCES ${common_SOURCES} win32_fullscreen.c win32_gamma.c
win32_init.c win32_input.c win32_joystick.c
win32_opengl.c win32_time.c win32_window.c
win32_dllmain.c)
elseif(_GLFW_X11_GLX)
set(libglfw_SOURCES ${common_SOURCES} x11_enable.c x11_fullscreen.c
x11_gamma.c x11_init.c x11_joystick.c
set(libglfw_SOURCES ${common_SOURCES} x11_fullscreen.c x11_gamma.c
x11_init.c x11_input.c x11_joystick.c
x11_keysym2unicode.c x11_opengl.c x11_time.c
x11_window.c)
else()
message(FATAL_ERROR "No supported platform was selected")
endif(_GLFW_COCOA_NSGL)
endif()
add_library(libglfwStatic STATIC ${libglfw_SOURCES})
add_library(libglfwShared SHARED ${libglfw_SOURCES})
@ -47,22 +47,23 @@ set_target_properties(libglfwStatic libglfwShared PROPERTIES
OUTPUT_NAME glfw)
if(WIN32)
target_link_libraries(libglfwShared winmm)
# The GLFW DLL needs a special compile-time macro and import library name
set_target_properties(libglfwShared PROPERTIES
DEFINE_SYMBOL GLFW_BUILD_DLL
COMPILE_DEFINITIONS "GLFW_BUILD_DLL;_GLFW_NO_DLOAD_GDI32;_GLFW_NO_DLOAD_WINMM"
PREFIX ""
IMPORT_PREFIX ""
IMPORT_SUFFIX "dll.lib")
endif(WIN32)
endif()
if(APPLE)
# Append -fno-common to the compile flags to work around a bug in the Apple GCC
get_target_property(CFLAGS libglfwShared COMPILE_FLAGS)
if(NOT CFLAGS)
if (NOT CFLAGS)
set(CFLAGS "")
endif(NOT CFLAGS)
endif()
set_target_properties(libglfwShared PROPERTIES COMPILE_FLAGS "${CFLAGS} -fno-common")
endif(APPLE)
endif()
install(TARGETS libglfwStatic libglfwShared DESTINATION lib)

View File

@ -29,47 +29,166 @@
#include "internal.h"
#include <stdlib.h>
#include <limits.h>
//========================================================================
// Check whether the display mode should be included in enumeration
//========================================================================
static BOOL modeIsGood(NSDictionary* mode)
static GLboolean modeIsGood(CGDisplayModeRef mode)
{
// This is a bit controversial, if you've got something other than an
// LCD computer monitor as an output device you might not want these
// checks. You might also want to reject modes which are interlaced,
// or TV out. There is no one-size-fits-all policy that can work here.
// This seems like a decent compromise, but certain applications may
// wish to patch this...
return [[mode objectForKey:(id)kCGDisplayBitsPerPixel] intValue] >= 15 &&
[mode objectForKey:(id)kCGDisplayModeIsSafeForHardware] != nil &&
[mode objectForKey:(id)kCGDisplayModeIsStretched] == nil;
uint32_t flags = CGDisplayModeGetIOFlags(mode);
if (!(flags & kDisplayModeValidFlag) || !(flags & kDisplayModeSafeFlag))
return GL_FALSE;
if (flags & kDisplayModeInterlacedFlag)
return GL_FALSE;
if (flags & kDisplayModeTelevisionFlag)
return GL_FALSE;
if (flags & kDisplayModeStretchedFlag)
return GL_FALSE;
CFStringRef format = CGDisplayModeCopyPixelEncoding(mode);
if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) &&
CFStringCompare(format, CFSTR(IO32BitDirectPixels), 0))
{
CFRelease(format);
return GL_FALSE;
}
CFRelease(format);
return GL_TRUE;
}
//========================================================================
// Convert Core Graphics display mode to GLFW video mode
//========================================================================
static GLFWvidmode vidmodeFromCGDisplayMode(NSDictionary* mode)
static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode)
{
unsigned int width =
[[mode objectForKey:(id)kCGDisplayWidth] unsignedIntValue];
unsigned int height =
[[mode objectForKey:(id)kCGDisplayHeight] unsignedIntValue];
unsigned int bps =
[[mode objectForKey:(id)kCGDisplayBitsPerSample] unsignedIntValue];
GLFWvidmode result;
result.width = width;
result.height = height;
result.redBits = bps;
result.greenBits = bps;
result.blueBits = bps;
result.width = CGDisplayModeGetWidth(mode);
result.height = CGDisplayModeGetHeight(mode);
CFStringRef format = CGDisplayModeCopyPixelEncoding(mode);
if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) == 0)
{
result.redBits = 5;
result.greenBits = 5;
result.blueBits = 5;
}
else
{
result.redBits = 8;
result.greenBits = 8;
result.blueBits = 8;
}
CFRelease(format);
return result;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Change the current video mode
//========================================================================
GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate)
{
CGDisplayModeRef bestMode = NULL;
CFArrayRef modes;
CFIndex count, i;
unsigned int leastSizeDiff = UINT_MAX;
double leastRateDiff = DBL_MAX;
modes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL);
count = CFArrayGetCount(modes);
for (i = 0; i < count; i++)
{
CGDisplayModeRef mode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
if (!modeIsGood(mode))
continue;
int modeBPP;
// Identify display mode pixel encoding
{
CFStringRef format = CGDisplayModeCopyPixelEncoding(mode);
if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) == 0)
modeBPP = 16;
else
modeBPP = 32;
CFRelease(format);
}
int modeWidth = (int) CGDisplayModeGetWidth(mode);
int modeHeight = (int) CGDisplayModeGetHeight(mode);
unsigned int sizeDiff = (abs(modeBPP - *bpp) << 25) |
((modeWidth - *width) * (modeWidth - *width) +
(modeHeight - *height) * (modeHeight - *height));
double rateDiff;
if (*refreshRate > 0)
rateDiff = fabs(CGDisplayModeGetRefreshRate(mode) - *refreshRate);
else
{
// If no refresh rate was specified, then they're all the same
rateDiff = 0;
}
if ((sizeDiff < leastSizeDiff) ||
(sizeDiff == leastSizeDiff && (rateDiff < leastRateDiff)))
{
bestMode = mode;
leastSizeDiff = sizeDiff;
leastRateDiff = rateDiff;
}
}
if (!bestMode)
{
CFRelease(modes);
return GL_FALSE;
}
CGDisplayCapture(CGMainDisplayID());
CGDisplaySetDisplayMode(CGMainDisplayID(), bestMode, NULL);
CFRelease(modes);
return GL_TRUE;
}
//========================================================================
// Restore the previously saved (original) video mode
//========================================================================
void _glfwRestoreVideoMode(void)
{
CGDisplaySetDisplayMode(CGMainDisplayID(),
_glfwLibrary.NS.desktopMode,
NULL);
CGDisplayRelease(CGMainDisplayID());
}
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
@ -80,19 +199,26 @@ static GLFWvidmode vidmodeFromCGDisplayMode(NSDictionary* mode)
int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
{
NSArray* modes = (NSArray*) CGDisplayAvailableModes(CGMainDisplayID());
unsigned int i, j = 0, n = [modes count];
CGDisplayModeRef mode;
CFArrayRef modes;
CFIndex count, i;
int stored = 0;
for (i = 0; i < n && j < (unsigned)maxcount; i++)
modes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL);
count = CFArrayGetCount(modes);
for (i = 0; i < count && stored < maxcount; i++)
{
NSDictionary *mode = [modes objectAtIndex:i];
mode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
if (modeIsGood(mode))
list[j++] = vidmodeFromCGDisplayMode(mode);
list[stored++] = vidmodeFromCGDisplayMode(mode);
}
return j;
CFRelease(modes);
return stored;
}
//========================================================================
// Get the desktop video mode
//========================================================================

View File

@ -32,6 +32,8 @@
#include <limits.h>
#include <string.h>
#include <ApplicationServices/ApplicationServices.h>
//************************************************************************
//**** GLFW internal functions ****

View File

@ -27,162 +27,45 @@
//
//========================================================================
// Needed for _NSGetProgname
#include <crt_externs.h>
#include "internal.h"
//========================================================================
// GLFW application class
// Change to our application bundle's resources directory, if present
//========================================================================
@interface GLFWApplication : NSApplication
@end
@implementation GLFWApplication
// From http://cocoadev.com/index.pl?GameKeyboardHandlingAlmost
// This works around an AppKit bug, where key up events while holding
// down the command key don't get sent to the key window.
- (void)sendEvent:(NSEvent *)event
static void changeToResourcesDirectory(void)
{
if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask))
[[self keyWindow] sendEvent:event];
else
[super sendEvent:event];
}
char resourcesPath[MAXPATHLEN];
@end
CFBundleRef bundle = CFBundleGetMainBundle();
if (!bundle)
return;
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(bundle);
// Prior to Snow Leopard, we need to use this oddly-named semi-private API
// to get the application menu working properly. Need to be careful in
// case it goes away in a future OS update.
@interface NSApplication (NSAppleMenu)
- (void)setAppleMenu:(NSMenu*)m;
@end
// Keys to search for as potential application names
NSString* GLFWNameKeys[] =
{
@"CFBundleDisplayName",
@"CFBundleName",
@"CFBundleExecutable",
};
//========================================================================
// Try to figure out what the calling application is called
//========================================================================
static NSString* findAppName(void)
{
unsigned int i;
NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
for (i = 0; i < sizeof(GLFWNameKeys) / sizeof(GLFWNameKeys[0]); i++)
CFStringRef last = CFURLCopyLastPathComponent(resourcesURL);
if (CFStringCompare(CFSTR("Resources"), last, 0) != kCFCompareEqualTo)
{
id name = [infoDictionary objectForKey:GLFWNameKeys[i]];
if (name &&
[name isKindOfClass:[NSString class]] &&
![@"" isEqualToString:name])
{
return name;
}
CFRelease(last);
CFRelease(resourcesURL);
return;
}
// If we get here, we're unbundled
if (!_glfwLibrary.NS.unbundled)
CFRelease(last);
if (!CFURLGetFileSystemRepresentation(resourcesURL,
true,
(UInt8*) resourcesPath,
MAXPATHLEN))
{
// Could do this only if we discover we're unbundled, but it should
// do no harm...
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
// Having the app in front of the terminal window is also generally
// handy. There is an NSApplication API to do this, but...
SetFrontProcess(&psn);
_glfwLibrary.NS.unbundled = GL_TRUE;
CFRelease(resourcesURL);
return;
}
char** progname = _NSGetProgname();
if (progname && *progname)
{
// TODO: UTF-8?
return [NSString stringWithUTF8String:*progname];
}
CFRelease(resourcesURL);
// Really shouldn't get here
return @"GLFW Application";
}
//========================================================================
// Set up the menu bar (manually)
// This is nasty, nasty stuff -- calls to undocumented semi-private APIs that
// could go away at any moment, lots of stuff that really should be
// localize(d|able), etc. Loading a nib would save us this horror, but that
// doesn't seem like a good thing to require of GLFW's clients.
//========================================================================
static void setUpMenuBar(void)
{
NSString* appName = findAppName();
NSMenu* bar = [[NSMenu alloc] init];
[NSApp setMainMenu:bar];
NSMenuItem* appMenuItem =
[bar addItemWithTitle:@"" action:NULL keyEquivalent:@""];
NSMenu* appMenu = [[NSMenu alloc] init];
[appMenuItem setSubmenu:appMenu];
[appMenu addItemWithTitle:[NSString stringWithFormat:@"About %@", appName]
action:@selector(orderFrontStandardAboutPanel:)
keyEquivalent:@""];
[appMenu addItem:[NSMenuItem separatorItem]];
NSMenu* servicesMenu = [[NSMenu alloc] init];
[NSApp setServicesMenu:servicesMenu];
[[appMenu addItemWithTitle:@"Services"
action:NULL
keyEquivalent:@""] setSubmenu:servicesMenu];
[appMenu addItem:[NSMenuItem separatorItem]];
[appMenu addItemWithTitle:[NSString stringWithFormat:@"Hide %@", appName]
action:@selector(hide:)
keyEquivalent:@"h"];
[[appMenu addItemWithTitle:@"Hide Others"
action:@selector(hideOtherApplications:)
keyEquivalent:@"h"]
setKeyEquivalentModifierMask:NSAlternateKeyMask | NSCommandKeyMask];
[appMenu addItemWithTitle:@"Show All"
action:@selector(unhideAllApplications:)
keyEquivalent:@""];
[appMenu addItem:[NSMenuItem separatorItem]];
[appMenu addItemWithTitle:[NSString stringWithFormat:@"Quit %@", appName]
action:@selector(terminate:)
keyEquivalent:@"q"];
NSMenuItem* windowMenuItem =
[bar addItemWithTitle:@"" action:NULL keyEquivalent:@""];
NSMenu* windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
[NSApp setWindowsMenu:windowMenu];
[windowMenuItem setSubmenu:windowMenu];
[windowMenu addItemWithTitle:@"Miniaturize"
action:@selector(performMiniaturize:)
keyEquivalent:@"m"];
[windowMenu addItemWithTitle:@"Zoom"
action:@selector(performZoom:)
keyEquivalent:@""];
[windowMenu addItem:[NSMenuItem separatorItem]];
[windowMenu addItemWithTitle:@"Bring All to Front"
action:@selector(arrangeInFront:)
keyEquivalent:@""];
// At least guard the call to private API to avoid an exception if it
// goes away. Hopefully that means the worst we'll break in future is to
// look ugly...
if ([NSApp respondsToSelector:@selector(setAppleMenu:)])
[NSApp setAppleMenu:appMenu];
chdir(resourcesPath);
}
@ -198,9 +81,6 @@ int _glfwPlatformInit(void)
{
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
// Implicitly create shared NSApplication instance
[GLFWApplication sharedApplication];
_glfwLibrary.NS.OpenGLFramework =
CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
if (_glfwLibrary.NS.OpenGLFramework == NULL)
@ -210,31 +90,30 @@ int _glfwPlatformInit(void)
return GL_FALSE;
}
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
changeToResourcesDirectory();
if (access([resourcePath cStringUsingEncoding:NSUTF8StringEncoding], R_OK) == 0)
chdir([resourcePath cStringUsingEncoding:NSUTF8StringEncoding]);
// Setting up menu bar must go exactly here else weirdness ensues
setUpMenuBar();
[NSApp finishLaunching];
_glfwPlatformSetTime(0.0);
_glfwLibrary.NS.desktopMode =
(NSDictionary*) CGDisplayCurrentMode(CGMainDisplayID());
_glfwLibrary.NS.desktopMode = CGDisplayCopyDisplayMode(CGMainDisplayID());
// Save the original gamma ramp
_glfwLibrary.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID());
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp;
_glfwInitTimer();
_glfwInitJoysticks();
_glfwLibrary.NS.eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
if (!_glfwLibrary.NS.eventSource)
return GL_FALSE;
CGEventSourceSetLocalEventsSuppressionInterval(_glfwLibrary.NS.eventSource,
0.0);
return GL_TRUE;
}
//========================================================================
// Close window, if open, and shut down GLFW
//========================================================================
@ -243,9 +122,17 @@ int _glfwPlatformTerminate(void)
{
// TODO: Probably other cleanup
if (_glfwLibrary.NS.eventSource)
{
CFRelease(_glfwLibrary.NS.eventSource);
_glfwLibrary.NS.eventSource = NULL;
}
// Restore the original gamma ramp
_glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp);
CGDisplayModeRelease(_glfwLibrary.NS.desktopMode);
[NSApp setDelegate:nil];
[_glfwLibrary.NS.delegate release];
_glfwLibrary.NS.delegate = nil;

View File

@ -152,7 +152,7 @@ static void addJoystickElement(_glfwJoystick* joystick, CFTypeRef refElement)
long number;
CFTypeRef refType;
_glfwJoystickElement* element = (_glfwJoystickElement*) _glfwMalloc(sizeof(_glfwJoystickElement));
_glfwJoystickElement* element = (_glfwJoystickElement*) malloc(sizeof(_glfwJoystickElement));
CFArrayAppendValue(elementsArray, element);
@ -232,33 +232,35 @@ static long getElementValue(_glfwJoystick* joystick, _glfwJoystickElement* eleme
static void removeJoystick(_glfwJoystick* joystick)
{
int i;
if (joystick->present)
{
joystick->present = GL_FALSE;
for (int i = 0; i < joystick->numAxes; i++)
for (i = 0; i < joystick->numAxes; i++)
{
_glfwJoystickElement* axes =
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->axes, i);
_glfwFree(axes);
free(axes);
}
CFArrayRemoveAllValues(joystick->axes);
joystick->numAxes = 0;
for (int i = 0; i < joystick->numButtons; i++)
for (i = 0; i < joystick->numButtons; i++)
{
_glfwJoystickElement* button =
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->buttons, i);
_glfwFree(button);
free(button);
}
CFArrayRemoveAllValues(joystick->buttons);
joystick->numButtons = 0;
for (int i = 0; i < joystick->numHats; i++)
for (i = 0; i < joystick->numHats; i++)
{
_glfwJoystickElement* hat =
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->hats, i);
_glfwFree(hat);
free(hat);
}
CFArrayRemoveAllValues(joystick->hats);
joystick->hats = 0;
@ -287,23 +289,26 @@ static void removalCallback(void* target, IOReturn result, void* refcon, void* s
static void pollJoystickEvents(void)
{
for (int i = 0; i < GLFW_JOYSTICK_LAST + 1; i++)
int i;
CFIndex j;
for (i = 0; i < GLFW_JOYSTICK_LAST + 1; i++)
{
_glfwJoystick* joystick = &_glfwJoysticks[i];
if (joystick->present)
{
for (CFIndex i = 0; i < joystick->numButtons; i++)
for (j = 0; j < joystick->numButtons; j++)
{
_glfwJoystickElement* button =
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->buttons, i);
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->buttons, j);
button->value = getElementValue(joystick, button);
}
for (CFIndex i = 0; i < joystick->numAxes; i++)
for (j = 0; j < joystick->numAxes; j++)
{
_glfwJoystickElement* axes =
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->axes, i);
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->axes, j);
axes->value = getElementValue(joystick, axes);
}
}
@ -449,7 +454,9 @@ void _glfwInitJoysticks(void)
void _glfwTerminateJoysticks(void)
{
for (int i = 0; i < GLFW_JOYSTICK_LAST + 1; i++)
int i;
for (i = 0; i < GLFW_JOYSTICK_LAST + 1; i++)
{
_glfwJoystick* joystick = &_glfwJoysticks[i];
removeJoystick(joystick);
@ -498,6 +505,8 @@ int _glfwPlatformGetJoystickParam(int joy, int param)
int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
{
int i;
if (joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_LAST)
return 0;
@ -514,7 +523,7 @@ int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
// Update joystick state
pollJoystickEvents();
for (int i = 0; i < numaxes; i++)
for (i = 0; i < numaxes; i++)
{
_glfwJoystickElement* axes =
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick.axes, i);
@ -543,6 +552,8 @@ int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
int numbuttons)
{
int i;
if (joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_LAST)
return 0;
@ -559,7 +570,7 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
// Update joystick state
pollJoystickEvents();
for (int i = 0; i < numbuttons; i++)
for (i = 0; i < numbuttons; i++)
{
_glfwJoystickElement* button = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick.buttons, i);
buttons[i] = button->value ? GLFW_PRESS : GLFW_RELEASE;
@ -568,4 +579,3 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
return numbuttons;
}

View File

@ -59,6 +59,7 @@ void _glfwPlatformSwapBuffers(void)
[window->NSGL.context flushBuffer];
}
//========================================================================
// Set double buffering swap interval
//========================================================================
@ -71,6 +72,7 @@ void _glfwPlatformSwapInterval(int interval)
[window->NSGL.context setValues:&sync forParameter:NSOpenGLCPSwapInterval];
}
//========================================================================
// Check if an OpenGL extension is available at runtime
//========================================================================
@ -81,6 +83,7 @@ int _glfwPlatformExtensionSupported(const char* extension)
return GL_FALSE;
}
//========================================================================
// Get the function pointer to an OpenGL function
//========================================================================
@ -99,6 +102,7 @@ void* _glfwPlatformGetProcAddress(const char* procname)
return symbol;
}
//========================================================================
// Copies the specified OpenGL state categories from src to dst
//========================================================================

View File

@ -37,6 +37,7 @@
#if defined(__OBJC__)
#import <Cocoa/Cocoa.h>
#else
#include <ApplicationServices/ApplicationServices.h>
typedef void* id;
#endif
@ -85,13 +86,14 @@ typedef struct _GLFWwindowNS
typedef struct _GLFWlibraryNS
{
struct {
double t0;
double base;
double resolution;
} timer;
// dlopen handle for dynamically loading OpenGL extension entry points
void* OpenGLFramework;
GLboolean unbundled;
id desktopMode;
CGDisplayModeRef desktopMode;
CGEventSourceRef eventSource;
id delegate;
id autoreleasePool;
} _GLFWlibraryNS;
@ -101,9 +103,15 @@ typedef struct _GLFWlibraryNS
// Prototypes for platform specific internal functions
//========================================================================
// Time
void _glfwInitTimer(void);
// Joystick input
void _glfwInitJoysticks(void);
void _glfwTerminateJoysticks(void);
// Fullscreen
GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate);
void _glfwRestoreVideoMode(void);
#endif // _platform_h_

View File

@ -29,6 +29,36 @@
#include "internal.h"
#include <mach/mach_time.h>
//========================================================================
// Return raw time
//========================================================================
static uint64_t getRawTime(void)
{
return mach_absolute_time();
}
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Initialise timer
//========================================================================
void _glfwInitTimer(void)
{
mach_timebase_info_data_t info;
mach_timebase_info(&info);
_glfwLibrary.NS.timer.resolution = (double) info.numer / (info.denom * 1.0e9);
_glfwLibrary.NS.timer.base = getRawTime();
}
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
@ -40,17 +70,18 @@
double _glfwPlatformGetTime(void)
{
return [NSDate timeIntervalSinceReferenceDate] -
_glfwLibrary.NS.timer.t0;
return (double) (getRawTime() - _glfwLibrary.NS.timer.base) *
_glfwLibrary.NS.timer.resolution;
}
//========================================================================
// Set timer value in seconds
//========================================================================
void _glfwPlatformSetTime(double time)
{
_glfwLibrary.NS.timer.t0 =
[NSDate timeIntervalSinceReferenceDate] - time;
_glfwLibrary.NS.timer.base = getRawTime() -
(uint64_t) (time / _glfwLibrary.NS.timer.resolution);
}

View File

@ -29,6 +29,9 @@
#include "internal.h"
// Needed for _NSGetProgname
#include <crt_externs.h>
//========================================================================
// Delegate for window related notifications
@ -109,6 +112,7 @@
@end
//========================================================================
// Delegate for application related notifications
//========================================================================
@ -130,13 +134,17 @@
@end
//========================================================================
// Keyboard symbol translation table
// Converts a Mac OS X keycode to a GLFW keycode
//========================================================================
// TODO: Need to find mappings for F13-F15, volume down/up/mute, and eject.
static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
static int convertMacKeyCode(unsigned int macKeyCode)
{
// Keyboard symbol translation table
// TODO: Need to find mappings for F13-F15, volume down/up/mute, and eject.
static const unsigned int table[128] =
{
/* 00 */ GLFW_KEY_A,
/* 01 */ GLFW_KEY_S,
/* 02 */ GLFW_KEY_D,
@ -147,7 +155,7 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
/* 07 */ GLFW_KEY_X,
/* 08 */ GLFW_KEY_C,
/* 09 */ GLFW_KEY_V,
/* 0a */ -1,
/* 0a */ GLFW_KEY_GRAVE_ACCENT,
/* 0b */ GLFW_KEY_B,
/* 0c */ GLFW_KEY_Q,
/* 0d */ GLFW_KEY_W,
@ -187,7 +195,7 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
/* 2f */ GLFW_KEY_PERIOD,
/* 30 */ GLFW_KEY_TAB,
/* 31 */ GLFW_KEY_SPACE,
/* 32 */ GLFW_KEY_GRAVE_ACCENT,
/* 32 */ GLFW_KEY_WORLD_1,
/* 33 */ GLFW_KEY_BACKSPACE,
/* 34 */ -1,
/* 35 */ GLFW_KEY_ESCAPE,
@ -265,23 +273,18 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
/* 7d */ GLFW_KEY_DOWN,
/* 7e */ GLFW_KEY_UP,
/* 7f */ -1,
};
};
//========================================================================
// Converts a Mac OS X keycode to a GLFW keycode
//========================================================================
static int convertMacKeyCode(unsigned int macKeyCode)
{
if (macKeyCode >= 128)
return -1;
// This treats keycodes as *positional*; that is, we'll return 'a'
// for the key left of 's', even on an AZERTY keyboard. The charInput
// function should still get 'q' though.
return MAC_TO_GLFW_KEYCODE_MAPPING[macKeyCode];
return table[macKeyCode];
}
//========================================================================
// Content view class for the GLFW window
//========================================================================
@ -385,15 +388,15 @@ static int convertMacKeyCode(unsigned int macKeyCode)
{
NSUInteger i, length;
NSString* characters;
int code = convertMacKeyCode([event keyCode]);
int key = convertMacKeyCode([event keyCode]);
if (code != -1)
if (key != -1)
{
_glfwInputKey(window, code, GLFW_PRESS);
_glfwInputKey(window, key, GLFW_PRESS);
if ([event modifierFlags] & NSCommandKeyMask)
{
if (!window->sysKeysDisabled)
if (window->systemKeys)
[super keyDown:event];
}
else
@ -409,7 +412,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
- (void)flagsChanged:(NSEvent *)event
{
int mode;
int mode, key;
unsigned int newModifierFlags =
[event modifierFlags] | NSDeviceIndependentModifierFlagsMask;
@ -419,14 +422,17 @@ static int convertMacKeyCode(unsigned int macKeyCode)
mode = GLFW_RELEASE;
window->NS.modifierFlags = newModifierFlags;
_glfwInputKey(window, MAC_TO_GLFW_KEYCODE_MAPPING[[event keyCode]], mode);
key = convertMacKeyCode([event keyCode]);
if (key != -1)
_glfwInputKey(window, key, mode);
}
- (void)keyUp:(NSEvent *)event
{
int code = convertMacKeyCode([event keyCode]);
if (code != -1)
_glfwInputKey(window, code, GLFW_RELEASE);
int key = convertMacKeyCode([event keyCode]);
if (key != -1)
_glfwInputKey(window, key, GLFW_RELEASE);
}
- (void)scrollWheel:(NSEvent *)event
@ -444,19 +450,229 @@ static int convertMacKeyCode(unsigned int macKeyCode)
@end
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Here is where the window is created, and the OpenGL rendering context is
// created
// GLFW application class
//========================================================================
int _glfwPlatformOpenWindow(_GLFWwindow* window,
const _GLFWwndconfig *wndconfig,
const _GLFWfbconfig *fbconfig)
@interface GLFWApplication : NSApplication
@end
@implementation GLFWApplication
// From http://cocoadev.com/index.pl?GameKeyboardHandlingAlmost
// This works around an AppKit bug, where key up events while holding
// down the command key don't get sent to the key window.
- (void)sendEvent:(NSEvent *)event
{
if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask))
[[self keyWindow] sendEvent:event];
else
[super sendEvent:event];
}
@end
//========================================================================
// Try to figure out what the calling application is called
//========================================================================
static NSString* findAppName(void)
{
unsigned int i;
NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
// Keys to search for as potential application names
NSString* GLFWNameKeys[] =
{
@"CFBundleDisplayName",
@"CFBundleName",
@"CFBundleExecutable",
};
for (i = 0; i < sizeof(GLFWNameKeys) / sizeof(GLFWNameKeys[0]); i++)
{
id name = [infoDictionary objectForKey:GLFWNameKeys[i]];
if (name &&
[name isKindOfClass:[NSString class]] &&
![@"" isEqualToString:name])
{
return name;
}
}
// If we get here, we're unbundled
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
// Having the app in front of the terminal window is also generally
// handy. There is an NSApplication API to do this, but...
SetFrontProcess(&psn);
char** progname = _NSGetProgname();
if (progname && *progname)
{
// TODO: UTF-8?
return [NSString stringWithUTF8String:*progname];
}
// Really shouldn't get here
return @"GLFW Application";
}
//========================================================================
// Set up the menu bar (manually)
// This is nasty, nasty stuff -- calls to undocumented semi-private APIs that
// could go away at any moment, lots of stuff that really should be
// localize(d|able), etc. Loading a nib would save us this horror, but that
// doesn't seem like a good thing to require of GLFW's clients.
//========================================================================
static void createMenuBar(void)
{
NSString* appName = findAppName();
NSMenu* bar = [[NSMenu alloc] init];
[NSApp setMainMenu:bar];
NSMenuItem* appMenuItem =
[bar addItemWithTitle:@"" action:NULL keyEquivalent:@""];
NSMenu* appMenu = [[NSMenu alloc] init];
[appMenuItem setSubmenu:appMenu];
[appMenu addItemWithTitle:[NSString stringWithFormat:@"About %@", appName]
action:@selector(orderFrontStandardAboutPanel:)
keyEquivalent:@""];
[appMenu addItem:[NSMenuItem separatorItem]];
NSMenu* servicesMenu = [[NSMenu alloc] init];
[NSApp setServicesMenu:servicesMenu];
[[appMenu addItemWithTitle:@"Services"
action:NULL
keyEquivalent:@""] setSubmenu:servicesMenu];
[appMenu addItem:[NSMenuItem separatorItem]];
[appMenu addItemWithTitle:[NSString stringWithFormat:@"Hide %@", appName]
action:@selector(hide:)
keyEquivalent:@"h"];
[[appMenu addItemWithTitle:@"Hide Others"
action:@selector(hideOtherApplications:)
keyEquivalent:@"h"]
setKeyEquivalentModifierMask:NSAlternateKeyMask | NSCommandKeyMask];
[appMenu addItemWithTitle:@"Show All"
action:@selector(unhideAllApplications:)
keyEquivalent:@""];
[appMenu addItem:[NSMenuItem separatorItem]];
[appMenu addItemWithTitle:[NSString stringWithFormat:@"Quit %@", appName]
action:@selector(terminate:)
keyEquivalent:@"q"];
NSMenuItem* windowMenuItem =
[bar addItemWithTitle:@"" action:NULL keyEquivalent:@""];
NSMenu* windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
[NSApp setWindowsMenu:windowMenu];
[windowMenuItem setSubmenu:windowMenu];
[windowMenu addItemWithTitle:@"Miniaturize"
action:@selector(performMiniaturize:)
keyEquivalent:@"m"];
[windowMenu addItemWithTitle:@"Zoom"
action:@selector(performZoom:)
keyEquivalent:@""];
[windowMenu addItem:[NSMenuItem separatorItem]];
[windowMenu addItemWithTitle:@"Bring All to Front"
action:@selector(arrangeInFront:)
keyEquivalent:@""];
// Prior to Snow Leopard, we need to use this oddly-named semi-private API
// to get the application menu working properly.
[NSApp performSelector:@selector(setAppleMenu:) withObject:appMenu];
}
//========================================================================
// Initialize the Cocoa Application Kit
//========================================================================
static GLboolean initializeAppKit(void)
{
if (NSApp)
return GL_TRUE;
// Implicitly create shared NSApplication instance
[GLFWApplication sharedApplication];
// Setting up the menu bar must go between sharedApplication
// above and finishLaunching below, in order to properly emulate the
// behavior of NSApplicationMain
createMenuBar();
[NSApp finishLaunching];
return GL_TRUE;
}
//========================================================================
// Create the Cocoa window
//========================================================================
static GLboolean createWindow(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig)
{
unsigned int styleMask = 0;
if (wndconfig->mode == GLFW_WINDOWED)
{
styleMask = NSTitledWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask;
if (wndconfig->resizable)
styleMask |= NSResizableWindowMask;
}
else
styleMask = NSBorderlessWindowMask;
window->NS.window = [[NSWindow alloc]
initWithContentRect:NSMakeRect(0, 0, window->width, window->height)
styleMask:styleMask
backing:NSBackingStoreBuffered
defer:NO];
if (window->NS.window == nil)
{
_glfwSetError(GLFW_PLATFORM_ERROR,
"Cocoa/NSOpenGL: Failed to create window");
return GL_FALSE;
}
[window->NS.window setTitle:[NSString stringWithUTF8String:wndconfig->title]];
[window->NS.window setContentView:[[GLFWContentView alloc]
initWithGlfwWindow:window]];
[window->NS.window setDelegate:window->NS.delegate];
[window->NS.window setAcceptsMouseMovedEvents:YES];
[window->NS.window center];
return GL_TRUE;
}
//========================================================================
// Create the OpenGL context
//========================================================================
static GLboolean createContext(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig,
const _GLFWfbconfig* fbconfig)
{
unsigned int attributeCount = 0;
// Mac OS X needs non-zero color size, so set resonable values
int colorBits = fbconfig->redBits + fbconfig->greenBits + fbconfig->blueBits;
if (colorBits == 0)
colorBits = 24;
else if (colorBits < 15)
colorBits = 15;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
// Fail if any OpenGL version above 2.1 other than 3.2 was requested
if (wndconfig->glMajor > 3 ||
@ -468,14 +684,23 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
return GL_FALSE;
}
if (wndconfig->glProfile)
if (wndconfig->glMajor > 2)
{
// Fail if a profile other than core was explicitly selected
if (!wndconfig->glForward)
{
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
"Cocoa/NSOpenGL: The targeted version of Mac OS X "
"only supports OpenGL 3.2 contexts if they are "
"forward-compatible");
return GL_FALSE;
}
if (wndconfig->glProfile != GLFW_OPENGL_CORE_PROFILE)
{
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
"Cocoa/NSOpenGL: The targeted version of Mac OS X "
"only supports the OpenGL core profile");
"only supports OpenGL 3.2 contexts if they use the "
"core profile");
return GL_FALSE;
}
}
@ -499,6 +724,106 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
return GL_FALSE;
}
#define ADD_ATTR(x) { attributes[attributeCount++] = x; }
#define ADD_ATTR2(x, y) { ADD_ATTR(x); ADD_ATTR(y); }
// Arbitrary array size here
NSOpenGLPixelFormatAttribute attributes[24];
ADD_ATTR(NSOpenGLPFADoubleBuffer);
if (wndconfig->mode == GLFW_FULLSCREEN)
{
ADD_ATTR(NSOpenGLPFANoRecovery);
ADD_ATTR2(NSOpenGLPFAScreenMask,
CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()));
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
if (wndconfig->glMajor > 2)
ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
ADD_ATTR2(NSOpenGLPFAColorSize, colorBits);
if (fbconfig->alphaBits > 0)
ADD_ATTR2(NSOpenGLPFAAlphaSize, fbconfig->alphaBits);
if (fbconfig->depthBits > 0)
ADD_ATTR2(NSOpenGLPFADepthSize, fbconfig->depthBits);
if (fbconfig->stencilBits > 0)
ADD_ATTR2(NSOpenGLPFAStencilSize, fbconfig->stencilBits);
int accumBits = fbconfig->accumRedBits + fbconfig->accumGreenBits +
fbconfig->accumBlueBits + fbconfig->accumAlphaBits;
if (accumBits > 0)
ADD_ATTR2(NSOpenGLPFAAccumSize, accumBits);
if (fbconfig->auxBuffers > 0)
ADD_ATTR2(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers);
if (fbconfig->stereo)
ADD_ATTR(NSOpenGLPFAStereo);
if (fbconfig->samples > 0)
{
ADD_ATTR2(NSOpenGLPFASampleBuffers, 1);
ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples);
}
ADD_ATTR(0);
#undef ADD_ATTR
#undef ADD_ATTR2
window->NSGL.pixelFormat =
[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
if (window->NSGL.pixelFormat == nil)
{
_glfwSetError(GLFW_PLATFORM_ERROR,
"Cocoa/NSOpenGL: Failed to create OpenGL pixel format");
return GL_FALSE;
}
NSOpenGLContext* share = NULL;
if (wndconfig->share)
share = wndconfig->share->NSGL.context;
window->NSGL.context =
[[NSOpenGLContext alloc] initWithFormat:window->NSGL.pixelFormat
shareContext:share];
if (window->NSGL.context == nil)
{
_glfwSetError(GLFW_PLATFORM_ERROR,
"Cocoa/NSOpenGL: Failed to create OpenGL context");
return GL_FALSE;
}
return GL_TRUE;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Here is where the window is created, and the OpenGL rendering context is
// created
//========================================================================
int _glfwPlatformOpenWindow(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig,
const _GLFWfbconfig* fbconfig)
{
if (!initializeAppKit())
return GL_FALSE;
window->resizable = wndconfig->resizable;
// We can only have one application delegate, but we only allocate it the
// first time we create a window to keep all window code in this file
if (_glfwLibrary.NS.delegate == nil)
@ -530,157 +855,30 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
else if (colorBits < 15)
colorBits = 15;
// Ignored hints:
// OpenGLMajor, OpenGLMinor, OpenGLForward:
// pending Mac OS X support for OpenGL 3.x
// OpenGLDebug
// pending it meaning anything on Mac OS X
// Don't use accumulation buffer support; it's not accelerated
// Aux buffers probably aren't accelerated either
CFDictionaryRef fullscreenMode = NULL;
if (wndconfig->mode == GLFW_FULLSCREEN)
{
// I think it's safe to pass 0 to the refresh rate for this function
// rather than conditionalizing the code to call the version which
// doesn't specify refresh...
fullscreenMode =
CGDisplayBestModeForParametersAndRefreshRateWithProperty(
CGMainDisplayID(),
colorBits + fbconfig->alphaBits,
window->width, window->height,
wndconfig->refreshRate,
// Controversial, see macosx_fullscreen.m for discussion
kCGDisplayModeIsSafeForHardware,
NULL);
window->width =
[[(id)fullscreenMode objectForKey:(id)kCGDisplayWidth] intValue];
window->height =
[[(id)fullscreenMode objectForKey:(id)kCGDisplayHeight] intValue];
}
unsigned int styleMask = 0;
if (wndconfig->mode == GLFW_WINDOWED)
{
styleMask = NSTitledWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask;
if (wndconfig->resizable)
styleMask |= NSResizableWindowMask;
}
else
styleMask = NSBorderlessWindowMask;
window->NS.window = [[NSWindow alloc]
initWithContentRect:NSMakeRect(0, 0, window->width, window->height)
styleMask:styleMask
backing:NSBackingStoreBuffered
defer:NO];
[window->NS.window setTitle:[NSString stringWithCString:wndconfig->title
encoding:NSISOLatin1StringEncoding]];
[window->NS.window setContentView:[[GLFWContentView alloc] initWithGlfwWindow:window]];
[window->NS.window setDelegate:window->NS.delegate];
[window->NS.window setAcceptsMouseMovedEvents:YES];
[window->NS.window center];
if (wndconfig->mode == GLFW_FULLSCREEN)
{
CGCaptureAllDisplays();
CGDisplaySwitchToMode(CGMainDisplayID(), fullscreenMode);
}
unsigned int attribute_count = 0;
#define ADD_ATTR(x) { attributes[attribute_count++] = x; }
#define ADD_ATTR2(x, y) { ADD_ATTR(x); ADD_ATTR(y); }
// Arbitrary array size here
NSOpenGLPixelFormatAttribute attributes[24];
ADD_ATTR(NSOpenGLPFADoubleBuffer);
if (wndconfig->mode == GLFW_FULLSCREEN)
{
ADD_ATTR(NSOpenGLPFAFullScreen);
ADD_ATTR(NSOpenGLPFANoRecovery);
ADD_ATTR2(NSOpenGLPFAScreenMask,
CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()));
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
if (wndconfig->glMajor > 2)
ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
ADD_ATTR2(NSOpenGLPFAColorSize, colorBits);
if (fbconfig->alphaBits > 0)
ADD_ATTR2(NSOpenGLPFAAlphaSize, fbconfig->alphaBits);
if (fbconfig->depthBits > 0)
ADD_ATTR2(NSOpenGLPFADepthSize, fbconfig->depthBits);
if (fbconfig->stencilBits > 0)
ADD_ATTR2(NSOpenGLPFAStencilSize, fbconfig->stencilBits);
int accumBits = fbconfig->accumRedBits + fbconfig->accumGreenBits +
fbconfig->accumBlueBits + fbconfig->accumAlphaBits;
if (accumBits > 0)
ADD_ATTR2(NSOpenGLPFAAccumSize, accumBits);
if (fbconfig->auxBuffers > 0)
ADD_ATTR2(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers);
if (fbconfig->stereo)
ADD_ATTR(NSOpenGLPFAStereo );
if (fbconfig->samples > 0)
{
ADD_ATTR2(NSOpenGLPFASampleBuffers, 1);
ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples);
}
ADD_ATTR(0);
#undef ADD_ATTR
#undef ADD_ATTR2
window->NSGL.pixelFormat =
[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
if (window->NSGL.pixelFormat == nil)
{
_glfwSetError(GLFW_PLATFORM_ERROR,
"Cocoa/NSOpenGL: Failed to create pixel format");
if (!createWindow(window, wndconfig))
return GL_FALSE;
}
NSOpenGLContext* share = NULL;
if (wndconfig->share)
share = wndconfig->share->NSGL.context;
window->NSGL.context =
[[NSOpenGLContext alloc] initWithFormat:window->NSGL.pixelFormat
shareContext:share];
if (window->NSGL.context == nil)
{
_glfwSetError(GLFW_PLATFORM_ERROR,
"Cocoa/NSOpenGL: Failed to create OpenGL context");
if (!createContext(window, wndconfig, fbconfig))
return GL_FALSE;
}
[window->NS.window makeKeyAndOrderFront:nil];
[window->NSGL.context setView:[window->NS.window contentView]];
if (wndconfig->mode == GLFW_FULLSCREEN)
{
// TODO: Make this work on pre-Leopard systems
int bpp = colorBits + fbconfig->alphaBits;
if (!_glfwSetVideoMode(&window->width,
&window->height,
&bpp,
&window->refreshRate))
{
return GL_FALSE;
}
[[window->NS.window contentView] enterFullScreenMode:[NSScreen mainScreen]
withOptions:nil];
}
@ -709,9 +907,7 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
{
[[window->NS.window contentView] exitFullScreenModeWithOptions:nil];
CGDisplaySwitchToMode(CGMainDisplayID(),
(CFDictionaryRef) _glfwLibrary.NS.desktopMode);
CGReleaseAllDisplays();
_glfwRestoreVideoMode();
}
[window->NSGL.pixelFormat release];
@ -731,16 +927,17 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
// TODO: Probably more cleanup
}
//========================================================================
// Set the window title
//========================================================================
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
{
[window->NS.window setTitle:[NSString stringWithCString:title
encoding:NSISOLatin1StringEncoding]];
[window->NS.window setTitle:[NSString stringWithUTF8String:title]];
}
//========================================================================
// Set the window size
//========================================================================
@ -750,6 +947,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
[window->NS.window setContentSize:NSMakeSize(width, height)];
}
//========================================================================
// Set the window position
//========================================================================
@ -770,6 +968,7 @@ void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y)
display:YES];
}
//========================================================================
// Iconify the window
//========================================================================
@ -779,6 +978,7 @@ void _glfwPlatformIconifyWindow(_GLFWwindow* window)
[window->NS.window miniaturize:nil];
}
//========================================================================
// Restore (un-iconify) the window
//========================================================================
@ -788,6 +988,7 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
[window->NS.window deminiaturize:nil];
}
//========================================================================
// Write back window parameters into GLFW window structure
//========================================================================
@ -862,6 +1063,7 @@ void _glfwPlatformRefreshWindowParams(void)
window->glDebug = GL_FALSE;
}
//========================================================================
// Poll for new window and input events
//========================================================================
@ -886,6 +1088,7 @@ void _glfwPlatformPollEvents(void)
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
}
//========================================================================
// Wait for new window and input events
//========================================================================
@ -904,6 +1107,7 @@ void _glfwPlatformWaitEvents( void )
_glfwPlatformPollEvents();
}
//========================================================================
// Set physical mouse cursor position
//========================================================================
@ -921,11 +1125,6 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y)
// calculating the maximum y coordinate of all screens, since Cocoa's
// "global coordinates" are upside down from CG's...
// Without this (once per app run, but it's convenient to do it here)
// events will be suppressed for a default of 0.25 seconds after we
// move the cursor.
CGSetLocalEventsSuppressionInterval(0.0);
NSPoint localPoint = NSMakePoint(x, y);
NSPoint globalPoint = [window->NS.window convertBaseToScreen:localPoint];
CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin;
@ -936,6 +1135,7 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y)
CGDisplayMoveCursorToPoint(CGMainDisplayID(), targetPoint);
}
//========================================================================
// Set physical mouse cursor mode
//========================================================================

View File

@ -60,11 +60,6 @@
// Define this to 1 if the Linux joystick API is available
#cmakedefine _GLFW_USE_LINUX_JOYSTICKS 1
// Define this to 1 to not load gdi32.dll dynamically
#cmakedefine _GLFW_NO_DLOAD_GDI32 1
// Define this to 1 to not load winmm.dll dynamically
#cmakedefine _GLFW_NO_DLOAD_WINMM 1
// The GLFW version as used by glfwGetVersionString
#define _GLFW_VERSION_FULL "@GLFW_VERSION_FULL@"

View File

@ -1,192 +0,0 @@
//========================================================================
// GLFW - An OpenGL library
// Platform: Any
// 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"
//========================================================================
// Enable and disable sticky keys mode
//========================================================================
static void enableStickyKeys(_GLFWwindow* window)
{
window->stickyKeys = GL_TRUE;
}
static void disableStickyKeys(_GLFWwindow* window)
{
int i;
window->stickyKeys = GL_FALSE;
// Release all sticky keys
for (i = 0; i <= GLFW_KEY_LAST; i++)
{
if (window->key[i] == GLFW_STICK)
window->key[i] = GLFW_RELEASE;
}
}
//========================================================================
// Enable and disable sticky mouse buttons mode
//========================================================================
static void enableStickyMouseButtons(_GLFWwindow* window)
{
window->stickyMouseButtons = GL_TRUE;
}
static void disableStickyMouseButtons(_GLFWwindow* window)
{
int i;
window->stickyMouseButtons = GL_FALSE;
// Release all sticky mouse buttons
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
{
if (window->mouseButton[i] == GLFW_STICK)
window->mouseButton[i] = GLFW_RELEASE;
}
}
//========================================================================
// Enable and disable system keys
//========================================================================
static void enableSystemKeys(_GLFWwindow* window)
{
if (!window->sysKeysDisabled)
return;
_glfwPlatformEnableSystemKeys(window);
// Indicate that system keys are no longer disabled
window->sysKeysDisabled = GL_FALSE;
}
static void disableSystemKeys(_GLFWwindow* window)
{
if (window->sysKeysDisabled)
return;
_glfwPlatformDisableSystemKeys(window);
// Indicate that system keys are now disabled
window->sysKeysDisabled = GL_TRUE;
}
//========================================================================
// Enable and disable key repeat
//========================================================================
static void enableKeyRepeat(_GLFWwindow* window)
{
window->keyRepeat = GL_TRUE;
}
static void disableKeyRepeat(_GLFWwindow* window)
{
window->keyRepeat = GL_FALSE;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW public API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Enable certain GLFW/window/system functions
//========================================================================
GLFWAPI void glfwEnable(GLFWwindow window, int token)
{
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
switch (token)
{
case GLFW_STICKY_KEYS:
enableStickyKeys(window);
break;
case GLFW_STICKY_MOUSE_BUTTONS:
enableStickyMouseButtons(window);
break;
case GLFW_SYSTEM_KEYS:
enableSystemKeys(window);
break;
case GLFW_KEY_REPEAT:
enableKeyRepeat(window);
break;
default:
_glfwSetError(GLFW_INVALID_ENUM, NULL);
break;
}
}
//========================================================================
// Disable certain GLFW/window/system functions
//========================================================================
GLFWAPI void glfwDisable(GLFWwindow window, int token)
{
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
switch (token)
{
case GLFW_STICKY_KEYS:
disableStickyKeys(window);
break;
case GLFW_STICKY_MOUSE_BUTTONS:
disableStickyMouseButtons(window);
break;
case GLFW_SYSTEM_KEYS:
disableSystemKeys(window);
break;
case GLFW_KEY_REPEAT:
disableKeyRepeat(window);
break;
default:
_glfwSetError(GLFW_INVALID_ENUM, NULL);
break;
}
}

View File

@ -35,30 +35,6 @@
#include <stdlib.h>
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Allocate memory using the allocator
//========================================================================
void* _glfwMalloc(size_t size)
{
return _glfwLibrary.allocator.malloc(size);
}
//========================================================================
// Free memory using the allocator
//========================================================================
void _glfwFree(void* ptr)
{
_glfwLibrary.allocator.free(ptr);
}
//////////////////////////////////////////////////////////////////////////
////// GLFW public API //////
//////////////////////////////////////////////////////////////////////////
@ -68,43 +44,12 @@ void _glfwFree(void* ptr)
//========================================================================
GLFWAPI int glfwInit(void)
{
return glfwInitWithModels(NULL, NULL);
}
//========================================================================
// Initialize various GLFW state using custom model interfaces
//========================================================================
GLFWAPI int glfwInitWithModels(GLFWthreadmodel* threading, GLFWallocator* allocator)
{
if (_glfwInitialized)
return GL_TRUE;
memset(&_glfwLibrary, 0, sizeof(_glfwLibrary));
if (threading)
_glfwLibrary.threading = *threading;
if (allocator)
{
// Verify that the specified model is complete
if (!allocator->malloc || !allocator->free)
{
_glfwSetError(GLFW_INVALID_VALUE, NULL);
return GL_FALSE;
}
_glfwLibrary.allocator = *allocator;
}
else
{
// Use the libc malloc and free
_glfwLibrary.allocator.malloc = malloc;
_glfwLibrary.allocator.free = free;
}
// Not all window hints have zero as their default value, so this
// needs to be here despite the memset above
_glfwSetDefaultWindowHints();

View File

@ -31,6 +31,122 @@
#include "internal.h"
//========================================================================
// Sets the cursor mode for the specified window
//========================================================================
static void setCursorMode(_GLFWwindow* window, int mode)
{
int centerPosX, centerPosY;
if (mode != GLFW_CURSOR_NORMAL &&
mode != GLFW_CURSOR_HIDDEN &&
mode != GLFW_CURSOR_CAPTURED)
{
_glfwSetError(GLFW_INVALID_ENUM, NULL);
return;
}
if (window->cursorMode == mode)
return;
centerPosX = window->width / 2;
centerPosY = window->height / 2;
if (mode == GLFW_CURSOR_CAPTURED)
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
_glfwInputCursorMotion(window,
centerPosX - window->cursorPosX,
centerPosY - window->cursorPosY);
}
_glfwPlatformSetCursorMode(window, mode);
window->cursorMode = mode;
}
//========================================================================
// Set sticky keys mode for the specified window
//========================================================================
static void setStickyKeys(_GLFWwindow* window, int enabled)
{
if (window->stickyKeys == enabled)
return;
if (!enabled)
{
int i;
// Release all sticky keys
for (i = 0; i <= GLFW_KEY_LAST; i++)
{
if (window->key[i] == GLFW_STICK)
window->key[i] = GLFW_RELEASE;
}
}
window->stickyKeys = enabled;
}
//========================================================================
// Set sticky mouse buttons mode for the specified window
//========================================================================
static void setStickyMouseButtons(_GLFWwindow* window, int enabled)
{
if (window->stickyMouseButtons == enabled)
return;
if (!enabled)
{
int i;
// Release all sticky mouse buttons
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
{
if (window->mouseButton[i] == GLFW_STICK)
window->mouseButton[i] = GLFW_RELEASE;
}
}
window->stickyMouseButtons = enabled;
}
//========================================================================
// Set system keys for the specified window
//========================================================================
static void setSystemKeys(_GLFWwindow* window, int enabled)
{
if (window->systemKeys == enabled)
return;
if (enabled)
_glfwPlatformEnableSystemKeys(window);
else
_glfwPlatformDisableSystemKeys(window);
window->systemKeys = enabled;
}
//========================================================================
// Set key repeat for the specified window
//========================================================================
static void setKeyRepeat(_GLFWwindow* window, int enabled)
{
window->keyRepeat = enabled;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
@ -41,7 +157,7 @@
void _glfwInputKey(_GLFWwindow* window, int key, int action)
{
GLboolean keyrepeat = GL_FALSE;
GLboolean repeated = GL_FALSE;
if (key < 0 || key > GLFW_KEY_LAST)
return;
@ -51,16 +167,16 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action)
return;
// Register key action
if(action == GLFW_RELEASE && window->stickyKeys)
if (action == GLFW_RELEASE && window->stickyKeys)
window->key[key] = GLFW_STICK;
else
{
keyrepeat = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS);
repeated = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS);
window->key[key] = (char) action;
}
// Call user callback function
if (_glfwLibrary.keyCallback && (window->keyRepeat || !keyrepeat))
if (_glfwLibrary.keyCallback && (window->keyRepeat || !repeated))
_glfwLibrary.keyCallback(window, key, action);
}
@ -161,6 +277,77 @@ void _glfwInputCursorEnter(_GLFWwindow* window, int entered)
////// GLFW public API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Returns the specified input mode of the specified window
//========================================================================
GLFWAPI int glfwGetInputMode(GLFWwindow handle, int mode)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
switch (mode)
{
case GLFW_CURSOR_MODE:
return window->cursorMode;
case GLFW_STICKY_KEYS:
return window->stickyKeys;
case GLFW_STICKY_MOUSE_BUTTONS:
return window->stickyMouseButtons;
case GLFW_SYSTEM_KEYS:
return window->systemKeys;
case GLFW_KEY_REPEAT:
return window->keyRepeat;
default:
_glfwSetError(GLFW_INVALID_ENUM, NULL);
return 0;
}
}
//========================================================================
// Sets the specified input mode of the specified window
//========================================================================
GLFWAPI void glfwSetInputMode(GLFWwindow handle, int mode, int value)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
switch (mode)
{
case GLFW_CURSOR_MODE:
setCursorMode(window, value);
break;
case GLFW_STICKY_KEYS:
setStickyKeys(window, value ? GL_TRUE : GL_FALSE);
break;
case GLFW_STICKY_MOUSE_BUTTONS:
setStickyMouseButtons(window, value ? GL_TRUE : GL_FALSE);
break;
case GLFW_SYSTEM_KEYS:
setSystemKeys(window, value ? GL_TRUE : GL_FALSE);
break;
case GLFW_KEY_REPEAT:
setKeyRepeat(window, value ? GL_TRUE : GL_FALSE);
break;
default:
_glfwSetError(GLFW_INVALID_ENUM, NULL);
break;
}
}
//========================================================================
// Returns the state of the specified key for the specified window
//========================================================================
@ -175,10 +362,8 @@ GLFWAPI int glfwGetKey(GLFWwindow handle, int key)
return GLFW_RELEASE;
}
// Is it a valid key?
if (key < 0 || key > GLFW_KEY_LAST)
{
// TODO: Decide whether key is a value or enum
_glfwSetError(GLFW_INVALID_ENUM,
"glfwGetKey: The specified key is invalid");
return GLFW_RELEASE;
@ -209,7 +394,6 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow handle, int button)
return GLFW_RELEASE;
}
// Is it a valid mouse button?
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
{
_glfwSetError(GLFW_INVALID_ENUM,
@ -242,7 +426,6 @@ GLFWAPI void glfwGetMousePos(GLFWwindow handle, int* xpos, int* ypos)
return;
}
// Return mouse position
if (xpos != NULL)
*xpos = window->cursorPosX;
@ -311,51 +494,6 @@ GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, int* xoffset, int* yoffset)
}
//========================================================================
// Sets the cursor mode for the specified window
//========================================================================
GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode)
{
int centerPosX, centerPosY;
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (mode != GLFW_CURSOR_NORMAL &&
mode != GLFW_CURSOR_HIDDEN &&
mode != GLFW_CURSOR_CAPTURED)
{
_glfwSetError(GLFW_INVALID_ENUM, NULL);
return;
}
if (window->cursorMode == mode)
return;
centerPosX = window->width / 2;
centerPosY = window->height / 2;
if (mode == GLFW_CURSOR_CAPTURED)
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
_glfwInputCursorMotion(window,
centerPosX - window->cursorPosX,
centerPosY - window->cursorPosY);
}
_glfwPlatformSetCursorMode(window, mode);
window->cursorMode = mode;
}
//========================================================================
// Set callback function for keyboard input
//========================================================================
@ -416,7 +554,6 @@ GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun)
return;
}
// Set callback function
_glfwLibrary.mousePosCallback = cbfun;
// Call the callback function to let the application know the current
@ -459,7 +596,6 @@ GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun)
return;
}
// Set callback function
_glfwLibrary.scrollCallback = cbfun;
}

View File

@ -37,9 +37,9 @@
//========================================================================
#if defined(_init_c_)
#define GLFWGLOBAL
#define GLFWGLOBAL
#else
#define GLFWGLOBAL extern
#define GLFWGLOBAL extern
#endif
@ -66,13 +66,13 @@
#include "../support/GL/glext.h"
#if defined(_GLFW_COCOA_NSGL)
#include "cocoa_platform.h"
#include "cocoa_platform.h"
#elif defined(_GLFW_WIN32_WGL)
#include "win32_platform.h"
#include "win32_platform.h"
#elif defined(_GLFW_X11_GLX)
#include "x11_platform.h"
#include "x11_platform.h"
#else
#error "No supported platform selected"
#error "No supported platform selected"
#endif
typedef struct _GLFWhints _GLFWhints;
@ -183,7 +183,7 @@ struct _GLFWwindow
GLboolean stickyKeys;
GLboolean stickyMouseButtons;
GLboolean keyRepeat;
GLboolean sysKeysDisabled; // system keys disabled flag
GLboolean systemKeys; // system keys enabled flag
int cursorPosX, cursorPosY;
int cursorMode;
int scrollX, scrollY;
@ -242,9 +242,6 @@ struct _GLFWlibrary
GLFWkeyfun keyCallback;
GLFWcharfun charCallback;
GLFWthreadmodel threading;
GLFWallocator allocator;
GLFWgammaramp currentRamp;
GLFWgammaramp originalRamp;
int originalRampSize;
@ -277,7 +274,7 @@ int _glfwPlatformInit(void);
int _glfwPlatformTerminate(void);
const char* _glfwPlatformGetVersionString(void);
// Enable/Disable
// Input
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window);
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window);
@ -327,10 +324,6 @@ void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long
// Prototypes for platform independent internal functions
//========================================================================
// Memory management (init.c)
void* _glfwMalloc(size_t size);
void _glfwFree(void* ptr);
// Fullscren management (fullscreen.c)
void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
@ -340,14 +333,14 @@ void _glfwSetError(int error, const char* description);
// Window management (window.c)
void _glfwSetDefaultWindowHints(void);
// WIndow event notification
// Window event notification (window.c)
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 _glfwInputWindowDamage(_GLFWwindow* window);
// Input event notification
// Input event notification (input.c)
void _glfwInputKey(_GLFWwindow* window, int key, int action);
void _glfwInputChar(_GLFWwindow* window, int character);
void _glfwInputScroll(_GLFWwindow* window, int x, int y);

View File

@ -47,7 +47,7 @@ static GLboolean initLibraries(void)
#ifndef _GLFW_NO_DLOAD_GDI32
// gdi32.dll (OpenGL pixel format functions & SwapBuffers)
_glfwLibrary.Win32.gdi.instance = LoadLibrary("gdi32.dll");
_glfwLibrary.Win32.gdi.instance = LoadLibrary(L"gdi32.dll");
if (!_glfwLibrary.Win32.gdi.instance)
return GL_FALSE;
@ -81,12 +81,12 @@ static GLboolean initLibraries(void)
#ifndef _GLFW_NO_DLOAD_WINMM
// winmm.dll (for joystick and timer support)
_glfwLibrary.Win32.winmm.instance = LoadLibrary("winmm.dll");
_glfwLibrary.Win32.winmm.instance = LoadLibrary(L"winmm.dll");
if (!_glfwLibrary.Win32.winmm.instance)
return GL_FALSE;
_glfwLibrary.Win32.winmm.joyGetDevCapsA = (JOYGETDEVCAPSA_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetDevCapsA");
_glfwLibrary.Win32.winmm.joyGetDevCaps = (JOYGETDEVCAPS_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetDevCapsW");
_glfwLibrary.Win32.winmm.joyGetPos = (JOYGETPOS_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetPos");
_glfwLibrary.Win32.winmm.joyGetPosEx = (JOYGETPOSEX_T)
@ -94,7 +94,7 @@ static GLboolean initLibraries(void)
_glfwLibrary.Win32.winmm.timeGetTime = (TIMEGETTIME_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "timeGetTime");
if (!_glfwLibrary.Win32.winmm.joyGetDevCapsA ||
if (!_glfwLibrary.Win32.winmm.joyGetDevCaps ||
!_glfwLibrary.Win32.winmm.joyGetPos ||
!_glfwLibrary.Win32.winmm.joyGetPosEx ||
!_glfwLibrary.Win32.winmm.timeGetTime)
@ -131,6 +131,60 @@ static void freeLibraries(void)
}
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Returns a wide string version of the specified UTF-8 string
//========================================================================
WCHAR* _glfwCreateWideStringFromUTF8(const char* source)
{
WCHAR* target;
int length;
length = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0);
if (!length)
return NULL;
target = (WCHAR*) malloc(sizeof(WCHAR) * (length + 1));
if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length + 1))
{
free(target);
return NULL;
}
return target;
}
//========================================================================
// Returns a UTF-8 string version of the specified wide string
//========================================================================
char* _glfwCreateUTF8FromWideString(const WCHAR* source)
{
char* target;
int length;
length = WideCharToMultiByte(CP_UTF8, 0, source, -1, NULL, 0, NULL, NULL);
if (!length)
return NULL;
target = (char*) malloc(length + 1);
if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, length + 1, NULL, NULL))
{
free(target);
return NULL;
}
return target;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////

View File

@ -45,6 +45,14 @@
// thinks it is the only one that gets to do so
#undef APIENTRY
// GLFW on Windows is Unicode only and does not work in MBCS mode
#ifndef UNICODE
#define UNICODE
#endif
// GLFW requires Windows XP
#define WINVER 0x0501
#include <windows.h>
#include <mmsystem.h>
@ -61,10 +69,10 @@
// Some old versions of w32api (used by MinGW and Cygwin) define
// WH_KEYBOARD_LL without typedef:ing KBDLLHOOKSTRUCT (!)
#if defined(__MINGW32__) || defined(__CYGWIN__)
#include <w32api.h>
#if defined(WH_KEYBOARD_LL) && (__W32API_MAJOR_VERSION == 1) && (__W32API_MINOR_VERSION <= 2)
#undef WH_KEYBOARD_LL
#endif
#include <w32api.h>
#if defined(WH_KEYBOARD_LL) && (__W32API_MAJOR_VERSION == 1) && (__W32API_MINOR_VERSION <= 2)
#undef WH_KEYBOARD_LL
#endif
#endif
//------------------------------------------------------------------------
@ -84,64 +92,64 @@ typedef struct tagKBDLLHOOKSTRUCT {
#endif // WH_KEYBOARD_LL
#ifndef LLKHF_ALTDOWN
#define LLKHF_ALTDOWN 0x00000020
#define LLKHF_ALTDOWN 0x00000020
#endif
#ifndef SPI_SETSCREENSAVERRUNNING
#define SPI_SETSCREENSAVERRUNNING 97
#define SPI_SETSCREENSAVERRUNNING 97
#endif
#ifndef SPI_GETANIMATION
#define SPI_GETANIMATION 72
#define SPI_GETANIMATION 72
#endif
#ifndef SPI_SETANIMATION
#define SPI_SETANIMATION 73
#define SPI_SETANIMATION 73
#endif
#ifndef SPI_GETFOREGROUNDLOCKTIMEOUT
#define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000
#define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000
#endif
#ifndef SPI_SETFOREGROUNDLOCKTIMEOUT
#define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001
#define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001
#endif
#ifndef CDS_FULLSCREEN
#define CDS_FULLSCREEN 4
#define CDS_FULLSCREEN 4
#endif
#ifndef PFD_GENERIC_ACCELERATED
#define PFD_GENERIC_ACCELERATED 0x00001000
#define PFD_GENERIC_ACCELERATED 0x00001000
#endif
#ifndef PFD_DEPTH_DONTCARE
#define PFD_DEPTH_DONTCARE 0x20000000
#define PFD_DEPTH_DONTCARE 0x20000000
#endif
#ifndef ENUM_CURRENT_SETTINGS
#define ENUM_CURRENT_SETTINGS -1
#define ENUM_CURRENT_SETTINGS -1
#endif
#ifndef ENUM_REGISTRY_SETTINGS
#define ENUM_REGISTRY_SETTINGS -2
#define ENUM_REGISTRY_SETTINGS -2
#endif
#ifndef WM_MOUSEWHEEL
#define WM_MOUSEWHEEL 0x020A
#define WM_MOUSEWHEEL 0x020A
#endif
#ifndef WHEEL_DELTA
#define WHEEL_DELTA 120
#define WHEEL_DELTA 120
#endif
#ifndef WM_MOUSEHWHEEL
#define WM_MOUSEHWHEEL 0x020E
#define WM_MOUSEHWHEEL 0x020E
#endif
#ifndef WM_XBUTTONDOWN
#define WM_XBUTTONDOWN 0x020B
#define WM_XBUTTONDOWN 0x020B
#endif
#ifndef WM_XBUTTONUP
#define WM_XBUTTONUP 0x020C
#define WM_XBUTTONUP 0x020C
#endif
#ifndef XBUTTON1
#define XBUTTON1 1
#define XBUTTON1 1
#endif
#ifndef XBUTTON2
#define XBUTTON2 2
#define XBUTTON2 2
#endif
@ -162,7 +170,7 @@ typedef BOOL (WINAPI * SETDEVICEGAMMARAMP_T) (HDC,PVOID);
// winmm.dll function pointer typedefs
#ifndef _GLFW_NO_DLOAD_WINMM
typedef MMRESULT (WINAPI * JOYGETDEVCAPSA_T) (UINT,LPJOYCAPSA,UINT);
typedef MMRESULT (WINAPI * JOYGETDEVCAPS_T) (UINT,LPJOYCAPS,UINT);
typedef MMRESULT (WINAPI * JOYGETPOS_T) (UINT,LPJOYINFO);
typedef MMRESULT (WINAPI * JOYGETPOSEX_T) (UINT,LPJOYINFOEX);
typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
@ -171,40 +179,40 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
// gdi32.dll shortcuts
#ifndef _GLFW_NO_DLOAD_GDI32
#define _glfw_ChoosePixelFormat _glfwLibrary.Win32.gdi.ChoosePixelFormat
#define _glfw_DescribePixelFormat _glfwLibrary.Win32.gdi.DescribePixelFormat
#define _glfw_GetPixelFormat _glfwLibrary.Win32.gdi.GetPixelFormat
#define _glfw_SetPixelFormat _glfwLibrary.Win32.gdi.SetPixelFormat
#define _glfw_SwapBuffers _glfwLibrary.Win32.gdi.SwapBuffers
#define _glfw_GetDeviceGammaRamp _glfwLibrary.Win32.gdi.GetDeviceGammaRamp
#define _glfw_SetDeviceGammaRamp _glfwLibrary.Win32.gdi.SetDeviceGammaRamp
#define _glfw_ChoosePixelFormat _glfwLibrary.Win32.gdi.ChoosePixelFormat
#define _glfw_DescribePixelFormat _glfwLibrary.Win32.gdi.DescribePixelFormat
#define _glfw_GetPixelFormat _glfwLibrary.Win32.gdi.GetPixelFormat
#define _glfw_SetPixelFormat _glfwLibrary.Win32.gdi.SetPixelFormat
#define _glfw_SwapBuffers _glfwLibrary.Win32.gdi.SwapBuffers
#define _glfw_GetDeviceGammaRamp _glfwLibrary.Win32.gdi.GetDeviceGammaRamp
#define _glfw_SetDeviceGammaRamp _glfwLibrary.Win32.gdi.SetDeviceGammaRamp
#else
#define _glfw_ChoosePixelFormat ChoosePixelFormat
#define _glfw_DescribePixelFormat DescribePixelFormat
#define _glfw_GetPixelFormat GetPixelFormat
#define _glfw_SetPixelFormat SetPixelFormat
#define _glfw_SwapBuffers SwapBuffers
#define _glfw_GetDeviceGammaRamp GetDeviceGammaRamp
#define _glfw_SetDeviceGammaRamp SetDeviceGammaRamp
#define _glfw_ChoosePixelFormat ChoosePixelFormat
#define _glfw_DescribePixelFormat DescribePixelFormat
#define _glfw_GetPixelFormat GetPixelFormat
#define _glfw_SetPixelFormat SetPixelFormat
#define _glfw_SwapBuffers SwapBuffers
#define _glfw_GetDeviceGammaRamp GetDeviceGammaRamp
#define _glfw_SetDeviceGammaRamp SetDeviceGammaRamp
#endif // _GLFW_NO_DLOAD_GDI32
// winmm.dll shortcuts
#ifndef _GLFW_NO_DLOAD_WINMM
#define _glfw_joyGetDevCaps _glfwLibrary.Win32.winmm.joyGetDevCapsA
#define _glfw_joyGetPos _glfwLibrary.Win32.winmm.joyGetPos
#define _glfw_joyGetPosEx _glfwLibrary.Win32.winmm.joyGetPosEx
#define _glfw_timeGetTime _glfwLibrary.Win32.winmm.timeGetTime
#define _glfw_joyGetDevCaps _glfwLibrary.Win32.winmm.joyGetDevCaps
#define _glfw_joyGetPos _glfwLibrary.Win32.winmm.joyGetPos
#define _glfw_joyGetPosEx _glfwLibrary.Win32.winmm.joyGetPosEx
#define _glfw_timeGetTime _glfwLibrary.Win32.winmm.timeGetTime
#else
#define _glfw_joyGetDevCaps joyGetDevCapsA
#define _glfw_joyGetPos joyGetPos
#define _glfw_joyGetPosEx joyGetPosEx
#define _glfw_timeGetTime timeGetTime
#define _glfw_joyGetDevCaps joyGetDevCaps
#define _glfw_joyGetPos joyGetPos
#define _glfw_joyGetPosEx joyGetPosEx
#define _glfw_timeGetTime timeGetTime
#endif // _GLFW_NO_DLOAD_WINMM
// We use versioned window class names in order not to cause conflicts
// between applications using different versions of GLFW
#define _GLFW_WNDCLASSNAME "GLFW30"
#define _GLFW_WNDCLASSNAME L"GLFW30"
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32
@ -309,7 +317,7 @@ typedef struct _GLFWlibraryWin32
// winmm.dll
struct {
HINSTANCE instance;
JOYGETDEVCAPSA_T joyGetDevCapsA;
JOYGETDEVCAPS_T joyGetDevCaps;
JOYGETPOS_T joyGetPos;
JOYGETPOSEX_T joyGetPosEx;
TIMEGETTIME_T timeGetTime;
@ -323,6 +331,10 @@ typedef struct _GLFWlibraryWin32
// Prototypes for platform specific internal functions
//========================================================================
// Wide strings
WCHAR* _glfwCreateWideStringFromUTF8(const char* source);
char* _glfwCreateUTF8FromWideString(const WCHAR* source);
// Time
void _glfwInitTimer(void);

View File

@ -195,7 +195,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
return NULL;
}
result = (_GLFWfbconfig*) _glfwMalloc(sizeof(_GLFWfbconfig) * count);
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
if (!result)
{
_glfwSetError(GLFW_OUT_OF_MEMORY,
@ -895,7 +895,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (_glfwLibrary.charCallback)
translateChar(window, (DWORD) wParam, (DWORD) lParam);
return 0;
break;
}
case WM_KEYUP:
@ -910,7 +910,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
else
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_RELEASE);
return 0;
break;
}
case WM_LBUTTONDOWN:
@ -1220,7 +1220,7 @@ static ATOM registerWindowClass(void)
wc.lpszClassName = _GLFW_WNDCLASSNAME; // Set class name
// Load user-provided icon if available
wc.hIcon = LoadIcon(_glfwLibrary.Win32.instance, "GLFW_ICON");
wc.hIcon = LoadIcon(_glfwLibrary.Win32.instance, L"GLFW_ICON");
if (!wc.hIcon)
{
// Load default icon
@ -1257,13 +1257,13 @@ static int choosePixelFormat(_GLFWwindow* window, const _GLFWfbconfig* fbconfig)
closest = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
if (!closest)
{
_glfwFree(fbconfigs);
free(fbconfigs);
return 0;
}
pixelFormat = (int) closest->platformID;
_glfwFree(fbconfigs);
free(fbconfigs);
fbconfigs = NULL;
closest = NULL;
@ -1283,6 +1283,7 @@ static int createWindow(_GLFWwindow* window,
int pixelFormat, fullWidth, fullHeight;
RECT wa;
POINT pos;
WCHAR* wideTitle;
// Set common window styles
dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
@ -1331,9 +1332,17 @@ static int createWindow(_GLFWwindow* window,
else
SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0);
wideTitle = _glfwCreateWideStringFromUTF8(wndconfig->title);
if (!wideTitle)
{
_glfwSetError(GLFW_PLATFORM_ERROR,
"glfwOpenWindow: Failed to convert title to wide string");
return GL_FALSE;
}
window->Win32.handle = CreateWindowEx(window->Win32.dwExStyle,
_GLFW_WNDCLASSNAME,
wndconfig->title,
wideTitle,
window->Win32.dwStyle,
wa.left, wa.top, // Window position
fullWidth, // Decorated window width
@ -1349,6 +1358,8 @@ static int createWindow(_GLFWwindow* window,
return GL_FALSE;
}
free(wideTitle);
window->WGL.DC = GetDC(window->Win32.handle);
if (!window->WGL.DC)
{
@ -1430,6 +1441,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
GLboolean recreateContext = GL_FALSE;
window->Win32.desiredRefreshRate = wndconfig->refreshRate;
window->resizable = wndconfig->resizable;
if (!_glfwLibrary.Win32.classAtom)
{
@ -1568,7 +1580,17 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{
SetWindowText(window->Win32.handle, title);
WCHAR* wideTitle = _glfwCreateWideStringFromUTF8(title);
if (!wideTitle)
{
_glfwSetError(GLFW_PLATFORM_ERROR,
"glfwSetWindowTitle: Failed to convert title to wide string");
return;
}
SetWindowText(window->Win32.handle, wideTitle);
free(wideTitle);
}

View File

@ -291,7 +291,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
height = 480;
}
window = (_GLFWwindow*) _glfwMalloc(sizeof(_GLFWwindow));
window = (_GLFWwindow*) malloc(sizeof(_GLFWwindow));
if (!window)
{
_glfwSetError(GLFW_OUT_OF_MEMORY,
@ -309,6 +309,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
window->height = height;
window->mode = mode;
window->cursorMode = GLFW_CURSOR_NORMAL;
window->systemKeys = GL_TRUE;
// Open the actual window and create its context
if (!_glfwPlatformOpenWindow(window, &wndconfig, &fbconfig))
@ -330,7 +331,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
// The GLFW specification states that fullscreen windows have the cursor
// captured by default
if (mode == GLFW_FULLSCREEN)
glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED);
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
@ -491,7 +492,7 @@ GLFWAPI void glfwCloseWindow(GLFWwindow handle)
*prev = window->next;
}
_glfwFree(window);
free(window);
}
@ -654,7 +655,6 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow handle)
if (!window->iconified)
return;
// Restore iconified window
_glfwPlatformRestoreWindow(window);
if (window->mode == GLFW_FULLSCREEN)

View File

@ -339,7 +339,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
return 0;
}
rgbarray = (int*) _glfwMalloc(sizeof(int) * viscount);
rgbarray = (int*) malloc(sizeof(int) * viscount);
rgbcount = 0;
// Build RGB array
@ -372,6 +372,8 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
}
}
XFree(vislist);
rescount = 0;
resarray = NULL;
@ -387,7 +389,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root);
sizelist = XRRConfigSizes(sc, &sizecount);
resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * sizecount);
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * sizecount);
for (k = 0; k < sizecount; k++)
{
@ -407,7 +409,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, &modecount, &modelist);
resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * modecount);
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * modecount);
for (k = 0; k < modecount; k++)
{
@ -436,7 +438,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
if (!resarray)
{
rescount = 1;
resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * rescount);
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * rescount);
resarray[0].width = DisplayWidth(_glfwLibrary.X11.display, screen);
resarray[0].height = DisplayHeight(_glfwLibrary.X11.display, screen);
@ -457,10 +459,8 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
}
}
XFree(vislist);
_glfwFree(resarray);
_glfwFree(rgbarray);
free(resarray);
free(rgbarray);
return count;
}

View File

@ -79,7 +79,11 @@ static int keyCodeToGLFWKeyCode(int keyCode)
// Note: This way we always force "NumLock = ON", which is intentional
// since the returned key code should correspond to a physical
// location.
#if defined(_GLFW_HAS_XKB)
keySym = XkbKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 1, 0);
#else
keySym = XKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 1);
#endif
switch (keySym)
{
case XK_KP_0: return GLFW_KEY_KP_0;
@ -102,7 +106,12 @@ static int keyCodeToGLFWKeyCode(int keyCode)
// Now try pimary keysym for function keys (non-printable keys). These
// should not be layout dependent (i.e. US layout and international
// layouts should give the same result).
#if defined(_GLFW_HAS_XKB)
keySym = XkbKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 0, 0);
#else
keySym = XKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 0);
#endif
switch (keySym)
{
case XK_Escape: return GLFW_KEY_ESCAPE;

View File

@ -31,8 +31,7 @@
#include "internal.h"
void (*glXGetProcAddress(const GLubyte* procName))();
void (*glXGetProcAddressARB(const GLubyte* procName))();
// This is the only glXGetProcAddress variant not declared by glxext.h
void (*glXGetProcAddressEXT(const GLubyte* procName))();

View File

@ -46,13 +46,6 @@
// extensions and not all operating systems come with an up-to-date version
#include "../support/GL/glxext.h"
// We need declarations for GLX version 1.3 or above even if the server doesn't
// support version 1.3
#ifndef GLX_VERSION_1_3
#error "GLX header version 1.3 or above is required"
#endif
// With XFree86, we can use the XF86VidMode extension
#if defined(_GLFW_HAS_XF86VIDMODE)
#include <X11/extensions/xf86vmode.h>
@ -141,6 +134,8 @@ typedef struct _GLFWwindowX11
Colormap colormap; // Window colormap
Window handle; // Window handle
Atom wmDeleteWindow; // WM_DELETE_WINDOW atom
Atom wmName; // _NET_WM_NAME atom
Atom wmIconName; // _NET_WM_ICON_NAME atom
Atom wmPing; // _NET_WM_PING atom
Atom wmState; // _NET_WM_STATE atom
Atom wmStateFullscreen; // _NET_WM_STATE_FULLSCREEN atom

View File

@ -39,7 +39,7 @@
static uint64_t getRawTime(void)
{
#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
#if defined(CLOCK_MONOTONIC)
if (_glfwLibrary.X11.timer.monotonic)
{
struct timespec ts;
@ -64,7 +64,7 @@ static uint64_t getRawTime(void)
void _glfwInitTimer(void)
{
#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
#if defined(CLOCK_MONOTONIC)
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)

View File

@ -195,6 +195,12 @@ static GLboolean hasEWMH(_GLFWwindow* window)
window->X11.wmStateFullscreen =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_FULLSCREEN");
window->X11.wmName =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_NAME");
window->X11.wmIconName =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_ICON_NAME");
window->X11.wmPing =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_PING");
@ -310,7 +316,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
}
}
result = (_GLFWfbconfig*) _glfwMalloc(sizeof(_GLFWfbconfig) * count);
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
if (!result)
{
_glfwSetError(GLFW_OUT_OF_MEMORY,
@ -1444,12 +1450,12 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
if (!result)
{
_glfwFree(fbconfigs);
free(fbconfigs);
return GL_FALSE;
}
closest = *result;
_glfwFree(fbconfigs);
free(fbconfigs);
}
if (!createContext(window, wndconfig, (GLXFBConfigID) closest.platformID))
@ -1544,9 +1550,39 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{
// Set window & icon title
XStoreName(_glfwLibrary.X11.display, window->X11.handle, title);
XSetIconName(_glfwLibrary.X11.display, window->X11.handle, title);
Atom type = XInternAtom(_glfwLibrary.X11.display, "UTF8_STRING", False);
#if defined(X_HAVE_UTF8_STRING)
Xutf8SetWMProperties(_glfwLibrary.X11.display,
window->X11.handle,
title, title,
NULL, 0,
NULL, NULL, NULL);
#else
// This may be a slightly better fallback than using XStoreName and
// XSetIconName, which always store their arguments using STRING
XmbSetWMProperties(_glfwLibrary.X11.display,
window->X11.handle,
title, title,
NULL, 0,
NULL, NULL, NULL);
#endif
if (window->X11.wmName != None)
{
XChangeProperty(_glfwLibrary.X11.display, window->X11.handle,
window->X11.wmName, type, 8,
PropModeReplace,
(unsigned char*) title, strlen(title));
}
if (window->X11.wmIconName != None)
{
XChangeProperty(_glfwLibrary.X11.display, window->X11.handle,
window->X11.wmIconName, type, 8,
PropModeReplace,
(unsigned char*) title, strlen(title));
}
}

View File

@ -36,6 +36,9 @@ target_link_libraries(joysticks ${STATIC_DEPS})
add_executable(listmodes listmodes.c)
target_link_libraries(listmodes ${STATIC_DEPS})
add_executable(modes modes.c getopt.c)
target_link_libraries(modes ${STATIC_DEPS})
add_executable(peter peter.c)
target_link_libraries(peter ${STATIC_DEPS})
@ -44,23 +47,37 @@ target_link_libraries(reopen ${STATIC_DEPS})
add_executable(accuracy WIN32 MACOSX_BUNDLE accuracy.c)
target_link_libraries(accuracy ${STATIC_DEPS})
set_target_properties(accuracy PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Accuracy")
add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c)
target_link_libraries(sharing ${STATIC_DEPS})
set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing")
add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c)
target_link_libraries(tearing ${STATIC_DEPS})
set_target_properties(tearing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Tearing")
add_executable(title WIN32 MACOSX_BUNDLE title.c)
target_link_libraries(title ${STATIC_DEPS})
set_target_properties(title PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Title")
add_executable(windows WIN32 MACOSX_BUNDLE windows.c)
target_link_libraries(windows ${STATIC_DEPS})
set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows")
set(WINDOWS_BINARIES accuracy sharing tearing windows)
set(WINDOWS_BINARIES accuracy sharing tearing title windows)
set(CONSOLE_BINARIES defaults events fsaa fsfocus gamma glfwinfo iconify
joysticks listmodes peter reopen)
joysticks listmodes modes peter reopen)
if(MSVC)
if (MSVC)
# Tell MSVC to use main instead of WinMain for Windows subsystem executables
set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES
LINK_FLAGS "/ENTRY:mainCRTStartup")
endif(MSVC)
endif()
if (APPLE)
set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES
MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION}
MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL})
endif()

View File

@ -40,8 +40,9 @@
#include <ctype.h>
#include <locale.h>
static GLboolean keyrepeat = 0;
static GLboolean systemkeys = 1;
static GLboolean keyrepeat = GL_FALSE;
static GLboolean systemkeys = GL_TRUE;
static GLboolean closeable = GL_TRUE;
static unsigned int counter = 0;
static const char* get_key_name(int key)
@ -230,7 +231,7 @@ static void window_size_callback(GLFWwindow window, int width, int height)
static int window_close_callback(GLFWwindow window)
{
printf("%08x at %0.3f: Window close\n", counter++, glfwGetTime());
return 1;
return closeable;
}
static void window_refresh_callback(GLFWwindow window)
@ -306,10 +307,7 @@ static void key_callback(GLFWwindow window, int key, int action)
case GLFW_KEY_R:
{
keyrepeat = !keyrepeat;
if (keyrepeat)
glfwEnable(window, GLFW_KEY_REPEAT);
else
glfwDisable(window, GLFW_KEY_REPEAT);
glfwSetInputMode(window, GLFW_KEY_REPEAT, keyrepeat);
printf("(( key repeat %s ))\n", keyrepeat ? "enabled" : "disabled");
break;
@ -318,14 +316,19 @@ static void key_callback(GLFWwindow window, int key, int action)
case GLFW_KEY_S:
{
systemkeys = !systemkeys;
if (systemkeys)
glfwEnable(window, GLFW_SYSTEM_KEYS);
else
glfwDisable(window, GLFW_SYSTEM_KEYS);
glfwSetInputMode(window, GLFW_SYSTEM_KEYS, systemkeys);
printf("(( system keys %s ))\n", systemkeys ? "enabled" : "disabled");
break;
}
case GLFW_KEY_C:
{
closeable = !closeable;
printf("(( closing %s ))\n", closeable ? "enabled" : "disabled");
break;
}
}
}

View File

@ -91,7 +91,7 @@ int main(void)
}
glfwSwapInterval(1);
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
glfwSetWindowFocusCallback(window_focus_callback);
glfwSetKeyCallback(window_key_callback);

View File

@ -35,11 +35,20 @@
#include "getopt.h"
#define STEP_SIZE 0.1f
static GLfloat gamma = 1.0f;
static void usage(void)
{
printf("Usage: gammatest [-h] [-f]\n");
printf("Usage: gamma [-h] [-f]\n");
}
static void set_gamma(float value)
{
gamma = value;
printf("Gamma: %f\n", gamma);
glfwSetGamma(gamma);
}
static void key_callback(GLFWwindow window, int key, int action)
@ -50,21 +59,27 @@ static void key_callback(GLFWwindow window, int key, int action)
switch (key)
{
case GLFW_KEY_ESCAPE:
{
glfwCloseWindow(window);
break;
}
case GLFW_KEY_KP_ADD:
case GLFW_KEY_Q:
gamma += 0.1f;
printf("Gamma: %f\n", gamma);
glfwSetGamma(gamma);
{
set_gamma(gamma + STEP_SIZE);
break;
}
case GLFW_KEY_KP_SUBTRACT:
case GLFW_KEY_W:
gamma -= 0.1f;
printf("Gamma: %f\n", gamma);
glfwSetGamma(gamma);
{
if (gamma - STEP_SIZE > 0.f)
set_gamma(gamma - STEP_SIZE);
break;
}
}
}
static void size_callback(GLFWwindow window, int width, int height)
@ -124,7 +139,7 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
printf("Gamma: %f\n", gamma);
set_gamma(1.f);
glfwSwapInterval(1);
glfwSetKeyCallback(key_callback);

View File

@ -51,7 +51,7 @@
static void usage(void)
{
printf("Usage: version [-h] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n");
printf("Usage: glfwinfo [-h] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n");
printf("available profiles: " PROFILE_NAME_CORE " " PROFILE_NAME_COMPAT " " PROFILE_NAME_ES2 "\n");
printf("available strategies: " STRATEGY_NAME_NONE " " STRATEGY_NAME_LOSE "\n");
}
@ -263,7 +263,7 @@ int main(int argc, char** argv)
if (major > 3 || (major == 3 && minor >= 2))
{
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
printf("OpenGL profile mask: 0x%08x (%s)\n", mask, get_profile_name(mask));
printf("OpenGL profile mask: %s (0x%08x)\n", get_profile_name(mask), mask);
printf("OpenGL profile parsed by GLFW: %s\n",
get_glfw_profile_name(glfwGetWindowParam(window, GLFW_OPENGL_PROFILE)));

View File

@ -62,6 +62,8 @@ static void key_callback(GLFWwindow window, int key, int action)
static void size_callback(GLFWwindow window, int width, int height)
{
printf("%0.2f Size %ix%i\n", glfwGetTime(), width, height);
glViewport(0, 0, width, height);
}

225
tests/modes.c Normal file
View File

@ -0,0 +1,225 @@
//========================================================================
// Video mode test
// Copyright (c) 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.
//
//========================================================================
//
// This test enumerates or verifies video modes
//
//========================================================================
#include <GL/glfw3.h>
#include <stdio.h>
#include <stdlib.h>
#include "getopt.h"
static GLFWwindow window = NULL;
enum Mode
{
NO_MODE,
LIST_MODE,
TEST_MODE
};
static void usage(void)
{
printf("Usage: modes -l\n");
printf(" modes -t\n");
printf(" modes -h\n");
}
static void print_mode(GLFWvidmode* mode)
{
printf("%i x %i x %i (%i %i %i)",
mode->width, mode->height,
mode->redBits + mode->greenBits + mode->blueBits,
mode->redBits, mode->greenBits, mode->blueBits);
}
static void error_callback(int error, const char* description)
{
fprintf(stderr, "Error: %s\n", description);
}
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)
{
window = NULL;
return GL_TRUE;
}
static void list_modes(GLFWvidmode* modes, int count)
{
int i;
GLFWvidmode mode;
glfwGetDesktopMode(&mode);
printf("Desktop mode: ");
print_mode(&mode);
putchar('\n');
for (i = 0; i < count; i++)
{
printf("%3i: ", i);
print_mode(modes + i);
putchar('\n');
}
}
static void test_modes(GLFWvidmode* modes, int count)
{
int i, width, height;
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowCloseCallback(window_close_callback);
for (i = 0; i < count; i++)
{
glfwOpenWindowHint(GLFW_RED_BITS, modes[i].redBits);
glfwOpenWindowHint(GLFW_GREEN_BITS, modes[i].greenBits);
glfwOpenWindowHint(GLFW_BLUE_BITS, modes[i].blueBits);
printf("Opening ");
print_mode(modes + i);
printf(" window\n");
window = glfwOpenWindow(modes[i].width, modes[i].height,
GLFW_FULLSCREEN, "Video Mode Test",
NULL);
if (!window)
{
printf("Failed to enter mode %i: ", i);
print_mode(modes + i);
putchar('\n');
continue;
}
glfwSetTime(0.0);
glfwSwapInterval(1);
while (glfwGetTime() < 5.0)
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
glfwPollEvents();
if (!window)
{
printf("User terminated program\n");
exit(EXIT_SUCCESS);
}
}
if (glfwGetWindowParam(window, GLFW_RED_BITS) != modes[i].redBits ||
glfwGetWindowParam(window, GLFW_GREEN_BITS) != modes[i].greenBits ||
glfwGetWindowParam(window, GLFW_BLUE_BITS) != modes[i].blueBits)
{
printf("*** Color bit mismatch: (%i %i %i) instead of (%i %i %i)\n",
glfwGetWindowParam(window, GLFW_RED_BITS),
glfwGetWindowParam(window, GLFW_GREEN_BITS),
glfwGetWindowParam(window, GLFW_BLUE_BITS),
modes[i].redBits,
modes[i].greenBits,
modes[i].blueBits);
}
glfwGetWindowSize(window, &width, &height);
if (width != modes[i].width || height != height)
{
printf("*** Size mismatch: %ix%i instead of %ix%i\n",
width, height,
modes[i].width, modes[i].height);
}
printf("Closing window\n");
glfwCloseWindow(window);
glfwPollEvents();
window = NULL;
sleep(5);
}
}
int main(int argc, char** argv)
{
int ch, found, count = 0, mode = NO_MODE;
GLFWvidmode* modes = NULL;
while ((ch = getopt(argc, argv, "lth")) != -1)
{
switch (ch)
{
case 'h':
usage();
exit(EXIT_SUCCESS);
case 'l':
mode = LIST_MODE;
break;
case 't':
mode = TEST_MODE;
break;
default:
usage();
exit(EXIT_FAILURE);
}
}
argc -= optind;
argv += optind;
glfwSetErrorCallback(error_callback);
if (!glfwInit())
exit(EXIT_FAILURE);
for (;;)
{
count += 256;
modes = realloc(modes, sizeof(GLFWvidmode) * count);
found = glfwGetVideoModes(modes, count);
if (found < count)
break;
}
if (mode == LIST_MODE)
list_modes(modes, found);
else if (mode == TEST_MODE)
test_modes(modes, found);
free(modes);
modes = NULL;
exit(EXIT_SUCCESS);
}

View File

@ -35,7 +35,6 @@
#include <stdio.h>
#include <stdlib.h>
static GLboolean cursor_captured = GL_FALSE;
static GLFWwindow window_handle = NULL;
static int cursor_x;
static int cursor_y;
@ -44,18 +43,16 @@ static GLboolean open_window(void);
static void toggle_mouse_cursor(GLFWwindow window)
{
if (cursor_captured)
if (glfwGetInputMode(window, GLFW_CURSOR_MODE) == GLFW_CURSOR_CAPTURED)
{
printf("Released cursor\n");
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
}
else
{
printf("Captured cursor\n");
glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED);
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED);
}
cursor_captured = !cursor_captured;
}
static void mouse_position_callback(GLFWwindow window, int x, int y)

View File

@ -92,8 +92,6 @@ static void draw_quad(GLuint texture)
glBindTexture(GL_TEXTURE_2D, texture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glColor3f(0.6f, 0.f, 0.6f);
glBegin(GL_QUADS);
glTexCoord2f(0.f, 0.f);
@ -142,6 +140,11 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
// Set drawing color for the first context and copy it to the second
glfwMakeContextCurrent(windows[0]);
glColor3f(0.6f, 0.f, 0.6f);
glfwCopyContext(windows[0], windows[1], GL_CURRENT_BIT);
// Put the second window to the right of the first one
glfwGetWindowPos(windows[0], &x, &y);
glfwSetWindowPos(windows[1], x + WIDTH + 50, y);

View File

@ -34,11 +34,30 @@
#include <stdlib.h>
#include <math.h>
static int swap_interval;
static void set_swap_interval(int value)
{
char title[256];
swap_interval = value;
glfwSwapInterval(swap_interval);
sprintf(title, "Tearing detector (interval %i)", swap_interval);
glfwSetWindowTitle(glfwGetCurrentContext(), title);
}
static void window_size_callback(GLFWwindow window, int width, int height)
{
glViewport(0, 0, width, height);
}
static void key_callback(GLFWwindow window, int key, int action)
{
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS)
set_swap_interval(!swap_interval);
}
int main(void)
{
float position;
@ -50,7 +69,7 @@ int main(void)
exit(EXIT_FAILURE);
}
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Tearing Detector", NULL);
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "", NULL);
if (!window)
{
glfwTerminate();
@ -59,8 +78,10 @@ int main(void)
exit(EXIT_FAILURE);
}
set_swap_interval(1);
glfwSetWindowSizeCallback(window_size_callback);
glfwSwapInterval(1);
glfwSetKeyCallback(key_callback);
glMatrixMode(GL_PROJECTION);
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);

70
tests/title.c Normal file
View File

@ -0,0 +1,70 @@
//========================================================================
// UTF-8 window title test
// Copyright (c) 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.
//
//========================================================================
//
// This test sets a UTF-8 window title
//
//========================================================================
#include <GL/glfw3.h>
#include <stdio.h>
#include <stdlib.h>
static void window_size_callback(GLFWwindow window, int width, int height)
{
glViewport(0, 0, width, height);
}
int main(void)
{
GLFWwindow window;
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "English 日本語 русский язык 官話", NULL);
if (!window)
{
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
glfwSwapInterval(1);
glfwSetWindowSizeCallback(window_size_callback);
while (glfwIsWindow(window) == GL_TRUE)
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
glfwWaitEvents();
}
exit(EXIT_SUCCESS);
}