代码拉取完成,页面将自动刷新
package kiwano
import (
"github.com/go-gl/glfw/v3.2/glfw"
"kiwanoengine.com/kiwano/external/gl"
)
type Option struct {
Width, Height int
Title string
ClearColor Color
NoTitleBar bool
Fullscreen bool
Resizable bool
Vsync bool
}
type Window struct {
Option
glfw.Window
}
func NewWindow(option *Option) (*Window, error) {
window := &Window{
Option: *option,
}
// Init GLFW
if err := glfw.Init(); err != nil {
return nil, err
}
glfw.WindowHint(glfw.ContextVersionMajor, 3)
glfw.WindowHint(glfw.ContextVersionMinor, 3)
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
glfw.WindowHint(glfw.Visible, glfw.False)
if option.NoTitleBar {
glfw.WindowHint(glfw.Decorated, glfw.False)
} else {
glfw.WindowHint(glfw.Decorated, glfw.True)
}
if option.Resizable {
glfw.WindowHint(glfw.Resizable, glfw.True)
} else {
glfw.WindowHint(glfw.Resizable, glfw.False)
}
// Get monitor information
monitor := glfw.GetPrimaryMonitor()
var monitorMode *glfw.VidMode
if monitor != nil {
monitorMode = monitor.GetVideoMode()
}
// Fullscreen mode
if option.Fullscreen && monitorMode != nil {
option.Width, option.Height = monitorMode.Width, monitorMode.Height
} else {
monitor = nil
}
// Create window
w, err := glfw.CreateWindow(option.Width, option.Height, option.Title, monitor, nil)
if err != nil {
return nil, err
}
if !option.Fullscreen && monitorMode != nil {
w.SetPos((monitorMode.Width-option.Width)/2, (monitorMode.Height-option.Height)/2)
}
w.MakeContextCurrent()
w.SetFramebufferSizeCallback(window.onFramebufferSizeCallback)
if option.Vsync {
glfw.SwapInterval(1)
} else {
glfw.SwapInterval(0)
}
// Init OpenGL
if err := gl.Init(); err != nil {
return nil, err
}
gl.ClearColor(option.ClearColor.ToVec4())
window.Window = *w
return window, nil
}
func (w *Window) onFramebufferSizeCallback(win *glfw.Window, width int, height int) {
w.Width, w.Height = width, height
gl.Viewport(0, 0, int32(width), int32(height))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。