66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
package engine
|
|
|
|
import "github.com/go-gl/glfw/v3.3/glfw"
|
|
|
|
type Window struct {
|
|
window *glfw.Window
|
|
title string
|
|
width, height int
|
|
}
|
|
|
|
func NewWindow(title string, width, height int) *Window {
|
|
return &Window{
|
|
title: title,
|
|
width: width,
|
|
height: height,
|
|
}
|
|
}
|
|
|
|
func (w *Window) Init() error {
|
|
if err := glfw.Init(); err != nil {
|
|
return err
|
|
}
|
|
|
|
glfw.WindowHint(glfw.ContextVersionMajor, 4)
|
|
glfw.WindowHint(glfw.ContextVersionMinor, 1)
|
|
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
|
|
glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
|
|
glfw.WindowHint(glfw.Resizable, glfw.True)
|
|
|
|
window, err := glfw.CreateWindow(w.width, w.height, w.title, nil, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
w.window = window
|
|
w.window.MakeContextCurrent()
|
|
w.window.SetFramebufferSizeCallback(w.framebufferSizeCallback)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (w *Window) framebufferSizeCallback(window *glfw.Window, width, height int) {
|
|
w.width, w.height = width, height
|
|
// Здесь можно добавить коллбэк для игры
|
|
}
|
|
|
|
func (w *Window) ShouldClose() bool {
|
|
return w.window.ShouldClose()
|
|
}
|
|
|
|
func (w *Window) PollEvents() {
|
|
glfw.PollEvents()
|
|
}
|
|
|
|
func (w *Window) SwapBuffers() {
|
|
w.window.SwapBuffers()
|
|
}
|
|
|
|
func (w *Window) Destroy() {
|
|
glfw.Terminate()
|
|
}
|
|
|
|
func (w *Window) GetSize() (int, int) {
|
|
return w.width, w.height
|
|
}
|