2023-08-01 16:56:58 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2022-05-27 13:38:45 +02:00
|
|
|
// SPDX-FileCopyrightText: 2002-2006 Marcus Geelnard
|
2023-08-03 18:11:13 +02:00
|
|
|
// SPDX-FileCopyrightText: 2006-2018 Camilla Löwy <elmindreda@glfw.org>
|
2022-05-27 13:38:45 +02:00
|
|
|
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
|
2022-04-19 17:49:43 +02:00
|
|
|
|
2023-10-03 16:07:53 +02:00
|
|
|
package glfw
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
func terminate() error {
|
|
|
|
for _, w := range _glfw.windows {
|
|
|
|
if err := w.Destroy(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range _glfw.cursors {
|
|
|
|
if err := c.Destroy(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_glfw.monitors = nil
|
|
|
|
|
|
|
|
if err := platformTerminate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_glfw.initialized = false
|
|
|
|
|
|
|
|
if err := _glfw.contextSlot.destroy(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Init() (ferr error) {
|
|
|
|
defer func() {
|
|
|
|
if ferr != nil {
|
2023-10-03 16:07:53 +02:00
|
|
|
// InvalidValue can happen when specific joysticks are used. This issue
|
|
|
|
// will be fixed in GLFW 3.3.5. As a temporary fix, ignore this error.
|
|
|
|
// See go-gl/glfw#292, go-gl/glfw#324, and glfw/glfw#1763
|
|
|
|
// (#1229).
|
|
|
|
if errors.Is(ferr, InvalidValue) {
|
|
|
|
ferr = nil
|
|
|
|
return
|
|
|
|
}
|
2022-09-09 18:52:46 +02:00
|
|
|
_ = terminate()
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if _glfw.initialized {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
_glfw.hints.init.hatButtons = true
|
|
|
|
|
|
|
|
if err := platformInit(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := _glfw.contextSlot.create(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_glfw.initialized = true
|
|
|
|
|
|
|
|
if err := defaultWindowHints(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Terminate() error {
|
|
|
|
if !_glfw.initialized {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if err := terminate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|