func initSDL() { if sdl.Init(sdl.INIT_VIDEO) != 0 { panic(sdl.GetError()) } if ttf.Init() != 0 { panic(sdl.GetError()) } font := ttf.OpenFont("testdata/VeraMono.ttf", 20) if font == nil { panic(sdl.GetError()) } appSurface = sdl.SetVideoMode(640, 480, 32, 0) sdlrenderer = NewSDLRenderer(sdl.CreateRGBSurface(sdl.SRCALPHA, 640, 480, 32, 0, 0, 0, 0), font) sdlrenderer.GetSurface().SetAlpha(sdl.SRCALPHA, 0xaa) console = NewConsole(nil) go func() { for { select { case rects := <-sdlrenderer.UpdatedRectsCh(): render(rects) } } }() render(nil) }
func initSDLSubSystems(app *spectrum.Application) error { if sdl.Init(sdl.INIT_VIDEO|sdl.INIT_AUDIO|sdl.INIT_JOYSTICK) != 0 { return errors.New(sdl.GetError()) } if ttf.Init() != 0 { return errors.New(sdl.GetError()) } if sdl.NumJoysticks() > 0 { // Open joystick joystick = sdl.JoystickOpen(DEFAULT_JOYSTICK_ID) if joystick != nil { if app.Verbose { app.PrintfMsg("Opened Joystick %d", DEFAULT_JOYSTICK_ID) app.PrintfMsg("Name: %s", sdl.JoystickName(DEFAULT_JOYSTICK_ID)) app.PrintfMsg("Number of Axes: %d", joystick.NumAxes()) app.PrintfMsg("Number of Buttons: %d", joystick.NumButtons()) app.PrintfMsg("Number of Balls: %d", joystick.NumBalls()) } } else { return errors.New("Couldn't open Joystick!") } } sdl.WM_SetCaption("GoSpeccy - ZX Spectrum Emulator", "") sdl.EnableUNICODE(1) return nil }
func BenchmarkRendering(b *testing.B) { if sdl.Init(sdl.INIT_EVERYTHING) != 0 { log.Fatal(sdl.GetError()) } screen := smslib.NewSDL2xScreen(false) displayLoop := smslib.NewSDLLoop(screen) go displayLoop.Run() sms := smslib.NewSMS(displayLoop) sms.LoadROM("../roms/blockhead.sms") numOfGeneratedFrames := 100 generatedFrames := make([]smslib.DisplayData, numOfGeneratedFrames) for i := 0; i < numOfGeneratedFrames; i++ { generatedFrames = append(generatedFrames, *sms.RenderFrame()) } b.ResetTimer() for i := 0; i < b.N; i++ { for _, frame := range generatedFrames { displayLoop.Display() <- &frame } } }
func NewVideo(caption string, events chan Event, framePool *sync.Pool, fps float64) (video *SDLVideo, err error) { video = &SDLVideo{ input: make(chan []uint8), events: events, framePool: framePool, palette: SDLPalette, overscan: true, caption: caption, fps: fps, } for i, _ := range video.palette { video.palette[i] <<= 8 } if sdl.Init(sdl.INIT_VIDEO|sdl.INIT_JOYSTICK|sdl.INIT_AUDIO) != 0 { err = errors.New(sdl.GetError()) return } video.screen = sdl.SetVideoMode(512, 480, 32, sdl.OPENGL|sdl.RESIZABLE|sdl.GL_DOUBLEBUFFER) if video.screen == nil { err = errors.New("Error setting video mode") return } sdl.WM_SetCaption("nintengo - "+video.caption, "") video.initGL() video.Reshape(int(video.screen.W), int(video.screen.H)) return }
func main() { if sdl.Init(sdl.INIT_VIDEO) != 0 { panic(sdl.GetError()) } defer sdl.Quit() screen := sdl.SetVideoMode(400, 300, 32, 0) if screen == nil { panic(sdl.GetError()) } sdl.WM_SetCaption("Template", "") ticker := time.NewTicker(1e9 / 2 /*2 Hz*/) loop: for { select { case <-ticker.C: // Note: For better efficiency, use UpdateRects instead of Flip screen.FillRect(nil /*color*/, rand.Uint32()) //screen.Blit(&sdl.Rect{x,y, 0, 0}, image, nil) screen.Flip() case event := <-sdl.Events: fmt.Printf("%#v\n", event) switch event.(type) { case sdl.QuitEvent: break loop } } } }
func main() { verbose := flag.Bool("verbose", false, "verbose mode") debug := flag.Bool("debug", false, "debug mode") fullScreen := flag.Bool("fullscreen", false, "go fullscreen") cpuProfile := flag.String("cpuprofile", "", "write cpu profile to file") help := flag.Bool("help", false, "Show usage") flag.Usage = usage flag.Parse() if *help { usage() return } if *cpuProfile != "" { f, err := os.Create(*cpuProfile) if err != nil { log.Fatal(err) } pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } application.Verbose = *verbose application.Debug = *debug if sdl.Init(sdl.INIT_EVERYTHING) != 0 { log.Fatal(sdl.GetError()) } screen := sms.NewSDL2xScreen(*fullScreen) sdlLoop := sms.NewSDLLoop(screen) emulatorLoop := newEmulatorLoop(sdlLoop) if emulatorLoop == nil { usage() return } cpuProfiling := *cpuProfile != "" commandLoop := newCommandLoop(emulatorLoop, sdlLoop, cpuProfiling) inputLoop := sms.NewInputLoop(emulatorLoop.sms) application.Register("Emulator loop", emulatorLoop) application.Register("Command loop", commandLoop) application.Register("SDL render loop", sdlLoop) application.Register("SDL input loop", inputLoop) exitCh := make(chan bool) application.Run(exitCh) <-exitCh sdl.Quit() }
func (v *Video) Init(t <-chan []uint32, n string) chan [2]int { v.tick = t v.resize = make(chan [2]int) if sdl.Init(sdl.INIT_VIDEO|sdl.INIT_JOYSTICK|sdl.INIT_AUDIO) != 0 { log.Fatal(sdl.GetError()) } v.screen = sdl.SetVideoMode(512, 480, 32, sdl.OPENGL|sdl.RESIZABLE) if v.screen == nil { log.Fatal(sdl.GetError()) } sdl.WM_SetCaption(fmt.Sprintf("Fergulator - %s", n), "") if gl.Init() != 0 { panic(sdl.GetError()) } gl.Enable(gl.TEXTURE_2D) v.Reshape(int(v.screen.W), int(v.screen.H)) v.tex = gl.GenTexture() v.fpsmanager = gfx.NewFramerate() v.fpsmanager.SetFramerate(70) joy = make([]*sdl.Joystick, sdl.NumJoysticks()) for i := 0; i < sdl.NumJoysticks(); i++ { joy[i] = sdl.JoystickOpen(i) fmt.Println("-----------------") if joy[i] != nil { fmt.Printf("Joystick %d\n", i) fmt.Println(" Name: ", sdl.JoystickName(0)) fmt.Println(" Number of Axes: ", joy[i].NumAxes()) fmt.Println(" Number of Buttons: ", joy[i].NumButtons()) fmt.Println(" Number of Balls: ", joy[i].NumBalls()) } else { fmt.Println(" Couldn't open Joystick!") } } return v.resize }
func BenchmarkCPU(b *testing.B) { if sdl.Init(sdl.INIT_EVERYTHING) != 0 { log.Fatal(sdl.GetError()) } screen := smslib.NewSDL2xScreen(false) displayLoop := smslib.NewSDLLoop(screen) go displayLoop.Run() sms := smslib.NewSMS(displayLoop) sms.LoadROM("../roms/blockhead.sms") b.ResetTimer() for i := 0; i < b.N; i++ { sms.RenderFrame() } }
func (this *RenderManager) Init() { this.tmx.Load("./test_cute.tmx") if sdl.Init(sdl.INIT_EVERYTHING) != 0 { log.Fatal(sdl.GetError()) } this.screen = sdl.SetVideoMode(707, 600, 32, sdl.RESIZABLE) if this.screen == nil { log.Fatal(sdl.GetError()) } var video_info = sdl.GetVideoInfo() println("HW_available = ", video_info.HW_available) println("WM_available = ", video_info.WM_available) println("Video_mem = ", video_info.Video_mem, "kb") sdl.EnableUNICODE(1) sdl.WM_SetCaption("Go-SDL SDL Test", "") if sdl.GetKeyName(270) != "[+]" { log.Fatal("GetKeyName broken") } this.ressourceManager = NewSpriteLoader() this.ressourceManager.Load("test_tileset.gspr") // this.animMap = ressourceManager.GetAnimMap() }
func (v *Video) Init(t <-chan []uint32, n string) { v.videoTick = t if sdl.Init(sdl.INIT_VIDEO|sdl.INIT_JOYSTICK|sdl.INIT_AUDIO) != 0 { log.Fatal(sdl.GetError()) } v.screen = sdl.SetVideoMode(512, 480, 32, sdl.OPENGL|sdl.RESIZABLE|sdl.GL_DOUBLEBUFFER) if v.screen == nil { log.Fatal(sdl.GetError()) } sdl.WM_SetCaption(fmt.Sprintf("Fergulator - %s", n), "") v.initGL() v.Reshape(int(v.screen.W), int(v.screen.H)) v.fpsmanager = gfx.NewFramerate() v.fpsmanager.SetFramerate(60) return }
func initSDL() { if sdl.Init(sdl.INIT_VIDEO) != 0 { panic(sdl.GetError()) } }