├── .gitignore ├── CMakeLists.txt ├── LICENSE.md ├── README.md ├── builder.py ├── deps ├── glew │ ├── LICENSE.txt │ ├── include │ │ └── GL │ │ │ ├── glew.h │ │ │ ├── glxew.h │ │ │ └── wglew.h │ └── src │ │ ├── glew.c │ │ ├── glewinfo.c │ │ └── visualinfo.c ├── glfw │ ├── .gitignore │ ├── CMake │ │ ├── MacOSXBundleInfo.plist.in │ │ ├── amd64-mingw32msvc.cmake │ │ ├── i586-mingw32msvc.cmake │ │ ├── i686-pc-mingw32.cmake │ │ ├── i686-w64-mingw32.cmake │ │ ├── modules │ │ │ ├── FindEGL.cmake │ │ │ ├── FindGLESv1.cmake │ │ │ ├── FindGLESv2.cmake │ │ │ ├── FindMir.cmake │ │ │ ├── FindWayland.cmake │ │ │ └── FindXKBCommon.cmake │ │ └── x86_64-w64-mingw32.cmake │ ├── CMakeLists.txt │ ├── COPYING.txt │ ├── README.md │ ├── cmake_uninstall.cmake.in │ ├── deps │ │ ├── EGL │ │ │ └── eglext.h │ │ ├── GL │ │ │ ├── glext.h │ │ │ ├── glxext.h │ │ │ └── wglext.h │ │ ├── KHR │ │ │ └── khrplatform.h │ │ ├── getopt.c │ │ ├── getopt.h │ │ ├── glad.c │ │ ├── glad │ │ │ └── glad.h │ │ ├── linmath.h │ │ ├── tinycthread.c │ │ └── tinycthread.h │ ├── docs │ │ ├── CMakeLists.txt │ │ ├── Doxyfile.in │ │ ├── DoxygenLayout.xml │ │ ├── build.dox │ │ ├── compat.dox │ │ ├── compile.dox │ │ ├── context.dox │ │ ├── extra.css │ │ ├── extra.less │ │ ├── footer.html │ │ ├── header.html │ │ ├── input.dox │ │ ├── internal.dox │ │ ├── intro.dox │ │ ├── main.dox │ │ ├── monitor.dox │ │ ├── moving.dox │ │ ├── news.dox │ │ ├── quick.dox │ │ ├── rift.dox │ │ ├── spaces.svg │ │ └── window.dox │ ├── examples │ │ ├── CMakeLists.txt │ │ ├── boing.c │ │ ├── gears.c │ │ ├── heightmap.c │ │ ├── particles.c │ │ ├── simple.c │ │ ├── splitview.c │ │ └── wave.c │ ├── include │ │ └── GLFW │ │ │ ├── glfw3.h │ │ │ └── glfw3native.h │ ├── src │ │ ├── CMakeLists.txt │ │ ├── cocoa_init.m │ │ ├── cocoa_monitor.m │ │ ├── cocoa_platform.h │ │ ├── cocoa_window.m │ │ ├── context.c │ │ ├── egl_context.c │ │ ├── egl_context.h │ │ ├── glfw3.pc.in │ │ ├── glfw3Config.cmake.in │ │ ├── glfw_config.h.in │ │ ├── glx_context.c │ │ ├── glx_context.h │ │ ├── init.c │ │ ├── input.c │ │ ├── internal.h │ │ ├── iokit_joystick.h │ │ ├── iokit_joystick.m │ │ ├── linux_joystick.c │ │ ├── linux_joystick.h │ │ ├── mach_time.c │ │ ├── mir_init.c │ │ ├── mir_monitor.c │ │ ├── mir_platform.h │ │ ├── mir_window.c │ │ ├── monitor.c │ │ ├── nsgl_context.h │ │ ├── nsgl_context.m │ │ ├── posix_time.c │ │ ├── posix_time.h │ │ ├── posix_tls.c │ │ ├── posix_tls.h │ │ ├── wgl_context.c │ │ ├── wgl_context.h │ │ ├── win32_init.c │ │ ├── win32_monitor.c │ │ ├── win32_platform.h │ │ ├── win32_time.c │ │ ├── win32_tls.c │ │ ├── win32_tls.h │ │ ├── win32_window.c │ │ ├── window.c │ │ ├── winmm_joystick.c │ │ ├── winmm_joystick.h │ │ ├── wl_init.c │ │ ├── wl_monitor.c │ │ ├── wl_platform.h │ │ ├── wl_window.c │ │ ├── x11_init.c │ │ ├── x11_monitor.c │ │ ├── x11_platform.h │ │ ├── x11_window.c │ │ ├── xkb_unicode.c │ │ └── xkb_unicode.h │ └── tests │ │ ├── CMakeLists.txt │ │ ├── clipboard.c │ │ ├── cursor.c │ │ ├── empty.c │ │ ├── events.c │ │ ├── gamma.c │ │ ├── glfwinfo.c │ │ ├── iconify.c │ │ ├── joysticks.c │ │ ├── monitors.c │ │ ├── msaa.c │ │ ├── reopen.c │ │ ├── sharing.c │ │ ├── tearing.c │ │ ├── threads.c │ │ ├── title.c │ │ └── windows.c ├── lodepng │ ├── lodepng.c │ └── lodepng.h ├── noise │ ├── noise.c │ └── noise.h ├── sqlite │ ├── shell.c │ ├── sqlite3.c │ ├── sqlite3.h │ └── sqlite3ext.h └── tinycthread │ ├── tinycthread.c │ └── tinycthread.h ├── server.py ├── shaders ├── block_fragment.glsl ├── block_vertex.glsl ├── line_fragment.glsl ├── line_vertex.glsl ├── sky_fragment.glsl ├── sky_vertex.glsl ├── text_fragment.glsl └── text_vertex.glsl ├── src ├── auth.c ├── auth.h ├── client.c ├── client.h ├── config.h ├── cube.c ├── cube.h ├── db.c ├── db.h ├── item.c ├── item.h ├── main.c ├── map.c ├── map.h ├── matrix.c ├── matrix.h ├── ring.c ├── ring.h ├── sign.c ├── sign.h ├── util.c ├── util.h ├── world.c └── world.h ├── textures ├── font.png ├── sign.png ├── sky.png └── texture.png └── world.py /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | Makefile 3 | CMakeCache.txt 4 | CMakeFiles 5 | cmake_install.cmake 6 | config.py 7 | craft 8 | world 9 | env 10 | log.txt 11 | *.o 12 | *.db 13 | *.exe 14 | *.dll 15 | *.pyc 16 | 17 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(craft) 4 | 5 | FILE(GLOB SOURCE_FILES src/*.c) 6 | 7 | add_executable( 8 | craft 9 | ${SOURCE_FILES} 10 | deps/glew/src/glew.c 11 | deps/lodepng/lodepng.c 12 | deps/noise/noise.c 13 | deps/sqlite/sqlite3.c 14 | deps/tinycthread/tinycthread.c) 15 | 16 | add_definitions(-std=c99 -O3) 17 | 18 | add_subdirectory(deps/glfw) 19 | include_directories(deps/glew/include) 20 | include_directories(deps/glfw/include) 21 | include_directories(deps/lodepng) 22 | include_directories(deps/noise) 23 | include_directories(deps/sqlite) 24 | include_directories(deps/tinycthread) 25 | 26 | if(MINGW) 27 | set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} 28 | "C:/Program Files/CURL/lib" "C:/Program Files (x86)/CURL/lib") 29 | set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} 30 | "C:/Program Files/CURL/include" "C:/Program Files (x86)/CURL/include") 31 | endif() 32 | 33 | find_package(CURL REQUIRED) 34 | include_directories(${CURL_INCLUDE_DIR}) 35 | 36 | if(APPLE) 37 | target_link_libraries(craft glfw 38 | ${GLFW_LIBRARIES} ${CURL_LIBRARIES}) 39 | endif() 40 | 41 | if(UNIX) 42 | target_link_libraries(craft dl glfw 43 | ${GLFW_LIBRARIES} ${CURL_LIBRARIES}) 44 | endif() 45 | 46 | if(MINGW) 47 | target_link_libraries(craft ws2_32.lib glfw 48 | ${GLFW_LIBRARIES} ${CURL_LIBRARIES}) 49 | endif() 50 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (C) 2013 Michael Fogleman 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /deps/glew/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The OpenGL Extension Wrangler Library 2 | Copyright (C) 2002-2007, Milan Ikits 3 | Copyright (C) 2002-2007, Marcelo E. Magallon 4 | Copyright (C) 2002, Lev Povalahev 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | * The name of the author may be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 31 | Mesa 3-D graphics library 32 | Version: 7.0 33 | 34 | Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a 37 | copy of this software and associated documentation files (the "Software"), 38 | to deal in the Software without restriction, including without limitation 39 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 40 | and/or sell copies of the Software, and to permit persons to whom the 41 | Software is furnished to do so, subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included 44 | in all copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 47 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 49 | BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 50 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 51 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 52 | 53 | 54 | Copyright (c) 2007 The Khronos Group Inc. 55 | 56 | Permission is hereby granted, free of charge, to any person obtaining a 57 | copy of this software and/or associated documentation files (the 58 | "Materials"), to deal in the Materials without restriction, including 59 | without limitation the rights to use, copy, modify, merge, publish, 60 | distribute, sublicense, and/or sell copies of the Materials, and to 61 | permit persons to whom the Materials are furnished to do so, subject to 62 | the following conditions: 63 | 64 | The above copyright notice and this permission notice shall be included 65 | in all copies or substantial portions of the Materials. 66 | 67 | THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 68 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 69 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 70 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 71 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 72 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 73 | MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 74 | -------------------------------------------------------------------------------- /deps/glfw/.gitignore: -------------------------------------------------------------------------------- 1 | # External junk 2 | .DS_Store 3 | _ReSharper* 4 | *.opensdf 5 | *.sdf 6 | *.dir 7 | *.vcxproj* 8 | *.sln 9 | Win32 10 | Debug 11 | Release 12 | 13 | # CMake files 14 | Makefile 15 | CMakeCache.txt 16 | CMakeFiles 17 | cmake_install.cmake 18 | cmake_uninstall.cmake 19 | 20 | # Generated files 21 | docs/Doxyfile 22 | docs/html 23 | docs/warnings.txt 24 | src/config.h 25 | src/glfw3.pc 26 | src/glfwConfig.cmake 27 | src/glfwConfigVersion.cmake 28 | 29 | # Compiled binaries 30 | src/libglfw.so 31 | src/libglfw.so.3 32 | src/libglfw.so.3.0 33 | src/libglfw.dylib 34 | src/libglfw.dylib 35 | src/libglfw.3.dylib 36 | src/libglfw.3.0.dylib 37 | src/libglfw3.a 38 | src/glfw3.lib 39 | src/glfw3.dll 40 | src/glfw3dll.lib 41 | src/glfw3dll.a 42 | examples/*.app 43 | examples/*.exe 44 | examples/boing 45 | examples/gears 46 | examples/heightmap 47 | examples/splitview 48 | examples/simple 49 | examples/wave 50 | tests/*.app 51 | tests/*.exe 52 | tests/accuracy 53 | tests/clipboard 54 | tests/defaults 55 | tests/events 56 | tests/fsaa 57 | tests/gamma 58 | tests/glfwinfo 59 | tests/iconify 60 | tests/joysticks 61 | tests/modes 62 | tests/peter 63 | tests/reopen 64 | tests/sharing 65 | tests/tearing 66 | tests/threads 67 | tests/title 68 | tests/version 69 | tests/windows 70 | 71 | -------------------------------------------------------------------------------- /deps/glfw/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 | -------------------------------------------------------------------------------- /deps/glfw/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 | -------------------------------------------------------------------------------- /deps/glfw/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 | -------------------------------------------------------------------------------- /deps/glfw/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 | -------------------------------------------------------------------------------- /deps/glfw/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 | -------------------------------------------------------------------------------- /deps/glfw/CMake/modules/FindEGL.cmake: -------------------------------------------------------------------------------- 1 | # Find EGL 2 | # 3 | # EGL_INCLUDE_DIR 4 | # EGL_LIBRARY 5 | # EGL_FOUND 6 | 7 | find_path(EGL_INCLUDE_DIR NAMES EGL/egl.h PATHS /opt/vc/include) 8 | 9 | set(EGL_NAMES ${EGL_NAMES} egl EGL libEGL) 10 | find_library(EGL_LIBRARY NAMES ${EGL_NAMES} PATHS /opt/vc/lib) 11 | 12 | include(FindPackageHandleStandardArgs) 13 | find_package_handle_standard_args(EGL DEFAULT_MSG EGL_LIBRARY EGL_INCLUDE_DIR) 14 | 15 | mark_as_advanced(EGL_INCLUDE_DIR EGL_LIBRARY) 16 | 17 | -------------------------------------------------------------------------------- /deps/glfw/CMake/modules/FindGLESv1.cmake: -------------------------------------------------------------------------------- 1 | # Find GLESv1 2 | # 3 | # GLESv1_INCLUDE_DIR 4 | # GLESv1_LIBRARY 5 | # GLESv1_FOUND 6 | 7 | find_path(GLESv1_INCLUDE_DIR NAMES GLES/gl.h PATHS /opt/vc/include) 8 | 9 | set(GLESv1_NAMES ${GLESv1_NAMES} GLESv1_CM libGLES_CM) 10 | find_library(GLESv1_LIBRARY NAMES ${GLESv1_NAMES} PATHS /opt/vc/lib) 11 | 12 | include(FindPackageHandleStandardArgs) 13 | find_package_handle_standard_args(GLESv1 DEFAULT_MSG GLESv1_LIBRARY GLESv1_INCLUDE_DIR) 14 | 15 | mark_as_advanced(GLESv1_INCLUDE_DIR GLESv1_LIBRARY) 16 | 17 | -------------------------------------------------------------------------------- /deps/glfw/CMake/modules/FindGLESv2.cmake: -------------------------------------------------------------------------------- 1 | # Find GLESv2 2 | # 3 | # GLESv2_INCLUDE_DIR 4 | # GLESv2_LIBRARY 5 | # GLESv2_FOUND 6 | 7 | find_path(GLESv2_INCLUDE_DIR NAMES GLES2/gl2.h PATHS /opt/vc/include) 8 | 9 | set(GLESv2_NAMES ${GLESv2_NAMES} GLESv2 libGLESv2) 10 | find_library(GLESv2_LIBRARY NAMES ${GLESv2_NAMES} PATHS /opt/vc/lib) 11 | 12 | include(FindPackageHandleStandardArgs) 13 | find_package_handle_standard_args(GLESv2 DEFAULT_MSG GLESv2_LIBRARY GLESv2_INCLUDE_DIR) 14 | 15 | mark_as_advanced(GLESv2_INCLUDE_DIR GLESv2_LIBRARY) 16 | 17 | -------------------------------------------------------------------------------- /deps/glfw/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 | -------------------------------------------------------------------------------- /deps/glfw/CMake/modules/FindWayland.cmake: -------------------------------------------------------------------------------- 1 | # Try to find Wayland on a Unix system 2 | # 3 | # This will define: 4 | # 5 | # WAYLAND_FOUND - True if Wayland is found 6 | # WAYLAND_LIBRARIES - Link these to use Wayland 7 | # WAYLAND_INCLUDE_DIR - Include directory for Wayland 8 | # WAYLAND_DEFINITIONS - Compiler flags for using Wayland 9 | # 10 | # In addition the following more fine grained variables will be defined: 11 | # 12 | # WAYLAND_CLIENT_FOUND WAYLAND_CLIENT_INCLUDE_DIR WAYLAND_CLIENT_LIBRARIES 13 | # WAYLAND_SERVER_FOUND WAYLAND_SERVER_INCLUDE_DIR WAYLAND_SERVER_LIBRARIES 14 | # WAYLAND_EGL_FOUND WAYLAND_EGL_INCLUDE_DIR WAYLAND_EGL_LIBRARIES 15 | # 16 | # Copyright (c) 2013 Martin Gräßlin 17 | # 18 | # Redistribution and use is allowed according to the terms of the BSD license. 19 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 20 | 21 | IF (NOT WIN32) 22 | IF (WAYLAND_INCLUDE_DIR AND WAYLAND_LIBRARIES) 23 | # In the cache already 24 | SET(WAYLAND_FIND_QUIETLY TRUE) 25 | ENDIF () 26 | 27 | # Use pkg-config to get the directories and then use these values 28 | # in the FIND_PATH() and FIND_LIBRARY() calls 29 | FIND_PACKAGE(PkgConfig) 30 | PKG_CHECK_MODULES(PKG_WAYLAND QUIET wayland-client wayland-server wayland-egl wayland-cursor) 31 | 32 | SET(WAYLAND_DEFINITIONS ${PKG_WAYLAND_CFLAGS}) 33 | 34 | FIND_PATH(WAYLAND_CLIENT_INCLUDE_DIR NAMES wayland-client.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS}) 35 | FIND_PATH(WAYLAND_SERVER_INCLUDE_DIR NAMES wayland-server.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS}) 36 | FIND_PATH(WAYLAND_EGL_INCLUDE_DIR NAMES wayland-egl.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS}) 37 | FIND_PATH(WAYLAND_CURSOR_INCLUDE_DIR NAMES wayland-cursor.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS}) 38 | 39 | FIND_LIBRARY(WAYLAND_CLIENT_LIBRARIES NAMES wayland-client HINTS ${PKG_WAYLAND_LIBRARY_DIRS}) 40 | FIND_LIBRARY(WAYLAND_SERVER_LIBRARIES NAMES wayland-server HINTS ${PKG_WAYLAND_LIBRARY_DIRS}) 41 | FIND_LIBRARY(WAYLAND_EGL_LIBRARIES NAMES wayland-egl HINTS ${PKG_WAYLAND_LIBRARY_DIRS}) 42 | FIND_LIBRARY(WAYLAND_CURSOR_LIBRARIES NAMES wayland-cursor HINTS ${PKG_WAYLAND_LIBRARY_DIRS}) 43 | 44 | set(WAYLAND_INCLUDE_DIR ${WAYLAND_CLIENT_INCLUDE_DIR} ${WAYLAND_SERVER_INCLUDE_DIR} ${WAYLAND_EGL_INCLUDE_DIR} ${WAYLAND_CURSOR_INCLUDE_DIR}) 45 | 46 | set(WAYLAND_LIBRARIES ${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_SERVER_LIBRARIES} ${WAYLAND_EGL_LIBRARIES} ${WAYLAND_CURSOR_LIBRARIES}) 47 | 48 | list(REMOVE_DUPLICATES WAYLAND_INCLUDE_DIR) 49 | 50 | include(FindPackageHandleStandardArgs) 51 | 52 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_CLIENT DEFAULT_MSG WAYLAND_CLIENT_LIBRARIES WAYLAND_CLIENT_INCLUDE_DIR) 53 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_SERVER DEFAULT_MSG WAYLAND_SERVER_LIBRARIES WAYLAND_SERVER_INCLUDE_DIR) 54 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_EGL DEFAULT_MSG WAYLAND_EGL_LIBRARIES WAYLAND_EGL_INCLUDE_DIR) 55 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_CURSOR DEFAULT_MSG WAYLAND_CURSOR_LIBRARIES WAYLAND_CURSOR_INCLUDE_DIR) 56 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND DEFAULT_MSG WAYLAND_LIBRARIES WAYLAND_INCLUDE_DIR) 57 | 58 | MARK_AS_ADVANCED( 59 | WAYLAND_INCLUDE_DIR WAYLAND_LIBRARIES 60 | WAYLAND_CLIENT_INCLUDE_DIR WAYLAND_CLIENT_LIBRARIES 61 | WAYLAND_SERVER_INCLUDE_DIR WAYLAND_SERVER_LIBRARIES 62 | WAYLAND_EGL_INCLUDE_DIR WAYLAND_EGL_LIBRARIES 63 | WAYLAND_CURSOR_INCLUDE_DIR WAYLAND_CURSOR_LIBRARIES 64 | ) 65 | 66 | ENDIF () 67 | -------------------------------------------------------------------------------- /deps/glfw/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 | -------------------------------------------------------------------------------- /deps/glfw/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 | -------------------------------------------------------------------------------- /deps/glfw/COPYING.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2006 Marcus Geelnard 2 | Copyright (c) 2006-2010 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 | -------------------------------------------------------------------------------- /deps/glfw/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 | -------------------------------------------------------------------------------- /deps/glfw/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 | -------------------------------------------------------------------------------- /deps/glfw/docs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_custom_target(docs ALL ${DOXYGEN_EXECUTABLE} 3 | WORKING_DIRECTORY ${GLFW_BINARY_DIR}/docs 4 | COMMENT "Generating HTML documentation" VERBATIM) 5 | 6 | -------------------------------------------------------------------------------- /deps/glfw/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 | -------------------------------------------------------------------------------- /deps/glfw/docs/footer.html: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /deps/glfw/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 | -------------------------------------------------------------------------------- /deps/glfw/docs/internal.dox: -------------------------------------------------------------------------------- 1 | /*! 2 | 3 | @page internals 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_GLXGETPROCADDRESS` 115 | 116 | */ 117 | -------------------------------------------------------------------------------- /deps/glfw/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 creating windows 8 | with OpenGL or OpenGL ES contexts and receiving many kinds of input. It is easy 9 | to integrate into existing applications and does not lay claim to the main loop. 10 | 11 | See @ref news_31 for release highlights or the 12 | [version history](http://www.glfw.org/changelog.html) for details. 13 | 14 | @ref quick is a guide for those new to GLFW. It takes you through how to write 15 | a small but complete program. For people coming from GLFW 2, the @ref moving 16 | guide explains what has changed and how to update existing code to use the new 17 | API. 18 | 19 | There are guides for each of the various areas of the API. 20 | 21 | - @ref intro – initialization, error handling and high-level design 22 | - @ref window – creating and working with windows and framebuffers 23 | - @ref context – working with OpenGL and OpenGL ES contexts 24 | - @ref monitor – enumerating and working with monitors and video modes 25 | - @ref input – receiving events, polling and processing input 26 | 27 | Once you have written a program, see the @ref compile and @ref build guides. 28 | 29 | The [reference documentation](modules.html) provides more detailed information 30 | about specific functions. 31 | 32 | There is a section on @ref guarantees_limitations for pointer lifetimes, 33 | reentrancy, thread safety, event order and backward and forward compatibility. 34 | 35 | The @ref rift fills in the gaps for how to use LibOVR with GLFW. 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, the @ref compat guide explains what APIs, standards and protocols GLFW 41 | uses 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 | -------------------------------------------------------------------------------- /deps/glfw/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | link_libraries(glfw) 3 | 4 | if (BUILD_SHARED_LIBS) 5 | add_definitions(-DGLFW_DLL) 6 | link_libraries("${OPENGL_gl_LIBRARY}" "${MATH_LIBRARY}") 7 | else() 8 | link_libraries(${glfw_LIBRARIES}) 9 | endif() 10 | 11 | include_directories("${GLFW_SOURCE_DIR}/include" 12 | "${GLFW_SOURCE_DIR}/deps") 13 | 14 | if ("${OPENGL_INCLUDE_DIR}") 15 | include_directories("${OPENGL_INCLUDE_DIR}") 16 | endif() 17 | 18 | set(GLAD "${GLFW_SOURCE_DIR}/deps/glad/glad.h" 19 | "${GLFW_SOURCE_DIR}/deps/glad.c") 20 | set(GETOPT "${GLFW_SOURCE_DIR}/deps/getopt.h" 21 | "${GLFW_SOURCE_DIR}/deps/getopt.c") 22 | set(TINYCTHREAD "${GLFW_SOURCE_DIR}/deps/tinycthread.h" 23 | "${GLFW_SOURCE_DIR}/deps/tinycthread.c") 24 | 25 | add_executable(boing WIN32 MACOSX_BUNDLE boing.c) 26 | add_executable(gears WIN32 MACOSX_BUNDLE gears.c) 27 | add_executable(heightmap WIN32 MACOSX_BUNDLE heightmap.c ${GLAD}) 28 | add_executable(particles WIN32 MACOSX_BUNDLE particles.c ${TINYCTHREAD} ${GETOPT}) 29 | add_executable(simple WIN32 MACOSX_BUNDLE simple.c) 30 | add_executable(splitview WIN32 MACOSX_BUNDLE splitview.c) 31 | add_executable(wave WIN32 MACOSX_BUNDLE wave.c) 32 | 33 | target_link_libraries(particles "${CMAKE_THREAD_LIBS_INIT}" "${RT_LIBRARY}") 34 | 35 | set(WINDOWS_BINARIES boing gears heightmap particles simple splitview wave) 36 | 37 | set_target_properties(${WINDOWS_BINARIES} PROPERTIES FOLDER "GLFW3/Examples") 38 | 39 | if (MSVC) 40 | # Tell MSVC to use main instead of WinMain for Windows subsystem executables 41 | set_target_properties(${WINDOWS_BINARIES} PROPERTIES 42 | LINK_FLAGS "/ENTRY:mainCRTStartup") 43 | endif() 44 | 45 | if (APPLE) 46 | set_target_properties(boing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Boing") 47 | set_target_properties(gears PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gears") 48 | set_target_properties(heightmap PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Heightmap") 49 | set_target_properties(particles PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Particles") 50 | set_target_properties(simple PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Simple") 51 | set_target_properties(splitview PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Split View") 52 | set_target_properties(wave PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Wave") 53 | 54 | set_target_properties(${WINDOWS_BINARIES} PROPERTIES 55 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} 56 | MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL} 57 | MACOSX_BUNDLE_INFO_PLIST "${GLFW_SOURCE_DIR}/CMake/MacOSXBundleInfo.plist.in") 58 | endif() 59 | 60 | -------------------------------------------------------------------------------- /deps/glfw/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 | 29 | #include 30 | #include 31 | 32 | static void error_callback(int error, const char* description) 33 | { 34 | fputs(description, stderr); 35 | } 36 | 37 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 38 | { 39 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 40 | glfwSetWindowShouldClose(window, GL_TRUE); 41 | } 42 | 43 | int main(void) 44 | { 45 | GLFWwindow* window; 46 | 47 | glfwSetErrorCallback(error_callback); 48 | 49 | if (!glfwInit()) 50 | exit(EXIT_FAILURE); 51 | 52 | window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL); 53 | if (!window) 54 | { 55 | glfwTerminate(); 56 | exit(EXIT_FAILURE); 57 | } 58 | 59 | glfwMakeContextCurrent(window); 60 | glfwSwapInterval(1); 61 | 62 | glfwSetKeyCallback(window, key_callback); 63 | 64 | while (!glfwWindowShouldClose(window)) 65 | { 66 | float ratio; 67 | int width, height; 68 | 69 | glfwGetFramebufferSize(window, &width, &height); 70 | ratio = width / (float) height; 71 | 72 | glViewport(0, 0, width, height); 73 | glClear(GL_COLOR_BUFFER_BIT); 74 | 75 | glMatrixMode(GL_PROJECTION); 76 | glLoadIdentity(); 77 | glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f); 78 | glMatrixMode(GL_MODELVIEW); 79 | 80 | glLoadIdentity(); 81 | glRotatef((float) glfwGetTime() * 50.f, 0.f, 0.f, 1.f); 82 | 83 | glBegin(GL_TRIANGLES); 84 | glColor3f(1.f, 0.f, 0.f); 85 | glVertex3f(-0.6f, -0.4f, 0.f); 86 | glColor3f(0.f, 1.f, 0.f); 87 | glVertex3f(0.6f, -0.4f, 0.f); 88 | glColor3f(0.f, 0.f, 1.f); 89 | glVertex3f(0.f, 0.6f, 0.f); 90 | glEnd(); 91 | 92 | glfwSwapBuffers(window); 93 | glfwPollEvents(); 94 | } 95 | 96 | glfwDestroyWindow(window); 97 | 98 | glfwTerminate(); 99 | exit(EXIT_SUCCESS); 100 | } 101 | 102 | //! [code] 103 | -------------------------------------------------------------------------------- /deps/glfw/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories("${GLFW_SOURCE_DIR}/src" 3 | "${GLFW_BINARY_DIR}/src" 4 | ${glfw_INCLUDE_DIRS}) 5 | 6 | add_definitions(-D_GLFW_USE_CONFIG_H) 7 | 8 | set(common_HEADERS internal.h 9 | "${GLFW_BINARY_DIR}/src/glfw_config.h" 10 | "${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h" 11 | "${GLFW_SOURCE_DIR}/include/GLFW/glfw3native.h") 12 | set(common_SOURCES context.c init.c input.c monitor.c window.c) 13 | 14 | if (_GLFW_COCOA) 15 | set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h iokit_joystick.h 16 | posix_tls.h) 17 | set(glfw_SOURCES ${common_SOURCES} cocoa_init.m cocoa_monitor.m 18 | cocoa_window.m iokit_joystick.m mach_time.c posix_tls.c) 19 | elseif (_GLFW_WIN32) 20 | set(glfw_HEADERS ${common_HEADERS} win32_platform.h win32_tls.h 21 | winmm_joystick.h) 22 | set(glfw_SOURCES ${common_SOURCES} win32_init.c win32_monitor.c win32_time.c 23 | win32_tls.c win32_window.c winmm_joystick.c) 24 | elseif (_GLFW_X11) 25 | set(glfw_HEADERS ${common_HEADERS} x11_platform.h xkb_unicode.h 26 | linux_joystick.h posix_time.h posix_tls.h) 27 | set(glfw_SOURCES ${common_SOURCES} x11_init.c x11_monitor.c x11_window.c 28 | xkb_unicode.c linux_joystick.c posix_time.c posix_tls.c) 29 | elseif (_GLFW_WAYLAND) 30 | set(glfw_HEADERS ${common_HEADERS} wl_platform.h linux_joystick.h 31 | posix_time.h posix_tls.h xkb_unicode.h) 32 | set(glfw_SOURCES ${common_SOURCES} wl_init.c wl_monitor.c wl_window.c 33 | linux_joystick.c posix_time.c posix_tls.c xkb_unicode.c) 34 | elseif (_GLFW_MIR) 35 | set(glfw_HEADERS ${common_HEADERS} mir_platform.h linux_joystick.h 36 | posix_time.h posix_tls.h xkb_unicode.h) 37 | set(glfw_SOURCES ${common_SOURCES} mir_init.c mir_monitor.c mir_window.c 38 | linux_joystick.c posix_time.c posix_tls.c xkb_unicode.c) 39 | endif() 40 | 41 | if (_GLFW_EGL) 42 | list(APPEND glfw_HEADERS ${common_HEADERS} egl_context.h) 43 | list(APPEND glfw_SOURCES ${common_SOURCES} egl_context.c) 44 | elseif (_GLFW_NSGL) 45 | list(APPEND glfw_HEADERS ${common_HEADERS} nsgl_context.h) 46 | list(APPEND glfw_SOURCES ${common_SOURCES} nsgl_context.m) 47 | elseif (_GLFW_WGL) 48 | list(APPEND glfw_HEADERS ${common_HEADERS} wgl_context.h) 49 | list(APPEND glfw_SOURCES ${common_SOURCES} wgl_context.c) 50 | elseif (_GLFW_X11) 51 | list(APPEND glfw_HEADERS ${common_HEADERS} glx_context.h) 52 | list(APPEND glfw_SOURCES ${common_SOURCES} glx_context.c) 53 | endif() 54 | 55 | if (APPLE) 56 | # For some reason, CMake doesn't know about .m 57 | set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C) 58 | endif() 59 | 60 | add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) 61 | set_target_properties(glfw PROPERTIES 62 | OUTPUT_NAME "${GLFW_LIB_NAME}" 63 | VERSION ${GLFW_VERSION} 64 | SOVERSION ${GLFW_VERSION_MAJOR} 65 | POSITION_INDEPENDENT_CODE ON 66 | FOLDER "GLFW3") 67 | 68 | if (BUILD_SHARED_LIBS) 69 | if (WIN32) 70 | # The GLFW DLL needs a special compile-time macro and import library name 71 | set_target_properties(glfw PROPERTIES PREFIX "" IMPORT_PREFIX "") 72 | 73 | if (MINGW) 74 | set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.a") 75 | else() 76 | set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib") 77 | endif() 78 | elseif (APPLE) 79 | # Append -fno-common to the compile flags to work around a bug in 80 | # Apple's GCC 81 | get_target_property(glfw_CFLAGS glfw COMPILE_FLAGS) 82 | if (NOT glfw_CFLAGS) 83 | set(glfw_CFLAGS "") 84 | endif() 85 | set_target_properties(glfw PROPERTIES 86 | COMPILE_FLAGS "${glfw_CFLAGS} -fno-common" 87 | INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}") 88 | endif() 89 | 90 | target_link_libraries(glfw ${glfw_LIBRARIES}) 91 | endif() 92 | 93 | if (GLFW_INSTALL) 94 | install(TARGETS glfw EXPORT glfwTargets DESTINATION lib${LIB_SUFFIX}) 95 | endif() 96 | 97 | -------------------------------------------------------------------------------- /deps/glfw/src/cocoa_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 OS X - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2010 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 | 32 | #if defined(__OBJC__) 33 | #import 34 | #else 35 | #include 36 | typedef void* id; 37 | #endif 38 | 39 | #include "posix_tls.h" 40 | #include "iokit_joystick.h" 41 | 42 | #if defined(_GLFW_NSGL) 43 | #include "nsgl_context.h" 44 | #else 45 | #error "The Cocoa backend depends on NSGL platform support" 46 | #endif 47 | 48 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS ns 49 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns 50 | #define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimeNS ns_time 51 | #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorNS ns 52 | #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorNS ns 53 | 54 | 55 | // Cocoa-specific per-window data 56 | // 57 | typedef struct _GLFWwindowNS 58 | { 59 | id object; 60 | id delegate; 61 | id view; 62 | unsigned int modifierFlags; 63 | 64 | // The total sum of the distances the cursor has been warped 65 | // since the last cursor motion event was processed 66 | // This is kept to counteract Cocoa doing the same internally 67 | double warpDeltaX, warpDeltaY; 68 | 69 | } _GLFWwindowNS; 70 | 71 | 72 | // Cocoa-specific global data 73 | // 74 | typedef struct _GLFWlibraryNS 75 | { 76 | CGEventSourceRef eventSource; 77 | id delegate; 78 | id autoreleasePool; 79 | id cursor; 80 | 81 | short int publicKeys[256]; 82 | char* clipboardString; 83 | 84 | } _GLFWlibraryNS; 85 | 86 | 87 | // Cocoa-specific per-monitor data 88 | // 89 | typedef struct _GLFWmonitorNS 90 | { 91 | CGDirectDisplayID displayID; 92 | CGDisplayModeRef previousMode; 93 | uint32_t unitNumber; 94 | 95 | } _GLFWmonitorNS; 96 | 97 | 98 | // Cocoa-specific per-cursor data 99 | // 100 | typedef struct _GLFWcursorNS 101 | { 102 | id object; 103 | 104 | } _GLFWcursorNS; 105 | 106 | 107 | // Cocoa-specific global timer data 108 | // 109 | typedef struct _GLFWtimeNS 110 | { 111 | double base; 112 | double resolution; 113 | 114 | } _GLFWtimeNS; 115 | 116 | 117 | void _glfwInitTimer(void); 118 | 119 | GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired); 120 | void _glfwRestoreVideoMode(_GLFWmonitor* monitor); 121 | 122 | #endif // _glfw3_cocoa_platform_h_ 123 | -------------------------------------------------------------------------------- /deps/glfw/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 | -------------------------------------------------------------------------------- /deps/glfw/src/glfw3Config.cmake.in: -------------------------------------------------------------------------------- 1 | # - Config file for the glfw3 package 2 | # It defines the following variables 3 | # GLFW3_INCLUDE_DIR, the path where GLFW headers are located 4 | # GLFW3_LIBRARY_DIR, folder in which the GLFW library is located 5 | # GLFW3_LIBRARY, library to link against to use GLFW 6 | 7 | set(GLFW3_VERSION "@GLFW_VERSION_FULL@") 8 | 9 | @PACKAGE_INIT@ 10 | 11 | set_and_check(GLFW3_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/include") 12 | set_and_check(GLFW3_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/lib@LIB_SUFFIX@") 13 | 14 | find_library(GLFW3_LIBRARY "@GLFW_LIB_NAME@" HINTS ${GLFW3_LIBRARY_DIR}) 15 | 16 | -------------------------------------------------------------------------------- /deps/glfw/src/glfw_config.h.in: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2010 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 GLFW for EGL 49 | #cmakedefine _GLFW_EGL 50 | // Define this to 1 if building GLFW for GLX 51 | #cmakedefine _GLFW_GLX 52 | // Define this to 1 if building GLFW for WGL 53 | #cmakedefine _GLFW_WGL 54 | // Define this to 1 if building GLFW for NSGL 55 | #cmakedefine _GLFW_NSGL 56 | 57 | // Define this to 1 if building as a shared library / dynamic library / DLL 58 | #cmakedefine _GLFW_BUILD_DLL 59 | 60 | // Define this to 1 to force use of high-performance GPU on hybrid systems 61 | #cmakedefine _GLFW_USE_HYBRID_HPG 62 | 63 | // Define this to 1 if the XInput X11 extension is available 64 | #cmakedefine _GLFW_HAS_XINPUT 65 | // Define this to 1 if the Xxf86vm X11 extension is available 66 | #cmakedefine _GLFW_HAS_XF86VM 67 | 68 | // Define this to 1 if glfwInit should change the current directory 69 | #cmakedefine _GLFW_USE_CHDIR 70 | // Define this to 1 if glfwCreateWindow should populate the menu bar 71 | #cmakedefine _GLFW_USE_MENUBAR 72 | // Define this to 1 if windows should use full resolution on Retina displays 73 | #cmakedefine _GLFW_USE_RETINA 74 | 75 | // Define this to 1 if using OpenGL as the client library 76 | #cmakedefine _GLFW_USE_OPENGL 77 | // Define this to 1 if using OpenGL ES 1.1 as the client library 78 | #cmakedefine _GLFW_USE_GLESV1 79 | // Define this to 1 if using OpenGL ES 2.0 as the client library 80 | #cmakedefine _GLFW_USE_GLESV2 81 | 82 | -------------------------------------------------------------------------------- /deps/glfw/src/glx_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 GLX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 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_glx_context_h_ 29 | #define _glfw3_glx_context_h_ 30 | 31 | #define GLX_GLXEXT_LEGACY 32 | #include 33 | 34 | // This path may need to be changed if you build GLFW using your own setup 35 | // We ship and use our own copy of glxext.h since GLFW uses fairly new 36 | // extensions and not all operating systems come with an up-to-date version 37 | #define GLX_GLXEXT_PROTOTYPES 38 | #include "../deps/GL/glxext.h" 39 | 40 | // libGL.so function pointer typedefs 41 | typedef int (*PFNGLXGETFBCONFIGATTRIBPROC)(Display*,GLXFBConfig,int,int*); 42 | typedef const char* (*PFNGLXGETCLIENTSTRINGPROC)(Display*,int); 43 | typedef Bool (*PFNGLXQUERYEXTENSIONPROC)(Display*,int*,int*); 44 | typedef Bool (*PFNGLXQUERYVERSIONPROC)(Display*,int*,int*); 45 | typedef void (*PFNGLXDESTROYCONTEXTPROC)(Display*,GLXContext); 46 | typedef Bool (*PFNGLXMAKECURRENTPROC)(Display*,GLXDrawable,GLXContext); 47 | typedef void (*PFNGLXSWAPBUFFERSPROC)(Display*,GLXDrawable); 48 | typedef const char* (*PFNGLXQUERYEXTENSIONSSTRINGPROC)(Display*,int); 49 | #define _glfw_glXGetFBConfigs _glfw.glx.GetFBConfigs 50 | #define _glfw_glXGetFBConfigAttrib _glfw.glx.GetFBConfigAttrib 51 | #define _glfw_glXGetClientString _glfw.glx.GetClientString 52 | #define _glfw_glXQueryExtension _glfw.glx.QueryExtension 53 | #define _glfw_glXQueryVersion _glfw.glx.QueryVersion 54 | #define _glfw_glXDestroyContext _glfw.glx.DestroyContext 55 | #define _glfw_glXMakeCurrent _glfw.glx.MakeCurrent 56 | #define _glfw_glXSwapBuffers _glfw.glx.SwapBuffers 57 | #define _glfw_glXQueryExtensionsString _glfw.glx.QueryExtensionsString 58 | #define _glfw_glXCreateNewContext _glfw.glx.CreateNewContext 59 | #define _glfw_glXGetVisualFromFBConfig _glfw.glx.GetVisualFromFBConfig 60 | 61 | #define _GLFW_PLATFORM_FBCONFIG GLXFBConfig glx 62 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX glx 63 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryGLX glx 64 | 65 | #ifndef GLX_MESA_swap_control 66 | typedef int (*PFNGLXSWAPINTERVALMESAPROC)(int); 67 | #endif 68 | 69 | 70 | // GLX-specific per-context data 71 | // 72 | typedef struct _GLFWcontextGLX 73 | { 74 | // Rendering context 75 | GLXContext context; 76 | // Visual of selected GLXFBConfig 77 | XVisualInfo* visual; 78 | 79 | } _GLFWcontextGLX; 80 | 81 | 82 | // GLX-specific global data 83 | // 84 | typedef struct _GLFWlibraryGLX 85 | { 86 | int major, minor; 87 | int eventBase; 88 | int errorBase; 89 | 90 | // dlopen handle for libGL.so.1 91 | void* handle; 92 | 93 | // GLX 1.3 functions 94 | PFNGLXGETFBCONFIGSPROC GetFBConfigs; 95 | PFNGLXGETFBCONFIGATTRIBPROC GetFBConfigAttrib; 96 | PFNGLXGETCLIENTSTRINGPROC GetClientString; 97 | PFNGLXQUERYEXTENSIONPROC QueryExtension; 98 | PFNGLXQUERYVERSIONPROC QueryVersion; 99 | PFNGLXDESTROYCONTEXTPROC DestroyContext; 100 | PFNGLXMAKECURRENTPROC MakeCurrent; 101 | PFNGLXSWAPBUFFERSPROC SwapBuffers; 102 | PFNGLXQUERYEXTENSIONSSTRINGPROC QueryExtensionsString; 103 | PFNGLXCREATENEWCONTEXTPROC CreateNewContext; 104 | PFNGLXGETVISUALFROMFBCONFIGPROC GetVisualFromFBConfig; 105 | 106 | // GLX 1.4 and extension functions 107 | PFNGLXGETPROCADDRESSPROC GetProcAddress; 108 | PFNGLXGETPROCADDRESSPROC GetProcAddressARB; 109 | PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI; 110 | PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT; 111 | PFNGLXSWAPINTERVALMESAPROC SwapIntervalMESA; 112 | PFNGLXCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; 113 | GLboolean SGI_swap_control; 114 | GLboolean EXT_swap_control; 115 | GLboolean MESA_swap_control; 116 | GLboolean ARB_multisample; 117 | GLboolean ARB_framebuffer_sRGB; 118 | GLboolean EXT_framebuffer_sRGB; 119 | GLboolean ARB_create_context; 120 | GLboolean ARB_create_context_profile; 121 | GLboolean ARB_create_context_robustness; 122 | GLboolean EXT_create_context_es2_profile; 123 | GLboolean ARB_context_flush_control; 124 | 125 | } _GLFWlibraryGLX; 126 | 127 | 128 | int _glfwInitContextAPI(void); 129 | void _glfwTerminateContextAPI(void); 130 | int _glfwCreateContext(_GLFWwindow* window, 131 | const _GLFWctxconfig* ctxconfig, 132 | const _GLFWfbconfig* fbconfig); 133 | void _glfwDestroyContext(_GLFWwindow* window); 134 | 135 | #endif // _glfw3_glx_context_h_ 136 | -------------------------------------------------------------------------------- /deps/glfw/src/init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 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 | GLboolean _glfwInitialized = GL_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 client API is unavailable"; 69 | case GLFW_VERSION_UNAVAILABLE: 70 | return "The requested client 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 | } 76 | 77 | return "ERROR: UNKNOWN ERROR TOKEN PASSED TO glfwErrorString"; 78 | } 79 | 80 | 81 | ////////////////////////////////////////////////////////////////////////// 82 | ////// GLFW event API ////// 83 | ////////////////////////////////////////////////////////////////////////// 84 | 85 | void _glfwInputError(int error, const char* format, ...) 86 | { 87 | if (_glfwErrorCallback) 88 | { 89 | char buffer[8192]; 90 | const char* description; 91 | 92 | if (format) 93 | { 94 | int count; 95 | va_list vl; 96 | 97 | va_start(vl, format); 98 | count = vsnprintf(buffer, sizeof(buffer), format, vl); 99 | va_end(vl); 100 | 101 | if (count < 0) 102 | buffer[sizeof(buffer) - 1] = '\0'; 103 | 104 | description = buffer; 105 | } 106 | else 107 | description = getErrorString(error); 108 | 109 | _glfwErrorCallback(error, description); 110 | } 111 | } 112 | 113 | 114 | ////////////////////////////////////////////////////////////////////////// 115 | ////// GLFW public API ////// 116 | ////////////////////////////////////////////////////////////////////////// 117 | 118 | GLFWAPI int glfwInit(void) 119 | { 120 | if (_glfwInitialized) 121 | return GL_TRUE; 122 | 123 | memset(&_glfw, 0, sizeof(_glfw)); 124 | 125 | if (!_glfwPlatformInit()) 126 | { 127 | _glfwPlatformTerminate(); 128 | return GL_FALSE; 129 | } 130 | 131 | _glfw.monitors = _glfwPlatformGetMonitors(&_glfw.monitorCount); 132 | _glfwInitialized = GL_TRUE; 133 | 134 | // Not all window hints have zero as their default value 135 | glfwDefaultWindowHints(); 136 | 137 | return GL_TRUE; 138 | } 139 | 140 | GLFWAPI void glfwTerminate(void) 141 | { 142 | int i; 143 | 144 | if (!_glfwInitialized) 145 | return; 146 | 147 | memset(&_glfw.callbacks, 0, sizeof(_glfw.callbacks)); 148 | 149 | while (_glfw.windowListHead) 150 | glfwDestroyWindow((GLFWwindow*) _glfw.windowListHead); 151 | 152 | while (_glfw.cursorListHead) 153 | glfwDestroyCursor((GLFWcursor*) _glfw.cursorListHead); 154 | 155 | for (i = 0; i < _glfw.monitorCount; i++) 156 | { 157 | _GLFWmonitor* monitor = _glfw.monitors[i]; 158 | if (monitor->originalRamp.size) 159 | _glfwPlatformSetGammaRamp(monitor, &monitor->originalRamp); 160 | } 161 | 162 | _glfwFreeMonitors(_glfw.monitors, _glfw.monitorCount); 163 | _glfw.monitors = NULL; 164 | _glfw.monitorCount = 0; 165 | 166 | _glfwPlatformTerminate(); 167 | 168 | memset(&_glfw, 0, sizeof(_glfw)); 169 | _glfwInitialized = GL_FALSE; 170 | } 171 | 172 | GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev) 173 | { 174 | if (major != NULL) 175 | *major = GLFW_VERSION_MAJOR; 176 | 177 | if (minor != NULL) 178 | *minor = GLFW_VERSION_MINOR; 179 | 180 | if (rev != NULL) 181 | *rev = GLFW_VERSION_REVISION; 182 | } 183 | 184 | GLFWAPI const char* glfwGetVersionString(void) 185 | { 186 | return _glfwPlatformGetVersionString(); 187 | } 188 | 189 | GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun) 190 | { 191 | _GLFW_SWAP_POINTERS(_glfwErrorCallback, cbfun); 192 | return cbfun; 193 | } 194 | 195 | -------------------------------------------------------------------------------- /deps/glfw/src/iokit_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 IOKit - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2014 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_iokit_joystick_h_ 28 | #define _glfw3_iokit_joystick_h_ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ 36 | _GLFWjoystickIOKit iokit_js 37 | 38 | 39 | // IOKit-specific per-joystick data 40 | // 41 | typedef struct _GLFWjoydevice 42 | { 43 | int 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 | } _GLFWjoydevice; 55 | 56 | // IOKit-specific joystick API data 57 | // 58 | typedef struct _GLFWjoystickIOKit 59 | { 60 | _GLFWjoydevice devices[GLFW_JOYSTICK_LAST + 1]; 61 | 62 | IOHIDManagerRef managerRef; 63 | } _GLFWjoystickIOKit; 64 | 65 | void _glfwInitJoysticks(void); 66 | void _glfwTerminateJoysticks(void); 67 | 68 | #endif // _glfw3_iokit_joystick_h_ 69 | -------------------------------------------------------------------------------- /deps/glfw/src/linux_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 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 \ 33 | _GLFWjoystickLinux linux_js 34 | 35 | 36 | // Linux-specific joystick API data 37 | // 38 | typedef struct _GLFWjoystickLinux 39 | { 40 | struct 41 | { 42 | int present; 43 | int fd; 44 | float* axes; 45 | int axisCount; 46 | unsigned char* buttons; 47 | int buttonCount; 48 | char* name; 49 | char* path; 50 | } js[GLFW_JOYSTICK_LAST + 1]; 51 | 52 | #if defined(__linux__) 53 | int inotify; 54 | int watch; 55 | regex_t regex; 56 | #endif /*__linux__*/ 57 | } _GLFWjoystickLinux; 58 | 59 | 60 | int _glfwInitJoysticks(void); 61 | void _glfwTerminateJoysticks(void); 62 | 63 | #endif // _glfw3_linux_joystick_h_ 64 | -------------------------------------------------------------------------------- /deps/glfw/src/mach_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 OS X - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2010 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 | // Return raw time 33 | // 34 | static uint64_t getRawTime(void) 35 | { 36 | return mach_absolute_time(); 37 | } 38 | 39 | 40 | ////////////////////////////////////////////////////////////////////////// 41 | ////// GLFW internal API ////// 42 | ////////////////////////////////////////////////////////////////////////// 43 | 44 | // Initialise timer 45 | // 46 | void _glfwInitTimer(void) 47 | { 48 | mach_timebase_info_data_t info; 49 | mach_timebase_info(&info); 50 | 51 | _glfw.ns_time.resolution = (double) info.numer / (info.denom * 1.0e9); 52 | _glfw.ns_time.base = getRawTime(); 53 | } 54 | 55 | 56 | ////////////////////////////////////////////////////////////////////////// 57 | ////// GLFW platform API ////// 58 | ////////////////////////////////////////////////////////////////////////// 59 | 60 | double _glfwPlatformGetTime(void) 61 | { 62 | return (double) (getRawTime() - _glfw.ns_time.base) * 63 | _glfw.ns_time.resolution; 64 | } 65 | 66 | void _glfwPlatformSetTime(double time) 67 | { 68 | _glfw.ns_time.base = getRawTime() - 69 | (uint64_t) (time / _glfw.ns_time.resolution); 70 | } 71 | 72 | -------------------------------------------------------------------------------- /deps/glfw/src/mir_init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 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 | #include 31 | 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW internal API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | int _glfwPlatformInit(void) 38 | { 39 | int error; 40 | 41 | _glfw.mir.connection = mir_connect_sync(NULL, __PRETTY_FUNCTION__); 42 | 43 | if (!mir_connection_is_valid(_glfw.mir.connection)) 44 | { 45 | _glfwInputError(GLFW_PLATFORM_ERROR, 46 | "Mir: Unable to connect to server: %s", 47 | mir_connection_get_error_message(_glfw.mir.connection)); 48 | 49 | return GL_FALSE; 50 | } 51 | 52 | _glfw.mir.display = 53 | mir_connection_get_egl_native_display(_glfw.mir.connection); 54 | 55 | if (!_glfwInitContextAPI()) 56 | return GL_FALSE; 57 | 58 | // Need the default conf for when we set a NULL cursor 59 | _glfw.mir.default_conf = mir_cursor_configuration_from_name(mir_arrow_cursor_name); 60 | 61 | _glfwInitTimer(); 62 | _glfwInitJoysticks(); 63 | 64 | _glfw.mir.event_queue = calloc(1, sizeof(EventQueue)); 65 | _glfwInitEventQueue(_glfw.mir.event_queue); 66 | 67 | error = pthread_mutex_init(&_glfw.mir.event_mutex, NULL); 68 | if (error) 69 | { 70 | _glfwInputError(GLFW_PLATFORM_ERROR, 71 | "Mir: Failed to create event mutex: %s", 72 | strerror(error)); 73 | return GL_FALSE; 74 | } 75 | 76 | return GL_TRUE; 77 | } 78 | 79 | void _glfwPlatformTerminate(void) 80 | { 81 | _glfwTerminateContextAPI(); 82 | _glfwTerminateJoysticks(); 83 | 84 | _glfwDeleteEventQueue(_glfw.mir.event_queue); 85 | 86 | pthread_mutex_destroy(&_glfw.mir.event_mutex); 87 | 88 | mir_connection_release(_glfw.mir.connection); 89 | } 90 | 91 | const char* _glfwPlatformGetVersionString(void) 92 | { 93 | return _GLFW_VERSION_NUMBER " Mir EGL" 94 | #if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK) 95 | " clock_gettime" 96 | #else 97 | " gettimeofday" 98 | #endif 99 | #if defined(__linux__) 100 | " /dev/js" 101 | #endif 102 | #if defined(_GLFW_BUILD_DLL) 103 | " shared" 104 | #endif 105 | ; 106 | } 107 | 108 | -------------------------------------------------------------------------------- /deps/glfw/src/mir_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 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 | GLboolean _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 | -------------------------------------------------------------------------------- /deps/glfw/src/mir_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 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 | 33 | #include 34 | 35 | #include "posix_tls.h" 36 | #include "posix_time.h" 37 | #include "linux_joystick.h" 38 | #include "xkb_unicode.h" 39 | 40 | #if defined(_GLFW_EGL) 41 | #include "egl_context.h" 42 | #else 43 | #error "The Mir backend depends on EGL platform support" 44 | #endif 45 | 46 | #define _GLFW_EGL_NATIVE_WINDOW window->mir.window 47 | #define _GLFW_EGL_NATIVE_DISPLAY _glfw.mir.display 48 | 49 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowMir mir 50 | #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorMir mir 51 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryMir mir 52 | #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorMir mir 53 | 54 | 55 | // Mir-specific Event Queue 56 | // 57 | typedef struct EventQueue 58 | { 59 | TAILQ_HEAD(, EventNode) head; 60 | } EventQueue; 61 | 62 | // Mir-specific per-window data 63 | // 64 | typedef struct _GLFWwindowMir 65 | { 66 | MirSurface* surface; 67 | int width; 68 | int height; 69 | MirEGLNativeWindowType window; 70 | 71 | } _GLFWwindowMir; 72 | 73 | 74 | // Mir-specific per-monitor data 75 | // 76 | typedef struct _GLFWmonitorMir 77 | { 78 | int cur_mode; 79 | int output_id; 80 | int x; 81 | int y; 82 | 83 | } _GLFWmonitorMir; 84 | 85 | 86 | // Mir-specific global data 87 | // 88 | typedef struct _GLFWlibraryMir 89 | { 90 | MirConnection* connection; 91 | MirEGLNativeDisplayType display; 92 | MirCursorConfiguration* default_conf; 93 | EventQueue* event_queue; 94 | 95 | pthread_mutex_t event_mutex; 96 | pthread_cond_t event_cond; 97 | 98 | } _GLFWlibraryMir; 99 | 100 | 101 | // Mir-specific per-cursor data 102 | // TODO: Only system cursors are implemented in Mir atm. Need to wait for support. 103 | // 104 | typedef struct _GLFWcursorMir 105 | { 106 | MirCursorConfiguration* conf; 107 | MirBufferStream* custom_cursor; 108 | } _GLFWcursorMir; 109 | 110 | 111 | extern void _glfwInitEventQueue(EventQueue* queue); 112 | extern void _glfwDeleteEventQueue(EventQueue* queue); 113 | 114 | #endif // _glfw3_mir_platform_h_ 115 | -------------------------------------------------------------------------------- /deps/glfw/src/nsgl_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 OS X - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2010 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_FBCONFIG 31 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL nsgl 32 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryNSGL nsgl 33 | 34 | 35 | // NSGL-specific per-context data 36 | // 37 | typedef struct _GLFWcontextNSGL 38 | { 39 | id pixelFormat; 40 | id context; 41 | 42 | } _GLFWcontextNSGL; 43 | 44 | 45 | // NSGL-specific global data 46 | // 47 | typedef struct _GLFWlibraryNSGL 48 | { 49 | // dlopen handle for OpenGL.framework (for glfwGetProcAddress) 50 | void* framework; 51 | 52 | } _GLFWlibraryNSGL; 53 | 54 | 55 | int _glfwInitContextAPI(void); 56 | void _glfwTerminateContextAPI(void); 57 | int _glfwCreateContext(_GLFWwindow* window, 58 | const _GLFWctxconfig* ctxconfig, 59 | const _GLFWfbconfig* fbconfig); 60 | void _glfwDestroyContext(_GLFWwindow* window); 61 | 62 | #endif // _glfw3_nsgl_context_h_ 63 | -------------------------------------------------------------------------------- /deps/glfw/src/posix_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 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 | // Return raw time 34 | // 35 | static uint64_t getRawTime(void) 36 | { 37 | #if defined(CLOCK_MONOTONIC) 38 | if (_glfw.posix_time.monotonic) 39 | { 40 | struct timespec ts; 41 | 42 | clock_gettime(CLOCK_MONOTONIC, &ts); 43 | return (uint64_t) ts.tv_sec * (uint64_t) 1000000000 + (uint64_t) ts.tv_nsec; 44 | } 45 | else 46 | #endif 47 | { 48 | struct timeval tv; 49 | 50 | gettimeofday(&tv, NULL); 51 | return (uint64_t) tv.tv_sec * (uint64_t) 1000000 + (uint64_t) tv.tv_usec; 52 | } 53 | } 54 | 55 | 56 | ////////////////////////////////////////////////////////////////////////// 57 | ////// GLFW internal API ////// 58 | ////////////////////////////////////////////////////////////////////////// 59 | 60 | // Initialise timer 61 | // 62 | void _glfwInitTimer(void) 63 | { 64 | #if defined(CLOCK_MONOTONIC) 65 | struct timespec ts; 66 | 67 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) 68 | { 69 | _glfw.posix_time.monotonic = GL_TRUE; 70 | _glfw.posix_time.resolution = 1e-9; 71 | } 72 | else 73 | #endif 74 | { 75 | _glfw.posix_time.resolution = 1e-6; 76 | } 77 | 78 | _glfw.posix_time.base = getRawTime(); 79 | } 80 | 81 | 82 | ////////////////////////////////////////////////////////////////////////// 83 | ////// GLFW platform API ////// 84 | ////////////////////////////////////////////////////////////////////////// 85 | 86 | double _glfwPlatformGetTime(void) 87 | { 88 | return (double) (getRawTime() - _glfw.posix_time.base) * 89 | _glfw.posix_time.resolution; 90 | } 91 | 92 | void _glfwPlatformSetTime(double time) 93 | { 94 | _glfw.posix_time.base = getRawTime() - 95 | (uint64_t) (time / _glfw.posix_time.resolution); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /deps/glfw/src/posix_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 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 | GLboolean monotonic; 41 | double resolution; 42 | uint64_t base; 43 | 44 | } _GLFWtimePOSIX; 45 | 46 | 47 | void _glfwInitTimer(void); 48 | 49 | #endif // _glfw3_posix_time_h_ 50 | -------------------------------------------------------------------------------- /deps/glfw/src/posix_tls.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 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 | int _glfwCreateContextTLS(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 GL_FALSE; 42 | } 43 | 44 | return GL_TRUE; 45 | } 46 | 47 | void _glfwDestroyContextTLS(void) 48 | { 49 | pthread_key_delete(_glfw.posix_tls.context); 50 | } 51 | 52 | void _glfwSetContextTLS(_GLFWwindow* context) 53 | { 54 | pthread_setspecific(_glfw.posix_tls.context, context); 55 | } 56 | 57 | 58 | ////////////////////////////////////////////////////////////////////////// 59 | ////// GLFW platform API ////// 60 | ////////////////////////////////////////////////////////////////////////// 61 | 62 | _GLFWwindow* _glfwPlatformGetCurrentContext(void) 63 | { 64 | return pthread_getspecific(_glfw.posix_tls.context); 65 | } 66 | 67 | -------------------------------------------------------------------------------- /deps/glfw/src/posix_tls.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 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 | pthread_key_t context; 41 | 42 | } _GLFWtlsPOSIX; 43 | 44 | 45 | int _glfwCreateContextTLS(void); 46 | void _glfwDestroyContextTLS(void); 47 | void _glfwSetContextTLS(_GLFWwindow* context); 48 | 49 | #endif // _glfw3_posix_tls_h_ 50 | -------------------------------------------------------------------------------- /deps/glfw/src/wgl_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 WGL - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 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 | // This path may need to be changed if you build GLFW using your own setup 32 | // We ship and use our own copy of wglext.h since GLFW uses fairly new 33 | // extensions and not all operating systems come with an up-to-date version 34 | #include "../deps/GL/wglext.h" 35 | 36 | // opengl32.dll function pointer typedefs 37 | typedef HGLRC (WINAPI * WGLCREATECONTEXT_T)(HDC); 38 | typedef BOOL (WINAPI * WGLDELETECONTEXT_T)(HGLRC); 39 | typedef PROC (WINAPI * WGLGETPROCADDRESS_T)(LPCSTR); 40 | typedef BOOL (WINAPI * WGLMAKECURRENT_T)(HDC,HGLRC); 41 | typedef BOOL (WINAPI * WGLSHARELISTS_T)(HGLRC,HGLRC); 42 | #define _glfw_wglCreateContext _glfw.wgl.opengl32.CreateContext 43 | #define _glfw_wglDeleteContext _glfw.wgl.opengl32.DeleteContext 44 | #define _glfw_wglGetProcAddress _glfw.wgl.opengl32.GetProcAddress 45 | #define _glfw_wglMakeCurrent _glfw.wgl.opengl32.MakeCurrent 46 | #define _glfw_wglShareLists _glfw.wgl.opengl32.ShareLists 47 | 48 | #define _GLFW_PLATFORM_FBCONFIG int wgl 49 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL wgl 50 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryWGL wgl 51 | 52 | 53 | // WGL-specific per-context data 54 | // 55 | typedef struct _GLFWcontextWGL 56 | { 57 | HDC dc; // Private GDI device context 58 | HGLRC context; // Permanent rendering context 59 | int interval; 60 | 61 | // WGL extensions (context specific) 62 | PFNWGLSWAPINTERVALEXTPROC SwapIntervalEXT; 63 | PFNWGLGETPIXELFORMATATTRIBIVARBPROC GetPixelFormatAttribivARB; 64 | PFNWGLGETEXTENSIONSSTRINGEXTPROC GetExtensionsStringEXT; 65 | PFNWGLGETEXTENSIONSSTRINGARBPROC GetExtensionsStringARB; 66 | PFNWGLCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; 67 | GLboolean EXT_swap_control; 68 | GLboolean ARB_multisample; 69 | GLboolean ARB_framebuffer_sRGB; 70 | GLboolean EXT_framebuffer_sRGB; 71 | GLboolean ARB_pixel_format; 72 | GLboolean ARB_create_context; 73 | GLboolean ARB_create_context_profile; 74 | GLboolean EXT_create_context_es2_profile; 75 | GLboolean ARB_create_context_robustness; 76 | GLboolean ARB_context_flush_control; 77 | 78 | } _GLFWcontextWGL; 79 | 80 | 81 | // WGL-specific global data 82 | // 83 | typedef struct _GLFWlibraryWGL 84 | { 85 | struct { 86 | HINSTANCE instance; 87 | WGLCREATECONTEXT_T CreateContext; 88 | WGLDELETECONTEXT_T DeleteContext; 89 | WGLGETPROCADDRESS_T GetProcAddress; 90 | WGLMAKECURRENT_T MakeCurrent; 91 | WGLSHARELISTS_T ShareLists; 92 | } opengl32; 93 | 94 | } _GLFWlibraryWGL; 95 | 96 | 97 | int _glfwInitContextAPI(void); 98 | void _glfwTerminateContextAPI(void); 99 | int _glfwCreateContext(_GLFWwindow* window, 100 | const _GLFWctxconfig* ctxconfig, 101 | const _GLFWfbconfig* fbconfig); 102 | void _glfwDestroyContext(_GLFWwindow* window); 103 | int _glfwAnalyzeContext(const _GLFWwindow* window, 104 | const _GLFWctxconfig* ctxconfig, 105 | const _GLFWfbconfig* fbconfig); 106 | 107 | #endif // _glfw3_wgl_context_h_ 108 | -------------------------------------------------------------------------------- /deps/glfw/src/win32_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 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 | // Return raw time 32 | // 33 | static unsigned __int64 getRawTime(void) 34 | { 35 | if (_glfw.win32_time.hasPC) 36 | { 37 | unsigned __int64 time; 38 | QueryPerformanceCounter((LARGE_INTEGER*) &time); 39 | return time; 40 | } 41 | else 42 | return (unsigned __int64) _glfw_timeGetTime(); 43 | } 44 | 45 | 46 | ////////////////////////////////////////////////////////////////////////// 47 | ////// GLFW internal API ////// 48 | ////////////////////////////////////////////////////////////////////////// 49 | 50 | // Initialise timer 51 | // 52 | void _glfwInitTimer(void) 53 | { 54 | unsigned __int64 frequency; 55 | 56 | if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency)) 57 | { 58 | _glfw.win32_time.hasPC = GL_TRUE; 59 | _glfw.win32_time.resolution = 1.0 / (double) frequency; 60 | } 61 | else 62 | { 63 | _glfw.win32_time.hasPC = GL_FALSE; 64 | _glfw.win32_time.resolution = 0.001; // winmm resolution is 1 ms 65 | } 66 | 67 | _glfw.win32_time.base = getRawTime(); 68 | } 69 | 70 | 71 | ////////////////////////////////////////////////////////////////////////// 72 | ////// GLFW platform API ////// 73 | ////////////////////////////////////////////////////////////////////////// 74 | 75 | double _glfwPlatformGetTime(void) 76 | { 77 | return (double) (getRawTime() - _glfw.win32_time.base) * 78 | _glfw.win32_time.resolution; 79 | } 80 | 81 | void _glfwPlatformSetTime(double time) 82 | { 83 | _glfw.win32_time.base = getRawTime() - 84 | (unsigned __int64) (time / _glfw.win32_time.resolution); 85 | } 86 | 87 | -------------------------------------------------------------------------------- /deps/glfw/src/win32_tls.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 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 | int _glfwCreateContextTLS(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 GL_FALSE; 43 | } 44 | 45 | _glfw.win32_tls.allocated = GL_TRUE; 46 | return GL_TRUE; 47 | } 48 | 49 | void _glfwDestroyContextTLS(void) 50 | { 51 | if (_glfw.win32_tls.allocated) 52 | TlsFree(_glfw.win32_tls.context); 53 | } 54 | 55 | void _glfwSetContextTLS(_GLFWwindow* context) 56 | { 57 | TlsSetValue(_glfw.win32_tls.context, context); 58 | } 59 | 60 | 61 | ////////////////////////////////////////////////////////////////////////// 62 | ////// GLFW platform API ////// 63 | ////////////////////////////////////////////////////////////////////////// 64 | 65 | _GLFWwindow* _glfwPlatformGetCurrentContext(void) 66 | { 67 | return TlsGetValue(_glfw.win32_tls.context); 68 | } 69 | 70 | -------------------------------------------------------------------------------- /deps/glfw/src/win32_tls.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 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_win32_tls_h_ 29 | #define _glfw3_win32_tls_h_ 30 | 31 | #define _GLFW_PLATFORM_LIBRARY_TLS_STATE _GLFWtlsWin32 win32_tls 32 | 33 | 34 | // Win32-specific global TLS data 35 | // 36 | typedef struct _GLFWtlsWin32 37 | { 38 | GLboolean allocated; 39 | DWORD context; 40 | 41 | } _GLFWtlsWin32; 42 | 43 | 44 | int _glfwCreateContextTLS(void); 45 | void _glfwDestroyContextTLS(void); 46 | void _glfwSetContextTLS(_GLFWwindow* context); 47 | 48 | #endif // _glfw3_win32_tls_h_ 49 | -------------------------------------------------------------------------------- /deps/glfw/src/winmm_joystick.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 WinMM - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 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 | 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW internal API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | // Convert axis value to the [-1,1] range 38 | // 39 | static float normalizeAxis(DWORD pos, DWORD min, DWORD max) 40 | { 41 | float fpos = (float) pos; 42 | float fmin = (float) min; 43 | float fmax = (float) max; 44 | 45 | return (2.f * (fpos - fmin) / (fmax - fmin)) - 1.f; 46 | } 47 | 48 | 49 | ////////////////////////////////////////////////////////////////////////// 50 | ////// GLFW internal API ////// 51 | ////////////////////////////////////////////////////////////////////////// 52 | 53 | // Initialize joystick interface 54 | // 55 | void _glfwInitJoysticks(void) 56 | { 57 | } 58 | 59 | // Close all opened joystick handles 60 | // 61 | void _glfwTerminateJoysticks(void) 62 | { 63 | int i; 64 | 65 | for (i = 0; i < GLFW_JOYSTICK_LAST; i++) 66 | free(_glfw.winmm_js[i].name); 67 | } 68 | 69 | 70 | ////////////////////////////////////////////////////////////////////////// 71 | ////// GLFW platform API ////// 72 | ////////////////////////////////////////////////////////////////////////// 73 | 74 | int _glfwPlatformJoystickPresent(int joy) 75 | { 76 | JOYINFO ji; 77 | 78 | if (_glfw_joyGetPos(joy, &ji) != JOYERR_NOERROR) 79 | return GL_FALSE; 80 | 81 | return GL_TRUE; 82 | } 83 | 84 | const float* _glfwPlatformGetJoystickAxes(int joy, int* count) 85 | { 86 | JOYCAPS jc; 87 | JOYINFOEX ji; 88 | float* axes = _glfw.winmm_js[joy].axes; 89 | 90 | if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR) 91 | return NULL; 92 | 93 | ji.dwSize = sizeof(JOYINFOEX); 94 | ji.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ | 95 | JOY_RETURNR | JOY_RETURNU | JOY_RETURNV; 96 | if (_glfw_joyGetPosEx(joy, &ji) != JOYERR_NOERROR) 97 | return NULL; 98 | 99 | axes[(*count)++] = normalizeAxis(ji.dwXpos, jc.wXmin, jc.wXmax); 100 | axes[(*count)++] = normalizeAxis(ji.dwYpos, jc.wYmin, jc.wYmax); 101 | 102 | if (jc.wCaps & JOYCAPS_HASZ) 103 | axes[(*count)++] = normalizeAxis(ji.dwZpos, jc.wZmin, jc.wZmax); 104 | 105 | if (jc.wCaps & JOYCAPS_HASR) 106 | axes[(*count)++] = normalizeAxis(ji.dwRpos, jc.wRmin, jc.wRmax); 107 | 108 | if (jc.wCaps & JOYCAPS_HASU) 109 | axes[(*count)++] = normalizeAxis(ji.dwUpos, jc.wUmin, jc.wUmax); 110 | 111 | if (jc.wCaps & JOYCAPS_HASV) 112 | axes[(*count)++] = normalizeAxis(ji.dwVpos, jc.wVmin, jc.wVmax); 113 | 114 | return axes; 115 | } 116 | 117 | const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count) 118 | { 119 | JOYCAPS jc; 120 | JOYINFOEX ji; 121 | unsigned char* buttons = _glfw.winmm_js[joy].buttons; 122 | 123 | if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR) 124 | return NULL; 125 | 126 | ji.dwSize = sizeof(JOYINFOEX); 127 | ji.dwFlags = JOY_RETURNBUTTONS | JOY_RETURNPOV; 128 | if (_glfw_joyGetPosEx(joy, &ji) != JOYERR_NOERROR) 129 | return NULL; 130 | 131 | while (*count < (int) jc.wNumButtons) 132 | { 133 | buttons[*count] = (unsigned char) 134 | (ji.dwButtons & (1UL << *count) ? GLFW_PRESS : GLFW_RELEASE); 135 | (*count)++; 136 | } 137 | 138 | // Virtual buttons - Inject data from hats 139 | // Each hat is exposed as 4 buttons which exposes 8 directions with 140 | // concurrent button presses 141 | // NOTE: this API exposes only one hat 142 | 143 | if ((jc.wCaps & JOYCAPS_HASPOV) && (jc.wCaps & JOYCAPS_POV4DIR)) 144 | { 145 | int i, value = ji.dwPOV / 100 / 45; 146 | 147 | // Bit fields of button presses for each direction, including nil 148 | const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 }; 149 | 150 | if (value < 0 || value > 8) 151 | value = 8; 152 | 153 | for (i = 0; i < 4; i++) 154 | { 155 | if (directions[value] & (1 << i)) 156 | buttons[(*count)++] = GLFW_PRESS; 157 | else 158 | buttons[(*count)++] = GLFW_RELEASE; 159 | } 160 | } 161 | 162 | return buttons; 163 | } 164 | 165 | const char* _glfwPlatformGetJoystickName(int joy) 166 | { 167 | JOYCAPS jc; 168 | 169 | if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR) 170 | return NULL; 171 | 172 | free(_glfw.winmm_js[joy].name); 173 | _glfw.winmm_js[joy].name = _glfwCreateUTF8FromWideString(jc.szPname); 174 | 175 | return _glfw.winmm_js[joy].name; 176 | } 177 | 178 | -------------------------------------------------------------------------------- /deps/glfw/src/winmm_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 WinMM - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2014 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_winmm_joystick_h_ 28 | #define _glfw3_winmm_joystick_h_ 29 | 30 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ 31 | _GLFWjoystickWinMM winmm_js[GLFW_JOYSTICK_LAST + 1] 32 | 33 | 34 | // WinMM-specific per-joystick data 35 | // 36 | typedef struct _GLFWjoystickWinMM 37 | { 38 | float axes[6]; 39 | unsigned char buttons[36]; // 32 buttons plus one hat 40 | char* name; 41 | } _GLFWjoystickWinMM; 42 | 43 | 44 | void _glfwInitJoysticks(void); 45 | void _glfwTerminateJoysticks(void); 46 | 47 | #endif // _glfw3_winmm_joystick_h_ 48 | -------------------------------------------------------------------------------- /deps/glfw/src/wl_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 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 | 33 | #include "posix_tls.h" 34 | #include "posix_time.h" 35 | #include "linux_joystick.h" 36 | #include "xkb_unicode.h" 37 | 38 | #if defined(_GLFW_EGL) 39 | #include "egl_context.h" 40 | #else 41 | #error "The Wayland backend depends on EGL platform support" 42 | #endif 43 | 44 | #define _GLFW_EGL_NATIVE_WINDOW window->wl.native 45 | #define _GLFW_EGL_NATIVE_DISPLAY _glfw.wl.display 46 | 47 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWayland wl 48 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWayland wl 49 | #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWayland wl 50 | #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorWayland wl 51 | 52 | 53 | // Wayland-specific video mode data 54 | // 55 | typedef struct _GLFWvidmodeWayland _GLFWvidmodeWayland; 56 | 57 | 58 | // Wayland-specific per-window data 59 | // 60 | typedef struct _GLFWwindowWayland 61 | { 62 | int width, height; 63 | GLboolean visible; 64 | struct wl_surface* surface; 65 | struct wl_egl_window* native; 66 | struct wl_shell_surface* shell_surface; 67 | struct wl_callback* callback; 68 | _GLFWcursor* currentCursor; 69 | double cursorPosX, cursorPosY; 70 | } _GLFWwindowWayland; 71 | 72 | 73 | // Wayland-specific global data 74 | // 75 | typedef struct _GLFWlibraryWayland 76 | { 77 | struct wl_display* display; 78 | struct wl_registry* registry; 79 | struct wl_compositor* compositor; 80 | struct wl_shell* shell; 81 | struct wl_shm* shm; 82 | struct wl_seat* seat; 83 | struct wl_pointer* pointer; 84 | struct wl_keyboard* keyboard; 85 | 86 | struct wl_cursor_theme* cursorTheme; 87 | struct wl_cursor* defaultCursor; 88 | struct wl_surface* cursorSurface; 89 | uint32_t pointerSerial; 90 | 91 | _GLFWmonitor** monitors; 92 | int monitorsCount; 93 | int monitorsSize; 94 | 95 | struct { 96 | struct xkb_context* context; 97 | struct xkb_keymap* keymap; 98 | struct xkb_state* state; 99 | xkb_mod_mask_t control_mask; 100 | xkb_mod_mask_t alt_mask; 101 | xkb_mod_mask_t shift_mask; 102 | xkb_mod_mask_t super_mask; 103 | unsigned int modifiers; 104 | } xkb; 105 | 106 | _GLFWwindow* pointerFocus; 107 | _GLFWwindow* keyboardFocus; 108 | 109 | } _GLFWlibraryWayland; 110 | 111 | 112 | // Wayland-specific per-monitor data 113 | // 114 | typedef struct _GLFWmonitorWayland 115 | { 116 | struct wl_output* output; 117 | 118 | _GLFWvidmodeWayland* modes; 119 | int modesCount; 120 | int modesSize; 121 | GLboolean done; 122 | 123 | int x; 124 | int y; 125 | 126 | } _GLFWmonitorWayland; 127 | 128 | 129 | // Wayland-specific per-cursor data 130 | // 131 | typedef struct _GLFWcursorWayland 132 | { 133 | struct wl_buffer* buffer; 134 | int width, height; 135 | int xhot, yhot; 136 | } _GLFWcursorWayland; 137 | 138 | 139 | void _glfwAddOutput(uint32_t name, uint32_t version); 140 | 141 | #endif // _glfw3_wayland_platform_h_ 142 | -------------------------------------------------------------------------------- /deps/glfw/src/xkb_unicode.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 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 | -------------------------------------------------------------------------------- /deps/glfw/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | link_libraries(glfw) 3 | 4 | if (BUILD_SHARED_LIBS) 5 | add_definitions(-DGLFW_DLL) 6 | link_libraries("${OPENGL_gl_LIBRARY}" "${MATH_LIBRARY}") 7 | else() 8 | link_libraries(${glfw_LIBRARIES}) 9 | endif() 10 | 11 | include_directories("${GLFW_SOURCE_DIR}/include" 12 | "${GLFW_SOURCE_DIR}/deps") 13 | 14 | if ("${OPENGL_INCLUDE_DIR}") 15 | include_directories("${OPENGL_INCLUDE_DIR}") 16 | endif() 17 | 18 | set(GETOPT "${GLFW_SOURCE_DIR}/deps/getopt.h" 19 | "${GLFW_SOURCE_DIR}/deps/getopt.c") 20 | set(TINYCTHREAD "${GLFW_SOURCE_DIR}/deps/tinycthread.h" 21 | "${GLFW_SOURCE_DIR}/deps/tinycthread.c") 22 | 23 | add_executable(clipboard clipboard.c ${GETOPT}) 24 | add_executable(events events.c ${GETOPT}) 25 | add_executable(msaa msaa.c ${GETOPT}) 26 | add_executable(gamma gamma.c ${GETOPT}) 27 | add_executable(glfwinfo glfwinfo.c ${GETOPT}) 28 | add_executable(iconify iconify.c ${GETOPT}) 29 | add_executable(joysticks joysticks.c) 30 | add_executable(monitors monitors.c ${GETOPT}) 31 | add_executable(reopen reopen.c) 32 | add_executable(cursor cursor.c) 33 | 34 | add_executable(empty WIN32 MACOSX_BUNDLE empty.c ${TINYCTHREAD}) 35 | set_target_properties(empty PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Empty Event") 36 | 37 | add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c) 38 | set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing") 39 | 40 | add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c ${GETOPT}) 41 | set_target_properties(tearing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Tearing") 42 | 43 | add_executable(threads WIN32 MACOSX_BUNDLE threads.c ${TINYCTHREAD}) 44 | set_target_properties(threads PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Threads") 45 | 46 | add_executable(title WIN32 MACOSX_BUNDLE title.c) 47 | set_target_properties(title PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Title") 48 | 49 | add_executable(windows WIN32 MACOSX_BUNDLE windows.c) 50 | set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows") 51 | 52 | target_link_libraries(empty "${CMAKE_THREAD_LIBS_INIT}" "${RT_LIBRARY}") 53 | target_link_libraries(threads "${CMAKE_THREAD_LIBS_INIT}" "${RT_LIBRARY}") 54 | 55 | set(WINDOWS_BINARIES empty sharing tearing threads title windows) 56 | set(CONSOLE_BINARIES clipboard events msaa gamma glfwinfo 57 | iconify joysticks monitors reopen cursor) 58 | 59 | set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES 60 | FOLDER "GLFW3/Tests") 61 | 62 | if (MSVC) 63 | # Tell MSVC to use main instead of WinMain for Windows subsystem executables 64 | set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES 65 | LINK_FLAGS "/ENTRY:mainCRTStartup") 66 | endif() 67 | 68 | if (APPLE) 69 | set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES 70 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} 71 | MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL} 72 | MACOSX_BUNDLE_INFO_PLIST "${GLFW_SOURCE_DIR}/CMake/MacOSXBundleInfo.plist.in") 73 | endif() 74 | 75 | -------------------------------------------------------------------------------- /deps/glfw/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 | 32 | #include 33 | #include 34 | 35 | #include "getopt.h" 36 | 37 | #if defined(__APPLE__) 38 | #define MODIFIER GLFW_MOD_SUPER 39 | #else 40 | #define MODIFIER GLFW_MOD_CONTROL 41 | #endif 42 | 43 | static void usage(void) 44 | { 45 | printf("Usage: clipboard [-h]\n"); 46 | } 47 | 48 | static void error_callback(int error, const char* description) 49 | { 50 | fprintf(stderr, "Error: %s\n", description); 51 | } 52 | 53 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 54 | { 55 | if (action != GLFW_PRESS) 56 | return; 57 | 58 | switch (key) 59 | { 60 | case GLFW_KEY_ESCAPE: 61 | glfwSetWindowShouldClose(window, GL_TRUE); 62 | break; 63 | 64 | case GLFW_KEY_V: 65 | if (mods == MODIFIER) 66 | { 67 | const char* string; 68 | 69 | string = glfwGetClipboardString(window); 70 | if (string) 71 | printf("Clipboard contains \"%s\"\n", string); 72 | else 73 | printf("Clipboard does not contain a string\n"); 74 | } 75 | break; 76 | 77 | case GLFW_KEY_C: 78 | if (mods == MODIFIER) 79 | { 80 | const char* string = "Hello GLFW World!"; 81 | glfwSetClipboardString(window, string); 82 | printf("Setting clipboard to \"%s\"\n", string); 83 | } 84 | break; 85 | } 86 | } 87 | 88 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 89 | { 90 | glViewport(0, 0, width, height); 91 | } 92 | 93 | int main(int argc, char** argv) 94 | { 95 | int ch; 96 | GLFWwindow* window; 97 | 98 | while ((ch = getopt(argc, argv, "h")) != -1) 99 | { 100 | switch (ch) 101 | { 102 | case 'h': 103 | usage(); 104 | exit(EXIT_SUCCESS); 105 | 106 | default: 107 | usage(); 108 | exit(EXIT_FAILURE); 109 | } 110 | } 111 | 112 | glfwSetErrorCallback(error_callback); 113 | 114 | if (!glfwInit()) 115 | { 116 | fprintf(stderr, "Failed to initialize GLFW\n"); 117 | exit(EXIT_FAILURE); 118 | } 119 | 120 | window = glfwCreateWindow(200, 200, "Clipboard Test", NULL, NULL); 121 | if (!window) 122 | { 123 | glfwTerminate(); 124 | 125 | fprintf(stderr, "Failed to open GLFW window\n"); 126 | exit(EXIT_FAILURE); 127 | } 128 | 129 | glfwMakeContextCurrent(window); 130 | glfwSwapInterval(1); 131 | 132 | glfwSetKeyCallback(window, key_callback); 133 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 134 | 135 | glMatrixMode(GL_PROJECTION); 136 | glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f); 137 | glMatrixMode(GL_MODELVIEW); 138 | 139 | glClearColor(0.5f, 0.5f, 0.5f, 0); 140 | 141 | while (!glfwWindowShouldClose(window)) 142 | { 143 | glClear(GL_COLOR_BUFFER_BIT); 144 | 145 | glColor3f(0.8f, 0.2f, 0.4f); 146 | glRectf(-0.5f, -0.5f, 0.5f, 0.5f); 147 | 148 | glfwSwapBuffers(window); 149 | glfwWaitEvents(); 150 | } 151 | 152 | glfwTerminate(); 153 | exit(EXIT_SUCCESS); 154 | } 155 | 156 | -------------------------------------------------------------------------------- /deps/glfw/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 | 34 | #include 35 | #include 36 | #include 37 | 38 | static volatile GLboolean running = GL_TRUE; 39 | 40 | static void error_callback(int error, const char* description) 41 | { 42 | fprintf(stderr, "Error: %s\n", description); 43 | } 44 | 45 | static int thread_main(void* data) 46 | { 47 | struct timespec time; 48 | 49 | while (running) 50 | { 51 | clock_gettime(CLOCK_REALTIME, &time); 52 | time.tv_sec += 1; 53 | thrd_sleep(&time, NULL); 54 | 55 | glfwPostEmptyEvent(); 56 | } 57 | 58 | return 0; 59 | } 60 | 61 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 62 | { 63 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 64 | glfwSetWindowShouldClose(window, GL_TRUE); 65 | } 66 | 67 | static float nrand(void) 68 | { 69 | return (float) rand() / (float) RAND_MAX; 70 | } 71 | 72 | int main(void) 73 | { 74 | int result; 75 | thrd_t thread; 76 | GLFWwindow* window; 77 | 78 | srand((unsigned int) time(NULL)); 79 | 80 | glfwSetErrorCallback(error_callback); 81 | 82 | if (!glfwInit()) 83 | exit(EXIT_FAILURE); 84 | 85 | window = glfwCreateWindow(640, 480, "Empty Event Test", NULL, NULL); 86 | if (!window) 87 | { 88 | glfwTerminate(); 89 | exit(EXIT_FAILURE); 90 | } 91 | 92 | glfwMakeContextCurrent(window); 93 | glfwSetKeyCallback(window, key_callback); 94 | 95 | if (thrd_create(&thread, thread_main, NULL) != thrd_success) 96 | { 97 | fprintf(stderr, "Failed to create secondary thread\n"); 98 | 99 | glfwTerminate(); 100 | exit(EXIT_FAILURE); 101 | } 102 | 103 | while (running) 104 | { 105 | int width, height; 106 | float r = nrand(), g = nrand(), b = nrand(); 107 | float l = (float) sqrt(r * r + g * g + b * b); 108 | 109 | glfwGetFramebufferSize(window, &width, &height); 110 | 111 | glViewport(0, 0, width, height); 112 | glClearColor(r / l, g / l, b / l, 1.f); 113 | glClear(GL_COLOR_BUFFER_BIT); 114 | glfwSwapBuffers(window); 115 | 116 | glfwWaitEvents(); 117 | 118 | if (glfwWindowShouldClose(window)) 119 | running = GL_FALSE; 120 | } 121 | 122 | glfwHideWindow(window); 123 | thrd_join(thread, &result); 124 | glfwDestroyWindow(window); 125 | 126 | glfwTerminate(); 127 | exit(EXIT_SUCCESS); 128 | } 129 | 130 | -------------------------------------------------------------------------------- /deps/glfw/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 | 33 | #include 34 | #include 35 | 36 | #include "getopt.h" 37 | 38 | #define STEP_SIZE 0.1f 39 | 40 | static GLfloat gamma_value = 1.0f; 41 | 42 | static void usage(void) 43 | { 44 | printf("Usage: gamma [-h] [-f]\n"); 45 | } 46 | 47 | static void set_gamma(GLFWwindow* window, float value) 48 | { 49 | GLFWmonitor* monitor = glfwGetWindowMonitor(window); 50 | if (!monitor) 51 | monitor = glfwGetPrimaryMonitor(); 52 | 53 | gamma_value = value; 54 | printf("Gamma: %f\n", gamma_value); 55 | glfwSetGamma(monitor, gamma_value); 56 | } 57 | 58 | static void error_callback(int error, const char* description) 59 | { 60 | fprintf(stderr, "Error: %s\n", description); 61 | } 62 | 63 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 64 | { 65 | if (action != GLFW_PRESS) 66 | return; 67 | 68 | switch (key) 69 | { 70 | case GLFW_KEY_ESCAPE: 71 | { 72 | glfwSetWindowShouldClose(window, GL_TRUE); 73 | break; 74 | } 75 | 76 | case GLFW_KEY_KP_ADD: 77 | case GLFW_KEY_Q: 78 | { 79 | set_gamma(window, gamma_value + STEP_SIZE); 80 | break; 81 | } 82 | 83 | case GLFW_KEY_KP_SUBTRACT: 84 | case GLFW_KEY_W: 85 | { 86 | if (gamma_value - STEP_SIZE > 0.f) 87 | set_gamma(window, gamma_value - STEP_SIZE); 88 | 89 | break; 90 | } 91 | } 92 | } 93 | 94 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 95 | { 96 | glViewport(0, 0, width, height); 97 | } 98 | 99 | int main(int argc, char** argv) 100 | { 101 | int width, height, ch; 102 | GLFWmonitor* monitor = NULL; 103 | GLFWwindow* window; 104 | 105 | glfwSetErrorCallback(error_callback); 106 | 107 | if (!glfwInit()) 108 | exit(EXIT_FAILURE); 109 | 110 | while ((ch = getopt(argc, argv, "fh")) != -1) 111 | { 112 | switch (ch) 113 | { 114 | case 'h': 115 | usage(); 116 | exit(EXIT_SUCCESS); 117 | 118 | case 'f': 119 | monitor = glfwGetPrimaryMonitor(); 120 | break; 121 | 122 | default: 123 | usage(); 124 | exit(EXIT_FAILURE); 125 | } 126 | } 127 | 128 | if (monitor) 129 | { 130 | const GLFWvidmode* mode = glfwGetVideoMode(monitor); 131 | 132 | glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); 133 | glfwWindowHint(GLFW_RED_BITS, mode->redBits); 134 | glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); 135 | glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); 136 | 137 | width = mode->width; 138 | height = mode->height; 139 | } 140 | else 141 | { 142 | width = 200; 143 | height = 200; 144 | } 145 | 146 | window = glfwCreateWindow(width, height, "Gamma Test", monitor, NULL); 147 | if (!window) 148 | { 149 | glfwTerminate(); 150 | exit(EXIT_FAILURE); 151 | } 152 | 153 | set_gamma(window, 1.f); 154 | 155 | glfwMakeContextCurrent(window); 156 | glfwSwapInterval(1); 157 | 158 | glfwSetKeyCallback(window, key_callback); 159 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 160 | 161 | glMatrixMode(GL_PROJECTION); 162 | glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f); 163 | glMatrixMode(GL_MODELVIEW); 164 | 165 | glClearColor(0.5f, 0.5f, 0.5f, 0); 166 | 167 | while (!glfwWindowShouldClose(window)) 168 | { 169 | glClear(GL_COLOR_BUFFER_BIT); 170 | 171 | glColor3f(0.8f, 0.2f, 0.4f); 172 | glRectf(-0.5f, -0.5f, 0.5f, 0.5f); 173 | 174 | glfwSwapBuffers(window); 175 | glfwWaitEvents(); 176 | } 177 | 178 | glfwTerminate(); 179 | exit(EXIT_SUCCESS); 180 | } 181 | 182 | -------------------------------------------------------------------------------- /deps/glfw/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 | #define GLFW_INCLUDE_GLEXT 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, GL_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 | glfwSwapInterval(1); 114 | 115 | if (!glfwExtensionSupported("GL_ARB_multisample")) 116 | { 117 | printf("GL_ARB_multisample extension not supported\n"); 118 | 119 | glfwTerminate(); 120 | exit(EXIT_FAILURE); 121 | } 122 | 123 | glfwShowWindow(window); 124 | 125 | glGetIntegerv(GL_SAMPLES_ARB, &samples); 126 | if (samples) 127 | printf("Context reports MSAA is available with %i samples\n", samples); 128 | else 129 | printf("Context reports MSAA is unavailable\n"); 130 | 131 | glMatrixMode(GL_PROJECTION); 132 | glOrtho(0.f, 1.f, 0.f, 0.5f, 0.f, 1.f); 133 | glMatrixMode(GL_MODELVIEW); 134 | 135 | while (!glfwWindowShouldClose(window)) 136 | { 137 | GLfloat time = (GLfloat) glfwGetTime(); 138 | 139 | glClear(GL_COLOR_BUFFER_BIT); 140 | 141 | glLoadIdentity(); 142 | glTranslatef(0.25f, 0.25f, 0.f); 143 | glRotatef(time, 0.f, 0.f, 1.f); 144 | 145 | glDisable(GL_MULTISAMPLE_ARB); 146 | glRectf(-0.15f, -0.15f, 0.15f, 0.15f); 147 | 148 | glLoadIdentity(); 149 | glTranslatef(0.75f, 0.25f, 0.f); 150 | glRotatef(time, 0.f, 0.f, 1.f); 151 | 152 | glEnable(GL_MULTISAMPLE_ARB); 153 | glRectf(-0.15f, -0.15f, 0.15f, 0.15f); 154 | 155 | glfwSwapBuffers(window); 156 | glfwPollEvents(); 157 | } 158 | 159 | glfwTerminate(); 160 | exit(EXIT_SUCCESS); 161 | } 162 | 163 | -------------------------------------------------------------------------------- /deps/glfw/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 | 38 | #include 39 | #include 40 | #include 41 | 42 | static void error_callback(int error, const char* description) 43 | { 44 | fprintf(stderr, "Error: %s\n", description); 45 | } 46 | 47 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 48 | { 49 | glViewport(0, 0, width, height); 50 | } 51 | 52 | static void window_close_callback(GLFWwindow* window) 53 | { 54 | printf("Close callback triggered\n"); 55 | } 56 | 57 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 58 | { 59 | if (action != GLFW_PRESS) 60 | return; 61 | 62 | switch (key) 63 | { 64 | case GLFW_KEY_Q: 65 | case GLFW_KEY_ESCAPE: 66 | glfwSetWindowShouldClose(window, GL_TRUE); 67 | break; 68 | } 69 | } 70 | 71 | static GLFWwindow* open_window(int width, int height, GLFWmonitor* monitor) 72 | { 73 | double base; 74 | GLFWwindow* window; 75 | 76 | base = glfwGetTime(); 77 | 78 | window = glfwCreateWindow(width, height, "Window Re-opener", monitor, NULL); 79 | if (!window) 80 | return NULL; 81 | 82 | glfwMakeContextCurrent(window); 83 | glfwSwapInterval(1); 84 | 85 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 86 | glfwSetWindowCloseCallback(window, window_close_callback); 87 | glfwSetKeyCallback(window, key_callback); 88 | 89 | if (monitor) 90 | { 91 | printf("Opening full screen window on monitor %s took %0.3f seconds\n", 92 | glfwGetMonitorName(monitor), 93 | glfwGetTime() - base); 94 | } 95 | else 96 | { 97 | printf("Opening regular window took %0.3f seconds\n", 98 | glfwGetTime() - base); 99 | } 100 | 101 | return window; 102 | } 103 | 104 | static void close_window(GLFWwindow* window) 105 | { 106 | double base = glfwGetTime(); 107 | glfwDestroyWindow(window); 108 | printf("Closing window took %0.3f seconds\n", glfwGetTime() - base); 109 | } 110 | 111 | int main(int argc, char** argv) 112 | { 113 | int count = 0; 114 | GLFWwindow* window; 115 | 116 | srand((unsigned int) time(NULL)); 117 | 118 | glfwSetErrorCallback(error_callback); 119 | 120 | if (!glfwInit()) 121 | exit(EXIT_FAILURE); 122 | 123 | for (;;) 124 | { 125 | int width, height; 126 | GLFWmonitor* monitor = NULL; 127 | 128 | if (count % 2 == 0) 129 | { 130 | int monitorCount; 131 | GLFWmonitor** monitors = glfwGetMonitors(&monitorCount); 132 | monitor = monitors[rand() % monitorCount]; 133 | } 134 | 135 | if (monitor) 136 | { 137 | const GLFWvidmode* mode = glfwGetVideoMode(monitor); 138 | width = mode->width; 139 | height = mode->height; 140 | } 141 | else 142 | { 143 | width = 640; 144 | height = 480; 145 | } 146 | 147 | window = open_window(width, height, monitor); 148 | if (!window) 149 | { 150 | glfwTerminate(); 151 | exit(EXIT_FAILURE); 152 | } 153 | 154 | glMatrixMode(GL_PROJECTION); 155 | glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f); 156 | glMatrixMode(GL_MODELVIEW); 157 | 158 | glfwSetTime(0.0); 159 | 160 | while (glfwGetTime() < 5.0) 161 | { 162 | glClear(GL_COLOR_BUFFER_BIT); 163 | 164 | glPushMatrix(); 165 | glRotatef((GLfloat) glfwGetTime() * 100.f, 0.f, 0.f, 1.f); 166 | glRectf(-0.5f, -0.5f, 1.f, 1.f); 167 | glPopMatrix(); 168 | 169 | glfwSwapBuffers(window); 170 | glfwPollEvents(); 171 | 172 | if (glfwWindowShouldClose(window)) 173 | { 174 | close_window(window); 175 | printf("User closed window\n"); 176 | 177 | glfwTerminate(); 178 | exit(EXIT_SUCCESS); 179 | } 180 | } 181 | 182 | printf("Closing window\n"); 183 | close_window(window); 184 | 185 | count++; 186 | } 187 | 188 | glfwTerminate(); 189 | } 190 | 191 | -------------------------------------------------------------------------------- /deps/glfw/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 | 32 | #include 33 | #include 34 | 35 | #define WIDTH 400 36 | #define HEIGHT 400 37 | #define OFFSET 50 38 | 39 | static GLFWwindow* windows[2]; 40 | 41 | static void error_callback(int error, const char* description) 42 | { 43 | fprintf(stderr, "Error: %s\n", description); 44 | } 45 | 46 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 47 | { 48 | if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE) 49 | glfwSetWindowShouldClose(window, GL_TRUE); 50 | } 51 | 52 | static GLFWwindow* open_window(const char* title, GLFWwindow* share, int posX, int posY) 53 | { 54 | GLFWwindow* window; 55 | 56 | glfwWindowHint(GLFW_VISIBLE, GL_FALSE); 57 | window = glfwCreateWindow(WIDTH, HEIGHT, title, NULL, share); 58 | if (!window) 59 | return NULL; 60 | 61 | glfwMakeContextCurrent(window); 62 | glfwSwapInterval(1); 63 | glfwSetWindowPos(window, posX, posY); 64 | glfwShowWindow(window); 65 | 66 | glfwSetKeyCallback(window, key_callback); 67 | 68 | return window; 69 | } 70 | 71 | static GLuint create_texture(void) 72 | { 73 | int x, y; 74 | char pixels[256 * 256]; 75 | GLuint texture; 76 | 77 | glGenTextures(1, &texture); 78 | glBindTexture(GL_TEXTURE_2D, texture); 79 | 80 | for (y = 0; y < 256; y++) 81 | { 82 | for (x = 0; x < 256; x++) 83 | pixels[y * 256 + x] = rand() % 256; 84 | } 85 | 86 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 256, 256, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels); 87 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 88 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 89 | 90 | return texture; 91 | } 92 | 93 | static void draw_quad(GLuint texture) 94 | { 95 | int width, height; 96 | glfwGetFramebufferSize(glfwGetCurrentContext(), &width, &height); 97 | 98 | glViewport(0, 0, width, height); 99 | 100 | glMatrixMode(GL_PROJECTION); 101 | glLoadIdentity(); 102 | glOrtho(0.f, 1.f, 0.f, 1.f, 0.f, 1.f); 103 | 104 | glEnable(GL_TEXTURE_2D); 105 | glBindTexture(GL_TEXTURE_2D, texture); 106 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 107 | 108 | glBegin(GL_QUADS); 109 | 110 | glTexCoord2f(0.f, 0.f); 111 | glVertex2f(0.f, 0.f); 112 | 113 | glTexCoord2f(1.f, 0.f); 114 | glVertex2f(1.f, 0.f); 115 | 116 | glTexCoord2f(1.f, 1.f); 117 | glVertex2f(1.f, 1.f); 118 | 119 | glTexCoord2f(0.f, 1.f); 120 | glVertex2f(0.f, 1.f); 121 | 122 | glEnd(); 123 | } 124 | 125 | int main(int argc, char** argv) 126 | { 127 | int x, y, width; 128 | GLuint texture; 129 | 130 | glfwSetErrorCallback(error_callback); 131 | 132 | if (!glfwInit()) 133 | exit(EXIT_FAILURE); 134 | 135 | windows[0] = open_window("First", NULL, OFFSET, OFFSET); 136 | if (!windows[0]) 137 | { 138 | glfwTerminate(); 139 | exit(EXIT_FAILURE); 140 | } 141 | 142 | // This is the one and only time we create a texture 143 | // It is created inside the first context, created above 144 | // It will then be shared with the second context, created below 145 | texture = create_texture(); 146 | 147 | glfwGetWindowPos(windows[0], &x, &y); 148 | glfwGetWindowSize(windows[0], &width, NULL); 149 | 150 | // Put the second window to the right of the first one 151 | windows[1] = open_window("Second", windows[0], x + width + OFFSET, y); 152 | if (!windows[1]) 153 | { 154 | glfwTerminate(); 155 | exit(EXIT_FAILURE); 156 | } 157 | 158 | // Set drawing color for both contexts 159 | glfwMakeContextCurrent(windows[0]); 160 | glColor3f(0.6f, 0.f, 0.6f); 161 | glfwMakeContextCurrent(windows[1]); 162 | glColor3f(0.6f, 0.6f, 0.f); 163 | 164 | glfwMakeContextCurrent(windows[0]); 165 | 166 | while (!glfwWindowShouldClose(windows[0]) && 167 | !glfwWindowShouldClose(windows[1])) 168 | { 169 | glfwMakeContextCurrent(windows[0]); 170 | draw_quad(texture); 171 | 172 | glfwMakeContextCurrent(windows[1]); 173 | draw_quad(texture); 174 | 175 | glfwSwapBuffers(windows[0]); 176 | glfwSwapBuffers(windows[1]); 177 | 178 | glfwWaitEvents(); 179 | } 180 | 181 | glfwTerminate(); 182 | exit(EXIT_SUCCESS); 183 | } 184 | 185 | -------------------------------------------------------------------------------- /deps/glfw/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 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include "getopt.h" 38 | 39 | static GLboolean swap_tear; 40 | static int swap_interval; 41 | static double frame_rate; 42 | 43 | static void usage(void) 44 | { 45 | printf("Usage: iconify [-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 update_window_title(GLFWwindow* window) 52 | { 53 | char title[256]; 54 | 55 | sprintf(title, "Tearing detector (interval %i%s, %0.1f Hz)", 56 | swap_interval, 57 | (swap_tear && swap_interval < 0) ? " (swap tear)" : "", 58 | frame_rate); 59 | 60 | glfwSetWindowTitle(window, title); 61 | } 62 | 63 | static void set_swap_interval(GLFWwindow* window, int interval) 64 | { 65 | swap_interval = interval; 66 | glfwSwapInterval(swap_interval); 67 | update_window_title(window); 68 | } 69 | 70 | static void error_callback(int error, const char* description) 71 | { 72 | fprintf(stderr, "Error: %s\n", description); 73 | } 74 | 75 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 76 | { 77 | glViewport(0, 0, width, height); 78 | } 79 | 80 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 81 | { 82 | if (action != GLFW_PRESS) 83 | return; 84 | 85 | switch (key) 86 | { 87 | case GLFW_KEY_UP: 88 | { 89 | if (swap_interval + 1 > swap_interval) 90 | set_swap_interval(window, swap_interval + 1); 91 | break; 92 | } 93 | 94 | case GLFW_KEY_DOWN: 95 | { 96 | if (swap_tear) 97 | { 98 | if (swap_interval - 1 < swap_interval) 99 | set_swap_interval(window, swap_interval - 1); 100 | } 101 | else 102 | { 103 | if (swap_interval - 1 >= 0) 104 | set_swap_interval(window, swap_interval - 1); 105 | } 106 | break; 107 | } 108 | 109 | case GLFW_KEY_ESCAPE: 110 | glfwSetWindowShouldClose(window, 1); 111 | break; 112 | } 113 | } 114 | 115 | int main(int argc, char** argv) 116 | { 117 | int ch, width, height; 118 | float position; 119 | unsigned long frame_count = 0; 120 | double last_time, current_time; 121 | GLboolean fullscreen = GL_FALSE; 122 | GLFWmonitor* monitor = NULL; 123 | GLFWwindow* window; 124 | 125 | while ((ch = getopt(argc, argv, "fh")) != -1) 126 | { 127 | switch (ch) 128 | { 129 | case 'h': 130 | usage(); 131 | exit(EXIT_SUCCESS); 132 | 133 | case 'f': 134 | fullscreen = GL_TRUE; 135 | break; 136 | } 137 | } 138 | 139 | glfwSetErrorCallback(error_callback); 140 | 141 | if (!glfwInit()) 142 | exit(EXIT_FAILURE); 143 | 144 | if (fullscreen) 145 | { 146 | const GLFWvidmode* mode; 147 | 148 | monitor = glfwGetPrimaryMonitor(); 149 | mode = glfwGetVideoMode(monitor); 150 | 151 | glfwWindowHint(GLFW_RED_BITS, mode->redBits); 152 | glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); 153 | glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); 154 | glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); 155 | 156 | width = mode->width; 157 | height = mode->height; 158 | } 159 | else 160 | { 161 | width = 640; 162 | height = 480; 163 | } 164 | 165 | window = glfwCreateWindow(width, height, "", monitor, NULL); 166 | if (!window) 167 | { 168 | glfwTerminate(); 169 | exit(EXIT_FAILURE); 170 | } 171 | 172 | glfwMakeContextCurrent(window); 173 | set_swap_interval(window, 0); 174 | 175 | last_time = glfwGetTime(); 176 | frame_rate = 0.0; 177 | swap_tear = (glfwExtensionSupported("WGL_EXT_swap_control_tear") || 178 | glfwExtensionSupported("GLX_EXT_swap_control_tear")); 179 | 180 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 181 | glfwSetKeyCallback(window, key_callback); 182 | 183 | glMatrixMode(GL_PROJECTION); 184 | glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f); 185 | glMatrixMode(GL_MODELVIEW); 186 | 187 | while (!glfwWindowShouldClose(window)) 188 | { 189 | glClear(GL_COLOR_BUFFER_BIT); 190 | 191 | position = cosf((float) glfwGetTime() * 4.f) * 0.75f; 192 | glRectf(position - 0.25f, -1.f, position + 0.25f, 1.f); 193 | 194 | glfwSwapBuffers(window); 195 | glfwPollEvents(); 196 | 197 | frame_count++; 198 | 199 | current_time = glfwGetTime(); 200 | if (current_time - last_time > 1.0) 201 | { 202 | frame_rate = frame_count / (current_time - last_time); 203 | frame_count = 0; 204 | last_time = current_time; 205 | update_window_title(window); 206 | } 207 | } 208 | 209 | glfwTerminate(); 210 | exit(EXIT_SUCCESS); 211 | } 212 | 213 | -------------------------------------------------------------------------------- /deps/glfw/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 | 35 | #include 36 | #include 37 | #include 38 | 39 | typedef struct 40 | { 41 | GLFWwindow* window; 42 | const char* title; 43 | float r, g, b; 44 | thrd_t id; 45 | } Thread; 46 | 47 | static volatile GLboolean running = GL_TRUE; 48 | 49 | static void error_callback(int error, const char* description) 50 | { 51 | fprintf(stderr, "Error: %s\n", description); 52 | } 53 | 54 | static int thread_main(void* data) 55 | { 56 | const Thread* thread = data; 57 | 58 | glfwMakeContextCurrent(thread->window); 59 | glfwSwapInterval(1); 60 | 61 | while (running) 62 | { 63 | const float v = (float) fabs(sin(glfwGetTime() * 2.f)); 64 | glClearColor(thread->r * v, thread->g * v, thread->b * v, 0.f); 65 | 66 | glClear(GL_COLOR_BUFFER_BIT); 67 | glfwSwapBuffers(thread->window); 68 | } 69 | 70 | glfwMakeContextCurrent(NULL); 71 | return 0; 72 | } 73 | 74 | int main(void) 75 | { 76 | int i, result; 77 | Thread threads[] = 78 | { 79 | { NULL, "Red", 1.f, 0.f, 0.f, 0 }, 80 | { NULL, "Green", 0.f, 1.f, 0.f, 0 }, 81 | { NULL, "Blue", 0.f, 0.f, 1.f, 0 } 82 | }; 83 | const int count = sizeof(threads) / sizeof(Thread); 84 | 85 | glfwSetErrorCallback(error_callback); 86 | 87 | if (!glfwInit()) 88 | exit(EXIT_FAILURE); 89 | 90 | glfwWindowHint(GLFW_VISIBLE, GL_FALSE); 91 | 92 | for (i = 0; i < count; i++) 93 | { 94 | threads[i].window = glfwCreateWindow(200, 200, 95 | threads[i].title, 96 | NULL, NULL); 97 | if (!threads[i].window) 98 | { 99 | glfwTerminate(); 100 | exit(EXIT_FAILURE); 101 | } 102 | 103 | glfwSetWindowPos(threads[i].window, 200 + 250 * i, 200); 104 | glfwShowWindow(threads[i].window); 105 | 106 | if (thrd_create(&threads[i].id, thread_main, threads + i) != 107 | thrd_success) 108 | { 109 | fprintf(stderr, "Failed to create secondary thread\n"); 110 | 111 | glfwTerminate(); 112 | exit(EXIT_FAILURE); 113 | } 114 | } 115 | 116 | while (running) 117 | { 118 | glfwWaitEvents(); 119 | 120 | for (i = 0; i < count; i++) 121 | { 122 | if (glfwWindowShouldClose(threads[i].window)) 123 | running = GL_FALSE; 124 | } 125 | } 126 | 127 | for (i = 0; i < count; i++) 128 | glfwHideWindow(threads[i].window); 129 | 130 | for (i = 0; i < count; i++) 131 | thrd_join(threads[i].id, &result); 132 | 133 | exit(EXIT_SUCCESS); 134 | } 135 | 136 | -------------------------------------------------------------------------------- /deps/glfw/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 | 32 | #include 33 | #include 34 | 35 | static void error_callback(int error, const char* description) 36 | { 37 | fprintf(stderr, "Error: %s\n", description); 38 | } 39 | 40 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 41 | { 42 | glViewport(0, 0, width, height); 43 | } 44 | 45 | int main(void) 46 | { 47 | GLFWwindow* window; 48 | 49 | glfwSetErrorCallback(error_callback); 50 | 51 | if (!glfwInit()) 52 | exit(EXIT_FAILURE); 53 | 54 | window = glfwCreateWindow(400, 400, "English 日本語 русский язык 官話", NULL, NULL); 55 | if (!window) 56 | { 57 | glfwTerminate(); 58 | exit(EXIT_FAILURE); 59 | } 60 | 61 | glfwMakeContextCurrent(window); 62 | glfwSwapInterval(1); 63 | 64 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 65 | 66 | while (!glfwWindowShouldClose(window)) 67 | { 68 | glClear(GL_COLOR_BUFFER_BIT); 69 | glfwSwapBuffers(window); 70 | glfwWaitEvents(); 71 | } 72 | 73 | glfwTerminate(); 74 | exit(EXIT_SUCCESS); 75 | } 76 | 77 | -------------------------------------------------------------------------------- /deps/glfw/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 | 32 | #include 33 | #include 34 | 35 | static const char* titles[] = 36 | { 37 | "Red", 38 | "Green", 39 | "Blue", 40 | "Yellow" 41 | }; 42 | 43 | static const struct 44 | { 45 | float r, g, b; 46 | } colors[] = 47 | { 48 | { 0.95f, 0.32f, 0.11f }, 49 | { 0.50f, 0.80f, 0.16f }, 50 | { 0.f, 0.68f, 0.94f }, 51 | { 0.98f, 0.74f, 0.04f } 52 | }; 53 | 54 | static void error_callback(int error, const char* description) 55 | { 56 | fprintf(stderr, "Error: %s\n", description); 57 | } 58 | 59 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 60 | { 61 | if (action != GLFW_PRESS) 62 | return; 63 | 64 | switch (key) 65 | { 66 | case GLFW_KEY_SPACE: 67 | { 68 | int xpos, ypos; 69 | glfwGetWindowPos(window, &xpos, &ypos); 70 | glfwSetWindowPos(window, xpos, ypos); 71 | break; 72 | } 73 | 74 | case GLFW_KEY_ESCAPE: 75 | glfwSetWindowShouldClose(window, GL_TRUE); 76 | break; 77 | } 78 | } 79 | 80 | int main(int argc, char** argv) 81 | { 82 | int i; 83 | GLboolean running = GL_TRUE; 84 | GLFWwindow* windows[4]; 85 | 86 | glfwSetErrorCallback(error_callback); 87 | 88 | if (!glfwInit()) 89 | exit(EXIT_FAILURE); 90 | 91 | glfwWindowHint(GLFW_DECORATED, GL_FALSE); 92 | glfwWindowHint(GLFW_VISIBLE, GL_FALSE); 93 | 94 | for (i = 0; i < 4; i++) 95 | { 96 | int left, top, right, bottom; 97 | 98 | windows[i] = glfwCreateWindow(200, 200, titles[i], NULL, NULL); 99 | if (!windows[i]) 100 | { 101 | glfwTerminate(); 102 | exit(EXIT_FAILURE); 103 | } 104 | 105 | glfwSetKeyCallback(windows[i], key_callback); 106 | 107 | glfwMakeContextCurrent(windows[i]); 108 | glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f); 109 | 110 | glfwGetWindowFrameSize(windows[i], &left, &top, &right, &bottom); 111 | glfwSetWindowPos(windows[i], 112 | 100 + (i & 1) * (200 + left + right), 113 | 100 + (i >> 1) * (200 + top + bottom)); 114 | } 115 | 116 | for (i = 0; i < 4; i++) 117 | glfwShowWindow(windows[i]); 118 | 119 | while (running) 120 | { 121 | for (i = 0; i < 4; i++) 122 | { 123 | glfwMakeContextCurrent(windows[i]); 124 | glClear(GL_COLOR_BUFFER_BIT); 125 | glfwSwapBuffers(windows[i]); 126 | 127 | if (glfwWindowShouldClose(windows[i])) 128 | running = GL_FALSE; 129 | } 130 | 131 | glfwPollEvents(); 132 | } 133 | 134 | glfwTerminate(); 135 | exit(EXIT_SUCCESS); 136 | } 137 | 138 | -------------------------------------------------------------------------------- /deps/noise/noise.h: -------------------------------------------------------------------------------- 1 | /* 2 | noise.h and noise.c are derived from this project: 3 | 4 | https://github.com/caseman/noise 5 | 6 | Copyright (c) 2008 Casey Duncan 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | 27 | #ifndef _noise_h_ 28 | #define _noise_h_ 29 | 30 | void seed(unsigned int x); 31 | 32 | float simplex2( 33 | float x, float y, 34 | int octaves, float persistence, float lacunarity); 35 | 36 | float simplex3( 37 | float x, float y, float z, 38 | int octaves, float persistence, float lacunarity); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /shaders/block_fragment.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | uniform sampler2D sampler; 4 | uniform sampler2D sky_sampler; 5 | uniform float timer; 6 | uniform float daylight; 7 | uniform int ortho; 8 | 9 | varying vec2 fragment_uv; 10 | varying float fragment_ao; 11 | varying float fragment_light; 12 | varying float fog_factor; 13 | varying float fog_height; 14 | varying float diffuse; 15 | 16 | const float pi = 3.14159265; 17 | 18 | void main() { 19 | vec3 color = vec3(texture2D(sampler, fragment_uv)); 20 | if (color == vec3(1.0, 0.0, 1.0)) { 21 | discard; 22 | } 23 | bool cloud = color == vec3(1.0, 1.0, 1.0); 24 | if (cloud && bool(ortho)) { 25 | discard; 26 | } 27 | float df = cloud ? 1.0 - diffuse * 0.2 : diffuse; 28 | float ao = cloud ? 1.0 - (1.0 - fragment_ao) * 0.2 : fragment_ao; 29 | ao = min(1.0, ao + fragment_light); 30 | df = min(1.0, df + fragment_light); 31 | float value = min(1.0, daylight + fragment_light); 32 | vec3 light_color = vec3(value * 0.3 + 0.2); 33 | vec3 ambient = vec3(value * 0.3 + 0.2); 34 | vec3 light = ambient + light_color * df; 35 | color = clamp(color * light * ao, vec3(0.0), vec3(1.0)); 36 | vec3 sky_color = vec3(texture2D(sky_sampler, vec2(timer, fog_height))); 37 | color = mix(color, sky_color, fog_factor); 38 | gl_FragColor = vec4(color, 1.0); 39 | } 40 | -------------------------------------------------------------------------------- /shaders/block_vertex.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | uniform mat4 matrix; 4 | uniform vec3 camera; 5 | uniform float fog_distance; 6 | uniform int ortho; 7 | 8 | attribute vec4 position; 9 | attribute vec3 normal; 10 | attribute vec4 uv; 11 | 12 | varying vec2 fragment_uv; 13 | varying float fragment_ao; 14 | varying float fragment_light; 15 | varying float fog_factor; 16 | varying float fog_height; 17 | varying float diffuse; 18 | 19 | const float pi = 3.14159265; 20 | const vec3 light_direction = normalize(vec3(-1.0, 1.0, -1.0)); 21 | 22 | void main() { 23 | gl_Position = matrix * position; 24 | fragment_uv = uv.xy; 25 | fragment_ao = 0.3 + (1.0 - uv.z) * 0.7; 26 | fragment_light = uv.w; 27 | diffuse = max(0.0, dot(normal, light_direction)); 28 | if (bool(ortho)) { 29 | fog_factor = 0.0; 30 | fog_height = 0.0; 31 | } 32 | else { 33 | float camera_distance = distance(camera, vec3(position)); 34 | fog_factor = pow(clamp(camera_distance / fog_distance, 0.0, 1.0), 4.0); 35 | float dy = position.y - camera.y; 36 | float dx = distance(position.xz, camera.xz); 37 | fog_height = (atan(dy, dx) + pi / 2) / pi; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /shaders/line_fragment.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | void main() { 4 | gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 5 | } 6 | -------------------------------------------------------------------------------- /shaders/line_vertex.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | uniform mat4 matrix; 4 | 5 | attribute vec4 position; 6 | 7 | void main() { 8 | gl_Position = matrix * position; 9 | } 10 | -------------------------------------------------------------------------------- /shaders/sky_fragment.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | uniform sampler2D sampler; 4 | uniform float timer; 5 | 6 | varying vec2 fragment_uv; 7 | 8 | void main() { 9 | vec2 uv = vec2(timer, fragment_uv.t); 10 | gl_FragColor = texture2D(sampler, uv); 11 | } 12 | -------------------------------------------------------------------------------- /shaders/sky_vertex.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | uniform mat4 matrix; 4 | 5 | attribute vec4 position; 6 | attribute vec3 normal; 7 | attribute vec2 uv; 8 | 9 | varying vec2 fragment_uv; 10 | 11 | void main() { 12 | gl_Position = matrix * position; 13 | fragment_uv = uv; 14 | } 15 | -------------------------------------------------------------------------------- /shaders/text_fragment.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | uniform sampler2D sampler; 4 | uniform bool is_sign; 5 | 6 | varying vec2 fragment_uv; 7 | 8 | void main() { 9 | vec4 color = texture2D(sampler, fragment_uv); 10 | if (is_sign) { 11 | if (color == vec4(1.0)) { 12 | discard; 13 | } 14 | } 15 | else { 16 | color.a = max(color.a, 0.4); 17 | } 18 | gl_FragColor = color; 19 | } 20 | -------------------------------------------------------------------------------- /shaders/text_vertex.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | uniform mat4 matrix; 4 | 5 | attribute vec4 position; 6 | attribute vec2 uv; 7 | 8 | varying vec2 fragment_uv; 9 | 10 | void main() { 11 | gl_Position = matrix * position; 12 | fragment_uv = uv; 13 | } 14 | -------------------------------------------------------------------------------- /src/auth.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "auth.h" 6 | 7 | #define MAX_POST_LENGTH 1024 8 | #define MAX_RESPONSE_LENGTH 1024 9 | 10 | size_t write_function(char *data, size_t size, size_t count, void *arg) { 11 | size_t length = size * count; 12 | char *dst = (char *)arg; 13 | char *src = malloc(length + 1); 14 | memcpy(src, data, length); 15 | src[length] = '\0'; 16 | strncat(dst, src, MAX_RESPONSE_LENGTH - strlen(dst) - 1); 17 | free(src); 18 | return length; 19 | } 20 | 21 | int get_access_token( 22 | char *result, int length, char *username, char *identity_token) 23 | { 24 | static char url[] = "https://craft.michaelfogleman.com/api/1/identity"; 25 | strncpy(result, "", length); 26 | CURL *curl = curl_easy_init(); 27 | if (curl) { 28 | char post[MAX_POST_LENGTH] = {0}; 29 | char response[MAX_RESPONSE_LENGTH] = {0}; 30 | long http_code = 0; 31 | snprintf(post, MAX_POST_LENGTH, "username=%s&identity_token=%s", 32 | username, identity_token); 33 | #ifdef _WIN32 34 | curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); 35 | #endif 36 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_function); 37 | curl_easy_setopt(curl, CURLOPT_WRITEDATA, response); 38 | curl_easy_setopt(curl, CURLOPT_URL, url); 39 | curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post); 40 | CURLcode code = curl_easy_perform(curl); 41 | curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); 42 | curl_easy_cleanup(curl); 43 | if (code == CURLE_OK && http_code == 200) { 44 | strncpy(result, response, length); 45 | return 1; 46 | } 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /src/auth.h: -------------------------------------------------------------------------------- 1 | #ifndef _auth_h_ 2 | #define _auth_h_ 3 | 4 | int get_access_token( 5 | char *result, int length, char *username, char *identity_token); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /src/client.h: -------------------------------------------------------------------------------- 1 | #ifndef _client_h_ 2 | #define _client_h_ 3 | 4 | #define DEFAULT_PORT 4080 5 | 6 | void client_enable(); 7 | void client_disable(); 8 | int get_client_enabled(); 9 | void client_connect(char *hostname, int port); 10 | void client_start(); 11 | void client_stop(); 12 | void client_send(char *data); 13 | char *client_recv(); 14 | void client_version(int version); 15 | void client_login(const char *username, const char *identity_token); 16 | void client_position(float x, float y, float z, float rx, float ry); 17 | void client_chunk(int p, int q, int key); 18 | void client_block(int x, int y, int z, int w); 19 | void client_light(int x, int y, int z, int w); 20 | void client_sign(int x, int y, int z, int face, const char *text); 21 | void client_talk(const char *text); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | #ifndef _config_h_ 2 | #define _config_h_ 3 | 4 | // app parameters 5 | #define DEBUG 0 6 | #define FULLSCREEN 0 7 | #define WINDOW_WIDTH 1024 8 | #define WINDOW_HEIGHT 768 9 | #define VSYNC 1 10 | #define SCROLL_THRESHOLD 0.1 11 | #define MAX_MESSAGES 4 12 | #define DB_PATH "craft.db" 13 | #define USE_CACHE 1 14 | #define DAY_LENGTH 600 15 | #define INVERT_MOUSE 0 16 | 17 | // rendering options 18 | #define SHOW_LIGHTS 1 19 | #define SHOW_PLANTS 1 20 | #define SHOW_CLOUDS 1 21 | #define SHOW_TREES 1 22 | #define SHOW_ITEM 1 23 | #define SHOW_CROSSHAIRS 1 24 | #define SHOW_WIREFRAME 1 25 | #define SHOW_INFO_TEXT 1 26 | #define SHOW_CHAT_TEXT 1 27 | #define SHOW_PLAYER_NAMES 1 28 | 29 | // key bindings 30 | #define CRAFT_KEY_FORWARD 'W' 31 | #define CRAFT_KEY_BACKWARD 'S' 32 | #define CRAFT_KEY_LEFT 'A' 33 | #define CRAFT_KEY_RIGHT 'D' 34 | #define CRAFT_KEY_JUMP GLFW_KEY_SPACE 35 | #define CRAFT_KEY_FLY GLFW_KEY_TAB 36 | #define CRAFT_KEY_OBSERVE 'O' 37 | #define CRAFT_KEY_OBSERVE_INSET 'P' 38 | #define CRAFT_KEY_ITEM_NEXT 'E' 39 | #define CRAFT_KEY_ITEM_PREV 'R' 40 | #define CRAFT_KEY_ZOOM GLFW_KEY_LEFT_SHIFT 41 | #define CRAFT_KEY_ORTHO 'F' 42 | #define CRAFT_KEY_CHAT 't' 43 | #define CRAFT_KEY_COMMAND '/' 44 | #define CRAFT_KEY_SIGN '`' 45 | 46 | // advanced parameters 47 | #define CREATE_CHUNK_RADIUS 10 48 | #define RENDER_CHUNK_RADIUS 10 49 | #define RENDER_SIGN_RADIUS 4 50 | #define DELETE_CHUNK_RADIUS 14 51 | #define CHUNK_SIZE 32 52 | #define COMMIT_INTERVAL 5 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/cube.h: -------------------------------------------------------------------------------- 1 | #ifndef _cube_h_ 2 | #define _cube_h_ 3 | 4 | void make_cube_faces( 5 | float *data, float ao[6][4], float light[6][4], 6 | int left, int right, int top, int bottom, int front, int back, 7 | int wleft, int wright, int wtop, int wbottom, int wfront, int wback, 8 | float x, float y, float z, float n); 9 | 10 | void make_cube( 11 | float *data, float ao[6][4], float light[6][4], 12 | int left, int right, int top, int bottom, int front, int back, 13 | float x, float y, float z, float n, int w); 14 | 15 | void make_plant( 16 | float *data, float ao, float light, 17 | float px, float py, float pz, float n, int w, float rotation); 18 | 19 | void make_player( 20 | float *data, 21 | float x, float y, float z, float rx, float ry); 22 | 23 | void make_cube_wireframe( 24 | float *data, float x, float y, float z, float n); 25 | 26 | void make_character( 27 | float *data, 28 | float x, float y, float n, float m, char c); 29 | 30 | void make_character_3d( 31 | float *data, float x, float y, float z, float n, int face, char c); 32 | 33 | void make_sphere(float *data, float r, int detail); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/db.h: -------------------------------------------------------------------------------- 1 | #ifndef _db_h_ 2 | #define _db_h_ 3 | 4 | #include "map.h" 5 | #include "sign.h" 6 | 7 | void db_enable(); 8 | void db_disable(); 9 | int get_db_enabled(); 10 | int db_init(char *path); 11 | void db_close(); 12 | void db_commit(); 13 | void db_auth_set(char *username, char *identity_token); 14 | int db_auth_select(char *username); 15 | void db_auth_select_none(); 16 | int db_auth_get( 17 | char *username, 18 | char *identity_token, int identity_token_length); 19 | int db_auth_get_selected( 20 | char *username, int username_length, 21 | char *identity_token, int identity_token_length); 22 | void db_save_state(float x, float y, float z, float rx, float ry); 23 | int db_load_state(float *x, float *y, float *z, float *rx, float *ry); 24 | void db_insert_block(int p, int q, int x, int y, int z, int w); 25 | void db_insert_light(int p, int q, int x, int y, int z, int w); 26 | void db_insert_sign( 27 | int p, int q, int x, int y, int z, int face, const char *text); 28 | void db_delete_sign(int x, int y, int z, int face); 29 | void db_delete_signs(int x, int y, int z); 30 | void db_delete_all_signs(); 31 | void db_load_blocks(Map *map, int p, int q); 32 | void db_load_lights(Map *map, int p, int q); 33 | void db_load_signs(SignList *list, int p, int q); 34 | int db_get_key(int p, int q); 35 | void db_set_key(int p, int q, int key); 36 | void db_worker_start(); 37 | void db_worker_stop(); 38 | int db_worker_run(void *arg); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/item.c: -------------------------------------------------------------------------------- 1 | #include "item.h" 2 | #include "util.h" 3 | 4 | const int items[] = { 5 | // items the user can build 6 | GRASS, 7 | SAND, 8 | STONE, 9 | BRICK, 10 | WOOD, 11 | CEMENT, 12 | DIRT, 13 | PLANK, 14 | SNOW, 15 | GLASS, 16 | COBBLE, 17 | LIGHT_STONE, 18 | DARK_STONE, 19 | CHEST, 20 | LEAVES, 21 | TALL_GRASS, 22 | YELLOW_FLOWER, 23 | RED_FLOWER, 24 | PURPLE_FLOWER, 25 | SUN_FLOWER, 26 | WHITE_FLOWER, 27 | BLUE_FLOWER, 28 | COLOR_00, 29 | COLOR_01, 30 | COLOR_02, 31 | COLOR_03, 32 | COLOR_04, 33 | COLOR_05, 34 | COLOR_06, 35 | COLOR_07, 36 | COLOR_08, 37 | COLOR_09, 38 | COLOR_10, 39 | COLOR_11, 40 | COLOR_12, 41 | COLOR_13, 42 | COLOR_14, 43 | COLOR_15, 44 | COLOR_16, 45 | COLOR_17, 46 | COLOR_18, 47 | COLOR_19, 48 | COLOR_20, 49 | COLOR_21, 50 | COLOR_22, 51 | COLOR_23, 52 | COLOR_24, 53 | COLOR_25, 54 | COLOR_26, 55 | COLOR_27, 56 | COLOR_28, 57 | COLOR_29, 58 | COLOR_30, 59 | COLOR_31 60 | }; 61 | 62 | const int item_count = sizeof(items) / sizeof(int); 63 | 64 | const int blocks[256][6] = { 65 | // w => (left, right, top, bottom, front, back) tiles 66 | {0, 0, 0, 0, 0, 0}, // 0 - empty 67 | {16, 16, 32, 0, 16, 16}, // 1 - grass 68 | {1, 1, 1, 1, 1, 1}, // 2 - sand 69 | {2, 2, 2, 2, 2, 2}, // 3 - stone 70 | {3, 3, 3, 3, 3, 3}, // 4 - brick 71 | {20, 20, 36, 4, 20, 20}, // 5 - wood 72 | {5, 5, 5, 5, 5, 5}, // 6 - cement 73 | {6, 6, 6, 6, 6, 6}, // 7 - dirt 74 | {7, 7, 7, 7, 7, 7}, // 8 - plank 75 | {24, 24, 40, 8, 24, 24}, // 9 - snow 76 | {9, 9, 9, 9, 9, 9}, // 10 - glass 77 | {10, 10, 10, 10, 10, 10}, // 11 - cobble 78 | {11, 11, 11, 11, 11, 11}, // 12 - light stone 79 | {12, 12, 12, 12, 12, 12}, // 13 - dark stone 80 | {13, 13, 13, 13, 13, 13}, // 14 - chest 81 | {14, 14, 14, 14, 14, 14}, // 15 - leaves 82 | {15, 15, 15, 15, 15, 15}, // 16 - cloud 83 | {0, 0, 0, 0, 0, 0}, // 17 84 | {0, 0, 0, 0, 0, 0}, // 18 85 | {0, 0, 0, 0, 0, 0}, // 19 86 | {0, 0, 0, 0, 0, 0}, // 20 87 | {0, 0, 0, 0, 0, 0}, // 21 88 | {0, 0, 0, 0, 0, 0}, // 22 89 | {0, 0, 0, 0, 0, 0}, // 23 90 | {0, 0, 0, 0, 0, 0}, // 24 91 | {0, 0, 0, 0, 0, 0}, // 25 92 | {0, 0, 0, 0, 0, 0}, // 26 93 | {0, 0, 0, 0, 0, 0}, // 27 94 | {0, 0, 0, 0, 0, 0}, // 28 95 | {0, 0, 0, 0, 0, 0}, // 29 96 | {0, 0, 0, 0, 0, 0}, // 30 97 | {0, 0, 0, 0, 0, 0}, // 31 98 | {176, 176, 176, 176, 176, 176}, // 32 99 | {177, 177, 177, 177, 177, 177}, // 33 100 | {178, 178, 178, 178, 178, 178}, // 34 101 | {179, 179, 179, 179, 179, 179}, // 35 102 | {180, 180, 180, 180, 180, 180}, // 36 103 | {181, 181, 181, 181, 181, 181}, // 37 104 | {182, 182, 182, 182, 182, 182}, // 38 105 | {183, 183, 183, 183, 183, 183}, // 39 106 | {184, 184, 184, 184, 184, 184}, // 40 107 | {185, 185, 185, 185, 185, 185}, // 41 108 | {186, 186, 186, 186, 186, 186}, // 42 109 | {187, 187, 187, 187, 187, 187}, // 43 110 | {188, 188, 188, 188, 188, 188}, // 44 111 | {189, 189, 189, 189, 189, 189}, // 45 112 | {190, 190, 190, 190, 190, 190}, // 46 113 | {191, 191, 191, 191, 191, 191}, // 47 114 | {192, 192, 192, 192, 192, 192}, // 48 115 | {193, 193, 193, 193, 193, 193}, // 49 116 | {194, 194, 194, 194, 194, 194}, // 50 117 | {195, 195, 195, 195, 195, 195}, // 51 118 | {196, 196, 196, 196, 196, 196}, // 52 119 | {197, 197, 197, 197, 197, 197}, // 53 120 | {198, 198, 198, 198, 198, 198}, // 54 121 | {199, 199, 199, 199, 199, 199}, // 55 122 | {200, 200, 200, 200, 200, 200}, // 56 123 | {201, 201, 201, 201, 201, 201}, // 57 124 | {202, 202, 202, 202, 202, 202}, // 58 125 | {203, 203, 203, 203, 203, 203}, // 59 126 | {204, 204, 204, 204, 204, 204}, // 60 127 | {205, 205, 205, 205, 205, 205}, // 61 128 | {206, 206, 206, 206, 206, 206}, // 62 129 | {207, 207, 207, 207, 207, 207}, // 63 130 | }; 131 | 132 | const int plants[256] = { 133 | // w => tile 134 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 16 135 | 48, // 17 - tall grass 136 | 49, // 18 - yellow flower 137 | 50, // 19 - red flower 138 | 51, // 20 - purple flower 139 | 52, // 21 - sun flower 140 | 53, // 22 - white flower 141 | 54, // 23 - blue flower 142 | }; 143 | 144 | int is_plant(int w) { 145 | switch (w) { 146 | case TALL_GRASS: 147 | case YELLOW_FLOWER: 148 | case RED_FLOWER: 149 | case PURPLE_FLOWER: 150 | case SUN_FLOWER: 151 | case WHITE_FLOWER: 152 | case BLUE_FLOWER: 153 | return 1; 154 | default: 155 | return 0; 156 | } 157 | } 158 | 159 | int is_obstacle(int w) { 160 | w = ABS(w); 161 | if (is_plant(w)) { 162 | return 0; 163 | } 164 | switch (w) { 165 | case EMPTY: 166 | case CLOUD: 167 | return 0; 168 | default: 169 | return 1; 170 | } 171 | } 172 | 173 | int is_transparent(int w) { 174 | if (w == EMPTY) { 175 | return 1; 176 | } 177 | w = ABS(w); 178 | if (is_plant(w)) { 179 | return 1; 180 | } 181 | switch (w) { 182 | case EMPTY: 183 | case GLASS: 184 | case LEAVES: 185 | return 1; 186 | default: 187 | return 0; 188 | } 189 | } 190 | 191 | int is_destructable(int w) { 192 | switch (w) { 193 | case EMPTY: 194 | case CLOUD: 195 | return 0; 196 | default: 197 | return 1; 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /src/item.h: -------------------------------------------------------------------------------- 1 | #ifndef _item_h_ 2 | #define _item_h_ 3 | 4 | #define EMPTY 0 5 | #define GRASS 1 6 | #define SAND 2 7 | #define STONE 3 8 | #define BRICK 4 9 | #define WOOD 5 10 | #define CEMENT 6 11 | #define DIRT 7 12 | #define PLANK 8 13 | #define SNOW 9 14 | #define GLASS 10 15 | #define COBBLE 11 16 | #define LIGHT_STONE 12 17 | #define DARK_STONE 13 18 | #define CHEST 14 19 | #define LEAVES 15 20 | #define CLOUD 16 21 | #define TALL_GRASS 17 22 | #define YELLOW_FLOWER 18 23 | #define RED_FLOWER 19 24 | #define PURPLE_FLOWER 20 25 | #define SUN_FLOWER 21 26 | #define WHITE_FLOWER 22 27 | #define BLUE_FLOWER 23 28 | #define COLOR_00 32 29 | #define COLOR_01 33 30 | #define COLOR_02 34 31 | #define COLOR_03 35 32 | #define COLOR_04 36 33 | #define COLOR_05 37 34 | #define COLOR_06 38 35 | #define COLOR_07 39 36 | #define COLOR_08 40 37 | #define COLOR_09 41 38 | #define COLOR_10 42 39 | #define COLOR_11 43 40 | #define COLOR_12 44 41 | #define COLOR_13 45 42 | #define COLOR_14 46 43 | #define COLOR_15 47 44 | #define COLOR_16 48 45 | #define COLOR_17 49 46 | #define COLOR_18 50 47 | #define COLOR_19 51 48 | #define COLOR_20 52 49 | #define COLOR_21 53 50 | #define COLOR_22 54 51 | #define COLOR_23 55 52 | #define COLOR_24 56 53 | #define COLOR_25 57 54 | #define COLOR_26 58 55 | #define COLOR_27 59 56 | #define COLOR_28 60 57 | #define COLOR_29 61 58 | #define COLOR_30 62 59 | #define COLOR_31 63 60 | 61 | extern const int items[]; 62 | extern const int item_count; 63 | extern const int blocks[256][6]; 64 | extern const int plants[256]; 65 | 66 | int is_plant(int w); 67 | int is_obstacle(int w); 68 | int is_transparent(int w); 69 | int is_destructable(int w); 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /src/map.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "map.h" 4 | 5 | int hash_int(int key) { 6 | key = ~key + (key << 15); 7 | key = key ^ (key >> 12); 8 | key = key + (key << 2); 9 | key = key ^ (key >> 4); 10 | key = key * 2057; 11 | key = key ^ (key >> 16); 12 | return key; 13 | } 14 | 15 | int hash(int x, int y, int z) { 16 | x = hash_int(x); 17 | y = hash_int(y); 18 | z = hash_int(z); 19 | return x ^ y ^ z; 20 | } 21 | 22 | void map_alloc(Map *map, int dx, int dy, int dz, int mask) { 23 | map->dx = dx; 24 | map->dy = dy; 25 | map->dz = dz; 26 | map->mask = mask; 27 | map->size = 0; 28 | map->data = (MapEntry *)calloc(map->mask + 1, sizeof(MapEntry)); 29 | } 30 | 31 | void map_free(Map *map) { 32 | free(map->data); 33 | } 34 | 35 | void map_copy(Map *dst, Map *src) { 36 | dst->dx = src->dx; 37 | dst->dy = src->dy; 38 | dst->dz = src->dz; 39 | dst->mask = src->mask; 40 | dst->size = src->size; 41 | dst->data = (MapEntry *)calloc(dst->mask + 1, sizeof(MapEntry)); 42 | memcpy(dst->data, src->data, (dst->mask + 1) * sizeof(MapEntry)); 43 | } 44 | 45 | int map_set(Map *map, int x, int y, int z, int w) { 46 | unsigned int index = hash(x, y, z) & map->mask; 47 | x -= map->dx; 48 | y -= map->dy; 49 | z -= map->dz; 50 | MapEntry *entry = map->data + index; 51 | int overwrite = 0; 52 | while (!EMPTY_ENTRY(entry)) { 53 | if (entry->e.x == x && entry->e.y == y && entry->e.z == z) { 54 | overwrite = 1; 55 | break; 56 | } 57 | index = (index + 1) & map->mask; 58 | entry = map->data + index; 59 | } 60 | if (overwrite) { 61 | if (entry->e.w != w) { 62 | entry->e.w = w; 63 | return 1; 64 | } 65 | } 66 | else if (w) { 67 | entry->e.x = x; 68 | entry->e.y = y; 69 | entry->e.z = z; 70 | entry->e.w = w; 71 | map->size++; 72 | if (map->size * 2 > map->mask) { 73 | map_grow(map); 74 | } 75 | return 1; 76 | } 77 | return 0; 78 | } 79 | 80 | int map_get(Map *map, int x, int y, int z) { 81 | unsigned int index = hash(x, y, z) & map->mask; 82 | x -= map->dx; 83 | y -= map->dy; 84 | z -= map->dz; 85 | if (x < 0 || x > 255) return 0; 86 | if (y < 0 || y > 255) return 0; 87 | if (z < 0 || z > 255) return 0; 88 | MapEntry *entry = map->data + index; 89 | while (!EMPTY_ENTRY(entry)) { 90 | if (entry->e.x == x && entry->e.y == y && entry->e.z == z) { 91 | return entry->e.w; 92 | } 93 | index = (index + 1) & map->mask; 94 | entry = map->data + index; 95 | } 96 | return 0; 97 | } 98 | 99 | void map_grow(Map *map) { 100 | Map new_map; 101 | new_map.dx = map->dx; 102 | new_map.dy = map->dy; 103 | new_map.dz = map->dz; 104 | new_map.mask = (map->mask << 1) | 1; 105 | new_map.size = 0; 106 | new_map.data = (MapEntry *)calloc(new_map.mask + 1, sizeof(MapEntry)); 107 | MAP_FOR_EACH(map, ex, ey, ez, ew) { 108 | map_set(&new_map, ex, ey, ez, ew); 109 | } END_MAP_FOR_EACH; 110 | free(map->data); 111 | map->mask = new_map.mask; 112 | map->size = new_map.size; 113 | map->data = new_map.data; 114 | } 115 | -------------------------------------------------------------------------------- /src/map.h: -------------------------------------------------------------------------------- 1 | #ifndef _map_h_ 2 | #define _map_h_ 3 | 4 | #define EMPTY_ENTRY(entry) ((entry)->value == 0) 5 | 6 | #define MAP_FOR_EACH(map, ex, ey, ez, ew) \ 7 | for (unsigned int i = 0; i <= map->mask; i++) { \ 8 | MapEntry *entry = map->data + i; \ 9 | if (EMPTY_ENTRY(entry)) { \ 10 | continue; \ 11 | } \ 12 | int ex = entry->e.x + map->dx; \ 13 | int ey = entry->e.y + map->dy; \ 14 | int ez = entry->e.z + map->dz; \ 15 | int ew = entry->e.w; 16 | 17 | #define END_MAP_FOR_EACH } 18 | 19 | typedef union { 20 | unsigned int value; 21 | struct { 22 | unsigned char x; 23 | unsigned char y; 24 | unsigned char z; 25 | char w; 26 | } e; 27 | } MapEntry; 28 | 29 | typedef struct { 30 | int dx; 31 | int dy; 32 | int dz; 33 | unsigned int mask; 34 | unsigned int size; 35 | MapEntry *data; 36 | } Map; 37 | 38 | void map_alloc(Map *map, int dx, int dy, int dz, int mask); 39 | void map_free(Map *map); 40 | void map_copy(Map *dst, Map *src); 41 | void map_grow(Map *map); 42 | int map_set(Map *map, int x, int y, int z, int w); 43 | int map_get(Map *map, int x, int y, int z); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/matrix.h: -------------------------------------------------------------------------------- 1 | #ifndef _matrix_h_ 2 | #define _matrix_h_ 3 | 4 | void normalize(float *x, float *y, float *z); 5 | void mat_identity(float *matrix); 6 | void mat_translate(float *matrix, float dx, float dy, float dz); 7 | void mat_rotate(float *matrix, float x, float y, float z, float angle); 8 | void mat_vec_multiply(float *vector, float *a, float *b); 9 | void mat_multiply(float *matrix, float *a, float *b); 10 | void mat_apply(float *data, float *matrix, int count, int offset, int stride); 11 | void frustum_planes(float planes[6][4], int radius, float *matrix); 12 | void mat_frustum( 13 | float *matrix, float left, float right, float bottom, 14 | float top, float znear, float zfar); 15 | void mat_perspective( 16 | float *matrix, float fov, float aspect, 17 | float near, float far); 18 | void mat_ortho( 19 | float *matrix, 20 | float left, float right, float bottom, float top, float near, float far); 21 | void set_matrix_2d(float *matrix, int width, int height); 22 | void set_matrix_3d( 23 | float *matrix, int width, int height, 24 | float x, float y, float z, float rx, float ry, 25 | float fov, int ortho, int radius); 26 | void set_matrix_item(float *matrix, int width, int height, int scale); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/ring.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "ring.h" 4 | 5 | void ring_alloc(Ring *ring, int capacity) { 6 | ring->capacity = capacity; 7 | ring->start = 0; 8 | ring->end = 0; 9 | ring->data = (RingEntry *)calloc(capacity, sizeof(RingEntry)); 10 | } 11 | 12 | void ring_free(Ring *ring) { 13 | free(ring->data); 14 | } 15 | 16 | int ring_empty(Ring *ring) { 17 | return ring->start == ring->end; 18 | } 19 | 20 | int ring_full(Ring *ring) { 21 | return ring->start == (ring->end + 1) % ring->capacity; 22 | } 23 | 24 | int ring_size(Ring *ring) { 25 | if (ring->end >= ring->start) { 26 | return ring->end - ring->start; 27 | } 28 | else { 29 | return ring->capacity - (ring->start - ring->end); 30 | } 31 | } 32 | 33 | void ring_grow(Ring *ring) { 34 | Ring new_ring; 35 | RingEntry entry; 36 | ring_alloc(&new_ring, ring->capacity * 2); 37 | while (ring_get(ring, &entry)) { 38 | ring_put(&new_ring, &entry); 39 | } 40 | free(ring->data); 41 | ring->capacity = new_ring.capacity; 42 | ring->start = new_ring.start; 43 | ring->end = new_ring.end; 44 | ring->data = new_ring.data; 45 | } 46 | 47 | void ring_put(Ring *ring, RingEntry *entry) { 48 | if (ring_full(ring)) { 49 | ring_grow(ring); 50 | } 51 | RingEntry *e = ring->data + ring->end; 52 | memcpy(e, entry, sizeof(RingEntry)); 53 | ring->end = (ring->end + 1) % ring->capacity; 54 | } 55 | 56 | void ring_put_block(Ring *ring, int p, int q, int x, int y, int z, int w) { 57 | RingEntry entry; 58 | entry.type = BLOCK; 59 | entry.p = p; 60 | entry.q = q; 61 | entry.x = x; 62 | entry.y = y; 63 | entry.z = z; 64 | entry.w = w; 65 | ring_put(ring, &entry); 66 | } 67 | 68 | void ring_put_light(Ring *ring, int p, int q, int x, int y, int z, int w) { 69 | RingEntry entry; 70 | entry.type = LIGHT; 71 | entry.p = p; 72 | entry.q = q; 73 | entry.x = x; 74 | entry.y = y; 75 | entry.z = z; 76 | entry.w = w; 77 | ring_put(ring, &entry); 78 | } 79 | 80 | void ring_put_key(Ring *ring, int p, int q, int key) { 81 | RingEntry entry; 82 | entry.type = KEY; 83 | entry.p = p; 84 | entry.q = q; 85 | entry.key = key; 86 | ring_put(ring, &entry); 87 | } 88 | 89 | void ring_put_commit(Ring *ring) { 90 | RingEntry entry; 91 | entry.type = COMMIT; 92 | ring_put(ring, &entry); 93 | } 94 | 95 | void ring_put_exit(Ring *ring) { 96 | RingEntry entry; 97 | entry.type = EXIT; 98 | ring_put(ring, &entry); 99 | } 100 | 101 | int ring_get(Ring *ring, RingEntry *entry) { 102 | if (ring_empty(ring)) { 103 | return 0; 104 | } 105 | RingEntry *e = ring->data + ring->start; 106 | memcpy(entry, e, sizeof(RingEntry)); 107 | ring->start = (ring->start + 1) % ring->capacity; 108 | return 1; 109 | } 110 | -------------------------------------------------------------------------------- /src/ring.h: -------------------------------------------------------------------------------- 1 | #ifndef _ring_h_ 2 | #define _ring_h_ 3 | 4 | typedef enum { 5 | BLOCK, 6 | LIGHT, 7 | KEY, 8 | COMMIT, 9 | EXIT 10 | } RingEntryType; 11 | 12 | typedef struct { 13 | RingEntryType type; 14 | int p; 15 | int q; 16 | int x; 17 | int y; 18 | int z; 19 | int w; 20 | int key; 21 | } RingEntry; 22 | 23 | typedef struct { 24 | unsigned int capacity; 25 | unsigned int start; 26 | unsigned int end; 27 | RingEntry *data; 28 | } Ring; 29 | 30 | void ring_alloc(Ring *ring, int capacity); 31 | void ring_free(Ring *ring); 32 | int ring_empty(Ring *ring); 33 | int ring_full(Ring *ring); 34 | int ring_size(Ring *ring); 35 | void ring_grow(Ring *ring); 36 | void ring_put(Ring *ring, RingEntry *entry); 37 | void ring_put_block(Ring *ring, int p, int q, int x, int y, int z, int w); 38 | void ring_put_light(Ring *ring, int p, int q, int x, int y, int z, int w); 39 | void ring_put_key(Ring *ring, int p, int q, int key); 40 | void ring_put_commit(Ring *ring); 41 | void ring_put_exit(Ring *ring); 42 | int ring_get(Ring *ring, RingEntry *entry); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/sign.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sign.h" 4 | 5 | void sign_list_alloc(SignList *list, int capacity) { 6 | list->capacity = capacity; 7 | list->size = 0; 8 | list->data = (Sign *)calloc(capacity, sizeof(Sign)); 9 | } 10 | 11 | void sign_list_free(SignList *list) { 12 | free(list->data); 13 | } 14 | 15 | void sign_list_grow(SignList *list) { 16 | SignList new_list; 17 | sign_list_alloc(&new_list, list->capacity * 2); 18 | memcpy(new_list.data, list->data, list->size * sizeof(Sign)); 19 | free(list->data); 20 | list->capacity = new_list.capacity; 21 | list->data = new_list.data; 22 | } 23 | 24 | void _sign_list_add(SignList *list, Sign *sign) { 25 | if (list->size == list->capacity) { 26 | sign_list_grow(list); 27 | } 28 | Sign *e = list->data + list->size++; 29 | memcpy(e, sign, sizeof(Sign)); 30 | } 31 | 32 | void sign_list_add( 33 | SignList *list, int x, int y, int z, int face, const char *text) 34 | { 35 | sign_list_remove(list, x, y, z, face); 36 | Sign sign; 37 | sign.x = x; 38 | sign.y = y; 39 | sign.z = z; 40 | sign.face = face; 41 | strncpy(sign.text, text, MAX_SIGN_LENGTH); 42 | sign.text[MAX_SIGN_LENGTH - 1] = '\0'; 43 | _sign_list_add(list, &sign); 44 | } 45 | 46 | int sign_list_remove(SignList *list, int x, int y, int z, int face) { 47 | int result = 0; 48 | for (int i = 0; i < list->size; i++) { 49 | Sign *e = list->data + i; 50 | if (e->x == x && e->y == y && e->z == z && e->face == face) { 51 | Sign *other = list->data + (--list->size); 52 | memcpy(e, other, sizeof(Sign)); 53 | i--; 54 | result++; 55 | } 56 | } 57 | return result; 58 | } 59 | 60 | int sign_list_remove_all(SignList *list, int x, int y, int z) { 61 | int result = 0; 62 | for (int i = 0; i < list->size; i++) { 63 | Sign *e = list->data + i; 64 | if (e->x == x && e->y == y && e->z == z) { 65 | Sign *other = list->data + (--list->size); 66 | memcpy(e, other, sizeof(Sign)); 67 | i--; 68 | result++; 69 | } 70 | } 71 | return result; 72 | } 73 | -------------------------------------------------------------------------------- /src/sign.h: -------------------------------------------------------------------------------- 1 | #ifndef _sign_h_ 2 | #define _sign_h_ 3 | 4 | #define MAX_SIGN_LENGTH 64 5 | 6 | typedef struct { 7 | int x; 8 | int y; 9 | int z; 10 | int face; 11 | char text[MAX_SIGN_LENGTH]; 12 | } Sign; 13 | 14 | typedef struct { 15 | unsigned int capacity; 16 | unsigned int size; 17 | Sign *data; 18 | } SignList; 19 | 20 | void sign_list_alloc(SignList *list, int capacity); 21 | void sign_list_free(SignList *list); 22 | void sign_list_grow(SignList *list); 23 | void sign_list_add( 24 | SignList *list, int x, int y, int z, int face, const char *text); 25 | int sign_list_remove(SignList *list, int x, int y, int z, int face); 26 | int sign_list_remove_all(SignList *list, int x, int y, int z); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/util.h: -------------------------------------------------------------------------------- 1 | #ifndef _util_h_ 2 | #define _util_h_ 3 | 4 | #include 5 | #include 6 | #include "config.h" 7 | 8 | #define PI 3.14159265359 9 | #define DEGREES(radians) ((radians) * 180 / PI) 10 | #define RADIANS(degrees) ((degrees) * PI / 180) 11 | #define ABS(x) ((x) < 0 ? (-(x)) : (x)) 12 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) 13 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) 14 | #define SIGN(x) (((x) > 0) - ((x) < 0)) 15 | 16 | #if DEBUG 17 | #define LOG(...) printf(__VA_ARGS__) 18 | #else 19 | #define LOG(...) 20 | #endif 21 | 22 | typedef struct { 23 | unsigned int fps; 24 | unsigned int frames; 25 | double since; 26 | } FPS; 27 | 28 | int rand_int(int n); 29 | double rand_double(); 30 | void update_fps(FPS *fps); 31 | 32 | GLuint gen_buffer(GLsizei size, GLfloat *data); 33 | void del_buffer(GLuint buffer); 34 | GLfloat *malloc_faces(int components, int faces); 35 | GLuint gen_faces(int components, int faces, GLfloat *data); 36 | GLuint make_shader(GLenum type, const char *source); 37 | GLuint load_shader(GLenum type, const char *path); 38 | GLuint make_program(GLuint shader1, GLuint shader2); 39 | GLuint load_program(const char *path1, const char *path2); 40 | void load_png_texture(const char *file_name); 41 | char *tokenize(char *str, const char *delim, char **key); 42 | int char_width(char input); 43 | int string_width(const char *input); 44 | int wrap(const char *input, int max_width, char *output, int max_length); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/world.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include "noise.h" 3 | #include "world.h" 4 | 5 | void create_world(int p, int q, world_func func, void *arg) { 6 | int pad = 1; 7 | for (int dx = -pad; dx < CHUNK_SIZE + pad; dx++) { 8 | for (int dz = -pad; dz < CHUNK_SIZE + pad; dz++) { 9 | int flag = 1; 10 | if (dx < 0 || dz < 0 || dx >= CHUNK_SIZE || dz >= CHUNK_SIZE) { 11 | flag = -1; 12 | } 13 | int x = p * CHUNK_SIZE + dx; 14 | int z = q * CHUNK_SIZE + dz; 15 | float f = simplex2(x * 0.01, z * 0.01, 4, 0.5, 2); 16 | float g = simplex2(-x * 0.01, -z * 0.01, 2, 0.9, 2); 17 | int mh = g * 32 + 16; 18 | int h = f * mh; 19 | int w = 1; 20 | int t = 12; 21 | if (h <= t) { 22 | h = t; 23 | w = 2; 24 | } 25 | // sand and grass terrain 26 | for (int y = 0; y < h; y++) { 27 | func(x, y, z, w * flag, arg); 28 | } 29 | if (w == 1) { 30 | if (SHOW_PLANTS) { 31 | // grass 32 | if (simplex2(-x * 0.1, z * 0.1, 4, 0.8, 2) > 0.6) { 33 | func(x, h, z, 17 * flag, arg); 34 | } 35 | // flowers 36 | if (simplex2(x * 0.05, -z * 0.05, 4, 0.8, 2) > 0.7) { 37 | int w = 18 + simplex2(x * 0.1, z * 0.1, 4, 0.8, 2) * 7; 38 | func(x, h, z, w * flag, arg); 39 | } 40 | } 41 | // trees 42 | int ok = SHOW_TREES; 43 | if (dx - 4 < 0 || dz - 4 < 0 || 44 | dx + 4 >= CHUNK_SIZE || dz + 4 >= CHUNK_SIZE) 45 | { 46 | ok = 0; 47 | } 48 | if (ok && simplex2(x, z, 6, 0.5, 2) > 0.84) { 49 | for (int y = h + 3; y < h + 8; y++) { 50 | for (int ox = -3; ox <= 3; ox++) { 51 | for (int oz = -3; oz <= 3; oz++) { 52 | int d = (ox * ox) + (oz * oz) + 53 | (y - (h + 4)) * (y - (h + 4)); 54 | if (d < 11) { 55 | func(x + ox, y, z + oz, 15, arg); 56 | } 57 | } 58 | } 59 | } 60 | for (int y = h; y < h + 7; y++) { 61 | func(x, y, z, 5, arg); 62 | } 63 | } 64 | } 65 | // clouds 66 | if (SHOW_CLOUDS) { 67 | for (int y = 64; y < 72; y++) { 68 | if (simplex3( 69 | x * 0.01, y * 0.1, z * 0.01, 8, 0.5, 2) > 0.75) 70 | { 71 | func(x, y, z, 16 * flag, arg); 72 | } 73 | } 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/world.h: -------------------------------------------------------------------------------- 1 | #ifndef _world_h_ 2 | #define _world_h_ 3 | 4 | typedef void (*world_func)(int, int, int, int, void *); 5 | 6 | void create_world(int p, int q, world_func func, void *arg); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /textures/font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fogleman/Craft/d6888a6e1e54340358ce25b1220f410541360b6b/textures/font.png -------------------------------------------------------------------------------- /textures/sign.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fogleman/Craft/d6888a6e1e54340358ce25b1220f410541360b6b/textures/sign.png -------------------------------------------------------------------------------- /textures/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fogleman/Craft/d6888a6e1e54340358ce25b1220f410541360b6b/textures/sky.png -------------------------------------------------------------------------------- /textures/texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fogleman/Craft/d6888a6e1e54340358ce25b1220f410541360b6b/textures/texture.png -------------------------------------------------------------------------------- /world.py: -------------------------------------------------------------------------------- 1 | # gcc -std=c99 -O3 -shared -o world \ 2 | # -I src -I deps/noise deps/noise/noise.c src/world.c 3 | 4 | from ctypes import CDLL, CFUNCTYPE, c_float, c_int, c_void_p 5 | from collections import OrderedDict 6 | 7 | dll = CDLL('./world') 8 | 9 | WORLD_FUNC = CFUNCTYPE(None, c_int, c_int, c_int, c_int, c_void_p) 10 | 11 | def dll_seed(x): 12 | dll.seed(x) 13 | 14 | def dll_create_world(p, q): 15 | result = {} 16 | def world_func(x, y, z, w, arg): 17 | result[(x, y, z)] = w 18 | dll.create_world(p, q, WORLD_FUNC(world_func), None) 19 | return result 20 | 21 | dll.simplex2.restype = c_float 22 | dll.simplex2.argtypes = [c_float, c_float, c_int, c_float, c_float] 23 | def dll_simplex2(x, y, octaves=1, persistence=0.5, lacunarity=2.0): 24 | return dll.simplex2(x, y, octaves, persistence, lacunarity) 25 | 26 | dll.simplex3.restype = c_float 27 | dll.simplex3.argtypes = [c_float, c_float, c_float, c_int, c_float, c_float] 28 | def dll_simplex3(x, y, z, octaves=1, persistence=0.5, lacunarity=2.0): 29 | return dll.simplex3(x, y, z, octaves, persistence, lacunarity) 30 | 31 | class World(object): 32 | def __init__(self, seed=None, cache_size=64): 33 | self.seed = seed 34 | self.cache = OrderedDict() 35 | self.cache_size = cache_size 36 | def create_chunk(self, p, q): 37 | if self.seed is not None: 38 | dll_seed(self.seed) 39 | return dll_create_world(p, q) 40 | def get_chunk(self, p, q): 41 | try: 42 | chunk = self.cache.pop((p, q)) 43 | except KeyError: 44 | chunk = self.create_chunk(p, q) 45 | self.cache[(p, q)] = chunk 46 | if len(self.cache) > self.cache_size: 47 | self.cache.popitem(False) 48 | return chunk 49 | --------------------------------------------------------------------------------