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