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

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

}
Пример #3
0
func (s *Shader) initUniform(name string, uni *gl.Int) {
	uni_name := gl.GLString(name)
	defer gl.GLStringFree(uni_name)
	*uni = gl.GetUniformLocation(s.program, uni_name)
	if *uni == -1 {
		fmt.Println("Error in getting uniform", gl.GoString(uni_name))
	}
}
Пример #4
0
func (s *Shader) initAttribute(name string, att *gl.Uint) {
	att_name := gl.GLString(name)
	defer gl.GLStringFree(att_name)
	att_tmp := gl.GetAttribLocation(s.program, att_name)
	if att_tmp == -1 {
		fmt.Println("Error in getting attribute ", gl.GoString(att_name))
	} else {
		*att = gl.Uint(att_tmp)
	}
}