func (s *Sprite) GetVAO() (VAO uint32) { gl.GenVertexArrays(1, &VAO) gl.BindVertexArray(VAO) gl.GenBuffers(1, &s.vbo) gl.BindBuffer(gl.ARRAY_BUFFER, s.vbo) gl.BufferData(gl.ARRAY_BUFFER, len(s.vertexData)*4, gl.Ptr(&s.vertexData[0]), gl.STATIC_DRAW) attrib_loc := uint32(gl.GetAttribLocation(s.program, gl.Str("vert\x00"))) color_loc := uint32(gl.GetAttribLocation(s.program, gl.Str("vertColor\x00"))) gl.EnableVertexAttribArray(attrib_loc) gl.VertexAttribPointer(attrib_loc, 3, gl.FLOAT, false, int32(unsafe.Sizeof(s.vertexData[0]))*7, nil) gl.EnableVertexAttribArray(color_loc) gl.VertexAttribPointer(color_loc, 4, gl.FLOAT, false, int32(unsafe.Sizeof(s.vertexData[0]))*7, gl.PtrOffset(3*4)) time_loc := gl.GetUniformLocation(s.program, gl.Str("time\x00")) gl.Uniform1f(time_loc, s.runtime) gl.BindBuffer(gl.ARRAY_BUFFER, 0) gl.BindVertexArray(0) //Update time := glfw.GetTime() elapsed := float32(time) - s.previousTime s.previousTime = float32(time) s.runtime = s.runtime + elapsed return }
func LoadShader(filename string, shader_type uint32) (shader uint32) { var shader_bytes []byte var shader_string string var shader_err error var status int32 shader = gl.CreateShader(shader_type) shader_bytes, shader_err = ioutil.ReadFile(filename) shader_bytes = append(shader_bytes, []byte("\x00")[0]) if shader_err != nil { log.Fatal("Could not load shader from file: ", filename) } shader_string = string(shader_bytes) csource := gl.Str(shader_string) gl.ShaderSource(shader, 1, &csource, nil) gl.CompileShader(shader) gl.GetShaderiv(shader, gl.COMPILE_STATUS, &status) if status == gl.FALSE { log.Printf("Compile error in shader %s:\n", filename) var logLength int32 gl.GetShaderiv(shader, gl.INFO_LOG_LENGTH, &logLength) l := strings.Repeat("\x00", int(logLength+1)) gl.GetShaderInfoLog(shader, logLength, nil, gl.Str(l)) log.Fatal(l) } return }