Beispiel #1
0
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
}
Beispiel #2
0
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
}
Beispiel #3
0
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
			}
		}
	}
}
Beispiel #4
0
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
}
Beispiel #5
0
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()
}
Beispiel #6
0
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
}
Beispiel #7
0
func (video *SDLVideo) SetCaption(caption string) {
	sdl.WM_SetCaption("nintengo - "+video.caption, "")
}