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] } }
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) }
func (r *Renderer) Render() { gl.EnableClientState(gl.VERTEX_ARRAY) for _, g := range r.GameObjects { gl.BindBuffer(gl.ARRAY_BUFFER, g.VboPosition.Vbo.Id) gl.VertexPointer(2, gl.FLOAT, 0, nil) gl.DrawArrays(gl.QUADS, 0, int32(4)) } gl.DisableClientState(gl.VERTEX_ARRAY) }
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) } }