Skip to content

Commit

Permalink
experiments with full-screen (F11)
Browse files Browse the repository at this point in the history
  • Loading branch information
mki1967 committed Feb 3, 2021
1 parent ddfb3ee commit ee6f514
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions assets/scripts/zenity-help.bash
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Key press actions:
Q - display your score and the number of remaining tokens
S - toggle SKYBOX ON/OFF
N - new SKYBOX
Shift+Q - quit
F11 - toggle full-screen
OR USE THE GAMEPAD:
Expand Down
7 changes: 7 additions & 0 deletions game.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ const skyboxChance = 0.25 // the chance of having withSkybox==true on the new st

// data structure for the game
type Mki3dGame struct {
// Quit the game
Quit bool

// is full screen mode?
FullScreen bool
// Saved position and size of non-fullscreen window
PosX, PosY int
SizeWidth, SizeHeight int
// assets info
AssetsPtr *Assets
// GLFW data
Expand Down
2 changes: 2 additions & 0 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Key press actions:
Q - display your score and the number of remaining tokens
S - toggle SKYBOX ON/OFF
N - new SKYBOX
Shift+Q - quit
F11 - toggle full-screen
OR USE THE GAMEPAD:
Expand Down
17 changes: 17 additions & 0 deletions key-callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ func (g *Mki3dGame) KeyCallback(w *glfw.Window, key glfw.Key, scancode int, acti
g.Skybox.RenderRandomCube()
g.withSkybox = true

case key == glfw.KeyF11: /* toggle full-screen */
if !g.FullScreen {
/// set full-screen
g.PosX, g.PosY = w.GetPos()
g.SizeWidth, g.SizeHeight = w.GetSize()
monitor := glfw.GetPrimaryMonitor()
mode := monitor.GetVideoMode()
w.SetMonitor(monitor, 0, 0, mode.Width, mode.Height, mode.RefreshRate)
g.FullScreen = true
} else {
// unset full-screen
monitor := glfw.GetPrimaryMonitor()
mode := monitor.GetVideoMode()
w.SetMonitor(nil, g.PosX, g.PosY, g.SizeWidth, g.SizeHeight, mode.RefreshRate)
g.FullScreen = false
}

}
}
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ func main() {

glfw.SwapInterval(1) // try to avoid tearing ???
// game.CheckGamepad() // test

// main loop
for !window.ShouldClose() && !game.Quit {

// Maintenance
window.SwapBuffers()
if doInMainThread != nil {
Expand Down

0 comments on commit ee6f514

Please sign in to comment.