├── examples ├── glfw.ico ├── glfw.icns ├── glfw.rc ├── CMakeLists.txt └── simple.c ├── src ├── glfw3Config.cmake.in ├── glfw3.pc.in ├── xkb_unicode.h ├── posix_time.h ├── posix_tls.h ├── cocoa_joystick.h ├── cocoa_time.c ├── nsgl_context.h ├── linux_joystick.h ├── win32_joystick.h ├── posix_tls.c ├── win32_tls.c ├── win32_time.c ├── posix_time.c ├── glfw_config.h.in ├── mir_platform.h ├── cocoa_platform.h ├── CMakeLists.txt ├── init.c ├── mir_monitor.c ├── wl_platform.h └── wgl_context.h ├── docs ├── footer.html ├── CMakeLists.txt ├── header.html ├── main.dox ├── internal.dox ├── extra.css ├── DoxygenLayout.xml ├── monitor.dox └── vulkan.dox ├── CMake ├── modules │ ├── FindMir.cmake │ ├── FindWaylandProtocols.cmake │ ├── FindXKBCommon.cmake │ └── FindVulkan.cmake ├── i586-mingw32msvc.cmake ├── amd64-mingw32msvc.cmake ├── i686-w64-mingw32.cmake ├── i686-pc-mingw32.cmake ├── x86_64-w64-mingw32.cmake └── MacOSXBundleInfo.plist.in ├── .appveyor.yml ├── .travis.yml ├── COPYING.txt ├── cmake_uninstall.cmake.in ├── .gitignore ├── deps ├── getopt.h ├── mingw │ └── _mingw_dxhelper.h └── vulkan │ └── vk_platform.h └── tests ├── title.c ├── timeout.c ├── CMakeLists.txt ├── empty.c ├── threads.c ├── icon.c ├── clipboard.c ├── windows.c ├── msaa.c ├── gamma.c ├── sharing.c ├── reopen.c ├── tearing.c ├── joysticks.c └── monitors.c /examples/glfw.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyecp/glfw/master/examples/glfw.ico -------------------------------------------------------------------------------- /examples/glfw.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyecp/glfw/master/examples/glfw.icns -------------------------------------------------------------------------------- /examples/glfw.rc: -------------------------------------------------------------------------------- 1 | 2 | GLFW_ICON ICON "glfw.ico" 3 | 4 | -------------------------------------------------------------------------------- /src/glfw3Config.cmake.in: -------------------------------------------------------------------------------- 1 | include("${CMAKE_CURRENT_LIST_DIR}/glfw3Targets.cmake") 2 | -------------------------------------------------------------------------------- /docs/footer.html: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/glfw3.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | includedir=${prefix}/include 4 | libdir=${exec_prefix}/lib@LIB_SUFFIX@ 5 | 6 | Name: GLFW 7 | Description: A multi-platform library for OpenGL, window and input 8 | Version: @GLFW_VERSION_FULL@ 9 | URL: http://www.glfw.org/ 10 | Requires.private: @GLFW_PKG_DEPS@ 11 | Libs: -L${libdir} -l@GLFW_LIB_NAME@ 12 | Libs.private: @GLFW_PKG_LIBS@ 13 | Cflags: -I${includedir} 14 | -------------------------------------------------------------------------------- /CMake/modules/FindMir.cmake: -------------------------------------------------------------------------------- 1 | # Try to find Mir on a Unix system 2 | # 3 | # This will define: 4 | # 5 | # MIR_LIBRARIES - Link these to use Wayland 6 | # MIR_INCLUDE_DIR - Include directory for Wayland 7 | # 8 | # Copyright (c) 2014 Brandon Schaefer 9 | 10 | if (NOT WIN32) 11 | 12 | find_package (PkgConfig) 13 | pkg_check_modules (PKG_MIR QUIET mirclient) 14 | 15 | set (MIR_INCLUDE_DIR ${PKG_MIR_INCLUDE_DIRS}) 16 | set (MIR_LIBRARIES ${PKG_MIR_LIBRARIES}) 17 | 18 | endif () 19 | -------------------------------------------------------------------------------- /.appveyor.yml: -------------------------------------------------------------------------------- 1 | branches: 2 | only: 3 | - ci 4 | - master 5 | skip_tags: true 6 | environment: 7 | matrix: 8 | - BUILD_SHARED_LIBS: ON 9 | - BUILD_SHARED_LIBS: OFF 10 | matrix: 11 | fast_finish: true 12 | build_script: 13 | - mkdir build 14 | - cd build 15 | - cmake -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% .. 16 | - cmake --build . 17 | notifications: 18 | - provider: Email 19 | to: 20 | - ci@glfw.org 21 | - on_build_failure: true 22 | - on_build_success: false 23 | -------------------------------------------------------------------------------- /CMake/i586-mingw32msvc.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross compiling from Linux to Win32 2 | SET(CMAKE_SYSTEM_NAME Windows) 3 | SET(CMAKE_SYSTEM_VERSION 1) 4 | SET(CMAKE_C_COMPILER "i586-mingw32msvc-gcc") 5 | SET(CMAKE_CXX_COMPILER "i586-mingw32msvc-g++") 6 | SET(CMAKE_RC_COMPILER "i586-mingw32msvc-windres") 7 | SET(CMAKE_RANLIB "i586-mingw32msvc-ranlib") 8 | 9 | # Configure the behaviour of the find commands 10 | SET(CMAKE_FIND_ROOT_PATH "/usr/i586-mingw32msvc") 11 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 12 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 13 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 14 | -------------------------------------------------------------------------------- /CMake/amd64-mingw32msvc.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross compiling from Linux to Win64 2 | SET(CMAKE_SYSTEM_NAME Windows) 3 | SET(CMAKE_SYSTEM_VERSION 1) 4 | SET(CMAKE_C_COMPILER "amd64-mingw32msvc-gcc") 5 | SET(CMAKE_CXX_COMPILER "amd64-mingw32msvc-g++") 6 | SET(CMAKE_RC_COMPILER "amd64-mingw32msvc-windres") 7 | SET(CMAKE_RANLIB "amd64-mingw32msvc-ranlib") 8 | 9 | # Configure the behaviour of the find commands 10 | SET(CMAKE_FIND_ROOT_PATH "/usr/amd64-mingw32msvc") 11 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 12 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 13 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | compiler: clang 3 | branches: 4 | only: 5 | - ci 6 | - master 7 | os: 8 | - linux 9 | - osx 10 | sudo: false 11 | addons: 12 | apt: 13 | sources: 14 | - kubuntu-backports 15 | packages: 16 | - cmake 17 | env: 18 | - BUILD_SHARED_LIBS=ON 19 | - BUILD_SHARED_LIBS=OFF 20 | script: 21 | - mkdir build 22 | - cd build 23 | - cmake -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} .. 24 | - cmake --build . 25 | notifications: 26 | email: 27 | recipients: 28 | - ci@glfw.org 29 | on_success: never 30 | on_failure: always 31 | -------------------------------------------------------------------------------- /CMake/i686-w64-mingw32.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross compiling from Linux to Win32 2 | SET(CMAKE_SYSTEM_NAME Windows) # Target system name 3 | SET(CMAKE_SYSTEM_VERSION 1) 4 | SET(CMAKE_C_COMPILER "i686-w64-mingw32-gcc") 5 | SET(CMAKE_CXX_COMPILER "i686-w64-mingw32-g++") 6 | SET(CMAKE_RC_COMPILER "i686-w64-mingw32-windres") 7 | SET(CMAKE_RANLIB "i686-w64-mingw32-ranlib") 8 | 9 | # Configure the behaviour of the find commands 10 | SET(CMAKE_FIND_ROOT_PATH "/usr/i686-w64-mingw32") 11 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 12 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 13 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 14 | -------------------------------------------------------------------------------- /CMake/i686-pc-mingw32.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross compiling from Linux to Win32 2 | SET(CMAKE_SYSTEM_NAME Windows) # Target system name 3 | SET(CMAKE_SYSTEM_VERSION 1) 4 | SET(CMAKE_C_COMPILER "i686-pc-mingw32-gcc") 5 | SET(CMAKE_CXX_COMPILER "i686-pc-mingw32-g++") 6 | SET(CMAKE_RC_COMPILER "i686-pc-mingw32-windres") 7 | SET(CMAKE_RANLIB "i686-pc-mingw32-ranlib") 8 | 9 | #Configure the behaviour of the find commands 10 | SET(CMAKE_FIND_ROOT_PATH "/opt/mingw/usr/i686-pc-mingw32") 11 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 12 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 13 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 14 | -------------------------------------------------------------------------------- /CMake/x86_64-w64-mingw32.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross compiling from Linux to Win32 2 | SET(CMAKE_SYSTEM_NAME Windows) # Target system name 3 | SET(CMAKE_SYSTEM_VERSION 1) 4 | SET(CMAKE_C_COMPILER "x86_64-w64-mingw32-gcc") 5 | SET(CMAKE_CXX_COMPILER "x86_64-w64-mingw32-g++") 6 | SET(CMAKE_RC_COMPILER "x86_64-w64-mingw32-windres") 7 | SET(CMAKE_RANLIB "x86_64-w64-mingw32-ranlib") 8 | 9 | # Configure the behaviour of the find commands 10 | SET(CMAKE_FIND_ROOT_PATH "/usr/x86_64-w64-mingw32") 11 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 12 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 13 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 14 | -------------------------------------------------------------------------------- /COPYING.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2006 Marcus Geelnard 2 | Copyright (c) 2006-2016 Camilla Berglund 3 | 4 | This software is provided 'as-is', without any express or implied 5 | warranty. In no event will the authors be held liable for any damages 6 | arising from the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it 10 | freely, subject to the following restrictions: 11 | 12 | 1. The origin of this software must not be misrepresented; you must not 13 | claim that you wrote the original software. If you use this software 14 | in a product, an acknowledgment in the product documentation would 15 | be appreciated but is not required. 16 | 17 | 2. Altered source versions must be plainly marked as such, and must not 18 | be misrepresented as being the original software. 19 | 20 | 3. This notice may not be removed or altered from any source 21 | distribution. 22 | 23 | -------------------------------------------------------------------------------- /CMake/modules/FindWaylandProtocols.cmake: -------------------------------------------------------------------------------- 1 | find_package(PkgConfig) 2 | 3 | pkg_check_modules(WaylandProtocols QUIET wayland-protocols>=${WaylandProtocols_FIND_VERSION}) 4 | 5 | execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-protocols 6 | OUTPUT_VARIABLE WaylandProtocols_PKGDATADIR 7 | RESULT_VARIABLE _pkgconfig_failed) 8 | if (_pkgconfig_failed) 9 | message(FATAL_ERROR "Missing wayland-protocols pkgdatadir") 10 | endif() 11 | 12 | string(REGEX REPLACE "[\r\n]" "" WaylandProtocols_PKGDATADIR "${WaylandProtocols_PKGDATADIR}") 13 | 14 | find_package_handle_standard_args(WaylandProtocols 15 | FOUND_VAR 16 | WaylandProtocols_FOUND 17 | REQUIRED_VARS 18 | WaylandProtocols_PKGDATADIR 19 | VERSION_VAR 20 | WaylandProtocols_VERSION 21 | HANDLE_COMPONENTS 22 | ) 23 | 24 | set(WAYLAND_PROTOCOLS_FOUND ${WaylandProtocols_FOUND}) 25 | set(WAYLAND_PROTOCOLS_PKGDATADIR ${WaylandProtocols_PKGDATADIR}) 26 | set(WAYLAND_PROTOCOLS_VERSION ${WaylandProtocols_VERSION}) 27 | -------------------------------------------------------------------------------- /CMake/modules/FindXKBCommon.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find XKBCommon 2 | # Once done, this will define 3 | # 4 | # XKBCOMMON_FOUND - System has XKBCommon 5 | # XKBCOMMON_INCLUDE_DIRS - The XKBCommon include directories 6 | # XKBCOMMON_LIBRARIES - The libraries needed to use XKBCommon 7 | # XKBCOMMON_DEFINITIONS - Compiler switches required for using XKBCommon 8 | 9 | find_package(PkgConfig) 10 | pkg_check_modules(PC_XKBCOMMON QUIET xkbcommon) 11 | set(XKBCOMMON_DEFINITIONS ${PC_XKBCOMMON_CFLAGS_OTHER}) 12 | 13 | find_path(XKBCOMMON_INCLUDE_DIR 14 | NAMES xkbcommon/xkbcommon.h 15 | HINTS ${PC_XKBCOMMON_INCLUDE_DIR} ${PC_XKBCOMMON_INCLUDE_DIRS} 16 | ) 17 | 18 | find_library(XKBCOMMON_LIBRARY 19 | NAMES xkbcommon 20 | HINTS ${PC_XKBCOMMON_LIBRARY} ${PC_XKBCOMMON_LIBRARY_DIRS} 21 | ) 22 | 23 | set(XKBCOMMON_LIBRARIES ${XKBCOMMON_LIBRARY}) 24 | set(XKBCOMMON_LIBRARY_DIRS ${XKBCOMMON_LIBRARY_DIRS}) 25 | set(XKBCOMMON_INCLUDE_DIRS ${XKBCOMMON_INCLUDE_DIR}) 26 | 27 | include(FindPackageHandleStandardArgs) 28 | find_package_handle_standard_args(XKBCommon DEFAULT_MSG 29 | XKBCOMMON_LIBRARY 30 | XKBCOMMON_INCLUDE_DIR 31 | ) 32 | 33 | mark_as_advanced(XKBCOMMON_LIBRARY XKBCOMMON_INCLUDE_DIR) 34 | 35 | -------------------------------------------------------------------------------- /CMake/modules/FindVulkan.cmake: -------------------------------------------------------------------------------- 1 | # Find Vulkan 2 | # 3 | # VULKAN_INCLUDE_DIR 4 | # VULKAN_LIBRARY 5 | # VULKAN_FOUND 6 | 7 | if (WIN32) 8 | find_path(VULKAN_INCLUDE_DIR NAMES vulkan/vulkan.h HINTS 9 | "$ENV{VULKAN_SDK}/Include" 10 | "$ENV{VK_SDK_PATH}/Include") 11 | if (CMAKE_CL_64) 12 | find_library(VULKAN_LIBRARY NAMES vulkan-1 HINTS 13 | "$ENV{VULKAN_SDK}/Bin" 14 | "$ENV{VK_SDK_PATH}/Bin") 15 | find_library(VULKAN_STATIC_LIBRARY NAMES vkstatic.1 HINTS 16 | "$ENV{VULKAN_SDK}/Bin" 17 | "$ENV{VK_SDK_PATH}/Bin") 18 | else() 19 | find_library(VULKAN_LIBRARY NAMES vulkan-1 HINTS 20 | "$ENV{VULKAN_SDK}/Bin32" 21 | "$ENV{VK_SDK_PATH}/Bin32") 22 | endif() 23 | else() 24 | find_path(VULKAN_INCLUDE_DIR NAMES vulkan/vulkan.h HINTS 25 | "$ENV{VULKAN_SDK}/include") 26 | find_library(VULKAN_LIBRARY NAMES vulkan HINTS 27 | "$ENV{VULKAN_SDK}/lib") 28 | endif() 29 | 30 | include(FindPackageHandleStandardArgs) 31 | find_package_handle_standard_args(Vulkan DEFAULT_MSG VULKAN_LIBRARY VULKAN_INCLUDE_DIR) 32 | 33 | mark_as_advanced(VULKAN_INCLUDE_DIR VULKAN_LIBRARY VULKAN_STATIC_LIBRARY) 34 | 35 | -------------------------------------------------------------------------------- /docs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(glfw_DOCS_SOURCES 3 | "${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h" 4 | "${GLFW_SOURCE_DIR}/include/GLFW/glfw3native.h" 5 | "${GLFW_SOURCE_DIR}/docs/main.dox" 6 | "${GLFW_SOURCE_DIR}/docs/news.dox" 7 | "${GLFW_SOURCE_DIR}/docs/moving.dox" 8 | "${GLFW_SOURCE_DIR}/docs/quick.dox" 9 | "${GLFW_SOURCE_DIR}/docs/compile.dox" 10 | "${GLFW_SOURCE_DIR}/docs/build.dox" 11 | "${GLFW_SOURCE_DIR}/docs/intro.dox" 12 | "${GLFW_SOURCE_DIR}/docs/context.dox" 13 | "${GLFW_SOURCE_DIR}/docs/monitor.dox" 14 | "${GLFW_SOURCE_DIR}/docs/window.dox" 15 | "${GLFW_SOURCE_DIR}/docs/input.dox" 16 | "${GLFW_SOURCE_DIR}/docs/vulkan.dox" 17 | "${GLFW_SOURCE_DIR}/docs/compat.dox") 18 | 19 | if (GLFW_DOCUMENT_INTERNALS) 20 | list(APPEND glfw_DOCS_SOURCES "${GLFW_SOURCE_DIR}/src/internal.h") 21 | endif() 22 | 23 | foreach(arg ${glfw_DOCS_SOURCES}) 24 | set(GLFW_DOCS_SOURCES "${GLFW_DOCS_SOURCES} ${arg}") 25 | endforeach() 26 | 27 | configure_file(Doxyfile.in Doxyfile @ONLY) 28 | 29 | add_custom_target(docs ALL "${DOXYGEN_EXECUTABLE}" 30 | WORKING_DIRECTORY "${GLFW_BINARY_DIR}/docs" 31 | COMMENT "Generating HTML documentation" VERBATIM) 32 | 33 | -------------------------------------------------------------------------------- /cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | 2 | if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 3 | message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") 4 | endif() 5 | 6 | file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 7 | string(REGEX REPLACE "\n" ";" files "${files}") 8 | 9 | foreach (file ${files}) 10 | message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") 11 | if (EXISTS "$ENV{DESTDIR}${file}") 12 | exec_program("@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 13 | OUTPUT_VARIABLE rm_out 14 | RETURN_VALUE rm_retval) 15 | if (NOT "${rm_retval}" STREQUAL 0) 16 | MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") 17 | endif() 18 | elseif (IS_SYMLINK "$ENV{DESTDIR}${file}") 19 | EXEC_PROGRAM("@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 20 | OUTPUT_VARIABLE rm_out 21 | RETURN_VALUE rm_retval) 22 | if (NOT "${rm_retval}" STREQUAL 0) 23 | message(FATAL_ERROR "Problem when removing symlink \"$ENV{DESTDIR}${file}\"") 24 | endif() 25 | else() 26 | message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") 27 | endif() 28 | endforeach() 29 | 30 | -------------------------------------------------------------------------------- /src/xkb_unicode.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #ifndef _glfw3_xkb_unicode_h_ 28 | #define _glfw3_xkb_unicode_h_ 29 | 30 | 31 | long _glfwKeySym2Unicode(unsigned int keysym); 32 | 33 | #endif // _glfw3_xkb_unicode_h_ 34 | -------------------------------------------------------------------------------- /CMake/MacOSXBundleInfo.plist.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${MACOSX_BUNDLE_EXECUTABLE_NAME} 9 | CFBundleGetInfoString 10 | ${MACOSX_BUNDLE_INFO_STRING} 11 | CFBundleIconFile 12 | ${MACOSX_BUNDLE_ICON_FILE} 13 | CFBundleIdentifier 14 | ${MACOSX_BUNDLE_GUI_IDENTIFIER} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleLongVersionString 18 | ${MACOSX_BUNDLE_LONG_VERSION_STRING} 19 | CFBundleName 20 | ${MACOSX_BUNDLE_BUNDLE_NAME} 21 | CFBundlePackageType 22 | APPL 23 | CFBundleShortVersionString 24 | ${MACOSX_BUNDLE_SHORT_VERSION_STRING} 25 | CFBundleSignature 26 | ???? 27 | CFBundleVersion 28 | ${MACOSX_BUNDLE_BUNDLE_VERSION} 29 | CSResourcesFileMapped 30 | 31 | LSRequiresCarbon 32 | 33 | NSHumanReadableCopyright 34 | ${MACOSX_BUNDLE_COPYRIGHT} 35 | NSHighResolutionCapable 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /docs/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | $projectname: $title 8 | $title 9 | 10 | 11 | 12 | $treeview 13 | $search 14 | $mathjax 15 | 16 | $extrastylesheet 17 | 18 | 19 |
20 | 21 | 22 |
23 |
24 | GLFW 25 | 31 |
32 |
33 | 34 | 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # External junk 2 | .DS_Store 3 | _ReSharper* 4 | *.opensdf 5 | *.sdf 6 | *.suo 7 | *.dir 8 | *.vcxproj* 9 | *.sln 10 | Win32 11 | x64 12 | Debug 13 | Release 14 | MinSizeRel 15 | RelWithDebInfo 16 | *.xcodeproj 17 | 18 | # CMake files 19 | Makefile 20 | CMakeCache.txt 21 | CMakeFiles 22 | CMakeScripts 23 | cmake_install.cmake 24 | cmake_uninstall.cmake 25 | 26 | # Generated files 27 | docs/Doxyfile 28 | docs/html 29 | docs/warnings.txt 30 | docs/doxygen_sqlite3.db 31 | src/glfw_config.h 32 | src/glfw3.pc 33 | src/glfw3Config.cmake 34 | src/glfw3ConfigVersion.cmake 35 | src/wayland-pointer-constraints-unstable-v1-client-protocol.h 36 | src/wayland-pointer-constraints-unstable-v1-protocol.c 37 | src/wayland-relative-pointer-unstable-v1-client-protocol.h 38 | src/wayland-relative-pointer-unstable-v1-protocol.c 39 | 40 | # Compiled binaries 41 | src/libglfw.so 42 | src/libglfw.so.3 43 | src/libglfw.so.3.2 44 | src/libglfw.dylib 45 | src/libglfw.dylib 46 | src/libglfw.3.dylib 47 | src/libglfw.3.2.dylib 48 | src/libglfw3.a 49 | src/glfw3.lib 50 | src/glfw3.dll 51 | src/glfw3dll.lib 52 | src/libglfw3dll.a 53 | examples/*.app 54 | examples/*.exe 55 | examples/boing 56 | examples/gears 57 | examples/heightmap 58 | examples/particles 59 | examples/splitview 60 | examples/simple 61 | examples/wave 62 | tests/*.app 63 | tests/*.exe 64 | tests/clipboard 65 | tests/cursor 66 | tests/empty 67 | tests/events 68 | tests/gamma 69 | tests/glfwinfo 70 | tests/iconify 71 | tests/joysticks 72 | tests/monitors 73 | tests/msaa 74 | tests/reopen 75 | tests/sharing 76 | tests/tearing 77 | tests/threads 78 | tests/title 79 | tests/version 80 | tests/vulkan 81 | tests/windows 82 | 83 | -------------------------------------------------------------------------------- /src/posix_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #ifndef _glfw3_posix_time_h_ 29 | #define _glfw3_posix_time_h_ 30 | 31 | #define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimePOSIX posix_time 32 | 33 | #include 34 | 35 | 36 | // POSIX-specific global timer data 37 | // 38 | typedef struct _GLFWtimePOSIX 39 | { 40 | GLFWbool monotonic; 41 | uint64_t frequency; 42 | 43 | } _GLFWtimePOSIX; 44 | 45 | 46 | void _glfwInitTimerPOSIX(void); 47 | 48 | #endif // _glfw3_posix_time_h_ 49 | -------------------------------------------------------------------------------- /src/posix_tls.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #ifndef _glfw3_posix_tls_h_ 29 | #define _glfw3_posix_tls_h_ 30 | 31 | #include 32 | 33 | #define _GLFW_PLATFORM_LIBRARY_TLS_STATE _GLFWtlsPOSIX posix_tls 34 | 35 | 36 | // POSIX-specific global TLS data 37 | // 38 | typedef struct _GLFWtlsPOSIX 39 | { 40 | GLFWbool allocated; 41 | pthread_key_t context; 42 | 43 | } _GLFWtlsPOSIX; 44 | 45 | 46 | GLFWbool _glfwInitThreadLocalStoragePOSIX(void); 47 | void _glfwTerminateThreadLocalStoragePOSIX(void); 48 | 49 | #endif // _glfw3_posix_tls_h_ 50 | -------------------------------------------------------------------------------- /docs/main.dox: -------------------------------------------------------------------------------- 1 | /*! 2 | 3 | @mainpage notitle 4 | 5 | @section main_intro Introduction 6 | 7 | GLFW is a free, Open Source, multi-platform library for OpenGL, OpenGL ES and 8 | Vulkan application development. It provides a simple, platform-independent API 9 | for creating windows, contexts and surfaces, reading input, handling events, etc. 10 | 11 | See @ref news_32 for release highlights or the 12 | [version history](http://www.glfw.org/changelog.html) for details. 13 | 14 | @ref quick_guide is a guide for users new to GLFW. It takes you through how to 15 | write a small but complete program. 16 | 17 | There are guides for each section of the API: 18 | 19 | - @ref intro_guide – initialization, error handling and high-level design 20 | - @ref window_guide – creating and working with windows and framebuffers 21 | - @ref context_guide – working with OpenGL and OpenGL ES contexts 22 | - @ref vulkan_guide - working with Vulkan objects and extensions 23 | - @ref monitor_guide – enumerating and working with monitors and video modes 24 | - @ref input_guide – receiving events, polling and processing input 25 | 26 | Once you have written a program, see @ref compile_guide and @ref build_guide. 27 | 28 | The [reference documentation](modules.html) provides more detailed information 29 | about specific functions. 30 | 31 | @ref moving_guide explains what has changed and how to update existing code to 32 | use the new API. 33 | 34 | There is a section on @ref guarantees_limitations for pointer lifetimes, 35 | reentrancy, thread safety, event order and backward and forward compatibility. 36 | 37 | The [FAQ](http://www.glfw.org/faq.html) answers many common questions about the 38 | design, implementation and use of GLFW. 39 | 40 | Finally, @ref compat_guide explains what APIs, standards and protocols GLFW uses 41 | and what happens when they are not present on a given machine. 42 | 43 | This documentation was generated with Doxygen. The sources for it are available 44 | in both the [source distribution](http://www.glfw.org/download.html) and 45 | [GitHub repository](https://github.com/glfw/glfw). 46 | 47 | */ 48 | -------------------------------------------------------------------------------- /src/cocoa_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Cocoa - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2016 Camilla Berglund 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #ifndef _glfw3_cocoa_joystick_h_ 28 | #define _glfw3_cocoa_joystick_h_ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ 36 | _GLFWjoystickNS ns_js[GLFW_JOYSTICK_LAST + 1] 37 | 38 | 39 | // Cocoa-specific per-joystick data 40 | // 41 | typedef struct _GLFWjoystickNS 42 | { 43 | GLFWbool present; 44 | char name[256]; 45 | 46 | IOHIDDeviceRef deviceRef; 47 | 48 | CFMutableArrayRef axisElements; 49 | CFMutableArrayRef buttonElements; 50 | CFMutableArrayRef hatElements; 51 | 52 | float* axes; 53 | unsigned char* buttons; 54 | } _GLFWjoystickNS; 55 | 56 | 57 | void _glfwInitJoysticksNS(void); 58 | void _glfwTerminateJoysticksNS(void); 59 | 60 | #endif // _glfw3_cocoa_joystick_h_ 61 | -------------------------------------------------------------------------------- /src/cocoa_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 OS X - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2016 Camilla Berglund 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include "internal.h" 28 | 29 | #include 30 | 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | ////// GLFW internal API ////// 34 | ////////////////////////////////////////////////////////////////////////// 35 | 36 | // Initialise timer 37 | // 38 | void _glfwInitTimerNS(void) 39 | { 40 | mach_timebase_info_data_t info; 41 | mach_timebase_info(&info); 42 | 43 | _glfw.ns_time.frequency = (info.denom * 1e9) / info.numer; 44 | } 45 | 46 | 47 | ////////////////////////////////////////////////////////////////////////// 48 | ////// GLFW platform API ////// 49 | ////////////////////////////////////////////////////////////////////////// 50 | 51 | uint64_t _glfwPlatformGetTimerValue(void) 52 | { 53 | return mach_absolute_time(); 54 | } 55 | 56 | uint64_t _glfwPlatformGetTimerFrequency(void) 57 | { 58 | return _glfw.ns_time.frequency; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/nsgl_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 OS X - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2016 Camilla Berglund 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #ifndef _glfw3_nsgl_context_h_ 28 | #define _glfw3_nsgl_context_h_ 29 | 30 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL nsgl 31 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryNSGL nsgl 32 | 33 | 34 | // NSGL-specific per-context data 35 | // 36 | typedef struct _GLFWcontextNSGL 37 | { 38 | id pixelFormat; 39 | id object; 40 | 41 | } _GLFWcontextNSGL; 42 | 43 | // NSGL-specific global data 44 | // 45 | typedef struct _GLFWlibraryNSGL 46 | { 47 | // dlopen handle for OpenGL.framework (for glfwGetProcAddress) 48 | CFBundleRef framework; 49 | 50 | } _GLFWlibraryNSGL; 51 | 52 | 53 | GLFWbool _glfwInitNSGL(void); 54 | void _glfwTerminateNSGL(void); 55 | GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, 56 | const _GLFWctxconfig* ctxconfig, 57 | const _GLFWfbconfig* fbconfig); 58 | void _glfwDestroyContextNSGL(_GLFWwindow* window); 59 | 60 | #endif // _glfw3_nsgl_context_h_ 61 | -------------------------------------------------------------------------------- /deps/getopt.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012, Kim Gräsman 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright notice, 7 | * this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright notice, 9 | * this list of conditions and the following disclaimer in the documentation 10 | * and/or other materials provided with the distribution. 11 | * * Neither the name of Kim Gräsman nor the names of contributors may be used 12 | * to endorse or promote products derived from this software without specific 13 | * prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL KIM GRÄSMAN BE LIABLE FOR ANY DIRECT, 19 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef INCLUDED_GETOPT_PORT_H 28 | #define INCLUDED_GETOPT_PORT_H 29 | 30 | #if defined(__cplusplus) 31 | extern "C" { 32 | #endif 33 | 34 | extern const int no_argument; 35 | extern const int required_argument; 36 | extern const int optional_argument; 37 | 38 | extern char* optarg; 39 | extern int optind, opterr, optopt; 40 | 41 | struct option { 42 | const char* name; 43 | int has_arg; 44 | int* flag; 45 | int val; 46 | }; 47 | 48 | int getopt(int argc, char* const argv[], const char* optstring); 49 | 50 | int getopt_long(int argc, char* const argv[], 51 | const char* optstring, const struct option* longopts, int* longindex); 52 | 53 | #if defined(__cplusplus) 54 | } 55 | #endif 56 | 57 | #endif // INCLUDED_GETOPT_PORT_H 58 | -------------------------------------------------------------------------------- /src/linux_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #ifndef _glfw3_linux_joystick_h_ 28 | #define _glfw3_linux_joystick_h_ 29 | 30 | #include 31 | 32 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE _GLFWjoylistLinux linux_js 33 | 34 | 35 | // Linux-specific joystick data 36 | // 37 | typedef struct _GLFWjoystickLinux 38 | { 39 | GLFWbool present; 40 | int fd; 41 | float* axes; 42 | int axisCount; 43 | unsigned char* buttons; 44 | int buttonCount; 45 | char* name; 46 | char* path; 47 | } _GLFWjoystickLinux; 48 | 49 | // Linux-specific joystick API data 50 | // 51 | typedef struct _GLFWjoylistLinux 52 | { 53 | _GLFWjoystickLinux js[GLFW_JOYSTICK_LAST + 1]; 54 | 55 | #if defined(__linux__) 56 | int inotify; 57 | int watch; 58 | regex_t regex; 59 | #endif /*__linux__*/ 60 | } _GLFWjoylistLinux; 61 | 62 | 63 | GLFWbool _glfwInitJoysticksLinux(void); 64 | void _glfwTerminateJoysticksLinux(void); 65 | 66 | void _glfwPollJoystickEvents(void); 67 | 68 | #endif // _glfw3_linux_joystick_h_ 69 | -------------------------------------------------------------------------------- /src/win32_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2016 Camilla Berglund 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #ifndef _glfw3_win32_joystick_h_ 28 | #define _glfw3_win32_joystick_h_ 29 | 30 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ 31 | _GLFWjoystickWin32 win32_js[GLFW_JOYSTICK_LAST + 1] 32 | 33 | // Joystick element (axis, button or slider) 34 | // 35 | typedef struct _GLFWjoyobjectWin32 36 | { 37 | int offset; 38 | int type; 39 | } _GLFWjoyobjectWin32; 40 | 41 | // Win32-specific per-joystick data 42 | // 43 | typedef struct _GLFWjoystickWin32 44 | { 45 | GLFWbool present; 46 | float* axes; 47 | int axisCount; 48 | unsigned char* buttons; 49 | int buttonCount; 50 | _GLFWjoyobjectWin32* objects; 51 | int objectCount; 52 | char* name; 53 | IDirectInputDevice8W* device; 54 | DWORD index; 55 | GUID guid; 56 | } _GLFWjoystickWin32; 57 | 58 | 59 | void _glfwInitJoysticksWin32(void); 60 | void _glfwTerminateJoysticksWin32(void); 61 | void _glfwDetectJoystickConnectionWin32(void); 62 | void _glfwDetectJoystickDisconnectionWin32(void); 63 | 64 | #endif // _glfw3_win32_joystick_h_ 65 | -------------------------------------------------------------------------------- /tests/title.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // UTF-8 window title test 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test sets a UTF-8 window title 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | static void error_callback(int error, const char* description) 37 | { 38 | fprintf(stderr, "Error: %s\n", description); 39 | } 40 | 41 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 42 | { 43 | glViewport(0, 0, width, height); 44 | } 45 | 46 | int main(void) 47 | { 48 | GLFWwindow* window; 49 | 50 | glfwSetErrorCallback(error_callback); 51 | 52 | if (!glfwInit()) 53 | exit(EXIT_FAILURE); 54 | 55 | window = glfwCreateWindow(400, 400, "English 日本語 русский язык 官話", NULL, NULL); 56 | if (!window) 57 | { 58 | glfwTerminate(); 59 | exit(EXIT_FAILURE); 60 | } 61 | 62 | glfwMakeContextCurrent(window); 63 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 64 | glfwSwapInterval(1); 65 | 66 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 67 | 68 | while (!glfwWindowShouldClose(window)) 69 | { 70 | glClear(GL_COLOR_BUFFER_BIT); 71 | glfwSwapBuffers(window); 72 | glfwWaitEvents(); 73 | } 74 | 75 | glfwTerminate(); 76 | exit(EXIT_SUCCESS); 77 | } 78 | 79 | -------------------------------------------------------------------------------- /src/posix_tls.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | 31 | ////////////////////////////////////////////////////////////////////////// 32 | ////// GLFW internal API ////// 33 | ////////////////////////////////////////////////////////////////////////// 34 | 35 | GLFWbool _glfwInitThreadLocalStoragePOSIX(void) 36 | { 37 | if (pthread_key_create(&_glfw.posix_tls.context, NULL) != 0) 38 | { 39 | _glfwInputError(GLFW_PLATFORM_ERROR, 40 | "POSIX: Failed to create context TLS"); 41 | return GLFW_FALSE; 42 | } 43 | 44 | _glfw.posix_tls.allocated = GLFW_TRUE; 45 | return GLFW_TRUE; 46 | } 47 | 48 | void _glfwTerminateThreadLocalStoragePOSIX(void) 49 | { 50 | if (_glfw.posix_tls.allocated) 51 | pthread_key_delete(_glfw.posix_tls.context); 52 | } 53 | 54 | 55 | ////////////////////////////////////////////////////////////////////////// 56 | ////// GLFW platform API ////// 57 | ////////////////////////////////////////////////////////////////////////// 58 | 59 | void _glfwPlatformSetCurrentContext(_GLFWwindow* context) 60 | { 61 | pthread_setspecific(_glfw.posix_tls.context, context); 62 | } 63 | 64 | _GLFWwindow* _glfwPlatformGetCurrentContext(void) 65 | { 66 | return pthread_getspecific(_glfw.posix_tls.context); 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/win32_tls.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | 31 | ////////////////////////////////////////////////////////////////////////// 32 | ////// GLFW internal API ////// 33 | ////////////////////////////////////////////////////////////////////////// 34 | 35 | GLFWbool _glfwInitThreadLocalStorageWin32(void) 36 | { 37 | _glfw.win32_tls.context = TlsAlloc(); 38 | if (_glfw.win32_tls.context == TLS_OUT_OF_INDEXES) 39 | { 40 | _glfwInputError(GLFW_PLATFORM_ERROR, 41 | "Win32: Failed to allocate TLS index"); 42 | return GLFW_FALSE; 43 | } 44 | 45 | _glfw.win32_tls.allocated = GLFW_TRUE; 46 | return GLFW_TRUE; 47 | } 48 | 49 | void _glfwTerminateThreadLocalStorageWin32(void) 50 | { 51 | if (_glfw.win32_tls.allocated) 52 | TlsFree(_glfw.win32_tls.context); 53 | } 54 | 55 | 56 | ////////////////////////////////////////////////////////////////////////// 57 | ////// GLFW platform API ////// 58 | ////////////////////////////////////////////////////////////////////////// 59 | 60 | void _glfwPlatformSetCurrentContext(_GLFWwindow* context) 61 | { 62 | TlsSetValue(_glfw.win32_tls.context, context); 63 | } 64 | 65 | _GLFWwindow* _glfwPlatformGetCurrentContext(void) 66 | { 67 | return TlsGetValue(_glfw.win32_tls.context); 68 | } 69 | 70 | -------------------------------------------------------------------------------- /src/win32_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | 31 | ////////////////////////////////////////////////////////////////////////// 32 | ////// GLFW internal API ////// 33 | ////////////////////////////////////////////////////////////////////////// 34 | 35 | // Initialise timer 36 | // 37 | void _glfwInitTimerWin32(void) 38 | { 39 | uint64_t frequency; 40 | 41 | if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency)) 42 | { 43 | _glfw.win32_time.hasPC = GLFW_TRUE; 44 | _glfw.win32_time.frequency = frequency; 45 | } 46 | else 47 | { 48 | _glfw.win32_time.hasPC = GLFW_FALSE; 49 | _glfw.win32_time.frequency = 1000; 50 | } 51 | } 52 | 53 | 54 | ////////////////////////////////////////////////////////////////////////// 55 | ////// GLFW platform API ////// 56 | ////////////////////////////////////////////////////////////////////////// 57 | 58 | uint64_t _glfwPlatformGetTimerValue(void) 59 | { 60 | if (_glfw.win32_time.hasPC) 61 | { 62 | uint64_t value; 63 | QueryPerformanceCounter((LARGE_INTEGER*) &value); 64 | return value; 65 | } 66 | else 67 | return (uint64_t) _glfw_timeGetTime(); 68 | } 69 | 70 | uint64_t _glfwPlatformGetTimerFrequency(void) 71 | { 72 | return _glfw.win32_time.frequency; 73 | } 74 | 75 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | link_libraries(glfw) 3 | 4 | include_directories(${glfw_INCLUDE_DIRS}) 5 | 6 | if (BUILD_SHARED_LIBS) 7 | link_libraries("${MATH_LIBRARY}") 8 | endif() 9 | 10 | if (MSVC) 11 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 12 | endif() 13 | 14 | include_directories("${GLFW_SOURCE_DIR}/deps") 15 | 16 | if (WIN32) 17 | set(ICON glfw.rc) 18 | elseif (APPLE) 19 | set(ICON glfw.icns) 20 | set_source_files_properties(glfw.icns PROPERTIES 21 | MAXOSX_PACKAGE_LOCATION "Resources") 22 | endif() 23 | 24 | set(GLAD "${GLFW_SOURCE_DIR}/deps/glad/glad.h" 25 | "${GLFW_SOURCE_DIR}/deps/glad.c") 26 | set(GETOPT "${GLFW_SOURCE_DIR}/deps/getopt.h" 27 | "${GLFW_SOURCE_DIR}/deps/getopt.c") 28 | set(TINYCTHREAD "${GLFW_SOURCE_DIR}/deps/tinycthread.h" 29 | "${GLFW_SOURCE_DIR}/deps/tinycthread.c") 30 | 31 | add_executable(boing WIN32 MACOSX_BUNDLE boing.c ${ICON} ${GLAD}) 32 | add_executable(gears WIN32 MACOSX_BUNDLE gears.c ${ICON} ${GLAD}) 33 | add_executable(heightmap WIN32 MACOSX_BUNDLE heightmap.c ${ICON} ${GLAD}) 34 | add_executable(particles WIN32 MACOSX_BUNDLE particles.c ${ICON} ${TINYCTHREAD} ${GETOPT} ${GLAD}) 35 | add_executable(simple WIN32 MACOSX_BUNDLE simple.c ${ICON} ${GLAD}) 36 | add_executable(splitview WIN32 MACOSX_BUNDLE splitview.c ${ICON} ${GLAD}) 37 | add_executable(wave WIN32 MACOSX_BUNDLE wave.c ${ICON} ${GLAD}) 38 | 39 | target_link_libraries(particles "${CMAKE_THREAD_LIBS_INIT}" "${RT_LIBRARY}") 40 | 41 | set(WINDOWS_BINARIES boing gears heightmap particles simple splitview wave) 42 | 43 | set_target_properties(${WINDOWS_BINARIES} PROPERTIES FOLDER "GLFW3/Examples") 44 | 45 | if (MSVC) 46 | # Tell MSVC to use main instead of WinMain for Windows subsystem executables 47 | set_target_properties(${WINDOWS_BINARIES} PROPERTIES 48 | LINK_FLAGS "/ENTRY:mainCRTStartup") 49 | endif() 50 | 51 | if (APPLE) 52 | set_target_properties(boing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Boing") 53 | set_target_properties(gears PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gears") 54 | set_target_properties(heightmap PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Heightmap") 55 | set_target_properties(particles PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Particles") 56 | set_target_properties(simple PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Simple") 57 | set_target_properties(splitview PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "SplitView") 58 | set_target_properties(wave PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Wave") 59 | 60 | set_target_properties(${WINDOWS_BINARIES} PROPERTIES 61 | RESOURCE glfw.icns 62 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} 63 | MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL} 64 | MACOSX_BUNDLE_ICON_FILE glfw.icns 65 | MACOSX_BUNDLE_INFO_PLIST "${GLFW_SOURCE_DIR}/CMake/MacOSXBundleInfo.plist.in") 66 | endif() 67 | 68 | -------------------------------------------------------------------------------- /src/posix_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | #include 31 | #include 32 | 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | ////// GLFW internal API ////// 36 | ////////////////////////////////////////////////////////////////////////// 37 | 38 | // Initialise timer 39 | // 40 | void _glfwInitTimerPOSIX(void) 41 | { 42 | #if defined(CLOCK_MONOTONIC) 43 | struct timespec ts; 44 | 45 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) 46 | { 47 | _glfw.posix_time.monotonic = GLFW_TRUE; 48 | _glfw.posix_time.frequency = 1000000000; 49 | } 50 | else 51 | #endif 52 | { 53 | _glfw.posix_time.monotonic = GLFW_FALSE; 54 | _glfw.posix_time.frequency = 1000000; 55 | } 56 | } 57 | 58 | 59 | ////////////////////////////////////////////////////////////////////////// 60 | ////// GLFW platform API ////// 61 | ////////////////////////////////////////////////////////////////////////// 62 | 63 | uint64_t _glfwPlatformGetTimerValue(void) 64 | { 65 | #if defined(CLOCK_MONOTONIC) 66 | if (_glfw.posix_time.monotonic) 67 | { 68 | struct timespec ts; 69 | clock_gettime(CLOCK_MONOTONIC, &ts); 70 | return (uint64_t) ts.tv_sec * (uint64_t) 1000000000 + (uint64_t) ts.tv_nsec; 71 | } 72 | else 73 | #endif 74 | { 75 | struct timeval tv; 76 | gettimeofday(&tv, NULL); 77 | return (uint64_t) tv.tv_sec * (uint64_t) 1000000 + (uint64_t) tv.tv_usec; 78 | } 79 | } 80 | 81 | uint64_t _glfwPlatformGetTimerFrequency(void) 82 | { 83 | return _glfw.posix_time.frequency; 84 | } 85 | 86 | -------------------------------------------------------------------------------- /tests/timeout.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Event wait timeout test 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test is intended to verify that waiting for events with timeout works 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | static void error_callback(int error, const char* description) 39 | { 40 | fprintf(stderr, "Error: %s\n", description); 41 | } 42 | 43 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 44 | { 45 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 46 | glfwSetWindowShouldClose(window, GLFW_TRUE); 47 | } 48 | 49 | static float nrand(void) 50 | { 51 | return (float) rand() / (float) RAND_MAX; 52 | } 53 | 54 | int main(void) 55 | { 56 | GLFWwindow* window; 57 | 58 | srand((unsigned int) time(NULL)); 59 | 60 | glfwSetErrorCallback(error_callback); 61 | 62 | if (!glfwInit()) 63 | exit(EXIT_FAILURE); 64 | 65 | window = glfwCreateWindow(640, 480, "Event Wait Timeout Test", NULL, NULL); 66 | if (!window) 67 | { 68 | glfwTerminate(); 69 | exit(EXIT_FAILURE); 70 | } 71 | 72 | glfwMakeContextCurrent(window); 73 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 74 | glfwSetKeyCallback(window, key_callback); 75 | 76 | while (!glfwWindowShouldClose(window)) 77 | { 78 | int width, height; 79 | float r = nrand(), g = nrand(), b = nrand(); 80 | float l = (float) sqrt(r * r + g * g + b * b); 81 | 82 | glfwGetFramebufferSize(window, &width, &height); 83 | 84 | glViewport(0, 0, width, height); 85 | glClearColor(r / l, g / l, b / l, 1.f); 86 | glClear(GL_COLOR_BUFFER_BIT); 87 | glfwSwapBuffers(window); 88 | 89 | glfwWaitEventsTimeout(1.0); 90 | } 91 | 92 | glfwDestroyWindow(window); 93 | 94 | glfwTerminate(); 95 | exit(EXIT_SUCCESS); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /src/glfw_config.h.in: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2010-2016 Camilla Berglund 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // As glfw_config.h.in, this file is used by CMake to produce the 27 | // glfw_config.h configuration header file. If you are adding a feature 28 | // requiring conditional compilation, this is where to add the macro. 29 | //======================================================================== 30 | // As glfw_config.h, this file defines compile-time option macros for a 31 | // specific platform and development environment. If you are using the 32 | // GLFW CMake files, modify glfw_config.h.in instead of this file. If you 33 | // are using your own build system, make this file define the appropriate 34 | // macros in whatever way is suitable. 35 | //======================================================================== 36 | 37 | // Define this to 1 if building GLFW for X11 38 | #cmakedefine _GLFW_X11 39 | // Define this to 1 if building GLFW for Win32 40 | #cmakedefine _GLFW_WIN32 41 | // Define this to 1 if building GLFW for Cocoa 42 | #cmakedefine _GLFW_COCOA 43 | // Define this to 1 if building GLFW for Wayland 44 | #cmakedefine _GLFW_WAYLAND 45 | // Define this to 1 if building GLFW for Mir 46 | #cmakedefine _GLFW_MIR 47 | 48 | // Define this to 1 if building as a shared library / dynamic library / DLL 49 | #cmakedefine _GLFW_BUILD_DLL 50 | // Define this to 1 to use Vulkan loader linked statically into application 51 | #cmakedefine _GLFW_VULKAN_STATIC 52 | 53 | // Define this to 1 to force use of high-performance GPU on hybrid systems 54 | #cmakedefine _GLFW_USE_HYBRID_HPG 55 | 56 | // Define this to 1 if the Xxf86vm X11 extension is available 57 | #cmakedefine _GLFW_HAS_XF86VM 58 | 59 | // Define this to 1 if glfwInit should change the current directory 60 | #cmakedefine _GLFW_USE_CHDIR 61 | // Define this to 1 if glfwCreateWindow should populate the menu bar 62 | #cmakedefine _GLFW_USE_MENUBAR 63 | // Define this to 1 if windows should use full resolution on Retina displays 64 | #cmakedefine _GLFW_USE_RETINA 65 | 66 | -------------------------------------------------------------------------------- /deps/mingw/_mingw_dxhelper.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the mingw-w64 runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #if defined(_MSC_VER) && !defined(_MSC_EXTENSIONS) 8 | #define NONAMELESSUNION 1 9 | #endif 10 | #if defined(NONAMELESSSTRUCT) && \ 11 | !defined(NONAMELESSUNION) 12 | #define NONAMELESSUNION 1 13 | #endif 14 | #if defined(NONAMELESSUNION) && \ 15 | !defined(NONAMELESSSTRUCT) 16 | #define NONAMELESSSTRUCT 1 17 | #endif 18 | #if !defined(__GNU_EXTENSION) 19 | #if defined(__GNUC__) || defined(__GNUG__) 20 | #define __GNU_EXTENSION __extension__ 21 | #else 22 | #define __GNU_EXTENSION 23 | #endif 24 | #endif /* __extension__ */ 25 | 26 | #ifndef __ANONYMOUS_DEFINED 27 | #define __ANONYMOUS_DEFINED 28 | #if defined(__GNUC__) || defined(__GNUG__) 29 | #define _ANONYMOUS_UNION __extension__ 30 | #define _ANONYMOUS_STRUCT __extension__ 31 | #else 32 | #define _ANONYMOUS_UNION 33 | #define _ANONYMOUS_STRUCT 34 | #endif 35 | #ifndef NONAMELESSUNION 36 | #define _UNION_NAME(x) 37 | #define _STRUCT_NAME(x) 38 | #else /* NONAMELESSUNION */ 39 | #define _UNION_NAME(x) x 40 | #define _STRUCT_NAME(x) x 41 | #endif 42 | #endif /* __ANONYMOUS_DEFINED */ 43 | 44 | #ifndef DUMMYUNIONNAME 45 | # ifdef NONAMELESSUNION 46 | # define DUMMYUNIONNAME u 47 | # define DUMMYUNIONNAME1 u1 /* Wine uses this variant */ 48 | # define DUMMYUNIONNAME2 u2 49 | # define DUMMYUNIONNAME3 u3 50 | # define DUMMYUNIONNAME4 u4 51 | # define DUMMYUNIONNAME5 u5 52 | # define DUMMYUNIONNAME6 u6 53 | # define DUMMYUNIONNAME7 u7 54 | # define DUMMYUNIONNAME8 u8 55 | # define DUMMYUNIONNAME9 u9 56 | # else /* NONAMELESSUNION */ 57 | # define DUMMYUNIONNAME 58 | # define DUMMYUNIONNAME1 /* Wine uses this variant */ 59 | # define DUMMYUNIONNAME2 60 | # define DUMMYUNIONNAME3 61 | # define DUMMYUNIONNAME4 62 | # define DUMMYUNIONNAME5 63 | # define DUMMYUNIONNAME6 64 | # define DUMMYUNIONNAME7 65 | # define DUMMYUNIONNAME8 66 | # define DUMMYUNIONNAME9 67 | # endif 68 | #endif /* DUMMYUNIONNAME */ 69 | 70 | #if !defined(DUMMYUNIONNAME1) /* MinGW does not define this one */ 71 | # ifdef NONAMELESSUNION 72 | # define DUMMYUNIONNAME1 u1 /* Wine uses this variant */ 73 | # else 74 | # define DUMMYUNIONNAME1 /* Wine uses this variant */ 75 | # endif 76 | #endif /* DUMMYUNIONNAME1 */ 77 | 78 | #ifndef DUMMYSTRUCTNAME 79 | # ifdef NONAMELESSUNION 80 | # define DUMMYSTRUCTNAME s 81 | # define DUMMYSTRUCTNAME1 s1 /* Wine uses this variant */ 82 | # define DUMMYSTRUCTNAME2 s2 83 | # define DUMMYSTRUCTNAME3 s3 84 | # define DUMMYSTRUCTNAME4 s4 85 | # define DUMMYSTRUCTNAME5 s5 86 | # else 87 | # define DUMMYSTRUCTNAME 88 | # define DUMMYSTRUCTNAME1 /* Wine uses this variant */ 89 | # define DUMMYSTRUCTNAME2 90 | # define DUMMYSTRUCTNAME3 91 | # define DUMMYSTRUCTNAME4 92 | # define DUMMYSTRUCTNAME5 93 | # endif 94 | #endif /* DUMMYSTRUCTNAME */ 95 | 96 | /* These are for compatibility with the Wine source tree */ 97 | 98 | #ifndef WINELIB_NAME_AW 99 | # ifdef __MINGW_NAME_AW 100 | # define WINELIB_NAME_AW __MINGW_NAME_AW 101 | # else 102 | # ifdef UNICODE 103 | # define WINELIB_NAME_AW(func) func##W 104 | # else 105 | # define WINELIB_NAME_AW(func) func##A 106 | # endif 107 | # endif 108 | #endif /* WINELIB_NAME_AW */ 109 | 110 | #ifndef DECL_WINELIB_TYPE_AW 111 | # ifdef __MINGW_TYPEDEF_AW 112 | # define DECL_WINELIB_TYPE_AW __MINGW_TYPEDEF_AW 113 | # else 114 | # define DECL_WINELIB_TYPE_AW(type) typedef WINELIB_NAME_AW(type) type; 115 | # endif 116 | #endif /* DECL_WINELIB_TYPE_AW */ 117 | 118 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | link_libraries(glfw) 3 | 4 | if (BUILD_SHARED_LIBS) 5 | link_libraries("${MATH_LIBRARY}") 6 | endif() 7 | 8 | if (MSVC) 9 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 10 | endif() 11 | 12 | include_directories("${GLFW_SOURCE_DIR}/deps") 13 | 14 | set(GLAD "${GLFW_SOURCE_DIR}/deps/glad/glad.h" 15 | "${GLFW_SOURCE_DIR}/deps/glad.c") 16 | set(GETOPT "${GLFW_SOURCE_DIR}/deps/getopt.h" 17 | "${GLFW_SOURCE_DIR}/deps/getopt.c") 18 | set(TINYCTHREAD "${GLFW_SOURCE_DIR}/deps/tinycthread.h" 19 | "${GLFW_SOURCE_DIR}/deps/tinycthread.c") 20 | 21 | add_executable(clipboard clipboard.c ${GETOPT} ${GLAD}) 22 | add_executable(events events.c ${GETOPT} ${GLAD}) 23 | add_executable(msaa msaa.c ${GETOPT} ${GLAD}) 24 | add_executable(gamma gamma.c ${GETOPT} ${GLAD}) 25 | add_executable(glfwinfo glfwinfo.c ${GETOPT} ${GLAD}) 26 | add_executable(iconify iconify.c ${GETOPT} ${GLAD}) 27 | add_executable(joysticks joysticks.c ${GLAD}) 28 | add_executable(monitors monitors.c ${GETOPT} ${GLAD}) 29 | add_executable(reopen reopen.c ${GLAD}) 30 | add_executable(cursor cursor.c ${GLAD}) 31 | 32 | add_executable(empty WIN32 MACOSX_BUNDLE empty.c ${TINYCTHREAD} ${GLAD}) 33 | add_executable(icon WIN32 MACOSX_BUNDLE icon.c ${GLAD}) 34 | add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c ${GLAD}) 35 | add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c ${GETOPT} ${GLAD}) 36 | add_executable(threads WIN32 MACOSX_BUNDLE threads.c ${TINYCTHREAD} ${GLAD}) 37 | add_executable(timeout WIN32 MACOSX_BUNDLE timeout.c ${GLAD}) 38 | add_executable(title WIN32 MACOSX_BUNDLE title.c ${GLAD}) 39 | add_executable(windows WIN32 MACOSX_BUNDLE windows.c ${GETOPT} ${GLAD}) 40 | 41 | target_link_libraries(empty "${CMAKE_THREAD_LIBS_INIT}" "${RT_LIBRARY}") 42 | target_link_libraries(threads "${CMAKE_THREAD_LIBS_INIT}" "${RT_LIBRARY}") 43 | 44 | set(WINDOWS_BINARIES empty icon sharing tearing threads timeout title windows) 45 | set(CONSOLE_BINARIES clipboard events msaa gamma glfwinfo 46 | iconify joysticks monitors reopen cursor) 47 | 48 | if (VULKAN_FOUND) 49 | add_executable(vulkan WIN32 vulkan.c ${ICON}) 50 | target_include_directories(vulkan PRIVATE "${VULKAN_INCLUDE_DIR}") 51 | if (NOT GLFW_VULKAN_STATIC) 52 | target_link_libraries(vulkan "${VULKAN_LIBRARY}") 53 | endif() 54 | list(APPEND WINDOWS_BINARIES vulkan) 55 | endif() 56 | 57 | set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES 58 | FOLDER "GLFW3/Tests") 59 | 60 | if (MSVC) 61 | # Tell MSVC to use main instead of WinMain for Windows subsystem executables 62 | set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES 63 | LINK_FLAGS "/ENTRY:mainCRTStartup") 64 | endif() 65 | 66 | if (APPLE) 67 | set_target_properties(empty PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Empty Event") 68 | set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing") 69 | set_target_properties(tearing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Tearing") 70 | set_target_properties(threads PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Threads") 71 | set_target_properties(timeout PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Timeout") 72 | set_target_properties(title PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Title") 73 | set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows") 74 | 75 | set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES 76 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} 77 | MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL} 78 | MACOSX_BUNDLE_INFO_PLIST "${GLFW_SOURCE_DIR}/CMake/MacOSXBundleInfo.plist.in") 79 | endif() 80 | 81 | -------------------------------------------------------------------------------- /tests/empty.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Empty event test 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test is intended to verify that posting of empty events works 27 | // 28 | //======================================================================== 29 | 30 | #include "tinycthread.h" 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | static volatile int running = GLFW_TRUE; 40 | 41 | static void error_callback(int error, const char* description) 42 | { 43 | fprintf(stderr, "Error: %s\n", description); 44 | } 45 | 46 | static int thread_main(void* data) 47 | { 48 | struct timespec time; 49 | 50 | while (running) 51 | { 52 | clock_gettime(CLOCK_REALTIME, &time); 53 | time.tv_sec += 1; 54 | thrd_sleep(&time, NULL); 55 | 56 | glfwPostEmptyEvent(); 57 | } 58 | 59 | return 0; 60 | } 61 | 62 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 63 | { 64 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 65 | glfwSetWindowShouldClose(window, GLFW_TRUE); 66 | } 67 | 68 | static float nrand(void) 69 | { 70 | return (float) rand() / (float) RAND_MAX; 71 | } 72 | 73 | int main(void) 74 | { 75 | int result; 76 | thrd_t thread; 77 | GLFWwindow* window; 78 | 79 | srand((unsigned int) time(NULL)); 80 | 81 | glfwSetErrorCallback(error_callback); 82 | 83 | if (!glfwInit()) 84 | exit(EXIT_FAILURE); 85 | 86 | window = glfwCreateWindow(640, 480, "Empty Event Test", NULL, NULL); 87 | if (!window) 88 | { 89 | glfwTerminate(); 90 | exit(EXIT_FAILURE); 91 | } 92 | 93 | glfwMakeContextCurrent(window); 94 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 95 | glfwSetKeyCallback(window, key_callback); 96 | 97 | if (thrd_create(&thread, thread_main, NULL) != thrd_success) 98 | { 99 | fprintf(stderr, "Failed to create secondary thread\n"); 100 | 101 | glfwTerminate(); 102 | exit(EXIT_FAILURE); 103 | } 104 | 105 | while (running) 106 | { 107 | int width, height; 108 | float r = nrand(), g = nrand(), b = nrand(); 109 | float l = (float) sqrt(r * r + g * g + b * b); 110 | 111 | glfwGetFramebufferSize(window, &width, &height); 112 | 113 | glViewport(0, 0, width, height); 114 | glClearColor(r / l, g / l, b / l, 1.f); 115 | glClear(GL_COLOR_BUFFER_BIT); 116 | glfwSwapBuffers(window); 117 | 118 | glfwWaitEvents(); 119 | 120 | if (glfwWindowShouldClose(window)) 121 | running = GLFW_FALSE; 122 | } 123 | 124 | glfwHideWindow(window); 125 | thrd_join(thread, &result); 126 | glfwDestroyWindow(window); 127 | 128 | glfwTerminate(); 129 | exit(EXIT_SUCCESS); 130 | } 131 | 132 | -------------------------------------------------------------------------------- /deps/vulkan/vk_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_platform.h 3 | // 4 | /* 5 | ** Copyright (c) 2014-2015 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | 21 | #ifndef VK_PLATFORM_H_ 22 | #define VK_PLATFORM_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" 26 | { 27 | #endif // __cplusplus 28 | 29 | /* 30 | *************************************************************************************************** 31 | * Platform-specific directives and type declarations 32 | *************************************************************************************************** 33 | */ 34 | 35 | /* Platform-specific calling convention macros. 36 | * 37 | * Platforms should define these so that Vulkan clients call Vulkan commands 38 | * with the same calling conventions that the Vulkan implementation expects. 39 | * 40 | * VKAPI_ATTR - Placed before the return type in function declarations. 41 | * Useful for C++11 and GCC/Clang-style function attribute syntax. 42 | * VKAPI_CALL - Placed after the return type in function declarations. 43 | * Useful for MSVC-style calling convention syntax. 44 | * VKAPI_PTR - Placed between the '(' and '*' in function pointer types. 45 | * 46 | * Function declaration: VKAPI_ATTR void VKAPI_CALL vkCommand(void); 47 | * Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void); 48 | */ 49 | #if defined(_WIN32) 50 | // On Windows, Vulkan commands use the stdcall convention 51 | #define VKAPI_ATTR 52 | #define VKAPI_CALL __stdcall 53 | #define VKAPI_PTR VKAPI_CALL 54 | #elif defined(__ANDROID__) && defined(__ARM_EABI__) && !defined(__ARM_ARCH_7A__) 55 | // Android does not support Vulkan in native code using the "armeabi" ABI. 56 | #error "Vulkan requires the 'armeabi-v7a' or 'armeabi-v7a-hard' ABI on 32-bit ARM CPUs" 57 | #elif defined(__ANDROID__) && defined(__ARM_ARCH_7A__) 58 | // On Android/ARMv7a, Vulkan functions use the armeabi-v7a-hard calling 59 | // convention, even if the application's native code is compiled with the 60 | // armeabi-v7a calling convention. 61 | #define VKAPI_ATTR __attribute__((pcs("aapcs-vfp"))) 62 | #define VKAPI_CALL 63 | #define VKAPI_PTR VKAPI_ATTR 64 | #else 65 | // On other platforms, use the default calling convention 66 | #define VKAPI_ATTR 67 | #define VKAPI_CALL 68 | #define VKAPI_PTR 69 | #endif 70 | 71 | #include 72 | 73 | #if !defined(VK_NO_STDINT_H) 74 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 75 | typedef signed __int8 int8_t; 76 | typedef unsigned __int8 uint8_t; 77 | typedef signed __int16 int16_t; 78 | typedef unsigned __int16 uint16_t; 79 | typedef signed __int32 int32_t; 80 | typedef unsigned __int32 uint32_t; 81 | typedef signed __int64 int64_t; 82 | typedef unsigned __int64 uint64_t; 83 | #else 84 | #include 85 | #endif 86 | #endif // !defined(VK_NO_STDINT_H) 87 | 88 | #ifdef __cplusplus 89 | } // extern "C" 90 | #endif // __cplusplus 91 | 92 | // Platform-specific headers required by platform window system extensions. 93 | // These are enabled prior to #including "vulkan.h". The same enable then 94 | // controls inclusion of the extension interfaces in vulkan.h. 95 | 96 | #ifdef VK_USE_PLATFORM_ANDROID_KHR 97 | #include 98 | #endif 99 | 100 | #ifdef VK_USE_PLATFORM_MIR_KHR 101 | #include 102 | #endif 103 | 104 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR 105 | #include 106 | #endif 107 | 108 | #ifdef VK_USE_PLATFORM_WIN32_KHR 109 | #include 110 | #endif 111 | 112 | #ifdef VK_USE_PLATFORM_XLIB_KHR 113 | #include 114 | #endif 115 | 116 | #ifdef VK_USE_PLATFORM_XCB_KHR 117 | #include 118 | #endif 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /tests/threads.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Multi-threading test 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test is intended to verify whether the OpenGL context part of 27 | // the GLFW API is able to be used from multiple threads 28 | // 29 | //======================================================================== 30 | 31 | #include "tinycthread.h" 32 | 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | typedef struct 41 | { 42 | GLFWwindow* window; 43 | const char* title; 44 | float r, g, b; 45 | thrd_t id; 46 | } Thread; 47 | 48 | static volatile int running = GLFW_TRUE; 49 | 50 | static void error_callback(int error, const char* description) 51 | { 52 | fprintf(stderr, "Error: %s\n", description); 53 | } 54 | 55 | static int thread_main(void* data) 56 | { 57 | const Thread* thread = data; 58 | 59 | glfwMakeContextCurrent(thread->window); 60 | glfwSwapInterval(1); 61 | 62 | while (running) 63 | { 64 | const float v = (float) fabs(sin(glfwGetTime() * 2.f)); 65 | glClearColor(thread->r * v, thread->g * v, thread->b * v, 0.f); 66 | 67 | glClear(GL_COLOR_BUFFER_BIT); 68 | glfwSwapBuffers(thread->window); 69 | } 70 | 71 | glfwMakeContextCurrent(NULL); 72 | return 0; 73 | } 74 | 75 | int main(void) 76 | { 77 | int i, result; 78 | Thread threads[] = 79 | { 80 | { NULL, "Red", 1.f, 0.f, 0.f, 0 }, 81 | { NULL, "Green", 0.f, 1.f, 0.f, 0 }, 82 | { NULL, "Blue", 0.f, 0.f, 1.f, 0 } 83 | }; 84 | const int count = sizeof(threads) / sizeof(Thread); 85 | 86 | glfwSetErrorCallback(error_callback); 87 | 88 | if (!glfwInit()) 89 | exit(EXIT_FAILURE); 90 | 91 | glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); 92 | 93 | for (i = 0; i < count; i++) 94 | { 95 | threads[i].window = glfwCreateWindow(200, 200, 96 | threads[i].title, 97 | NULL, NULL); 98 | if (!threads[i].window) 99 | { 100 | glfwTerminate(); 101 | exit(EXIT_FAILURE); 102 | } 103 | 104 | glfwSetWindowPos(threads[i].window, 200 + 250 * i, 200); 105 | glfwShowWindow(threads[i].window); 106 | } 107 | 108 | glfwMakeContextCurrent(threads[0].window); 109 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 110 | glfwMakeContextCurrent(NULL); 111 | 112 | for (i = 0; i < count; i++) 113 | { 114 | if (thrd_create(&threads[i].id, thread_main, threads + i) != 115 | thrd_success) 116 | { 117 | fprintf(stderr, "Failed to create secondary thread\n"); 118 | 119 | glfwTerminate(); 120 | exit(EXIT_FAILURE); 121 | } 122 | } 123 | 124 | while (running) 125 | { 126 | glfwWaitEvents(); 127 | 128 | for (i = 0; i < count; i++) 129 | { 130 | if (glfwWindowShouldClose(threads[i].window)) 131 | running = GLFW_FALSE; 132 | } 133 | } 134 | 135 | for (i = 0; i < count; i++) 136 | glfwHideWindow(threads[i].window); 137 | 138 | for (i = 0; i < count; i++) 139 | thrd_join(threads[i].id, &result); 140 | 141 | exit(EXIT_SUCCESS); 142 | } 143 | 144 | -------------------------------------------------------------------------------- /src/mir_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Mir - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014-2015 Brandon Schaefer 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #ifndef _glfw3_mir_platform_h_ 28 | #define _glfw3_mir_platform_h_ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | typedef VkFlags VkMirSurfaceCreateFlagsKHR; 37 | 38 | typedef struct VkMirSurfaceCreateInfoKHR 39 | { 40 | VkStructureType sType; 41 | const void* pNext; 42 | VkMirSurfaceCreateFlagsKHR flags; 43 | MirConnection* connection; 44 | MirSurface* mirSurface; 45 | } VkMirSurfaceCreateInfoKHR; 46 | 47 | typedef VkResult (APIENTRY *PFN_vkCreateMirSurfaceKHR)(VkInstance,const VkMirSurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*); 48 | typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceMirPresentationSupportKHR)(VkPhysicalDevice,uint32_t,MirConnection*); 49 | 50 | #include "posix_tls.h" 51 | #include "posix_time.h" 52 | #include "linux_joystick.h" 53 | #include "xkb_unicode.h" 54 | #include "egl_context.h" 55 | 56 | #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) 57 | #define _glfw_dlclose(handle) dlclose(handle) 58 | #define _glfw_dlsym(handle, name) dlsym(handle, name) 59 | 60 | #define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->mir.window) 61 | #define _GLFW_EGL_NATIVE_DISPLAY ((EGLNativeDisplayType) _glfw.mir.display) 62 | 63 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowMir mir 64 | #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorMir mir 65 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryMir mir 66 | #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorMir mir 67 | 68 | #define _GLFW_PLATFORM_CONTEXT_STATE 69 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE 70 | 71 | 72 | // Mir-specific Event Queue 73 | // 74 | typedef struct EventQueue 75 | { 76 | TAILQ_HEAD(, EventNode) head; 77 | } EventQueue; 78 | 79 | // Mir-specific per-window data 80 | // 81 | typedef struct _GLFWwindowMir 82 | { 83 | MirSurface* surface; 84 | int width; 85 | int height; 86 | MirEGLNativeWindowType window; 87 | 88 | } _GLFWwindowMir; 89 | 90 | // Mir-specific per-monitor data 91 | // 92 | typedef struct _GLFWmonitorMir 93 | { 94 | int cur_mode; 95 | int output_id; 96 | int x; 97 | int y; 98 | 99 | } _GLFWmonitorMir; 100 | 101 | // Mir-specific global data 102 | // 103 | typedef struct _GLFWlibraryMir 104 | { 105 | MirConnection* connection; 106 | MirEGLNativeDisplayType display; 107 | MirCursorConfiguration* default_conf; 108 | EventQueue* event_queue; 109 | 110 | short int publicKeys[256]; 111 | 112 | pthread_mutex_t event_mutex; 113 | pthread_cond_t event_cond; 114 | 115 | } _GLFWlibraryMir; 116 | 117 | // Mir-specific per-cursor data 118 | // TODO: Only system cursors are implemented in Mir atm. Need to wait for support. 119 | // 120 | typedef struct _GLFWcursorMir 121 | { 122 | MirCursorConfiguration* conf; 123 | MirBufferStream* custom_cursor; 124 | } _GLFWcursorMir; 125 | 126 | 127 | extern void _glfwInitEventQueueMir(EventQueue* queue); 128 | extern void _glfwDeleteEventQueueMir(EventQueue* queue); 129 | 130 | #endif // _glfw3_mir_platform_h_ 131 | -------------------------------------------------------------------------------- /tests/icon.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Window icon test program 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This program is used to test the icon feature. 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | // a simple glfw logo 38 | const char* const logo[] = 39 | { 40 | "................", 41 | "................", 42 | "...0000..0......", 43 | "...0.....0......", 44 | "...0.00..0......", 45 | "...0..0..0......", 46 | "...0000..0000...", 47 | "................", 48 | "................", 49 | "...000..0...0...", 50 | "...0....0...0...", 51 | "...000..0.0.0...", 52 | "...0....0.0.0...", 53 | "...0....00000...", 54 | "................", 55 | "................" 56 | }; 57 | 58 | const unsigned char icon_colors[5][4] = 59 | { 60 | { 0, 0, 0, 255 }, // black 61 | { 255, 0, 0, 255 }, // red 62 | { 0, 255, 0, 255 }, // green 63 | { 0, 0, 255, 255 }, // blue 64 | { 255, 255, 255, 255 } // white 65 | }; 66 | 67 | static int cur_icon_color = 0; 68 | 69 | static void set_icon(GLFWwindow* window, int icon_color) 70 | { 71 | int x, y; 72 | unsigned char pixels[16 * 16 * 4]; 73 | unsigned char* target = pixels; 74 | GLFWimage img = { 16, 16, pixels }; 75 | 76 | for (y = 0; y < img.width; y++) 77 | { 78 | for (x = 0; x < img.height; x++) 79 | { 80 | if (logo[y][x] == '0') 81 | memcpy(target, icon_colors[icon_color], 4); 82 | else 83 | memset(target, 0, 4); 84 | 85 | target += 4; 86 | } 87 | } 88 | 89 | glfwSetWindowIcon(window, 1, &img); 90 | } 91 | 92 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 93 | { 94 | if (action != GLFW_PRESS) 95 | return; 96 | 97 | switch (key) 98 | { 99 | case GLFW_KEY_ESCAPE: 100 | glfwSetWindowShouldClose(window, GLFW_TRUE); 101 | break; 102 | case GLFW_KEY_SPACE: 103 | cur_icon_color = (cur_icon_color + 1) % 5; 104 | set_icon(window, cur_icon_color); 105 | break; 106 | case GLFW_KEY_X: 107 | glfwSetWindowIcon(window, 0, NULL); 108 | break; 109 | } 110 | } 111 | 112 | int main(int argc, char** argv) 113 | { 114 | GLFWwindow* window; 115 | 116 | if (!glfwInit()) 117 | { 118 | fprintf(stderr, "Failed to initialize GLFW\n"); 119 | exit(EXIT_FAILURE); 120 | } 121 | 122 | window = glfwCreateWindow(200, 200, "Window Icon", NULL, NULL); 123 | if (!window) 124 | { 125 | glfwTerminate(); 126 | 127 | fprintf(stderr, "Failed to open GLFW window\n"); 128 | exit(EXIT_FAILURE); 129 | } 130 | 131 | glfwMakeContextCurrent(window); 132 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 133 | 134 | glfwSetKeyCallback(window, key_callback); 135 | set_icon(window, cur_icon_color); 136 | 137 | while (!glfwWindowShouldClose(window)) 138 | { 139 | glClear(GL_COLOR_BUFFER_BIT); 140 | glfwSwapBuffers(window); 141 | glfwWaitEvents(); 142 | } 143 | 144 | glfwDestroyWindow(window); 145 | glfwTerminate(); 146 | exit(EXIT_SUCCESS); 147 | } 148 | 149 | -------------------------------------------------------------------------------- /docs/internal.dox: -------------------------------------------------------------------------------- 1 | /*! 2 | 3 | @page internals_guide Internal structure 4 | 5 | @tableofcontents 6 | 7 | There are several interfaces inside GLFW. Each interface has its own area of 8 | responsibility and its own naming conventions. 9 | 10 | 11 | @section internals_public Public interface 12 | 13 | The most well-known is the public interface, described in the glfw3.h header 14 | file. This is implemented in source files shared by all platforms and these 15 | files contain no platform-specific code. This code usually ends up calling the 16 | platform and internal interfaces to do the actual work. 17 | 18 | The public interface uses the OpenGL naming conventions except with GLFW and 19 | glfw instead of GL and gl. For struct members, where OpenGL sets no precedent, 20 | it use headless camel case. 21 | 22 | Examples: @ref glfwCreateWindow, @ref GLFWwindow, @ref GLFWvidmode.redBits, 23 | `GLFW_RED_BITS` 24 | 25 | 26 | @section internals_native Native interface 27 | 28 | The [native interface](@ref native) is a small set of publicly available 29 | but platform-specific functions, described in the glfw3native.h header file and 30 | used to gain access to the underlying window, context and (on some platforms) 31 | display handles used by the platform interface. 32 | 33 | The function names of the native interface are similar to those of the public 34 | interface, but embeds the name of the interface that the returned handle is 35 | from. 36 | 37 | Examples: @ref glfwGetX11Window, @ref glfwGetWGLContext 38 | 39 | 40 | @section internals_internal Internal interface 41 | 42 | The internal interface consists of utility functions used by all other 43 | interfaces. It is shared code implemented in the same shared source files as 44 | the public and event interfaces. The internal interface is described in the 45 | internal.h header file. 46 | 47 | The internal interface is in charge of GLFW's global data, which it stores in 48 | a `_GLFWlibrary` struct named `_glfw`. 49 | 50 | The internal interface uses the same style as the public interface, except all 51 | global names have a leading underscore. 52 | 53 | Examples: @ref _glfwIsValidContextConfig, @ref _GLFWwindow, `_glfw.currentRamp` 54 | 55 | 56 | @section internals_platform Platform interface 57 | 58 | The platform interface implements all platform-specific operations as a service 59 | to the public interface. This includes event processing. The platform 60 | interface is never directly called by application code and never directly calls 61 | application-provided callbacks. It is also prohibited from modifying the 62 | platform-independent part of the internal structs. Instead, it calls the event 63 | interface when events interesting to GLFW are received. 64 | 65 | The platform interface mirrors those parts of the public interface that needs to 66 | perform platform-specific operations on some or all platforms. The are also 67 | named the same except that the glfw function prefix is replaced by 68 | _glfwPlatform. 69 | 70 | Examples: @ref _glfwPlatformCreateWindow 71 | 72 | The platform interface also defines structs that contain platform-specific 73 | global and per-object state. Their names mirror those of the internal 74 | interface, except that an interface-specific suffix is added. 75 | 76 | Examples: `_GLFWwindowX11`, `_GLFWcontextWGL` 77 | 78 | These structs are incorporated as members into the internal interface structs 79 | using special macros that name them after the specific interface used. This 80 | prevents shared code from accidentally using these members. 81 | 82 | Examples: `window.win32.handle`, `_glfw.x11.display` 83 | 84 | 85 | @section internals_event Event interface 86 | 87 | The event interface is implemented in the same shared source files as the public 88 | interface and is responsible for delivering the events it receives to the 89 | application, either via callbacks, via window state changes or both. 90 | 91 | The function names of the event interface use a `_glfwInput` prefix and the 92 | ObjectEvent pattern. 93 | 94 | Examples: @ref _glfwInputWindowFocus, @ref _glfwInputCursorMotion 95 | 96 | 97 | @section internals_static Static functions 98 | 99 | Static functions may be used by any interface and have no prefixes or suffixes. 100 | These use headless camel case. 101 | 102 | Examples: `clearScrollOffsets` 103 | 104 | 105 | @section internals_config Configuration macros 106 | 107 | GLFW uses a number of configuration macros to select at compile time which 108 | interfaces and code paths to use. They are defined in the glfw_config.h header file, 109 | which is generated from the `glfw_config.h.in` file by CMake. 110 | 111 | Configuration macros the same style as tokens in the public interface, except 112 | with a leading underscore. 113 | 114 | Examples: `_GLFW_HAS_XF86VM` 115 | 116 | */ 117 | -------------------------------------------------------------------------------- /tests/clipboard.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Clipboard test program 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This program is used to test the clipboard functionality. 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | #include "getopt.h" 37 | 38 | #if defined(__APPLE__) 39 | #define MODIFIER GLFW_MOD_SUPER 40 | #else 41 | #define MODIFIER GLFW_MOD_CONTROL 42 | #endif 43 | 44 | static void usage(void) 45 | { 46 | printf("Usage: clipboard [-h]\n"); 47 | } 48 | 49 | static void error_callback(int error, const char* description) 50 | { 51 | fprintf(stderr, "Error: %s\n", description); 52 | } 53 | 54 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 55 | { 56 | if (action != GLFW_PRESS) 57 | return; 58 | 59 | switch (key) 60 | { 61 | case GLFW_KEY_ESCAPE: 62 | glfwSetWindowShouldClose(window, GLFW_TRUE); 63 | break; 64 | 65 | case GLFW_KEY_V: 66 | if (mods == MODIFIER) 67 | { 68 | const char* string; 69 | 70 | string = glfwGetClipboardString(window); 71 | if (string) 72 | printf("Clipboard contains \"%s\"\n", string); 73 | else 74 | printf("Clipboard does not contain a string\n"); 75 | } 76 | break; 77 | 78 | case GLFW_KEY_C: 79 | if (mods == MODIFIER) 80 | { 81 | const char* string = "Hello GLFW World!"; 82 | glfwSetClipboardString(window, string); 83 | printf("Setting clipboard to \"%s\"\n", string); 84 | } 85 | break; 86 | } 87 | } 88 | 89 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 90 | { 91 | glViewport(0, 0, width, height); 92 | } 93 | 94 | int main(int argc, char** argv) 95 | { 96 | int ch; 97 | GLFWwindow* window; 98 | 99 | while ((ch = getopt(argc, argv, "h")) != -1) 100 | { 101 | switch (ch) 102 | { 103 | case 'h': 104 | usage(); 105 | exit(EXIT_SUCCESS); 106 | 107 | default: 108 | usage(); 109 | exit(EXIT_FAILURE); 110 | } 111 | } 112 | 113 | glfwSetErrorCallback(error_callback); 114 | 115 | if (!glfwInit()) 116 | { 117 | fprintf(stderr, "Failed to initialize GLFW\n"); 118 | exit(EXIT_FAILURE); 119 | } 120 | 121 | window = glfwCreateWindow(200, 200, "Clipboard Test", NULL, NULL); 122 | if (!window) 123 | { 124 | glfwTerminate(); 125 | 126 | fprintf(stderr, "Failed to open GLFW window\n"); 127 | exit(EXIT_FAILURE); 128 | } 129 | 130 | glfwMakeContextCurrent(window); 131 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 132 | glfwSwapInterval(1); 133 | 134 | glfwSetKeyCallback(window, key_callback); 135 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 136 | 137 | glMatrixMode(GL_PROJECTION); 138 | glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f); 139 | glMatrixMode(GL_MODELVIEW); 140 | 141 | glClearColor(0.5f, 0.5f, 0.5f, 0); 142 | 143 | while (!glfwWindowShouldClose(window)) 144 | { 145 | glClear(GL_COLOR_BUFFER_BIT); 146 | 147 | glColor3f(0.8f, 0.2f, 0.4f); 148 | glRectf(-0.5f, -0.5f, 0.5f, 0.5f); 149 | 150 | glfwSwapBuffers(window); 151 | glfwWaitEvents(); 152 | } 153 | 154 | glfwTerminate(); 155 | exit(EXIT_SUCCESS); 156 | } 157 | 158 | -------------------------------------------------------------------------------- /tests/windows.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Simple multi-window test 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test creates four windows and clears each in a different color 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | #include "getopt.h" 37 | 38 | static const char* titles[] = 39 | { 40 | "Red", 41 | "Green", 42 | "Blue", 43 | "Yellow" 44 | }; 45 | 46 | static const struct 47 | { 48 | float r, g, b; 49 | } colors[] = 50 | { 51 | { 0.95f, 0.32f, 0.11f }, 52 | { 0.50f, 0.80f, 0.16f }, 53 | { 0.f, 0.68f, 0.94f }, 54 | { 0.98f, 0.74f, 0.04f } 55 | }; 56 | 57 | static void usage(void) 58 | { 59 | printf("Usage: windows [-h] [-b]\n"); 60 | printf("Options:\n"); 61 | printf(" -b create decorated windows\n"); 62 | printf(" -h show this help\n"); 63 | } 64 | 65 | static void error_callback(int error, const char* description) 66 | { 67 | fprintf(stderr, "Error: %s\n", description); 68 | } 69 | 70 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 71 | { 72 | if (action != GLFW_PRESS) 73 | return; 74 | 75 | switch (key) 76 | { 77 | case GLFW_KEY_SPACE: 78 | { 79 | int xpos, ypos; 80 | glfwGetWindowPos(window, &xpos, &ypos); 81 | glfwSetWindowPos(window, xpos, ypos); 82 | break; 83 | } 84 | 85 | case GLFW_KEY_ESCAPE: 86 | glfwSetWindowShouldClose(window, GLFW_TRUE); 87 | break; 88 | } 89 | } 90 | 91 | int main(int argc, char** argv) 92 | { 93 | int i, ch; 94 | int decorated = GLFW_FALSE; 95 | int running = GLFW_TRUE; 96 | GLFWwindow* windows[4]; 97 | 98 | while ((ch = getopt(argc, argv, "bh")) != -1) 99 | { 100 | switch (ch) 101 | { 102 | case 'b': 103 | decorated = GLFW_TRUE; 104 | break; 105 | case 'h': 106 | usage(); 107 | exit(EXIT_SUCCESS); 108 | default: 109 | usage(); 110 | exit(EXIT_FAILURE); 111 | } 112 | } 113 | 114 | glfwSetErrorCallback(error_callback); 115 | 116 | if (!glfwInit()) 117 | exit(EXIT_FAILURE); 118 | 119 | glfwWindowHint(GLFW_DECORATED, decorated); 120 | glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); 121 | 122 | for (i = 0; i < 4; i++) 123 | { 124 | int left, top, right, bottom; 125 | 126 | windows[i] = glfwCreateWindow(200, 200, titles[i], NULL, NULL); 127 | if (!windows[i]) 128 | { 129 | glfwTerminate(); 130 | exit(EXIT_FAILURE); 131 | } 132 | 133 | glfwSetKeyCallback(windows[i], key_callback); 134 | 135 | glfwMakeContextCurrent(windows[i]); 136 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 137 | glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f); 138 | 139 | glfwGetWindowFrameSize(windows[i], &left, &top, &right, &bottom); 140 | glfwSetWindowPos(windows[i], 141 | 100 + (i & 1) * (200 + left + right), 142 | 100 + (i >> 1) * (200 + top + bottom)); 143 | } 144 | 145 | for (i = 0; i < 4; i++) 146 | glfwShowWindow(windows[i]); 147 | 148 | while (running) 149 | { 150 | for (i = 0; i < 4; i++) 151 | { 152 | glfwMakeContextCurrent(windows[i]); 153 | glClear(GL_COLOR_BUFFER_BIT); 154 | glfwSwapBuffers(windows[i]); 155 | 156 | if (glfwWindowShouldClose(windows[i])) 157 | running = GLFW_FALSE; 158 | } 159 | 160 | glfwWaitEvents(); 161 | } 162 | 163 | glfwTerminate(); 164 | exit(EXIT_SUCCESS); 165 | } 166 | 167 | -------------------------------------------------------------------------------- /docs/extra.css: -------------------------------------------------------------------------------- 1 | #navrow1,#navrow2,#navrow3,#navrow4,.tablist a,.tablist a:visited,.tablist a:hover,.tablist li,.tablist li.current a,.memdoc,dl.reflist dd,div.toc li,.ah,span.lineno,span.lineno a,span.lineno a:hover,.note code,.pre code,.post code,.invariant code,.warning code,.attention code,.deprecated code,.bug code,.todo code,.test code,.doxtable code{background:none}#titlearea,.footer,.contents,div.header,.memdoc,table.doxtable td,table.doxtable th,hr,.memSeparator{border:none}.tablist a,.tablist a:visited,.tablist a:hover,.tablist li,.tablist li.current a,.reflist dt a.el,.levels span,.directory .levels span{text-shadow:none}.memdoc,dl.reflist dd{box-shadow:none}div.headertitle,.note code,.pre code,.post code,.invariant code,.warning code,.attention code,.deprecated code,.bug code,.todo code,.test code,table.doxtable code{padding:0}#nav-path,.directory .levels,span.lineno{display:none}html,#titlearea,.footer,tr.even,.directory tr.even,.doxtable tr:nth-child(even),.mdescLeft,.mdescRight,.memItemLeft,.memItemRight,code{background:#f2f2f2}body{color:#4d4d4d}h1,h2,h2.groupheader,h3,div.toc h3,h4,h5,h6,strong,em{color:#1a1a1a;border-bottom:none}h1{padding-top:0.5em;font-size:180%}h2{padding-top:0.5em;margin-bottom:0;font-size:140%}h3{padding-top:0.5em;margin-bottom:0;font-size:110%}.glfwheader{font-size:16px;height:64px;max-width:920px;min-width:800px;padding:0 32px;margin:0 auto}#glfwhome{line-height:64px;padding-right:48px;color:#666;font-size:2.5em;background:url("http://www.glfw.org/css/arrow.png") no-repeat right}.glfwnavbar{list-style-type:none;margin:0 auto;float:right}#glfwhome,.glfwnavbar li{float:left}.glfwnavbar a,.glfwnavbar a:visited{line-height:64px;margin-left:2em;display:block;color:#666}#glfwhome,.glfwnavbar a,.glfwnavbar a:visited{transition:.35s ease}#titlearea,.footer{color:#666}address.footer{text-align:center;padding:2em;margin-top:3em}#top{background:#666}#navrow1,#navrow2,#navrow3,#navrow4{max-width:920px;min-width:800px;margin:0 auto;font-size:13px}.tablist{height:36px;display:block;position:relative}.tablist a,.tablist a:visited,.tablist a:hover,.tablist li,.tablist li.current a{color:#f2f2f2}.tablist li.current a{background:linear-gradient(to bottom, #ffa733 0, #f60 100%);box-shadow:inset 0 0 32px #f60;text-shadow:0 -1px 1px #b34700;color:#fff}.contents{min-height:590px}div.contents,div.header{max-width:920px;margin:0 auto;padding:0 32px;background:#fff none}table.doxtable th,dl.reflist dt{background:linear-gradient(to bottom, #ffa733 0, #f60 100%);box-shadow:inset 0 0 32px #f60;text-shadow:0 -1px 1px #b34700;color:#fff}dl.reflist dt a.el{color:#f60;padding:.2em;border-radius:4px;background-color:#ffe0cc}div.toc{float:none;width:auto}div.toc h3{font-size:1.17em}div.toc ul{padding-left:1.5em}div.toc li{font-size:1em;padding-left:0;list-style-type:disc}div.toc,.memproto,div.qindex,div.ah{background:linear-gradient(to bottom, #f2f2f2 0, #e6e6e6 100%);box-shadow:inset 0 0 32px #e6e6e6;text-shadow:0 1px 1px #fff;color:#1a1a1a;border:2px solid #e6e6e6;border-radius:4px}.paramname{color:#803300}dl.reflist dt{border:2px solid #f60;border-top-left-radius:4px;border-top-right-radius:4px;border-bottom:none}dl.reflist dd{border:2px solid #f60;border-bottom-right-radius:4px;border-bottom-left-radius:4px;border-top:none}table.doxtable{border-collapse:inherit;border-spacing:0;border:2px solid #f60;border-radius:4px}a,a:hover,a:visited,a:visited:hover,.contents a:visited,.el,a.el:visited,#glfwhome:hover,.tablist a:hover,span.lineno a:hover{color:#f60;text-decoration:none}div.directory{border-collapse:inherit;border-spacing:0;border:2px solid #f60;border-radius:4px}hr,.memSeparator{height:2px;background:linear-gradient(to right, #f2f2f2 0, #d9d9d9 50%, #f2f2f2 100%)}dl.note,dl.pre,dl.post,dl.invariant{background:linear-gradient(to bottom, #ddfad1 0, #cbf7ba 100%);box-shadow:inset 0 0 32px #baf5a3;color:#1e5309;border:2px solid #afe599}dl.warning,dl.attention{background:linear-gradient(to bottom, #fae8d1 0, #f7ddba 100%);box-shadow:inset 0 0 32px #f5d1a3;color:#533309;border:2px solid #e5c499}dl.deprecated,dl.bug{background:linear-gradient(to bottom, #fad1e3 0, #f7bad6 100%);box-shadow:inset 0 0 32px #f5a3c8;color:#53092a;border:2px solid #e599bb}dl.todo,dl.test{background:linear-gradient(to bottom, #d1ecfa 0, #bae3f7 100%);box-shadow:inset 0 0 32px #a3daf5;color:#093a53;border:2px solid #99cce5}dl.note,dl.pre,dl.post,dl.invariant,dl.warning,dl.attention,dl.deprecated,dl.bug,dl.todo,dl.test{border-radius:4px;padding:1em;text-shadow:0 1px 1px #fff;margin:1em 0}.note a,.pre a,.post a,.invariant a,.warning a,.attention a,.deprecated a,.bug a,.todo a,.test a,.note a:visited,.pre a:visited,.post a:visited,.invariant a:visited,.warning a:visited,.attention a:visited,.deprecated a:visited,.bug a:visited,.todo a:visited,.test a:visited{color:inherit}div.line{line-height:inherit}div.fragment,pre.fragment{background:#f2f2f2;border-radius:4px;border:none;padding:1em;overflow:auto;border-left:4px solid #ccc;margin:1em 0}.lineno a,.lineno a:visited,.line,pre.fragment{color:#4d4d4d}span.preprocessor,span.comment{color:#007899}a.code,a.code:visited{color:#e64500}span.keyword,span.keywordtype,span.keywordflow{color:#404040;font-weight:bold}span.stringliteral{color:#360099}code{padding:.1em;border-radius:4px} 2 | -------------------------------------------------------------------------------- /tests/msaa.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Multisample anti-aliasing test 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test renders two high contrast, slowly rotating quads, one aliased 27 | // and one (hopefully) anti-aliased, thus allowing for visual verification 28 | // of whether MSAA is indeed enabled 29 | // 30 | //======================================================================== 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | #include "getopt.h" 39 | 40 | static void error_callback(int error, const char* description) 41 | { 42 | fprintf(stderr, "Error: %s\n", description); 43 | } 44 | 45 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 46 | { 47 | glViewport(0, 0, width, height); 48 | } 49 | 50 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 51 | { 52 | if (action != GLFW_PRESS) 53 | return; 54 | 55 | switch (key) 56 | { 57 | case GLFW_KEY_SPACE: 58 | glfwSetTime(0.0); 59 | break; 60 | } 61 | } 62 | 63 | static void usage(void) 64 | { 65 | printf("Usage: msaa [-h] [-s SAMPLES]\n"); 66 | } 67 | 68 | int main(int argc, char** argv) 69 | { 70 | int ch, samples = 4; 71 | GLFWwindow* window; 72 | 73 | while ((ch = getopt(argc, argv, "hs:")) != -1) 74 | { 75 | switch (ch) 76 | { 77 | case 'h': 78 | usage(); 79 | exit(EXIT_SUCCESS); 80 | case 's': 81 | samples = atoi(optarg); 82 | break; 83 | default: 84 | usage(); 85 | exit(EXIT_FAILURE); 86 | } 87 | } 88 | 89 | glfwSetErrorCallback(error_callback); 90 | 91 | if (!glfwInit()) 92 | exit(EXIT_FAILURE); 93 | 94 | if (samples) 95 | printf("Requesting MSAA with %i samples\n", samples); 96 | else 97 | printf("Requesting that MSAA not be available\n"); 98 | 99 | glfwWindowHint(GLFW_SAMPLES, samples); 100 | glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); 101 | 102 | window = glfwCreateWindow(800, 400, "Aliasing Detector", NULL, NULL); 103 | if (!window) 104 | { 105 | glfwTerminate(); 106 | exit(EXIT_FAILURE); 107 | } 108 | 109 | glfwSetKeyCallback(window, key_callback); 110 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 111 | 112 | glfwMakeContextCurrent(window); 113 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 114 | glfwSwapInterval(1); 115 | 116 | if (!GLAD_GL_ARB_multisample && !GLAD_GL_VERSION_1_3) 117 | { 118 | printf("Multisampling is not supported\n"); 119 | 120 | glfwTerminate(); 121 | exit(EXIT_FAILURE); 122 | } 123 | 124 | glfwShowWindow(window); 125 | 126 | glGetIntegerv(GL_SAMPLES, &samples); 127 | if (samples) 128 | printf("Context reports MSAA is available with %i samples\n", samples); 129 | else 130 | printf("Context reports MSAA is unavailable\n"); 131 | 132 | glMatrixMode(GL_PROJECTION); 133 | glOrtho(0.f, 1.f, 0.f, 0.5f, 0.f, 1.f); 134 | glMatrixMode(GL_MODELVIEW); 135 | 136 | while (!glfwWindowShouldClose(window)) 137 | { 138 | GLfloat time = (GLfloat) glfwGetTime(); 139 | 140 | glClear(GL_COLOR_BUFFER_BIT); 141 | 142 | glLoadIdentity(); 143 | glTranslatef(0.25f, 0.25f, 0.f); 144 | glRotatef(time, 0.f, 0.f, 1.f); 145 | 146 | glDisable(GL_MULTISAMPLE_ARB); 147 | glRectf(-0.15f, -0.15f, 0.15f, 0.15f); 148 | 149 | glLoadIdentity(); 150 | glTranslatef(0.75f, 0.25f, 0.f); 151 | glRotatef(time, 0.f, 0.f, 1.f); 152 | 153 | glEnable(GL_MULTISAMPLE_ARB); 154 | glRectf(-0.15f, -0.15f, 0.15f, 0.15f); 155 | 156 | glfwSwapBuffers(window); 157 | glfwPollEvents(); 158 | } 159 | 160 | glfwTerminate(); 161 | exit(EXIT_SUCCESS); 162 | } 163 | 164 | -------------------------------------------------------------------------------- /examples/simple.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Simple GLFW example 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | //! [code] 26 | 27 | #include 28 | #include 29 | 30 | #include "linmath.h" 31 | 32 | #include 33 | #include 34 | 35 | static const struct 36 | { 37 | float x, y; 38 | float r, g, b; 39 | } vertices[3] = 40 | { 41 | { -0.6f, -0.4f, 1.f, 0.f, 0.f }, 42 | { 0.6f, -0.4f, 0.f, 1.f, 0.f }, 43 | { 0.f, 0.6f, 0.f, 0.f, 1.f } 44 | }; 45 | 46 | static const char* vertex_shader_text = 47 | "uniform mat4 MVP;\n" 48 | "attribute vec3 vCol;\n" 49 | "attribute vec2 vPos;\n" 50 | "varying vec3 color;\n" 51 | "void main()\n" 52 | "{\n" 53 | " gl_Position = MVP * vec4(vPos, 0.0, 1.0);\n" 54 | " color = vCol;\n" 55 | "}\n"; 56 | 57 | static const char* fragment_shader_text = 58 | "varying vec3 color;\n" 59 | "void main()\n" 60 | "{\n" 61 | " gl_FragColor = vec4(color, 1.0);\n" 62 | "}\n"; 63 | 64 | static void error_callback(int error, const char* description) 65 | { 66 | fprintf(stderr, "Error: %s\n", description); 67 | } 68 | 69 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 70 | { 71 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 72 | glfwSetWindowShouldClose(window, GLFW_TRUE); 73 | } 74 | 75 | int main(void) 76 | { 77 | GLFWwindow* window; 78 | GLuint vertex_buffer, vertex_shader, fragment_shader, program; 79 | GLint mvp_location, vpos_location, vcol_location; 80 | 81 | glfwSetErrorCallback(error_callback); 82 | 83 | if (!glfwInit()) 84 | exit(EXIT_FAILURE); 85 | 86 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); 87 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 88 | 89 | window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL); 90 | if (!window) 91 | { 92 | glfwTerminate(); 93 | exit(EXIT_FAILURE); 94 | } 95 | 96 | glfwSetKeyCallback(window, key_callback); 97 | 98 | glfwMakeContextCurrent(window); 99 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 100 | glfwSwapInterval(1); 101 | 102 | // NOTE: OpenGL error checks have been omitted for brevity 103 | 104 | glGenBuffers(1, &vertex_buffer); 105 | glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); 106 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); 107 | 108 | vertex_shader = glCreateShader(GL_VERTEX_SHADER); 109 | glShaderSource(vertex_shader, 1, &vertex_shader_text, NULL); 110 | glCompileShader(vertex_shader); 111 | 112 | fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); 113 | glShaderSource(fragment_shader, 1, &fragment_shader_text, NULL); 114 | glCompileShader(fragment_shader); 115 | 116 | program = glCreateProgram(); 117 | glAttachShader(program, vertex_shader); 118 | glAttachShader(program, fragment_shader); 119 | glLinkProgram(program); 120 | 121 | mvp_location = glGetUniformLocation(program, "MVP"); 122 | vpos_location = glGetAttribLocation(program, "vPos"); 123 | vcol_location = glGetAttribLocation(program, "vCol"); 124 | 125 | glEnableVertexAttribArray(vpos_location); 126 | glVertexAttribPointer(vpos_location, 2, GL_FLOAT, GL_FALSE, 127 | sizeof(float) * 5, (void*) 0); 128 | glEnableVertexAttribArray(vcol_location); 129 | glVertexAttribPointer(vcol_location, 3, GL_FLOAT, GL_FALSE, 130 | sizeof(float) * 5, (void*) (sizeof(float) * 2)); 131 | 132 | while (!glfwWindowShouldClose(window)) 133 | { 134 | float ratio; 135 | int width, height; 136 | mat4x4 m, p, mvp; 137 | 138 | glfwGetFramebufferSize(window, &width, &height); 139 | ratio = width / (float) height; 140 | 141 | glViewport(0, 0, width, height); 142 | glClear(GL_COLOR_BUFFER_BIT); 143 | 144 | mat4x4_identity(m); 145 | mat4x4_rotate_Z(m, m, (float) glfwGetTime()); 146 | mat4x4_ortho(p, -ratio, ratio, -1.f, 1.f, 1.f, -1.f); 147 | mat4x4_mul(mvp, p, m); 148 | 149 | glUseProgram(program); 150 | glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat*) mvp); 151 | glDrawArrays(GL_TRIANGLES, 0, 3); 152 | 153 | glfwSwapBuffers(window); 154 | glfwPollEvents(); 155 | } 156 | 157 | glfwDestroyWindow(window); 158 | 159 | glfwTerminate(); 160 | exit(EXIT_SUCCESS); 161 | } 162 | 163 | //! [code] 164 | -------------------------------------------------------------------------------- /src/cocoa_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 OS X - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2016 Camilla Berglund 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #ifndef _glfw3_cocoa_platform_h_ 28 | #define _glfw3_cocoa_platform_h_ 29 | 30 | #include 31 | #include 32 | 33 | #if defined(__OBJC__) 34 | #import 35 | #import 36 | #else 37 | #include 38 | #include 39 | typedef void* id; 40 | #endif 41 | 42 | #include "posix_tls.h" 43 | #include "cocoa_joystick.h" 44 | #include "nsgl_context.h" 45 | 46 | #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) 47 | #define _glfw_dlclose(handle) dlclose(handle) 48 | #define _glfw_dlsym(handle, name) dlsym(handle, name) 49 | 50 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS ns 51 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns 52 | #define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimeNS ns_time 53 | #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorNS ns 54 | #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorNS ns 55 | 56 | #define _GLFW_EGL_CONTEXT_STATE 57 | #define _GLFW_EGL_LIBRARY_CONTEXT_STATE 58 | 59 | // HIToolbox.framework pointer typedefs 60 | #define kTISPropertyUnicodeKeyLayoutData _glfw.ns.tis.kPropertyUnicodeKeyLayoutData 61 | #define kTISNotifySelectedKeyboardInputSourceChanged _glfw.ns.tis.kNotifySelectedKeyboardInputSourceChanged 62 | typedef TISInputSourceRef (*PFN_TISCopyCurrentKeyboardLayoutInputSource)(void); 63 | #define TISCopyCurrentKeyboardLayoutInputSource _glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource 64 | typedef void* (*PFN_TISGetInputSourceProperty)(TISInputSourceRef,CFStringRef); 65 | #define TISGetInputSourceProperty _glfw.ns.tis.GetInputSourceProperty 66 | typedef UInt8 (*PFN_LMGetKbdType)(void); 67 | #define LMGetKbdType _glfw.ns.tis.GetKbdType 68 | 69 | 70 | // Cocoa-specific per-window data 71 | // 72 | typedef struct _GLFWwindowNS 73 | { 74 | id object; 75 | id delegate; 76 | id view; 77 | 78 | // The total sum of the distances the cursor has been warped 79 | // since the last cursor motion event was processed 80 | // This is kept to counteract Cocoa doing the same internally 81 | double cursorWarpDeltaX, cursorWarpDeltaY; 82 | 83 | } _GLFWwindowNS; 84 | 85 | // Cocoa-specific global data 86 | // 87 | typedef struct _GLFWlibraryNS 88 | { 89 | CGEventSourceRef eventSource; 90 | id delegate; 91 | id autoreleasePool; 92 | id cursor; 93 | TISInputSourceRef inputSource; 94 | IOHIDManagerRef hidManager; 95 | id unicodeData; 96 | id listener; 97 | 98 | char keyName[64]; 99 | short int publicKeys[256]; 100 | short int nativeKeys[GLFW_KEY_LAST + 1]; 101 | char* clipboardString; 102 | // Where to place the cursor when re-enabled 103 | double restoreCursorPosX, restoreCursorPosY; 104 | // The window whose disabled cursor mode is active 105 | _GLFWwindow* disabledCursorWindow; 106 | 107 | struct { 108 | CFBundleRef bundle; 109 | PFN_TISCopyCurrentKeyboardLayoutInputSource CopyCurrentKeyboardLayoutInputSource; 110 | PFN_TISGetInputSourceProperty GetInputSourceProperty; 111 | PFN_LMGetKbdType GetKbdType; 112 | CFStringRef kPropertyUnicodeKeyLayoutData; 113 | CFStringRef kNotifySelectedKeyboardInputSourceChanged; 114 | } tis; 115 | 116 | } _GLFWlibraryNS; 117 | 118 | // Cocoa-specific per-monitor data 119 | // 120 | typedef struct _GLFWmonitorNS 121 | { 122 | CGDirectDisplayID displayID; 123 | CGDisplayModeRef previousMode; 124 | uint32_t unitNumber; 125 | 126 | } _GLFWmonitorNS; 127 | 128 | // Cocoa-specific per-cursor data 129 | // 130 | typedef struct _GLFWcursorNS 131 | { 132 | id object; 133 | 134 | } _GLFWcursorNS; 135 | 136 | // Cocoa-specific global timer data 137 | // 138 | typedef struct _GLFWtimeNS 139 | { 140 | uint64_t frequency; 141 | 142 | } _GLFWtimeNS; 143 | 144 | 145 | void _glfwInitTimerNS(void); 146 | 147 | GLFWbool _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired); 148 | void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor); 149 | 150 | #endif // _glfw3_cocoa_platform_h_ 151 | -------------------------------------------------------------------------------- /tests/gamma.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Gamma correction test program 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This program is used to test the gamma correction functionality for 27 | // both full screen and windowed mode windows 28 | // 29 | //======================================================================== 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | #include "getopt.h" 38 | 39 | #define STEP_SIZE 0.1f 40 | 41 | static GLfloat gamma_value = 1.0f; 42 | 43 | static void usage(void) 44 | { 45 | printf("Usage: gamma [-h] [-f]\n"); 46 | printf("Options:\n"); 47 | printf(" -f create full screen window\n"); 48 | printf(" -h show this help\n"); 49 | } 50 | 51 | static void set_gamma(GLFWwindow* window, float value) 52 | { 53 | GLFWmonitor* monitor = glfwGetWindowMonitor(window); 54 | if (!monitor) 55 | monitor = glfwGetPrimaryMonitor(); 56 | 57 | gamma_value = value; 58 | printf("Gamma: %f\n", gamma_value); 59 | glfwSetGamma(monitor, gamma_value); 60 | } 61 | 62 | static void error_callback(int error, const char* description) 63 | { 64 | fprintf(stderr, "Error: %s\n", description); 65 | } 66 | 67 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 68 | { 69 | if (action != GLFW_PRESS) 70 | return; 71 | 72 | switch (key) 73 | { 74 | case GLFW_KEY_ESCAPE: 75 | { 76 | glfwSetWindowShouldClose(window, GLFW_TRUE); 77 | break; 78 | } 79 | 80 | case GLFW_KEY_KP_ADD: 81 | case GLFW_KEY_UP: 82 | case GLFW_KEY_Q: 83 | { 84 | set_gamma(window, gamma_value + STEP_SIZE); 85 | break; 86 | } 87 | 88 | case GLFW_KEY_KP_SUBTRACT: 89 | case GLFW_KEY_DOWN: 90 | case GLFW_KEY_W: 91 | { 92 | if (gamma_value - STEP_SIZE > 0.f) 93 | set_gamma(window, gamma_value - STEP_SIZE); 94 | 95 | break; 96 | } 97 | } 98 | } 99 | 100 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 101 | { 102 | glViewport(0, 0, width, height); 103 | } 104 | 105 | int main(int argc, char** argv) 106 | { 107 | int width, height, ch; 108 | GLFWmonitor* monitor = NULL; 109 | GLFWwindow* window; 110 | 111 | glfwSetErrorCallback(error_callback); 112 | 113 | if (!glfwInit()) 114 | exit(EXIT_FAILURE); 115 | 116 | while ((ch = getopt(argc, argv, "fh")) != -1) 117 | { 118 | switch (ch) 119 | { 120 | case 'h': 121 | usage(); 122 | exit(EXIT_SUCCESS); 123 | 124 | case 'f': 125 | monitor = glfwGetPrimaryMonitor(); 126 | break; 127 | 128 | default: 129 | usage(); 130 | exit(EXIT_FAILURE); 131 | } 132 | } 133 | 134 | if (monitor) 135 | { 136 | const GLFWvidmode* mode = glfwGetVideoMode(monitor); 137 | 138 | glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); 139 | glfwWindowHint(GLFW_RED_BITS, mode->redBits); 140 | glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); 141 | glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); 142 | 143 | width = mode->width; 144 | height = mode->height; 145 | } 146 | else 147 | { 148 | width = 200; 149 | height = 200; 150 | } 151 | 152 | window = glfwCreateWindow(width, height, "Gamma Test", monitor, NULL); 153 | if (!window) 154 | { 155 | glfwTerminate(); 156 | exit(EXIT_FAILURE); 157 | } 158 | 159 | set_gamma(window, 1.f); 160 | 161 | glfwMakeContextCurrent(window); 162 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 163 | glfwSwapInterval(1); 164 | 165 | glfwSetKeyCallback(window, key_callback); 166 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 167 | 168 | glMatrixMode(GL_PROJECTION); 169 | glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f); 170 | glMatrixMode(GL_MODELVIEW); 171 | 172 | glClearColor(0.5f, 0.5f, 0.5f, 0); 173 | 174 | while (!glfwWindowShouldClose(window)) 175 | { 176 | glClear(GL_COLOR_BUFFER_BIT); 177 | 178 | glColor3f(0.8f, 0.2f, 0.4f); 179 | glRectf(-0.5f, -0.5f, 0.5f, 0.5f); 180 | 181 | glfwSwapBuffers(window); 182 | glfwWaitEvents(); 183 | } 184 | 185 | glfwTerminate(); 186 | exit(EXIT_SUCCESS); 187 | } 188 | 189 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(common_HEADERS internal.h 3 | "${GLFW_BINARY_DIR}/src/glfw_config.h" 4 | "${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h" 5 | "${GLFW_SOURCE_DIR}/include/GLFW/glfw3native.h") 6 | set(common_SOURCES context.c init.c input.c monitor.c vulkan.c window.c) 7 | 8 | if (_GLFW_COCOA) 9 | set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h cocoa_joystick.h 10 | posix_tls.h nsgl_context.h) 11 | set(glfw_SOURCES ${common_SOURCES} cocoa_init.m cocoa_joystick.m 12 | cocoa_monitor.m cocoa_window.m cocoa_time.c posix_tls.c 13 | nsgl_context.m) 14 | elseif (_GLFW_WIN32) 15 | set(glfw_HEADERS ${common_HEADERS} win32_platform.h win32_joystick.h 16 | wgl_context.h egl_context.h) 17 | set(glfw_SOURCES ${common_SOURCES} win32_init.c win32_joystick.c 18 | win32_monitor.c win32_time.c win32_tls.c win32_window.c 19 | wgl_context.c egl_context.c) 20 | elseif (_GLFW_X11) 21 | set(glfw_HEADERS ${common_HEADERS} x11_platform.h xkb_unicode.h 22 | linux_joystick.h posix_time.h posix_tls.h glx_context.h 23 | egl_context.h) 24 | set(glfw_SOURCES ${common_SOURCES} x11_init.c x11_monitor.c x11_window.c 25 | xkb_unicode.c linux_joystick.c posix_time.c posix_tls.c 26 | glx_context.c egl_context.c) 27 | elseif (_GLFW_WAYLAND) 28 | set(glfw_HEADERS ${common_HEADERS} wl_platform.h linux_joystick.h 29 | posix_time.h posix_tls.h xkb_unicode.h egl_context.h) 30 | set(glfw_SOURCES ${common_SOURCES} wl_init.c wl_monitor.c wl_window.c 31 | linux_joystick.c posix_time.c posix_tls.c xkb_unicode.c 32 | egl_context.c) 33 | 34 | ecm_add_wayland_client_protocol(glfw_SOURCES 35 | PROTOCOL 36 | ${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/relative-pointer/relative-pointer-unstable-v1.xml 37 | BASENAME relative-pointer-unstable-v1) 38 | ecm_add_wayland_client_protocol(glfw_SOURCES 39 | PROTOCOL 40 | ${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml 41 | BASENAME pointer-constraints-unstable-v1) 42 | elseif (_GLFW_MIR) 43 | set(glfw_HEADERS ${common_HEADERS} mir_platform.h linux_joystick.h 44 | posix_time.h posix_tls.h xkb_unicode.h egl_context.h) 45 | set(glfw_SOURCES ${common_SOURCES} mir_init.c mir_monitor.c mir_window.c 46 | linux_joystick.c posix_time.c posix_tls.c xkb_unicode.c 47 | egl_context.c) 48 | endif() 49 | 50 | if (APPLE) 51 | # For some reason, CMake doesn't know about .m 52 | set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C) 53 | endif() 54 | 55 | add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) 56 | set_target_properties(glfw PROPERTIES 57 | OUTPUT_NAME ${GLFW_LIB_NAME} 58 | VERSION ${GLFW_VERSION} 59 | SOVERSION ${GLFW_VERSION_MAJOR} 60 | POSITION_INDEPENDENT_CODE ON 61 | FOLDER "GLFW3") 62 | 63 | target_compile_definitions(glfw PRIVATE -D_GLFW_USE_CONFIG_H) 64 | target_include_directories(glfw PUBLIC 65 | $ 66 | $/include>) 67 | target_include_directories(glfw PRIVATE 68 | "${GLFW_SOURCE_DIR}/src" 69 | "${GLFW_BINARY_DIR}/src" 70 | ${glfw_INCLUDE_DIRS}) 71 | 72 | # HACK: When building on MinGW, WINVER and UNICODE need to be defined before 73 | # the inclusion of stddef.h (by glfw3.h), which is itself included before 74 | # win32_platform.h. We define them here until a saner solution can be found 75 | # NOTE: MinGW-w64 and Visual C++ do /not/ need this hack. 76 | target_compile_definitions(glfw PRIVATE 77 | "$<$:UNICODE;WINVER=0x0501>") 78 | 79 | # Enable a reasonable set of warnings (no, -Wextra is not reasonable) 80 | target_compile_options(glfw PRIVATE 81 | "$<$:-Wall>" 82 | "$<$:-Wall>") 83 | 84 | if (BUILD_SHARED_LIBS) 85 | if (WIN32) 86 | if (MINGW) 87 | # Remove the lib prefix on the DLL (but not the import library 88 | set_target_properties(glfw PROPERTIES PREFIX "") 89 | 90 | # Add a suffix to the import library to avoid naming conflicts 91 | set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.a") 92 | else() 93 | # Add a suffix to the import library to avoid naming conflicts 94 | set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib") 95 | endif() 96 | elseif (APPLE) 97 | # Add -fno-common to work around a bug in Apple's GCC 98 | target_compile_options(glfw PRIVATE "-fno-common") 99 | 100 | set_target_properties(glfw PROPERTIES 101 | INSTALL_NAME_DIR "lib${LIB_SUFFIX}") 102 | elseif (UNIX) 103 | # Hide symbols not explicitly tagged for export from the shared library 104 | target_compile_options(glfw PRIVATE "-fvisibility=hidden") 105 | endif() 106 | 107 | target_compile_definitions(glfw INTERFACE -DGLFW_DLL) 108 | target_link_libraries(glfw PRIVATE ${glfw_LIBRARIES}) 109 | else() 110 | target_link_libraries(glfw INTERFACE ${glfw_LIBRARIES}) 111 | endif() 112 | 113 | if (MSVC) 114 | target_compile_definitions(glfw PRIVATE _CRT_SECURE_NO_WARNINGS) 115 | endif() 116 | 117 | if (GLFW_INSTALL) 118 | install(TARGETS glfw EXPORT glfwTargets DESTINATION lib${LIB_SUFFIX}) 119 | endif() 120 | 121 | -------------------------------------------------------------------------------- /tests/sharing.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Context sharing test program 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This program is used to test sharing of objects between contexts 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | #define WIDTH 400 37 | #define HEIGHT 400 38 | #define OFFSET 50 39 | 40 | static GLFWwindow* windows[2]; 41 | 42 | static void error_callback(int error, const char* description) 43 | { 44 | fprintf(stderr, "Error: %s\n", description); 45 | } 46 | 47 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 48 | { 49 | if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE) 50 | glfwSetWindowShouldClose(window, GLFW_TRUE); 51 | } 52 | 53 | static GLFWwindow* open_window(const char* title, GLFWwindow* share, int posX, int posY) 54 | { 55 | GLFWwindow* window; 56 | 57 | glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); 58 | window = glfwCreateWindow(WIDTH, HEIGHT, title, NULL, share); 59 | if (!window) 60 | return NULL; 61 | 62 | glfwMakeContextCurrent(window); 63 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 64 | glfwSwapInterval(1); 65 | glfwSetWindowPos(window, posX, posY); 66 | glfwShowWindow(window); 67 | 68 | glfwSetKeyCallback(window, key_callback); 69 | 70 | return window; 71 | } 72 | 73 | static GLuint create_texture(void) 74 | { 75 | int x, y; 76 | char pixels[256 * 256]; 77 | GLuint texture; 78 | 79 | glGenTextures(1, &texture); 80 | glBindTexture(GL_TEXTURE_2D, texture); 81 | 82 | for (y = 0; y < 256; y++) 83 | { 84 | for (x = 0; x < 256; x++) 85 | pixels[y * 256 + x] = rand() % 256; 86 | } 87 | 88 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 256, 256, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels); 89 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 90 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 91 | 92 | return texture; 93 | } 94 | 95 | static void draw_quad(GLuint texture) 96 | { 97 | int width, height; 98 | glfwGetFramebufferSize(glfwGetCurrentContext(), &width, &height); 99 | 100 | glViewport(0, 0, width, height); 101 | 102 | glMatrixMode(GL_PROJECTION); 103 | glLoadIdentity(); 104 | glOrtho(0.f, 1.f, 0.f, 1.f, 0.f, 1.f); 105 | 106 | glEnable(GL_TEXTURE_2D); 107 | glBindTexture(GL_TEXTURE_2D, texture); 108 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 109 | 110 | glBegin(GL_QUADS); 111 | 112 | glTexCoord2f(0.f, 0.f); 113 | glVertex2f(0.f, 0.f); 114 | 115 | glTexCoord2f(1.f, 0.f); 116 | glVertex2f(1.f, 0.f); 117 | 118 | glTexCoord2f(1.f, 1.f); 119 | glVertex2f(1.f, 1.f); 120 | 121 | glTexCoord2f(0.f, 1.f); 122 | glVertex2f(0.f, 1.f); 123 | 124 | glEnd(); 125 | } 126 | 127 | int main(int argc, char** argv) 128 | { 129 | int x, y, width; 130 | GLuint texture; 131 | 132 | glfwSetErrorCallback(error_callback); 133 | 134 | if (!glfwInit()) 135 | exit(EXIT_FAILURE); 136 | 137 | windows[0] = open_window("First", NULL, OFFSET, OFFSET); 138 | if (!windows[0]) 139 | { 140 | glfwTerminate(); 141 | exit(EXIT_FAILURE); 142 | } 143 | 144 | // This is the one and only time we create a texture 145 | // It is created inside the first context, created above 146 | // It will then be shared with the second context, created below 147 | texture = create_texture(); 148 | 149 | glfwGetWindowPos(windows[0], &x, &y); 150 | glfwGetWindowSize(windows[0], &width, NULL); 151 | 152 | // Put the second window to the right of the first one 153 | windows[1] = open_window("Second", windows[0], x + width + OFFSET, y); 154 | if (!windows[1]) 155 | { 156 | glfwTerminate(); 157 | exit(EXIT_FAILURE); 158 | } 159 | 160 | // Set drawing color for both contexts 161 | glfwMakeContextCurrent(windows[0]); 162 | glColor3f(0.6f, 0.f, 0.6f); 163 | glfwMakeContextCurrent(windows[1]); 164 | glColor3f(0.6f, 0.6f, 0.f); 165 | 166 | glfwMakeContextCurrent(windows[0]); 167 | 168 | while (!glfwWindowShouldClose(windows[0]) && 169 | !glfwWindowShouldClose(windows[1])) 170 | { 171 | glfwMakeContextCurrent(windows[0]); 172 | draw_quad(texture); 173 | 174 | glfwMakeContextCurrent(windows[1]); 175 | draw_quad(texture); 176 | 177 | glfwSwapBuffers(windows[0]); 178 | glfwSwapBuffers(windows[1]); 179 | 180 | glfwWaitEvents(); 181 | } 182 | 183 | glfwTerminate(); 184 | exit(EXIT_SUCCESS); 185 | } 186 | 187 | -------------------------------------------------------------------------------- /tests/reopen.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Window re-opener (open/close stress test) 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test came about as the result of bug #1262773 27 | // 28 | // It closes and re-opens the GLFW window every five seconds, alternating 29 | // between windowed and full screen mode 30 | // 31 | // It also times and logs opening and closing actions and attempts to separate 32 | // user initiated window closing from its own 33 | // 34 | //======================================================================== 35 | 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | static void error_callback(int error, const char* description) 44 | { 45 | fprintf(stderr, "Error: %s\n", description); 46 | } 47 | 48 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 49 | { 50 | glViewport(0, 0, width, height); 51 | } 52 | 53 | static void window_close_callback(GLFWwindow* window) 54 | { 55 | printf("Close callback triggered\n"); 56 | } 57 | 58 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 59 | { 60 | if (action != GLFW_PRESS) 61 | return; 62 | 63 | switch (key) 64 | { 65 | case GLFW_KEY_Q: 66 | case GLFW_KEY_ESCAPE: 67 | glfwSetWindowShouldClose(window, GLFW_TRUE); 68 | break; 69 | } 70 | } 71 | 72 | static GLFWwindow* open_window(int width, int height, GLFWmonitor* monitor) 73 | { 74 | double base; 75 | GLFWwindow* window; 76 | 77 | base = glfwGetTime(); 78 | 79 | window = glfwCreateWindow(width, height, "Window Re-opener", monitor, NULL); 80 | if (!window) 81 | return NULL; 82 | 83 | glfwMakeContextCurrent(window); 84 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 85 | glfwSwapInterval(1); 86 | 87 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 88 | glfwSetWindowCloseCallback(window, window_close_callback); 89 | glfwSetKeyCallback(window, key_callback); 90 | 91 | if (monitor) 92 | { 93 | printf("Opening full screen window on monitor %s took %0.3f seconds\n", 94 | glfwGetMonitorName(monitor), 95 | glfwGetTime() - base); 96 | } 97 | else 98 | { 99 | printf("Opening regular window took %0.3f seconds\n", 100 | glfwGetTime() - base); 101 | } 102 | 103 | return window; 104 | } 105 | 106 | static void close_window(GLFWwindow* window) 107 | { 108 | double base = glfwGetTime(); 109 | glfwDestroyWindow(window); 110 | printf("Closing window took %0.3f seconds\n", glfwGetTime() - base); 111 | } 112 | 113 | int main(int argc, char** argv) 114 | { 115 | int count = 0; 116 | GLFWwindow* window; 117 | 118 | srand((unsigned int) time(NULL)); 119 | 120 | glfwSetErrorCallback(error_callback); 121 | 122 | if (!glfwInit()) 123 | exit(EXIT_FAILURE); 124 | 125 | for (;;) 126 | { 127 | int width, height; 128 | GLFWmonitor* monitor = NULL; 129 | 130 | if (count % 2 == 0) 131 | { 132 | int monitorCount; 133 | GLFWmonitor** monitors = glfwGetMonitors(&monitorCount); 134 | monitor = monitors[rand() % monitorCount]; 135 | } 136 | 137 | if (monitor) 138 | { 139 | const GLFWvidmode* mode = glfwGetVideoMode(monitor); 140 | width = mode->width; 141 | height = mode->height; 142 | } 143 | else 144 | { 145 | width = 640; 146 | height = 480; 147 | } 148 | 149 | window = open_window(width, height, monitor); 150 | if (!window) 151 | { 152 | glfwTerminate(); 153 | exit(EXIT_FAILURE); 154 | } 155 | 156 | glMatrixMode(GL_PROJECTION); 157 | glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f); 158 | glMatrixMode(GL_MODELVIEW); 159 | 160 | glfwSetTime(0.0); 161 | 162 | while (glfwGetTime() < 5.0) 163 | { 164 | glClear(GL_COLOR_BUFFER_BIT); 165 | 166 | glPushMatrix(); 167 | glRotatef((GLfloat) glfwGetTime() * 100.f, 0.f, 0.f, 1.f); 168 | glRectf(-0.5f, -0.5f, 1.f, 1.f); 169 | glPopMatrix(); 170 | 171 | glfwSwapBuffers(window); 172 | glfwPollEvents(); 173 | 174 | if (glfwWindowShouldClose(window)) 175 | { 176 | close_window(window); 177 | printf("User closed window\n"); 178 | 179 | glfwTerminate(); 180 | exit(EXIT_SUCCESS); 181 | } 182 | } 183 | 184 | printf("Closing window\n"); 185 | close_window(window); 186 | 187 | count++; 188 | } 189 | 190 | glfwTerminate(); 191 | } 192 | 193 | -------------------------------------------------------------------------------- /src/init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | 36 | // The three global variables below comprise all global data in GLFW. 37 | // Any other global variable is a bug. 38 | 39 | // Global state shared between compilation units of GLFW 40 | // These are documented in internal.h 41 | // 42 | GLFWbool _glfwInitialized = GLFW_FALSE; 43 | _GLFWlibrary _glfw; 44 | 45 | // This is outside of _glfw so it can be initialized and usable before 46 | // glfwInit is called, which lets that function report errors 47 | // 48 | static GLFWerrorfun _glfwErrorCallback = NULL; 49 | 50 | 51 | // Returns a generic string representation of the specified error 52 | // 53 | static const char* getErrorString(int error) 54 | { 55 | switch (error) 56 | { 57 | case GLFW_NOT_INITIALIZED: 58 | return "The GLFW library is not initialized"; 59 | case GLFW_NO_CURRENT_CONTEXT: 60 | return "There is no current context"; 61 | case GLFW_INVALID_ENUM: 62 | return "Invalid argument for enum parameter"; 63 | case GLFW_INVALID_VALUE: 64 | return "Invalid value for parameter"; 65 | case GLFW_OUT_OF_MEMORY: 66 | return "Out of memory"; 67 | case GLFW_API_UNAVAILABLE: 68 | return "The requested API is unavailable"; 69 | case GLFW_VERSION_UNAVAILABLE: 70 | return "The requested API version is unavailable"; 71 | case GLFW_PLATFORM_ERROR: 72 | return "A platform-specific error occurred"; 73 | case GLFW_FORMAT_UNAVAILABLE: 74 | return "The requested format is unavailable"; 75 | case GLFW_NO_WINDOW_CONTEXT: 76 | return "The specified window has no context"; 77 | default: 78 | return "ERROR: UNKNOWN GLFW ERROR"; 79 | } 80 | } 81 | 82 | 83 | ////////////////////////////////////////////////////////////////////////// 84 | ////// GLFW event API ////// 85 | ////////////////////////////////////////////////////////////////////////// 86 | 87 | void _glfwInputError(int error, const char* format, ...) 88 | { 89 | if (_glfwErrorCallback) 90 | { 91 | char buffer[8192]; 92 | const char* description; 93 | 94 | if (format) 95 | { 96 | int count; 97 | va_list vl; 98 | 99 | va_start(vl, format); 100 | count = vsnprintf(buffer, sizeof(buffer), format, vl); 101 | va_end(vl); 102 | 103 | if (count < 0) 104 | buffer[sizeof(buffer) - 1] = '\0'; 105 | 106 | description = buffer; 107 | } 108 | else 109 | description = getErrorString(error); 110 | 111 | _glfwErrorCallback(error, description); 112 | } 113 | } 114 | 115 | 116 | ////////////////////////////////////////////////////////////////////////// 117 | ////// GLFW public API ////// 118 | ////////////////////////////////////////////////////////////////////////// 119 | 120 | GLFWAPI int glfwInit(void) 121 | { 122 | if (_glfwInitialized) 123 | return GLFW_TRUE; 124 | 125 | memset(&_glfw, 0, sizeof(_glfw)); 126 | 127 | if (!_glfwPlatformInit()) 128 | { 129 | _glfwPlatformTerminate(); 130 | return GLFW_FALSE; 131 | } 132 | 133 | _glfw.monitors = _glfwPlatformGetMonitors(&_glfw.monitorCount); 134 | _glfwInitialized = GLFW_TRUE; 135 | 136 | _glfw.timerOffset = _glfwPlatformGetTimerValue(); 137 | 138 | // Not all window hints have zero as their default value 139 | glfwDefaultWindowHints(); 140 | 141 | return GLFW_TRUE; 142 | } 143 | 144 | GLFWAPI void glfwTerminate(void) 145 | { 146 | int i; 147 | 148 | if (!_glfwInitialized) 149 | return; 150 | 151 | memset(&_glfw.callbacks, 0, sizeof(_glfw.callbacks)); 152 | 153 | while (_glfw.windowListHead) 154 | glfwDestroyWindow((GLFWwindow*) _glfw.windowListHead); 155 | 156 | while (_glfw.cursorListHead) 157 | glfwDestroyCursor((GLFWcursor*) _glfw.cursorListHead); 158 | 159 | for (i = 0; i < _glfw.monitorCount; i++) 160 | { 161 | _GLFWmonitor* monitor = _glfw.monitors[i]; 162 | if (monitor->originalRamp.size) 163 | _glfwPlatformSetGammaRamp(monitor, &monitor->originalRamp); 164 | } 165 | 166 | _glfwTerminateVulkan(); 167 | 168 | _glfwFreeMonitors(_glfw.monitors, _glfw.monitorCount); 169 | _glfw.monitors = NULL; 170 | _glfw.monitorCount = 0; 171 | 172 | _glfwPlatformTerminate(); 173 | 174 | memset(&_glfw, 0, sizeof(_glfw)); 175 | _glfwInitialized = GLFW_FALSE; 176 | } 177 | 178 | GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev) 179 | { 180 | if (major != NULL) 181 | *major = GLFW_VERSION_MAJOR; 182 | 183 | if (minor != NULL) 184 | *minor = GLFW_VERSION_MINOR; 185 | 186 | if (rev != NULL) 187 | *rev = GLFW_VERSION_REVISION; 188 | } 189 | 190 | GLFWAPI const char* glfwGetVersionString(void) 191 | { 192 | return _glfwPlatformGetVersionString(); 193 | } 194 | 195 | GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun) 196 | { 197 | _GLFW_SWAP_POINTERS(_glfwErrorCallback, cbfun); 198 | return cbfun; 199 | } 200 | 201 | -------------------------------------------------------------------------------- /tests/tearing.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Vsync enabling test 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test renders a high contrast, horizontally moving bar, allowing for 27 | // visual verification of whether the set swap interval is indeed obeyed 28 | // 29 | //======================================================================== 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include "getopt.h" 39 | 40 | static int swap_tear; 41 | static int swap_interval; 42 | static double frame_rate; 43 | 44 | static void usage(void) 45 | { 46 | printf("Usage: tearing [-h] [-f]\n"); 47 | printf("Options:\n"); 48 | printf(" -f create full screen window\n"); 49 | printf(" -h show this help\n"); 50 | } 51 | 52 | static void update_window_title(GLFWwindow* window) 53 | { 54 | char title[256]; 55 | 56 | sprintf(title, "Tearing detector (interval %i%s, %0.1f Hz)", 57 | swap_interval, 58 | (swap_tear && swap_interval < 0) ? " (swap tear)" : "", 59 | frame_rate); 60 | 61 | glfwSetWindowTitle(window, title); 62 | } 63 | 64 | static void set_swap_interval(GLFWwindow* window, int interval) 65 | { 66 | swap_interval = interval; 67 | glfwSwapInterval(swap_interval); 68 | update_window_title(window); 69 | } 70 | 71 | static void error_callback(int error, const char* description) 72 | { 73 | fprintf(stderr, "Error: %s\n", description); 74 | } 75 | 76 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 77 | { 78 | glViewport(0, 0, width, height); 79 | } 80 | 81 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 82 | { 83 | if (action != GLFW_PRESS) 84 | return; 85 | 86 | switch (key) 87 | { 88 | case GLFW_KEY_UP: 89 | { 90 | if (swap_interval + 1 > swap_interval) 91 | set_swap_interval(window, swap_interval + 1); 92 | break; 93 | } 94 | 95 | case GLFW_KEY_DOWN: 96 | { 97 | if (swap_tear) 98 | { 99 | if (swap_interval - 1 < swap_interval) 100 | set_swap_interval(window, swap_interval - 1); 101 | } 102 | else 103 | { 104 | if (swap_interval - 1 >= 0) 105 | set_swap_interval(window, swap_interval - 1); 106 | } 107 | break; 108 | } 109 | 110 | case GLFW_KEY_ESCAPE: 111 | glfwSetWindowShouldClose(window, 1); 112 | break; 113 | } 114 | } 115 | 116 | int main(int argc, char** argv) 117 | { 118 | int ch, width, height; 119 | float position; 120 | unsigned long frame_count = 0; 121 | double last_time, current_time; 122 | int fullscreen = GLFW_FALSE; 123 | GLFWmonitor* monitor = NULL; 124 | GLFWwindow* window; 125 | 126 | while ((ch = getopt(argc, argv, "fh")) != -1) 127 | { 128 | switch (ch) 129 | { 130 | case 'h': 131 | usage(); 132 | exit(EXIT_SUCCESS); 133 | 134 | case 'f': 135 | fullscreen = GLFW_TRUE; 136 | break; 137 | } 138 | } 139 | 140 | glfwSetErrorCallback(error_callback); 141 | 142 | if (!glfwInit()) 143 | exit(EXIT_FAILURE); 144 | 145 | if (fullscreen) 146 | { 147 | const GLFWvidmode* mode; 148 | 149 | monitor = glfwGetPrimaryMonitor(); 150 | mode = glfwGetVideoMode(monitor); 151 | 152 | glfwWindowHint(GLFW_RED_BITS, mode->redBits); 153 | glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); 154 | glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); 155 | glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); 156 | 157 | width = mode->width; 158 | height = mode->height; 159 | } 160 | else 161 | { 162 | width = 640; 163 | height = 480; 164 | } 165 | 166 | window = glfwCreateWindow(width, height, "", monitor, NULL); 167 | if (!window) 168 | { 169 | glfwTerminate(); 170 | exit(EXIT_FAILURE); 171 | } 172 | 173 | glfwMakeContextCurrent(window); 174 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 175 | set_swap_interval(window, 0); 176 | 177 | last_time = glfwGetTime(); 178 | frame_rate = 0.0; 179 | swap_tear = (glfwExtensionSupported("WGL_EXT_swap_control_tear") || 180 | glfwExtensionSupported("GLX_EXT_swap_control_tear")); 181 | 182 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 183 | glfwSetKeyCallback(window, key_callback); 184 | 185 | glMatrixMode(GL_PROJECTION); 186 | glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f); 187 | glMatrixMode(GL_MODELVIEW); 188 | 189 | while (!glfwWindowShouldClose(window)) 190 | { 191 | glClear(GL_COLOR_BUFFER_BIT); 192 | 193 | position = cosf((float) glfwGetTime() * 4.f) * 0.75f; 194 | glRectf(position - 0.25f, -1.f, position + 0.25f, 1.f); 195 | 196 | glfwSwapBuffers(window); 197 | glfwPollEvents(); 198 | 199 | frame_count++; 200 | 201 | current_time = glfwGetTime(); 202 | if (current_time - last_time > 1.0) 203 | { 204 | frame_rate = frame_count / (current_time - last_time); 205 | frame_count = 0; 206 | last_time = current_time; 207 | update_window_title(window); 208 | } 209 | } 210 | 211 | glfwTerminate(); 212 | exit(EXIT_SUCCESS); 213 | } 214 | 215 | -------------------------------------------------------------------------------- /src/mir_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Mir - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014-2015 Brandon Schaefer 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include "internal.h" 28 | 29 | #include 30 | 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | ////// GLFW platform API ////// 34 | ////////////////////////////////////////////////////////////////////////// 35 | 36 | _GLFWmonitor** _glfwPlatformGetMonitors(int* count) 37 | { 38 | int i, found = 0; 39 | _GLFWmonitor** monitors = NULL; 40 | MirDisplayConfiguration* displayConfig = 41 | mir_connection_create_display_config(_glfw.mir.connection); 42 | 43 | *count = 0; 44 | 45 | for (i = 0; i < displayConfig->num_outputs; i++) 46 | { 47 | const MirDisplayOutput* out = displayConfig->outputs + i; 48 | 49 | if (out->used && 50 | out->connected && 51 | out->num_modes && 52 | out->current_mode < out->num_modes) 53 | { 54 | found++; 55 | monitors = realloc(monitors, sizeof(_GLFWmonitor*) * found); 56 | monitors[i] = _glfwAllocMonitor("Unknown", 57 | out->physical_width_mm, 58 | out->physical_height_mm); 59 | 60 | monitors[i]->mir.x = out->position_x; 61 | monitors[i]->mir.y = out->position_y; 62 | monitors[i]->mir.output_id = out->output_id; 63 | monitors[i]->mir.cur_mode = out->current_mode; 64 | 65 | monitors[i]->modes = _glfwPlatformGetVideoModes(monitors[i], 66 | &monitors[i]->modeCount); 67 | } 68 | } 69 | 70 | mir_display_config_destroy(displayConfig); 71 | 72 | *count = found; 73 | return monitors; 74 | } 75 | 76 | GLFWbool _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second) 77 | { 78 | return first->mir.output_id == second->mir.output_id; 79 | } 80 | 81 | void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) 82 | { 83 | if (xpos) 84 | *xpos = monitor->mir.x; 85 | if (ypos) 86 | *ypos = monitor->mir.y; 87 | } 88 | 89 | void FillInRGBBitsFromPixelFormat(GLFWvidmode* mode, const MirPixelFormat pf) 90 | { 91 | switch (pf) 92 | { 93 | case mir_pixel_format_rgb_565: 94 | mode->redBits = 5; 95 | mode->greenBits = 6; 96 | mode->blueBits = 5; 97 | break; 98 | case mir_pixel_format_rgba_5551: 99 | mode->redBits = 5; 100 | mode->greenBits = 5; 101 | mode->blueBits = 5; 102 | break; 103 | case mir_pixel_format_rgba_4444: 104 | mode->redBits = 4; 105 | mode->greenBits = 4; 106 | mode->blueBits = 4; 107 | break; 108 | case mir_pixel_format_abgr_8888: 109 | case mir_pixel_format_xbgr_8888: 110 | case mir_pixel_format_argb_8888: 111 | case mir_pixel_format_xrgb_8888: 112 | case mir_pixel_format_bgr_888: 113 | case mir_pixel_format_rgb_888: 114 | default: 115 | mode->redBits = 8; 116 | mode->greenBits = 8; 117 | mode->blueBits = 8; 118 | break; 119 | } 120 | } 121 | 122 | GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) 123 | { 124 | int i; 125 | GLFWvidmode* modes = NULL; 126 | MirDisplayConfiguration* displayConfig = 127 | mir_connection_create_display_config(_glfw.mir.connection); 128 | 129 | for (i = 0; i < displayConfig->num_outputs; i++) 130 | { 131 | const MirDisplayOutput* out = displayConfig->outputs + i; 132 | if (out->output_id != monitor->mir.output_id) 133 | continue; 134 | 135 | modes = calloc(out->num_modes, sizeof(GLFWvidmode)); 136 | 137 | for (*found = 0; *found < out->num_modes; (*found)++) 138 | { 139 | modes[*found].width = out->modes[*found].horizontal_resolution; 140 | modes[*found].height = out->modes[*found].vertical_resolution; 141 | modes[*found].refreshRate = out->modes[*found].refresh_rate; 142 | 143 | FillInRGBBitsFromPixelFormat(&modes[*found], out->output_formats[*found]); 144 | } 145 | 146 | break; 147 | } 148 | 149 | mir_display_config_destroy(displayConfig); 150 | 151 | return modes; 152 | } 153 | 154 | void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) 155 | { 156 | *mode = monitor->modes[monitor->mir.cur_mode]; 157 | } 158 | 159 | void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 160 | { 161 | _glfwInputError(GLFW_PLATFORM_ERROR, 162 | "Mir: Unsupported function %s", __PRETTY_FUNCTION__); 163 | } 164 | 165 | void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) 166 | { 167 | _glfwInputError(GLFW_PLATFORM_ERROR, 168 | "Mir: Unsupported function %s", __PRETTY_FUNCTION__); 169 | } 170 | 171 | 172 | ////////////////////////////////////////////////////////////////////////// 173 | ////// GLFW native API ////// 174 | ////////////////////////////////////////////////////////////////////////// 175 | 176 | GLFWAPI int glfwGetMirMonitor(GLFWmonitor* handle) 177 | { 178 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 179 | _GLFW_REQUIRE_INIT_OR_RETURN(0); 180 | return monitor->mir.output_id; 181 | } 182 | 183 | -------------------------------------------------------------------------------- /tests/joysticks.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Joystick input test 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test displays the state of every button and axis of every connected 27 | // joystick and/or gamepad 28 | // 29 | //======================================================================== 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #ifdef _MSC_VER 39 | #define strdup(x) _strdup(x) 40 | #endif 41 | 42 | static int joysticks[GLFW_JOYSTICK_LAST + 1]; 43 | static int joystick_count = 0; 44 | 45 | static void error_callback(int error, const char* description) 46 | { 47 | fprintf(stderr, "Error: %s\n", description); 48 | } 49 | 50 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 51 | { 52 | glViewport(0, 0, width, height); 53 | } 54 | 55 | static void draw_joystick(int index, int x, int y, int width, int height) 56 | { 57 | int i; 58 | int axis_count, button_count; 59 | const float* axes; 60 | const unsigned char* buttons; 61 | const int axis_height = 3 * height / 4; 62 | const int button_height = height / 4; 63 | 64 | axes = glfwGetJoystickAxes(joysticks[index], &axis_count); 65 | if (axis_count) 66 | { 67 | const int axis_width = width / axis_count; 68 | 69 | for (i = 0; i < axis_count; i++) 70 | { 71 | float value = axes[i] / 2.f + 0.5f; 72 | 73 | glColor3f(0.3f, 0.3f, 0.3f); 74 | glRecti(x + i * axis_width, 75 | y, 76 | x + (i + 1) * axis_width, 77 | y + axis_height); 78 | 79 | glColor3f(1.f, 1.f, 1.f); 80 | glRecti(x + i * axis_width, 81 | y + (int) (value * (axis_height - 5)), 82 | x + (i + 1) * axis_width, 83 | y + 5 + (int) (value * (axis_height - 5))); 84 | } 85 | } 86 | 87 | buttons = glfwGetJoystickButtons(joysticks[index], &button_count); 88 | if (button_count) 89 | { 90 | const int button_width = width / button_count; 91 | 92 | for (i = 0; i < button_count; i++) 93 | { 94 | if (buttons[i]) 95 | glColor3f(1.f, 1.f, 1.f); 96 | else 97 | glColor3f(0.3f, 0.3f, 0.3f); 98 | 99 | glRecti(x + i * button_width, 100 | y + axis_height, 101 | x + (i + 1) * button_width, 102 | y + axis_height + button_height); 103 | } 104 | } 105 | } 106 | 107 | static void draw_joysticks(GLFWwindow* window) 108 | { 109 | int i, width, height, offset = 0; 110 | 111 | glfwGetFramebufferSize(window, &width, &height); 112 | 113 | glMatrixMode(GL_PROJECTION); 114 | glLoadIdentity(); 115 | glOrtho(0.f, width, height, 0.f, 1.f, -1.f); 116 | glMatrixMode(GL_MODELVIEW); 117 | 118 | for (i = 0; i < joystick_count; i++) 119 | { 120 | draw_joystick(i, 121 | 0, offset * height / joystick_count, 122 | width, height / joystick_count); 123 | offset++; 124 | } 125 | } 126 | 127 | static void joystick_callback(int joy, int event) 128 | { 129 | if (event == GLFW_CONNECTED) 130 | { 131 | int axis_count, button_count; 132 | 133 | glfwGetJoystickAxes(joy, &axis_count); 134 | glfwGetJoystickButtons(joy, &button_count); 135 | 136 | printf("Found joystick %i named \'%s\' with %i axes, %i buttons\n", 137 | joy + 1, 138 | glfwGetJoystickName(joy), 139 | axis_count, 140 | button_count); 141 | 142 | joysticks[joystick_count++] = joy; 143 | } 144 | else if (event == GLFW_DISCONNECTED) 145 | { 146 | int i; 147 | 148 | for (i = 0; i < joystick_count; i++) 149 | { 150 | if (joysticks[i] == joy) 151 | break; 152 | } 153 | 154 | for (i = i + 1; i < joystick_count; i++) 155 | joysticks[i - 1] = joysticks[i]; 156 | 157 | printf("Lost joystick %i\n", joy + 1); 158 | joystick_count--; 159 | } 160 | } 161 | 162 | static void find_joysticks(void) 163 | { 164 | int joy; 165 | 166 | for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) 167 | { 168 | if (glfwJoystickPresent(joy)) 169 | joystick_callback(joy, GLFW_CONNECTED); 170 | } 171 | } 172 | 173 | int main(void) 174 | { 175 | GLFWwindow* window; 176 | 177 | memset(joysticks, 0, sizeof(joysticks)); 178 | 179 | glfwSetErrorCallback(error_callback); 180 | 181 | if (!glfwInit()) 182 | exit(EXIT_FAILURE); 183 | 184 | find_joysticks(); 185 | glfwSetJoystickCallback(joystick_callback); 186 | 187 | window = glfwCreateWindow(640, 480, "Joystick Test", NULL, NULL); 188 | if (!window) 189 | { 190 | glfwTerminate(); 191 | exit(EXIT_FAILURE); 192 | } 193 | 194 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 195 | 196 | glfwMakeContextCurrent(window); 197 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 198 | glfwSwapInterval(1); 199 | 200 | while (!glfwWindowShouldClose(window)) 201 | { 202 | glClear(GL_COLOR_BUFFER_BIT); 203 | 204 | draw_joysticks(window); 205 | 206 | glfwSwapBuffers(window); 207 | glfwPollEvents(); 208 | 209 | // Workaround for an issue with msvcrt and mintty 210 | fflush(stdout); 211 | } 212 | 213 | glfwTerminate(); 214 | exit(EXIT_SUCCESS); 215 | } 216 | 217 | -------------------------------------------------------------------------------- /docs/DoxygenLayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | -------------------------------------------------------------------------------- /src/wl_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Wayland - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #ifndef _glfw3_wayland_platform_h_ 28 | #define _glfw3_wayland_platform_h_ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | typedef VkFlags VkWaylandSurfaceCreateFlagsKHR; 35 | 36 | typedef struct VkWaylandSurfaceCreateInfoKHR 37 | { 38 | VkStructureType sType; 39 | const void* pNext; 40 | VkWaylandSurfaceCreateFlagsKHR flags; 41 | struct wl_display* display; 42 | struct wl_surface* surface; 43 | } VkWaylandSurfaceCreateInfoKHR; 44 | 45 | typedef VkResult (APIENTRY *PFN_vkCreateWaylandSurfaceKHR)(VkInstance,const VkWaylandSurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*); 46 | typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)(VkPhysicalDevice,uint32_t,struct wl_display*); 47 | 48 | #include "posix_tls.h" 49 | #include "posix_time.h" 50 | #include "linux_joystick.h" 51 | #include "xkb_unicode.h" 52 | #include "egl_context.h" 53 | 54 | #include "wayland-relative-pointer-unstable-v1-client-protocol.h" 55 | #include "wayland-pointer-constraints-unstable-v1-client-protocol.h" 56 | 57 | #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) 58 | #define _glfw_dlclose(handle) dlclose(handle) 59 | #define _glfw_dlsym(handle, name) dlsym(handle, name) 60 | 61 | #define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->wl.native) 62 | #define _GLFW_EGL_NATIVE_DISPLAY ((EGLNativeDisplayType) _glfw.wl.display) 63 | 64 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWayland wl 65 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWayland wl 66 | #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWayland wl 67 | #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorWayland wl 68 | 69 | #define _GLFW_PLATFORM_CONTEXT_STATE 70 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE 71 | 72 | 73 | // Wayland-specific video mode data 74 | // 75 | typedef struct _GLFWvidmodeWayland _GLFWvidmodeWayland; 76 | 77 | // Wayland-specific per-window data 78 | // 79 | typedef struct _GLFWwindowWayland 80 | { 81 | int width, height; 82 | GLFWbool visible; 83 | GLFWbool maximized; 84 | struct wl_surface* surface; 85 | struct wl_egl_window* native; 86 | struct wl_shell_surface* shell_surface; 87 | struct wl_callback* callback; 88 | 89 | _GLFWcursor* currentCursor; 90 | double cursorPosX, cursorPosY; 91 | 92 | char* title; 93 | 94 | // We need to track the monitors the window spans on to calculate the 95 | // optimal scaling factor. 96 | int scale; 97 | _GLFWmonitor** monitors; 98 | int monitorsCount; 99 | int monitorsSize; 100 | 101 | struct { 102 | struct zwp_relative_pointer_v1* relativePointer; 103 | struct zwp_locked_pointer_v1* lockedPointer; 104 | } pointerLock; 105 | } _GLFWwindowWayland; 106 | 107 | // Wayland-specific global data 108 | // 109 | typedef struct _GLFWlibraryWayland 110 | { 111 | struct wl_display* display; 112 | struct wl_registry* registry; 113 | struct wl_compositor* compositor; 114 | struct wl_shell* shell; 115 | struct wl_shm* shm; 116 | struct wl_seat* seat; 117 | struct wl_pointer* pointer; 118 | struct wl_keyboard* keyboard; 119 | struct zwp_relative_pointer_manager_v1* relativePointerManager; 120 | struct zwp_pointer_constraints_v1* pointerConstraints; 121 | 122 | int wl_compositor_version; 123 | 124 | struct wl_cursor_theme* cursorTheme; 125 | struct wl_surface* cursorSurface; 126 | uint32_t pointerSerial; 127 | 128 | _GLFWmonitor** monitors; 129 | int monitorsCount; 130 | int monitorsSize; 131 | 132 | short int publicKeys[256]; 133 | 134 | struct { 135 | struct xkb_context* context; 136 | struct xkb_keymap* keymap; 137 | struct xkb_state* state; 138 | xkb_mod_mask_t control_mask; 139 | xkb_mod_mask_t alt_mask; 140 | xkb_mod_mask_t shift_mask; 141 | xkb_mod_mask_t super_mask; 142 | unsigned int modifiers; 143 | } xkb; 144 | 145 | _GLFWwindow* pointerFocus; 146 | _GLFWwindow* keyboardFocus; 147 | 148 | } _GLFWlibraryWayland; 149 | 150 | // Wayland-specific per-monitor data 151 | // 152 | typedef struct _GLFWmonitorWayland 153 | { 154 | struct wl_output* output; 155 | 156 | _GLFWvidmodeWayland* modes; 157 | int modesCount; 158 | int modesSize; 159 | GLFWbool done; 160 | 161 | int x; 162 | int y; 163 | int scale; 164 | } _GLFWmonitorWayland; 165 | 166 | // Wayland-specific per-cursor data 167 | // 168 | typedef struct _GLFWcursorWayland 169 | { 170 | struct wl_cursor_image* image; 171 | struct wl_buffer* buffer; 172 | int width, height; 173 | int xhot, yhot; 174 | } _GLFWcursorWayland; 175 | 176 | 177 | void _glfwAddOutputWayland(uint32_t name, uint32_t version); 178 | 179 | #endif // _glfw3_wayland_platform_h_ 180 | -------------------------------------------------------------------------------- /src/wgl_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 WGL - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #ifndef _glfw3_wgl_context_h_ 29 | #define _glfw3_wgl_context_h_ 30 | 31 | 32 | #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 33 | #define WGL_SUPPORT_OPENGL_ARB 0x2010 34 | #define WGL_DRAW_TO_WINDOW_ARB 0x2001 35 | #define WGL_PIXEL_TYPE_ARB 0x2013 36 | #define WGL_TYPE_RGBA_ARB 0x202b 37 | #define WGL_ACCELERATION_ARB 0x2003 38 | #define WGL_NO_ACCELERATION_ARB 0x2025 39 | #define WGL_RED_BITS_ARB 0x2015 40 | #define WGL_RED_SHIFT_ARB 0x2016 41 | #define WGL_GREEN_BITS_ARB 0x2017 42 | #define WGL_GREEN_SHIFT_ARB 0x2018 43 | #define WGL_BLUE_BITS_ARB 0x2019 44 | #define WGL_BLUE_SHIFT_ARB 0x201a 45 | #define WGL_ALPHA_BITS_ARB 0x201b 46 | #define WGL_ALPHA_SHIFT_ARB 0x201c 47 | #define WGL_ACCUM_BITS_ARB 0x201d 48 | #define WGL_ACCUM_RED_BITS_ARB 0x201e 49 | #define WGL_ACCUM_GREEN_BITS_ARB 0x201f 50 | #define WGL_ACCUM_BLUE_BITS_ARB 0x2020 51 | #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 52 | #define WGL_DEPTH_BITS_ARB 0x2022 53 | #define WGL_STENCIL_BITS_ARB 0x2023 54 | #define WGL_AUX_BUFFERS_ARB 0x2024 55 | #define WGL_STEREO_ARB 0x2012 56 | #define WGL_DOUBLE_BUFFER_ARB 0x2011 57 | #define WGL_SAMPLES_ARB 0x2042 58 | #define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20a9 59 | #define WGL_CONTEXT_DEBUG_BIT_ARB 0x00000001 60 | #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 61 | #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 62 | #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 63 | #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 64 | #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 65 | #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 66 | #define WGL_CONTEXT_FLAGS_ARB 0x2094 67 | #define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 68 | #define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 69 | #define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 70 | #define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 71 | #define WGL_NO_RESET_NOTIFICATION_ARB 0x8261 72 | #define WGL_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097 73 | #define WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0 74 | #define WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098 75 | 76 | #define ERROR_INVALID_VERSION_ARB 0x2095 77 | #define ERROR_INVALID_PROFILE_ARB 0x2096 78 | 79 | typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC)(int); 80 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC)(HDC,int,int,UINT,const int*,int*); 81 | typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC)(void); 82 | typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC)(HDC); 83 | typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC,HGLRC,const int*); 84 | 85 | typedef HGLRC (WINAPI * WGLCREATECONTEXT_T)(HDC); 86 | typedef BOOL (WINAPI * WGLDELETECONTEXT_T)(HGLRC); 87 | typedef PROC (WINAPI * WGLGETPROCADDRESS_T)(LPCSTR); 88 | typedef HDC (WINAPI * WGLGETCURRENTDC_T)(void); 89 | typedef BOOL (WINAPI * WGLMAKECURRENT_T)(HDC,HGLRC); 90 | typedef BOOL (WINAPI * WGLSHARELISTS_T)(HGLRC,HGLRC); 91 | 92 | // opengl32.dll function pointer typedefs 93 | #define wglCreateContext _glfw.wgl.CreateContext 94 | #define wglDeleteContext _glfw.wgl.DeleteContext 95 | #define wglGetProcAddress _glfw.wgl.GetProcAddress 96 | #define wglGetCurrentDC _glfw.wgl.GetCurrentDC 97 | #define wglMakeCurrent _glfw.wgl.MakeCurrent 98 | #define wglShareLists _glfw.wgl.ShareLists 99 | 100 | #define _GLFW_RECREATION_NOT_NEEDED 0 101 | #define _GLFW_RECREATION_REQUIRED 1 102 | #define _GLFW_RECREATION_IMPOSSIBLE 2 103 | 104 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL wgl 105 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryWGL wgl 106 | 107 | 108 | // WGL-specific per-context data 109 | // 110 | typedef struct _GLFWcontextWGL 111 | { 112 | HDC dc; 113 | HGLRC handle; 114 | int interval; 115 | 116 | } _GLFWcontextWGL; 117 | 118 | // WGL-specific global data 119 | // 120 | typedef struct _GLFWlibraryWGL 121 | { 122 | HINSTANCE instance; 123 | WGLCREATECONTEXT_T CreateContext; 124 | WGLDELETECONTEXT_T DeleteContext; 125 | WGLGETPROCADDRESS_T GetProcAddress; 126 | WGLGETCURRENTDC_T GetCurrentDC; 127 | WGLMAKECURRENT_T MakeCurrent; 128 | WGLSHARELISTS_T ShareLists; 129 | 130 | GLFWbool extensionsLoaded; 131 | 132 | PFNWGLSWAPINTERVALEXTPROC SwapIntervalEXT; 133 | PFNWGLGETPIXELFORMATATTRIBIVARBPROC GetPixelFormatAttribivARB; 134 | PFNWGLGETEXTENSIONSSTRINGEXTPROC GetExtensionsStringEXT; 135 | PFNWGLGETEXTENSIONSSTRINGARBPROC GetExtensionsStringARB; 136 | PFNWGLCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; 137 | GLFWbool EXT_swap_control; 138 | GLFWbool ARB_multisample; 139 | GLFWbool ARB_framebuffer_sRGB; 140 | GLFWbool EXT_framebuffer_sRGB; 141 | GLFWbool ARB_pixel_format; 142 | GLFWbool ARB_create_context; 143 | GLFWbool ARB_create_context_profile; 144 | GLFWbool EXT_create_context_es2_profile; 145 | GLFWbool ARB_create_context_robustness; 146 | GLFWbool ARB_context_flush_control; 147 | 148 | } _GLFWlibraryWGL; 149 | 150 | 151 | GLFWbool _glfwInitWGL(void); 152 | void _glfwTerminateWGL(void); 153 | GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, 154 | const _GLFWctxconfig* ctxconfig, 155 | const _GLFWfbconfig* fbconfig); 156 | 157 | #endif // _glfw3_wgl_context_h_ 158 | -------------------------------------------------------------------------------- /docs/monitor.dox: -------------------------------------------------------------------------------- 1 | /*! 2 | 3 | @page monitor_guide Monitor guide 4 | 5 | @tableofcontents 6 | 7 | This guide introduces the monitor related functions of GLFW. For details on 8 | a specific function in this category, see the @ref monitor. There are also 9 | guides for the other areas of GLFW. 10 | 11 | - @ref intro_guide 12 | - @ref window_guide 13 | - @ref context_guide 14 | - @ref vulkan_guide 15 | - @ref input_guide 16 | 17 | 18 | @section monitor_object Monitor objects 19 | 20 | A monitor object represents a currently connected monitor and is represented as 21 | a pointer to the [opaque](https://en.wikipedia.org/wiki/Opaque_data_type) type 22 | @ref GLFWmonitor. Monitor objects cannot be created or destroyed by the 23 | application and retain their addresses until the monitors they represent are 24 | disconnected or until the library is [terminated](@ref intro_init_terminate). 25 | 26 | Each monitor has a current video mode, a list of supported video modes, 27 | a virtual position, a human-readable name, an estimated physical size and 28 | a gamma ramp. One of the monitors is the primary monitor. 29 | 30 | The virtual position of a monitor is in 31 | [screen coordinates](@ref coordinate_systems) and, together with the current 32 | video mode, describes the viewports that the connected monitors provide into the 33 | virtual desktop that spans them. 34 | 35 | To see how GLFW views your monitor setup and its available video modes, run the 36 | `monitors` test program. 37 | 38 | 39 | @subsection monitor_monitors Retrieving monitors 40 | 41 | The primary monitor is returned by @ref glfwGetPrimaryMonitor. It is the user's 42 | preferred monitor and is usually the one with global UI elements like task bar 43 | or menu bar. 44 | 45 | @code 46 | GLFWmonitor* primary = glfwGetPrimaryMonitor(); 47 | @endcode 48 | 49 | You can retrieve all currently connected monitors with @ref glfwGetMonitors. 50 | See the reference documentation for the lifetime of the returned array. 51 | 52 | @code 53 | int count; 54 | GLFWmonitor** monitors = glfwGetMonitors(&count); 55 | @endcode 56 | 57 | The primary monitor is always the first monitor in the returned array, but other 58 | monitors may be moved to a different index when a monitor is connected or 59 | disconnected. 60 | 61 | 62 | @subsection monitor_event Monitor configuration changes 63 | 64 | If you wish to be notified when a monitor is connected or disconnected, set 65 | a monitor callback. 66 | 67 | @code 68 | glfwSetMonitorCallback(monitor_callback); 69 | @endcode 70 | 71 | The callback function receives the handle for the monitor that has been 72 | connected or disconnected and the event that occurred. 73 | 74 | @code 75 | void monitor_callback(GLFWmonitor* monitor, int event) 76 | { 77 | if (event == GLFW_CONNECTED) 78 | { 79 | // The monitor was connected 80 | } 81 | else if (event == GLFW_DISCONNECTED) 82 | { 83 | // The monitor was disconnected 84 | } 85 | } 86 | @endcode 87 | 88 | If a monitor is disconnected, any windows that are full screen on it get forced 89 | into windowed mode. 90 | 91 | 92 | @section monitor_properties Monitor properties 93 | 94 | Each monitor has a current video mode, a list of supported video modes, 95 | a virtual position, a human-readable name, an estimated physical size and 96 | a gamma ramp. 97 | 98 | 99 | @subsection monitor_modes Video modes 100 | 101 | GLFW generally does a good job selecting a suitable video mode when you create 102 | a full screen window, change its video mode or or make a windowed one full 103 | screen, but it is sometimes useful to know exactly which video modes are 104 | supported. 105 | 106 | Video modes are represented as @ref GLFWvidmode structures. You can get an 107 | array of the video modes supported by a monitor with @ref glfwGetVideoModes. 108 | See the reference documentation for the lifetime of the returned array. 109 | 110 | @code 111 | int count; 112 | GLFWvidmode* modes = glfwGetVideoModes(monitor, &count); 113 | @endcode 114 | 115 | To get the current video mode of a monitor call @ref glfwGetVideoMode. See the 116 | reference documentation for the lifetime of the returned pointer. 117 | 118 | @code 119 | const GLFWvidmode* mode = glfwGetVideoMode(monitor); 120 | @endcode 121 | 122 | The resolution of a video mode is specified in 123 | [screen coordinates](@ref coordinate_systems), not pixels. 124 | 125 | 126 | @subsection monitor_size Physical size 127 | 128 | The physical size of a monitor in millimetres, or an estimation of it, can be 129 | retrieved with @ref glfwGetMonitorPhysicalSize. This has no relation to its 130 | current _resolution_, i.e. the width and height of its current 131 | [video mode](@ref monitor_modes). 132 | 133 | @code 134 | int widthMM, heightMM; 135 | glfwGetMonitorPhysicalSize(monitor, &widthMM, &heightMM); 136 | @endcode 137 | 138 | This can, for example, be used together with the current video mode to calculate 139 | the DPI of a monitor. 140 | 141 | @code 142 | const double dpi = mode->width / (widthMM / 25.4); 143 | @endcode 144 | 145 | 146 | @subsection monitor_pos Virtual position 147 | 148 | The position of the monitor on the virtual desktop, in 149 | [screen coordinates](@ref coordinate_systems), can be retrieved with @ref 150 | glfwGetMonitorPos. 151 | 152 | @code 153 | int xpos, ypos; 154 | glfwGetMonitorPos(monitor, &xpos, &ypos); 155 | @endcode 156 | 157 | 158 | @subsection monitor_name Human-readable name 159 | 160 | The human-readable, UTF-8 encoded name of a monitor is returned by @ref 161 | glfwGetMonitorName. See the reference documentation for the lifetime of the 162 | returned string. 163 | 164 | @code 165 | const char* name = glfwGetMonitorName(monitor); 166 | @endcode 167 | 168 | Monitor names are not guaranteed to be unique. Two monitors of the same model 169 | and make may have the same name. Only the monitor handle is guaranteed to be 170 | unique, and only until that monitor is disconnected. 171 | 172 | 173 | @subsection monitor_gamma Gamma ramp 174 | 175 | The gamma ramp of a monitor can be set with @ref glfwSetGammaRamp, which accepts 176 | a monitor handle and a pointer to a @ref GLFWgammaramp structure. 177 | 178 | @code 179 | GLFWgammaramp ramp; 180 | unsigned short red[256], green[256], blue[256]; 181 | 182 | ramp.size = 256; 183 | ramp.red = red; 184 | ramp.green = green; 185 | ramp.blue = blue; 186 | 187 | for (i = 0; i < ramp.size; i++) 188 | { 189 | // Fill out gamma ramp arrays as desired 190 | } 191 | 192 | glfwSetGammaRamp(monitor, &ramp); 193 | @endcode 194 | 195 | The gamma ramp data is copied before the function returns, so there is no need 196 | to keep it around once the ramp has been set. 197 | 198 | @note It is recommended to use gamma ramps of size 256, as that is the size 199 | supported by all graphics cards on all platforms. 200 | 201 | The current gamma ramp for a monitor is returned by @ref glfwGetGammaRamp. See 202 | the reference documentation for the lifetime of the returned structure. 203 | 204 | @code 205 | const GLFWgammaramp* ramp = glfwGetGammaRamp(monitor); 206 | @endcode 207 | 208 | If you wish to set a regular gamma ramp, you can have GLFW calculate it for you 209 | from the desired exponent with @ref glfwSetGamma, which in turn calls @ref 210 | glfwSetGammaRamp with the resulting ramp. 211 | 212 | @code 213 | glfwSetGamma(monitor, 1.0); 214 | @endcode 215 | 216 | */ 217 | -------------------------------------------------------------------------------- /tests/monitors.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Monitor information tool 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test prints monitor and video mode information or verifies video 27 | // modes 28 | // 29 | //======================================================================== 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include "getopt.h" 39 | 40 | enum Mode 41 | { 42 | LIST_MODE, 43 | TEST_MODE 44 | }; 45 | 46 | static void usage(void) 47 | { 48 | printf("Usage: monitors [-t]\n"); 49 | printf(" monitors -h\n"); 50 | } 51 | 52 | static const char* format_mode(const GLFWvidmode* mode) 53 | { 54 | static char buffer[512]; 55 | 56 | sprintf(buffer, 57 | "%i x %i x %i (%i %i %i) %i Hz", 58 | mode->width, mode->height, 59 | mode->redBits + mode->greenBits + mode->blueBits, 60 | mode->redBits, mode->greenBits, mode->blueBits, 61 | mode->refreshRate); 62 | 63 | buffer[sizeof(buffer) - 1] = '\0'; 64 | return buffer; 65 | } 66 | 67 | static void error_callback(int error, const char* description) 68 | { 69 | fprintf(stderr, "Error: %s\n", description); 70 | } 71 | 72 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 73 | { 74 | printf("Framebuffer resized to %ix%i\n", width, height); 75 | 76 | glViewport(0, 0, width, height); 77 | } 78 | 79 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 80 | { 81 | if (key == GLFW_KEY_ESCAPE) 82 | glfwSetWindowShouldClose(window, GLFW_TRUE); 83 | } 84 | 85 | static void list_modes(GLFWmonitor* monitor) 86 | { 87 | int count, x, y, widthMM, heightMM, i; 88 | const GLFWvidmode* mode = glfwGetVideoMode(monitor); 89 | const GLFWvidmode* modes = glfwGetVideoModes(monitor, &count); 90 | 91 | glfwGetMonitorPos(monitor, &x, &y); 92 | glfwGetMonitorPhysicalSize(monitor, &widthMM, &heightMM); 93 | 94 | printf("Name: %s (%s)\n", 95 | glfwGetMonitorName(monitor), 96 | glfwGetPrimaryMonitor() == monitor ? "primary" : "secondary"); 97 | printf("Current mode: %s\n", format_mode(mode)); 98 | printf("Virtual position: %i %i\n", x, y); 99 | 100 | printf("Physical size: %i x %i mm (%0.2f dpi)\n", 101 | widthMM, heightMM, mode->width * 25.4f / widthMM); 102 | 103 | printf("Modes:\n"); 104 | 105 | for (i = 0; i < count; i++) 106 | { 107 | printf("%3u: %s", (unsigned int) i, format_mode(modes + i)); 108 | 109 | if (memcmp(mode, modes + i, sizeof(GLFWvidmode)) == 0) 110 | printf(" (current mode)"); 111 | 112 | putchar('\n'); 113 | } 114 | } 115 | 116 | static void test_modes(GLFWmonitor* monitor) 117 | { 118 | int i, count; 119 | GLFWwindow* window; 120 | const GLFWvidmode* modes = glfwGetVideoModes(monitor, &count); 121 | 122 | for (i = 0; i < count; i++) 123 | { 124 | const GLFWvidmode* mode = modes + i; 125 | GLFWvidmode current; 126 | 127 | glfwWindowHint(GLFW_RED_BITS, mode->redBits); 128 | glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); 129 | glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); 130 | glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); 131 | 132 | printf("Testing mode %u on monitor %s: %s\n", 133 | (unsigned int) i, 134 | glfwGetMonitorName(monitor), 135 | format_mode(mode)); 136 | 137 | window = glfwCreateWindow(mode->width, mode->height, 138 | "Video Mode Test", 139 | glfwGetPrimaryMonitor(), 140 | NULL); 141 | if (!window) 142 | { 143 | printf("Failed to enter mode %u: %s\n", 144 | (unsigned int) i, 145 | format_mode(mode)); 146 | continue; 147 | } 148 | 149 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 150 | glfwSetKeyCallback(window, key_callback); 151 | 152 | glfwMakeContextCurrent(window); 153 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 154 | glfwSwapInterval(1); 155 | 156 | glfwSetTime(0.0); 157 | 158 | while (glfwGetTime() < 5.0) 159 | { 160 | glClear(GL_COLOR_BUFFER_BIT); 161 | glfwSwapBuffers(window); 162 | glfwPollEvents(); 163 | 164 | if (glfwWindowShouldClose(window)) 165 | { 166 | printf("User terminated program\n"); 167 | 168 | glfwTerminate(); 169 | exit(EXIT_SUCCESS); 170 | } 171 | } 172 | 173 | glGetIntegerv(GL_RED_BITS, ¤t.redBits); 174 | glGetIntegerv(GL_GREEN_BITS, ¤t.greenBits); 175 | glGetIntegerv(GL_BLUE_BITS, ¤t.blueBits); 176 | 177 | glfwGetWindowSize(window, ¤t.width, ¤t.height); 178 | 179 | if (current.redBits != mode->redBits || 180 | current.greenBits != mode->greenBits || 181 | current.blueBits != mode->blueBits) 182 | { 183 | printf("*** Color bit mismatch: (%i %i %i) instead of (%i %i %i)\n", 184 | current.redBits, current.greenBits, current.blueBits, 185 | mode->redBits, mode->greenBits, mode->blueBits); 186 | } 187 | 188 | if (current.width != mode->width || current.height != mode->height) 189 | { 190 | printf("*** Size mismatch: %ix%i instead of %ix%i\n", 191 | current.width, current.height, 192 | mode->width, mode->height); 193 | } 194 | 195 | printf("Closing window\n"); 196 | 197 | glfwDestroyWindow(window); 198 | window = NULL; 199 | 200 | glfwPollEvents(); 201 | } 202 | } 203 | 204 | int main(int argc, char** argv) 205 | { 206 | int ch, i, count, mode = LIST_MODE; 207 | GLFWmonitor** monitors; 208 | 209 | while ((ch = getopt(argc, argv, "th")) != -1) 210 | { 211 | switch (ch) 212 | { 213 | case 'h': 214 | usage(); 215 | exit(EXIT_SUCCESS); 216 | case 't': 217 | mode = TEST_MODE; 218 | break; 219 | default: 220 | usage(); 221 | exit(EXIT_FAILURE); 222 | } 223 | } 224 | 225 | glfwSetErrorCallback(error_callback); 226 | 227 | if (!glfwInit()) 228 | exit(EXIT_FAILURE); 229 | 230 | monitors = glfwGetMonitors(&count); 231 | 232 | for (i = 0; i < count; i++) 233 | { 234 | if (mode == LIST_MODE) 235 | list_modes(monitors[i]); 236 | else if (mode == TEST_MODE) 237 | test_modes(monitors[i]); 238 | } 239 | 240 | glfwTerminate(); 241 | exit(EXIT_SUCCESS); 242 | } 243 | 244 | -------------------------------------------------------------------------------- /docs/vulkan.dox: -------------------------------------------------------------------------------- 1 | /*! 2 | 3 | @page vulkan_guide Vulkan guide 4 | 5 | @tableofcontents 6 | 7 | This guide is intended to fill the gaps between the [Vulkan 8 | documentation](https://www.khronos.org/vulkan/) and the rest of the GLFW 9 | documentation and is not a replacement for either. It assumes some familiarity 10 | with Vulkan concepts like loaders, devices, queues and surfaces and leaves it to 11 | the Vulkan documentation to explain the details of Vulkan functions. 12 | 13 | To develop for Vulkan you should install an SDK for your platform, for example 14 | the [LunarG Vulkan SDK](https://vulkan.lunarg.com/). Apart from the headers and 15 | libraries, it also provides the validation layers necessary for development. 16 | 17 | The GLFW library does not need the Vulkan SDK to enable support for Vulkan. 18 | However, any Vulkan-specific test and example programs are built only if the 19 | CMake files find a Vulkan SDK. 20 | 21 | For details on a specific function in this category, see the @ref vulkan. There 22 | are also guides for the other areas of the GLFW API. 23 | 24 | - @ref intro_guide 25 | - @ref window_guide 26 | - @ref context_guide 27 | - @ref monitor_guide 28 | - @ref input_guide 29 | 30 | 31 | @section vulkan_include Including the Vulkan and GLFW header files 32 | 33 | To include the Vulkan header, define [GLFW_INCLUDE_VULKAN](@ref build_macros) 34 | before including the GLFW header. 35 | 36 | @code 37 | #define GLFW_INCLUDE_VULKAN 38 | #include 39 | @endcode 40 | 41 | If you instead want to include the Vulkan header from a custom location or use 42 | your own custom Vulkan header then do this before the GLFW header. 43 | 44 | @code 45 | #include 46 | #include 47 | @endcode 48 | 49 | Unless a Vulkan header is included, either by the GLFW header or above it, any 50 | GLFW functions that take or return Vulkan types will not be declared. 51 | 52 | The `VK_USE_PLATFORM_*_KHR` macros do not need to be defined for the Vulkan part 53 | of GLFW to work. Define them only if you are using these extensions directly. 54 | 55 | 56 | @section vulkan_support Querying for Vulkan support 57 | 58 | If you are linking directly against the Vulkan loader then you can skip this 59 | section. The canonical desktop loader library exports all Vulkan core and 60 | Khronos extension functions, allowing them to be called directly. 61 | 62 | If you are loading the Vulkan loader dynamically instead of linking directly 63 | against it, you can check for the availability of a loader with @ref 64 | glfwVulkanSupported. 65 | 66 | @code 67 | if (glfwVulkanSupported()) 68 | { 69 | // Vulkan is available, at least for compute 70 | } 71 | @endcode 72 | 73 | This function returns `GLFW_TRUE` if the Vulkan loader was found. This check is 74 | performed by @ref glfwInit. 75 | 76 | If no loader was found, calling any other Vulkan related GLFW function will 77 | generate a @ref GLFW_API_UNAVAILABLE error. 78 | 79 | 80 | @subsection vulkan_proc Querying Vulkan function pointers 81 | 82 | To load any Vulkan core or extension function from the found loader, call @ref 83 | glfwGetInstanceProcAddress. To load functions needed for instance creation, 84 | pass `NULL` as the instance. 85 | 86 | @code 87 | PFN_vkCreateInstance pfnCreateInstance = (PFN_vkCreateInstance) 88 | glfwGetInstanceProcAddress(NULL, "vkCreateInstance"); 89 | @endcode 90 | 91 | Once you have created an instance, you can load from it all other Vulkan core 92 | functions and functions from any instance extensions you enabled. 93 | 94 | @code 95 | PFN_vkCreateDevice pfnCreateDevice = (PFN_vkCreateDevice) 96 | glfwGetInstanceProcAddress(instance, "vkCreateDevice"); 97 | @endcode 98 | 99 | This function in turn calls `vkGetInstanceProcAddr`. If that fails, the 100 | function falls back to a platform-specific query of the Vulkan loader (i.e. 101 | `dlsym` or `GetProcAddress`). If that also fails, the function returns `NULL`. 102 | For more information about `vkGetInstanceProcAddr`, see the Vulkan 103 | documentation. 104 | 105 | Vulkan also provides `vkGetDeviceProcAddr` for loading device-specific versions 106 | of Vulkan function. This function can be retrieved from an instance with @ref 107 | glfwGetInstanceProcAddress. 108 | 109 | @code 110 | PFN_vkGetDeviceProcAddr pfnGetDeviceProcAddr = (PFN_vkGetDeviceProcAddr) 111 | glfwGetInstanceProcAddress(instance, "vkGetDeviceProcAddr"); 112 | @endcode 113 | 114 | Device-specific functions may execute a little bit faster, due to not having to 115 | dispatch internally based on the device passed to them. For more information 116 | about `vkGetDeviceProcAddr`, see the Vulkan documentation. 117 | 118 | 119 | @section vulkan_ext Querying required Vulkan extensions 120 | 121 | To do anything useful with Vulkan you need to create an instance. If you want 122 | to use Vulkan to render to a window, you must enable the instance extensions 123 | GLFW requires to create Vulkan surfaces. 124 | 125 | To query the instance extensions required, call @ref 126 | glfwGetRequiredInstanceExtensions. 127 | 128 | @code 129 | uint32_t count; 130 | const char** extensions = glfwGetRequiredInstanceExtensions(&count); 131 | @endcode 132 | 133 | These extensions must all be enabled when creating instances that are going to 134 | be passed to @ref glfwGetPhysicalDevicePresentationSupport and @ref 135 | glfwCreateWindowSurface. The set of extensions will vary depending on platform 136 | and may also vary depending on graphics drivers and other factors. 137 | 138 | If it fails it will return `NULL` and GLFW will not be able to create Vulkan 139 | window surfaces. You can still use Vulkan for off-screen rendering and compute 140 | work. 141 | 142 | The returned array will always contain `VK_KHR_surface`, so if you don't 143 | require any additional extensions you can pass this list directly to the 144 | `VkInstanceCreateInfo` struct. 145 | 146 | @code 147 | VkInstanceCreateInfo ici; 148 | 149 | memset(&ici, 0, sizeof(ici)); 150 | ici.enabledExtensionCount = count; 151 | ici.ppEnabledExtensionNames = extensions; 152 | ... 153 | @endcode 154 | 155 | Additional extensions may be required by future versions of GLFW. You should 156 | check whether any extensions you wish to enable are already in the returned 157 | array, as it is an error to specify an extension more than once in the 158 | `VkInstanceCreateInfo` struct. 159 | 160 | 161 | @section vulkan_present Querying for Vulkan presentation support 162 | 163 | Not every queue family of every Vulkan device can present images to surfaces. 164 | To check whether a specific queue family of a physical device supports image 165 | presentation without first having to create a window and surface, call @ref 166 | glfwGetPhysicalDevicePresentationSupport. 167 | 168 | @code 169 | if (glfwGetPhysicalDevicePresentationSupport(instance, physical_device, queue_family_index)) 170 | { 171 | // Queue family supports image presentation 172 | } 173 | @endcode 174 | 175 | The `VK_KHR_surface` extension additionally provides the 176 | `vkGetPhysicalDeviceSurfaceSupportKHR` function, which performs the same test on 177 | an existing Vulkan surface. 178 | 179 | 180 | @section vulkan_window Creating the window 181 | 182 | Unless you will be using OpenGL or OpenGL ES with the same window as Vulkan, 183 | there is no need to create a context. You can disable context creation with the 184 | [GLFW_CLIENT_API](@ref window_hints_ctx) hint. 185 | 186 | @code 187 | glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); 188 | GLFWwindow* window = glfwCreateWindow(640, 480, "Window Title", NULL, NULL); 189 | @endcode 190 | 191 | See @ref context_less for more information. 192 | 193 | 194 | @section vulkan_surface Creating a Vulkan window surface 195 | 196 | You can create a Vulkan surface (as defined by the `VK_KHR_surface` extension) 197 | for a GLFW window with @ref glfwCreateWindowSurface. 198 | 199 | @code 200 | VkSurfaceKHR surface; 201 | VkResult err = glfwCreateWindowSurface(instance, window, NULL, &surface); 202 | if (err) 203 | { 204 | // Window surface creation failed 205 | } 206 | @endcode 207 | 208 | It is your responsibility to destroy the surface. GLFW does not destroy it for 209 | you. Call `vkDestroySurfaceKHR` function from the same extension to destroy it. 210 | 211 | */ 212 | --------------------------------------------------------------------------------