Exemplo n.º 1
0
func (s *Shader) initShader(t gl.Enum, str string, shader *gl.Uint) {
	*shader = gl.CreateShader(t)
	if *shader == 0 {
		fmt.Println("error creating shader of type ", t)
	}

	src := gl.GLStringArray(str)
	defer gl.GLStringArrayFree(src)

	gl.ShaderSource(*shader, 1, &src[0], nil)
	gl.CompileShader(*shader)

	var (
		status      gl.Int
		info_length gl.Int
		message     *gl.Char
	)

	gl.GetShaderiv(*shader, gl.COMPILE_STATUS, &status)
	if status == gl.FALSE {
		fmt.Println("Error compiling shader")
		gl.GetShaderiv(*shader, gl.INFO_LOG_LENGTH, &info_length)
		message = gl.GLStringAlloc(gl.Sizei(info_length))
		gl.GetShaderInfoLog(*shader, gl.Sizei(info_length), nil, message)
		fmt.Println(gl.GoString(message))
		gl.GLStringFree(message)
	}

}
Exemplo n.º 2
0
func (s *Shader) initWithString(vert_shader string, frag_shader string) {

	s.initShader(gl.VERTEX_SHADER, vert_shader, &s.vert_shader)
	s.initShader(gl.FRAGMENT_SHADER, frag_shader, &s.frag_shader)

	s.program = gl.CreateProgram()

	gl.AttachShader(s.program, s.vert_shader)
	gl.AttachShader(s.program, s.frag_shader)
	gl.LinkProgram(s.program)

	var (
		status      gl.Int
		info_length gl.Int
		message     *gl.Char
	)

	gl.GetProgramiv(s.program, gl.LINK_STATUS, &status)
	if status == gl.FALSE {
		fmt.Println("Error linking program")
		gl.GetProgramiv(s.program, gl.INFO_LOG_LENGTH, &info_length)
		message = gl.GLStringAlloc(gl.Sizei(info_length))
		gl.GetProgramInfoLog(s.program, gl.Sizei(info_length), nil, message)
		fmt.Println(gl.GoString(message))
		gl.GLStringFree(message)
	}

	s.initAttributes()
	s.initUniforms()

}