mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-23 10:48:51 -05:00
Merge branch 'cursor-enter-leave' of github.com:elmindreda/glfw into cursor-enter-leave
This commit is contained in:
commit
1234e0c537
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -4,6 +4,7 @@ CMakeCache.txt
|
||||||
Makefile
|
Makefile
|
||||||
cmake_uninstall.cmake
|
cmake_uninstall.cmake
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
docs/Doxyfile
|
||||||
src/config.h
|
src/config.h
|
||||||
src/libglfw.pc
|
src/libglfw.pc
|
||||||
src/libglfw.so
|
src/libglfw.so
|
||||||
|
@ -32,6 +33,7 @@ tests/peter
|
||||||
tests/reopen
|
tests/reopen
|
||||||
tests/sharing
|
tests/sharing
|
||||||
tests/tearing
|
tests/tearing
|
||||||
|
tests/title
|
||||||
tests/windows
|
tests/windows
|
||||||
tests/*.app
|
tests/*.app
|
||||||
tests/*.exe
|
tests/*.exe
|
||||||
|
|
|
@ -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)
|
|
|
@ -1,10 +1,19 @@
|
||||||
This folder contains a collection of toolchains definition in order to
|
This directory contains a collection of toolchain definitions for cross
|
||||||
support cross compilation. The naming scheme is the following:
|
compilation, currently limited to compiling Win32 binaries on Linux.
|
||||||
|
|
||||||
|
The toolchain file naming scheme is as follows:
|
||||||
|
|
||||||
host-system-compiler.cmake
|
host-system-compiler.cmake
|
||||||
|
|
||||||
to use this at the time you run the initial cmake command use the
|
To use these files you add a special parameter when configuring the source tree:
|
||||||
following parameter
|
|
||||||
-DCMAKE_TOOLCHAIN_FILE=./toolchains/XXX-XXX-XXX.cmake
|
cmake -DCMAKE_TOOLCHAIN_FILE=<toolchain-file> .
|
||||||
which maps to file in this folder.
|
|
||||||
|
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
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
project(GLFW C)
|
project(GLFW C)
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.4)
|
cmake_minimum_required(VERSION 2.8)
|
||||||
cmake_policy(VERSION 2.4)
|
|
||||||
|
|
||||||
set(GLFW_VERSION_MAJOR "3")
|
set(GLFW_VERSION_MAJOR "3")
|
||||||
set(GLFW_VERSION_MINOR "0")
|
set(GLFW_VERSION_MINOR "0")
|
||||||
|
@ -27,7 +26,7 @@ if (WIN32)
|
||||||
# Set up library and include paths
|
# Set up library and include paths
|
||||||
list(APPEND GLFW_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
|
list(APPEND GLFW_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
|
||||||
list(APPEND GLFW_LIBRARIES ${OPENGL_gl_LIBRARY})
|
list(APPEND GLFW_LIBRARIES ${OPENGL_gl_LIBRARY})
|
||||||
endif (WIN32)
|
endif()
|
||||||
|
|
||||||
#--------------------------------------------------------------------
|
#--------------------------------------------------------------------
|
||||||
# Set up GLFW for Xlib and GLX on Unix-like systems with X Windows
|
# 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
|
# Define the platform identifier
|
||||||
set(_GLFW_X11_GLX 1)
|
set(_GLFW_X11_GLX 1)
|
||||||
|
|
||||||
|
find_package(X11 REQUIRED)
|
||||||
|
|
||||||
# Set up library and include paths
|
# Set up library and include paths
|
||||||
list(APPEND GLFW_INCLUDE_DIR ${X11_X11_INCLUDE_PATH} ${OPENGL_INCLUDE_DIR})
|
list(APPEND GLFW_INCLUDE_DIR ${X11_X11_INCLUDE_PATH} ${OPENGL_INCLUDE_DIR})
|
||||||
list(APPEND GLFW_LIBRARIES ${X11_X11_LIB} ${OPENGL_gl_LIBRARY})
|
list(APPEND GLFW_LIBRARIES ${X11_X11_LIB} ${OPENGL_gl_LIBRARY})
|
||||||
|
@ -45,61 +46,58 @@ if (UNIX AND NOT APPLE)
|
||||||
find_library(MATH_LIBRARY m)
|
find_library(MATH_LIBRARY m)
|
||||||
if (MATH_LIBRARY)
|
if (MATH_LIBRARY)
|
||||||
list(APPEND GLFW_LIBRARIES ${MATH_LIBRARY})
|
list(APPEND GLFW_LIBRARIES ${MATH_LIBRARY})
|
||||||
endif(MATH_LIBRARY)
|
endif()
|
||||||
|
|
||||||
find_library(RT_LIBRARY rt)
|
find_library(RT_LIBRARY rt)
|
||||||
if (RT_LIBRARY)
|
if (RT_LIBRARY)
|
||||||
list(APPEND GLFW_LIBRARIES ${RT_LIBRARY})
|
list(APPEND GLFW_LIBRARIES ${RT_LIBRARY})
|
||||||
endif(RT_LIBRARY)
|
endif()
|
||||||
|
|
||||||
include(CheckFunctionExists)
|
include(CheckFunctionExists)
|
||||||
include(CheckSymbolExists)
|
include(CheckSymbolExists)
|
||||||
|
|
||||||
include(${GLFW_SOURCE_DIR}/CMake/CheckX11Extensions.cmake)
|
|
||||||
set(CMAKE_REQUIRED_LIBRARIES ${GLFW_LIBRARIES})
|
set(CMAKE_REQUIRED_LIBRARIES ${GLFW_LIBRARIES})
|
||||||
|
|
||||||
# Check for XRandR (modern resolution switching extension)
|
# Check for XRandR (modern resolution switching extension)
|
||||||
check_x11_xrandr()
|
if (X11_Xrandr_FOUND)
|
||||||
if (X11_XRANDR_FOUND)
|
|
||||||
set(_GLFW_HAS_XRANDR 1)
|
set(_GLFW_HAS_XRANDR 1)
|
||||||
list(APPEND GLFW_INCLUDE_DIR ${X11_XRANDR_INCLUDE_DIR})
|
list(APPEND GLFW_INCLUDE_DIR ${X11_Xrandr_INCLUDE_PATH})
|
||||||
list(APPEND GLFW_LIBRARIES ${X11_XRANDR_LIBRARIES})
|
list(APPEND GLFW_LIBRARIES ${X11_Xrandr_LIB})
|
||||||
endif(X11_XRANDR_FOUND)
|
endif()
|
||||||
|
|
||||||
# Check for Xf86VidMode (fallback legacy resolution switching extension)
|
# Check for Xf86VidMode (fallback legacy resolution switching extension)
|
||||||
check_x11_xf86vidmode()
|
if (X11_xf86vmode_FOUND)
|
||||||
if (X11_XF86VIDMODE_FOUND)
|
|
||||||
set(_GLFW_HAS_XF86VIDMODE 1)
|
set(_GLFW_HAS_XF86VIDMODE 1)
|
||||||
list(APPEND GLFW_INCLUDE_DIR ${X11_XF86VIDMODE_INCLUDE_DIR})
|
list(APPEND GLFW_INCLUDE_DIR ${X11_xf86vmode_INCLUDE_PATH})
|
||||||
list(APPEND GLFW_LIBRARIES ${X11_XF86VIDMODE_LIBRARIES})
|
endif()
|
||||||
endif(X11_XF86VIDMODE_FOUND)
|
|
||||||
|
|
||||||
# Check for Xkb (X keyboard extension)
|
# 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 for glXGetProcAddress
|
||||||
check_function_exists(glXGetProcAddress _GLFW_HAS_GLXGETPROCADDRESS)
|
check_function_exists(glXGetProcAddress _GLFW_HAS_GLXGETPROCADDRESS)
|
||||||
|
|
||||||
if (NOT _GLFW_HAS_GLXGETPROCADDRESS)
|
if (NOT _GLFW_HAS_GLXGETPROCADDRESS)
|
||||||
check_function_exists(glXGetProcAddressARB _GLFW_HAS_GLXGETPROCADDRESSARB)
|
check_function_exists(glXGetProcAddressARB _GLFW_HAS_GLXGETPROCADDRESSARB)
|
||||||
endif (NOT _GLFW_HAS_GLXGETPROCADDRESS)
|
endif()
|
||||||
|
|
||||||
if (NOT _GLFW_HAS_GLXGETPROCADDRESS AND NOT _GLFW_HAS_GLXGETPROCADDRESSARB)
|
if (NOT _GLFW_HAS_GLXGETPROCADDRESS AND NOT _GLFW_HAS_GLXGETPROCADDRESSARB)
|
||||||
check_function_exists(glXGetProcAddressEXT _GLFW_HAS_GLXGETPROCADDRESSEXT)
|
check_function_exists(glXGetProcAddressEXT _GLFW_HAS_GLXGETPROCADDRESSEXT)
|
||||||
endif (NOT _GLFW_HAS_GLXGETPROCADDRESS AND NOT _GLFW_HAS_GLXGETPROCADDRESSARB)
|
endif()
|
||||||
|
|
||||||
if (NOT _GLFW_HAS_GLXGETPROCADDRESS AND
|
if (NOT _GLFW_HAS_GLXGETPROCADDRESS AND
|
||||||
NOT _GLFW_HAS_GLXGETPROCADDRESSARB AND
|
NOT _GLFW_HAS_GLXGETPROCADDRESSARB AND
|
||||||
NOT _GLFW_HAS_GLXGETPROCADDRESSEXT)
|
NOT _GLFW_HAS_GLXGETPROCADDRESSEXT)
|
||||||
message(WARNING "No glXGetProcAddressXXX variant found")
|
message(WARNING "No glXGetProcAddressXXX variant found")
|
||||||
endif (NOT _GLFW_HAS_GLXGETPROCADDRESS AND
|
endif()
|
||||||
NOT _GLFW_HAS_GLXGETPROCADDRESSARB AND
|
|
||||||
NOT _GLFW_HAS_GLXGETPROCADDRESSEXT)
|
|
||||||
|
|
||||||
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||||
set(_GLFW_USE_LINUX_JOYSTICKS 1)
|
set(_GLFW_USE_LINUX_JOYSTICKS 1)
|
||||||
endif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
endif()
|
||||||
endif(UNIX AND NOT APPLE)
|
endif()
|
||||||
|
|
||||||
#--------------------------------------------------------------------
|
#--------------------------------------------------------------------
|
||||||
# Set up GLFW for Cocoa and NSOpenGL on Mac OS X
|
# 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")
|
set(CMAKE_C_FLAGS "-mmacosx-version-min=10.5")
|
||||||
else(GLFW_BUILD_UNIVERSAL)
|
else(GLFW_BUILD_UNIVERSAL)
|
||||||
message(STATUS "Building GLFW only for the native architecture")
|
message(STATUS "Building GLFW only for the native architecture")
|
||||||
endif(GLFW_BUILD_UNIVERSAL)
|
endif()
|
||||||
|
|
||||||
# Set up library and include paths
|
# Set up library and include paths
|
||||||
find_library(COCOA_FRAMEWORK Cocoa)
|
find_library(COCOA_FRAMEWORK Cocoa)
|
||||||
|
@ -130,7 +128,7 @@ if (UNIX AND APPLE)
|
||||||
list(APPEND GLFW_LIBRARIES ${OPENGL_gl_LIBRARY})
|
list(APPEND GLFW_LIBRARIES ${OPENGL_gl_LIBRARY})
|
||||||
list(APPEND GLFW_LIBRARIES ${IOKIT_FRAMEWORK})
|
list(APPEND GLFW_LIBRARIES ${IOKIT_FRAMEWORK})
|
||||||
list(APPEND GLFW_LIBRARIES ${CORE_FOUNDATION_FRAMEWORK})
|
list(APPEND GLFW_LIBRARIES ${CORE_FOUNDATION_FRAMEWORK})
|
||||||
endif(UNIX AND APPLE)
|
endif()
|
||||||
|
|
||||||
#--------------------------------------------------------------------
|
#--------------------------------------------------------------------
|
||||||
# Add subdirectories
|
# Add subdirectories
|
||||||
|
@ -139,11 +137,11 @@ add_subdirectory(src)
|
||||||
|
|
||||||
if (GLFW_BUILD_EXAMPLES)
|
if (GLFW_BUILD_EXAMPLES)
|
||||||
add_subdirectory(examples)
|
add_subdirectory(examples)
|
||||||
endif(GLFW_BUILD_EXAMPLES)
|
endif()
|
||||||
|
|
||||||
if (GLFW_BUILD_TESTS)
|
if (GLFW_BUILD_TESTS)
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
endif(GLFW_BUILD_TESTS)
|
endif()
|
||||||
|
|
||||||
#--------------------------------------------------------------------
|
#--------------------------------------------------------------------
|
||||||
# Create shared configuration header
|
# Create shared configuration header
|
||||||
|
@ -161,17 +159,14 @@ install(DIRECTORY include/GL DESTINATION include
|
||||||
install(FILES COPYING.txt readme.html
|
install(FILES COPYING.txt readme.html
|
||||||
DESTINATION share/doc/glfw-${GLFW_VERSION_FULL}/)
|
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
|
# -- Documentation generation
|
||||||
#--------------------------------------------------------------------
|
#--------------------------------------------------------------------
|
||||||
#include("${GLFW_SOURCE_DIR}/documentation.cmake")
|
configure_file("${GLFW_SOURCE_DIR}/docs/Doxyfile.in"
|
||||||
#configure_file("${GLFW_SOURCE_DIR}/Doxyfile.in"
|
"${GLFW_BINARY_DIR}/docs/Doxyfile"
|
||||||
# "${GLFW_BINARY_DIR}/Doxyfile"
|
@ONLY)
|
||||||
# IMMEDIATE @ONLY)
|
|
||||||
#add_doxygen_target("${GLFW_BINARY_DIR}/Doxyfile")
|
|
||||||
#add_subdirectory(docs)
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------
|
#--------------------------------------------------------------------
|
||||||
# Uninstall operation
|
# Uninstall operation
|
||||||
|
|
1687
docs/Doxyfile.in
Normal file
1687
docs/Doxyfile.in
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -14,7 +14,13 @@ if(APPLE)
|
||||||
add_executable("Split View" MACOSX_BUNDLE splitview.c)
|
add_executable("Split View" MACOSX_BUNDLE splitview.c)
|
||||||
add_executable(Triangle MACOSX_BUNDLE triangle.c)
|
add_executable(Triangle MACOSX_BUNDLE triangle.c)
|
||||||
add_executable(Wave MACOSX_BUNDLE wave.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
|
# Set boring names for executables
|
||||||
add_executable(boing WIN32 boing.c)
|
add_executable(boing WIN32 boing.c)
|
||||||
add_executable(gears WIN32 gears.c)
|
add_executable(gears WIN32 gears.c)
|
||||||
|
@ -22,13 +28,21 @@ else(APPLE)
|
||||||
add_executable(splitview WIN32 splitview.c)
|
add_executable(splitview WIN32 splitview.c)
|
||||||
add_executable(triangle WIN32 triangle.c)
|
add_executable(triangle WIN32 triangle.c)
|
||||||
add_executable(wave WIN32 wave.c)
|
add_executable(wave WIN32 wave.c)
|
||||||
endif(APPLE)
|
endif()
|
||||||
|
|
||||||
set(WINDOWS_BINARIES boing gears heightmap splitview triangle wave)
|
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
|
set(WINDOWS_BINARIES boing gears heightmap splitview triangle wave)
|
||||||
|
|
||||||
# Tell MSVC to use main instead of WinMain for Windows subsystem executables
|
# Tell MSVC to use main instead of WinMain for Windows subsystem executables
|
||||||
set_target_properties(${WINDOWS_BINARIES} PROPERTIES
|
set_target_properties(${WINDOWS_BINARIES} PROPERTIES
|
||||||
LINK_FLAGS "/ENTRY:mainCRTStartup")
|
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()
|
||||||
|
|
||||||
|
|
|
@ -586,7 +586,7 @@ int main( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowSizeCallback( reshape );
|
glfwSetWindowSizeCallback( reshape );
|
||||||
glfwEnable( window, GLFW_STICKY_KEYS );
|
glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE );
|
||||||
glfwSwapInterval( 1 );
|
glfwSwapInterval( 1 );
|
||||||
glfwSetTime( 0.0 );
|
glfwSetTime( 0.0 );
|
||||||
|
|
||||||
|
|
|
@ -339,7 +339,7 @@ int main(int argc, char *argv[])
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwEnable( window, GLFW_KEY_REPEAT );
|
glfwSetInputMode( window, GLFW_KEY_REPEAT, GL_TRUE );
|
||||||
glfwSwapInterval( 1 );
|
glfwSwapInterval( 1 );
|
||||||
|
|
||||||
// Parse command-line options
|
// Parse command-line options
|
||||||
|
|
|
@ -573,7 +573,7 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GL_TRUE != glfwInit())
|
if (!glfwInit())
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ERROR: Unable to initialize GLFW\n");
|
fprintf(stderr, "ERROR: Unable to initialize GLFW\n");
|
||||||
usage();
|
usage();
|
||||||
|
|
|
@ -462,10 +462,10 @@ int main(void)
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
// Enable sticky keys
|
// Enable sticky keys
|
||||||
glfwEnable(window, GLFW_STICKY_KEYS);
|
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
|
||||||
|
|
||||||
// Enable mouse cursor (only needed for fullscreen mode)
|
// Enable mouse cursor (only needed for fullscreen mode)
|
||||||
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
|
||||||
|
|
||||||
// Set callback functions
|
// Set callback functions
|
||||||
glfwSetWindowSizeCallback(windowSizeFun);
|
glfwSetWindowSizeCallback(windowSizeFun);
|
||||||
|
|
|
@ -30,7 +30,7 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure we can capture the escape key being pressed below
|
// 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)
|
// Enable vertical sync (on cards that support it)
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
|
@ -309,13 +309,13 @@ void mouse_button_callback(GLFWwindow window, int button, int action)
|
||||||
|
|
||||||
if (action == GLFW_PRESS)
|
if (action == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED);
|
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED);
|
||||||
locked = GL_TRUE;
|
locked = GL_TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
locked = GL_FALSE;
|
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
|
// Keyboard handler
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwEnable(window, GLFW_KEY_REPEAT);
|
glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE);
|
||||||
|
|
||||||
// Window resize handler
|
// Window resize handler
|
||||||
glfwSetWindowSizeCallback(window_resize_callback);
|
glfwSetWindowSizeCallback(window_resize_callback);
|
||||||
|
|
|
@ -136,10 +136,6 @@ extern "C" {
|
||||||
|
|
||||||
/* -------------------- END SYSTEM/COMPILER SPECIFIC --------------------- */
|
/* -------------------- 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
|
/* 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
|
* 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
|
* 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_COMPAT_PROFILE 0x00000002
|
||||||
#define GLFW_OPENGL_ES2_PROFILE 0x00000004
|
#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_KEYS 0x00030002
|
||||||
#define GLFW_STICKY_MOUSE_BUTTONS 0x00030003
|
#define GLFW_STICKY_MOUSE_BUTTONS 0x00030003
|
||||||
#define GLFW_SYSTEM_KEYS 0x00030004
|
#define GLFW_SYSTEM_KEYS 0x00030004
|
||||||
#define GLFW_KEY_REPEAT 0x00030005
|
#define GLFW_KEY_REPEAT 0x00030005
|
||||||
|
|
||||||
/* glfwSetCursorMode tokens */
|
/* GLFW_CURSOR_MODE values */
|
||||||
#define GLFW_CURSOR_NORMAL 0x00040001
|
#define GLFW_CURSOR_NORMAL 0x00040001
|
||||||
#define GLFW_CURSOR_HIDDEN 0x00040002
|
#define GLFW_CURSOR_HIDDEN 0x00040002
|
||||||
#define GLFW_CURSOR_CAPTURED 0x00040003
|
#define GLFW_CURSOR_CAPTURED 0x00040003
|
||||||
|
@ -478,8 +475,6 @@ typedef void (* GLFWcursorenterfun)(GLFWwindow,int);
|
||||||
typedef void (* GLFWscrollfun)(GLFWwindow,int,int);
|
typedef void (* GLFWscrollfun)(GLFWwindow,int,int);
|
||||||
typedef void (* GLFWkeyfun)(GLFWwindow,int,int);
|
typedef void (* GLFWkeyfun)(GLFWwindow,int,int);
|
||||||
typedef void (* GLFWcharfun)(GLFWwindow,int);
|
typedef void (* GLFWcharfun)(GLFWwindow,int);
|
||||||
typedef void* (* GLFWmallocfun)(size_t);
|
|
||||||
typedef void (* GLFWfreefun)(void*);
|
|
||||||
|
|
||||||
/* The video mode structure used by glfwGetVideoModes */
|
/* The video mode structure used by glfwGetVideoModes */
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -499,19 +494,6 @@ typedef struct
|
||||||
unsigned short blue[GLFW_GAMMA_RAMP_SIZE];
|
unsigned short blue[GLFW_GAMMA_RAMP_SIZE];
|
||||||
} GLFWgammaramp;
|
} GLFWgammaramp;
|
||||||
|
|
||||||
/* Custom memory allocator interface */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GLFWmallocfun malloc;
|
|
||||||
GLFWfreefun free;
|
|
||||||
} GLFWallocator;
|
|
||||||
|
|
||||||
/* Custom threading model interface */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int dummy;
|
|
||||||
} GLFWthreadmodel;
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Prototypes
|
* Prototypes
|
||||||
|
@ -519,7 +501,6 @@ typedef struct
|
||||||
|
|
||||||
/* Initialization, termination and version querying */
|
/* Initialization, termination and version querying */
|
||||||
GLFWAPI int glfwInit(void);
|
GLFWAPI int glfwInit(void);
|
||||||
GLFWAPI int glfwInitWithModels(GLFWthreadmodel* threading, GLFWallocator* allocator);
|
|
||||||
GLFWAPI void glfwTerminate(void);
|
GLFWAPI void glfwTerminate(void);
|
||||||
GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev);
|
GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev);
|
||||||
GLFWAPI const char* glfwGetVersionString(void);
|
GLFWAPI const char* glfwGetVersionString(void);
|
||||||
|
@ -564,11 +545,12 @@ GLFWAPI void glfwPollEvents(void);
|
||||||
GLFWAPI void glfwWaitEvents(void);
|
GLFWAPI void glfwWaitEvents(void);
|
||||||
|
|
||||||
/* Input handling */
|
/* 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 glfwGetKey(GLFWwindow window, int key);
|
||||||
GLFWAPI int glfwGetMouseButton(GLFWwindow window, int button);
|
GLFWAPI int glfwGetMouseButton(GLFWwindow window, int button);
|
||||||
GLFWAPI void glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos);
|
GLFWAPI void glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos);
|
||||||
GLFWAPI void glfwSetMousePos(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 glfwGetScrollOffset(GLFWwindow window, int* xoffset, int* yoffset);
|
||||||
GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun);
|
GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun);
|
||||||
GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun);
|
GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun);
|
||||||
|
@ -595,10 +577,6 @@ GLFWAPI int glfwExtensionSupported(const char* extension);
|
||||||
GLFWAPI void* glfwGetProcAddress(const char* procname);
|
GLFWAPI void* glfwGetProcAddress(const char* procname);
|
||||||
GLFWAPI void glfwCopyContext(GLFWwindow src, GLFWwindow dst, unsigned long mask);
|
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
|
* Global definition cleanup
|
||||||
|
|
25
readme.html
25
readme.html
|
@ -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>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>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>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>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_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_ROBUSTNESS</code> window hint and associated strategy tokens for <code>GL_ARB_robustness</code> support</li>
|
||||||
<li>Added <code>GLFW_OPENGL_REVISION</code> window parameter to make up for removal of <code>glfwGetGLVersion</code></li>
|
<li>Added <code>GLFW_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>windows</code> simple multi-window test program</li>
|
||||||
<li>Added <code>sharing</code> simple OpenGL object sharing 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>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 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 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>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 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.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</code> token to <code>GLFW_WINDOWED</code></li>
|
||||||
<li>Renamed <code>GLFW_WINDOW_NO_RESIZE</code> to <code>GLFW_WINDOW_RESIZABLE</code></li>
|
<li>Renamed <code>GLFW_WINDOW_NO_RESIZE</code> to <code>GLFW_WINDOW_RESIZABLE</code></li>
|
||||||
|
@ -293,6 +293,7 @@ version of GLFW.</p>
|
||||||
<li>Replaced ad hoc build system with CMake</li>
|
<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 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 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>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 event auto-polling and the <code>GLFW_AUTO_POLL_EVENTS</code> window enable</li>
|
||||||
<li>Removed the Win32 port .def files</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>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 OpenGL 3.2 core profile in 10.7 Lion and above</li>
|
||||||
<li>[Cocoa] Added support for joysticks</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 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: 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 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 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 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: Calling <code>glXCreateContextAttribsARB</code> with an unavailable OpenGL version caused the application to terminate with a <code>BadMatch</code> Xlib error</li>
|
||||||
<li>[X11] Bugfix: A synchronization point necessary for jitter-free locked cursor mode was incorrectly removed</li>
|
<li>[X11] Bugfix: 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] 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: 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: 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: 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>
|
</ul>
|
||||||
|
|
||||||
<h3>v2.7</h3>
|
<h3>v2.7</h3>
|
||||||
|
@ -810,6 +823,8 @@ their skills. Special thanks go out to:</p>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
|
|
||||||
|
<li>artblanc, for a patch replacing a deprecated Core Graphics call</li>
|
||||||
|
|
||||||
<li>Bobyshev Alexander and Martins Mozeiko, for the original proposal of
|
<li>Bobyshev Alexander and Martins Mozeiko, for the original proposal of
|
||||||
an FSAA hint and their work on the Win32 implementation of FSAA</li>
|
an FSAA hint and their work on the Win32 implementation of FSAA</li>
|
||||||
|
|
||||||
|
@ -831,6 +846,9 @@ their skills. Special thanks go out to:</p>
|
||||||
<li>Ralph Eastwood, for the initial design and implementation of the gamma
|
<li>Ralph Eastwood, for the initial design and implementation of the gamma
|
||||||
correction API</li>
|
correction API</li>
|
||||||
|
|
||||||
|
<li>GeO4d, for the implementation of cursor enter/leave notifications on
|
||||||
|
Win32.</li>
|
||||||
|
|
||||||
<li>Gerald Franz, who made GLFW compile under IRIX, and supplied patches
|
<li>Gerald Franz, who made GLFW compile under IRIX, and supplied patches
|
||||||
for the X11 keyboard translation routine</li>
|
for the X11 keyboard translation routine</li>
|
||||||
|
|
||||||
|
@ -865,6 +883,9 @@ their skills. Special thanks go out to:</p>
|
||||||
|
|
||||||
<li>Tristam MacDonald, for his bug reports and feedback on the Cocoa port</li>
|
<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>David Medlock, for doing the initial Lua port</li>
|
||||||
|
|
||||||
<li>Kenneth Miller, for his many and detailed bug reports on Win32</li>
|
<li>Kenneth Miller, for his many and detailed bug reports on Win32</li>
|
||||||
|
|
|
@ -2,42 +2,42 @@
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
if (_GLFW_HAS_XRANDR)
|
if (_GLFW_HAS_XRANDR)
|
||||||
set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xrandr")
|
set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xrandr")
|
||||||
endif(_GLFW_HAS_XRANDR)
|
endif()
|
||||||
if (_GLFW_HAS_XF86VIDMODE)
|
if (_GLFW_HAS_XF86VIDMODE)
|
||||||
set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xxf86vm")
|
set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xxf86vm")
|
||||||
endif(_GLFW_HAS_XF86VIDMODE)
|
endif()
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY)
|
${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY)
|
||||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc DESTINATION lib/pkgconfig)
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc DESTINATION lib/pkgconfig)
|
||||||
endif(UNIX)
|
endif()
|
||||||
|
|
||||||
include_directories(${GLFW_SOURCE_DIR}/src
|
include_directories(${GLFW_SOURCE_DIR}/src
|
||||||
${GLFW_BINARY_DIR}/src
|
${GLFW_BINARY_DIR}/src
|
||||||
${GLFW_INCLUDE_DIR})
|
${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)
|
joystick.c opengl.c time.c window.c)
|
||||||
|
|
||||||
if(_GLFW_COCOA_NSGL)
|
if(_GLFW_COCOA_NSGL)
|
||||||
set(libglfw_SOURCES ${common_SOURCES} cocoa_enable.m cocoa_fullscreen.m
|
set(libglfw_SOURCES ${common_SOURCES} cocoa_fullscreen.m cocoa_gamma.c
|
||||||
cocoa_gamma.m cocoa_init.m cocoa_joystick.m
|
cocoa_init.m cocoa_input.m cocoa_joystick.m
|
||||||
cocoa_opengl.m cocoa_time.m cocoa_window.m)
|
cocoa_opengl.m cocoa_time.c cocoa_window.m)
|
||||||
|
|
||||||
# For some reason, CMake doesn't know about .m
|
# For some reason, CMake doesn't know about .m
|
||||||
set_source_files_properties(${libglfw_SOURCES} PROPERTIES LANGUAGE C)
|
set_source_files_properties(${libglfw_SOURCES} PROPERTIES LANGUAGE C)
|
||||||
elseif(_GLFW_WIN32_WGL)
|
elseif(_GLFW_WIN32_WGL)
|
||||||
set(libglfw_SOURCES ${common_SOURCES} win32_enable.c win32_fullscreen.c
|
set(libglfw_SOURCES ${common_SOURCES} win32_fullscreen.c win32_gamma.c
|
||||||
win32_gamma.c win32_init.c win32_joystick.c
|
win32_init.c win32_input.c win32_joystick.c
|
||||||
win32_opengl.c win32_time.c win32_window.c
|
win32_opengl.c win32_time.c win32_window.c
|
||||||
win32_dllmain.c)
|
win32_dllmain.c)
|
||||||
elseif(_GLFW_X11_GLX)
|
elseif(_GLFW_X11_GLX)
|
||||||
set(libglfw_SOURCES ${common_SOURCES} x11_enable.c x11_fullscreen.c
|
set(libglfw_SOURCES ${common_SOURCES} x11_fullscreen.c x11_gamma.c
|
||||||
x11_gamma.c x11_init.c x11_joystick.c
|
x11_init.c x11_input.c x11_joystick.c
|
||||||
x11_keysym2unicode.c x11_opengl.c x11_time.c
|
x11_keysym2unicode.c x11_opengl.c x11_time.c
|
||||||
x11_window.c)
|
x11_window.c)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "No supported platform was selected")
|
message(FATAL_ERROR "No supported platform was selected")
|
||||||
endif(_GLFW_COCOA_NSGL)
|
endif()
|
||||||
|
|
||||||
add_library(libglfwStatic STATIC ${libglfw_SOURCES})
|
add_library(libglfwStatic STATIC ${libglfw_SOURCES})
|
||||||
add_library(libglfwShared SHARED ${libglfw_SOURCES})
|
add_library(libglfwShared SHARED ${libglfw_SOURCES})
|
||||||
|
@ -47,22 +47,23 @@ set_target_properties(libglfwStatic libglfwShared PROPERTIES
|
||||||
OUTPUT_NAME glfw)
|
OUTPUT_NAME glfw)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
|
target_link_libraries(libglfwShared winmm)
|
||||||
# The GLFW DLL needs a special compile-time macro and import library name
|
# The GLFW DLL needs a special compile-time macro and import library name
|
||||||
set_target_properties(libglfwShared PROPERTIES
|
set_target_properties(libglfwShared PROPERTIES
|
||||||
DEFINE_SYMBOL GLFW_BUILD_DLL
|
COMPILE_DEFINITIONS "GLFW_BUILD_DLL;_GLFW_NO_DLOAD_GDI32;_GLFW_NO_DLOAD_WINMM"
|
||||||
PREFIX ""
|
PREFIX ""
|
||||||
IMPORT_PREFIX ""
|
IMPORT_PREFIX ""
|
||||||
IMPORT_SUFFIX "dll.lib")
|
IMPORT_SUFFIX "dll.lib")
|
||||||
endif(WIN32)
|
endif()
|
||||||
|
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
# Append -fno-common to the compile flags to work around a bug in the Apple GCC
|
# Append -fno-common to the compile flags to work around a bug in the Apple GCC
|
||||||
get_target_property(CFLAGS libglfwShared COMPILE_FLAGS)
|
get_target_property(CFLAGS libglfwShared COMPILE_FLAGS)
|
||||||
if (NOT CFLAGS)
|
if (NOT CFLAGS)
|
||||||
set(CFLAGS "")
|
set(CFLAGS "")
|
||||||
endif(NOT CFLAGS)
|
endif()
|
||||||
set_target_properties(libglfwShared PROPERTIES COMPILE_FLAGS "${CFLAGS} -fno-common")
|
set_target_properties(libglfwShared PROPERTIES COMPILE_FLAGS "${CFLAGS} -fno-common")
|
||||||
endif(APPLE)
|
endif()
|
||||||
|
|
||||||
install(TARGETS libglfwStatic libglfwShared DESTINATION lib)
|
install(TARGETS libglfwStatic libglfwShared DESTINATION lib)
|
||||||
|
|
||||||
|
|
|
@ -29,47 +29,166 @@
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Check whether the display mode should be included in enumeration
|
// 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
|
uint32_t flags = CGDisplayModeGetIOFlags(mode);
|
||||||
// LCD computer monitor as an output device you might not want these
|
if (!(flags & kDisplayModeValidFlag) || !(flags & kDisplayModeSafeFlag))
|
||||||
// checks. You might also want to reject modes which are interlaced,
|
return GL_FALSE;
|
||||||
// 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
|
if (flags & kDisplayModeInterlacedFlag)
|
||||||
// wish to patch this...
|
return GL_FALSE;
|
||||||
return [[mode objectForKey:(id)kCGDisplayBitsPerPixel] intValue] >= 15 &&
|
|
||||||
[mode objectForKey:(id)kCGDisplayModeIsSafeForHardware] != nil &&
|
if (flags & kDisplayModeTelevisionFlag)
|
||||||
[mode objectForKey:(id)kCGDisplayModeIsStretched] == nil;
|
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
|
// 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;
|
GLFWvidmode result;
|
||||||
result.width = width;
|
result.width = CGDisplayModeGetWidth(mode);
|
||||||
result.height = height;
|
result.height = CGDisplayModeGetHeight(mode);
|
||||||
result.redBits = bps;
|
|
||||||
result.greenBits = bps;
|
CFStringRef format = CGDisplayModeCopyPixelEncoding(mode);
|
||||||
result.blueBits = bps;
|
|
||||||
|
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;
|
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 //////
|
////// GLFW platform API //////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -80,19 +199,26 @@ static GLFWvidmode vidmodeFromCGDisplayMode(NSDictionary* mode)
|
||||||
|
|
||||||
int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||||
{
|
{
|
||||||
NSArray* modes = (NSArray*) CGDisplayAvailableModes(CGMainDisplayID());
|
CGDisplayModeRef mode;
|
||||||
unsigned int i, j = 0, n = [modes count];
|
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))
|
if (modeIsGood(mode))
|
||||||
list[j++] = vidmodeFromCGDisplayMode(mode);
|
list[stored++] = vidmodeFromCGDisplayMode(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return j;
|
CFRelease(modes);
|
||||||
|
return stored;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Get the desktop video mode
|
// Get the desktop video mode
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
|
|
||||||
|
|
||||||
//************************************************************************
|
//************************************************************************
|
||||||
//**** GLFW internal functions ****
|
//**** GLFW internal functions ****
|
203
src/cocoa_init.m
203
src/cocoa_init.m
|
@ -27,162 +27,45 @@
|
||||||
//
|
//
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
// Needed for _NSGetProgname
|
|
||||||
#include <crt_externs.h>
|
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW application class
|
// Change to our application bundle's resources directory, if present
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
@interface GLFWApplication : NSApplication
|
static void changeToResourcesDirectory(void)
|
||||||
@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))
|
char resourcesPath[MAXPATHLEN];
|
||||||
[[self keyWindow] sendEvent:event];
|
|
||||||
else
|
CFBundleRef bundle = CFBundleGetMainBundle();
|
||||||
[super sendEvent:event];
|
if (!bundle)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(bundle);
|
||||||
|
|
||||||
|
CFStringRef last = CFURLCopyLastPathComponent(resourcesURL);
|
||||||
|
if (CFStringCompare(CFSTR("Resources"), last, 0) != kCFCompareEqualTo)
|
||||||
|
{
|
||||||
|
CFRelease(last);
|
||||||
|
CFRelease(resourcesURL);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
CFRelease(last);
|
||||||
|
|
||||||
|
if (!CFURLGetFileSystemRepresentation(resourcesURL,
|
||||||
// Prior to Snow Leopard, we need to use this oddly-named semi-private API
|
true,
|
||||||
// to get the application menu working properly. Need to be careful in
|
(UInt8*) resourcesPath,
|
||||||
// case it goes away in a future OS update.
|
MAXPATHLEN))
|
||||||
@interface NSApplication (NSAppleMenu)
|
|
||||||
- (void)setAppleMenu:(NSMenu*)m;
|
|
||||||
@end
|
|
||||||
|
|
||||||
// Keys to search for as potential application names
|
|
||||||
NSString* GLFWNameKeys[] =
|
|
||||||
{
|
{
|
||||||
@"CFBundleDisplayName",
|
CFRelease(resourcesURL);
|
||||||
@"CFBundleName",
|
return;
|
||||||
@"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++)
|
|
||||||
{
|
|
||||||
id name = [infoDictionary objectForKey:GLFWNameKeys[i]];
|
|
||||||
if (name &&
|
|
||||||
[name isKindOfClass:[NSString class]] &&
|
|
||||||
![@"" isEqualToString:name])
|
|
||||||
{
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we get here, we're unbundled
|
CFRelease(resourcesURL);
|
||||||
if (!_glfwLibrary.NS.unbundled)
|
|
||||||
{
|
|
||||||
// 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
|
chdir(resourcesPath);
|
||||||
// handy. There is an NSApplication API to do this, but...
|
|
||||||
SetFrontProcess(&psn);
|
|
||||||
|
|
||||||
_glfwLibrary.NS.unbundled = GL_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -198,9 +81,6 @@ int _glfwPlatformInit(void)
|
||||||
{
|
{
|
||||||
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
|
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
// Implicitly create shared NSApplication instance
|
|
||||||
[GLFWApplication sharedApplication];
|
|
||||||
|
|
||||||
_glfwLibrary.NS.OpenGLFramework =
|
_glfwLibrary.NS.OpenGLFramework =
|
||||||
CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
|
CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
|
||||||
if (_glfwLibrary.NS.OpenGLFramework == NULL)
|
if (_glfwLibrary.NS.OpenGLFramework == NULL)
|
||||||
|
@ -210,31 +90,30 @@ int _glfwPlatformInit(void)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
|
changeToResourcesDirectory();
|
||||||
|
|
||||||
if (access([resourcePath cStringUsingEncoding:NSUTF8StringEncoding], R_OK) == 0)
|
_glfwLibrary.NS.desktopMode = CGDisplayCopyDisplayMode(CGMainDisplayID());
|
||||||
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());
|
|
||||||
|
|
||||||
// Save the original gamma ramp
|
// Save the original gamma ramp
|
||||||
_glfwLibrary.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID());
|
_glfwLibrary.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID());
|
||||||
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
|
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
|
||||||
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp;
|
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp;
|
||||||
|
|
||||||
|
_glfwInitTimer();
|
||||||
|
|
||||||
_glfwInitJoysticks();
|
_glfwInitJoysticks();
|
||||||
|
|
||||||
|
_glfwLibrary.NS.eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||||
|
if (!_glfwLibrary.NS.eventSource)
|
||||||
|
return GL_FALSE;
|
||||||
|
|
||||||
|
CGEventSourceSetLocalEventsSuppressionInterval(_glfwLibrary.NS.eventSource,
|
||||||
|
0.0);
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Close window, if open, and shut down GLFW
|
// Close window, if open, and shut down GLFW
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -243,9 +122,17 @@ int _glfwPlatformTerminate(void)
|
||||||
{
|
{
|
||||||
// TODO: Probably other cleanup
|
// TODO: Probably other cleanup
|
||||||
|
|
||||||
|
if (_glfwLibrary.NS.eventSource)
|
||||||
|
{
|
||||||
|
CFRelease(_glfwLibrary.NS.eventSource);
|
||||||
|
_glfwLibrary.NS.eventSource = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Restore the original gamma ramp
|
// Restore the original gamma ramp
|
||||||
_glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp);
|
_glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp);
|
||||||
|
|
||||||
|
CGDisplayModeRelease(_glfwLibrary.NS.desktopMode);
|
||||||
|
|
||||||
[NSApp setDelegate:nil];
|
[NSApp setDelegate:nil];
|
||||||
[_glfwLibrary.NS.delegate release];
|
[_glfwLibrary.NS.delegate release];
|
||||||
_glfwLibrary.NS.delegate = nil;
|
_glfwLibrary.NS.delegate = nil;
|
||||||
|
|
|
@ -152,7 +152,7 @@ static void addJoystickElement(_glfwJoystick* joystick, CFTypeRef refElement)
|
||||||
long number;
|
long number;
|
||||||
CFTypeRef refType;
|
CFTypeRef refType;
|
||||||
|
|
||||||
_glfwJoystickElement* element = (_glfwJoystickElement*) _glfwMalloc(sizeof(_glfwJoystickElement));
|
_glfwJoystickElement* element = (_glfwJoystickElement*) malloc(sizeof(_glfwJoystickElement));
|
||||||
|
|
||||||
CFArrayAppendValue(elementsArray, element);
|
CFArrayAppendValue(elementsArray, element);
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ static void removeJoystick(_glfwJoystick* joystick)
|
||||||
{
|
{
|
||||||
_glfwJoystickElement* axes =
|
_glfwJoystickElement* axes =
|
||||||
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->axes, i);
|
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->axes, i);
|
||||||
_glfwFree(axes);
|
free(axes);
|
||||||
}
|
}
|
||||||
CFArrayRemoveAllValues(joystick->axes);
|
CFArrayRemoveAllValues(joystick->axes);
|
||||||
joystick->numAxes = 0;
|
joystick->numAxes = 0;
|
||||||
|
@ -251,7 +251,7 @@ static void removeJoystick(_glfwJoystick* joystick)
|
||||||
{
|
{
|
||||||
_glfwJoystickElement* button =
|
_glfwJoystickElement* button =
|
||||||
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->buttons, i);
|
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->buttons, i);
|
||||||
_glfwFree(button);
|
free(button);
|
||||||
}
|
}
|
||||||
CFArrayRemoveAllValues(joystick->buttons);
|
CFArrayRemoveAllValues(joystick->buttons);
|
||||||
joystick->numButtons = 0;
|
joystick->numButtons = 0;
|
||||||
|
@ -260,7 +260,7 @@ static void removeJoystick(_glfwJoystick* joystick)
|
||||||
{
|
{
|
||||||
_glfwJoystickElement* hat =
|
_glfwJoystickElement* hat =
|
||||||
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->hats, i);
|
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->hats, i);
|
||||||
_glfwFree(hat);
|
free(hat);
|
||||||
}
|
}
|
||||||
CFArrayRemoveAllValues(joystick->hats);
|
CFArrayRemoveAllValues(joystick->hats);
|
||||||
joystick->hats = 0;
|
joystick->hats = 0;
|
||||||
|
@ -579,4 +579,3 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
|
||||||
return numbuttons;
|
return numbuttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,7 @@ void _glfwPlatformSwapBuffers(void)
|
||||||
[window->NSGL.context flushBuffer];
|
[window->NSGL.context flushBuffer];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set double buffering swap interval
|
// Set double buffering swap interval
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -71,6 +72,7 @@ void _glfwPlatformSwapInterval(int interval)
|
||||||
[window->NSGL.context setValues:&sync forParameter:NSOpenGLCPSwapInterval];
|
[window->NSGL.context setValues:&sync forParameter:NSOpenGLCPSwapInterval];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Check if an OpenGL extension is available at runtime
|
// Check if an OpenGL extension is available at runtime
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -81,6 +83,7 @@ int _glfwPlatformExtensionSupported(const char* extension)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Get the function pointer to an OpenGL function
|
// Get the function pointer to an OpenGL function
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -99,6 +102,7 @@ void* _glfwPlatformGetProcAddress(const char* procname)
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Copies the specified OpenGL state categories from src to dst
|
// Copies the specified OpenGL state categories from src to dst
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#if defined(__OBJC__)
|
#if defined(__OBJC__)
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
#else
|
#else
|
||||||
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
typedef void* id;
|
typedef void* id;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -85,13 +86,14 @@ typedef struct _GLFWwindowNS
|
||||||
typedef struct _GLFWlibraryNS
|
typedef struct _GLFWlibraryNS
|
||||||
{
|
{
|
||||||
struct {
|
struct {
|
||||||
double t0;
|
double base;
|
||||||
|
double resolution;
|
||||||
} timer;
|
} timer;
|
||||||
|
|
||||||
// dlopen handle for dynamically loading OpenGL extension entry points
|
// dlopen handle for dynamically loading OpenGL extension entry points
|
||||||
void* OpenGLFramework;
|
void* OpenGLFramework;
|
||||||
GLboolean unbundled;
|
CGDisplayModeRef desktopMode;
|
||||||
id desktopMode;
|
CGEventSourceRef eventSource;
|
||||||
id delegate;
|
id delegate;
|
||||||
id autoreleasePool;
|
id autoreleasePool;
|
||||||
} _GLFWlibraryNS;
|
} _GLFWlibraryNS;
|
||||||
|
@ -101,9 +103,15 @@ typedef struct _GLFWlibraryNS
|
||||||
// Prototypes for platform specific internal functions
|
// Prototypes for platform specific internal functions
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
|
// Time
|
||||||
|
void _glfwInitTimer(void);
|
||||||
|
|
||||||
// Joystick input
|
// Joystick input
|
||||||
void _glfwInitJoysticks(void);
|
void _glfwInitJoysticks(void);
|
||||||
void _glfwTerminateJoysticks(void);
|
void _glfwTerminateJoysticks(void);
|
||||||
|
|
||||||
|
// Fullscreen
|
||||||
|
GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate);
|
||||||
|
void _glfwRestoreVideoMode(void);
|
||||||
|
|
||||||
#endif // _platform_h_
|
#endif // _platform_h_
|
||||||
|
|
|
@ -29,6 +29,36 @@
|
||||||
|
|
||||||
#include "internal.h"
|
#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 //////
|
////// GLFW platform API //////
|
||||||
|
@ -40,17 +70,18 @@
|
||||||
|
|
||||||
double _glfwPlatformGetTime(void)
|
double _glfwPlatformGetTime(void)
|
||||||
{
|
{
|
||||||
return [NSDate timeIntervalSinceReferenceDate] -
|
return (double) (getRawTime() - _glfwLibrary.NS.timer.base) *
|
||||||
_glfwLibrary.NS.timer.t0;
|
_glfwLibrary.NS.timer.resolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set timer value in seconds
|
// Set timer value in seconds
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformSetTime(double time)
|
void _glfwPlatformSetTime(double time)
|
||||||
{
|
{
|
||||||
_glfwLibrary.NS.timer.t0 =
|
_glfwLibrary.NS.timer.base = getRawTime() -
|
||||||
[NSDate timeIntervalSinceReferenceDate] - time;
|
(uint64_t) (time / _glfwLibrary.NS.timer.resolution);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
|
// Needed for _NSGetProgname
|
||||||
|
#include <crt_externs.h>
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Delegate for window related notifications
|
// Delegate for window related notifications
|
||||||
|
@ -109,6 +112,7 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Delegate for application related notifications
|
// Delegate for application related notifications
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -130,12 +134,16 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Keyboard symbol translation table
|
// Converts a Mac OS X keycode to a GLFW keycode
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
|
static int convertMacKeyCode(unsigned int macKeyCode)
|
||||||
|
{
|
||||||
|
// Keyboard symbol translation table
|
||||||
// TODO: Need to find mappings for F13-F15, volume down/up/mute, and eject.
|
// 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 const unsigned int table[128] =
|
||||||
{
|
{
|
||||||
/* 00 */ GLFW_KEY_A,
|
/* 00 */ GLFW_KEY_A,
|
||||||
/* 01 */ GLFW_KEY_S,
|
/* 01 */ GLFW_KEY_S,
|
||||||
|
@ -147,7 +155,7 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
|
||||||
/* 07 */ GLFW_KEY_X,
|
/* 07 */ GLFW_KEY_X,
|
||||||
/* 08 */ GLFW_KEY_C,
|
/* 08 */ GLFW_KEY_C,
|
||||||
/* 09 */ GLFW_KEY_V,
|
/* 09 */ GLFW_KEY_V,
|
||||||
/* 0a */ -1,
|
/* 0a */ GLFW_KEY_GRAVE_ACCENT,
|
||||||
/* 0b */ GLFW_KEY_B,
|
/* 0b */ GLFW_KEY_B,
|
||||||
/* 0c */ GLFW_KEY_Q,
|
/* 0c */ GLFW_KEY_Q,
|
||||||
/* 0d */ GLFW_KEY_W,
|
/* 0d */ GLFW_KEY_W,
|
||||||
|
@ -187,7 +195,7 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
|
||||||
/* 2f */ GLFW_KEY_PERIOD,
|
/* 2f */ GLFW_KEY_PERIOD,
|
||||||
/* 30 */ GLFW_KEY_TAB,
|
/* 30 */ GLFW_KEY_TAB,
|
||||||
/* 31 */ GLFW_KEY_SPACE,
|
/* 31 */ GLFW_KEY_SPACE,
|
||||||
/* 32 */ GLFW_KEY_GRAVE_ACCENT,
|
/* 32 */ GLFW_KEY_WORLD_1,
|
||||||
/* 33 */ GLFW_KEY_BACKSPACE,
|
/* 33 */ GLFW_KEY_BACKSPACE,
|
||||||
/* 34 */ -1,
|
/* 34 */ -1,
|
||||||
/* 35 */ GLFW_KEY_ESCAPE,
|
/* 35 */ GLFW_KEY_ESCAPE,
|
||||||
|
@ -267,21 +275,16 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
|
||||||
/* 7f */ -1,
|
/* 7f */ -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// Converts a Mac OS X keycode to a GLFW keycode
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
static int convertMacKeyCode(unsigned int macKeyCode)
|
|
||||||
{
|
|
||||||
if (macKeyCode >= 128)
|
if (macKeyCode >= 128)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// This treats keycodes as *positional*; that is, we'll return 'a'
|
// This treats keycodes as *positional*; that is, we'll return 'a'
|
||||||
// for the key left of 's', even on an AZERTY keyboard. The charInput
|
// for the key left of 's', even on an AZERTY keyboard. The charInput
|
||||||
// function should still get 'q' though.
|
// function should still get 'q' though.
|
||||||
return MAC_TO_GLFW_KEYCODE_MAPPING[macKeyCode];
|
return table[macKeyCode];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Content view class for the GLFW window
|
// Content view class for the GLFW window
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -385,15 +388,15 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||||
{
|
{
|
||||||
NSUInteger i, length;
|
NSUInteger i, length;
|
||||||
NSString* characters;
|
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 ([event modifierFlags] & NSCommandKeyMask)
|
||||||
{
|
{
|
||||||
if (!window->sysKeysDisabled)
|
if (window->systemKeys)
|
||||||
[super keyDown:event];
|
[super keyDown:event];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -409,7 +412,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||||
|
|
||||||
- (void)flagsChanged:(NSEvent *)event
|
- (void)flagsChanged:(NSEvent *)event
|
||||||
{
|
{
|
||||||
int mode;
|
int mode, key;
|
||||||
unsigned int newModifierFlags =
|
unsigned int newModifierFlags =
|
||||||
[event modifierFlags] | NSDeviceIndependentModifierFlagsMask;
|
[event modifierFlags] | NSDeviceIndependentModifierFlagsMask;
|
||||||
|
|
||||||
|
@ -419,14 +422,17 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||||
mode = GLFW_RELEASE;
|
mode = GLFW_RELEASE;
|
||||||
|
|
||||||
window->NS.modifierFlags = newModifierFlags;
|
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
|
- (void)keyUp:(NSEvent *)event
|
||||||
{
|
{
|
||||||
int code = convertMacKeyCode([event keyCode]);
|
int key = convertMacKeyCode([event keyCode]);
|
||||||
if (code != -1)
|
if (key != -1)
|
||||||
_glfwInputKey(window, code, GLFW_RELEASE);
|
_glfwInputKey(window, key, GLFW_RELEASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)scrollWheel:(NSEvent *)event
|
- (void)scrollWheel:(NSEvent *)event
|
||||||
|
@ -443,6 +449,169 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// GLFW application class
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
@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
|
// Create the Cocoa window
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -476,9 +645,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
[window->NS.window setTitle:[NSString stringWithCString:wndconfig->title
|
[window->NS.window setTitle:[NSString stringWithUTF8String:wndconfig->title]];
|
||||||
encoding:NSISOLatin1StringEncoding]];
|
|
||||||
|
|
||||||
[window->NS.window setContentView:[[GLFWContentView alloc]
|
[window->NS.window setContentView:[[GLFWContentView alloc]
|
||||||
initWithGlfwWindow:window]];
|
initWithGlfwWindow:window]];
|
||||||
[window->NS.window setDelegate:window->NS.delegate];
|
[window->NS.window setDelegate:window->NS.delegate];
|
||||||
|
@ -488,6 +655,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Create the OpenGL context
|
// Create the OpenGL context
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -516,14 +684,23 @@ static GLboolean createContext(_GLFWwindow* window,
|
||||||
return GL_FALSE;
|
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)
|
if (wndconfig->glProfile != GLFW_OPENGL_CORE_PROFILE)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||||
"Cocoa/NSOpenGL: The targeted version of Mac OS X "
|
"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;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -557,7 +734,6 @@ static GLboolean createContext(_GLFWwindow* window,
|
||||||
|
|
||||||
if (wndconfig->mode == GLFW_FULLSCREEN)
|
if (wndconfig->mode == GLFW_FULLSCREEN)
|
||||||
{
|
{
|
||||||
ADD_ATTR(NSOpenGLPFAFullScreen);
|
|
||||||
ADD_ATTR(NSOpenGLPFANoRecovery);
|
ADD_ATTR(NSOpenGLPFANoRecovery);
|
||||||
ADD_ATTR2(NSOpenGLPFAScreenMask,
|
ADD_ATTR2(NSOpenGLPFAScreenMask,
|
||||||
CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()));
|
CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()));
|
||||||
|
@ -607,7 +783,7 @@ static GLboolean createContext(_GLFWwindow* window,
|
||||||
if (window->NSGL.pixelFormat == nil)
|
if (window->NSGL.pixelFormat == nil)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Cocoa/NSOpenGL: Failed to create pixel format");
|
"Cocoa/NSOpenGL: Failed to create OpenGL pixel format");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -643,6 +819,11 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||||
const _GLFWwndconfig* wndconfig,
|
const _GLFWwndconfig* wndconfig,
|
||||||
const _GLFWfbconfig* fbconfig)
|
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
|
// 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
|
// first time we create a window to keep all window code in this file
|
||||||
if (_glfwLibrary.NS.delegate == nil)
|
if (_glfwLibrary.NS.delegate == nil)
|
||||||
|
@ -674,37 +855,9 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||||
else if (colorBits < 15)
|
else if (colorBits < 15)
|
||||||
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
|
// Don't use accumulation buffer support; it's not accelerated
|
||||||
// Aux buffers probably aren't accelerated either
|
// 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];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!createWindow(window, wndconfig))
|
if (!createWindow(window, wndconfig))
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
|
@ -716,13 +869,16 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||||
|
|
||||||
if (wndconfig->mode == GLFW_FULLSCREEN)
|
if (wndconfig->mode == GLFW_FULLSCREEN)
|
||||||
{
|
{
|
||||||
CGCaptureAllDisplays();
|
int bpp = colorBits + fbconfig->alphaBits;
|
||||||
CGDisplaySwitchToMode(CGMainDisplayID(), fullscreenMode);
|
|
||||||
|
if (!_glfwSetVideoMode(&window->width,
|
||||||
|
&window->height,
|
||||||
|
&bpp,
|
||||||
|
&window->refreshRate))
|
||||||
|
{
|
||||||
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wndconfig->mode == GLFW_FULLSCREEN)
|
|
||||||
{
|
|
||||||
// TODO: Make this work on pre-Leopard systems
|
|
||||||
[[window->NS.window contentView] enterFullScreenMode:[NSScreen mainScreen]
|
[[window->NS.window contentView] enterFullScreenMode:[NSScreen mainScreen]
|
||||||
withOptions:nil];
|
withOptions:nil];
|
||||||
}
|
}
|
||||||
|
@ -751,9 +907,7 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
[[window->NS.window contentView] exitFullScreenModeWithOptions:nil];
|
[[window->NS.window contentView] exitFullScreenModeWithOptions:nil];
|
||||||
|
|
||||||
CGDisplaySwitchToMode(CGMainDisplayID(),
|
_glfwRestoreVideoMode();
|
||||||
(CFDictionaryRef) _glfwLibrary.NS.desktopMode);
|
|
||||||
CGReleaseAllDisplays();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[window->NSGL.pixelFormat release];
|
[window->NSGL.pixelFormat release];
|
||||||
|
@ -773,16 +927,17 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
|
||||||
// TODO: Probably more cleanup
|
// TODO: Probably more cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set the window title
|
// Set the window title
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
|
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
|
||||||
{
|
{
|
||||||
[window->NS.window setTitle:[NSString stringWithCString:title
|
[window->NS.window setTitle:[NSString stringWithUTF8String:title]];
|
||||||
encoding:NSISOLatin1StringEncoding]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set the window size
|
// Set the window size
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -792,6 +947,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
||||||
[window->NS.window setContentSize:NSMakeSize(width, height)];
|
[window->NS.window setContentSize:NSMakeSize(width, height)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set the window position
|
// Set the window position
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -812,6 +968,7 @@ void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y)
|
||||||
display:YES];
|
display:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Iconify the window
|
// Iconify the window
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -821,6 +978,7 @@ void _glfwPlatformIconifyWindow(_GLFWwindow* window)
|
||||||
[window->NS.window miniaturize:nil];
|
[window->NS.window miniaturize:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Restore (un-iconify) the window
|
// Restore (un-iconify) the window
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -830,6 +988,7 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
||||||
[window->NS.window deminiaturize:nil];
|
[window->NS.window deminiaturize:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Write back window parameters into GLFW window structure
|
// Write back window parameters into GLFW window structure
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -904,6 +1063,7 @@ void _glfwPlatformRefreshWindowParams(void)
|
||||||
window->glDebug = GL_FALSE;
|
window->glDebug = GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Poll for new window and input events
|
// Poll for new window and input events
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -928,6 +1088,7 @@ void _glfwPlatformPollEvents(void)
|
||||||
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
|
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Wait for new window and input events
|
// Wait for new window and input events
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -946,6 +1107,7 @@ void _glfwPlatformWaitEvents( void )
|
||||||
_glfwPlatformPollEvents();
|
_glfwPlatformPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set physical mouse cursor position
|
// Set physical mouse cursor position
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -963,11 +1125,6 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y)
|
||||||
// calculating the maximum y coordinate of all screens, since Cocoa's
|
// calculating the maximum y coordinate of all screens, since Cocoa's
|
||||||
// "global coordinates" are upside down from CG'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 localPoint = NSMakePoint(x, y);
|
||||||
NSPoint globalPoint = [window->NS.window convertBaseToScreen:localPoint];
|
NSPoint globalPoint = [window->NS.window convertBaseToScreen:localPoint];
|
||||||
CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin;
|
CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin;
|
||||||
|
@ -978,6 +1135,7 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y)
|
||||||
CGDisplayMoveCursorToPoint(CGMainDisplayID(), targetPoint);
|
CGDisplayMoveCursorToPoint(CGMainDisplayID(), targetPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set physical mouse cursor mode
|
// Set physical mouse cursor mode
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
|
@ -60,11 +60,6 @@
|
||||||
// Define this to 1 if the Linux joystick API is available
|
// Define this to 1 if the Linux joystick API is available
|
||||||
#cmakedefine _GLFW_USE_LINUX_JOYSTICKS 1
|
#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
|
// The GLFW version as used by glfwGetVersionString
|
||||||
#define _GLFW_VERSION_FULL "@GLFW_VERSION_FULL@"
|
#define _GLFW_VERSION_FULL "@GLFW_VERSION_FULL@"
|
||||||
|
|
||||||
|
|
192
src/enable.c
192
src/enable.c
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
55
src/init.c
55
src/init.c
|
@ -35,30 +35,6 @@
|
||||||
#include <stdlib.h>
|
#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 //////
|
////// GLFW public API //////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -68,43 +44,12 @@ void _glfwFree(void* ptr)
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI int glfwInit(void)
|
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)
|
if (_glfwInitialized)
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
|
|
||||||
memset(&_glfwLibrary, 0, sizeof(_glfwLibrary));
|
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
|
// Not all window hints have zero as their default value, so this
|
||||||
// needs to be here despite the memset above
|
// needs to be here despite the memset above
|
||||||
_glfwSetDefaultWindowHints();
|
_glfwSetDefaultWindowHints();
|
||||||
|
|
244
src/input.c
244
src/input.c
|
@ -31,6 +31,122 @@
|
||||||
#include "internal.h"
|
#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 //////
|
////// GLFW internal API //////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -41,7 +157,7 @@
|
||||||
|
|
||||||
void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
||||||
{
|
{
|
||||||
GLboolean keyrepeat = GL_FALSE;
|
GLboolean repeated = GL_FALSE;
|
||||||
|
|
||||||
if (key < 0 || key > GLFW_KEY_LAST)
|
if (key < 0 || key > GLFW_KEY_LAST)
|
||||||
return;
|
return;
|
||||||
|
@ -55,12 +171,12 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
||||||
window->key[key] = GLFW_STICK;
|
window->key[key] = GLFW_STICK;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
keyrepeat = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS);
|
repeated = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS);
|
||||||
window->key[key] = (char) action;
|
window->key[key] = (char) action;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call user callback function
|
// Call user callback function
|
||||||
if (_glfwLibrary.keyCallback && (window->keyRepeat || !keyrepeat))
|
if (_glfwLibrary.keyCallback && (window->keyRepeat || !repeated))
|
||||||
_glfwLibrary.keyCallback(window, key, action);
|
_glfwLibrary.keyCallback(window, key, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +277,77 @@ void _glfwInputCursorEnter(_GLFWwindow* window, int entered)
|
||||||
////// GLFW public API //////
|
////// 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
|
// 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;
|
return GLFW_RELEASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is it a valid key?
|
|
||||||
if (key < 0 || key > GLFW_KEY_LAST)
|
if (key < 0 || key > GLFW_KEY_LAST)
|
||||||
{
|
{
|
||||||
// TODO: Decide whether key is a value or enum
|
|
||||||
_glfwSetError(GLFW_INVALID_ENUM,
|
_glfwSetError(GLFW_INVALID_ENUM,
|
||||||
"glfwGetKey: The specified key is invalid");
|
"glfwGetKey: The specified key is invalid");
|
||||||
return GLFW_RELEASE;
|
return GLFW_RELEASE;
|
||||||
|
@ -209,7 +394,6 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow handle, int button)
|
||||||
return GLFW_RELEASE;
|
return GLFW_RELEASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is it a valid mouse button?
|
|
||||||
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
|
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_INVALID_ENUM,
|
_glfwSetError(GLFW_INVALID_ENUM,
|
||||||
|
@ -242,7 +426,6 @@ GLFWAPI void glfwGetMousePos(GLFWwindow handle, int* xpos, int* ypos)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return mouse position
|
|
||||||
if (xpos != NULL)
|
if (xpos != NULL)
|
||||||
*xpos = window->cursorPosX;
|
*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
|
// Set callback function for keyboard input
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -416,7 +554,6 @@ GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set callback function
|
|
||||||
_glfwLibrary.mousePosCallback = cbfun;
|
_glfwLibrary.mousePosCallback = cbfun;
|
||||||
|
|
||||||
// Call the callback function to let the application know the current
|
// Call the callback function to let the application know the current
|
||||||
|
@ -459,7 +596,6 @@ GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set callback function
|
|
||||||
_glfwLibrary.scrollCallback = cbfun;
|
_glfwLibrary.scrollCallback = cbfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,7 +183,7 @@ struct _GLFWwindow
|
||||||
GLboolean stickyKeys;
|
GLboolean stickyKeys;
|
||||||
GLboolean stickyMouseButtons;
|
GLboolean stickyMouseButtons;
|
||||||
GLboolean keyRepeat;
|
GLboolean keyRepeat;
|
||||||
GLboolean sysKeysDisabled; // system keys disabled flag
|
GLboolean systemKeys; // system keys enabled flag
|
||||||
int cursorPosX, cursorPosY;
|
int cursorPosX, cursorPosY;
|
||||||
int cursorMode;
|
int cursorMode;
|
||||||
int scrollX, scrollY;
|
int scrollX, scrollY;
|
||||||
|
@ -242,9 +242,6 @@ struct _GLFWlibrary
|
||||||
GLFWkeyfun keyCallback;
|
GLFWkeyfun keyCallback;
|
||||||
GLFWcharfun charCallback;
|
GLFWcharfun charCallback;
|
||||||
|
|
||||||
GLFWthreadmodel threading;
|
|
||||||
GLFWallocator allocator;
|
|
||||||
|
|
||||||
GLFWgammaramp currentRamp;
|
GLFWgammaramp currentRamp;
|
||||||
GLFWgammaramp originalRamp;
|
GLFWgammaramp originalRamp;
|
||||||
int originalRampSize;
|
int originalRampSize;
|
||||||
|
@ -277,7 +274,7 @@ int _glfwPlatformInit(void);
|
||||||
int _glfwPlatformTerminate(void);
|
int _glfwPlatformTerminate(void);
|
||||||
const char* _glfwPlatformGetVersionString(void);
|
const char* _glfwPlatformGetVersionString(void);
|
||||||
|
|
||||||
// Enable/Disable
|
// Input
|
||||||
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window);
|
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window);
|
||||||
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window);
|
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window);
|
||||||
|
|
||||||
|
@ -327,10 +324,6 @@ void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long
|
||||||
// Prototypes for platform independent internal functions
|
// Prototypes for platform independent internal functions
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
// Memory management (init.c)
|
|
||||||
void* _glfwMalloc(size_t size);
|
|
||||||
void _glfwFree(void* ptr);
|
|
||||||
|
|
||||||
// Fullscren management (fullscreen.c)
|
// Fullscren management (fullscreen.c)
|
||||||
void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
|
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)
|
// Window management (window.c)
|
||||||
void _glfwSetDefaultWindowHints(void);
|
void _glfwSetDefaultWindowHints(void);
|
||||||
|
|
||||||
// WIndow event notification
|
// Window event notification (window.c)
|
||||||
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated);
|
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated);
|
||||||
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y);
|
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y);
|
||||||
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
|
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
|
||||||
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified);
|
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified);
|
||||||
void _glfwInputWindowDamage(_GLFWwindow* window);
|
void _glfwInputWindowDamage(_GLFWwindow* window);
|
||||||
|
|
||||||
// Input event notification
|
// Input event notification (input.c)
|
||||||
void _glfwInputKey(_GLFWwindow* window, int key, int action);
|
void _glfwInputKey(_GLFWwindow* window, int key, int action);
|
||||||
void _glfwInputChar(_GLFWwindow* window, int character);
|
void _glfwInputChar(_GLFWwindow* window, int character);
|
||||||
void _glfwInputScroll(_GLFWwindow* window, int x, int y);
|
void _glfwInputScroll(_GLFWwindow* window, int x, int y);
|
||||||
|
|
|
@ -47,7 +47,7 @@ static GLboolean initLibraries(void)
|
||||||
#ifndef _GLFW_NO_DLOAD_GDI32
|
#ifndef _GLFW_NO_DLOAD_GDI32
|
||||||
// gdi32.dll (OpenGL pixel format functions & SwapBuffers)
|
// 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)
|
if (!_glfwLibrary.Win32.gdi.instance)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
|
@ -81,12 +81,12 @@ static GLboolean initLibraries(void)
|
||||||
#ifndef _GLFW_NO_DLOAD_WINMM
|
#ifndef _GLFW_NO_DLOAD_WINMM
|
||||||
// winmm.dll (for joystick and timer support)
|
// 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)
|
if (!_glfwLibrary.Win32.winmm.instance)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
_glfwLibrary.Win32.winmm.joyGetDevCapsA = (JOYGETDEVCAPSA_T)
|
_glfwLibrary.Win32.winmm.joyGetDevCaps = (JOYGETDEVCAPS_T)
|
||||||
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetDevCapsA");
|
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetDevCapsW");
|
||||||
_glfwLibrary.Win32.winmm.joyGetPos = (JOYGETPOS_T)
|
_glfwLibrary.Win32.winmm.joyGetPos = (JOYGETPOS_T)
|
||||||
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetPos");
|
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetPos");
|
||||||
_glfwLibrary.Win32.winmm.joyGetPosEx = (JOYGETPOSEX_T)
|
_glfwLibrary.Win32.winmm.joyGetPosEx = (JOYGETPOSEX_T)
|
||||||
|
@ -94,7 +94,7 @@ static GLboolean initLibraries(void)
|
||||||
_glfwLibrary.Win32.winmm.timeGetTime = (TIMEGETTIME_T)
|
_glfwLibrary.Win32.winmm.timeGetTime = (TIMEGETTIME_T)
|
||||||
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "timeGetTime");
|
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "timeGetTime");
|
||||||
|
|
||||||
if (!_glfwLibrary.Win32.winmm.joyGetDevCapsA ||
|
if (!_glfwLibrary.Win32.winmm.joyGetDevCaps ||
|
||||||
!_glfwLibrary.Win32.winmm.joyGetPos ||
|
!_glfwLibrary.Win32.winmm.joyGetPos ||
|
||||||
!_glfwLibrary.Win32.winmm.joyGetPosEx ||
|
!_glfwLibrary.Win32.winmm.joyGetPosEx ||
|
||||||
!_glfwLibrary.Win32.winmm.timeGetTime)
|
!_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 //////
|
////// GLFW platform API //////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -45,6 +45,14 @@
|
||||||
// thinks it is the only one that gets to do so
|
// thinks it is the only one that gets to do so
|
||||||
#undef APIENTRY
|
#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 <windows.h>
|
||||||
#include <mmsystem.h>
|
#include <mmsystem.h>
|
||||||
|
|
||||||
|
@ -162,7 +170,7 @@ typedef BOOL (WINAPI * SETDEVICEGAMMARAMP_T) (HDC,PVOID);
|
||||||
|
|
||||||
// winmm.dll function pointer typedefs
|
// winmm.dll function pointer typedefs
|
||||||
#ifndef _GLFW_NO_DLOAD_WINMM
|
#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 * JOYGETPOS_T) (UINT,LPJOYINFO);
|
||||||
typedef MMRESULT (WINAPI * JOYGETPOSEX_T) (UINT,LPJOYINFOEX);
|
typedef MMRESULT (WINAPI * JOYGETPOSEX_T) (UINT,LPJOYINFOEX);
|
||||||
typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
|
typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
|
||||||
|
@ -190,12 +198,12 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
|
||||||
|
|
||||||
// winmm.dll shortcuts
|
// winmm.dll shortcuts
|
||||||
#ifndef _GLFW_NO_DLOAD_WINMM
|
#ifndef _GLFW_NO_DLOAD_WINMM
|
||||||
#define _glfw_joyGetDevCaps _glfwLibrary.Win32.winmm.joyGetDevCapsA
|
#define _glfw_joyGetDevCaps _glfwLibrary.Win32.winmm.joyGetDevCaps
|
||||||
#define _glfw_joyGetPos _glfwLibrary.Win32.winmm.joyGetPos
|
#define _glfw_joyGetPos _glfwLibrary.Win32.winmm.joyGetPos
|
||||||
#define _glfw_joyGetPosEx _glfwLibrary.Win32.winmm.joyGetPosEx
|
#define _glfw_joyGetPosEx _glfwLibrary.Win32.winmm.joyGetPosEx
|
||||||
#define _glfw_timeGetTime _glfwLibrary.Win32.winmm.timeGetTime
|
#define _glfw_timeGetTime _glfwLibrary.Win32.winmm.timeGetTime
|
||||||
#else
|
#else
|
||||||
#define _glfw_joyGetDevCaps joyGetDevCapsA
|
#define _glfw_joyGetDevCaps joyGetDevCaps
|
||||||
#define _glfw_joyGetPos joyGetPos
|
#define _glfw_joyGetPos joyGetPos
|
||||||
#define _glfw_joyGetPosEx joyGetPosEx
|
#define _glfw_joyGetPosEx joyGetPosEx
|
||||||
#define _glfw_timeGetTime timeGetTime
|
#define _glfw_timeGetTime timeGetTime
|
||||||
|
@ -204,7 +212,7 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
|
||||||
|
|
||||||
// We use versioned window class names in order not to cause conflicts
|
// We use versioned window class names in order not to cause conflicts
|
||||||
// between applications using different versions of GLFW
|
// between applications using different versions of GLFW
|
||||||
#define _GLFW_WNDCLASSNAME "GLFW30"
|
#define _GLFW_WNDCLASSNAME L"GLFW30"
|
||||||
|
|
||||||
|
|
||||||
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32
|
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32
|
||||||
|
@ -260,6 +268,7 @@ typedef struct _GLFWwindowWin32
|
||||||
// Various platform specific internal variables
|
// Various platform specific internal variables
|
||||||
int desiredRefreshRate; // Desired vertical monitor refresh rate
|
int desiredRefreshRate; // Desired vertical monitor refresh rate
|
||||||
GLboolean cursorCentered;
|
GLboolean cursorCentered;
|
||||||
|
GLboolean cursorInside;
|
||||||
int oldMouseX, oldMouseY;
|
int oldMouseX, oldMouseY;
|
||||||
} _GLFWwindowWin32;
|
} _GLFWwindowWin32;
|
||||||
|
|
||||||
|
@ -309,7 +318,7 @@ typedef struct _GLFWlibraryWin32
|
||||||
// winmm.dll
|
// winmm.dll
|
||||||
struct {
|
struct {
|
||||||
HINSTANCE instance;
|
HINSTANCE instance;
|
||||||
JOYGETDEVCAPSA_T joyGetDevCapsA;
|
JOYGETDEVCAPS_T joyGetDevCaps;
|
||||||
JOYGETPOS_T joyGetPos;
|
JOYGETPOS_T joyGetPos;
|
||||||
JOYGETPOSEX_T joyGetPosEx;
|
JOYGETPOSEX_T joyGetPosEx;
|
||||||
TIMEGETTIME_T timeGetTime;
|
TIMEGETTIME_T timeGetTime;
|
||||||
|
@ -323,6 +332,10 @@ typedef struct _GLFWlibraryWin32
|
||||||
// Prototypes for platform specific internal functions
|
// Prototypes for platform specific internal functions
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
|
// Wide strings
|
||||||
|
WCHAR* _glfwCreateWideStringFromUTF8(const char* source);
|
||||||
|
char* _glfwCreateUTF8FromWideString(const WCHAR* source);
|
||||||
|
|
||||||
// Time
|
// Time
|
||||||
void _glfwInitTimer(void);
|
void _glfwInitTimer(void);
|
||||||
|
|
||||||
|
|
|
@ -195,7 +195,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = (_GLFWfbconfig*) _glfwMalloc(sizeof(_GLFWfbconfig) * count);
|
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
||||||
|
@ -895,7 +895,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||||
if (_glfwLibrary.charCallback)
|
if (_glfwLibrary.charCallback)
|
||||||
translateChar(window, (DWORD) wParam, (DWORD) lParam);
|
translateChar(window, (DWORD) wParam, (DWORD) lParam);
|
||||||
|
|
||||||
return 0;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WM_KEYUP:
|
case WM_KEYUP:
|
||||||
|
@ -910,7 +910,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||||
else
|
else
|
||||||
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_RELEASE);
|
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_RELEASE);
|
||||||
|
|
||||||
return 0;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
||||||
|
@ -1021,6 +1021,26 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||||
_glfwInputCursorMotion(window, x, y);
|
_glfwInputCursorMotion(window, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!window->Win32.cursorInside)
|
||||||
|
{
|
||||||
|
TRACKMOUSEEVENT tme;
|
||||||
|
ZeroMemory(&tme, sizeof(tme));
|
||||||
|
tme.cbSize = sizeof(tme);
|
||||||
|
tme.dwFlags = TME_LEAVE;
|
||||||
|
tme.hwndTrack = window->Win32.handle;
|
||||||
|
TrackMouseEvent(&tme);
|
||||||
|
|
||||||
|
window->Win32.cursorInside = GL_TRUE;
|
||||||
|
_glfwInputCursorEnter(window, GL_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case WM_MOUSELEAVE:
|
||||||
|
{
|
||||||
|
window->Win32.cursorInside = GL_FALSE;
|
||||||
|
_glfwInputCursorEnter(window, GL_FALSE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1220,7 +1240,7 @@ static ATOM registerWindowClass(void)
|
||||||
wc.lpszClassName = _GLFW_WNDCLASSNAME; // Set class name
|
wc.lpszClassName = _GLFW_WNDCLASSNAME; // Set class name
|
||||||
|
|
||||||
// Load user-provided icon if available
|
// 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)
|
if (!wc.hIcon)
|
||||||
{
|
{
|
||||||
// Load default icon
|
// Load default icon
|
||||||
|
@ -1257,13 +1277,13 @@ static int choosePixelFormat(_GLFWwindow* window, const _GLFWfbconfig* fbconfig)
|
||||||
closest = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
|
closest = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
|
||||||
if (!closest)
|
if (!closest)
|
||||||
{
|
{
|
||||||
_glfwFree(fbconfigs);
|
free(fbconfigs);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pixelFormat = (int) closest->platformID;
|
pixelFormat = (int) closest->platformID;
|
||||||
|
|
||||||
_glfwFree(fbconfigs);
|
free(fbconfigs);
|
||||||
fbconfigs = NULL;
|
fbconfigs = NULL;
|
||||||
closest = NULL;
|
closest = NULL;
|
||||||
|
|
||||||
|
@ -1283,6 +1303,7 @@ static int createWindow(_GLFWwindow* window,
|
||||||
int pixelFormat, fullWidth, fullHeight;
|
int pixelFormat, fullWidth, fullHeight;
|
||||||
RECT wa;
|
RECT wa;
|
||||||
POINT pos;
|
POINT pos;
|
||||||
|
WCHAR* wideTitle;
|
||||||
|
|
||||||
// Set common window styles
|
// Set common window styles
|
||||||
dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
|
dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
|
||||||
|
@ -1331,9 +1352,17 @@ static int createWindow(_GLFWwindow* window,
|
||||||
else
|
else
|
||||||
SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0);
|
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,
|
window->Win32.handle = CreateWindowEx(window->Win32.dwExStyle,
|
||||||
_GLFW_WNDCLASSNAME,
|
_GLFW_WNDCLASSNAME,
|
||||||
wndconfig->title,
|
wideTitle,
|
||||||
window->Win32.dwStyle,
|
window->Win32.dwStyle,
|
||||||
wa.left, wa.top, // Window position
|
wa.left, wa.top, // Window position
|
||||||
fullWidth, // Decorated window width
|
fullWidth, // Decorated window width
|
||||||
|
@ -1349,6 +1378,8 @@ static int createWindow(_GLFWwindow* window,
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(wideTitle);
|
||||||
|
|
||||||
window->WGL.DC = GetDC(window->Win32.handle);
|
window->WGL.DC = GetDC(window->Win32.handle);
|
||||||
if (!window->WGL.DC)
|
if (!window->WGL.DC)
|
||||||
{
|
{
|
||||||
|
@ -1430,6 +1461,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||||
GLboolean recreateContext = GL_FALSE;
|
GLboolean recreateContext = GL_FALSE;
|
||||||
|
|
||||||
window->Win32.desiredRefreshRate = wndconfig->refreshRate;
|
window->Win32.desiredRefreshRate = wndconfig->refreshRate;
|
||||||
|
window->resizable = wndconfig->resizable;
|
||||||
|
|
||||||
if (!_glfwLibrary.Win32.classAtom)
|
if (!_glfwLibrary.Win32.classAtom)
|
||||||
{
|
{
|
||||||
|
@ -1568,7 +1600,17 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
|
||||||
|
|
||||||
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -291,7 +291,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
||||||
height = 480;
|
height = 480;
|
||||||
}
|
}
|
||||||
|
|
||||||
window = (_GLFWwindow*) _glfwMalloc(sizeof(_GLFWwindow));
|
window = (_GLFWwindow*) malloc(sizeof(_GLFWwindow));
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
||||||
|
@ -309,6 +309,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
||||||
window->height = height;
|
window->height = height;
|
||||||
window->mode = mode;
|
window->mode = mode;
|
||||||
window->cursorMode = GLFW_CURSOR_NORMAL;
|
window->cursorMode = GLFW_CURSOR_NORMAL;
|
||||||
|
window->systemKeys = GL_TRUE;
|
||||||
|
|
||||||
// Open the actual window and create its context
|
// Open the actual window and create its context
|
||||||
if (!_glfwPlatformOpenWindow(window, &wndconfig, &fbconfig))
|
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
|
// The GLFW specification states that fullscreen windows have the cursor
|
||||||
// captured by default
|
// captured by default
|
||||||
if (mode == GLFW_FULLSCREEN)
|
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
|
// Clearing the front buffer to black to avoid garbage pixels left over
|
||||||
// from previous uses of our bit of VRAM
|
// from previous uses of our bit of VRAM
|
||||||
|
@ -491,7 +492,7 @@ GLFWAPI void glfwCloseWindow(GLFWwindow handle)
|
||||||
*prev = window->next;
|
*prev = window->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
_glfwFree(window);
|
free(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -654,7 +655,6 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow handle)
|
||||||
if (!window->iconified)
|
if (!window->iconified)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Restore iconified window
|
|
||||||
_glfwPlatformRestoreWindow(window);
|
_glfwPlatformRestoreWindow(window);
|
||||||
|
|
||||||
if (window->mode == GLFW_FULLSCREEN)
|
if (window->mode == GLFW_FULLSCREEN)
|
||||||
|
|
|
@ -339,7 +339,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
rgbarray = (int*) _glfwMalloc(sizeof(int) * viscount);
|
rgbarray = (int*) malloc(sizeof(int) * viscount);
|
||||||
rgbcount = 0;
|
rgbcount = 0;
|
||||||
|
|
||||||
// Build RGB array
|
// Build RGB array
|
||||||
|
@ -372,6 +372,8 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XFree(vislist);
|
||||||
|
|
||||||
rescount = 0;
|
rescount = 0;
|
||||||
resarray = NULL;
|
resarray = NULL;
|
||||||
|
|
||||||
|
@ -387,7 +389,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||||
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root);
|
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root);
|
||||||
sizelist = XRRConfigSizes(sc, &sizecount);
|
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++)
|
for (k = 0; k < sizecount; k++)
|
||||||
{
|
{
|
||||||
|
@ -407,7 +409,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||||
|
|
||||||
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, &modecount, &modelist);
|
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++)
|
for (k = 0; k < modecount; k++)
|
||||||
{
|
{
|
||||||
|
@ -436,7 +438,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||||
if (!resarray)
|
if (!resarray)
|
||||||
{
|
{
|
||||||
rescount = 1;
|
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].width = DisplayWidth(_glfwLibrary.X11.display, screen);
|
||||||
resarray[0].height = DisplayHeight(_glfwLibrary.X11.display, screen);
|
resarray[0].height = DisplayHeight(_glfwLibrary.X11.display, screen);
|
||||||
|
@ -457,10 +459,8 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XFree(vislist);
|
free(resarray);
|
||||||
|
free(rgbarray);
|
||||||
_glfwFree(resarray);
|
|
||||||
_glfwFree(rgbarray);
|
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,11 @@ static int keyCodeToGLFWKeyCode(int keyCode)
|
||||||
// Note: This way we always force "NumLock = ON", which is intentional
|
// Note: This way we always force "NumLock = ON", which is intentional
|
||||||
// since the returned key code should correspond to a physical
|
// since the returned key code should correspond to a physical
|
||||||
// location.
|
// location.
|
||||||
|
#if defined(_GLFW_HAS_XKB)
|
||||||
|
keySym = XkbKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 1, 0);
|
||||||
|
#else
|
||||||
keySym = XKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 1);
|
keySym = XKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 1);
|
||||||
|
#endif
|
||||||
switch (keySym)
|
switch (keySym)
|
||||||
{
|
{
|
||||||
case XK_KP_0: return GLFW_KEY_KP_0;
|
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
|
// Now try pimary keysym for function keys (non-printable keys). These
|
||||||
// should not be layout dependent (i.e. US layout and international
|
// should not be layout dependent (i.e. US layout and international
|
||||||
// layouts should give the same result).
|
// 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);
|
keySym = XKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
switch (keySym)
|
switch (keySym)
|
||||||
{
|
{
|
||||||
case XK_Escape: return GLFW_KEY_ESCAPE;
|
case XK_Escape: return GLFW_KEY_ESCAPE;
|
||||||
|
|
|
@ -31,8 +31,7 @@
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
|
|
||||||
void (*glXGetProcAddress(const GLubyte* procName))();
|
// This is the only glXGetProcAddress variant not declared by glxext.h
|
||||||
void (*glXGetProcAddressARB(const GLubyte* procName))();
|
|
||||||
void (*glXGetProcAddressEXT(const GLubyte* procName))();
|
void (*glXGetProcAddressEXT(const GLubyte* procName))();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -46,13 +46,6 @@
|
||||||
// extensions and not all operating systems come with an up-to-date version
|
// extensions and not all operating systems come with an up-to-date version
|
||||||
#include "../support/GL/glxext.h"
|
#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
|
// With XFree86, we can use the XF86VidMode extension
|
||||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||||
#include <X11/extensions/xf86vmode.h>
|
#include <X11/extensions/xf86vmode.h>
|
||||||
|
@ -141,6 +134,8 @@ typedef struct _GLFWwindowX11
|
||||||
Colormap colormap; // Window colormap
|
Colormap colormap; // Window colormap
|
||||||
Window handle; // Window handle
|
Window handle; // Window handle
|
||||||
Atom wmDeleteWindow; // WM_DELETE_WINDOW atom
|
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 wmPing; // _NET_WM_PING atom
|
||||||
Atom wmState; // _NET_WM_STATE atom
|
Atom wmState; // _NET_WM_STATE atom
|
||||||
Atom wmStateFullscreen; // _NET_WM_STATE_FULLSCREEN atom
|
Atom wmStateFullscreen; // _NET_WM_STATE_FULLSCREEN atom
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
static uint64_t getRawTime(void)
|
static uint64_t getRawTime(void)
|
||||||
{
|
{
|
||||||
#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
|
#if defined(CLOCK_MONOTONIC)
|
||||||
if (_glfwLibrary.X11.timer.monotonic)
|
if (_glfwLibrary.X11.timer.monotonic)
|
||||||
{
|
{
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
|
@ -64,7 +64,7 @@ static uint64_t getRawTime(void)
|
||||||
|
|
||||||
void _glfwInitTimer(void)
|
void _glfwInitTimer(void)
|
||||||
{
|
{
|
||||||
#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
|
#if defined(CLOCK_MONOTONIC)
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
|
|
||||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
|
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
|
||||||
|
|
|
@ -195,6 +195,12 @@ static GLboolean hasEWMH(_GLFWwindow* window)
|
||||||
window->X11.wmStateFullscreen =
|
window->X11.wmStateFullscreen =
|
||||||
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_FULLSCREEN");
|
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 =
|
window->X11.wmPing =
|
||||||
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_PING");
|
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)
|
if (!result)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
||||||
|
@ -1444,12 +1450,12 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||||
result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
|
result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_glfwFree(fbconfigs);
|
free(fbconfigs);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
closest = *result;
|
closest = *result;
|
||||||
_glfwFree(fbconfigs);
|
free(fbconfigs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!createContext(window, wndconfig, (GLXFBConfigID) closest.platformID))
|
if (!createContext(window, wndconfig, (GLXFBConfigID) closest.platformID))
|
||||||
|
@ -1544,9 +1550,39 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
|
||||||
|
|
||||||
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
||||||
{
|
{
|
||||||
// Set window & icon title
|
Atom type = XInternAtom(_glfwLibrary.X11.display, "UTF8_STRING", False);
|
||||||
XStoreName(_glfwLibrary.X11.display, window->X11.handle, title);
|
|
||||||
XSetIconName(_glfwLibrary.X11.display, window->X11.handle, title);
|
#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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,9 @@ target_link_libraries(joysticks ${STATIC_DEPS})
|
||||||
add_executable(listmodes listmodes.c)
|
add_executable(listmodes listmodes.c)
|
||||||
target_link_libraries(listmodes ${STATIC_DEPS})
|
target_link_libraries(listmodes ${STATIC_DEPS})
|
||||||
|
|
||||||
|
add_executable(modes modes.c getopt.c)
|
||||||
|
target_link_libraries(modes ${STATIC_DEPS})
|
||||||
|
|
||||||
add_executable(peter peter.c)
|
add_executable(peter peter.c)
|
||||||
target_link_libraries(peter ${STATIC_DEPS})
|
target_link_libraries(peter ${STATIC_DEPS})
|
||||||
|
|
||||||
|
@ -44,23 +47,37 @@ target_link_libraries(reopen ${STATIC_DEPS})
|
||||||
|
|
||||||
add_executable(accuracy WIN32 MACOSX_BUNDLE accuracy.c)
|
add_executable(accuracy WIN32 MACOSX_BUNDLE accuracy.c)
|
||||||
target_link_libraries(accuracy ${STATIC_DEPS})
|
target_link_libraries(accuracy ${STATIC_DEPS})
|
||||||
|
set_target_properties(accuracy PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Accuracy")
|
||||||
|
|
||||||
add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c)
|
add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c)
|
||||||
target_link_libraries(sharing ${STATIC_DEPS})
|
target_link_libraries(sharing ${STATIC_DEPS})
|
||||||
|
set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing")
|
||||||
|
|
||||||
add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c)
|
add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c)
|
||||||
target_link_libraries(tearing ${STATIC_DEPS})
|
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)
|
add_executable(windows WIN32 MACOSX_BUNDLE windows.c)
|
||||||
target_link_libraries(windows ${STATIC_DEPS})
|
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
|
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
|
# Tell MSVC to use main instead of WinMain for Windows subsystem executables
|
||||||
set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES
|
set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES
|
||||||
LINK_FLAGS "/ENTRY:mainCRTStartup")
|
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()
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,9 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
|
||||||
static GLboolean keyrepeat = 0;
|
static GLboolean keyrepeat = GL_FALSE;
|
||||||
static GLboolean systemkeys = 1;
|
static GLboolean systemkeys = GL_TRUE;
|
||||||
|
static GLboolean closeable = GL_TRUE;
|
||||||
static unsigned int counter = 0;
|
static unsigned int counter = 0;
|
||||||
|
|
||||||
static const char* get_key_name(int key)
|
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)
|
static int window_close_callback(GLFWwindow window)
|
||||||
{
|
{
|
||||||
printf("%08x at %0.3f: Window close\n", counter++, glfwGetTime());
|
printf("%08x at %0.3f: Window close\n", counter++, glfwGetTime());
|
||||||
return 1;
|
return closeable;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_refresh_callback(GLFWwindow window)
|
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:
|
case GLFW_KEY_R:
|
||||||
{
|
{
|
||||||
keyrepeat = !keyrepeat;
|
keyrepeat = !keyrepeat;
|
||||||
if (keyrepeat)
|
glfwSetInputMode(window, GLFW_KEY_REPEAT, keyrepeat);
|
||||||
glfwEnable(window, GLFW_KEY_REPEAT);
|
|
||||||
else
|
|
||||||
glfwDisable(window, GLFW_KEY_REPEAT);
|
|
||||||
|
|
||||||
printf("(( key repeat %s ))\n", keyrepeat ? "enabled" : "disabled");
|
printf("(( key repeat %s ))\n", keyrepeat ? "enabled" : "disabled");
|
||||||
break;
|
break;
|
||||||
|
@ -318,14 +316,19 @@ static void key_callback(GLFWwindow window, int key, int action)
|
||||||
case GLFW_KEY_S:
|
case GLFW_KEY_S:
|
||||||
{
|
{
|
||||||
systemkeys = !systemkeys;
|
systemkeys = !systemkeys;
|
||||||
if (systemkeys)
|
glfwSetInputMode(window, GLFW_SYSTEM_KEYS, systemkeys);
|
||||||
glfwEnable(window, GLFW_SYSTEM_KEYS);
|
|
||||||
else
|
|
||||||
glfwDisable(window, GLFW_SYSTEM_KEYS);
|
|
||||||
|
|
||||||
printf("(( system keys %s ))\n", systemkeys ? "enabled" : "disabled");
|
printf("(( system keys %s ))\n", systemkeys ? "enabled" : "disabled");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case GLFW_KEY_C:
|
||||||
|
{
|
||||||
|
closeable = !closeable;
|
||||||
|
|
||||||
|
printf("(( closing %s ))\n", closeable ? "enabled" : "disabled");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
|
||||||
|
|
||||||
glfwSetWindowFocusCallback(window_focus_callback);
|
glfwSetWindowFocusCallback(window_focus_callback);
|
||||||
glfwSetKeyCallback(window_key_callback);
|
glfwSetKeyCallback(window_key_callback);
|
||||||
|
|
|
@ -35,11 +35,20 @@
|
||||||
|
|
||||||
#include "getopt.h"
|
#include "getopt.h"
|
||||||
|
|
||||||
|
#define STEP_SIZE 0.1f
|
||||||
|
|
||||||
static GLfloat gamma = 1.0f;
|
static GLfloat gamma = 1.0f;
|
||||||
|
|
||||||
static void usage(void)
|
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)
|
static void key_callback(GLFWwindow window, int key, int action)
|
||||||
|
@ -50,22 +59,28 @@ static void key_callback(GLFWwindow window, int key, int action)
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case GLFW_KEY_ESCAPE:
|
case GLFW_KEY_ESCAPE:
|
||||||
|
{
|
||||||
glfwCloseWindow(window);
|
glfwCloseWindow(window);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case GLFW_KEY_KP_ADD:
|
case GLFW_KEY_KP_ADD:
|
||||||
case GLFW_KEY_Q:
|
case GLFW_KEY_Q:
|
||||||
gamma += 0.1f;
|
{
|
||||||
printf("Gamma: %f\n", gamma);
|
set_gamma(gamma + STEP_SIZE);
|
||||||
glfwSetGamma(gamma);
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case GLFW_KEY_KP_SUBTRACT:
|
case GLFW_KEY_KP_SUBTRACT:
|
||||||
case GLFW_KEY_W:
|
case GLFW_KEY_W:
|
||||||
gamma -= 0.1f;
|
{
|
||||||
printf("Gamma: %f\n", gamma);
|
if (gamma - STEP_SIZE > 0.f)
|
||||||
glfwSetGamma(gamma);
|
set_gamma(gamma - STEP_SIZE);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void size_callback(GLFWwindow window, int width, int height)
|
static void size_callback(GLFWwindow window, int width, int height)
|
||||||
{
|
{
|
||||||
|
@ -124,7 +139,7 @@ int main(int argc, char** argv)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Gamma: %f\n", gamma);
|
set_gamma(1.f);
|
||||||
|
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
|
|
||||||
static void usage(void)
|
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 profiles: " PROFILE_NAME_CORE " " PROFILE_NAME_COMPAT " " PROFILE_NAME_ES2 "\n");
|
||||||
printf("available strategies: " STRATEGY_NAME_NONE " " STRATEGY_NAME_LOSE "\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))
|
if (major > 3 || (major == 3 && minor >= 2))
|
||||||
{
|
{
|
||||||
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
|
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",
|
printf("OpenGL profile parsed by GLFW: %s\n",
|
||||||
get_glfw_profile_name(glfwGetWindowParam(window, GLFW_OPENGL_PROFILE)));
|
get_glfw_profile_name(glfwGetWindowParam(window, GLFW_OPENGL_PROFILE)));
|
||||||
|
|
|
@ -62,6 +62,8 @@ static void key_callback(GLFWwindow window, int key, int action)
|
||||||
|
|
||||||
static void size_callback(GLFWwindow window, int width, int height)
|
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);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
225
tests/modes.c
Normal file
225
tests/modes.c
Normal 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);
|
||||||
|
}
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static GLboolean cursor_captured = GL_FALSE;
|
|
||||||
static GLFWwindow window_handle = NULL;
|
static GLFWwindow window_handle = NULL;
|
||||||
static int cursor_x;
|
static int cursor_x;
|
||||||
static int cursor_y;
|
static int cursor_y;
|
||||||
|
@ -44,18 +43,16 @@ static GLboolean open_window(void);
|
||||||
|
|
||||||
static void toggle_mouse_cursor(GLFWwindow window)
|
static void toggle_mouse_cursor(GLFWwindow window)
|
||||||
{
|
{
|
||||||
if (cursor_captured)
|
if (glfwGetInputMode(window, GLFW_CURSOR_MODE) == GLFW_CURSOR_CAPTURED)
|
||||||
{
|
{
|
||||||
printf("Released cursor\n");
|
printf("Released cursor\n");
|
||||||
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Captured cursor\n");
|
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)
|
static void mouse_position_callback(GLFWwindow window, int x, int y)
|
||||||
|
|
|
@ -92,8 +92,6 @@ static void draw_quad(GLuint texture)
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||||
|
|
||||||
glColor3f(0.6f, 0.f, 0.6f);
|
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
glTexCoord2f(0.f, 0.f);
|
glTexCoord2f(0.f, 0.f);
|
||||||
|
@ -142,6 +140,11 @@ int main(int argc, char** argv)
|
||||||
exit(EXIT_FAILURE);
|
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
|
// Put the second window to the right of the first one
|
||||||
glfwGetWindowPos(windows[0], &x, &y);
|
glfwGetWindowPos(windows[0], &x, &y);
|
||||||
glfwSetWindowPos(windows[1], x + WIDTH + 50, y);
|
glfwSetWindowPos(windows[1], x + WIDTH + 50, y);
|
||||||
|
|
|
@ -34,11 +34,30 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.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)
|
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||||
{
|
{
|
||||||
glViewport(0, 0, width, 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)
|
int main(void)
|
||||||
{
|
{
|
||||||
float position;
|
float position;
|
||||||
|
@ -50,7 +69,7 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Tearing Detector", NULL);
|
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -59,8 +78,10 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_swap_interval(1);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSwapInterval(1);
|
glfwSetKeyCallback(key_callback);
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
|
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
|
||||||
|
|
70
tests/title.c
Normal file
70
tests/title.c
Normal 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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user