64 lines
1 KiB
Go
64 lines
1 KiB
Go
// Package
|
|
package main
|
|
|
|
// Libraries
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"runtime"
|
|
|
|
"github.com/go-gl/gl/v2.1/gl"
|
|
"github.com/go-gl/glfw/v3.3/glfw"
|
|
)
|
|
|
|
// Structures
|
|
type Window struct {
|
|
title string
|
|
width, height int
|
|
window *glfw.Window
|
|
}
|
|
|
|
// Interfaces
|
|
func (w *Window) Init(title string, _w int, _h int) {
|
|
// Setting variables
|
|
w.title = title
|
|
w.width = _w
|
|
w.height = _h
|
|
|
|
// DBEUG
|
|
fmt.Println(": ENGINE STARTING")
|
|
|
|
// Locking thread
|
|
runtime.LockOSThread()
|
|
|
|
// Starting GLFW
|
|
err := glfw.Init()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// Creating a window
|
|
w.window, err = glfw.CreateWindow(w.width, w.height, w.title, nil, nil)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
w.window.MakeContextCurrent()
|
|
|
|
// Staring OpenGL
|
|
if err := gl.Init(); err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
gl.ClearColor(0, 0, 0, 1)
|
|
}
|
|
func (w *Window) Run(execute func(w *Window)) {
|
|
for !w.window.ShouldClose() {
|
|
w.window.SwapBuffers()
|
|
glfw.PollEvents()
|
|
gl.Clear(gl.COLOR_BUFFER_BIT)
|
|
execute(w)
|
|
}
|
|
}
|
|
func (w *Window) Stop() {
|
|
glfw.Terminate()
|
|
}
|