opengl-deferred/main.go
2024-10-11 18:38:21 +02:00

63 lines
1.2 KiB
Go

package main
import (
"fmt"
"os"
"git.tek.govt.hu/dowerx/opengl-deferred/types/shader"
"github.com/go-gl/gl/v4.6-core/gl"
"github.com/go-gl/glfw/v3.3/glfw"
)
const (
WIDTH = 640
HEIGHT = 480
TITLE = "opengl-deferred"
)
func main() {
// init glfw
if err := glfw.Init(); err != nil {
panic(err)
}
defer glfw.Terminate()
glfw.WindowHint(glfw.Resizable, glfw.False)
glfw.WindowHint(glfw.ContextVersionMajor, 4)
glfw.WindowHint(glfw.ContextVersionMinor, 6)
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
window, err := glfw.CreateWindow(WIDTH, HEIGHT, TITLE, nil, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
// init glow
if err := gl.Init(); err != nil {
panic(err)
}
fmt.Println("OpenGL version:", gl.GoStr(gl.GetString(gl.VERSION)))
// load assets
// shader
vertexSource, err := os.ReadFile("assets/shader/deferred/deferred.vs")
if err != nil {
panic(err)
}
fragmentSource, err := os.ReadFile("assets/shader/deferred/deferred.fs")
if err != nil {
panic(err)
}
deferredShader, err := shader.New(string(vertexSource), string(fragmentSource))
if err != nil {
panic(err)
}
defer deferredShader.Delete()
deferredShader.Use()
}