Example #1
0
func LoadShaders(glctx gl.Context, program gl.Program, vertexAsset, fragmentAsset string) error {
	vertexShader, err := loadShader(glctx, gl.VERTEX_SHADER, vertexAsset)
	if err != nil {
		return err
	}
	fragmentShader, err := loadShader(glctx, gl.FRAGMENT_SHADER, fragmentAsset)
	if err != nil {
		glctx.DeleteShader(vertexShader)
		return err
	}

	if glctx.GetProgrami(program, gl.ATTACHED_SHADERS) > 0 {
		for _, shader := range glctx.GetAttachedShaders(program) {
			glctx.DetachShader(program, shader)
		}
	}

	glctx.AttachShader(program, vertexShader)
	glctx.AttachShader(program, fragmentShader)
	glctx.LinkProgram(program)

	// Flag shaders for deletion when program is unlinked.
	glctx.DeleteShader(vertexShader)
	glctx.DeleteShader(fragmentShader)

	if glctx.GetProgrami(program, gl.LINK_STATUS) == 0 {
		defer glctx.DeleteProgram(program)
		return fmt.Errorf("LoadShaders: %s", glctx.GetProgramInfoLog(program))
	}
	return nil
}
Example #2
0
//停止时触发,清理
func onStop(glctx gl.Context) {
	glctx.DeleteProgram(program)
	glctx.DeleteBuffer(positionbuf)
	glctx.DeleteBuffer(colorbuf)
	fps.Release()
	images.Release()
}
Example #3
0
// CreateProgram creates, compiles, and links a gl.Program.
func CreateProgram(glctx gl.Context, vertexSrc, fragmentSrc string) (gl.Program, error) {
	program := glctx.CreateProgram()
	if program.Value == 0 {
		return gl.Program{}, fmt.Errorf("glutil: no programs available")
	}

	vertexShader, err := loadShader(glctx, gl.VERTEX_SHADER, vertexSrc)
	if err != nil {
		return gl.Program{}, err
	}
	fragmentShader, err := loadShader(glctx, gl.FRAGMENT_SHADER, fragmentSrc)
	if err != nil {
		glctx.DeleteShader(vertexShader)
		return gl.Program{}, err
	}

	glctx.AttachShader(program, vertexShader)
	glctx.AttachShader(program, fragmentShader)
	glctx.LinkProgram(program)

	// Flag shaders for deletion when program is unlinked.
	glctx.DeleteShader(vertexShader)
	glctx.DeleteShader(fragmentShader)

	if glctx.GetProgrami(program, gl.LINK_STATUS) == 0 {
		defer glctx.DeleteProgram(program)
		return gl.Program{}, fmt.Errorf("glutil: %s", glctx.GetProgramInfoLog(program))
	}
	return program, nil
}
Example #4
0
File: main.go Project: bmatsuo/rex
func onStop(glctx gl.Context) {
	glctx.DeleteProgram(program)
	glctx.DeleteBuffer(buf)
	fps.Release()
	if statusPainter != nil {
		statusPainter.Release()
	}
	images.Release()
}
Example #5
0
// Use this to exit your game safely
// It will automatically unload all your assets and dispose the stage
// Schedule an exit from the application. On android, this will cause a call to pause() and dispose() some time in the future,
// it will not immediately finish your application.
// On iOS this should be avoided in production as it breaks Apples guidelines
func appStop(glctx gl.Context) {
	println("Exiting")
	running = false
	if currentScene.OnPause != nil {
		currentScene.OnPause(currentScene)
		soundsPlayer.Close()
	}
	glctx.DeleteProgram(program)
	glctx.DeleteBuffer(buf)
	fps.Release()
	images.Release()
}
Example #6
0
func onStop(glctx gl.Context) {
	manager.StopLayers()
	glctx.DeleteProgram(frameData.Program)
}
Example #7
0
func onStop(glctx gl.Context) {
	glctx.DeleteProgram(program)
	glctx.DeleteBuffer(buf)
	fps.Release()
	images.Release()
}
Example #8
0
func (prg Program) Delete(ctx gl.Context) {
	ctx.DeleteProgram(prg.Program)
}
Example #9
0
func onStop(glctx gl.Context) {
	glctx.DeleteProgram(program)
	board.Release()
	ReleaseSound()
}