Exemplo n.º 1
0
func (r *Renderer) Render() {
	gl.EnableClientState(gl.VERTEX_ARRAY)

	rVbo := r.Vbos[0]
	gl.BindBuffer(gl.ARRAY_BUFFER, rVbo.Id)

	for _, c := range r.Layer.Flatten() {
		renderable := c.GetRenderable()
		transform := c.GetTransform()

		if renderable == nil || transform == nil || !c.Visible() {
			continue
		}

		if rVbo != renderable.VboPosition.Vbo {
			rVbo = renderable.VboPosition.Vbo
			gl.BindBuffer(gl.ARRAY_BUFFER, rVbo.Id)
		}

		gl.VertexPointer(ValsInVertex, gl.FLOAT, 0, nil)

		if transform.NeedsUpdate {
			transform.Update()
		}

		gl.LoadMatrixf(&(transform.Matrix[0]))
		gl.DrawArrays(gl.QUADS, int32(renderable.VboPosition.Index/ValsInVertex),
			int32(renderable.Length/ValsInVertex))
	}

	gl.DisableClientState(gl.VERTEX_ARRAY)
}
Exemplo n.º 2
0
func (t *Transform) update() {
	gl.LoadMatrixf(&(t.parent.matrix[0]))
	gl.Translatef(t.position.X, t.position.Y, 0)
	gl.Rotatef(t.rotation, 0, 0, -1)
	gl.GetFloatv(gl.MODELVIEW_MATRIX, &(t.parent.matrix[0]))

	for _, c := range t.children {
		c.update()
	}
}
Exemplo n.º 3
0
func (t *Transform) Update() {
	var m *float32
	if t.parentTransform != nil {
		m = &(t.parentTransform.Matrix[0])
	} else {
		m = &(t.Matrix[0])
	}

	gl.LoadMatrixf(m)
	gl.Translatef(t.position.X, t.position.Y, 0)
	gl.Rotatef(t.rotation, 0, 0, -1)
	gl.GetFloatv(gl.MODELVIEW_MATRIX, &(t.Matrix[0]))
	t.NeedsUpdate = false

	for _, c := range t.childTransforms {
		c.Update()
	}
}