mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-23 18:17:32 +00:00
63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
package ui
|
|
|
|
import (
|
|
"image"
|
|
"log"
|
|
"runtime"
|
|
|
|
"github.com/go-gl/gl/v2.1/gl"
|
|
"github.com/go-gl/glfw/v3.2/glfw"
|
|
"github.com/gordonklaus/portaudio"
|
|
)
|
|
|
|
const (
|
|
width = 256
|
|
height = 240
|
|
scale = 3
|
|
title = "NES"
|
|
)
|
|
|
|
func init() {
|
|
// we need a parallel OS thread to avoid audio stuttering
|
|
runtime.GOMAXPROCS(2)
|
|
|
|
// we need to keep OpenGL calls on a single thread
|
|
runtime.LockOSThread()
|
|
}
|
|
|
|
func Run(paths []string, imageChannel chan *image.RGBA, inputChannel chan int) {
|
|
// initialize audio
|
|
portaudio.Initialize()
|
|
defer portaudio.Terminate()
|
|
|
|
audio := NewAudio()
|
|
if err := audio.Start(); err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
defer audio.Stop()
|
|
|
|
// initialize glfw
|
|
if err := glfw.Init(); err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
defer glfw.Terminate()
|
|
|
|
// create window
|
|
glfw.WindowHint(glfw.ContextVersionMajor, 2)
|
|
glfw.WindowHint(glfw.ContextVersionMinor, 1)
|
|
window, err := glfw.CreateWindow(width*scale, height*scale, title, nil, nil)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
window.MakeContextCurrent()
|
|
|
|
// initialize gl
|
|
if err := gl.Init(); err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
gl.Enable(gl.TEXTURE_2D)
|
|
|
|
// run director
|
|
director := NewDirector(window, audio, imageChannel, inputChannel)
|
|
director.Start(paths)
|
|
}
|