hlgl/main.go

58 lines
1.3 KiB
Go
Raw Normal View History

2024-11-23 21:54:20 -07:00
package main
import (
"runtime"
"github.com/go-gl/gl/v4.1-core/gl"
"github.com/go-gl/glfw/v3.3/glfw"
"github.com/go-gl/mathgl/mgl32"
)
const (
start_width = 1920
start_height = 1080
)
func main() {
runtime.LockOSThread()
if err := glfw.Init(); err != nil {
}
defer glfw.Terminate()
glfw.WindowHint(glfw.ContextVersionMajor, 4)
glfw.WindowHint(glfw.ContextVersionMinor, 1)
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
window, err := glfw.CreateWindow(start_width, start_height, "Learning OpenGL", nil, nil)
if err != nil {
panic(err)
2024-11-23 21:54:20 -07:00
}
window.MakeContextCurrent()
if err := gl.Init(); err != nil {
panic(err)
2024-11-23 21:54:20 -07:00
}
projection := CreateOrthographicProjection(start_width, start_height)
InitHLGL(projection)
2024-11-23 21:54:20 -07:00
gl.ClearColor(0.2, 0.3, 0.3, 1.0)
for !window.ShouldClose() {
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
// DrawRectangleWH(100, 100, 700, 150, HLColorRGBA{255, 0, 0, 255})
// DrawRectangleWH(400, 200, 300, 300, HLColorRGBA{0, 255, 0, 255})
DrawRoundedRectangle(200, 500, 200, 200, 10, HLColorRGBA{0, 0, 255, 255})
2024-11-23 21:54:20 -07:00
window.SwapBuffers()
glfw.WaitEvents()
2024-11-23 21:54:20 -07:00
}
window.Destroy()
return
2024-11-23 21:54:20 -07:00
}
func CreateOrthographicProjection(width, height int) mgl32.Mat4 {
return mgl32.Ortho(0, float32(width), 0, float32(height), -1, 1)
}