Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fullscreen support, cmdline and keyboard toggle #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ http://www.michaelfogleman.com/static/nes/
### Dependencies

github.com/go-gl/gl/v2.1/gl
github.com/go-gl/glfw/v3.1/glfw
github.com/go-gl/glfw/v3.2/glfw
github.com/gordonklaus/portaudio

The portaudio-go dependency requires PortAudio on your system:
Expand Down Expand Up @@ -68,6 +68,8 @@ Keyboard controls are indicated below.
| B (Turbo) | S |
| Reset | R |

Full Screen Mode - CRTL + F

### Mappers

The following mappers have been implemented:
Expand Down
25 changes: 21 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,39 @@ import (
"os"
"path"
"strings"
"fmt"

"github.com/fogleman/nes/ui"
)

func main() {
log.SetFlags(0)
paths := getPaths()
args, fullscreen := extractFlags()
paths := getPaths(args)
if len(paths) == 0 {
log.Fatalln("no rom files specified or found")
}
ui.Run(paths)
ui.Run(paths, fullscreen)
}

func getPaths() []string {
func extractFlags() ([]string, bool) {
args := os.Args

for i, x := range args {
//Probably should add a keyboard shortcut for this also
if x == "--fullscreen" {
a := append(args[:i], args[i+1:]...)
fmt.Printf("fullscreen - args - %v -- a %b", args, a)
return a, true
}
}

return args, false
}

func getPaths(argsv []string ) []string {
var arg string
args := os.Args[1:]
args := argsv[1:]
if len(args) == 1 {
arg = args[0]
} else {
Expand Down
2 changes: 1 addition & 1 deletion ui/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/fogleman/nes/nes"
"github.com/go-gl/gl/v2.1/gl"
"github.com/go-gl/glfw/v3.1/glfw"
"github.com/go-gl/glfw/v3.2/glfw"
)

type View interface {
Expand Down
19 changes: 18 additions & 1 deletion ui/gameview.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/fogleman/nes/nes"
"github.com/go-gl/gl/v2.1/gl"
"github.com/go-gl/glfw/v3.1/glfw"
"github.com/go-gl/glfw/v3.2/glfw"
)

const padding = 0
Expand Down Expand Up @@ -93,6 +93,10 @@ func (view *GameView) onKey(window *glfw.Window,
screenshot(view.console.Buffer())
case glfw.KeyR:
view.console.Reset()
case glfw.KeyF:
if mods == glfw.ModControl {
view.ToggleFullScreen(window)
}
case glfw.KeyTab:
if view.record {
view.record = false
Expand All @@ -105,6 +109,19 @@ func (view *GameView) onKey(window *glfw.Window,
}
}

func (view *GameView) ToggleFullScreen(window *glfw.Window) {
if window.GetMonitor() == nil {
monitor := glfw.GetPrimaryMonitor()
vid := monitor.GetVideoMode()
window.SetMonitor(monitor, 0, 0, vid.Width, vid.Height, 60)
} else {
//This actually requires glfw 3.3 to work perfectly on osx
//otherwise the window is not the right size
window.SetMonitor(nil, 0, 0, width*scale, height*scale, 0)
}
}


func drawBuffer(window *glfw.Window) {
w, h := window.GetFramebufferSize()
s1 := float32(w) / 256
Expand Down
2 changes: 1 addition & 1 deletion ui/menuview.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/fogleman/nes/nes"
"github.com/go-gl/gl/v2.1/gl"
"github.com/go-gl/glfw/v3.1/glfw"
"github.com/go-gl/glfw/v3.2/glfw"
)

const (
Expand Down
16 changes: 13 additions & 3 deletions ui/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime"

"github.com/go-gl/gl/v2.1/gl"
"github.com/go-gl/glfw/v3.1/glfw"
"github.com/go-gl/glfw/v3.2/glfw"
"github.com/gordonklaus/portaudio"
)

Expand All @@ -24,7 +24,7 @@ func init() {
runtime.LockOSThread()
}

func Run(paths []string) {
func Run(paths []string, fullscreen bool) {
// initialize audio
portaudio.Initialize()
defer portaudio.Terminate()
Expand All @@ -44,10 +44,20 @@ func Run(paths []string) {
// create window
glfw.WindowHint(glfw.ContextVersionMajor, 2)
glfw.WindowHint(glfw.ContextVersionMinor, 1)
window, err := glfw.CreateWindow(width*scale, height*scale, title, nil, nil)

var err error
var window *glfw.Window
if fullscreen == false {
window, err = glfw.CreateWindow(width*scale, height*scale, title, nil, nil)
} else {
monitor := glfw.GetPrimaryMonitor()
vid := monitor.GetVideoMode()
window, err = glfw.CreateWindow(vid.Width, vid.Height, title, monitor, nil)
}
if err != nil {
log.Fatalln(err)
}

window.MakeContextCurrent()

// initialize gl
Expand Down
2 changes: 1 addition & 1 deletion ui/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/fogleman/nes/nes"
"github.com/go-gl/gl/v2.1/gl"
"github.com/go-gl/glfw/v3.1/glfw"
"github.com/go-gl/glfw/v3.2/glfw"
)

var homeDir string
Expand Down