├── .clang-format ├── .gitattributes ├── .gitignore ├── .vscode └── .cmaketools.json ├── CMakeLists.txt ├── Example_CPP ├── CMakeLists.txt ├── Screen_Capture_Example.cpp ├── lodepng.cpp ├── lodepng.h └── tiny_jpeg.h ├── Example_CSharp ├── CMakeLists.txt ├── Program.cs └── screen_capture_lite_example_csharp.csproj ├── Example_OpenGL ├── CMakeLists.txt ├── Screen_Capture_Example_OpenGL.cpp └── glfw │ ├── .mailmap │ ├── CMake │ ├── GenerateMappings.cmake │ ├── MacOSXBundleInfo.plist.in │ ├── i686-w64-mingw32-clang.cmake │ ├── i686-w64-mingw32.cmake │ ├── modules │ │ ├── FindEpollShim.cmake │ │ ├── FindOSMesa.cmake │ │ ├── FindWaylandProtocols.cmake │ │ └── FindXKBCommon.cmake │ ├── x86_64-w64-mingw32-clang.cmake │ └── x86_64-w64-mingw32.cmake │ ├── CMakeLists.txt │ ├── LICENSE.md │ ├── README.md │ ├── cmake_uninstall.cmake.in │ ├── deps │ ├── getopt.c │ ├── getopt.h │ ├── glad │ │ ├── gl.h │ │ ├── khrplatform.h │ │ ├── vk_platform.h │ │ └── vulkan.h │ ├── glad_gl.c │ ├── glad_vulkan.c │ ├── linmath.h │ ├── mingw │ │ ├── _mingw_dxhelper.h │ │ ├── dinput.h │ │ └── xinput.h │ ├── nuklear.h │ ├── nuklear_glfw_gl2.h │ ├── stb_image_write.h │ ├── tinycthread.c │ ├── tinycthread.h │ └── vs2008 │ │ └── stdint.h │ ├── docs │ ├── CMakeLists.txt │ ├── CODEOWNERS │ ├── CONTRIBUTING.md │ ├── Doxyfile.in │ ├── DoxygenLayout.xml │ ├── SUPPORT.md │ ├── build.dox │ ├── compat.dox │ ├── compile.dox │ ├── context.dox │ ├── extra.css │ ├── extra.css.map │ ├── extra.scss │ ├── footer.html │ ├── header.html │ ├── input.dox │ ├── internal.dox │ ├── intro.dox │ ├── main.dox │ ├── monitor.dox │ ├── moving.dox │ ├── news.dox │ ├── quick.dox │ ├── spaces.svg │ ├── vulkan.dox │ └── window.dox │ ├── examples │ ├── CMakeLists.txt │ ├── boing.c │ ├── gears.c │ ├── glfw.icns │ ├── glfw.ico │ ├── glfw.rc │ ├── heightmap.c │ ├── offscreen.c │ ├── particles.c │ ├── sharing.c │ ├── simple.c │ ├── splitview.c │ └── wave.c │ ├── include │ └── GLFW │ │ ├── glfw3.h │ │ └── glfw3native.h │ ├── src │ ├── CMakeLists.txt │ ├── cocoa_init.m │ ├── cocoa_joystick.h │ ├── cocoa_joystick.m │ ├── cocoa_monitor.m │ ├── cocoa_platform.h │ ├── cocoa_time.c │ ├── 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 │ ├── linux_joystick.c │ ├── linux_joystick.h │ ├── mappings.h │ ├── mappings.h.in │ ├── monitor.c │ ├── nsgl_context.h │ ├── nsgl_context.m │ ├── null_init.c │ ├── null_joystick.c │ ├── null_joystick.h │ ├── null_monitor.c │ ├── null_platform.h │ ├── null_window.c │ ├── osmesa_context.c │ ├── osmesa_context.h │ ├── posix_thread.c │ ├── posix_thread.h │ ├── posix_time.c │ ├── posix_time.h │ ├── vulkan.c │ ├── wgl_context.c │ ├── wgl_context.h │ ├── win32_init.c │ ├── win32_joystick.c │ ├── win32_joystick.h │ ├── win32_monitor.c │ ├── win32_platform.h │ ├── win32_thread.c │ ├── win32_time.c │ ├── win32_window.c │ ├── window.c │ ├── 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 │ ├── icon.c │ ├── iconify.c │ ├── inputlag.c │ ├── joysticks.c │ ├── monitors.c │ ├── msaa.c │ ├── opacity.c │ ├── reopen.c │ ├── tearing.c │ ├── threads.c │ ├── timeout.c │ ├── title.c │ ├── triangle-vulkan.c │ └── windows.c ├── Example_Unity └── CMakeLists.txt ├── LICENSE ├── Logotype primary.png ├── README.md ├── azure-devops └── build-windows.yml ├── azure-pipelines.yml ├── cmake_uninstall.cmake.in ├── include ├── ScreenCapture.h ├── ScreenCapture_C_API.h ├── internal │ ├── SCCommon.h │ └── ThreadManager.h ├── ios │ ├── CGFrameProcessor.h │ ├── NSFrameProcessor.h │ ├── NSFrameProcessorm.h │ ├── NSMouseCapture.h │ └── NSMouseProcessor.h ├── linux │ ├── X11FrameProcessor.h │ └── X11MouseProcessor.h └── windows │ ├── DXFrameProcessor.h │ ├── GDIFrameProcessor.h │ ├── GDIHelpers.h │ └── GDIMouseProcessor.h ├── modules ├── screen_capture_lite_sharedConfig.cmake.in └── screen_capture_lite_staticConfig.cmake.in ├── releasenotes.txt ├── src_cpp ├── CMakeLists.txt ├── SCCommon.cpp ├── ScreenCapture.c ├── ScreenCapture.cpp ├── ThreadManager.cpp ├── ios │ ├── CGFrameProcessor.cpp │ ├── GetMonitors.cpp │ ├── GetWindows.cpp │ ├── NSFrameProcessor.cpp │ ├── NSFrameProcessor.mm │ ├── NSMouseCapture.m │ ├── NSMouseProcessor.cpp │ └── ThreadRunner.cpp ├── linux │ ├── GetMonitors.cpp │ ├── GetWindows.cpp │ ├── ThreadRunner.cpp │ ├── X11FrameProcessor.cpp │ └── X11MouseProcessor.cpp └── windows │ ├── DXFrameProcessor.cpp │ ├── GDIFrameProcessor.cpp │ ├── GDIMouseProcessor.cpp │ ├── GetMonitors.cpp │ ├── GetWindows.cpp │ └── ThreadRunner.cpp └── src_csharp ├── CMakeLists.txt ├── MonitorCaptureConfiguration.cs ├── NativeFunctions.cs ├── NativeTypes.cs ├── ScreenCaptureManager.cs ├── UnmanagedUtility.cs ├── WindowCaptureConfiguration.cs └── screen_capture_lite_csharp.csproj /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | Language: Cpp 3 | IndentWidth: 4 4 | TabWidth: 8 5 | UseTab: Never 6 | BreakBeforeBraces: Stroustrup 7 | NamespaceIndentation: Inner 8 | ColumnLimit: 150 -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | [Rr]eleases/ 14 | x64/ 15 | x86/ 16 | build/ 17 | bld/ 18 | [Bb]in/ 19 | [Oo]bj/ 20 | 21 | # Roslyn cache directories 22 | *.ide/ 23 | 24 | # MSTest test Results 25 | [Tt]est[Rr]esult*/ 26 | [Bb]uild[Ll]og.* 27 | 28 | #NUNIT 29 | *.VisualState.xml 30 | TestResult.xml 31 | 32 | # Build Results of an ATL Project 33 | [Dd]ebugPS/ 34 | [Rr]eleasePS/ 35 | dlldata.c 36 | 37 | *_i.c 38 | *_p.c 39 | *_i.h 40 | *.ilk 41 | *.meta 42 | *.obj 43 | *.pch 44 | *.pdb 45 | *.pgc 46 | *.pgd 47 | *.rsp 48 | *.sbr 49 | *.tlb 50 | *.tli 51 | *.tlh 52 | *.tmp 53 | *.tmp_proj 54 | *.log 55 | *.vspscc 56 | *.vssscc 57 | .builds 58 | *.pidb 59 | *.svclog 60 | *.scc 61 | *.db 62 | *.opendb 63 | 64 | # Chutzpah Test files 65 | _Chutzpah* 66 | 67 | # Visual C++ cache files 68 | ipch/ 69 | *.aps 70 | *.ncb 71 | *.opensdf 72 | *.sdf 73 | *.cachefile 74 | .vs/ 75 | 76 | # Visual Studio profiler 77 | *.psess 78 | *.vsp 79 | *.vspx 80 | 81 | # TFS 2012 Local Workspace 82 | $tf/ 83 | 84 | # Guidance Automation Toolkit 85 | *.gpState 86 | 87 | # ReSharper is a .NET coding add-in 88 | _ReSharper*/ 89 | *.[Rr]e[Ss]harper 90 | *.DotSettings.user 91 | 92 | # JustCode is a .NET coding addin-in 93 | .JustCode 94 | 95 | # TeamCity is a build add-in 96 | _TeamCity* 97 | 98 | # DotCover is a Code Coverage Tool 99 | *.dotCover 100 | 101 | # NCrunch 102 | _NCrunch_* 103 | .*crunch*.local.xml 104 | 105 | # MightyMoose 106 | *.mm.* 107 | AutoTest.Net/ 108 | 109 | # Web workbench (sass) 110 | .sass-cache/ 111 | 112 | # Installshield output folder 113 | [Ee]xpress/ 114 | 115 | # DocProject is a documentation generator add-in 116 | DocProject/buildhelp/ 117 | DocProject/Help/*.HxT 118 | DocProject/Help/*.HxC 119 | DocProject/Help/*.hhc 120 | DocProject/Help/*.hhk 121 | DocProject/Help/*.hhp 122 | DocProject/Help/Html2 123 | DocProject/Help/html 124 | 125 | # Click-Once directory 126 | publish/ 127 | 128 | # Publish Web Output 129 | *.[Pp]ublish.xml 130 | *.azurePubxml 131 | # TODO: Comment the next line if you want to checkin your web deploy settings 132 | # but database connection strings (with potential passwords) will be unencrypted 133 | *.pubxml 134 | *.publishproj 135 | 136 | # NuGet Packages 137 | *.nupkg 138 | # The packages folder can be ignored because of Package Restore 139 | **/packages/* 140 | # except build/, which is used as an MSBuild target. 141 | !**/packages/build/ 142 | # If using the old MSBuild-Integrated Package Restore, uncomment this: 143 | #!**/packages/repositories.config 144 | 145 | # Windows Azure Build Output 146 | csx/ 147 | *.build.csdef 148 | 149 | # Windows Store app package directory 150 | AppPackages/ 151 | 152 | # Others 153 | sql/ 154 | *.Cache 155 | ClientBin/ 156 | [Ss]tyle[Cc]op.* 157 | ~$* 158 | *~ 159 | *.dbmdl 160 | *.dbproj.schemaview 161 | *.pfx 162 | *.publishsettings 163 | node_modules/ 164 | 165 | # RIA/Silverlight projects 166 | Generated_Code/ 167 | 168 | # Backup & report files from converting an old project file 169 | # to a newer Visual Studio version. Backup files are not needed, 170 | # because we have git ;-) 171 | _UpgradeReport_Files/ 172 | Backup*/ 173 | UpgradeLog*.XML 174 | UpgradeLog*.htm 175 | 176 | # SQL Server files 177 | *.mdf 178 | *.ldf 179 | 180 | # Business Intelligence projects 181 | *.rdl.data 182 | *.bim.layout 183 | *.bim_*.settings 184 | 185 | # Microsoft Fakes 186 | FakesAssemblies/ 187 | 188 | # ========================= 189 | # Operating System Files 190 | # ========================= 191 | 192 | # OSX 193 | # ========================= 194 | 195 | .DS_Store 196 | .AppleDouble 197 | .LSOverride 198 | 199 | # Icon must end with two \r 200 | Icon 201 | 202 | 203 | # Thumbnails 204 | ._* 205 | 206 | # Files that might appear on external disk 207 | .Spotlight-V100 208 | .Trashes 209 | 210 | # Directories potentially created on remote AFP share 211 | .AppleDB 212 | .AppleDesktop 213 | Network Trash Folder 214 | Temporary Items 215 | .apdisk 216 | 217 | # Windows 218 | # ========================= 219 | 220 | # Windows image file caches 221 | Thumbs.db 222 | ehthumbs.db 223 | 224 | # Folder config file 225 | Desktop.ini 226 | 227 | # Recycle Bin used on file shares 228 | $RECYCLE.BIN/ 229 | 230 | # Windows Installer files 231 | *.cab 232 | *.msi 233 | *.msm 234 | *.msp 235 | .vs/* 236 | CMakeFiles 237 | CMakeCache.txt 238 | CTestTestfile.cmake 239 | Makefile 240 | cmake_install.cmake 241 | cmake_uninstall.cmake 242 | CMakeSettings.json 243 | *.dll 244 | *.sh -------------------------------------------------------------------------------- /.vscode/.cmaketools.json: -------------------------------------------------------------------------------- 1 | { 2 | "variant": null, 3 | "activeEnvironments": [], 4 | "codeModel": null 5 | } -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | project(screen_capture_lite_build VERSION 17.1) 3 | 4 | set(CMAKE_CXX_STANDARD 17) 5 | #set(CMAKE_DEBUG_POSTFIX "d") 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | set(CMAKE_CXX_EXTENSIONS OFF) 8 | option(BUILD_EXAMPLE "Build example" ON) 9 | option(BUILD_CSHARP "Build C#" ON) 10 | option(BUILD_SHARED_LIBS "Build shared libraries" ON) 11 | set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 12 | set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 13 | 14 | if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt) 15 | if (NOT CMAKE_BUILD_TYPE) 16 | set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE) 17 | endif() 18 | endif() 19 | 20 | if(MSVC) 21 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 -D_SILENCE_CXX20_OLD_SHARED_PTR_ATOMIC_SUPPORT_DEPRECATION_WARNING") 22 | else() 23 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic") 24 | endif() 25 | 26 | if(${BUILD_SHARED_LIBS}) 27 | set(TARGET_SUFFIX shared) 28 | else() 29 | set(TARGET_SUFFIX static) 30 | endif() 31 | 32 | set(TARGET_NAME screen_capture_lite_${TARGET_SUFFIX}) 33 | 34 | add_subdirectory(src_cpp) 35 | if(${BUILD_CSHARP} AND ${BUILD_SHARED_LIBS}) 36 | add_subdirectory(src_csharp) 37 | endif() 38 | 39 | install (TARGETS ${TARGET_NAME} 40 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 41 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 42 | PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 43 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 44 | ) 45 | 46 | configure_file(modules/${TARGET_NAME}Config.cmake.in ${TARGET_NAME}Config.cmake @ONLY) 47 | 48 | #export(TARGETS ${TARGET_NAME} FILE ${TARGET_NAME}-config.cmake) 49 | #install(EXPORT ${TARGET_NAME}-config FILE ${TARGET_NAME}-config.cmake DESTINATION lib/cmake/screen_capture_lite) 50 | 51 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}Config.cmake 52 | DESTINATION lib${LIB_SUFFIX}/cmake/${TARGET_NAME}) 53 | 54 | 55 | install (FILES 56 | include/ScreenCapture.h 57 | DESTINATION include 58 | ) 59 | 60 | if (NOT TARGET uninstall) 61 | configure_file( 62 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" 63 | "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" 64 | IMMEDIATE @ONLY) 65 | 66 | add_custom_target(uninstall 67 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) 68 | endif() 69 | 70 | enable_testing() 71 | 72 | if (${BUILD_EXAMPLE}) 73 | add_subdirectory(Example_OpenGL) 74 | add_subdirectory(Example_CPP) 75 | if(${BUILD_CSHARP} AND ${BUILD_SHARED_LIBS}) 76 | add_subdirectory(Example_CSharp) 77 | add_subdirectory(Example_Unity) 78 | endif() 79 | endif() 80 | -------------------------------------------------------------------------------- /Example_CPP/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(screen_capture_example_cpp) 2 | 3 | if(WIN32) 4 | add_definitions(-DNOMINMAX) 5 | endif() 6 | 7 | if(NOT ${BUILD_SHARED_LIBS}) 8 | if(WIN32) 9 | set(${PROJECT_NAME}_PLATFORM_LIBS Dwmapi) 10 | elseif(APPLE) 11 | find_package(Threads REQUIRED) 12 | find_library(corefoundation_lib CoreFoundation REQUIRED) 13 | find_library(cocoa_lib Cocoa REQUIRED) 14 | find_library(coremedia_lib CoreMedia REQUIRED) 15 | find_library(avfoundation_lib AVFoundation REQUIRED) 16 | find_library(coregraphics_lib CoreGraphics REQUIRED) 17 | find_library(corevideo_lib CoreVideo REQUIRED) 18 | 19 | set(${PROJECT_NAME}_PLATFORM_LIBS 20 | ${CMAKE_THREAD_LIBS_INIT} 21 | ${corefoundation_lib} 22 | ${cocoa_lib} 23 | ${coremedia_lib} 24 | ${avfoundation_lib} 25 | ${coregraphics_lib} 26 | ${corevideo_lib} 27 | ) 28 | else() 29 | find_package(X11 REQUIRED) 30 | if(!X11_XTest_FOUND) 31 | message(FATAL_ERROR "X11 extensions are required, but not found!") 32 | endif() 33 | if(!X11_Xfixes_LIB) 34 | message(FATAL_ERROR "X11 fixes extension is required, but not found!") 35 | endif() 36 | find_package(Threads REQUIRED) 37 | set(${PROJECT_NAME}_PLATFORM_LIBS 38 | ${X11_LIBRARIES} 39 | ${X11_Xfixes_LIB} 40 | ${X11_XTest_LIB} 41 | ${X11_Xinerama_LIB} 42 | ${CMAKE_THREAD_LIBS_INIT} 43 | ) 44 | endif() 45 | endif() 46 | 47 | include_directories( 48 | ../include 49 | ) 50 | 51 | add_executable(${PROJECT_NAME}_${TARGET_SUFFIX} 52 | lodepng.cpp 53 | Screen_Capture_Example.cpp 54 | ) 55 | target_link_libraries(${PROJECT_NAME}_${TARGET_SUFFIX} screen_capture_lite_${TARGET_SUFFIX} ${${PROJECT_NAME}_PLATFORM_LIBS}) 56 | 57 | install (TARGETS ${PROJECT_NAME}_${TARGET_SUFFIX} screen_capture_lite_${TARGET_SUFFIX} 58 | RUNTIME DESTINATION Examples 59 | ) 60 | 61 | -------------------------------------------------------------------------------- /Example_CSharp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(screen_capture_lite_example_csharp) 2 | 3 | set(OUTPUT ${PROJECT_NAME}.dll) 4 | set(CSPROJ ${PROJECT_NAME}.csproj) 5 | 6 | execute_process(COMMAND dotnet --version 7 | RESULT_VARIABLE result 8 | OUTPUT_QUIET 9 | ERROR_QUIET) 10 | if(result) 11 | message(STATUS "dotnet executable not found but by this build, if you want to build CSharp Bindings, you must install dotnet") 12 | else() 13 | set(PLATFORM x64) 14 | if(NOT DEFINED CMAKE_GENERATOR_PLATFORM) 15 | set(PLATFORM x64) 16 | elseif("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Win32") 17 | set(PLATFORM x86) 18 | ENDIF() 19 | message(STATUS "Found dotnet executable CSHARP bindings will be generated!") 20 | add_custom_command(OUTPUT ${OUTPUT} 21 | COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_LIST_DIR} 22 | COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_BINARY_DIR}/Example_CSharp 23 | COMMAND ${CMAKE_COMMAND} -E copy 24 | ${CMAKE_CURRENT_LIST_DIR}/${CSPROJ} 25 | ${CMAKE_BINARY_DIR}/Example_CSharp 26 | COMMAND ${CMAKE_COMMAND} -E copy 27 | ${CMAKE_CURRENT_LIST_DIR}/Program.cs 28 | ${CMAKE_BINARY_DIR}/Example_CSharp 29 | COMMAND dotnet build --configuration ${CMAKE_BUILD_TYPE} /p:Platform=${PLATFORM} ${CMAKE_BINARY_DIR}/Example_CSharp/${CSPROJ} -o ${CMAKE_BINARY_DIR} 30 | COMMENT "Building ${PROJECT_NAME} dotnet build --configuration ${CMAKE_BUILD_TYPE} /p:Platform=${PLATFORM} ${CMAKE_BINARY_DIR}/Example_CSharp/${CSPROJ} -o ${CMAKE_BINARY_DIR}" 31 | ) 32 | add_custom_target(${PROJECT_NAME} ALL DEPENDS ${OUTPUT}) 33 | 34 | install (FILES ${CMAKE_BINARY_DIR}/${OUTPUT} 35 | DESTINATION bin 36 | ) 37 | install (FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pdb 38 | DESTINATION bin 39 | OPTIONAL 40 | ) 41 | 42 | install (TARGETS screen_capture_lite_${TARGET_SUFFIX} 43 | RUNTIME DESTINATION Examples 44 | ) 45 | 46 | endif() 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Example_CSharp/screen_capture_lite_example_csharp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net6.0 6 | false 7 | x64;x86 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | Always 27 | 28 | 29 | Always 30 | 31 | 32 | Always 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Example_OpenGL/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(screen_capture_example_opengl_cpp) 2 | 3 | if(WIN32) 4 | add_definitions(-DNOMINMAX) 5 | endif() 6 | 7 | if(NOT ${BUILD_SHARED_LIBS}) 8 | if(WIN32) 9 | set(${PROJECT_NAME}_PLATFORM_LIBS Dwmapi) 10 | elseif(APPLE) 11 | find_package(Threads REQUIRED) 12 | find_library(corefoundation_lib CoreFoundation REQUIRED) 13 | find_library(cocoa_lib Cocoa REQUIRED) 14 | find_library(coremedia_lib CoreMedia REQUIRED) 15 | find_library(avfoundation_lib AVFoundation REQUIRED) 16 | find_library(coregraphics_lib CoreGraphics REQUIRED) 17 | find_library(corevideo_lib CoreVideo REQUIRED) 18 | 19 | set(${PROJECT_NAME}_PLATFORM_LIBS 20 | ${CMAKE_THREAD_LIBS_INIT} 21 | ${corefoundation_lib} 22 | ${cocoa_lib} 23 | ${coremedia_lib} 24 | ${avfoundation_lib} 25 | ${coregraphics_lib} 26 | ${corevideo_lib} 27 | ) 28 | else() 29 | find_package(X11 REQUIRED) 30 | if(!X11_XTest_FOUND) 31 | message(FATAL_ERROR "X11 extensions are required, but not found!") 32 | endif() 33 | if(!X11_Xfixes_LIB) 34 | message(FATAL_ERROR "X11 fixes extension is required, but not found!") 35 | endif() 36 | find_package(Threads REQUIRED) 37 | set(${PROJECT_NAME}_PLATFORM_LIBS 38 | ${X11_LIBRARIES} 39 | ${X11_Xfixes_LIB} 40 | ${X11_XTest_LIB} 41 | ${X11_Xinerama_LIB} 42 | ${CMAKE_THREAD_LIBS_INIT} 43 | ) 44 | endif() 45 | endif() 46 | 47 | include_directories( 48 | glfw/deps 49 | glfw/include 50 | ../include 51 | ) 52 | 53 | set(GLAD_GL glfw/deps/glad/gl.h 54 | glfw/deps/glad_gl.c) 55 | 56 | option(GLFW_BUILD_EXAMPLES OFF) 57 | option(GLFW_BUILD_TESTS OFF) 58 | option(GLFW_BUILD_DOCS OFF) 59 | option(USE_MSVC_RUNTIME_LIBRARY_DLL OFF) 60 | 61 | if (MSVC OR CMAKE_C_SIMULATE_ID STREQUAL "MSVC") 62 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 63 | endif() 64 | 65 | add_subdirectory(glfw) 66 | 67 | add_executable(${PROJECT_NAME}_${TARGET_SUFFIX} 68 | Screen_Capture_Example_OpenGL.cpp 69 | ${GLAD_GL} 70 | ) 71 | 72 | target_link_libraries(${PROJECT_NAME}_${TARGET_SUFFIX} screen_capture_lite_${TARGET_SUFFIX} ${${PROJECT_NAME}_PLATFORM_LIBS} glfw) 73 | 74 | install (TARGETS ${PROJECT_NAME}_${TARGET_SUFFIX} screen_capture_lite_${TARGET_SUFFIX} 75 | RUNTIME DESTINATION Examples 76 | ) 77 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/.mailmap: -------------------------------------------------------------------------------- 1 | Camilla Löwy 2 | Camilla Löwy 3 | Camilla Löwy 4 | 5 | Emmanuel Gil Peyrot 6 | 7 | Marcus Geelnard 8 | Marcus Geelnard 9 | Marcus Geelnard 10 | 11 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/CMake/GenerateMappings.cmake: -------------------------------------------------------------------------------- 1 | # Usage: 2 | # cmake -P GenerateMappings.cmake 3 | 4 | set(source_url "https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt") 5 | set(source_path "${CMAKE_CURRENT_BINARY_DIR}/gamecontrollerdb.txt") 6 | set(template_path "${CMAKE_ARGV3}") 7 | set(target_path "${CMAKE_ARGV4}") 8 | 9 | if (NOT EXISTS "${template_path}") 10 | message(FATAL_ERROR "Failed to find template file ${template_path}") 11 | endif() 12 | 13 | file(DOWNLOAD "${source_url}" "${source_path}" 14 | STATUS download_status 15 | TLS_VERIFY on) 16 | 17 | list(GET download_status 0 status_code) 18 | list(GET download_status 1 status_message) 19 | 20 | if (status_code) 21 | message(FATAL_ERROR "Failed to download ${source_url}: ${status_message}") 22 | endif() 23 | 24 | file(STRINGS "${source_path}" lines) 25 | foreach(line ${lines}) 26 | if ("${line}" MATCHES "^[0-9a-fA-F].*$") 27 | set(GLFW_GAMEPAD_MAPPINGS "${GLFW_GAMEPAD_MAPPINGS}\"${line}\",\n") 28 | endif() 29 | endforeach() 30 | 31 | configure_file("${template_path}" "${target_path}" @ONLY NEWLINE_STYLE UNIX) 32 | file(REMOVE "${source_path}") 33 | 34 | -------------------------------------------------------------------------------- /Example_OpenGL/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 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/CMake/i686-w64-mingw32-clang.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross-compiling with 32-bit MinGW-w64 Clang 2 | SET(CMAKE_SYSTEM_NAME Windows) # Target system name 3 | SET(CMAKE_SYSTEM_VERSION 1) 4 | SET(CMAKE_C_COMPILER "i686-w64-mingw32-clang") 5 | SET(CMAKE_CXX_COMPILER "i686-w64-mingw32-clang++") 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 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/CMake/i686-w64-mingw32.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross-compiling with 32-bit MinGW-w64 GCC 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 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/CMake/modules/FindEpollShim.cmake: -------------------------------------------------------------------------------- 1 | # Find EpollShim 2 | # Once done, this will define 3 | # 4 | # EPOLLSHIM_FOUND - System has EpollShim 5 | # EPOLLSHIM_INCLUDE_DIRS - The EpollShim include directories 6 | # EPOLLSHIM_LIBRARIES - The libraries needed to use EpollShim 7 | 8 | find_path(EPOLLSHIM_INCLUDE_DIRS NAMES sys/epoll.h sys/timerfd.h HINTS /usr/local/include/libepoll-shim) 9 | find_library(EPOLLSHIM_LIBRARIES NAMES epoll-shim libepoll-shim HINTS /usr/local/lib) 10 | 11 | if (EPOLLSHIM_INCLUDE_DIRS AND EPOLLSHIM_LIBRARIES) 12 | set(EPOLLSHIM_FOUND TRUE) 13 | endif (EPOLLSHIM_INCLUDE_DIRS AND EPOLLSHIM_LIBRARIES) 14 | 15 | include(FindPackageHandleStandardArgs) 16 | find_package_handle_standard_args(EPOLLSHIM DEFAULT_MSG EPOLLSHIM_LIBRARIES EPOLLSHIM_INCLUDE_DIRS) 17 | mark_as_advanced(EPOLLSHIM_INCLUDE_DIRS EPOLLSHIM_LIBRARIES) 18 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/CMake/modules/FindOSMesa.cmake: -------------------------------------------------------------------------------- 1 | # Try to find OSMesa on a Unix system 2 | # 3 | # This will define: 4 | # 5 | # OSMESA_LIBRARIES - Link these to use OSMesa 6 | # OSMESA_INCLUDE_DIR - Include directory for OSMesa 7 | # 8 | # Copyright (c) 2014 Brandon Schaefer 9 | 10 | if (NOT WIN32) 11 | 12 | find_package (PkgConfig) 13 | pkg_check_modules (PKG_OSMESA QUIET osmesa) 14 | 15 | set (OSMESA_INCLUDE_DIR ${PKG_OSMESA_INCLUDE_DIRS}) 16 | set (OSMESA_LIBRARIES ${PKG_OSMESA_LIBRARIES}) 17 | 18 | endif () 19 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/CMake/modules/FindWaylandProtocols.cmake: -------------------------------------------------------------------------------- 1 | find_package(PkgConfig) 2 | 3 | pkg_check_modules(WaylandProtocols QUIET wayland-protocols>=${WaylandProtocols_FIND_VERSION}) 4 | 5 | execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-protocols 6 | OUTPUT_VARIABLE WaylandProtocols_PKGDATADIR 7 | RESULT_VARIABLE _pkgconfig_failed) 8 | if (_pkgconfig_failed) 9 | message(FATAL_ERROR "Missing wayland-protocols pkgdatadir") 10 | endif() 11 | 12 | string(REGEX REPLACE "[\r\n]" "" WaylandProtocols_PKGDATADIR "${WaylandProtocols_PKGDATADIR}") 13 | 14 | find_package_handle_standard_args(WaylandProtocols 15 | FOUND_VAR 16 | WaylandProtocols_FOUND 17 | REQUIRED_VARS 18 | WaylandProtocols_PKGDATADIR 19 | VERSION_VAR 20 | WaylandProtocols_VERSION 21 | HANDLE_COMPONENTS 22 | ) 23 | 24 | set(WAYLAND_PROTOCOLS_FOUND ${WaylandProtocols_FOUND}) 25 | set(WAYLAND_PROTOCOLS_PKGDATADIR ${WaylandProtocols_PKGDATADIR}) 26 | set(WAYLAND_PROTOCOLS_VERSION ${WaylandProtocols_VERSION}) 27 | -------------------------------------------------------------------------------- /Example_OpenGL/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 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/CMake/x86_64-w64-mingw32-clang.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross-compiling with 64-bit MinGW-w64 Clang 2 | SET(CMAKE_SYSTEM_NAME Windows) # Target system name 3 | SET(CMAKE_SYSTEM_VERSION 1) 4 | SET(CMAKE_C_COMPILER "x86_64-w64-mingw32-clang") 5 | SET(CMAKE_CXX_COMPILER "x86_64-w64-mingw32-clang++") 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 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/CMake/x86_64-w64-mingw32.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross-compiling with 64-bit MinGW-w64 GCC 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 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2006 Marcus Geelnard 2 | 3 | Copyright (c) 2006-2019 Camilla Löwy 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 | -------------------------------------------------------------------------------- /Example_OpenGL/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 | -------------------------------------------------------------------------------- /Example_OpenGL/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 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/deps/glad/vk_platform.h: -------------------------------------------------------------------------------- 1 | /* */ 2 | /* File: vk_platform.h */ 3 | /* */ 4 | /* 5 | ** Copyright (c) 2014-2017 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | 21 | #ifndef VK_PLATFORM_H_ 22 | #define VK_PLATFORM_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" 26 | { 27 | #endif /* __cplusplus */ 28 | 29 | /* 30 | *************************************************************************************************** 31 | * Platform-specific directives and type declarations 32 | *************************************************************************************************** 33 | */ 34 | 35 | /* Platform-specific calling convention macros. 36 | * 37 | * Platforms should define these so that Vulkan clients call Vulkan commands 38 | * with the same calling conventions that the Vulkan implementation expects. 39 | * 40 | * VKAPI_ATTR - Placed before the return type in function declarations. 41 | * Useful for C++11 and GCC/Clang-style function attribute syntax. 42 | * VKAPI_CALL - Placed after the return type in function declarations. 43 | * Useful for MSVC-style calling convention syntax. 44 | * VKAPI_PTR - Placed between the '(' and '*' in function pointer types. 45 | * 46 | * Function declaration: VKAPI_ATTR void VKAPI_CALL vkCommand(void); 47 | * Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void); 48 | */ 49 | #if defined(_WIN32) 50 | /* On Windows, Vulkan commands use the stdcall convention */ 51 | #define VKAPI_ATTR 52 | #define VKAPI_CALL __stdcall 53 | #define VKAPI_PTR VKAPI_CALL 54 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7 55 | #error "Vulkan isn't supported for the 'armeabi' NDK ABI" 56 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE) 57 | /* On Android 32-bit ARM targets, Vulkan functions use the "hardfloat" */ 58 | /* calling convention, i.e. float parameters are passed in registers. This */ 59 | /* is true even if the rest of the application passes floats on the stack, */ 60 | /* as it does by default when compiling for the armeabi-v7a NDK ABI. */ 61 | #define VKAPI_ATTR __attribute__((pcs("aapcs-vfp"))) 62 | #define VKAPI_CALL 63 | #define VKAPI_PTR VKAPI_ATTR 64 | #else 65 | /* On other platforms, use the default calling convention */ 66 | #define VKAPI_ATTR 67 | #define VKAPI_CALL 68 | #define VKAPI_PTR 69 | #endif 70 | 71 | #include 72 | 73 | #if !defined(VK_NO_STDINT_H) 74 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 75 | typedef signed __int8 int8_t; 76 | typedef unsigned __int8 uint8_t; 77 | typedef signed __int16 int16_t; 78 | typedef unsigned __int16 uint16_t; 79 | typedef signed __int32 int32_t; 80 | typedef unsigned __int32 uint32_t; 81 | typedef signed __int64 int64_t; 82 | typedef unsigned __int64 uint64_t; 83 | #else 84 | #include 85 | #endif 86 | #endif /* !defined(VK_NO_STDINT_H) */ 87 | 88 | #ifdef __cplusplus 89 | } /* extern "C" */ 90 | #endif /* __cplusplus */ 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/deps/mingw/_mingw_dxhelper.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the mingw-w64 runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #if defined(_MSC_VER) && !defined(_MSC_EXTENSIONS) 8 | #define NONAMELESSUNION 1 9 | #endif 10 | #if defined(NONAMELESSSTRUCT) && \ 11 | !defined(NONAMELESSUNION) 12 | #define NONAMELESSUNION 1 13 | #endif 14 | #if defined(NONAMELESSUNION) && \ 15 | !defined(NONAMELESSSTRUCT) 16 | #define NONAMELESSSTRUCT 1 17 | #endif 18 | #if !defined(__GNU_EXTENSION) 19 | #if defined(__GNUC__) || defined(__GNUG__) 20 | #define __GNU_EXTENSION __extension__ 21 | #else 22 | #define __GNU_EXTENSION 23 | #endif 24 | #endif /* __extension__ */ 25 | 26 | #ifndef __ANONYMOUS_DEFINED 27 | #define __ANONYMOUS_DEFINED 28 | #if defined(__GNUC__) || defined(__GNUG__) 29 | #define _ANONYMOUS_UNION __extension__ 30 | #define _ANONYMOUS_STRUCT __extension__ 31 | #else 32 | #define _ANONYMOUS_UNION 33 | #define _ANONYMOUS_STRUCT 34 | #endif 35 | #ifndef NONAMELESSUNION 36 | #define _UNION_NAME(x) 37 | #define _STRUCT_NAME(x) 38 | #else /* NONAMELESSUNION */ 39 | #define _UNION_NAME(x) x 40 | #define _STRUCT_NAME(x) x 41 | #endif 42 | #endif /* __ANONYMOUS_DEFINED */ 43 | 44 | #ifndef DUMMYUNIONNAME 45 | # ifdef NONAMELESSUNION 46 | # define DUMMYUNIONNAME u 47 | # define DUMMYUNIONNAME1 u1 /* Wine uses this variant */ 48 | # define DUMMYUNIONNAME2 u2 49 | # define DUMMYUNIONNAME3 u3 50 | # define DUMMYUNIONNAME4 u4 51 | # define DUMMYUNIONNAME5 u5 52 | # define DUMMYUNIONNAME6 u6 53 | # define DUMMYUNIONNAME7 u7 54 | # define DUMMYUNIONNAME8 u8 55 | # define DUMMYUNIONNAME9 u9 56 | # else /* NONAMELESSUNION */ 57 | # define DUMMYUNIONNAME 58 | # define DUMMYUNIONNAME1 /* Wine uses this variant */ 59 | # define DUMMYUNIONNAME2 60 | # define DUMMYUNIONNAME3 61 | # define DUMMYUNIONNAME4 62 | # define DUMMYUNIONNAME5 63 | # define DUMMYUNIONNAME6 64 | # define DUMMYUNIONNAME7 65 | # define DUMMYUNIONNAME8 66 | # define DUMMYUNIONNAME9 67 | # endif 68 | #endif /* DUMMYUNIONNAME */ 69 | 70 | #if !defined(DUMMYUNIONNAME1) /* MinGW does not define this one */ 71 | # ifdef NONAMELESSUNION 72 | # define DUMMYUNIONNAME1 u1 /* Wine uses this variant */ 73 | # else 74 | # define DUMMYUNIONNAME1 /* Wine uses this variant */ 75 | # endif 76 | #endif /* DUMMYUNIONNAME1 */ 77 | 78 | #ifndef DUMMYSTRUCTNAME 79 | # ifdef NONAMELESSUNION 80 | # define DUMMYSTRUCTNAME s 81 | # define DUMMYSTRUCTNAME1 s1 /* Wine uses this variant */ 82 | # define DUMMYSTRUCTNAME2 s2 83 | # define DUMMYSTRUCTNAME3 s3 84 | # define DUMMYSTRUCTNAME4 s4 85 | # define DUMMYSTRUCTNAME5 s5 86 | # else 87 | # define DUMMYSTRUCTNAME 88 | # define DUMMYSTRUCTNAME1 /* Wine uses this variant */ 89 | # define DUMMYSTRUCTNAME2 90 | # define DUMMYSTRUCTNAME3 91 | # define DUMMYSTRUCTNAME4 92 | # define DUMMYSTRUCTNAME5 93 | # endif 94 | #endif /* DUMMYSTRUCTNAME */ 95 | 96 | /* These are for compatibility with the Wine source tree */ 97 | 98 | #ifndef WINELIB_NAME_AW 99 | # ifdef __MINGW_NAME_AW 100 | # define WINELIB_NAME_AW __MINGW_NAME_AW 101 | # else 102 | # ifdef UNICODE 103 | # define WINELIB_NAME_AW(func) func##W 104 | # else 105 | # define WINELIB_NAME_AW(func) func##A 106 | # endif 107 | # endif 108 | #endif /* WINELIB_NAME_AW */ 109 | 110 | #ifndef DECL_WINELIB_TYPE_AW 111 | # ifdef __MINGW_TYPEDEF_AW 112 | # define DECL_WINELIB_TYPE_AW __MINGW_TYPEDEF_AW 113 | # else 114 | # define DECL_WINELIB_TYPE_AW(type) typedef WINELIB_NAME_AW(type) type; 115 | # endif 116 | #endif /* DECL_WINELIB_TYPE_AW */ 117 | 118 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/docs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # NOTE: The order of this list determines the order of items in the Guides 3 | # (i.e. Pages) list in the generated documentation 4 | set(GLFW_DOXYGEN_SOURCES 5 | "include/GLFW/glfw3.h" 6 | "include/GLFW/glfw3native.h" 7 | "docs/main.dox" 8 | "docs/news.dox" 9 | "docs/quick.dox" 10 | "docs/moving.dox" 11 | "docs/compile.dox" 12 | "docs/build.dox" 13 | "docs/intro.dox" 14 | "docs/context.dox" 15 | "docs/monitor.dox" 16 | "docs/window.dox" 17 | "docs/input.dox" 18 | "docs/vulkan.dox" 19 | "docs/compat.dox" 20 | "docs/internal.dox") 21 | 22 | # Format the source list into a Doxyfile INPUT value that Doxygen can parse 23 | foreach(path IN LISTS GLFW_DOXYGEN_SOURCES) 24 | set(GLFW_DOXYGEN_INPUT "${GLFW_DOXYGEN_INPUT} \\\n\"${GLFW_SOURCE_DIR}/${path}\"") 25 | endforeach() 26 | 27 | configure_file(Doxyfile.in Doxyfile @ONLY) 28 | 29 | add_custom_target(docs ALL "${DOXYGEN_EXECUTABLE}" 30 | WORKING_DIRECTORY "${GLFW_BINARY_DIR}/docs" 31 | COMMENT "Generating HTML documentation" VERBATIM) 32 | 33 | set_target_properties(docs PROPERTIES FOLDER "GLFW3") 34 | 35 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/docs/CODEOWNERS: -------------------------------------------------------------------------------- 1 | 2 | * @elmindreda 3 | 4 | src/wl_* @linkmauve 5 | 6 | docs/*.css @glfw/webdev 7 | docs/*.scss @glfw/webdev 8 | docs/*.html @glfw/webdev 9 | docs/*.xml @glfw/webdev 10 | 11 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/docs/DoxygenLayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/docs/SUPPORT.md: -------------------------------------------------------------------------------- 1 | # Support resources 2 | 3 | See the [latest documentation](http://www.glfw.org/docs/latest/) for tutorials, 4 | guides and the API reference. 5 | 6 | If you have questions about using GLFW, we have a 7 | [forum](https://discourse.glfw.org/), and the `#glfw` IRC channel on 8 | [Freenode](http://freenode.net/). 9 | 10 | Bugs are reported to our [issue tracker](https://github.com/glfw/glfw/issues). 11 | Please check the [contribution 12 | guide](https://github.com/glfw/glfw/blob/master/docs/CONTRIBUTING.md) for 13 | information on what to include when reporting a bug. 14 | 15 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/docs/extra.css.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sourceRoot":"","sources":["extra.scss"],"names":[],"mappings":"AA8EA,4GACI,gBACA,iBAGJ,yBACC,yDAGD,6HACC,sDAGD,yIACC,sDAGD,mBACI,WA9EuB,KA+EvB,iBAGJ,uBACC,MAzFoB,QA0FjB,iBAGJ,6UACC,gBAGD,mJACC,YAGD,yHACC,iBAGD,sBACC,gBAGD,4LACC,UAGD,yCACC,aAGD,kMACC,WAnHgC,QAsHjC,KACC,MA1HoB,QA6HrB,sDACC,MA/Ge,QAgHf,mBAGD,GACE,iBACA,eAGF,GACE,iBACA,gBACA,eAGF,GACE,iBACA,gBACA,eAGF,YACC,eACA,gBACA,gBACA,eACA,cAEA,aACA,mBACA,eACA,2BACA,mBACA,sBAGD,UACC,iBACA,mBACA,MA/J0B,KAgK1B,gBACA,qEAGD,YACC,qBACA,kBACA,YAGD,yBACC,WAGD,oCACC,iBACA,gBACA,cACA,MAlL0B,KAqL3B,YACC,eAGD,8CACC,qBAGD,mBACC,MA9L0B,KAiM3B,eACC,kBACA,YACA,eAGD,KACC,WAxM0B,KA2M3B,UACC,gBACA,cACA,eAGD,WACC,gBACA,cACA,eAGD,UACI,aAGJ,mBACI,iBACA,iBAGJ,WACC,gBACA,aACA,mBACA,eACA,2BACA,mBACA,sBAGD,mEACC,MA9OgC,QAiPjC,gCACC,MArPoB,QAwPrB,sCACC,MAjOoB,KAoOrB,yBACC,kBAGD,UACC,iBAGD,wBACC,gBACA,cACA,eACA,qBAGD,uDACC,gEACA,+BACA,+BACA,gBACA,MArPgB,KAwPjB,mBACC,MA5PoB,KA6PpB,aACA,kBACA,yBAGD,QACC,WACA,WAGD,WACC,iBAGD,WACC,mBAGD,WACC,cACA,eACA,qBAGD,oCACC,gEACA,kCACA,2BACA,MAlSe,QAmSf,yBACA,kBAGD,WACC,MA3QuB,QA8QxB,cACC,sBACA,2BACA,4BACA,mBAGD,cACC,sBACA,+BACA,8BACA,gBAGD,mCACC,wBACA,iBACA,sBACA,kBAGD,gIACC,MAxToB,KAyTpB,qBAGD,cACC,wBACA,iBACA,sBACA,kBAGD,iBACC,WACA,4EAGD,oCApSC,gEACA,kCACA,cACA,yBAqSD,wBAxSC,gEACA,kCACA,cACA,yBAySD,qBA5SC,gEACA,kCACA,cACA,yBA6SD,gBAhTC,gEACA,kCACA,cACA,yBAiTD,iGACC,kBACA,YACA,2BACA,aAGD,kRACC,cAGD,SACC,oBAGD,0BACC,mBACA,kBACA,YACA,YACA,cACA,2BACA,aAGD,+CACC,MA1YoB,QA6YrB,+BACC,cAGD,sBACC,cAGD,+CACC,cACA,iBAGD,mBACC,cAGD,KACC,aACA","file":"extra.css"} -------------------------------------------------------------------------------- /Example_OpenGL/glfw/docs/footer.html: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/docs/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $projectname: $title 9 | $title 10 | 11 | 12 | 13 | $treeview 14 | $search 15 | $mathjax 16 | 17 | $extrastylesheet 18 | 19 | 20 |
21 | 22 | 23 |
24 |
25 | GLFW 26 | 31 |
32 |
33 | 34 | 35 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/docs/internal.dox: -------------------------------------------------------------------------------- 1 | /*! 2 | 3 | @page internals_guide Internal structure 4 | 5 | @tableofcontents 6 | 7 | There are several interfaces inside GLFW. Each interface has its own area of 8 | responsibility and its own naming conventions. 9 | 10 | 11 | @section internals_public Public interface 12 | 13 | The most well-known is the public interface, described in the glfw3.h header 14 | file. This is implemented in source files shared by all platforms and these 15 | files contain no platform-specific code. This code usually ends up calling the 16 | platform and internal interfaces to do the actual work. 17 | 18 | The public interface uses the OpenGL naming conventions except with GLFW and 19 | glfw instead of GL and gl. For struct members, where OpenGL sets no precedent, 20 | it use headless camel case. 21 | 22 | Examples: `glfwCreateWindow`, `GLFWwindow`, `GLFW_RED_BITS` 23 | 24 | 25 | @section internals_native Native interface 26 | 27 | The [native interface](@ref native) is a small set of publicly available 28 | but platform-specific functions, described in the glfw3native.h header file and 29 | used to gain access to the underlying window, context and (on some platforms) 30 | display handles used by the platform interface. 31 | 32 | The function names of the native interface are similar to those of the public 33 | interface, but embeds the name of the interface that the returned handle is 34 | from. 35 | 36 | Examples: `glfwGetX11Window`, `glfwGetWGLContext` 37 | 38 | 39 | @section internals_internal Internal interface 40 | 41 | The internal interface consists of utility functions used by all other 42 | interfaces. It is shared code implemented in the same shared source files as 43 | the public and event interfaces. The internal interface is described in the 44 | internal.h header file. 45 | 46 | The internal interface is in charge of GLFW's global data, which it stores in 47 | a `_GLFWlibrary` struct named `_glfw`. 48 | 49 | The internal interface uses the same style as the public interface, except all 50 | global names have a leading underscore. 51 | 52 | Examples: `_glfwIsValidContextConfig`, `_GLFWwindow`, `_glfw.monitorCount` 53 | 54 | 55 | @section internals_platform Platform interface 56 | 57 | The platform interface implements all platform-specific operations as a service 58 | to the public interface. This includes event processing. The platform 59 | interface is never directly called by application code and never directly calls 60 | application-provided callbacks. It is also prohibited from modifying the 61 | platform-independent part of the internal structs. Instead, it calls the event 62 | interface when events interesting to GLFW are received. 63 | 64 | The platform interface mirrors those parts of the public interface that needs to 65 | perform platform-specific operations on some or all platforms. The are also 66 | named the same except that the glfw function prefix is replaced by 67 | _glfwPlatform. 68 | 69 | Examples: `_glfwPlatformCreateWindow` 70 | 71 | The platform interface also defines structs that contain platform-specific 72 | global and per-object state. Their names mirror those of the internal 73 | interface, except that an interface-specific suffix is added. 74 | 75 | Examples: `_GLFWwindowX11`, `_GLFWcontextWGL` 76 | 77 | These structs are incorporated as members into the internal interface structs 78 | using special macros that name them after the specific interface used. This 79 | prevents shared code from accidentally using these members. 80 | 81 | Examples: `window->win32.handle`, `_glfw.x11.display` 82 | 83 | 84 | @section internals_event Event interface 85 | 86 | The event interface is implemented in the same shared source files as the public 87 | interface and is responsible for delivering the events it receives to the 88 | application, either via callbacks, via window state changes or both. 89 | 90 | The function names of the event interface use a `_glfwInput` prefix and the 91 | ObjectEvent pattern. 92 | 93 | Examples: `_glfwInputWindowFocus`, `_glfwInputCursorPos` 94 | 95 | 96 | @section internals_static Static functions 97 | 98 | Static functions may be used by any interface and have no prefixes or suffixes. 99 | These use headless camel case. 100 | 101 | Examples: `isValidElementForJoystick` 102 | 103 | 104 | @section internals_config Configuration macros 105 | 106 | GLFW uses a number of configuration macros to select at compile time which 107 | interfaces and code paths to use. They are defined in the glfw_config.h header file, 108 | which is generated from the `glfw_config.h.in` file by CMake. 109 | 110 | Configuration macros the same style as tokens in the public interface, except 111 | with a leading underscore. 112 | 113 | Examples: `_GLFW_WIN32`, `_GLFW_BUILD_DLL` 114 | 115 | */ 116 | -------------------------------------------------------------------------------- /Example_OpenGL/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 OpenGL, OpenGL ES and 8 | Vulkan application development. It provides a simple, platform-independent API 9 | for creating windows, contexts and surfaces, reading input, handling events, etc. 10 | 11 | @ref news_33 list new features, caveats and deprecations. 12 | 13 | @ref quick_guide is a guide for users new to GLFW. It takes you through how to 14 | write a small but complete program. 15 | 16 | There are guides for each section of the API: 17 | 18 | - @ref intro_guide – initialization, error handling and high-level design 19 | - @ref window_guide – creating and working with windows and framebuffers 20 | - @ref context_guide – working with OpenGL and OpenGL ES contexts 21 | - @ref vulkan_guide - working with Vulkan objects and extensions 22 | - @ref monitor_guide – enumerating and working with monitors and video modes 23 | - @ref input_guide – receiving events, polling and processing input 24 | 25 | Once you have written a program, see @ref compile_guide and @ref build_guide. 26 | 27 | The [reference documentation](modules.html) provides more detailed information 28 | about specific functions. 29 | 30 | @ref moving_guide explains what has changed and how to update existing code to 31 | use the new API. 32 | 33 | There is a section on @ref guarantees_limitations for pointer lifetimes, 34 | reentrancy, thread safety, event order and backward and forward compatibility. 35 | 36 | The [FAQ](https://www.glfw.org/faq.html) answers many common questions about the 37 | design, implementation and use of GLFW. 38 | 39 | Finally, @ref compat_guide explains what APIs, standards and protocols GLFW uses 40 | and what happens when they are not present on a given machine. 41 | 42 | This documentation was generated with Doxygen. The sources for it are available 43 | in both the [source distribution](https://www.glfw.org/download.html) and 44 | [GitHub repository](https://github.com/glfw/glfw). 45 | 46 | */ 47 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | link_libraries(glfw) 3 | 4 | include_directories("${GLFW_SOURCE_DIR}/deps") 5 | 6 | if (MATH_LIBRARY) 7 | link_libraries("${MATH_LIBRARY}") 8 | endif() 9 | 10 | if (MSVC) 11 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 12 | endif() 13 | 14 | if (WIN32) 15 | set(ICON glfw.rc) 16 | elseif (APPLE) 17 | set(ICON glfw.icns) 18 | endif() 19 | 20 | if (${CMAKE_VERSION} VERSION_EQUAL "3.1.0" OR 21 | ${CMAKE_VERSION} VERSION_GREATER "3.1.0") 22 | set(CMAKE_C_STANDARD 99) 23 | else() 24 | # Remove this fallback when removing support for CMake version less than 3.1 25 | add_compile_options("$<$:-std=c99>" 26 | "$<$:-std=c99>" 27 | "$<$:-std=c99>") 28 | 29 | endif() 30 | 31 | set(GLAD_GL "${GLFW_SOURCE_DIR}/deps/glad/gl.h" 32 | "${GLFW_SOURCE_DIR}/deps/glad_gl.c") 33 | set(GETOPT "${GLFW_SOURCE_DIR}/deps/getopt.h" 34 | "${GLFW_SOURCE_DIR}/deps/getopt.c") 35 | set(TINYCTHREAD "${GLFW_SOURCE_DIR}/deps/tinycthread.h" 36 | "${GLFW_SOURCE_DIR}/deps/tinycthread.c") 37 | 38 | add_executable(boing WIN32 MACOSX_BUNDLE boing.c ${ICON} ${GLAD_GL}) 39 | add_executable(gears WIN32 MACOSX_BUNDLE gears.c ${ICON} ${GLAD_GL}) 40 | add_executable(heightmap WIN32 MACOSX_BUNDLE heightmap.c ${ICON} ${GLAD_GL}) 41 | add_executable(offscreen offscreen.c ${ICON} ${GLAD_GL}) 42 | add_executable(particles WIN32 MACOSX_BUNDLE particles.c ${ICON} ${TINYCTHREAD} ${GETOPT} ${GLAD_GL}) 43 | add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c ${ICON} ${GLAD_GL}) 44 | add_executable(simple WIN32 MACOSX_BUNDLE simple.c ${ICON} ${GLAD_GL}) 45 | add_executable(splitview WIN32 MACOSX_BUNDLE splitview.c ${ICON} ${GLAD_GL}) 46 | add_executable(wave WIN32 MACOSX_BUNDLE wave.c ${ICON} ${GLAD_GL}) 47 | 48 | target_link_libraries(particles "${CMAKE_THREAD_LIBS_INIT}") 49 | if (RT_LIBRARY) 50 | target_link_libraries(particles "${RT_LIBRARY}") 51 | endif() 52 | 53 | set(GUI_ONLY_BINARIES boing gears heightmap particles sharing simple splitview 54 | wave) 55 | set(CONSOLE_BINARIES offscreen) 56 | 57 | set_target_properties(${GUI_ONLY_BINARIES} ${CONSOLE_BINARIES} PROPERTIES 58 | FOLDER "GLFW3/Examples") 59 | 60 | if (GLFW_USE_OSMESA) 61 | target_compile_definitions(offscreen PRIVATE USE_NATIVE_OSMESA) 62 | endif() 63 | 64 | if (MSVC) 65 | # Tell MSVC to use main instead of WinMain for Windows subsystem executables 66 | set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES 67 | LINK_FLAGS "/ENTRY:mainCRTStartup") 68 | endif() 69 | 70 | if (APPLE) 71 | set_target_properties(boing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Boing") 72 | set_target_properties(gears PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gears") 73 | set_target_properties(heightmap PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Heightmap") 74 | set_target_properties(particles PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Particles") 75 | set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing") 76 | set_target_properties(simple PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Simple") 77 | set_target_properties(splitview PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "SplitView") 78 | set_target_properties(wave PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Wave") 79 | 80 | set_source_files_properties(glfw.icns PROPERTIES 81 | MACOSX_PACKAGE_LOCATION "Resources") 82 | set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES 83 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} 84 | MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION} 85 | MACOSX_BUNDLE_ICON_FILE glfw.icns 86 | MACOSX_BUNDLE_INFO_PLIST "${GLFW_SOURCE_DIR}/CMake/MacOSXBundleInfo.plist.in") 87 | endif() 88 | 89 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/examples/glfw.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smasherprog/screen_capture_lite/b77bc46c53fd01d4678cacd4766a22de2b7ab3d4/Example_OpenGL/glfw/examples/glfw.icns -------------------------------------------------------------------------------- /Example_OpenGL/glfw/examples/glfw.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smasherprog/screen_capture_lite/b77bc46c53fd01d4678cacd4766a22de2b7ab3d4/Example_OpenGL/glfw/examples/glfw.ico -------------------------------------------------------------------------------- /Example_OpenGL/glfw/examples/glfw.rc: -------------------------------------------------------------------------------- 1 | 2 | GLFW_ICON ICON "glfw.ico" 3 | 4 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/cocoa_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Cocoa - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 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 28 | #include 29 | #include 30 | #include 31 | 32 | #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickNS ns 33 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyJoystick; } 34 | 35 | #define _GLFW_PLATFORM_MAPPING_NAME "Mac OS X" 36 | 37 | // Cocoa-specific per-joystick data 38 | // 39 | typedef struct _GLFWjoystickNS 40 | { 41 | IOHIDDeviceRef device; 42 | CFMutableArrayRef axes; 43 | CFMutableArrayRef buttons; 44 | CFMutableArrayRef hats; 45 | } _GLFWjoystickNS; 46 | 47 | 48 | void _glfwInitJoysticksNS(void); 49 | void _glfwTerminateJoysticksNS(void); 50 | 51 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/cocoa_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 macOS - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2016 Camilla Löwy 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 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | #include 32 | 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | ////// GLFW internal API ////// 36 | ////////////////////////////////////////////////////////////////////////// 37 | 38 | // Initialise timer 39 | // 40 | void _glfwInitTimerNS(void) 41 | { 42 | mach_timebase_info_data_t info; 43 | mach_timebase_info(&info); 44 | 45 | _glfw.timer.ns.frequency = (info.denom * 1e9) / info.numer; 46 | } 47 | 48 | 49 | ////////////////////////////////////////////////////////////////////////// 50 | ////// GLFW platform API ////// 51 | ////////////////////////////////////////////////////////////////////////// 52 | 53 | uint64_t _glfwPlatformGetTimerValue(void) 54 | { 55 | return mach_absolute_time(); 56 | } 57 | 58 | uint64_t _glfwPlatformGetTimerFrequency(void) 59 | { 60 | return _glfw.timer.ns.frequency; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/glfw3.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 4 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 5 | 6 | Name: GLFW 7 | Description: A multi-platform library for OpenGL, window and input 8 | Version: @GLFW_VERSION@ 9 | URL: https://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 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/glfw3Config.cmake.in: -------------------------------------------------------------------------------- 1 | include("${CMAKE_CURRENT_LIST_DIR}/glfw3Targets.cmake") 2 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/glfw_config.h.in: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2010-2016 Camilla Löwy 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 OSMesa 46 | #cmakedefine _GLFW_OSMESA 47 | 48 | // Define this to 1 if building as a shared library / dynamic library / DLL 49 | #cmakedefine _GLFW_BUILD_DLL 50 | // Define this to 1 to use Vulkan loader linked statically into application 51 | #cmakedefine _GLFW_VULKAN_STATIC 52 | 53 | // Define this to 1 to force use of high-performance GPU on hybrid systems 54 | #cmakedefine _GLFW_USE_HYBRID_HPG 55 | 56 | // Define this to 1 if xkbcommon supports the compose key 57 | #cmakedefine HAVE_XKBCOMMON_COMPOSE_H 58 | // Define this to 1 if the libc supports memfd_create() 59 | #cmakedefine HAVE_MEMFD_CREATE 60 | 61 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/linux_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 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 | #include 28 | #include 29 | #include 30 | 31 | #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickLinux linjs 32 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE _GLFWlibraryLinux linjs 33 | 34 | #define _GLFW_PLATFORM_MAPPING_NAME "Linux" 35 | 36 | // Linux-specific joystick data 37 | // 38 | typedef struct _GLFWjoystickLinux 39 | { 40 | int fd; 41 | char path[PATH_MAX]; 42 | int keyMap[KEY_CNT - BTN_MISC]; 43 | int absMap[ABS_CNT]; 44 | struct input_absinfo absInfo[ABS_CNT]; 45 | int hats[4][2]; 46 | } _GLFWjoystickLinux; 47 | 48 | // Linux-specific joystick API data 49 | // 50 | typedef struct _GLFWlibraryLinux 51 | { 52 | int inotify; 53 | int watch; 54 | regex_t regex; 55 | GLFWbool dropped; 56 | } _GLFWlibraryLinux; 57 | 58 | 59 | GLFWbool _glfwInitJoysticksLinux(void); 60 | void _glfwTerminateJoysticksLinux(void); 61 | void _glfwDetectJoystickConnectionLinux(void); 62 | 63 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/mappings.h.in: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2018 Camilla Löwy 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 mappings.h.in, this file is used by CMake to produce the mappings.h 27 | // header file. If you are adding a GLFW specific gamepad mapping, this is 28 | // where to put it. 29 | //======================================================================== 30 | // As mappings.h, this provides all pre-defined gamepad mappings, including 31 | // all available in SDL_GameControllerDB. Do not edit this file. Any gamepad 32 | // mappings not specific to GLFW should be submitted to SDL_GameControllerDB. 33 | // This file can be re-generated from mappings.h.in and the upstream 34 | // gamecontrollerdb.txt with the GenerateMappings.cmake script. 35 | //======================================================================== 36 | 37 | // All gamepad mappings not labeled GLFW are copied from the 38 | // SDL_GameControllerDB project under the following license: 39 | // 40 | // Simple DirectMedia Layer 41 | // Copyright (C) 1997-2013 Sam Lantinga 42 | // 43 | // This software is provided 'as-is', without any express or implied warranty. 44 | // In no event will the authors be held liable for any damages arising from the 45 | // use of this software. 46 | // 47 | // Permission is granted to anyone to use this software for any purpose, 48 | // including commercial applications, and to alter it and redistribute it 49 | // freely, subject to the following restrictions: 50 | // 51 | // 1. The origin of this software must not be misrepresented; you must not 52 | // claim that you wrote the original software. If you use this software 53 | // in a product, an acknowledgment in the product documentation would 54 | // be appreciated but is not required. 55 | // 56 | // 2. Altered source versions must be plainly marked as such, and must not be 57 | // misrepresented as being the original software. 58 | // 59 | // 3. This notice may not be removed or altered from any source distribution. 60 | 61 | const char* _glfwDefaultMappings[] = 62 | { 63 | @GLFW_GAMEPAD_MAPPINGS@ 64 | "78696e70757401000000000000000000,XInput Gamepad (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 65 | "78696e70757402000000000000000000,XInput Wheel (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 66 | "78696e70757403000000000000000000,XInput Arcade Stick (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 67 | "78696e70757404000000000000000000,XInput Flight Stick (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 68 | "78696e70757405000000000000000000,XInput Dance Pad (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 69 | "78696e70757406000000000000000000,XInput Guitar (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 70 | "78696e70757408000000000000000000,XInput Drum Kit (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 71 | NULL 72 | }; 73 | 74 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/nsgl_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 macOS - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2019 Camilla Löwy 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 | // NOTE: Many Cocoa enum values have been renamed and we need to build across 28 | // SDK versions where one is unavailable or the other deprecated 29 | // We use the newer names in code and these macros to handle compatibility 30 | #if MAC_OS_X_VERSION_MAX_ALLOWED < 101400 31 | #define NSOpenGLContextParameterSwapInterval NSOpenGLCPSwapInterval 32 | #define NSOpenGLContextParameterSurfaceOpacity NSOpenGLCPSurfaceOpacity 33 | #endif 34 | 35 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL nsgl 36 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryNSGL nsgl 37 | 38 | #include 39 | 40 | 41 | // NSGL-specific per-context data 42 | // 43 | typedef struct _GLFWcontextNSGL 44 | { 45 | id pixelFormat; 46 | id object; 47 | 48 | } _GLFWcontextNSGL; 49 | 50 | // NSGL-specific global data 51 | // 52 | typedef struct _GLFWlibraryNSGL 53 | { 54 | // dlopen handle for OpenGL.framework (for glfwGetProcAddress) 55 | CFBundleRef framework; 56 | 57 | } _GLFWlibraryNSGL; 58 | 59 | 60 | GLFWbool _glfwInitNSGL(void); 61 | void _glfwTerminateNSGL(void); 62 | GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, 63 | const _GLFWctxconfig* ctxconfig, 64 | const _GLFWfbconfig* fbconfig); 65 | void _glfwDestroyContextNSGL(_GLFWwindow* window); 66 | 67 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/null_init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 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 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW platform API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | int _glfwPlatformInit(void) 38 | { 39 | _glfwInitTimerPOSIX(); 40 | return GLFW_TRUE; 41 | } 42 | 43 | void _glfwPlatformTerminate(void) 44 | { 45 | _glfwTerminateOSMesa(); 46 | } 47 | 48 | const char* _glfwPlatformGetVersionString(void) 49 | { 50 | return _GLFW_VERSION_NUMBER " null OSMesa"; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/null_joystick.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016-2017 Camilla Löwy 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 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | ////// GLFW platform API ////// 34 | ////////////////////////////////////////////////////////////////////////// 35 | 36 | int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode) 37 | { 38 | return GLFW_FALSE; 39 | } 40 | 41 | void _glfwPlatformUpdateGamepadGUID(char* guid) 42 | { 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/null_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 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 | #define _GLFW_PLATFORM_JOYSTICK_STATE struct { int dummyJoystick; } 28 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyLibraryJoystick; } 29 | 30 | #define _GLFW_PLATFORM_MAPPING_NAME "" 31 | 32 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/null_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2019 Camilla Löwy 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 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW platform API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor) 38 | { 39 | } 40 | 41 | void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) 42 | { 43 | } 44 | 45 | void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor, 46 | float* xscale, float* yscale) 47 | { 48 | if (xscale) 49 | *xscale = 1.f; 50 | if (yscale) 51 | *yscale = 1.f; 52 | } 53 | 54 | void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor, 55 | int* xpos, int* ypos, 56 | int* width, int* height) 57 | { 58 | } 59 | 60 | GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) 61 | { 62 | return NULL; 63 | } 64 | 65 | void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) 66 | { 67 | } 68 | 69 | GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 70 | { 71 | return GLFW_FALSE; 72 | } 73 | 74 | void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) 75 | { 76 | } 77 | 78 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/null_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 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 29 | 30 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNull null 31 | 32 | #define _GLFW_PLATFORM_CONTEXT_STATE struct { int dummyContext; } 33 | #define _GLFW_PLATFORM_MONITOR_STATE struct { int dummyMonitor; } 34 | #define _GLFW_PLATFORM_CURSOR_STATE struct { int dummyCursor; } 35 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE struct { int dummyLibraryWindow; } 36 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE struct { int dummyLibraryContext; } 37 | #define _GLFW_EGL_CONTEXT_STATE struct { int dummyEGLContext; } 38 | #define _GLFW_EGL_LIBRARY_CONTEXT_STATE struct { int dummyEGLLibraryContext; } 39 | 40 | #include "osmesa_context.h" 41 | #include "posix_time.h" 42 | #include "posix_thread.h" 43 | #include "null_joystick.h" 44 | 45 | #if defined(_GLFW_WIN32) 46 | #define _glfw_dlopen(name) LoadLibraryA(name) 47 | #define _glfw_dlclose(handle) FreeLibrary((HMODULE) handle) 48 | #define _glfw_dlsym(handle, name) GetProcAddress((HMODULE) handle, name) 49 | #else 50 | #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) 51 | #define _glfw_dlclose(handle) dlclose(handle) 52 | #define _glfw_dlsym(handle, name) dlsym(handle, name) 53 | #endif 54 | 55 | // Null-specific per-window data 56 | // 57 | typedef struct _GLFWwindowNull 58 | { 59 | int width; 60 | int height; 61 | } _GLFWwindowNull; 62 | 63 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/osmesa_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 OSMesa - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 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 | #define OSMESA_RGBA 0x1908 29 | #define OSMESA_FORMAT 0x22 30 | #define OSMESA_DEPTH_BITS 0x30 31 | #define OSMESA_STENCIL_BITS 0x31 32 | #define OSMESA_ACCUM_BITS 0x32 33 | #define OSMESA_PROFILE 0x33 34 | #define OSMESA_CORE_PROFILE 0x34 35 | #define OSMESA_COMPAT_PROFILE 0x35 36 | #define OSMESA_CONTEXT_MAJOR_VERSION 0x36 37 | #define OSMESA_CONTEXT_MINOR_VERSION 0x37 38 | 39 | typedef void* OSMesaContext; 40 | typedef void (*OSMESAproc)(void); 41 | 42 | typedef OSMesaContext (GLAPIENTRY * PFN_OSMesaCreateContextExt)(GLenum,GLint,GLint,GLint,OSMesaContext); 43 | typedef OSMesaContext (GLAPIENTRY * PFN_OSMesaCreateContextAttribs)(const int*,OSMesaContext); 44 | typedef void (GLAPIENTRY * PFN_OSMesaDestroyContext)(OSMesaContext); 45 | typedef int (GLAPIENTRY * PFN_OSMesaMakeCurrent)(OSMesaContext,void*,int,int,int); 46 | typedef int (GLAPIENTRY * PFN_OSMesaGetColorBuffer)(OSMesaContext,int*,int*,int*,void**); 47 | typedef int (GLAPIENTRY * PFN_OSMesaGetDepthBuffer)(OSMesaContext,int*,int*,int*,void**); 48 | typedef GLFWglproc (GLAPIENTRY * PFN_OSMesaGetProcAddress)(const char*); 49 | #define OSMesaCreateContextExt _glfw.osmesa.CreateContextExt 50 | #define OSMesaCreateContextAttribs _glfw.osmesa.CreateContextAttribs 51 | #define OSMesaDestroyContext _glfw.osmesa.DestroyContext 52 | #define OSMesaMakeCurrent _glfw.osmesa.MakeCurrent 53 | #define OSMesaGetColorBuffer _glfw.osmesa.GetColorBuffer 54 | #define OSMesaGetDepthBuffer _glfw.osmesa.GetDepthBuffer 55 | #define OSMesaGetProcAddress _glfw.osmesa.GetProcAddress 56 | 57 | #define _GLFW_OSMESA_CONTEXT_STATE _GLFWcontextOSMesa osmesa 58 | #define _GLFW_OSMESA_LIBRARY_CONTEXT_STATE _GLFWlibraryOSMesa osmesa 59 | 60 | 61 | // OSMesa-specific per-context data 62 | // 63 | typedef struct _GLFWcontextOSMesa 64 | { 65 | OSMesaContext handle; 66 | int width; 67 | int height; 68 | void* buffer; 69 | 70 | } _GLFWcontextOSMesa; 71 | 72 | // OSMesa-specific global data 73 | // 74 | typedef struct _GLFWlibraryOSMesa 75 | { 76 | void* handle; 77 | 78 | PFN_OSMesaCreateContextExt CreateContextExt; 79 | PFN_OSMesaCreateContextAttribs CreateContextAttribs; 80 | PFN_OSMesaDestroyContext DestroyContext; 81 | PFN_OSMesaMakeCurrent MakeCurrent; 82 | PFN_OSMesaGetColorBuffer GetColorBuffer; 83 | PFN_OSMesaGetDepthBuffer GetDepthBuffer; 84 | PFN_OSMesaGetProcAddress GetProcAddress; 85 | 86 | } _GLFWlibraryOSMesa; 87 | 88 | 89 | GLFWbool _glfwInitOSMesa(void); 90 | void _glfwTerminateOSMesa(void); 91 | GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window, 92 | const _GLFWctxconfig* ctxconfig, 93 | const _GLFWfbconfig* fbconfig); 94 | 95 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/posix_thread.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 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 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ////// GLFW platform API ////// 38 | ////////////////////////////////////////////////////////////////////////// 39 | 40 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) 41 | { 42 | assert(tls->posix.allocated == GLFW_FALSE); 43 | 44 | if (pthread_key_create(&tls->posix.key, NULL) != 0) 45 | { 46 | _glfwInputError(GLFW_PLATFORM_ERROR, 47 | "POSIX: Failed to create context TLS"); 48 | return GLFW_FALSE; 49 | } 50 | 51 | tls->posix.allocated = GLFW_TRUE; 52 | return GLFW_TRUE; 53 | } 54 | 55 | void _glfwPlatformDestroyTls(_GLFWtls* tls) 56 | { 57 | if (tls->posix.allocated) 58 | pthread_key_delete(tls->posix.key); 59 | memset(tls, 0, sizeof(_GLFWtls)); 60 | } 61 | 62 | void* _glfwPlatformGetTls(_GLFWtls* tls) 63 | { 64 | assert(tls->posix.allocated == GLFW_TRUE); 65 | return pthread_getspecific(tls->posix.key); 66 | } 67 | 68 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) 69 | { 70 | assert(tls->posix.allocated == GLFW_TRUE); 71 | pthread_setspecific(tls->posix.key, value); 72 | } 73 | 74 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) 75 | { 76 | assert(mutex->posix.allocated == GLFW_FALSE); 77 | 78 | if (pthread_mutex_init(&mutex->posix.handle, NULL) != 0) 79 | { 80 | _glfwInputError(GLFW_PLATFORM_ERROR, "POSIX: Failed to create mutex"); 81 | return GLFW_FALSE; 82 | } 83 | 84 | return mutex->posix.allocated = GLFW_TRUE; 85 | } 86 | 87 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) 88 | { 89 | if (mutex->posix.allocated) 90 | pthread_mutex_destroy(&mutex->posix.handle); 91 | memset(mutex, 0, sizeof(_GLFWmutex)); 92 | } 93 | 94 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) 95 | { 96 | assert(mutex->posix.allocated == GLFW_TRUE); 97 | pthread_mutex_lock(&mutex->posix.handle); 98 | } 99 | 100 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) 101 | { 102 | assert(mutex->posix.allocated == GLFW_TRUE); 103 | pthread_mutex_unlock(&mutex->posix.handle); 104 | } 105 | 106 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/posix_thread.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 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 29 | 30 | #define _GLFW_PLATFORM_TLS_STATE _GLFWtlsPOSIX posix 31 | #define _GLFW_PLATFORM_MUTEX_STATE _GLFWmutexPOSIX posix 32 | 33 | 34 | // POSIX-specific thread local storage data 35 | // 36 | typedef struct _GLFWtlsPOSIX 37 | { 38 | GLFWbool allocated; 39 | pthread_key_t key; 40 | 41 | } _GLFWtlsPOSIX; 42 | 43 | // POSIX-specific mutex data 44 | // 45 | typedef struct _GLFWmutexPOSIX 46 | { 47 | GLFWbool allocated; 48 | pthread_mutex_t handle; 49 | 50 | } _GLFWmutexPOSIX; 51 | 52 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/posix_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 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 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ////// GLFW internal API ////// 38 | ////////////////////////////////////////////////////////////////////////// 39 | 40 | // Initialise timer 41 | // 42 | void _glfwInitTimerPOSIX(void) 43 | { 44 | #if defined(CLOCK_MONOTONIC) 45 | struct timespec ts; 46 | 47 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) 48 | { 49 | _glfw.timer.posix.monotonic = GLFW_TRUE; 50 | _glfw.timer.posix.frequency = 1000000000; 51 | } 52 | else 53 | #endif 54 | { 55 | _glfw.timer.posix.monotonic = GLFW_FALSE; 56 | _glfw.timer.posix.frequency = 1000000; 57 | } 58 | } 59 | 60 | 61 | ////////////////////////////////////////////////////////////////////////// 62 | ////// GLFW platform API ////// 63 | ////////////////////////////////////////////////////////////////////////// 64 | 65 | uint64_t _glfwPlatformGetTimerValue(void) 66 | { 67 | #if defined(CLOCK_MONOTONIC) 68 | if (_glfw.timer.posix.monotonic) 69 | { 70 | struct timespec ts; 71 | clock_gettime(CLOCK_MONOTONIC, &ts); 72 | return (uint64_t) ts.tv_sec * (uint64_t) 1000000000 + (uint64_t) ts.tv_nsec; 73 | } 74 | else 75 | #endif 76 | { 77 | struct timeval tv; 78 | gettimeofday(&tv, NULL); 79 | return (uint64_t) tv.tv_sec * (uint64_t) 1000000 + (uint64_t) tv.tv_usec; 80 | } 81 | } 82 | 83 | uint64_t _glfwPlatformGetTimerFrequency(void) 84 | { 85 | return _glfw.timer.posix.frequency; 86 | } 87 | 88 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/posix_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 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 | #define _GLFW_PLATFORM_LIBRARY_TIMER_STATE _GLFWtimerPOSIX posix 29 | 30 | #include 31 | 32 | 33 | // POSIX-specific global timer data 34 | // 35 | typedef struct _GLFWtimerPOSIX 36 | { 37 | GLFWbool monotonic; 38 | uint64_t frequency; 39 | 40 | } _GLFWtimerPOSIX; 41 | 42 | 43 | void _glfwInitTimerPOSIX(void); 44 | 45 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/win32_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 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 | #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickWin32 win32 28 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyLibraryJoystick; } 29 | 30 | #define _GLFW_PLATFORM_MAPPING_NAME "Windows" 31 | 32 | // Joystick element (axis, button or slider) 33 | // 34 | typedef struct _GLFWjoyobjectWin32 35 | { 36 | int offset; 37 | int type; 38 | } _GLFWjoyobjectWin32; 39 | 40 | // Win32-specific per-joystick data 41 | // 42 | typedef struct _GLFWjoystickWin32 43 | { 44 | _GLFWjoyobjectWin32* objects; 45 | int objectCount; 46 | IDirectInputDevice8W* device; 47 | DWORD index; 48 | GUID guid; 49 | } _GLFWjoystickWin32; 50 | 51 | 52 | void _glfwInitJoysticksWin32(void); 53 | void _glfwTerminateJoysticksWin32(void); 54 | void _glfwDetectJoystickConnectionWin32(void); 55 | void _glfwDetectJoystickDisconnectionWin32(void); 56 | 57 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/win32_thread.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 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 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | 34 | 35 | ////////////////////////////////////////////////////////////////////////// 36 | ////// GLFW platform API ////// 37 | ////////////////////////////////////////////////////////////////////////// 38 | 39 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) 40 | { 41 | assert(tls->win32.allocated == GLFW_FALSE); 42 | 43 | tls->win32.index = TlsAlloc(); 44 | if (tls->win32.index == TLS_OUT_OF_INDEXES) 45 | { 46 | _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, 47 | "Win32: Failed to allocate TLS index"); 48 | return GLFW_FALSE; 49 | } 50 | 51 | tls->win32.allocated = GLFW_TRUE; 52 | return GLFW_TRUE; 53 | } 54 | 55 | void _glfwPlatformDestroyTls(_GLFWtls* tls) 56 | { 57 | if (tls->win32.allocated) 58 | TlsFree(tls->win32.index); 59 | memset(tls, 0, sizeof(_GLFWtls)); 60 | } 61 | 62 | void* _glfwPlatformGetTls(_GLFWtls* tls) 63 | { 64 | assert(tls->win32.allocated == GLFW_TRUE); 65 | return TlsGetValue(tls->win32.index); 66 | } 67 | 68 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) 69 | { 70 | assert(tls->win32.allocated == GLFW_TRUE); 71 | TlsSetValue(tls->win32.index, value); 72 | } 73 | 74 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) 75 | { 76 | assert(mutex->win32.allocated == GLFW_FALSE); 77 | InitializeCriticalSection(&mutex->win32.section); 78 | return mutex->win32.allocated = GLFW_TRUE; 79 | } 80 | 81 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) 82 | { 83 | if (mutex->win32.allocated) 84 | DeleteCriticalSection(&mutex->win32.section); 85 | memset(mutex, 0, sizeof(_GLFWmutex)); 86 | } 87 | 88 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) 89 | { 90 | assert(mutex->win32.allocated == GLFW_TRUE); 91 | EnterCriticalSection(&mutex->win32.section); 92 | } 93 | 94 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) 95 | { 96 | assert(mutex->win32.allocated == GLFW_TRUE); 97 | LeaveCriticalSection(&mutex->win32.section); 98 | } 99 | 100 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/win32_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 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 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW internal API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | // Initialise timer 38 | // 39 | void _glfwInitTimerWin32(void) 40 | { 41 | uint64_t frequency; 42 | 43 | if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency)) 44 | { 45 | _glfw.timer.win32.hasPC = GLFW_TRUE; 46 | _glfw.timer.win32.frequency = frequency; 47 | } 48 | else 49 | { 50 | _glfw.timer.win32.hasPC = GLFW_FALSE; 51 | _glfw.timer.win32.frequency = 1000; 52 | } 53 | } 54 | 55 | 56 | ////////////////////////////////////////////////////////////////////////// 57 | ////// GLFW platform API ////// 58 | ////////////////////////////////////////////////////////////////////////// 59 | 60 | uint64_t _glfwPlatformGetTimerValue(void) 61 | { 62 | if (_glfw.timer.win32.hasPC) 63 | { 64 | uint64_t value; 65 | QueryPerformanceCounter((LARGE_INTEGER*) &value); 66 | return value; 67 | } 68 | else 69 | return (uint64_t) timeGetTime(); 70 | } 71 | 72 | uint64_t _glfwPlatformGetTimerFrequency(void) 73 | { 74 | return _glfw.timer.win32.frequency; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/src/xkb_unicode.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 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 | long _glfwKeySym2Unicode(unsigned int keysym); 28 | 29 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | link_libraries(glfw) 3 | 4 | include_directories("${GLFW_SOURCE_DIR}/deps") 5 | 6 | if (MATH_LIBRARY) 7 | link_libraries("${MATH_LIBRARY}") 8 | endif() 9 | 10 | if (MSVC) 11 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 12 | endif() 13 | 14 | set(GLAD_GL "${GLFW_SOURCE_DIR}/deps/glad/gl.h" 15 | "${GLFW_SOURCE_DIR}/deps/glad_gl.c") 16 | set(GLAD_VULKAN "${GLFW_SOURCE_DIR}/deps/glad/vulkan.h" 17 | "${GLFW_SOURCE_DIR}/deps/glad_vulkan.c") 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 | if (${CMAKE_VERSION} VERSION_EQUAL "3.1.0" OR 24 | ${CMAKE_VERSION} VERSION_GREATER "3.1.0") 25 | set(CMAKE_C_STANDARD 99) 26 | else() 27 | # Remove this fallback when removing support for CMake version less than 3.1 28 | add_compile_options("$<$:-std=c99>" 29 | "$<$:-std=c99>" 30 | "$<$:-std=c99>") 31 | 32 | endif() 33 | 34 | add_executable(clipboard clipboard.c ${GETOPT} ${GLAD_GL}) 35 | add_executable(events events.c ${GETOPT} ${GLAD_GL}) 36 | add_executable(msaa msaa.c ${GETOPT} ${GLAD_GL}) 37 | add_executable(glfwinfo glfwinfo.c ${GETOPT} ${GLAD_GL} ${GLAD_VULKAN}) 38 | add_executable(iconify iconify.c ${GETOPT} ${GLAD_GL}) 39 | add_executable(monitors monitors.c ${GETOPT} ${GLAD_GL}) 40 | add_executable(reopen reopen.c ${GLAD_GL}) 41 | add_executable(cursor cursor.c ${GLAD_GL}) 42 | 43 | add_executable(empty WIN32 MACOSX_BUNDLE empty.c ${TINYCTHREAD} ${GLAD_GL}) 44 | add_executable(gamma WIN32 MACOSX_BUNDLE gamma.c ${GLAD_GL}) 45 | add_executable(icon WIN32 MACOSX_BUNDLE icon.c ${GLAD_GL}) 46 | add_executable(inputlag WIN32 MACOSX_BUNDLE inputlag.c ${GETOPT} ${GLAD_GL}) 47 | add_executable(joysticks WIN32 MACOSX_BUNDLE joysticks.c ${GLAD_GL}) 48 | add_executable(opacity WIN32 MACOSX_BUNDLE opacity.c ${GLAD_GL}) 49 | add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c ${GLAD_GL}) 50 | add_executable(threads WIN32 MACOSX_BUNDLE threads.c ${TINYCTHREAD} ${GLAD_GL}) 51 | add_executable(timeout WIN32 MACOSX_BUNDLE timeout.c ${GLAD_GL}) 52 | add_executable(title WIN32 MACOSX_BUNDLE title.c ${GLAD_GL}) 53 | add_executable(triangle-vulkan WIN32 triangle-vulkan.c ${GLAD_VULKAN}) 54 | add_executable(windows WIN32 MACOSX_BUNDLE windows.c ${GETOPT} ${GLAD_GL}) 55 | 56 | target_link_libraries(empty "${CMAKE_THREAD_LIBS_INIT}") 57 | target_link_libraries(threads "${CMAKE_THREAD_LIBS_INIT}") 58 | if (RT_LIBRARY) 59 | target_link_libraries(empty "${RT_LIBRARY}") 60 | target_link_libraries(threads "${RT_LIBRARY}") 61 | endif() 62 | 63 | set(GUI_ONLY_BINARIES empty gamma icon inputlag joysticks opacity tearing 64 | threads timeout title triangle-vulkan windows) 65 | set(CONSOLE_BINARIES clipboard events msaa glfwinfo iconify monitors reopen 66 | cursor) 67 | 68 | set_target_properties(${GUI_ONLY_BINARIES} ${CONSOLE_BINARIES} PROPERTIES 69 | FOLDER "GLFW3/Tests") 70 | 71 | if (MSVC) 72 | # Tell MSVC to use main instead of WinMain for Windows subsystem executables 73 | set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES 74 | LINK_FLAGS "/ENTRY:mainCRTStartup") 75 | endif() 76 | 77 | if (APPLE) 78 | set_target_properties(empty PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Empty Event") 79 | set_target_properties(gamma PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gamma") 80 | set_target_properties(inputlag PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Input Lag") 81 | set_target_properties(joysticks PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Joysticks") 82 | set_target_properties(opacity PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Opacity") 83 | set_target_properties(tearing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Tearing") 84 | set_target_properties(threads PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Threads") 85 | set_target_properties(timeout PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Timeout") 86 | set_target_properties(title PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Title") 87 | set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows") 88 | 89 | set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES 90 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} 91 | MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION} 92 | MACOSX_BUNDLE_INFO_PLIST "${GLFW_SOURCE_DIR}/CMake/MacOSXBundleInfo.plist.in") 93 | endif() 94 | 95 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/tests/clipboard.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Clipboard test program 3 | // Copyright (c) Camilla Löwy 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 | #define GLFW_INCLUDE_NONE 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | #include "getopt.h" 38 | 39 | #if defined(__APPLE__) 40 | #define MODIFIER GLFW_MOD_SUPER 41 | #else 42 | #define MODIFIER GLFW_MOD_CONTROL 43 | #endif 44 | 45 | static void usage(void) 46 | { 47 | printf("Usage: clipboard [-h]\n"); 48 | } 49 | 50 | static void error_callback(int error, const char* description) 51 | { 52 | fprintf(stderr, "Error: %s\n", description); 53 | } 54 | 55 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 56 | { 57 | if (action != GLFW_PRESS) 58 | return; 59 | 60 | switch (key) 61 | { 62 | case GLFW_KEY_ESCAPE: 63 | glfwSetWindowShouldClose(window, GLFW_TRUE); 64 | break; 65 | 66 | case GLFW_KEY_V: 67 | if (mods == MODIFIER) 68 | { 69 | const char* string; 70 | 71 | string = glfwGetClipboardString(NULL); 72 | if (string) 73 | printf("Clipboard contains \"%s\"\n", string); 74 | else 75 | printf("Clipboard does not contain a string\n"); 76 | } 77 | break; 78 | 79 | case GLFW_KEY_C: 80 | if (mods == MODIFIER) 81 | { 82 | const char* string = "Hello GLFW World!"; 83 | glfwSetClipboardString(NULL, string); 84 | printf("Setting clipboard to \"%s\"\n", string); 85 | } 86 | break; 87 | } 88 | } 89 | 90 | int main(int argc, char** argv) 91 | { 92 | int ch; 93 | GLFWwindow* window; 94 | 95 | while ((ch = getopt(argc, argv, "h")) != -1) 96 | { 97 | switch (ch) 98 | { 99 | case 'h': 100 | usage(); 101 | exit(EXIT_SUCCESS); 102 | 103 | default: 104 | usage(); 105 | exit(EXIT_FAILURE); 106 | } 107 | } 108 | 109 | glfwSetErrorCallback(error_callback); 110 | 111 | if (!glfwInit()) 112 | { 113 | fprintf(stderr, "Failed to initialize GLFW\n"); 114 | exit(EXIT_FAILURE); 115 | } 116 | 117 | window = glfwCreateWindow(200, 200, "Clipboard Test", NULL, NULL); 118 | if (!window) 119 | { 120 | glfwTerminate(); 121 | 122 | fprintf(stderr, "Failed to open GLFW window\n"); 123 | exit(EXIT_FAILURE); 124 | } 125 | 126 | glfwMakeContextCurrent(window); 127 | gladLoadGL(glfwGetProcAddress); 128 | glfwSwapInterval(1); 129 | 130 | glfwSetKeyCallback(window, key_callback); 131 | 132 | glClearColor(0.5f, 0.5f, 0.5f, 0); 133 | 134 | while (!glfwWindowShouldClose(window)) 135 | { 136 | glClear(GL_COLOR_BUFFER_BIT); 137 | 138 | glfwSwapBuffers(window); 139 | glfwWaitEvents(); 140 | } 141 | 142 | glfwTerminate(); 143 | exit(EXIT_SUCCESS); 144 | } 145 | 146 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/tests/empty.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Empty event test 3 | // Copyright (c) Camilla Löwy 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 | #define GLFW_INCLUDE_NONE 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | static volatile int running = GLFW_TRUE; 41 | 42 | static void error_callback(int error, const char* description) 43 | { 44 | fprintf(stderr, "Error: %s\n", description); 45 | } 46 | 47 | static int thread_main(void* data) 48 | { 49 | struct timespec time; 50 | 51 | while (running) 52 | { 53 | clock_gettime(CLOCK_REALTIME, &time); 54 | time.tv_sec += 1; 55 | thrd_sleep(&time, NULL); 56 | 57 | glfwPostEmptyEvent(); 58 | } 59 | 60 | return 0; 61 | } 62 | 63 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 64 | { 65 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 66 | glfwSetWindowShouldClose(window, GLFW_TRUE); 67 | } 68 | 69 | static float nrand(void) 70 | { 71 | return (float) rand() / (float) RAND_MAX; 72 | } 73 | 74 | int main(void) 75 | { 76 | int result; 77 | thrd_t thread; 78 | GLFWwindow* window; 79 | 80 | srand((unsigned int) time(NULL)); 81 | 82 | glfwSetErrorCallback(error_callback); 83 | 84 | if (!glfwInit()) 85 | exit(EXIT_FAILURE); 86 | 87 | window = glfwCreateWindow(640, 480, "Empty Event Test", NULL, NULL); 88 | if (!window) 89 | { 90 | glfwTerminate(); 91 | exit(EXIT_FAILURE); 92 | } 93 | 94 | glfwMakeContextCurrent(window); 95 | gladLoadGL(glfwGetProcAddress); 96 | glfwSetKeyCallback(window, key_callback); 97 | 98 | if (thrd_create(&thread, thread_main, NULL) != thrd_success) 99 | { 100 | fprintf(stderr, "Failed to create secondary thread\n"); 101 | 102 | glfwTerminate(); 103 | exit(EXIT_FAILURE); 104 | } 105 | 106 | while (running) 107 | { 108 | int width, height; 109 | float r = nrand(), g = nrand(), b = nrand(); 110 | float l = (float) sqrt(r * r + g * g + b * b); 111 | 112 | glfwGetFramebufferSize(window, &width, &height); 113 | 114 | glViewport(0, 0, width, height); 115 | glClearColor(r / l, g / l, b / l, 1.f); 116 | glClear(GL_COLOR_BUFFER_BIT); 117 | glfwSwapBuffers(window); 118 | 119 | glfwWaitEvents(); 120 | 121 | if (glfwWindowShouldClose(window)) 122 | running = GLFW_FALSE; 123 | } 124 | 125 | glfwHideWindow(window); 126 | thrd_join(thread, &result); 127 | glfwDestroyWindow(window); 128 | 129 | glfwTerminate(); 130 | exit(EXIT_SUCCESS); 131 | } 132 | 133 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/tests/icon.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Window icon test program 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This program is used to test the icon feature. 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #define GLFW_INCLUDE_NONE 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | // a simple glfw logo 39 | const char* const logo[] = 40 | { 41 | "................", 42 | "................", 43 | "...0000..0......", 44 | "...0.....0......", 45 | "...0.00..0......", 46 | "...0..0..0......", 47 | "...0000..0000...", 48 | "................", 49 | "................", 50 | "...000..0...0...", 51 | "...0....0...0...", 52 | "...000..0.0.0...", 53 | "...0....0.0.0...", 54 | "...0....00000...", 55 | "................", 56 | "................" 57 | }; 58 | 59 | const unsigned char icon_colors[5][4] = 60 | { 61 | { 0, 0, 0, 255 }, // black 62 | { 255, 0, 0, 255 }, // red 63 | { 0, 255, 0, 255 }, // green 64 | { 0, 0, 255, 255 }, // blue 65 | { 255, 255, 255, 255 } // white 66 | }; 67 | 68 | static int cur_icon_color = 0; 69 | 70 | static void set_icon(GLFWwindow* window, int icon_color) 71 | { 72 | int x, y; 73 | unsigned char pixels[16 * 16 * 4]; 74 | unsigned char* target = pixels; 75 | GLFWimage img = { 16, 16, pixels }; 76 | 77 | for (y = 0; y < img.width; y++) 78 | { 79 | for (x = 0; x < img.height; x++) 80 | { 81 | if (logo[y][x] == '0') 82 | memcpy(target, icon_colors[icon_color], 4); 83 | else 84 | memset(target, 0, 4); 85 | 86 | target += 4; 87 | } 88 | } 89 | 90 | glfwSetWindowIcon(window, 1, &img); 91 | } 92 | 93 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 94 | { 95 | if (action != GLFW_PRESS) 96 | return; 97 | 98 | switch (key) 99 | { 100 | case GLFW_KEY_ESCAPE: 101 | glfwSetWindowShouldClose(window, GLFW_TRUE); 102 | break; 103 | case GLFW_KEY_SPACE: 104 | cur_icon_color = (cur_icon_color + 1) % 5; 105 | set_icon(window, cur_icon_color); 106 | break; 107 | case GLFW_KEY_X: 108 | glfwSetWindowIcon(window, 0, NULL); 109 | break; 110 | } 111 | } 112 | 113 | int main(int argc, char** argv) 114 | { 115 | GLFWwindow* window; 116 | 117 | if (!glfwInit()) 118 | { 119 | fprintf(stderr, "Failed to initialize GLFW\n"); 120 | exit(EXIT_FAILURE); 121 | } 122 | 123 | window = glfwCreateWindow(200, 200, "Window Icon", NULL, NULL); 124 | if (!window) 125 | { 126 | glfwTerminate(); 127 | 128 | fprintf(stderr, "Failed to open GLFW window\n"); 129 | exit(EXIT_FAILURE); 130 | } 131 | 132 | glfwMakeContextCurrent(window); 133 | gladLoadGL(glfwGetProcAddress); 134 | 135 | glfwSetKeyCallback(window, key_callback); 136 | set_icon(window, cur_icon_color); 137 | 138 | while (!glfwWindowShouldClose(window)) 139 | { 140 | glClear(GL_COLOR_BUFFER_BIT); 141 | glfwSwapBuffers(window); 142 | glfwWaitEvents(); 143 | } 144 | 145 | glfwDestroyWindow(window); 146 | glfwTerminate(); 147 | exit(EXIT_SUCCESS); 148 | } 149 | 150 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/tests/opacity.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Window opacity test program 3 | // Copyright (c) Camilla Löwy 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 | #include 27 | #define GLFW_INCLUDE_NONE 28 | #include 29 | 30 | #define NK_IMPLEMENTATION 31 | #define NK_INCLUDE_FIXED_TYPES 32 | #define NK_INCLUDE_FONT_BAKING 33 | #define NK_INCLUDE_DEFAULT_FONT 34 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 35 | #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT 36 | #define NK_INCLUDE_STANDARD_VARARGS 37 | #include 38 | 39 | #define NK_GLFW_GL2_IMPLEMENTATION 40 | #include 41 | 42 | #include 43 | #include 44 | 45 | static void error_callback(int error, const char* description) 46 | { 47 | fprintf(stderr, "Error: %s\n", description); 48 | } 49 | 50 | int main(int argc, char** argv) 51 | { 52 | GLFWwindow* window; 53 | struct nk_context* nk; 54 | struct nk_font_atlas* atlas; 55 | 56 | glfwSetErrorCallback(error_callback); 57 | 58 | if (!glfwInit()) 59 | exit(EXIT_FAILURE); 60 | 61 | glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE); 62 | 63 | window = glfwCreateWindow(400, 400, "Opacity", NULL, NULL); 64 | if (!window) 65 | { 66 | glfwTerminate(); 67 | exit(EXIT_FAILURE); 68 | } 69 | 70 | glfwMakeContextCurrent(window); 71 | gladLoadGL(glfwGetProcAddress); 72 | glfwSwapInterval(1); 73 | 74 | nk = nk_glfw3_init(window, NK_GLFW3_INSTALL_CALLBACKS); 75 | nk_glfw3_font_stash_begin(&atlas); 76 | nk_glfw3_font_stash_end(); 77 | 78 | while (!glfwWindowShouldClose(window)) 79 | { 80 | int width, height; 81 | struct nk_rect area; 82 | 83 | glfwGetWindowSize(window, &width, &height); 84 | area = nk_rect(0.f, 0.f, (float) width, (float) height); 85 | 86 | glClear(GL_COLOR_BUFFER_BIT); 87 | nk_glfw3_new_frame(); 88 | if (nk_begin(nk, "", area, 0)) 89 | { 90 | float opacity = glfwGetWindowOpacity(window); 91 | nk_layout_row_dynamic(nk, 30, 2); 92 | if (nk_slider_float(nk, 0.f, &opacity, 1.f, 0.001f)) 93 | glfwSetWindowOpacity(window, opacity); 94 | nk_labelf(nk, NK_TEXT_LEFT, "%0.3f", opacity); 95 | } 96 | 97 | nk_end(nk); 98 | nk_glfw3_render(NK_ANTI_ALIASING_ON); 99 | 100 | glfwSwapBuffers(window); 101 | glfwWaitEventsTimeout(1.0); 102 | } 103 | 104 | nk_glfw3_shutdown(); 105 | glfwTerminate(); 106 | exit(EXIT_SUCCESS); 107 | } 108 | 109 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/tests/threads.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Multi-threading test 3 | // Copyright (c) Camilla Löwy 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 | #define GLFW_INCLUDE_NONE 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | typedef struct 42 | { 43 | GLFWwindow* window; 44 | const char* title; 45 | float r, g, b; 46 | thrd_t id; 47 | } Thread; 48 | 49 | static volatile int running = GLFW_TRUE; 50 | 51 | static void error_callback(int error, const char* description) 52 | { 53 | fprintf(stderr, "Error: %s\n", description); 54 | } 55 | 56 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 57 | { 58 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 59 | glfwSetWindowShouldClose(window, GLFW_TRUE); 60 | } 61 | 62 | static int thread_main(void* data) 63 | { 64 | const Thread* thread = data; 65 | 66 | glfwMakeContextCurrent(thread->window); 67 | glfwSwapInterval(1); 68 | 69 | while (running) 70 | { 71 | const float v = (float) fabs(sin(glfwGetTime() * 2.f)); 72 | glClearColor(thread->r * v, thread->g * v, thread->b * v, 0.f); 73 | 74 | glClear(GL_COLOR_BUFFER_BIT); 75 | glfwSwapBuffers(thread->window); 76 | } 77 | 78 | glfwMakeContextCurrent(NULL); 79 | return 0; 80 | } 81 | 82 | int main(void) 83 | { 84 | int i, result; 85 | Thread threads[] = 86 | { 87 | { NULL, "Red", 1.f, 0.f, 0.f, 0 }, 88 | { NULL, "Green", 0.f, 1.f, 0.f, 0 }, 89 | { NULL, "Blue", 0.f, 0.f, 1.f, 0 } 90 | }; 91 | const int count = sizeof(threads) / sizeof(Thread); 92 | 93 | glfwSetErrorCallback(error_callback); 94 | 95 | if (!glfwInit()) 96 | exit(EXIT_FAILURE); 97 | 98 | glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); 99 | 100 | for (i = 0; i < count; i++) 101 | { 102 | threads[i].window = glfwCreateWindow(200, 200, 103 | threads[i].title, 104 | NULL, NULL); 105 | if (!threads[i].window) 106 | { 107 | glfwTerminate(); 108 | exit(EXIT_FAILURE); 109 | } 110 | 111 | glfwSetKeyCallback(threads[i].window, key_callback); 112 | 113 | glfwSetWindowPos(threads[i].window, 200 + 250 * i, 200); 114 | glfwShowWindow(threads[i].window); 115 | } 116 | 117 | glfwMakeContextCurrent(threads[0].window); 118 | gladLoadGL(glfwGetProcAddress); 119 | glfwMakeContextCurrent(NULL); 120 | 121 | for (i = 0; i < count; i++) 122 | { 123 | if (thrd_create(&threads[i].id, thread_main, threads + i) != 124 | thrd_success) 125 | { 126 | fprintf(stderr, "Failed to create secondary thread\n"); 127 | 128 | glfwTerminate(); 129 | exit(EXIT_FAILURE); 130 | } 131 | } 132 | 133 | while (running) 134 | { 135 | glfwWaitEvents(); 136 | 137 | for (i = 0; i < count; i++) 138 | { 139 | if (glfwWindowShouldClose(threads[i].window)) 140 | running = GLFW_FALSE; 141 | } 142 | } 143 | 144 | for (i = 0; i < count; i++) 145 | glfwHideWindow(threads[i].window); 146 | 147 | for (i = 0; i < count; i++) 148 | thrd_join(threads[i].id, &result); 149 | 150 | exit(EXIT_SUCCESS); 151 | } 152 | 153 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/tests/timeout.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Event wait timeout test 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test is intended to verify that waiting for events with timeout works 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #define GLFW_INCLUDE_NONE 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | static void error_callback(int error, const char* description) 40 | { 41 | fprintf(stderr, "Error: %s\n", description); 42 | } 43 | 44 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 45 | { 46 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 47 | glfwSetWindowShouldClose(window, GLFW_TRUE); 48 | } 49 | 50 | static float nrand(void) 51 | { 52 | return (float) rand() / (float) RAND_MAX; 53 | } 54 | 55 | int main(void) 56 | { 57 | GLFWwindow* window; 58 | 59 | srand((unsigned int) time(NULL)); 60 | 61 | glfwSetErrorCallback(error_callback); 62 | 63 | if (!glfwInit()) 64 | exit(EXIT_FAILURE); 65 | 66 | window = glfwCreateWindow(640, 480, "Event Wait Timeout Test", NULL, NULL); 67 | if (!window) 68 | { 69 | glfwTerminate(); 70 | exit(EXIT_FAILURE); 71 | } 72 | 73 | glfwMakeContextCurrent(window); 74 | gladLoadGL(glfwGetProcAddress); 75 | glfwSetKeyCallback(window, key_callback); 76 | 77 | while (!glfwWindowShouldClose(window)) 78 | { 79 | int width, height; 80 | float r = nrand(), g = nrand(), b = nrand(); 81 | float l = (float) sqrt(r * r + g * g + b * b); 82 | 83 | glfwGetFramebufferSize(window, &width, &height); 84 | 85 | glViewport(0, 0, width, height); 86 | glClearColor(r / l, g / l, b / l, 1.f); 87 | glClear(GL_COLOR_BUFFER_BIT); 88 | glfwSwapBuffers(window); 89 | 90 | glfwWaitEventsTimeout(1.0); 91 | } 92 | 93 | glfwDestroyWindow(window); 94 | 95 | glfwTerminate(); 96 | exit(EXIT_SUCCESS); 97 | } 98 | 99 | -------------------------------------------------------------------------------- /Example_OpenGL/glfw/tests/title.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // UTF-8 window title test 3 | // Copyright (c) Camilla Löwy 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 | #define GLFW_INCLUDE_NONE 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | static void error_callback(int error, const char* description) 38 | { 39 | fprintf(stderr, "Error: %s\n", description); 40 | } 41 | 42 | int main(void) 43 | { 44 | GLFWwindow* window; 45 | 46 | glfwSetErrorCallback(error_callback); 47 | 48 | if (!glfwInit()) 49 | exit(EXIT_FAILURE); 50 | 51 | window = glfwCreateWindow(400, 400, "English 日本語 русский язык 官話", NULL, NULL); 52 | if (!window) 53 | { 54 | glfwTerminate(); 55 | exit(EXIT_FAILURE); 56 | } 57 | 58 | glfwMakeContextCurrent(window); 59 | gladLoadGL(glfwGetProcAddress); 60 | glfwSwapInterval(1); 61 | 62 | while (!glfwWindowShouldClose(window)) 63 | { 64 | glClear(GL_COLOR_BUFFER_BIT); 65 | glfwSwapBuffers(window); 66 | glfwWaitEvents(); 67 | } 68 | 69 | glfwTerminate(); 70 | exit(EXIT_SUCCESS); 71 | } 72 | 73 | -------------------------------------------------------------------------------- /Example_Unity/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(screen_capture_example_unity) 2 | 3 | if(WIN32) 4 | 5 | elseif(APPLE) 6 | else() 7 | endif() 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Scott 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Logotype primary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smasherprog/screen_capture_lite/b77bc46c53fd01d4678cacd4766a22de2b7ab3d4/Logotype primary.png -------------------------------------------------------------------------------- /azure-devops/build-windows.yml: -------------------------------------------------------------------------------- 1 | parameters: 2 | - name: name 3 | - name: targetPlatform 4 | - name: image 5 | 6 | jobs: 7 | - job: ${{ parameters.name }} 8 | pool: 9 | vmImage: ${{ parameters.image }} 10 | steps: 11 | - task: CMake@1 12 | inputs: 13 | cmakeArgs: '.. -G"Visual Studio 17 2022" -DCMAKE_GENERATOR_PLATFORM=${{ parameters.targetPlatform }} -A ${{ parameters.targetPlatform }} -DCMAKE_INSTALL_PREFIX=./output' 14 | - task: CMake@1 15 | inputs: 16 | cmakeArgs: '--build . --target INSTALL' 17 | - task: ArchiveFiles@2 18 | condition: and(succeeded(), eq(variables.isMain, true)) 19 | inputs: 20 | rootFolderOrFile: '$(Build.SourcesDirectory)/build/output/' 21 | includeRootFolder: true 22 | archiveType: 'zip' 23 | archiveFile: '$(Build.ArtifactStagingDirectory)/Windows_${{ parameters.targetPlatform }}_$(Build.BuildId).zip' 24 | replaceExistingArchive: true 25 | - task: GitHubRelease@1 26 | condition: and(succeeded(), eq(variables.isMain, true)) 27 | inputs: 28 | gitHubConnection: 'smasherprog' 29 | repositoryName: '$(Build.Repository.Name)' 30 | action: 'edit' 31 | target: '$(Build.SourceVersion)' 32 | tagSource: 'userSpecifiedTag' 33 | tag: '17.1.$(Build.BuildId)' 34 | addChangeLog: false 35 | isPreRelease: true 36 | assets: '$(Build.ArtifactStagingDirectory)/Windows_${{ parameters.targetPlatform }}_$(Build.BuildId).zip' 37 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | - master 3 | pr: 4 | - master 5 | 6 | variables: 7 | isMain: $[eq(variables['Build.SourceBranch'], 'refs/heads/master')] 8 | 9 | jobs: 10 | - job: createrelease 11 | pool: 12 | vmImage: windows-latest 13 | steps: 14 | - task: GitHubRelease@1 15 | condition: and(succeeded(), eq(variables.isMain, true)) 16 | inputs: 17 | gitHubConnection: 'smasherprog' 18 | repositoryName: '$(Build.Repository.Name)' 19 | action: 'create' 20 | target: '$(Build.SourceVersion)' 21 | tagSource: 'userSpecifiedTag' 22 | tag: '17.1.$(Build.BuildId)' 23 | releaseNotesFilePath: 'releasenotes.txt' 24 | isPreRelease: true 25 | addChangeLog: false 26 | - template: azure-devops/build-windows.yml 27 | parameters: 28 | name: 'Windows_VS2019_x86' 29 | targetPlatform: Win32 30 | image: 'windows-latest' 31 | - template: azure-devops/build-windows.yml 32 | parameters: 33 | name: 'Windows_VS2019_x64' 34 | targetPlatform: x64 35 | image: 'windows-latest' 36 | - job: mac_build 37 | pool: 38 | vmImage: 'macOS-latest' 39 | steps: 40 | - script: cmake . && make; 41 | - job: ubuntu_build 42 | pool: 43 | vmImage: 'ubuntu-latest' 44 | steps: 45 | - script: | 46 | sudo apt install -y libx11-dev libxfixes-dev libxtst-dev libxinerama-dev libxrandr-dev libxcursor-dev 47 | CXX=clang++ CC=clang cmake . && make; -------------------------------------------------------------------------------- /cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | if (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt") 2 | message(SEND_ERROR "Cannot find install_manifest: ${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt") 3 | message(FATAL_ERROR "Did you install from this build ?") 4 | endif() 5 | 6 | file(READ "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt" files) 7 | string(REGEX REPLACE "\n" ";" files "${files}") 8 | foreach(file ${files}) 9 | message(STATUS "Uninstalling $ENV{DESTDIR}${file}") 10 | if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 11 | exec_program( 12 | "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 13 | OUTPUT_VARIABLE rm_out 14 | RETURN_VALUE rm_retval 15 | ) 16 | if(NOT "${rm_retval}" STREQUAL 0) 17 | message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") 18 | endif() 19 | else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 20 | message(STATUS "File $ENV{DESTDIR}${file} does not exist.") 21 | endif() 22 | endforeach() -------------------------------------------------------------------------------- /include/ios/CGFrameProcessor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "internal/SCCommon.h" 3 | #include 4 | 5 | namespace SL { 6 | namespace Screen_Capture { 7 | class CGFrameProcessor: public BaseFrameProcessor { 8 | Monitor SelectedMonitor; 9 | public: 10 | 11 | DUPL_RETURN Init(std::shared_ptr data, Window& window); 12 | DUPL_RETURN ProcessFrame(const Window& window); 13 | }; 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /include/ios/NSFrameProcessor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "internal/SCCommon.h" 3 | 4 | namespace SL { 5 | namespace Screen_Capture { 6 | class NSFrameProcessor; 7 | struct NSFrameProcessorImpl; 8 | NSFrameProcessorImpl* CreateNSFrameProcessorImpl(); 9 | void DestroyNSFrameProcessorImpl(NSFrameProcessorImpl*); 10 | void setMinFrameDuration(NSFrameProcessorImpl*, const std::chrono::microseconds& ); 11 | void Pause_(NSFrameProcessorImpl*); 12 | void Resume_(NSFrameProcessorImpl*); 13 | 14 | DUPL_RETURN Init(NSFrameProcessorImpl* createdimpl, NSFrameProcessor* parent, const std::chrono::microseconds& ); 15 | 16 | class NSFrameProcessor : public BaseFrameProcessor { 17 | NSFrameProcessorImpl* NSFrameProcessorImpl_ = nullptr; 18 | std::chrono::microseconds LastDuration; 19 | public: 20 | NSFrameProcessor(); 21 | ~NSFrameProcessor(); 22 | Monitor SelectedMonitor; 23 | void Pause(); 24 | void Resume(); 25 | 26 | DUPL_RETURN Init(std::shared_ptr data, Monitor& monitor); 27 | DUPL_RETURN ProcessFrame(const Monitor& curentmonitorinfo); 28 | DUPL_RETURN Init(std::shared_ptr data, Window& window); 29 | DUPL_RETURN ProcessFrame(const Window& window); 30 | 31 | }; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /include/ios/NSFrameProcessorm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #import "internal/SCCommon.h" 3 | #import "NSFrameProcessor.h" 4 | #import 5 | #import 6 | 7 | @interface FrameProcessor: NSObject 8 | @property(nonatomic, assign) SL::Screen_Capture::NSFrameProcessor* nsframeprocessor; 9 | @property(nonatomic, retain) AVCaptureSession *avcapturesession; 10 | @property(nonatomic, retain) AVCaptureVideoDataOutput *output; 11 | @property(nonatomic, retain) AVCaptureScreenInput* avinput; 12 | @property(atomic) bool Working; 13 | @property(atomic) bool Paused; 14 | -(SL::Screen_Capture::DUPL_RETURN) Init:(SL::Screen_Capture::NSFrameProcessor*) parent second:(CMTime)interval; 15 | -(void) setFrameRate:(CMTime)interval; 16 | -(void) Stop; 17 | -(void) Pause; 18 | -(void) Resume; 19 | @end 20 | 21 | 22 | -------------------------------------------------------------------------------- /include/ios/NSMouseCapture.h: -------------------------------------------------------------------------------- 1 | #ifndef Header_h 2 | #define Header_h 3 | 4 | struct SL_MouseCur{ 5 | CGImageRef Image; 6 | int HotSpotx; 7 | int HotSpoty; 8 | }; 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | void SLScreen_Capture_InitMouseCapture(); 14 | struct SL_MouseCur SLScreen_Capture_GetCurrentMouseImage(); 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/ios/NSMouseProcessor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "internal/SCCommon.h" 3 | #include 4 | #include "TargetConditionals.h" 5 | #include 6 | 7 | namespace SL { 8 | namespace Screen_Capture { 9 | 10 | class NSMouseProcessor : public BaseMouseProcessor { 11 | public: 12 | const int MaxCursurorSize=32; 13 | DUPL_RETURN Init(std::shared_ptr data); 14 | DUPL_RETURN ProcessFrame(); 15 | 16 | }; 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /include/linux/X11FrameProcessor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "internal/SCCommon.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace SL { 9 | namespace Screen_Capture { 10 | 11 | class X11FrameProcessor: public BaseFrameProcessor { 12 | 13 | Display* SelectedDisplay=nullptr; 14 | XID SelectedWindow = 0; 15 | XImage* XImage_=nullptr; 16 | std::unique_ptr ShmInfo; 17 | Monitor SelectedMonitor; 18 | 19 | public: 20 | X11FrameProcessor(); 21 | ~X11FrameProcessor(); 22 | 23 | void Pause() {} 24 | void Resume() {} 25 | DUPL_RETURN Init(std::shared_ptr data, Monitor& monitor); 26 | DUPL_RETURN ProcessFrame(const Monitor& currentmonitorinfo); 27 | DUPL_RETURN Init(std::shared_ptr data, const Window& selectedwindow); 28 | DUPL_RETURN ProcessFrame(Window& selectedwindow); 29 | }; 30 | } 31 | } -------------------------------------------------------------------------------- /include/linux/X11MouseProcessor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "internal/SCCommon.h" 3 | #include 4 | #include 5 | #include 6 | 7 | namespace SL { 8 | namespace Screen_Capture { 9 | 10 | class X11MouseProcessor : public BaseMouseProcessor { 11 | Display* SelectedDisplay=nullptr; 12 | XID RootWindow; 13 | 14 | public: 15 | const int MaxCursurorSize =32; 16 | X11MouseProcessor(); 17 | ~X11MouseProcessor(); 18 | DUPL_RETURN Init(std::shared_ptr data); 19 | DUPL_RETURN ProcessFrame(); 20 | 21 | }; 22 | 23 | } 24 | } -------------------------------------------------------------------------------- /include/windows/DXFrameProcessor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "internal/SCCommon.h" 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace SL { 11 | namespace Screen_Capture { 12 | class DXFrameProcessor : public BaseFrameProcessor { 13 | Microsoft::WRL::ComPtr Device; 14 | Microsoft::WRL::ComPtr DeviceContext; 15 | Microsoft::WRL::ComPtr StagingSurf; 16 | 17 | Microsoft::WRL::ComPtr OutputDuplication; 18 | DXGI_OUTPUT_DESC OutputDesc; 19 | UINT Output; 20 | std::vector MetaDataBuffer; 21 | Monitor SelectedMonitor; 22 | 23 | public: 24 | 25 | void Pause() {} 26 | void Resume() {} 27 | DUPL_RETURN Init(std::shared_ptr data, Monitor &monitor); 28 | DUPL_RETURN ProcessFrame(const Monitor ¤tmonitorinfo); 29 | }; 30 | 31 | } // namespace Screen_Capture 32 | } // namespace SL -------------------------------------------------------------------------------- /include/windows/GDIFrameProcessor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ScreenCapture.h" 3 | #include "internal/SCCommon.h" 4 | #include 5 | #include "GDIHelpers.h" 6 | 7 | namespace SL { 8 | namespace Screen_Capture { 9 | 10 | class GDIFrameProcessor : public BaseFrameProcessor { 11 | HDCWrapper MonitorDC; 12 | HDCWrapper CaptureDC; 13 | HBITMAPWrapper CaptureBMP; 14 | Monitor SelectedMonitor; 15 | HWND SelectedWindow; 16 | std::unique_ptr NewImageBuffer; 17 | 18 | std::shared_ptr Data; 19 | public: 20 | void Pause() {} 21 | void Resume() {} 22 | DUPL_RETURN Init(std::shared_ptr data, const Monitor& monitor); 23 | DUPL_RETURN ProcessFrame(const Monitor& currentmonitorinfo); 24 | DUPL_RETURN Init(std::shared_ptr data, const Window& selectedwindow); 25 | DUPL_RETURN ProcessFrame(Window& selectedwindow); 26 | }; 27 | } 28 | } -------------------------------------------------------------------------------- /include/windows/GDIHelpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN 4 | #include 5 | #include 6 | namespace SL { 7 | namespace Screen_Capture { 8 | class HDCWrapper { 9 | public: 10 | HDCWrapper() : DC(nullptr) {} 11 | ~HDCWrapper() { if (DC != nullptr) { DeleteDC(DC); } } 12 | HDC DC; 13 | }; 14 | class HBITMAPWrapper { 15 | public: 16 | HBITMAPWrapper() : Bitmap(nullptr) {} 17 | ~HBITMAPWrapper() { if (Bitmap != nullptr) { DeleteObject(Bitmap); } } 18 | HBITMAP Bitmap; 19 | }; 20 | struct WindowDimensions { 21 | RECT ClientRect; 22 | RECT ClientBorder; 23 | WINDOWPLACEMENT Placement; 24 | }; 25 | 26 | inline WindowDimensions GetWindowRect(HWND hwnd) { 27 | WindowDimensions ret = { 0 }; 28 | GetWindowRect(hwnd, &ret.ClientRect); 29 | ret.Placement.length = sizeof(WINDOWPLACEMENT); 30 | GetWindowPlacement(hwnd, &ret.Placement); 31 | 32 | RECT frame = { 0 }; 33 | if (SUCCEEDED(DwmGetWindowAttribute(hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, &frame, sizeof(frame)))) { 34 | 35 | ret.ClientBorder.left = frame.left - ret.ClientRect.left; 36 | ret.ClientBorder.top = frame.top - ret.ClientRect.top; 37 | ret.ClientBorder.right = ret.ClientRect.right - frame.right; 38 | ret.ClientBorder.bottom = ret.ClientRect.bottom - frame.bottom; 39 | } 40 | 41 | ret.ClientRect.bottom -= ret.ClientBorder.bottom; 42 | ret.ClientRect.top += ret.ClientBorder.top; 43 | ret.ClientRect.left += ret.ClientBorder.left; 44 | ret.ClientRect.right -= ret.ClientBorder.right; 45 | 46 | return ret; 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /include/windows/GDIMouseProcessor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ScreenCapture.h" 3 | #include "internal/SCCommon.h" 4 | #include 5 | #include "GDIHelpers.h" 6 | 7 | namespace SL { 8 | namespace Screen_Capture { 9 | 10 | class GDIMouseProcessor : public BaseMouseProcessor { 11 | HDCWrapper MonitorDC; 12 | HDCWrapper CaptureDC; 13 | 14 | public: 15 | 16 | DUPL_RETURN Init(std::shared_ptr data); 17 | DUPL_RETURN ProcessFrame(); 18 | }; 19 | } 20 | } -------------------------------------------------------------------------------- /modules/screen_capture_lite_sharedConfig.cmake.in: -------------------------------------------------------------------------------- 1 | set(screen_capture_lite_shared_FOUND 1) 2 | 3 | set(screen_capture_lite_shared_VERSION_COUNT 2) 4 | set(screen_capture_lite_shared_VERSION_MAJOR "@CMAKE_PROJECT_VERSION_MAJOR@") 5 | set(screen_capture_lite_shared_VERSION_MINOR "@CMAKE_PROJECT_VERSION_MINOR@") 6 | 7 | set(screen_capture_lite_shared_INCLUDE_DIR "@CMAKE_INSTALL_PREFIX@/include") 8 | set(screen_capture_lite_shared_INCLUDE_DIRS ${screen_capture_lite_shared_INCLUDE_DIR}) 9 | 10 | set(screen_capture_lite_shared_LIBRARY_DIR "@CMAKE_INSTALL_PREFIX@/lib@LIB_SUFFIX@") 11 | 12 | find_library(screen_capture_lite_shared_LIBRARY screen_capture_lite_shared HINTS ${screen_capture_lite_shared_LIBRARY_DIR}) 13 | 14 | set(screen_capture_lite_shared_LIBS ${screen_capture_lite_shared_LIBRARY}) 15 | set(screen_capture_lite_shared_LIBRARIES ${screen_capture_lite_shared_LIBS}) 16 | -------------------------------------------------------------------------------- /modules/screen_capture_lite_staticConfig.cmake.in: -------------------------------------------------------------------------------- 1 | set(screen_capture_lite_static_FOUND 1) 2 | 3 | set(screen_capture_lite_static_VERSION_COUNT 2) 4 | set(screen_capture_lite_static_VERSION_MAJOR "@CMAKE_PROJECT_VERSION_MAJOR@") 5 | set(screen_capture_lite_static_VERSION_MINOR "@CMAKE_PROJECT_VERSION_MINOR@") 6 | 7 | set(screen_capture_lite_static_INCLUDE_DIR "@CMAKE_INSTALL_PREFIX@/include") 8 | set(screen_capture_lite_static_INCLUDE_DIRS ${screen_capture_lite_static_INCLUDE_DIR}) 9 | 10 | set(screen_capture_lite_static_LIBRARY_DIR "@CMAKE_INSTALL_PREFIX@/lib@LIB_SUFFIX@") 11 | 12 | find_library(screen_capture_lite_static_LIBRARY screen_capture_lite_static HINTS ${screen_capture_lite_static_LIBRARY_DIR}) 13 | 14 | set(screen_capture_lite_static_LIBS ${screen_capture_lite_static_LIBRARY}) 15 | set(screen_capture_lite_static_LIBRARIES ${screen_capture_lite_static_LIBS}) 16 | -------------------------------------------------------------------------------- /releasenotes.txt: -------------------------------------------------------------------------------- 1 | Fixed Example Code Extract to RGB code 2 | Added functions to check if application has permission to capture the screen, Request permission, and can request permission -------------------------------------------------------------------------------- /src_cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(screen_capture_lite) 2 | 3 | if(WIN32) 4 | set(SCREEN_CAPTURE_PLATFORM_SRC 5 | windows/GetWindows.cpp 6 | windows/GetMonitors.cpp 7 | windows/DXFrameProcessor.cpp 8 | ../include/windows/DXFrameProcessor.h 9 | windows/GDIFrameProcessor.cpp 10 | ../include/windows/GDIFrameProcessor.h 11 | windows/GDIMouseProcessor.cpp 12 | ../include/windows/GDIMouseProcessor.h 13 | windows/ThreadRunner.cpp 14 | ../include/windows/GDIHelpers.h 15 | ) 16 | set(SCREEN_CAPTURE_PLATFORM_INC 17 | ../include/windows 18 | ) 19 | add_definitions(-DNOMINMAX) 20 | link_libraries(dxgi.lib d3d11.lib) 21 | elseif(APPLE) 22 | 23 | set(SCREEN_CAPTURE_PLATFORM_SRC 24 | ios/GetWindows.cpp 25 | ios/NSMouseCapture.m 26 | ../include/ios/NSMouseCapture.h 27 | ios/NSFrameProcessor.cpp 28 | ios/NSFrameProcessor.mm 29 | ../include/ios/NSFrameProcessorm.h 30 | ../include/ios/NSFrameProcessor.h 31 | ios/NSMouseProcessor.cpp 32 | ../include/ios/NSMouseProcessor.h 33 | ios/CGFrameProcessor.cpp 34 | ../include/ios/CGFrameProcessor.h 35 | ios/GetMonitors.cpp 36 | ios/ThreadRunner.cpp 37 | ) 38 | set(SCREEN_CAPTURE_PLATFORM_INC 39 | ../include/ios 40 | ) 41 | else() 42 | set(SCREEN_CAPTURE_PLATFORM_SRC 43 | ../include/linux/X11MouseProcessor.h 44 | linux/X11MouseProcessor.cpp 45 | ../include/linux/X11FrameProcessor.h 46 | linux/X11FrameProcessor.cpp 47 | linux/GetMonitors.cpp 48 | linux/GetWindows.cpp 49 | linux/ThreadRunner.cpp 50 | ) 51 | find_package(X11 REQUIRED) 52 | if(!X11_XTest_FOUND) 53 | message(FATAL_ERROR "X11 extensions are required, but not found!") 54 | endif() 55 | if(!X11_Xfixes_LIB) 56 | message(FATAL_ERROR "X11 fixes extension is required, but not found!") 57 | endif() 58 | set(SCREEN_CAPTURE_PLATFORM_INC 59 | ../include/linux 60 | ${X11_INCLUDE_DIR} 61 | ) 62 | endif() 63 | 64 | 65 | include_directories( 66 | ../include 67 | ${SCREEN_CAPTURE_PLATFORM_INC} 68 | ) 69 | 70 | set(libsrc 71 | ../include/ScreenCapture.h 72 | ../include/internal/SCCommon.h 73 | ../include/internal/ThreadManager.h 74 | ScreenCapture.c 75 | ScreenCapture.cpp 76 | SCCommon.cpp 77 | ThreadManager.cpp 78 | ${SCREEN_CAPTURE_PLATFORM_SRC} 79 | ) 80 | 81 | if(NOT ${BUILD_SHARED_LIBS}) 82 | message("Building STATIC Library") 83 | add_library(${PROJECT_NAME}_static STATIC ${libsrc}) 84 | target_link_libraries(${PROJECT_NAME}_static Dwmapi) 85 | else() 86 | message("Building SHARED Library") 87 | 88 | add_library(${PROJECT_NAME}_shared SHARED ${libsrc} ../include/ScreenCapture_C_API.h) 89 | 90 | add_definitions(-DSC_LITE_DLL) 91 | if(WIN32) 92 | target_link_libraries(${PROJECT_NAME}_shared Dwmapi) 93 | if (!MINGW) 94 | install (FILES $ DESTINATION bin OPTIONAL) 95 | endif() 96 | elseif(APPLE) 97 | find_package(Threads REQUIRED) 98 | find_library(corefoundation_lib CoreFoundation REQUIRED) 99 | find_library(cocoa_lib Cocoa REQUIRED) 100 | find_library(coremedia_lib CoreMedia REQUIRED) 101 | find_library(avfoundation_lib AVFoundation REQUIRED) 102 | find_library(coregraphics_lib CoreGraphics REQUIRED) 103 | find_library(corevideo_lib CoreVideo REQUIRED) 104 | 105 | target_link_libraries( 106 | ${PROJECT_NAME}_shared 107 | ${CMAKE_THREAD_LIBS_INIT} 108 | ${corefoundation_lib} 109 | ${cocoa_lib} 110 | ${coremedia_lib} 111 | ${avfoundation_lib} 112 | ${coregraphics_lib} 113 | ${corevideo_lib} 114 | ) 115 | else() 116 | find_package(X11 REQUIRED) 117 | if(!X11_XTest_FOUND) 118 | message(FATAL_ERROR "X11 extensions are required, but not found!") 119 | endif() 120 | if(!X11_Xfixes_LIB) 121 | message(FATAL_ERROR "X11 fixes extension is required, but not found!") 122 | endif() 123 | find_package(Threads REQUIRED) 124 | target_link_libraries( 125 | ${PROJECT_NAME}_shared 126 | ${X11_LIBRARIES} 127 | ${X11_Xfixes_LIB} 128 | ${X11_XTest_LIB} 129 | ${X11_Xinerama_LIB} 130 | ${CMAKE_THREAD_LIBS_INIT} 131 | ) 132 | endif() 133 | endif() 134 | -------------------------------------------------------------------------------- /src_cpp/ScreenCapture.c: -------------------------------------------------------------------------------- 1 | #include "ScreenCapture_C_API.h" 2 | -------------------------------------------------------------------------------- /src_cpp/ThreadManager.cpp: -------------------------------------------------------------------------------- 1 | #include "internal/ThreadManager.h" 2 | #include 3 | #include 4 | #include 5 | 6 | SL::Screen_Capture::ThreadManager::ThreadManager() 7 | { 8 | } 9 | SL::Screen_Capture::ThreadManager::~ThreadManager() 10 | { 11 | Join(); 12 | } 13 | inline std::ostream &operator<<(std::ostream &os, const SL::Screen_Capture::Monitor &p) 14 | { 15 | return os << "Id=" << p.Id << " Index=" << p.Index << " Height=" << p.Height << " Width=" << p.Width << " OffsetX=" << p.OffsetX 16 | << " OffsetY=" << p.OffsetY << " Name=" << p.Name; 17 | } 18 | void SL::Screen_Capture::ThreadManager::Init(const std::shared_ptr& data) 19 | { 20 | assert(m_ThreadHandles.empty()); 21 | 22 | if (data->ScreenCaptureData.getThingsToWatch) { 23 | auto monitors = data->ScreenCaptureData.getThingsToWatch(); 24 | auto mons = GetMonitors(); 25 | for ([[maybe_unused]] auto &m : monitors) { 26 | assert(isMonitorInsideBounds(mons, m)); 27 | } 28 | 29 | m_ThreadHandles.resize(monitors.size() + (data->ScreenCaptureData.OnMouseChanged ? 1 : 0)); // add another thread for mouse capturing if needed 30 | 31 | for (size_t i = 0; i < monitors.size(); ++i) { 32 | m_ThreadHandles[i] = std::thread(&SL::Screen_Capture::RunCaptureMonitor, data, monitors[i]); 33 | } 34 | if (data->ScreenCaptureData.OnMouseChanged) { 35 | m_ThreadHandles.back() = std::thread([data] { 36 | SL::Screen_Capture::RunCaptureMouse(data); 37 | }); 38 | } 39 | 40 | } 41 | else if (data->WindowCaptureData.getThingsToWatch) { 42 | auto windows = data->WindowCaptureData.getThingsToWatch(); 43 | m_ThreadHandles.resize(windows.size() + (data->WindowCaptureData.OnMouseChanged ? 1 : 0)); // add another thread for mouse capturing if needed 44 | for (size_t i = 0; i < windows.size(); ++i) { 45 | m_ThreadHandles[i] = std::thread(&SL::Screen_Capture::RunCaptureWindow, data, windows[i]); 46 | } 47 | if (data->WindowCaptureData.OnMouseChanged) { 48 | m_ThreadHandles.back() = std::thread([data] { 49 | SL::Screen_Capture::RunCaptureMouse(data); 50 | }); 51 | } 52 | } 53 | } 54 | 55 | void SL::Screen_Capture::ThreadManager::Join() 56 | { 57 | for (auto& t : m_ThreadHandles) { 58 | if (t.joinable()) { 59 | if (t.get_id() == std::this_thread::get_id()) { 60 | t.detach();// will run to completion 61 | } 62 | else { 63 | t.join(); 64 | } 65 | } 66 | } 67 | m_ThreadHandles.clear(); 68 | } 69 | -------------------------------------------------------------------------------- /src_cpp/ios/CGFrameProcessor.cpp: -------------------------------------------------------------------------------- 1 | #include "CGFrameProcessor.h" 2 | #include "TargetConditionals.h" 3 | #include 4 | #include 5 | 6 | namespace SL { 7 | namespace Screen_Capture { 8 | 9 | 10 | DUPL_RETURN CGFrameProcessor::Init(std::shared_ptr data, Window &window) 11 | { 12 | auto ret = DUPL_RETURN::DUPL_RETURN_SUCCESS; 13 | Data = data; 14 | return ret; 15 | } 16 | DUPL_RETURN CGFrameProcessor::ProcessFrame(const Window &window) 17 | { 18 | 19 | auto Ret = DUPL_RETURN_SUCCESS; 20 | 21 | auto imageRef = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, static_cast(window.Handle), 22 | kCGWindowImageBoundsIgnoreFraming); 23 | if (!imageRef) 24 | return DUPL_RETURN_ERROR_EXPECTED; // this happens when the monitors change. 25 | 26 | auto width = CGImageGetWidth(imageRef); 27 | auto height = CGImageGetHeight(imageRef); 28 | 29 | if (width != window.Size.x || height != window.Size.y) { 30 | CGImageRelease(imageRef); 31 | return DUPL_RETURN_ERROR_EXPECTED; // this happens when the window sizes change. 32 | } 33 | auto prov = CGImageGetDataProvider(imageRef); 34 | if (!prov) { 35 | CGImageRelease(imageRef); 36 | return DUPL_RETURN_ERROR_EXPECTED; 37 | } 38 | auto bytesperrow = CGImageGetBytesPerRow(imageRef); 39 | auto bitsperpixel = CGImageGetBitsPerPixel(imageRef); 40 | // right now only support full 32 bit images.. Most desktops should run this as its the most efficent 41 | assert(bitsperpixel == sizeof(ImageBGRA) * 8); 42 | 43 | auto rawdatas = CGDataProviderCopyData(prov); 44 | auto buf = CFDataGetBytePtr(rawdatas); 45 | ProcessCapture(Data->WindowCaptureData, *this, window, buf, bytesperrow); 46 | 47 | CFRelease(rawdatas); 48 | CGImageRelease(imageRef); 49 | return Ret; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src_cpp/ios/GetMonitors.cpp: -------------------------------------------------------------------------------- 1 | #include "ScreenCapture.h" 2 | #include "internal/SCCommon.h" 3 | #include 4 | 5 | 6 | namespace SL{ 7 | namespace Screen_Capture{ 8 | 9 | std::vector GetMonitors() { 10 | std::vector ret; 11 | std::vector displays; 12 | CGDisplayCount count=0; 13 | //get count 14 | CGGetActiveDisplayList(0, 0, &count); 15 | displays.resize(count); 16 | 17 | CGGetActiveDisplayList(count, displays.data(), &count); 18 | for(auto i = 0; i < count; i++) { 19 | //only include non-mirrored displays 20 | if(CGDisplayMirrorsDisplay(displays[i]) == kCGNullDirectDisplay){ 21 | 22 | auto dismode =CGDisplayCopyDisplayMode(displays[i]); 23 | 24 | auto width = CGDisplayModeGetPixelWidth(dismode); 25 | auto height = CGDisplayModeGetPixelHeight(dismode); 26 | CGDisplayModeRelease(dismode); 27 | auto r = CGDisplayBounds(displays[i]); 28 | auto scale = static_cast(width)/static_cast(r.size.width); 29 | auto name = std::string("Monitor ") + std::to_string(displays[i]); 30 | ret.push_back(CreateMonitor(static_cast(ret.size()), displays[i],height,width, int(r.origin.x), int(r.origin.y), name, scale)); 31 | } 32 | } 33 | return ret; 34 | 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src_cpp/ios/GetWindows.cpp: -------------------------------------------------------------------------------- 1 | #include "ScreenCapture.h" 2 | #include "internal/SCCommon.h" 3 | #include 4 | #include 5 | #include "TargetConditionals.h" 6 | #include 7 | #include 8 | 9 | namespace SL 10 | { 11 | namespace Screen_Capture 12 | { 13 | 14 | std::vector GetWindows() 15 | { 16 | CGDisplayCount count=0; 17 | CGGetActiveDisplayList(0, 0, &count); 18 | std::vector displays; 19 | displays.resize(count); 20 | CGGetActiveDisplayList(count, displays.data(), &count); 21 | auto xscale=1.0f; 22 | auto yscale = 1.0f; 23 | 24 | for(auto i = 0; i < count; i++) { 25 | //only include non-mirrored displays 26 | if(CGDisplayMirrorsDisplay(displays[i]) == kCGNullDirectDisplay){ 27 | 28 | auto dismode =CGDisplayCopyDisplayMode(displays[i]); 29 | auto scaledsize = CGDisplayBounds(displays[i]); 30 | 31 | auto pixelwidth = CGDisplayModeGetPixelWidth(dismode); 32 | auto pixelheight = CGDisplayModeGetPixelHeight(dismode); 33 | 34 | CGDisplayModeRelease(dismode); 35 | 36 | if(scaledsize.size.width !=pixelwidth){//scaling going on! 37 | xscale = static_cast(pixelwidth)/static_cast(scaledsize.size.width); 38 | } 39 | if(scaledsize.size.height !=pixelheight){//scaling going on! 40 | yscale = static_cast(pixelheight)/static_cast(scaledsize.size.height); 41 | } 42 | break; 43 | } 44 | } 45 | 46 | auto windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID); 47 | std::vector ret; 48 | CFIndex numWindows = CFArrayGetCount(windowList ); 49 | 50 | for( int i = 0; i < (int)numWindows; i++ ) { 51 | Window w = {}; 52 | uint32_t windowid=0; 53 | auto dict = static_cast(CFArrayGetValueAtIndex(windowList, i)); 54 | auto cfwindowname = static_cast(CFDictionaryGetValue(dict, kCGWindowName)); 55 | CFStringGetCString(cfwindowname, w.Name, sizeof(w.Name), kCFStringEncodingUTF8); 56 | w.Name[sizeof(w.Name)-1] = '\n'; 57 | 58 | 59 | CFNumberGetValue(static_cast(CFDictionaryGetValue(dict, kCGWindowNumber)), kCFNumberIntType, &windowid); 60 | w.Handle = static_cast(windowid); 61 | 62 | auto dims =static_cast(CFDictionaryGetValue(dict,kCGWindowBounds)); 63 | CGRect rect; 64 | CGRectMakeWithDictionaryRepresentation(dims, &rect); 65 | w.Position.x = static_cast(rect.origin.x); 66 | w.Position.y = static_cast(rect.origin.y); 67 | 68 | w.Size.x = static_cast(rect.size.width * xscale); 69 | w.Size.y = static_cast(rect.size.height* yscale); 70 | std::transform(std::begin(w.Name), std::end(w.Name), std::begin(w.Name), ::tolower); 71 | ret.push_back(w); 72 | } 73 | CFRelease(windowList); 74 | return ret; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src_cpp/ios/NSFrameProcessor.cpp: -------------------------------------------------------------------------------- 1 | #include "NSFrameProcessor.h" 2 | 3 | namespace SL { 4 | namespace Screen_Capture { 5 | 6 | NSFrameProcessor::NSFrameProcessor(){ 7 | NSFrameProcessorImpl_ = nullptr; 8 | } 9 | NSFrameProcessor::~NSFrameProcessor(){ 10 | DestroyNSFrameProcessorImpl(NSFrameProcessorImpl_); 11 | } 12 | DUPL_RETURN NSFrameProcessor::Init(std::shared_ptr data, Monitor &monitor) 13 | { 14 | Data = data; 15 | auto timer = std::atomic_load(&Data->ScreenCaptureData.FrameTimer); 16 | LastDuration = timer->duration(); 17 | SelectedMonitor = monitor; 18 | NSFrameProcessorImpl_ = CreateNSFrameProcessorImpl(); 19 | return Screen_Capture::Init(NSFrameProcessorImpl_, this, LastDuration); 20 | } 21 | 22 | DUPL_RETURN NSFrameProcessor::ProcessFrame(const Monitor &curentmonitorinfo) 23 | { 24 | auto timer = std::atomic_load(&Data->ScreenCaptureData.FrameTimer); 25 | //get the timer and check if we need to update the internal timer 26 | if(timer->duration()!= LastDuration){ 27 | LastDuration = timer->duration(); 28 | setMinFrameDuration(NSFrameProcessorImpl_, LastDuration); 29 | } 30 | return DUPL_RETURN_SUCCESS; 31 | } 32 | void NSFrameProcessor::Pause(){ 33 | Pause_(NSFrameProcessorImpl_); 34 | } 35 | void NSFrameProcessor::Resume(){ 36 | Resume_(NSFrameProcessorImpl_); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src_cpp/ios/NSMouseCapture.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSMouseCapture.m 3 | // Screen_Capture 4 | // 5 | // Created by scott lee on 1/11/17. 6 | // 7 | // 8 | 9 | #import 10 | #import 11 | #import "NSMouseCapture.h" 12 | 13 | void SLScreen_Capture_InitMouseCapture(){ 14 | [NSApplication sharedApplication]; 15 | } 16 | struct SL_MouseCur SLScreen_Capture_GetCurrentMouseImage(){ 17 | struct SL_MouseCur ret= {}; 18 | 19 | @autoreleasepool { 20 | NSCursor *cur = [NSCursor currentSystemCursor]; 21 | if(cur==nil) return ret; 22 | NSImage *overlay = [cur image]; 23 | CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)[overlay TIFFRepresentation], NULL); 24 | ret.Image = CGImageSourceCreateImageAtIndex(source, 0, NULL); 25 | NSPoint p = [cur hotSpot]; 26 | ret.HotSpotx = p.x; 27 | ret.HotSpoty = p.y; 28 | CFRelease(source); 29 | } 30 | 31 | return ret; 32 | } -------------------------------------------------------------------------------- /src_cpp/ios/NSMouseProcessor.cpp: -------------------------------------------------------------------------------- 1 | #include "NSMouseProcessor.h" 2 | #include "NSMouseCapture.h" 3 | #include 4 | 5 | namespace SL { 6 | namespace Screen_Capture { 7 | 8 | DUPL_RETURN NSMouseProcessor::Init(std::shared_ptr data) 9 | { 10 | auto ret = DUPL_RETURN::DUPL_RETURN_SUCCESS; 11 | Data = data; 12 | SLScreen_Capture_InitMouseCapture(); 13 | return ret; 14 | } 15 | // 16 | // Process a given frame and its metadata 17 | // 18 | 19 | DUPL_RETURN NSMouseProcessor::ProcessFrame() 20 | { 21 | auto Ret = DUPL_RETURN_SUCCESS; 22 | 23 | if (Data->ScreenCaptureData.OnMouseChanged || Data->WindowCaptureData.OnMouseChanged) { 24 | auto mouseev = CGEventCreate(NULL); 25 | auto loc = CGEventGetLocation(mouseev); 26 | CFRelease(mouseev); 27 | 28 | auto imageRef = SLScreen_Capture_GetCurrentMouseImage(); 29 | 30 | if (imageRef.Image == NULL) 31 | return Ret; 32 | auto width = CGImageGetWidth(imageRef.Image); 33 | auto height = CGImageGetHeight(imageRef.Image); 34 | 35 | auto prov = CGImageGetDataProvider(imageRef.Image); 36 | auto bytesperrow = CGImageGetBytesPerRow(imageRef.Image); 37 | auto rawdatas = CGDataProviderCopyData(prov); 38 | auto buf = CFDataGetBytePtr(rawdatas); 39 | auto datalen = CFDataGetLength(rawdatas); 40 | if (datalen > ImageBufferSize || !ImageBuffer || !NewImageBuffer) { 41 | NewImageBuffer = std::make_unique(datalen); 42 | ImageBuffer = std::make_unique(datalen); 43 | ImageBufferSize = datalen; 44 | } 45 | 46 | memcpy(NewImageBuffer.get(), buf, datalen); 47 | CFRelease(rawdatas); 48 | 49 | // this is not needed. It is freed when the image is released 50 | // CGDataProviderRelease(prov); 51 | 52 | CGImageRelease(imageRef.Image); 53 | 54 | ImageRect imgrect; 55 | imgrect.left = imgrect.top = 0; 56 | imgrect.right = width; 57 | imgrect.bottom = height; 58 | auto wholeimgfirst = CreateImage(imgrect, bytesperrow, reinterpret_cast(NewImageBuffer.get())); 59 | 60 | auto lastx = static_cast(loc.x); 61 | auto lasty = static_cast(loc.y); 62 | 63 | MousePoint mousepoint = {}; 64 | mousepoint.Position = Point{lastx, lasty}; 65 | mousepoint.HotSpot = Point{imageRef.HotSpotx, imageRef.HotSpoty}; 66 | 67 | // if the mouse image is different, send the new image and swap the data 68 | 69 | if (memcmp(NewImageBuffer.get(), ImageBuffer.get(), datalen) != 0) { 70 | if (Data->ScreenCaptureData.OnMouseChanged) { 71 | Data->ScreenCaptureData.OnMouseChanged(&wholeimgfirst, mousepoint); 72 | } 73 | if (Data->WindowCaptureData.OnMouseChanged) { 74 | Data->WindowCaptureData.OnMouseChanged(&wholeimgfirst, mousepoint); 75 | } 76 | std::swap(NewImageBuffer, ImageBuffer); 77 | } 78 | else if (Last_x != lastx || Last_y != lasty) { 79 | if (Data->ScreenCaptureData.OnMouseChanged) { 80 | Data->ScreenCaptureData.OnMouseChanged(nullptr, mousepoint); 81 | } 82 | if (Data->WindowCaptureData.OnMouseChanged) { 83 | Data->WindowCaptureData.OnMouseChanged(nullptr, mousepoint); 84 | } 85 | } 86 | Last_x = lastx; 87 | Last_y = lasty; 88 | } 89 | return Ret; 90 | } 91 | 92 | } // namespace Screen_Capture 93 | } // namespace SL 94 | -------------------------------------------------------------------------------- /src_cpp/ios/ThreadRunner.cpp: -------------------------------------------------------------------------------- 1 | #include "ScreenCapture.h" 2 | #include "internal/ThreadManager.h" 3 | #include "CGFrameProcessor.h" 4 | #include "NSMouseProcessor.h" 5 | #include "NSFrameProcessor.h" 6 | 7 | namespace SL{ 8 | namespace Screen_Capture{ 9 | void RunCaptureMouse(std::shared_ptr data) { 10 | TryCaptureMouse(data); 11 | } 12 | void RunCaptureMonitor(std::shared_ptr data, Monitor monitor){ 13 | TryCaptureMonitor(data, monitor); 14 | } 15 | void RunCaptureWindow(std::shared_ptr data, Window window){ 16 | TryCaptureWindow(data, window); 17 | } 18 | } 19 | } 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src_cpp/linux/GetMonitors.cpp: -------------------------------------------------------------------------------- 1 | #include "ScreenCapture.h" 2 | #include "internal/SCCommon.h" 3 | #include 4 | #include 5 | #include 6 | 7 | namespace SL 8 | { 9 | namespace Screen_Capture 10 | { 11 | 12 | std::vector GetMonitors() 13 | { 14 | std::vector ret; 15 | 16 | Display* display = XOpenDisplay(NULL); 17 | if(display==NULL){ 18 | return ret; 19 | } 20 | int nmonitors = 0; 21 | XineramaScreenInfo* screen = XineramaQueryScreens(display, &nmonitors); 22 | if(screen==NULL){ 23 | XCloseDisplay(display); 24 | return ret; 25 | } 26 | ret.reserve(nmonitors); 27 | 28 | for(auto i = 0; i < nmonitors; i++) { 29 | 30 | auto name = std::string("Display ") + std::to_string(i); 31 | ret.push_back(CreateMonitor( 32 | i, screen[i].screen_number, screen[i].height, screen[i].width, screen[i].x_org, screen[i].y_org, name, 1.0f)); 33 | } 34 | XFree(screen); 35 | XCloseDisplay(display); 36 | return ret; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src_cpp/linux/GetWindows.cpp: -------------------------------------------------------------------------------- 1 | #include "ScreenCapture.h" 2 | #include "internal/SCCommon.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | namespace { 12 | class UniqueTextProperty { 13 | public: 14 | UniqueTextProperty() 15 | { 16 | p.value = nullptr; 17 | } 18 | 19 | UniqueTextProperty(const UniqueTextProperty&) = delete; 20 | UniqueTextProperty& operator=(const UniqueTextProperty&) = delete; 21 | 22 | UniqueTextProperty(UniqueTextProperty&& other): 23 | p{other.p} 24 | { 25 | other.p = XTextProperty{}; 26 | } 27 | 28 | UniqueTextProperty& operator=(UniqueTextProperty&& other) 29 | { 30 | swap(*this, other); 31 | return *this; 32 | } 33 | 34 | friend void swap(UniqueTextProperty& lhs, UniqueTextProperty& rhs) { 35 | using std::swap; 36 | swap(lhs.p, rhs.p); 37 | } 38 | 39 | ~UniqueTextProperty() 40 | { 41 | if (p.value) { 42 | XFree(p.value); 43 | } 44 | } 45 | 46 | auto& get() { 47 | return p; 48 | } 49 | 50 | private: 51 | XTextProperty p; 52 | }; 53 | 54 | auto GetWMName(Display* display, Window window) 55 | { 56 | auto x = UniqueTextProperty{}; 57 | XGetWMName(display, window, &x.get()); 58 | return x; 59 | } 60 | 61 | auto TextPropertyToStrings( 62 | Display* dpy, 63 | const XTextProperty& prop 64 | ) 65 | { 66 | char **list; 67 | auto n_strings = 0; 68 | auto result = std::vector{}; 69 | 70 | auto status = XmbTextPropertyToTextList( 71 | dpy, 72 | &prop, 73 | &list, 74 | &n_strings 75 | ); 76 | 77 | if (status < Success or not n_strings or not *list) { 78 | return result; 79 | } 80 | 81 | for (auto i = 0; i < n_strings; ++i) { 82 | result.emplace_back(list[i]); 83 | } 84 | 85 | XFreeStringList(list); 86 | 87 | return result; 88 | } 89 | } 90 | 91 | namespace SL 92 | { 93 | namespace Screen_Capture 94 | { 95 | 96 | void AddWindow(Display* display, XID& window, std::vector& wnd) 97 | { 98 | using namespace std::string_literals; 99 | 100 | auto wm_name = GetWMName(display, window); 101 | auto candidates = TextPropertyToStrings(display, wm_name.get()); 102 | Window w = {}; 103 | w.Handle = static_cast( (size_t) window); 104 | 105 | XWindowAttributes wndattr; 106 | XGetWindowAttributes(display, window, &wndattr); 107 | 108 | w.Position = Point{ wndattr.x, wndattr.y }; 109 | w.Size = Point{ wndattr.width, wndattr.height }; 110 | 111 | auto name = candidates.empty() ? std::string() : std::move(candidates.front()); 112 | if (name.size() > sizeof(w.Name) - 1) { 113 | name.resize(sizeof(w.Name) - 1); 114 | } 115 | std::transform(name.begin(), name.end(), std::begin(w.Name), ::tolower); 116 | wnd.push_back(w); 117 | } 118 | 119 | std::vector GetWindows() 120 | { 121 | auto* display = XOpenDisplay(NULL); 122 | Atom a = XInternAtom(display, "_NET_CLIENT_LIST", true); 123 | Atom actualType; 124 | int format; 125 | unsigned long numItems, bytesAfter; 126 | unsigned char* data = 0; 127 | int status = XGetWindowProperty(display, 128 | XDefaultRootWindow(display), 129 | a, 130 | 0L, 131 | (~0L), 132 | false, 133 | AnyPropertyType, 134 | &actualType, 135 | &format, 136 | &numItems, 137 | &bytesAfter, 138 | &data); 139 | std::vector ret; 140 | if(status >= Success && numItems) { 141 | auto array = (XID*)data; 142 | for(decltype(numItems) k = 0; k < numItems; k++) { 143 | auto w = array[k]; 144 | AddWindow(display, w, ret); 145 | } 146 | XFree(data); 147 | } 148 | XCloseDisplay(display); 149 | return ret; 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /src_cpp/linux/ThreadRunner.cpp: -------------------------------------------------------------------------------- 1 | #include "ScreenCapture.h" 2 | #include "X11FrameProcessor.h" 3 | #include "X11MouseProcessor.h" 4 | #include "internal/ThreadManager.h" 5 | 6 | namespace SL { 7 | namespace Screen_Capture { 8 | void RunCaptureMouse(std::shared_ptr data) { TryCaptureMouse(data); } 9 | void RunCaptureMonitor(std::shared_ptr data, Monitor monitor) { TryCaptureMonitor(data, monitor); } 10 | void RunCaptureWindow(std::shared_ptr data, Window window) { TryCaptureWindow(data, window); } 11 | bool IsScreenCaptureEnabled() { return true; }/// need someone to implement this 12 | void RequestScreenCapture() {} 13 | bool CanRequestScreenCapture() { return false; } 14 | } // namespace Screen_Capture 15 | } // namespace SL 16 | -------------------------------------------------------------------------------- /src_cpp/linux/X11FrameProcessor.cpp: -------------------------------------------------------------------------------- 1 | #include "X11FrameProcessor.h" 2 | #include 3 | #include 4 | #include 5 | 6 | namespace SL 7 | { 8 | namespace Screen_Capture 9 | { 10 | X11FrameProcessor::X11FrameProcessor() 11 | { 12 | } 13 | 14 | X11FrameProcessor::~X11FrameProcessor() 15 | { 16 | if(ShmInfo) { 17 | shmdt(ShmInfo->shmaddr); 18 | shmctl(ShmInfo->shmid, IPC_RMID, 0); 19 | XShmDetach(SelectedDisplay, ShmInfo.get()); 20 | } 21 | if(XImage_) { 22 | XDestroyImage(XImage_); 23 | } 24 | if(SelectedDisplay) { 25 | XCloseDisplay(SelectedDisplay); 26 | } 27 | } 28 | 29 | DUPL_RETURN X11FrameProcessor::Init(std::shared_ptr data, const Window& selectedwindow){ 30 | 31 | auto ret = DUPL_RETURN::DUPL_RETURN_SUCCESS; 32 | Data = data; 33 | SelectedDisplay = XOpenDisplay(NULL); 34 | SelectedWindow = selectedwindow.Handle; 35 | if(!SelectedDisplay) { 36 | return DUPL_RETURN::DUPL_RETURN_ERROR_EXPECTED; 37 | } 38 | int scr = XDefaultScreen(SelectedDisplay); 39 | 40 | ShmInfo = std::make_unique(); 41 | 42 | XImage_ = XShmCreateImage(SelectedDisplay, 43 | DefaultVisual(SelectedDisplay, scr), 44 | DefaultDepth(SelectedDisplay, scr), 45 | ZPixmap, 46 | NULL, 47 | ShmInfo.get(), 48 | selectedwindow.Size.x, 49 | selectedwindow.Size.y); 50 | ShmInfo->shmid = shmget(IPC_PRIVATE, XImage_->bytes_per_line * XImage_->height, IPC_CREAT | 0777); 51 | 52 | ShmInfo->readOnly = False; 53 | ShmInfo->shmaddr = XImage_->data = (char*)shmat(ShmInfo->shmid, 0, 0); 54 | 55 | XShmAttach(SelectedDisplay, ShmInfo.get()); 56 | 57 | return ret; 58 | } 59 | DUPL_RETURN X11FrameProcessor::Init(std::shared_ptr data, Monitor& monitor) 60 | { 61 | auto ret = DUPL_RETURN::DUPL_RETURN_SUCCESS; 62 | Data = data; 63 | SelectedMonitor = monitor; 64 | SelectedDisplay = XOpenDisplay(NULL); 65 | if(!SelectedDisplay) { 66 | return DUPL_RETURN::DUPL_RETURN_ERROR_EXPECTED; 67 | } 68 | int scr = XDefaultScreen(SelectedDisplay); 69 | 70 | ShmInfo = std::make_unique(); 71 | 72 | XImage_ = XShmCreateImage(SelectedDisplay, 73 | DefaultVisual(SelectedDisplay, scr), 74 | DefaultDepth(SelectedDisplay, scr), 75 | ZPixmap, 76 | NULL, 77 | ShmInfo.get(), 78 | Width(SelectedMonitor), 79 | Height(SelectedMonitor)); 80 | ShmInfo->shmid = shmget(IPC_PRIVATE, XImage_->bytes_per_line * XImage_->height, IPC_CREAT | 0777); 81 | 82 | ShmInfo->readOnly = False; 83 | ShmInfo->shmaddr = XImage_->data = (char*)shmat(ShmInfo->shmid, 0, 0); 84 | 85 | XShmAttach(SelectedDisplay, ShmInfo.get()); 86 | 87 | return ret; 88 | } 89 | 90 | DUPL_RETURN X11FrameProcessor::ProcessFrame(const Monitor& curentmonitorinfo) 91 | { 92 | auto Ret = DUPL_RETURN_SUCCESS; 93 | if(!XShmGetImage(SelectedDisplay, 94 | RootWindow(SelectedDisplay, DefaultScreen(SelectedDisplay)), 95 | XImage_, 96 | OffsetX(SelectedMonitor), 97 | OffsetY(SelectedMonitor), 98 | AllPlanes)) { 99 | return DUPL_RETURN_ERROR_EXPECTED; 100 | } 101 | ProcessCapture(Data->ScreenCaptureData, *this, SelectedMonitor, (unsigned char*)XImage_->data, XImage_->bytes_per_line); 102 | return Ret; 103 | } 104 | DUPL_RETURN X11FrameProcessor::ProcessFrame(Window& selectedwindow){ 105 | 106 | auto Ret = DUPL_RETURN_SUCCESS; 107 | XWindowAttributes wndattr; 108 | if(XGetWindowAttributes(SelectedDisplay, SelectedWindow, &wndattr) ==0){ 109 | return DUPL_RETURN::DUPL_RETURN_ERROR_EXPECTED;//window might not be valid any more 110 | } 111 | if(wndattr.width != Width(selectedwindow) || wndattr.height != Height(selectedwindow)){ 112 | return DUPL_RETURN::DUPL_RETURN_ERROR_EXPECTED;//window size changed. This will rebuild everything 113 | } 114 | if(!XShmGetImage(SelectedDisplay, 115 | selectedwindow.Handle, 116 | XImage_, 117 | 0, 118 | 0, 119 | AllPlanes)) { 120 | return DUPL_RETURN_ERROR_EXPECTED; 121 | } 122 | ProcessCapture(Data->WindowCaptureData, *this, selectedwindow, (unsigned char*)XImage_->data, XImage_->bytes_per_line); 123 | return Ret; 124 | } 125 | } 126 | } -------------------------------------------------------------------------------- /src_cpp/linux/X11MouseProcessor.cpp: -------------------------------------------------------------------------------- 1 | #include "X11MouseProcessor.h" 2 | 3 | #include 4 | #include 5 | 6 | namespace SL { 7 | namespace Screen_Capture { 8 | 9 | X11MouseProcessor::X11MouseProcessor() {} 10 | 11 | X11MouseProcessor::~X11MouseProcessor() 12 | { 13 | if (SelectedDisplay) { 14 | XCloseDisplay(SelectedDisplay); 15 | } 16 | } 17 | DUPL_RETURN X11MouseProcessor::Init(std::shared_ptr data) 18 | { 19 | auto ret = DUPL_RETURN::DUPL_RETURN_SUCCESS; 20 | Data = data; 21 | SelectedDisplay = XOpenDisplay(NULL); 22 | if (!SelectedDisplay) { 23 | return DUPL_RETURN::DUPL_RETURN_ERROR_EXPECTED; 24 | } 25 | RootWindow = DefaultRootWindow(SelectedDisplay); 26 | if (!RootWindow) { 27 | return DUPL_RETURN::DUPL_RETURN_ERROR_EXPECTED; 28 | } 29 | return ret; 30 | } 31 | // 32 | // Process a given frame and its metadata 33 | // 34 | DUPL_RETURN X11MouseProcessor::ProcessFrame() 35 | { 36 | auto Ret = DUPL_RETURN_SUCCESS; 37 | if (Data->ScreenCaptureData.OnMouseChanged || Data->WindowCaptureData.OnMouseChanged) { 38 | auto img = XFixesGetCursorImage(SelectedDisplay); 39 | 40 | if (sizeof(img->pixels[0]) == 8) { // if the pixelstride is 64 bits.. scale down to 32bits 41 | auto pixels = (int *)img->pixels; 42 | for (auto i = 0; i < img->width * img->height; ++i) { 43 | pixels[i] = pixels[i * 2]; 44 | } 45 | } 46 | ImageRect imgrect; 47 | imgrect.left = imgrect.top = 0; 48 | imgrect.right = img->width; 49 | imgrect.bottom = img->height; 50 | auto newsize = sizeof(ImageBGRA) * imgrect.right * imgrect.bottom; 51 | if (static_cast(newsize) > ImageBufferSize || !ImageBuffer || !NewImageBuffer) { 52 | NewImageBuffer = std::make_unique(newsize); 53 | ImageBuffer = std::make_unique(newsize); 54 | ImageBufferSize = newsize; 55 | } 56 | 57 | memcpy(ImageBuffer.get(), img->pixels, newsize); 58 | 59 | // Get the mouse cursor position 60 | int x, y, root_x, root_y = 0; 61 | unsigned int mask = 0; 62 | XID child_win, root_win; 63 | XQueryPointer(SelectedDisplay, RootWindow, &child_win, &root_win, &root_x, &root_y, &x, &y, &mask); 64 | 65 | XFree(img); 66 | 67 | MousePoint mousepoint = {}; 68 | mousepoint.Position = Point{x, y}; 69 | mousepoint.HotSpot = Point{static_cast(img->xhot), static_cast(img->yhot)}; 70 | 71 | auto wholeimg = CreateImage(imgrect, imgrect.right * sizeof(ImageBGRA), reinterpret_cast(ImageBuffer.get())); 72 | // if the mouse image is different, send the new image and swap the data 73 | if (memcmp(ImageBuffer.get(), NewImageBuffer.get(), newsize) != 0) { 74 | if (Data->ScreenCaptureData.OnMouseChanged) { 75 | Data->ScreenCaptureData.OnMouseChanged(&wholeimg, mousepoint); 76 | } 77 | if (Data->WindowCaptureData.OnMouseChanged) { 78 | Data->WindowCaptureData.OnMouseChanged(&wholeimg, mousepoint); 79 | } 80 | std::swap(ImageBuffer, NewImageBuffer); 81 | } 82 | else if (Last_x != x || Last_y != y) { 83 | if (Data->ScreenCaptureData.OnMouseChanged) { 84 | Data->ScreenCaptureData.OnMouseChanged(nullptr, mousepoint); 85 | } 86 | if (Data->WindowCaptureData.OnMouseChanged) { 87 | Data->WindowCaptureData.OnMouseChanged(nullptr, mousepoint); 88 | } 89 | } 90 | Last_x = x; 91 | Last_y = y; 92 | } 93 | return Ret; 94 | } 95 | 96 | } // namespace Screen_Capture 97 | } // namespace SL -------------------------------------------------------------------------------- /src_cpp/windows/GetMonitors.cpp: -------------------------------------------------------------------------------- 1 | #include "ScreenCapture.h" 2 | #include "internal/SCCommon.h" 3 | #include 4 | 5 | namespace SL { 6 | namespace Screen_Capture { 7 | 8 | float scaleFromDpi(int xdpi) 9 | { 10 | switch (xdpi) { 11 | case 96: 12 | return 1.0f; 13 | break; 14 | case 120: 15 | return 1.25f; 16 | break; 17 | case 144: 18 | return 1.5f; 19 | break; 20 | case 192: 21 | return 2.0f; 22 | break; 23 | } 24 | 25 | return 1.0f; 26 | } 27 | 28 | std::vector GetMonitors() 29 | { 30 | std::vector ret; 31 | 32 | IDXGIAdapter *pAdapter = nullptr; 33 | IDXGIFactory *pFactory = nullptr; 34 | 35 | // Create a DXGIFactory object. 36 | if (SUCCEEDED(CreateDXGIFactory(__uuidof(IDXGIFactory), (void **)&pFactory))) { 37 | for (UINT i = 0; pFactory->EnumAdapters(i, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++i) { 38 | IDXGIOutput *pOutput; 39 | 40 | for (UINT j = 0; pAdapter->EnumOutputs(j, &pOutput) != DXGI_ERROR_NOT_FOUND; ++j) { 41 | DXGI_OUTPUT_DESC desc; 42 | pOutput->GetDesc(&desc); 43 | pOutput->Release(); 44 | std::wstring wname = desc.DeviceName; 45 | auto size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, &wname[0], static_cast(wname.size()), NULL, 0, NULL, NULL); 46 | std::string name = std::string(size, 0); 47 | WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, &wname[0], static_cast(wname.size()), &name[0], static_cast(size), NULL, NULL); 48 | if (name.size() > static_cast(sizeof(Monitor::Name))) { 49 | name.resize(sizeof(Monitor::Name)); 50 | } 51 | DEVMODEW devMode = {}; 52 | EnumDisplaySettingsW(desc.DeviceName, ENUM_CURRENT_SETTINGS, &devMode); 53 | 54 | auto mon = CreateDCW(desc.DeviceName, NULL, NULL, NULL); 55 | auto xdpi = GetDeviceCaps(mon, LOGPIXELSX); 56 | DeleteDC(mon); 57 | auto scale = scaleFromDpi(xdpi); 58 | 59 | bool flipSides = desc.Rotation == DXGI_MODE_ROTATION_ROTATE90 || desc.Rotation == DXGI_MODE_ROTATION_ROTATE270; 60 | ret.push_back(CreateMonitor(static_cast(ret.size()), j, i, flipSides ? devMode.dmPelsWidth : devMode.dmPelsHeight, 61 | flipSides ? devMode.dmPelsHeight : devMode.dmPelsWidth, devMode.dmPosition.x, devMode.dmPosition.y, 62 | name, scale)); 63 | } 64 | pAdapter->Release(); 65 | } 66 | pFactory->Release(); 67 | } 68 | return ret; 69 | } 70 | } // namespace Screen_Capture 71 | } // namespace SL -------------------------------------------------------------------------------- /src_cpp/windows/GetWindows.cpp: -------------------------------------------------------------------------------- 1 | #include "GDIHelpers.h" 2 | #include "ScreenCapture.h" 3 | #include "internal/SCCommon.h" 4 | #include 5 | 6 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 7 | #include 8 | 9 | namespace SL { 10 | namespace Screen_Capture { 11 | 12 | struct srch { 13 | std::vector Found; 14 | }; 15 | 16 | bool IsAltTabWindow(HWND hwnd) 17 | { 18 | HWND hwndTry, hwndWalk = NULL; 19 | if (!IsWindowVisible(hwnd)) 20 | return false; 21 | 22 | hwndTry = GetAncestor(hwnd, GA_ROOTOWNER); 23 | while (hwndTry != hwndWalk) { 24 | hwndWalk = hwndTry; 25 | hwndTry = GetLastActivePopup(hwndWalk); 26 | if (IsWindowVisible(hwndTry)) 27 | break; 28 | } 29 | if (hwndWalk != hwnd) 30 | return false; 31 | TITLEBARINFO ti; 32 | // the following removes some task tray programs and "Program Manager" 33 | ti.cbSize = sizeof(ti); 34 | GetTitleBarInfo(hwnd, &ti); 35 | if (ti.rgstate[0] & STATE_SYSTEM_INVISIBLE) 36 | return false; 37 | 38 | // Tool windows should not be displayed either, these do not appear in the 39 | // task bar. 40 | if (GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW) 41 | return false; 42 | 43 | return true; 44 | } 45 | BOOL CALLBACK EnumWindowsProc(_In_ HWND hwnd, _In_ LPARAM lParam) 46 | { 47 | if (!IsAltTabWindow(hwnd)) { 48 | return TRUE; 49 | } 50 | 51 | Window w = {}; 52 | 53 | DWORD pid; 54 | GetWindowThreadProcessId(hwnd, &pid); 55 | w.Name[0] = '\n'; 56 | // make sure 57 | if (pid != GetCurrentProcessId()) { 58 | GetWindowTextA(hwnd, w.Name, sizeof(w.Name)); 59 | } 60 | 61 | srch *s = (srch *)lParam; 62 | w.Handle = reinterpret_cast(hwnd); 63 | auto windowrect = SL::Screen_Capture::GetWindowRect(hwnd); 64 | w.Position.x = windowrect.ClientRect.left; 65 | w.Position.y = windowrect.ClientRect.top; 66 | w.Size.x = windowrect.ClientRect.right - windowrect.ClientRect.left; 67 | w.Size.y = windowrect.ClientRect.bottom - windowrect.ClientRect.top; 68 | std::transform(std::begin(w.Name), std::end(w.Name), std::begin(w.Name), [](char c) { return static_cast(std::tolower(c)); }); 69 | s->Found.push_back(w); 70 | return TRUE; 71 | } 72 | 73 | std::vector GetWindows() 74 | { 75 | srch s; 76 | EnumWindows(EnumWindowsProc, (LPARAM)&s); 77 | return s.Found; 78 | } 79 | 80 | } // namespace Screen_Capture 81 | } // namespace SL 82 | -------------------------------------------------------------------------------- /src_cpp/windows/ThreadRunner.cpp: -------------------------------------------------------------------------------- 1 | #include "DXFrameProcessor.h" 2 | #include "GDIFrameProcessor.h" 3 | #include "GDIMouseProcessor.h" 4 | #include "ScreenCapture.h" 5 | #include "internal/ThreadManager.h" 6 | 7 | #define WIN32_LEAN_AND_MEAN 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace SL { 15 | namespace Screen_Capture { 16 | 17 | template void ProcessExit(DUPL_RETURN Ret, T *TData) 18 | { 19 | if (Ret != DUPL_RETURN_SUCCESS) { 20 | if (Ret == DUPL_RETURN_ERROR_EXPECTED) { 21 | // The system is in a transition state so request the duplication be restarted 22 | TData->CommonData_.ExpectedErrorEvent = true; 23 | } 24 | else { 25 | // Unexpected error so exit the application 26 | TData->CommonData_.UnexpectedErrorEvent = true; 27 | } 28 | } 29 | } 30 | 31 | void RequestScreenCapture() {} 32 | bool CanRequestScreenCapture() { return false; } 33 | 34 | bool IsScreenCaptureEnabled() 35 | { 36 | HDESK CurrentDesktop = nullptr; 37 | CurrentDesktop = OpenInputDesktop(0, FALSE, GENERIC_ALL); 38 | if (!CurrentDesktop) { 39 | // We do not have access to the desktop so request a retry 40 | return false; 41 | } 42 | 43 | // Attach desktop to this thread 44 | bool DesktopAttached = SetThreadDesktop(CurrentDesktop) != 0; 45 | CloseDesktop(CurrentDesktop); 46 | CurrentDesktop = nullptr; 47 | if (!DesktopAttached) { 48 | // We do not have access to the desktop so request a retry 49 | return false; 50 | } 51 | return true; 52 | } 53 | template bool SwitchToInputDesktop(const std::shared_ptr data) 54 | { 55 | HDESK CurrentDesktop = nullptr; 56 | CurrentDesktop = OpenInputDesktop(0, FALSE, GENERIC_ALL); 57 | if (!CurrentDesktop) { 58 | // We do not have access to the desktop so request a retry 59 | data->CommonData_.ExpectedErrorEvent = true; 60 | ProcessExit(DUPL_RETURN::DUPL_RETURN_ERROR_EXPECTED, data.get()); 61 | return false; 62 | } 63 | 64 | // Attach desktop to this thread 65 | bool DesktopAttached = SetThreadDesktop(CurrentDesktop) != 0; 66 | CloseDesktop(CurrentDesktop); 67 | CurrentDesktop = nullptr; 68 | if (!DesktopAttached) { 69 | // We do not have access to the desktop so request a retry 70 | data->CommonData_.ExpectedErrorEvent = true; 71 | ProcessExit(DUPL_RETURN::DUPL_RETURN_ERROR_EXPECTED, data.get()); 72 | return false; 73 | } 74 | return true; 75 | } 76 | void RunCaptureMouse(std::shared_ptr data) 77 | { 78 | if (!SwitchToInputDesktop(data)) 79 | return; 80 | TryCaptureMouse(data); 81 | } 82 | void RunCaptureMonitor(std::shared_ptr data, Monitor monitor) 83 | { 84 | // need to switch to the input desktop for capturing... 85 | if (!SwitchToInputDesktop(data)) 86 | return; 87 | #if defined _DEBUG || !defined NDEBUG 88 | std::cout << "Starting to Capture on Monitor " << Name(monitor) << std::endl; 89 | std::cout << "Trying DirectX Desktop Duplication " << std::endl; 90 | #endif 91 | if (!TryCaptureMonitor(data, monitor)) { // if DX is not supported, fallback to GDI capture 92 | #if defined _DEBUG || !defined NDEBUG 93 | std::cout << "DirectX Desktop Duplication not supported, falling back to GDI Capturing . . ." << std::endl; 94 | #endif 95 | TryCaptureMonitor(data, monitor); 96 | } 97 | } 98 | 99 | void RunCaptureWindow(std::shared_ptr data, Window wnd) 100 | { 101 | // need to switch to the input desktop for capturing... 102 | if (!SwitchToInputDesktop(data)) 103 | return; 104 | TryCaptureWindow(data, wnd); 105 | } 106 | } // namespace Screen_Capture 107 | } // namespace SL 108 | -------------------------------------------------------------------------------- /src_csharp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(screen_capture_lite_csharp) 2 | 3 | set(OUTPUT ${PROJECT_NAME}.dll) 4 | set(CSPROJ ${PROJECT_NAME}.csproj) 5 | 6 | execute_process(COMMAND dotnet --version 7 | RESULT_VARIABLE result 8 | OUTPUT_QUIET 9 | ERROR_QUIET) 10 | if(result) 11 | message(STATUS "dotnet executable not found but by this build, if you want to build CSharp Bindings, you must install dotnet") 12 | else() 13 | set(PLATFORM x64) 14 | if(NOT DEFINED CMAKE_GENERATOR_PLATFORM) 15 | set(PLATFORM x64) 16 | elseif("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Win32") 17 | set(PLATFORM x86) 18 | ENDIF() 19 | 20 | message(STATUS "Found dotnet executable CSHARP bindings will be generated!") 21 | add_custom_command(OUTPUT ${OUTPUT} 22 | COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_LIST_DIR} 23 | COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_BINARY_DIR}/src_csharp 24 | COMMAND ${CMAKE_COMMAND} -E copy 25 | ${CMAKE_CURRENT_LIST_DIR}/${CSPROJ} 26 | ${CMAKE_BINARY_DIR}/src_csharp 27 | COMMAND ${CMAKE_COMMAND} -E copy 28 | ${CMAKE_CURRENT_LIST_DIR}/MonitorCaptureConfiguration.cs 29 | ${CMAKE_CURRENT_LIST_DIR}/NativeFunctions.cs 30 | ${CMAKE_CURRENT_LIST_DIR}/NativeTypes.cs 31 | ${CMAKE_CURRENT_LIST_DIR}/ScreenCaptureManager.cs 32 | ${CMAKE_CURRENT_LIST_DIR}/UnmanagedUtility.cs 33 | ${CMAKE_CURRENT_LIST_DIR}/WindowCaptureConfiguration.cs 34 | ${CMAKE_BINARY_DIR}/src_csharp 35 | COMMAND dotnet build --configuration ${CMAKE_BUILD_TYPE} /p:Platform=${PLATFORM} ${CMAKE_BINARY_DIR}/src_csharp/${CSPROJ} -o ${CMAKE_BINARY_DIR} 36 | COMMENT "Building ${PROJECT_NAME} dotnet build --configuration ${CMAKE_BUILD_TYPE} /p:Platform=${PLATFORM} ${CMAKE_BINARY_DIR}/src_csharp/${CSPROJ} -o ${CMAKE_BINARY_DIR}" 37 | ) 38 | 39 | add_custom_target(${PROJECT_NAME} ALL DEPENDS ${OUTPUT}) 40 | add_dependencies(${PROJECT_NAME} screen_capture_lite_${TARGET_SUFFIX}) 41 | 42 | install (FILES ${CMAKE_BINARY_DIR}/${OUTPUT} 43 | DESTINATION bin 44 | ) 45 | install (FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pdb 46 | DESTINATION bin 47 | OPTIONAL 48 | ) 49 | 50 | endif() 51 | -------------------------------------------------------------------------------- /src_csharp/NativeTypes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SCL 5 | { 6 | 7 | [StructLayout(LayoutKind.Sequential)] 8 | public class Point 9 | { 10 | public int x; 11 | public int y; 12 | } 13 | 14 | [StructLayout(LayoutKind.Sequential)] 15 | public class MousePoint 16 | { 17 | public Point Position; 18 | public Point HotSpot; 19 | }; 20 | 21 | [StructLayout(LayoutKind.Sequential)] 22 | public class Window 23 | { 24 | public IntPtr Handle; 25 | public Point Position; 26 | public Point Size; 27 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] 28 | public string Name; 29 | } 30 | 31 | [StructLayout(LayoutKind.Sequential)] 32 | public class Monitor 33 | { 34 | public int Id; 35 | public int Index; 36 | public int Adapter; 37 | public int Height; 38 | public int Width; 39 | public int OriginalHeight; 40 | public int OriginalWidth; 41 | // Offsets are the number of pixels that a monitor can be from the origin. For example, users can shuffle their 42 | // monitors around so this affects their offset. 43 | public int OffsetX; 44 | public int OffsetY; 45 | public int OriginalOffsetX; 46 | public int OriginalOffsetY; 47 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] 48 | public string Name; 49 | public float Scaling; 50 | } 51 | 52 | [StructLayout(LayoutKind.Sequential)] 53 | public class ImageRect 54 | { 55 | public int left; 56 | public int top; 57 | public int right; 58 | public int bottom; 59 | } 60 | 61 | [StructLayout(LayoutKind.Sequential)] 62 | public class Image 63 | { 64 | public ImageRect Bounds; 65 | public int BytesToNextRow; 66 | [MarshalAs(UnmanagedType.I1)] 67 | public bool isContiguous; 68 | // alpha is always unused and might contain garbage 69 | public IntPtr Data; 70 | } 71 | 72 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 73 | public delegate Window[] WindowCallback(); 74 | 75 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 76 | public delegate Monitor[] MonitorCallback(); 77 | 78 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 79 | public delegate void MouseCaptureCallback(IntPtr img, IntPtr mousePoint); 80 | 81 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 82 | public delegate void MouseCaptureCallbackWithContext(IntPtr intPtr, IntPtr mousePoint, IntPtr context); 83 | 84 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 85 | public delegate void ScreenCaptureCallback(IntPtr img, IntPtr monitor); 86 | 87 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 88 | public delegate void ScreenCaptureCallbackWithContext(IntPtr img, IntPtr monitor, IntPtr context); 89 | 90 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 91 | public delegate void WindowCaptureCallback(IntPtr img, IntPtr window); 92 | 93 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 94 | public delegate void WindowCaptureCallbackWithContext(IntPtr img, IntPtr window, IntPtr context); 95 | 96 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 97 | public delegate int BufferCallback(IntPtr buffer, int buffersize); 98 | 99 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 100 | public delegate int MonitorWindowCallbackWithContext(IntPtr buffer, int buffersize, IntPtr context); 101 | 102 | 103 | } -------------------------------------------------------------------------------- /src_csharp/ScreenCaptureManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SCL 4 | { 5 | public class ScreenCaptureManager : IDisposable 6 | { 7 | 8 | public IntPtr Session { get; private set; } 9 | 10 | private IDisposable _configuration; 11 | 12 | private bool disposedValue = false; 13 | 14 | public bool IsPaused 15 | { 16 | get => NativeFunctions.SCL_IsPaused(Session) != 0; 17 | set 18 | { 19 | if (value) 20 | { 21 | NativeFunctions.SCL_PauseCapturing(Session); 22 | } 23 | else 24 | { 25 | NativeFunctions.SCL_Resume(Session); 26 | } 27 | } 28 | } 29 | 30 | public ScreenCaptureManager(WindowCaptureConfiguration config) 31 | { 32 | _configuration = config; 33 | Session = NativeFunctions.SCL_WindowStartCapturing(config.Config); 34 | } 35 | 36 | public ScreenCaptureManager(MonitorCaptureConfiguration config) 37 | { 38 | _configuration = config; 39 | Session = NativeFunctions.SCL_MonitorStartCapturing(config.Config); 40 | } 41 | 42 | 43 | public ScreenCaptureManager SetFrameChangeInterval(int milliseconds) 44 | { 45 | NativeFunctions.SCL_SetFrameChangeInterval(Session, milliseconds); 46 | return this; 47 | } 48 | 49 | public ScreenCaptureManager SetMouseChangeInterval(int milliseconds) 50 | { 51 | NativeFunctions.SCL_SetMouseChangeInterval(Session, milliseconds); 52 | return this; 53 | } 54 | 55 | public ScreenCaptureManager PauseCapturing() 56 | { 57 | NativeFunctions.SCL_PauseCapturing(Session); 58 | return this; 59 | } 60 | 61 | protected virtual void Dispose(bool disposing) 62 | { 63 | if (!disposedValue) 64 | { 65 | 66 | if (Session != IntPtr.Zero) NativeFunctions.SCL_FreeIScreenCaptureManagerWrapper(Session); 67 | Session = IntPtr.Zero; 68 | 69 | if (disposing) 70 | { 71 | _configuration?.Dispose(); 72 | _configuration = null; 73 | } 74 | 75 | disposedValue = true; 76 | } 77 | } 78 | 79 | // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources 80 | ~ScreenCaptureManager() 81 | { 82 | // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method 83 | Dispose(disposing: false); 84 | } 85 | 86 | public void Dispose() 87 | { 88 | // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method 89 | Dispose(disposing: true); 90 | GC.SuppressFinalize(this); 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /src_csharp/screen_capture_lite_csharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | 6 | 7 | 8 | true 9 | 10 | 11 | 12 | --------------------------------------------------------------------------------