go-gl/glfw

GitHub: go-gl/glfw

为 Go 语言提供 GLFW 3 的完整绑定,使开发者能够在 Go 中便捷地创建窗口、管理渲染上下文和处理输入事件来构建图形应用。

Stars: 1689 | Forks: 193

[![测试](https://static.pigsec.cn/wp-content/uploads/repos/cas/09/097271ca091990be630ef6043309cc48240faa054413384202036fa2efedb2d2.svg)](https://github.com/go-gl/glfw/actions/workflows/tests.yml) [![静态分析](https://static.pigsec.cn/wp-content/uploads/repos/cas/9b/9b6dce43bb5af915a23a678b9d8aec909e6750b41507e6923c4ad9f366d280b9.svg)](https://github.com/go-gl/glfw/actions/workflows/analysis.yml) [![GoDoc](https://godoc.org/github.com/go-gl/glfw/v3.4/glfw?status.svg)](https://godoc.org/github.com/go-gl/glfw/v3.4/glfw) # 适用于 Go 的 GLFW 3.4 ## 安装 * GLFW C 库源码已包含在内,并作为 Go package 的一部分自动构建。但您需要确保已具备 GLFW 的相关依赖: * 在 macOS 上,您需要 Xcode 或 Xcode Command Line Tools (`xcode-select --install`) 以获取所需的头文件和库。 * 在类似 Ubuntu/Debian 的 Linux 发行版上,默认的 Linux 构建会同时启用 X11 和 Wayland,因此您需要 `libgl1-mesa-dev`、`xorg-dev`、`libwayland-dev`、`libxkbcommon-dev` 和 `wayland-protocols`。 * 在类似 CentOS/Fedora 的 Linux 发行版上,您需要 `libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel mesa-libGL-devel libXi-devel libXxf86vm-devel` 包。 * 在 FreeBSD 上,您需要 `pkgconf` 包。如果要在 X 环境下构建,还需要 `xorg` 包;如果要在 Wayland 环境下构建,则需要 `wayland` 包。 * 在 NetBSD 上,要在 X 环境下构建,您需要安装 X11 sets。所有图形化安装均已包含这些内容,非图形化系统可以通过 `sysinst(8)` 添加。由于上游 GLFW 缺少对 wscons 的支持,Wayland 的支持尚不完整。如果尝试在 Wayland 环境下构建,您需要安装 `wayland libepoll-shim` 包并设置环境变量 `PKG_CONFIG_PATH=/usr/pkg/libdata/pkgconfig`。 * 在 OpenBSD 上,您需要 X11 sets。它们默认已安装,并可以随时从 ramdisk kernel 中添加。 * 完整详情请参见[此处](http://www.glfw.org/docs/latest/compile.html#compile_deps)。 * Windows 上需要 Go 1.4+(否则您必须严格使用 MinGW v4.8.1,请参阅 [Go issue 8811](https://github.com/golang/go/issues/8811))。 ``` go get github.com/go-gl/glfw/v3.4/glfw ``` ### OpenGL ES 如果您的目标系统仅提供 OpenGL ES 实现(某些 ARM 板即是如此),您需要链接到该实现。 您可以通过定义相应的构建 tag 来完成此操作,例如: ``` go get -tags=gles2 github.com/go-gl/glfw/v3.4/glfw ``` 支持的 tag 包括 `gles1`、`gles2`、`gles3` 和 `vulkan`。 请注意,所需的包可能与上面列出的有所不同;请查阅您的硬件文档。 ## 用法 ``` package main import ( "runtime" "github.com/go-gl/glfw/v3.4/glfw" ) func init() { // This is needed to arrange that main() runs on main thread. // See documentation for functions that are only allowed to be called from the main thread. runtime.LockOSThread() } func main() { err := glfw.Init() if err != nil { panic(err) } defer glfw.Terminate() window, err := glfw.CreateWindow(640, 480, "Testing", nil, nil) if err != nil { panic(err) } window.MakeContextCurrent() for !window.ShouldClose() { // Do OpenGL stuff. window.SwapBuffers() glfw.PollEvents() } } ``` ## 更新日志 ### GLFW 3.4 特定更改 * 本节是 v3.4 分支的累积更新,包含多个 commit 的更改。 * 在 Linux 上添加了对 X11 和 Wayland 之间动态运行时切换的支持。 * 使用 `glfwGetPlatform()` 替换了编译时的 Wayland 图标检查。 * 映射了 `GLFW_FEATURE_UNAVAILABLE` 和 `GLFW_FEATURE_UNIMPLEMENTED`,以防止在不支持的平台上发生 Go panic。 * 映射了 `GLFW_CURSOR_UNAVAILABLE` 和 `GLFW_PLATFORM_UNAVAILABLE`。 * 添加了函数 `GetPlatform`。 * 添加了函数 `PlatformSupported`。 * 添加了函数 `InitAllocator`。 * 添加了函数 `InitVulkanLoader`。 * 添加了函数 `GetError`。 * 添加了函数 `GetPhysicalDevicePresentationSupport`。 * 添加了函数 `Window.GetTitle`。 * 添加了函数 `Window.GetCocoaView`。 * 添加了 hint `MousePassthrough`。 * 添加了 hint `PositionX`。 * 添加了 hint `PositionY`。 * 添加了 hint `ContextDebug`。 * 添加了 hint `ContextNoError`。 * 添加了 hint `AnglePlatformType`。 * 添加了 hint `PlatformHint`。 * 添加了 hint `ScaleFramebuffer`。 * 添加了 hint `Win32KeyboardMenu`。 * 添加了 hint `Win32ShowDefault`。 * 添加了 hint `WaylandAppID`。 * 添加了 hint `WaylandLibdecor`。 * 添加了 hint `X11XcbVulkanSurface`。 * 添加了 hint 值 `AnyPosition`。 * 添加了 hint 值 `WaylandPreferLibdecor`。 * 添加了 hint 值 `WaylandDisableLibdecor`。 * 添加了光标模式值 `CursorCaptured`。 * 未映射 `GLFW_UNLIMITED_MOUSE_BUTTONS`,因为此 package 使用的内置 GLFW C 版本中不存在该内容。 * 添加了多个新的标准光标,如 `PointingHandCursor`、`ResizeEWCursor` 等。 * 添加了 `AnglePlatformType*` hint 值,用于配置 ANGLE 渲染后端。 * 添加了 `Platform` 类型及其值(`AnyPlatform`、`PlatformWin32`、`PlatformCocoa`、`PlatformWayland`、`PlatformX11`、`PlatformNull`)。 ### GLFW 3.3 特定更改 - Joystick 函数现在使用 receiver,而不是将 joystick ID 作为参数传递。 - 故意未实现 Vulkan 方法。`Window.Handle` 可用于通过[此](https://github.com/vulkan-go/vulkan) package 创建 Vulkan surface。 * 将 `Window.GLFWWindow` 重命名为 `Window.Handle` * 添加了函数 `Window.SetAttrib`。 * 添加了函数 `Window.RequestAttention`。 * 添加了函数 `Window.GetContentScale`。 * 添加了函数 `Window.GetOpacity`。 * 添加了函数 `Window.SetOpacity`。 * 添加了函数 `Window.SetMaximizeCallback`。 * 添加了函数 `Window.SetContentScaleCallback`。 * 添加了函数 `Monitor.GetWorkarea`。 * 添加了函数 `Monitor.GetContentScale`。 * 添加了函数 `Monitor.SetUserPointer`。 * 添加了函数 `Monitor.GetUserPointer`。 * 添加了函数 `InitHint`。 * 添加了函数 `RawMouseMotionSupported` * 添加了函数 `GetKeyScancode`。 * 添加了函数 `WindowHintString`。 * 添加了函数 `GetClipboardString`。 * 添加了函数 `SetClipboardString`。 * 添加了函数 `Joystick.GetHats`。 * 添加了函数 `Joystick.IsGamepad`。 * 添加了函数 `Joystick.GetGUID`。 * 添加了函数 `Joystick.GetGamepadName`。 * 添加了函数 `Joystick.GetGamepadState`。 * 添加了函数 `Joystick.SetUserPointer`。 * 添加了函数 `Joystick.GetUserPointer`。 * 添加了函数 `UpdateGamepadMappings`。 * 添加了函数 `SetX11SelectionString`。 * 添加了函数 `GetX11SelectionString`。 * 添加了 gamepad button ID。 * 添加了 gamepad axis ID。 * 添加了 joystick hat 状态 ID。 * 添加了 ModifierKey `ModCapsLock`。 * 添加了 ModifierKey `ModNumLock` * 添加了 InputMode `LockKeyMods`。 * 添加了 InputMode `RawMouseMotion`。 * 添加了 hint `Hovered`。 * 添加了 hint `CenterCursor`。 * 添加了 hint `TransparentFramebuffer`。 * 添加了 hint `FocusOnShow`。 * 添加了 hint `ScaleToMonitor`。 * 添加了 hint `JoystickHatButtons`。 * 添加了 hint `CocoaChdirResources`。 * 添加了 hint `CocoaMenubar`。 * 添加了 hint `TransparentFramebuffer`。 * 添加了 hint 值 `OSMesaContextAPI`。 * 添加了 hint 值 `CocoaGraphicsSwitching`。 * 添加了 hint 值 `CocoaRetinaFramebuffer`。 * 添加了字符串 hint 值 `CocoaFrameNAME`。 * 添加了字符串 hint 值 `X11ClassName`。 * 添加了字符串 hint 值 `X11InstanceName`。 * 将 `MonitorEvent` 重命名为 `PeripheralEvent`,以便与 joystick 事件复用。 * `Joystick.GetButtons` 返回 `[]Action` 而非 `[]byte`。 * `SetMonitorCallback` 返回 `MonitorCallback`。 * `Focus` 不再返回 error。 * `Iconify` 不再返回 error。 * `Maximize` 不再返回 error。 * `Restore` 不再返回 error。 * `GetClipboardString` 不再返回 error。 ### GLFW 3.2 特定更改 - 简易的 `go get` 安装。GLFW 源代码现已包含在 repo 中并会被编译进去,因此您无需自行构建 GLFW 或分发共享库。所使用的 GLFW C 库版本列于 [GLFW_C_REVISION.txt](https://github.com/go-gl/glfw/blob/master/v3.2/glfw/GLFW_C_REVISION.txt) 文件中。 - error callback 现在在内部设置。如果 error 是可恢复的,函数会返回带有相应代码和描述的 error(通过类型断言转换为 glfw3.Error 来访问这些变量)。否则,将触发 panic。 * 添加了函数 `Window.SetSizeLimits`。 * 添加了函数 `Window.SetAspectRatio`。 * 添加了函数 `Window.SetMonitor`。 * 添加了函数 `Window.Maximize`。 * 添加了函数 `Window.SetIcon`。 * 添加了函数 `Window.Focus`。 * 添加了函数 `GetKeyName`。 * 添加了函数 `VulkanSupported`。 * 添加了函数 `GetTimerValue`。 * 添加了函数 `GetTimerFrequency`。 * 添加了函数 `WaitEventsTimeout`。 * 添加了函数 `SetJoystickCallback`。 * 添加了 window hint `Maximized`。 * 添加了 hint `NoAPI`。 * 添加了 hint `NativeContextAPI`。 * 添加了 hint `EGLContextAPI`。 ### GLFW 3.1 特定更改 * 添加了类型 `Cursor`。 * 添加了函数 `Window.SetDropCallback`。 * 添加了函数 `Window.SetCharModsCallback`。 * 添加了函数 `PostEmptyEvent`。 * 添加了函数 `CreateCursor`。 * 添加了函数 `CreateStandardCursor`。 * 添加了函数 `Cursor.Destroy`。 * 添加了函数 `Window.SetCursor`。 * 添加了函数 `Window.GetFrameSize`。 * 添加了 window hint `Floating`。 * 添加了 window hint `AutoIconify`。 * 添加了 window hint `ContextReleaseBehavior`。 * 添加了 window hint `DoubleBuffer`。 * 添加了 hint 值 `AnyReleaseBehavior`。 * 添加了 hint 值 `ReleaseBehaviorFlush`。 * 添加了 hint 值 `ReleaseBehaviorNone`。 * 添加了 hint 值 `DontCare`。 ### API 更改 * `Window.Iconify` 返回 error。 * `Window.Restore` 返回 error。 * `Init` 返回 error 而不是 `bool`。 * `GetJoystickAxes` 不再返回 error。 * `GetJoystickButtons` 不再返回 error。 * `GetJoystickName` 不再返回 error。 * `GetMonitors` 不再返回 error。 * `GetPrimaryMonitor` 不再返回 error。 * `Monitor.GetGammaRamp` 不再返回 error。 * `Monitor.GetVideoMode` 不再返回 error。 * `Monitor.GetVideoModes` 不再返回 error。 * `GetCurrentContext` 不再返回 error。 * `Window.SetCharCallback` 接受 `rune` 而不是 `uint`。 * 添加了类型 `Error`。 * 移除了 `SetErrorCallback`。 * 移除了错误代码 `NotInitialized`。 * 移除了错误代码 `NoCurrentContext`。 * 移除了错误代码 `InvalidEnum`。 * 移除了错误代码 `InvalidValue`。 * 移除了错误代码 `OutOfMemory`。 * 移除了错误代码 `PlatformError`。 * 移除了 `KeyBracket`。 * 将 `Window.SetCharacterCallback` 重命名为 `Window.SetCharCallback`。 * 将 `Window.GetCursorPosition` 重命名为 `GetCursorPos`。 * 将 `Window.SetCursorPosition` 重命名为 `SetCursorPos`。 * 将 `CursorPositionCallback` 重命名为 `CursorPosCallback`。 * 将 `Window.SetCursorPositionCallback` 重命名为 `SetCursorPosCallback`。 * 将 `VideoMode` 重命名为 `VidMode`。 * 将 `Monitor.GetPosition` 重命名为 `Monitor.GetPos`。 * 将 `Window.GetPosition` 重命名为 `Window.GetPos`。 * 将 `Window.SetPosition` 重命名为 `Window.SetPos`。 * 将 `Window.GetAttribute` 重命名为 `Window.GetAttrib`。 * 将 `Window.SetPositionCallback` 重命名为 `Window.SetPosCallback`。 * 将 `PositionCallback` 重命名为 `PosCallback`。 * 将 `Cursor` 重命名为 `CursorMode`。 * 将 `StickyKeys` 重命名为 `StickyKeysMode`* 将 `StickyMouseButtons` 重命名为 `StickyMouseButtonsMode`。 * 将 `ApiUnavailable` 重命名为 `APIUnavailable`。 * 将 `ClientApi` 重命名为 `ClientAPI`。 * 将 `OpenglForwardCompatible` 重命名为 `OpenGLForwardCompatible`。 * 将 `OpenglDebugContext` 重命名为 `OpenGLDebugContext`。 * 将 `OpenglProfile` 重命名为 `OpenGLProfile`。 * 将 `SrgbCapable` 重命名为 `SRGBCapable`。 * 将 `OpenglApi` 重命名为 `OpenGLAPI`。 * 将 `OpenglEsApi` 重命名为 `OpenGLESAPI`。 * 将 `OpenglAnyProfile` 重命名为 `OpenGLAnyProfile`。 * 将 `OpenglCoreProfile` 重命名为 `OpenGLCoreProfile`。 * 将 `OpenglCompatProfile` 重命名为 `OpenGLCompatProfile`。 * 将 `KeyKp...` 重命名为 `KeyKP...`。
标签:客户端加密, 日志审计