61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package window
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/veandco/go-sdl2/sdl"
|
|
)
|
|
|
|
/*
|
|
NOTE: We're using the SDL with goroutines example.
|
|
Every call to an SDL function must be passed through the sdl.Do() function so that it joins the queue of thread-sensitive calls.
|
|
You'll see this a lot below, but basically every SDL function must do something like this:
|
|
sdl.Do(func() {
|
|
err = sdl.SomeFunction()
|
|
})
|
|
This is for thread safety because SDL is not intended to be thread-safe.
|
|
However, the rest of the code can do whatever it wants with threads so long as the SDL calls all use this method.
|
|
*/
|
|
|
|
const (
|
|
SDL_INIT_FLAGS uint32 = sdl.INIT_TIMER | sdl.INIT_AUDIO | sdl.INIT_VIDEO | sdl.INIT_EVENTS | sdl.INIT_JOYSTICK | sdl.INIT_HAPTIC | sdl.INIT_GAMECONTROLLER // ignore sensor subsystem
|
|
|
|
SDL_WINDOW_FLAGS uint32 = sdl.WINDOW_SHOWN | sdl.WINDOW_RESIZABLE
|
|
SDL_FULLSCREEN_WINDOW_FLAGS uint32 = SDL_WINDOW_FLAGS | sdl.WINDOW_FULLSCREEN_DESKTOP
|
|
SDL_WINDOW_WIDTH int32 = 800
|
|
SDL_WINDOW_HEIGHT int32 = 600
|
|
)
|
|
|
|
func SdlInit() error {
|
|
var err error
|
|
|
|
// Initialize SDL
|
|
sdl.Do(func() {
|
|
err = sdl.Init(SDL_INIT_FLAGS)
|
|
})
|
|
if err != nil {
|
|
err = fmt.Errorf("failed initializing SDL: %w", err)
|
|
return err
|
|
}
|
|
|
|
// Set some base SDL settings
|
|
sdl.Do(func() {
|
|
// Disable the Linux compositor flicker.
|
|
// https://github.com/mosra/magnum/issues/184#issuecomment-425952900
|
|
sdl.SetHint(sdl.HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0")
|
|
|
|
sdl.DisableScreenSaver()
|
|
|
|
// Capture the mouse for movement
|
|
//sdl.SetRelativeMouseMode(true)
|
|
})
|
|
|
|
return nil
|
|
}
|
|
|
|
func SdlQuit() {
|
|
sdl.Do(func() {
|
|
sdl.Quit()
|
|
})
|
|
}
|