func newBox(width, height float32) *box { var err error box := new(box) // Sound player box.player, err = mandala.NewAudioPlayer() if err != nil { mandala.Fatalf("%s\n", err.Error()) } // Chipmunk body box.physicsShape = chipmunk.NewBox( vect.Vect{0, 0}, vect.Float(width), vect.Float(height), ) box.physicsShape.SetElasticity(BoxElasticity) box.physicsBody = chipmunk.NewBody(vect.Float(BoxMass), box.physicsShape.Moment(float32(BoxMass))) box.physicsBody.AddShape(box.physicsShape) box.physicsBody.CallbackHandler = callbacks{} // OpenGL shape box.openglShape = shapes.NewBox(width, height) return box }
func (t *TestSuite) TestAudio() { // Open an audio file from resources responseCh := make(chan mandala.LoadResourceResponse) mandala.ReadResource("raw/android.raw", responseCh) response := <-responseCh buffer := response.Buffer t.True(response.Error == nil, "An error occured during resource opening") // Create the audio player player, err := mandala.NewAudioPlayer() t.True(err == nil) // Hum...this seems to fail for now max, err := player.GetMaxVolumeLevel() t.True(err == nil, "Error in getting the max volume level") t.True(max > 0, fmt.Sprintf("Max volume level is %d", max)) if player != nil { player.Play(buffer, nil) } }
func newWorld(width, height int) *world { world := &world{ width: width, height: height, projMatrix: mathgl.Ortho2D(0, float32(width), 0, float32(height)), viewMatrix: mathgl.Ident4f(), space: chipmunk.NewSpace(), } world.space.Gravity = vect.Vect{0, Gravity} // Initialize the audio player var err error world.explosionPlayer, err = mandala.NewAudioPlayer() if err != nil { mandala.Fatalf("%s\n", err.Error()) } // Read the PCM audio samples responseCh := make(chan mandala.LoadResourceResponse) mandala.ReadResource("raw/explosion.pcm", responseCh) response := <-responseCh if response.Error != nil { mandala.Fatalf(response.Error.Error()) } world.explosionBuffer = response.Buffer responseCh = make(chan mandala.LoadResourceResponse) mandala.ReadResource("raw/impact.pcm", responseCh) response = <-responseCh if response.Error != nil { mandala.Fatalf(response.Error.Error()) } world.impactBuffer = response.Buffer return world }
func NewWorld(width, height int) *World { world := &World{ width: width, height: height, projMatrix: mathgl.Ortho2D(0, float32(width), 0, float32(height)), viewMatrix: mathgl.Ident4f(), space: chipmunk.NewSpace(), } world.space.Gravity = vect.Vect{0, Gravity} // Initialize the audio players var err error world.explosionPlayer, err = mandala.NewAudioPlayer() if err != nil { mandala.Fatalf("%s\n", err.Error()) } world.impactPlayer, err = mandala.NewAudioPlayer() if err != nil { mandala.Fatalf("%s\n", err.Error()) } // Read the PCM audio samples responseCh := make(chan mandala.LoadResourceResponse) mandala.ReadResource("raw/explosion.pcm", responseCh) response := <-responseCh if response.Error != nil { mandala.Fatalf(response.Error.Error()) } world.explosionBuffer = response.Buffer responseCh = make(chan mandala.LoadResourceResponse) mandala.ReadResource("raw/impact.pcm", responseCh) response = <-responseCh if response.Error != nil { mandala.Fatalf(response.Error.Error()) } world.impactBuffer = response.Buffer // Compile the shaders world.boxProgramShader = shaders.NewProgram(shapes.DefaultBoxFS, shapes.DefaultBoxVS) world.segmentProgramShader = shaders.NewProgram(shapes.DefaultSegmentFS, shapes.DefaultSegmentVS) // Load the font responseCh = make(chan mandala.LoadResourceResponse) mandala.ReadResource("raw/freesans.ttf", responseCh) response = <-responseCh fontBuffer := response.Buffer err = response.Error if err != nil { panic(err) } world.font, err = gltext.LoadTruetype(bytes.NewBuffer(fontBuffer), world, 12, 32, 127, gltext.LeftToRight) if err != nil { panic(err) } return world }