public class VertexBuffer extends Object
FloatBuffer
and makes it easier to push 2-D vertices
into the buffer and then draw them using any mode desired. The default
constructor uses a global buffer since drawing in OpenGL is not
multi-threaded.Constructor and Description |
---|
VertexBuffer(int capacity)
Creates a private buffer.
|
Modifier and Type | Method and Description |
---|---|
void |
addVertex(float[] array,
int offset,
int numVertices)
Adds multiple vertices to the buffer.
|
void |
addVertex(float x,
float y)
Adds a vertex to the buffer.
|
void |
addVertices(FloatBuffer vertices)
Adds multiple vertices to the buffer.
|
void |
clear()
Discard all existing points.
|
void |
drawBuffer(GL2 gl,
int mode)
Draws the vertices and rewinds the buffer to be ready to draw next time.
|
FloatBuffer |
getBuffer() |
static VertexBuffer |
getSharedBuffer()
Creates a buffer that uses the shared global buffer.
|
public VertexBuffer(int capacity)
capacity
- The size of the buffer in number of verticespublic static VertexBuffer getSharedBuffer()
#VertexBuffer(int)
.public void addVertex(float[] array, int offset, int numVertices)
array
- The array containing vertices in the form (x,y),(x,y)offset
- The starting indexnumVertices
- The number of vertices, pairs of floatspublic void addVertex(float x, float y)
x
- The x coordinatey
- The y coordinatepublic void addVertices(FloatBuffer vertices)
vertices
- The buffer of new vertices to add.public void clear()
public FloatBuffer getBuffer()
public void drawBuffer(GL2 gl, int mode)
gl
- The graphics context to use to drawmode
- The mode, e.g. GL#GL_LINE_STRIP
Copyright © 2010-2013. All Rights Reserved.