From 092ad543e5ecf84102ee7cb2b7892c9cef329c0d Mon Sep 17 00:00:00 2001 From: Marvin Blum Date: Mon, 8 Aug 2016 21:35:01 +0200 Subject: [PATCH] Fixed bug in text renderer, upgraded to GLFW 3.2, added fullscreen and FPS limitation. --- ToDo.md | 6 +++-- demo/keyframe/keyframe.go | 3 ++- game.go | 55 +++++++++++++++++++++++++++------------ text.go | 4 +++ 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/ToDo.md b/ToDo.md index ddc5b24..77af0cc 100644 --- a/ToDo.md +++ b/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 diff --git a/demo/keyframe/keyframe.go b/demo/keyframe/keyframe.go index d7cf921..eaba82a 100644 --- a/demo/keyframe/keyframe.go +++ b/demo/keyframe/keyframe.go @@ -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) } diff --git a/game.go b/game.go index ca386c8..f7d8acf 100644 --- a/game.go +++ b/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 { diff --git a/text.go b/text.go index 0220bc1..ea37efe 100644 --- a/text.go +++ b/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)