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
}
Example #2
0
func render(w *glfw.Window, program uint32) {
	gl.ClearColor(0, 0, 0, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.UseProgram(program)
	gl.BindVertexArray(firstSprite.GetVAO())
	gl.DrawArrays(gl.TRIANGLES, 0, 6)

	//Swap buffers
	w.SwapBuffers()
	glfw.PollEvents()
	gl.UseProgram(0)
}