Example #1
0
File: gc.go Project: stanim/draw2d
func (p *Painter) Flush() {
	if len(p.vertices) != 0 {
		gl.EnableClientState(gl.COLOR_ARRAY)
		gl.EnableClientState(gl.VERTEX_ARRAY)
		gl.ColorPointer(4, gl.UNSIGNED_BYTE, 0, gl.Ptr(p.colors))
		gl.VertexPointer(2, gl.INT, 0, gl.Ptr(p.vertices))

		// draw lines
		gl.DrawArrays(gl.LINES, 0, int32(len(p.vertices)/2))
		gl.DisableClientState(gl.VERTEX_ARRAY)
		gl.DisableClientState(gl.COLOR_ARRAY)
		p.vertices = p.vertices[0:0]
		p.colors = p.colors[0:0]
	}
}
Example #2
0
func List(width, height int, list *draw.List) {
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.Enable(gl.SCISSOR_TEST)
	defer gl.Disable(gl.SCISSOR_TEST)

	gl.EnableClientState(gl.VERTEX_ARRAY)
	defer gl.DisableClientState(gl.VERTEX_ARRAY)

	gl.EnableClientState(gl.COLOR_ARRAY)
	defer gl.DisableClientState(gl.COLOR_ARRAY)

	gl.EnableClientState(gl.TEXTURE_COORD_ARRAY)
	defer gl.DisableClientState(gl.TEXTURE_COORD_ARRAY)

	gl.VertexPointer(2, gl.FLOAT, vertexStride, unsafe.Pointer(&(list.Vertices[0].P)))
	gl.TexCoordPointer(2, gl.FLOAT, vertexStride, unsafe.Pointer(&(list.Vertices[0].UV)))
	gl.ColorPointer(4, gl.UNSIGNED_BYTE, vertexStride, unsafe.Pointer(&(list.Vertices[0].Color)))

	offset := 0
	for _, cmd := range list.Commands {
		if cmd.Count == 0 {
			continue
		}
		if cmd.Texture == 0 {
			gl.Disable(gl.TEXTURE_2D)
		} else {
			gl.Enable(gl.TEXTURE_2D)
			gl.BindTexture(gl.TEXTURE_2D, uint32(cmd.Texture))
		}

		x, y, w, h := cmd.Clip.AsInt32()
		gl.Scissor(x, int32(height)-y-h, w, h)
		gl.DrawElements(gl.TRIANGLES, int32(cmd.Count), indexType, gl.Ptr(list.Indicies[offset:]))
		offset += int(cmd.Count)
	}
}