mirror of
https://github.com/Kugelschieber/go-game.git
synced 2026-01-18 06:40:28 +00:00
Fixed bug in text renderer, upgraded to GLFW 3.2, added fullscreen and FPS limitation.
This commit is contained in:
6
ToDo.md
6
ToDo.md
@@ -2,7 +2,9 @@
|
||||
|
||||
* ~~cleanup resources~~
|
||||
* more logging
|
||||
* limit FPS
|
||||
* fullscreen
|
||||
* ~~limit FPS~~
|
||||
- does this really work?
|
||||
* ~~fullscreen~~
|
||||
* simple access to default resources like GetTex()
|
||||
* ~~text rendering + font loading~~
|
||||
* more options for GLFW
|
||||
|
||||
@@ -55,6 +55,7 @@ func main() {
|
||||
options := goga.RunOptions{ClearColor: goga.Vec4{0, 0, 0, 0},
|
||||
Resizable: true,
|
||||
SetViewportOnResize: true,
|
||||
ExitOnClose: true}
|
||||
ExitOnClose: true,
|
||||
Fullscreen: true}
|
||||
goga.Run(&game, &options)
|
||||
}
|
||||
|
||||
55
game.go
55
game.go
@@ -2,7 +2,7 @@ package goga
|
||||
|
||||
import (
|
||||
"github.com/go-gl/gl/v4.5-core/gl"
|
||||
"github.com/go-gl/glfw/v3.1/glfw"
|
||||
"github.com/go-gl/glfw/v3.2/glfw"
|
||||
"log"
|
||||
"math"
|
||||
"runtime"
|
||||
@@ -29,6 +29,9 @@ type RunOptions struct {
|
||||
SetViewportOnResize bool
|
||||
ResizeCallbackFunc ResizeCallback
|
||||
ExitOnClose bool
|
||||
RefreshRate int
|
||||
Fullscreen bool
|
||||
MonitorId uint // index
|
||||
}
|
||||
|
||||
// Main game object.
|
||||
@@ -88,32 +91,52 @@ func Run(game Game, options *RunOptions) {
|
||||
title := default_title
|
||||
exitOnClose := default_exit_on_close
|
||||
|
||||
if options != nil && options.Width > 0 {
|
||||
width = options.Width
|
||||
}
|
||||
|
||||
if options != nil && options.Height > 0 {
|
||||
height = options.Height
|
||||
}
|
||||
|
||||
if options != nil && len(options.Title) > 0 {
|
||||
title = options.Title
|
||||
}
|
||||
|
||||
if options != nil {
|
||||
if options.Width > 0 {
|
||||
width = options.Width
|
||||
}
|
||||
|
||||
if options.Height > 0 {
|
||||
height = options.Height
|
||||
}
|
||||
|
||||
if len(options.Title) > 0 {
|
||||
title = options.Title
|
||||
}
|
||||
|
||||
exitOnClose = options.ExitOnClose
|
||||
|
||||
if !options.Resizable {
|
||||
glfw.WindowHint(glfw.Resizable, glfw.False)
|
||||
}
|
||||
}
|
||||
|
||||
if options != nil && !options.Resizable {
|
||||
glfw.WindowHint(glfw.Resizable, glfw.False)
|
||||
var monitor *glfw.Monitor
|
||||
|
||||
if options != nil && options.Fullscreen {
|
||||
monitors := glfw.GetMonitors()
|
||||
|
||||
if int(options.MonitorId) < len(monitors) {
|
||||
monitor = monitors[options.MonitorId]
|
||||
}
|
||||
}
|
||||
|
||||
wnd, err := glfw.CreateWindow(int(width), int(height), title, nil, nil)
|
||||
if monitor != nil {
|
||||
videoMode := monitor.GetVideoMode()
|
||||
width = uint32(videoMode.Width)
|
||||
height = uint32(videoMode.Height)
|
||||
}
|
||||
|
||||
wnd, err := glfw.CreateWindow(int(width), int(height), title, monitor, nil)
|
||||
|
||||
if err != nil {
|
||||
panic("Error creating GLFW window: " + err.Error())
|
||||
}
|
||||
|
||||
if options != nil && options.RefreshRate != 0 {
|
||||
glfw.WindowHint(glfw.RefreshRate, options.RefreshRate)
|
||||
}
|
||||
|
||||
// window event handlers
|
||||
wnd.SetSizeCallback(func(w *glfw.Window, width, height int) {
|
||||
if options == nil {
|
||||
|
||||
4
text.go
4
text.go
@@ -414,6 +414,10 @@ func (r *TextRenderer) GetName() string {
|
||||
|
||||
// Renders texts.
|
||||
func (r *TextRenderer) Update(delta float64) {
|
||||
if r.Font == nil {
|
||||
return
|
||||
}
|
||||
|
||||
r.Shader.Bind()
|
||||
r.Shader.SendMat3(Default_shader_text_ortho, *MultMat3(r.Camera.CalcOrtho(), r.CalcModel()))
|
||||
r.Shader.SendUniform1i(Default_shader_text_tex, 0)
|
||||
|
||||
Reference in New Issue
Block a user