Esempio n. 1
0
File: texture.go Progetto: dmac/gg
func (s *Sprite) Draw() {
	gg.UseProgram(s.program)

	vattrib, err := gg.GetAttribLocation(s.program, "vertex_position")
	if err != nil {
		log.Fatal(err)
	}
	gg.EnableVertexAttribArray(vattrib)
	gg.BindBuffer(gg.ARRAY_BUFFER, s.pvbo)
	gg.VertexAttribPointer(vattrib, 3, gg.FLOAT, false, 0, 0)

	tattrib, err := gg.GetAttribLocation(s.program, "vertex_texture")
	if err != nil {
		log.Fatal(err)
	}
	gg.EnableVertexAttribArray(tattrib)
	gg.BindBuffer(gg.ARRAY_BUFFER, s.tvbo)
	gg.VertexAttribPointer(tattrib, 2, gg.FLOAT, false, 0, 0)

	gg.ActiveTexture(gg.TEXTURE0)
	gg.BindTexture(gg.TEXTURE_2D, s.tex)
	texUniform, err := gg.GetUniformLocation(s.program, "tex_loc")
	if err != nil {
		log.Fatal(err)
	}
	gg.Uniform1i(texUniform, 0)

	gg.DrawArrays(gg.TRIANGLE_FAN, 0, 4)
}
Esempio n. 2
0
File: tetris.go Progetto: dmac/gg
func (s *Sprite) Draw() error {
	gg.UseProgram(s.program)

	model := s.transform()
	modelUniform, err := gg.GetUniformLocation(s.program, "model")
	if err != nil {
		return err
	}
	gg.UniformMatrix4fv(modelUniform, model[:])

	gg.ActiveTexture(gg.TEXTURE0)
	gg.BindTexture(gg.TEXTURE_2D, s.tex)
	textureUniform, err := gg.GetUniformLocation(s.program, "tex_loc")
	if err != nil {
		return err
	}
	gg.Uniform1i(textureUniform, 0)

	vattrib, err := gg.GetAttribLocation(s.program, "vertex_position")
	if err != nil {
		return err
	}
	gg.EnableVertexAttribArray(vattrib)
	gg.BindBuffer(gg.ARRAY_BUFFER, s.pbuf)
	gg.VertexAttribPointer(vattrib, 3, gg.FLOAT, false, 0, 0)

	tattrib, err := gg.GetAttribLocation(s.program, "vertex_texture")
	if err != nil {
		return err
	}
	gg.EnableVertexAttribArray(tattrib)
	gg.BindBuffer(gg.ARRAY_BUFFER, s.tbuf)
	gg.VertexAttribPointer(tattrib, 2, gg.FLOAT, false, 0, 0)

	gg.DrawArrays(gg.TRIANGLE_FAN, 0, 4)
	return nil
}