Пример #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
}
Пример #2
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
}