54 lines
988 B
Go
54 lines
988 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
"runtime"
|
||
|
|
||
|
"github.com/go-gl/gl/v3.3-core/gl"
|
||
|
"github.com/go-gl/glfw/v3.3/glfw"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
width = 800
|
||
|
height = 600
|
||
|
title = "Go OpenGL Example"
|
||
|
)
|
||
|
|
||
|
func init() {
|
||
|
runtime.LockOSThread()
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
err := glfw.Init()
|
||
|
if err != nil {
|
||
|
log.Fatalln("Failed to initialize GLFW:", err)
|
||
|
}
|
||
|
defer glfw.Terminate()
|
||
|
|
||
|
glfw.WindowHint(glfw.ContextVersionMajor, 3)
|
||
|
glfw.WindowHint(glfw.ContextVersionMinor, 3)
|
||
|
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
|
||
|
glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
|
||
|
|
||
|
window, err := glfw.CreateWindow(width, height, title, nil, nil)
|
||
|
if err != nil {
|
||
|
log.Fatalln("Failed to create window:", err)
|
||
|
}
|
||
|
|
||
|
window.MakeContextCurrent()
|
||
|
glfw.SwapInterval(1)
|
||
|
|
||
|
if err := gl.Init(); err != nil {
|
||
|
log.Fatalln("Failed to initialize OpenGL:", err)
|
||
|
}
|
||
|
|
||
|
gl.ClearColor(0.1, 0.1, 0.1, 1.0)
|
||
|
|
||
|
for !window.ShouldClose() {
|
||
|
gl.Clear(gl.COLOR_BUFFER_BIT)
|
||
|
|
||
|
window.SwapBuffers()
|
||
|
glfw.PollEvents()
|
||
|
}
|
||
|
}
|