Esempio n. 1
0
// Draw actually renders the shape on the surface.
func (box *Box) Draw() {
	box.program.Use()

	gl.VertexAttribPointer(box.posId, 2, gl.FLOAT, false, 0, &box.vertices[0])
	gl.EnableVertexAttribArray(box.posId)

	gl.VertexAttribPointer(box.colorId, 4, gl.FLOAT, false, 0, &box.vColor[0])
	gl.EnableVertexAttribArray(box.colorId)

	gl.UniformMatrix4fv(int32(box.modelMatrixId), 1, false, (*float32)(&box.modelMatrix[0]))
	gl.UniformMatrix4fv(int32(box.projMatrixId), 1, false, (*float32)(&box.projMatrix[0]))
	gl.UniformMatrix4fv(int32(box.viewMatrixId), 1, false, (*float32)(&box.viewMatrix[0]))

	gl.Uniform1f(int32(box.texRatioId), 0.0)

	// Texture
	if len(box.texCoords) > 0 {
		gl.Uniform1f(int32(box.texRatioId), 1.0)
		gl.VertexAttribPointer(box.texInId, 2, gl.FLOAT, false, 0, &box.texCoords[0])
		gl.EnableVertexAttribArray(box.texInId)
		gl.ActiveTexture(gl.TEXTURE0)
		gl.BindTexture(gl.TEXTURE_2D, box.texBuffer)
		gl.Uniform1i(int32(box.textureId), 0)
	}

	gl.DrawArrays(gl.TRIANGLE_STRIP, 0, 4)

	gl.Flush()
	gl.Finish()
}
Esempio n. 2
0
func (renderState *renderState) draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT)

	gl.VertexAttribPointer(attrPos, 4, gl.FLOAT, false, 6*4, &vertices[0])
	gl.VertexAttribPointer(attrTexIn, 2, gl.FLOAT, false, 6*4, &vertices[4])

	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, textureBuffer)
	gl.Uniform1i(int32(unifTexture), 0)

	gl.DrawArrays(gl.TRIANGLE_FAN, 0, 4)
	gl.Flush()
	gl.Finish()
}
Esempio n. 3
0
// Draw actually renders the segment on the surface.
func (segment *Segment) Draw() {
	segment.program.Use()
	gl.VertexAttribPointer(segment.posId, 2, gl.FLOAT, false, 0, &segment.vertices[0])
	gl.EnableVertexAttribArray(segment.posId)

	gl.VertexAttribPointer(segment.colorId, 4, gl.FLOAT, false, 0, &segment.vColor[0])
	gl.EnableVertexAttribArray(segment.colorId)

	gl.UniformMatrix4fv(int32(segment.modelMatrixId), 1, false, (*float32)(&segment.modelMatrix[0]))
	gl.UniformMatrix4fv(int32(segment.projMatrixId), 1, false, (*float32)(&segment.projMatrix[0]))
	gl.UniformMatrix4fv(int32(segment.viewMatrixId), 1, false, (*float32)(&segment.viewMatrix[0]))

	gl.DrawArrays(gl.LINES, 0, 2)

	gl.Flush()
	gl.Finish()
}