public class DrawQueue
extends java.lang.Object
Usage instructions:
Step 1: Create a DrawQueue. This only has to be done once, as the same DrawQueue can be reused an infinite amount of times. Make sure to pass in as high an initial capacity as you think you will use, as when this capacity is exceeded new native buffers will have to be allocated, which is a relatively expensive operation.
Step 2: Call setNextColor(java.awt.Color, float)
to set the
color of the following vertices. If you don't call this the DrawQueue will
use a default color of solid white, or whatever was used previously if you
are reusing an existing DrawQueue.
Step 3: Add the vertices of your shape with
addVertices(float[])
. You can change the color again
between sets of vertices.
Step 4: Once you are done setting up a shape call
finishShape(int)
with the draw mode that shape should use.
You must finish a shape after adding all vertices or you will
encounter graphical errors!
Step 5: Repeat steps 2-4 for each shape you wish to draw. Once all shapes
have been added to the DrawQueue, call finish()
to
finalize the contents and ready it for drawing.
Step 6: Call draw()
to draw the DrawQueue's contents. The
OpenGL client states GL11.GL_VERTEX_ARRAY
and
GL11.GL_COLOR_ARRAY
must be enabled for this method to function
correctly. You can call this method as many times as you want.
Step 7: When you need to reuse a DrawQueue, just return to Step 2. After finishing a DrawQueue it is ready for writing again.
Constructor and Description |
---|
DrawQueue(int initialCapacity)
Creates a new auto-resizing DrawQueue with the draw flag
GL15.GL_DYNAMIC_DRAW . |
DrawQueue(int initialCapacity,
int drawFlag)
Creates a new auto-resizing DrawQueue.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addVertex(float x,
float y)
Add a single vertex to the current shape.
|
boolean |
addVertex(org.lwjgl.util.vector.Vector2f vertex)
Add a single vertex to the current shape.
|
boolean |
addVertices(float[] vertices)
Add vertex data to the current shape.
|
boolean |
addVertices(java.util.List<org.lwjgl.util.vector.Vector2f> vertices)
Add vertex data to the current shape.
|
void |
clear()
Clears all data from the DrawQueue.
|
void |
draw()
Renders all data in the DrawQueue.
|
void |
finish()
Readies the list of shapes for drawing.
|
void |
finishShape(int shapeDrawMode)
Finalizes the current shape.
|
boolean |
isEmpty()
Checks whether this DrawQueue contains any vertex data yet.
|
static void |
releaseDeadQueues()
Releases the vertex and color buffers of all DrawQueues that have been
garbage collected.
|
void |
setNextColor(java.awt.Color color,
float alphaMod)
Sets the color of any vertices added after this method is called.
|
void |
setNextColor(float red,
float green,
float blue,
float alpha)
Sets the color of any vertices added after this method is called.
|
void |
setNextColor(int red,
int green,
int blue,
int alpha)
Sets the color of any vertices added after this method is called.
|
public DrawQueue(int initialCapacity)
GL15.GL_DYNAMIC_DRAW
.
initialCapacity
- The initial maximum number of vertices this
DrawQueue should hold, used for allocating native
buffers of the proper size. If this capacity is
exceeded new native buffers of the proper size
will be allocated automatically. Resizing is a
relatively expensive operation, so you should try
to set this to the maximum number of vertices you
expect the DrawQueue to hold over its lifetime.
public DrawQueue(int initialCapacity, int drawFlag)
initialCapacity
- The initial maximum number of vertices this
DrawQueue should hold, used for allocating native
buffers of the proper size. If this capacity is
exceeded new native buffers of the proper size
will be allocated automatically. Resizing is a
relatively expensive operation, so you should try
to set this to the maximum number of vertices you
expect the DrawQueue to hold over its lifetime.drawFlag
- The buffer data stream type, only used if VBOs are
active. Default is GL15.GL_DYNAMIC_DRAW
.
public static void releaseDeadQueues()
public void clear()
public boolean isEmpty()
true
if no vertices have been added to the DrawQueue,
false
otherwise.
public void setNextColor(java.awt.Color color, float alphaMod)
color
- The color of the next shape. All vertices added until
this method is called again will use this color.alphaMod
- Multiplies color
's alpha channel by this number
(should be between 0 and 1). You will usually pass in
CommonRadar.getContactAlpha()
for contacts, or
CommonRadar.getRadarAlpha()
for UI elements. Also
useful to avoid creating a new Color object every frame
just to add fade effects.
public void setNextColor(float red, float green, float blue, float alpha)
red
- The red channel value of the color you wish to use (should
be between 0 and 1).green
- The green channel value of the color you wish to use (should
be between 0 and 1).blue
- The blue channel value of the color you wish to use (should
be between 0 and 1).alpha
- The alpha channel value of the color you wish to use (should
be between 0 and 1).
public void setNextColor(int red, int green, int blue, int alpha)
red
- The red channel value of the color you wish to use (should
be between 0 and 255).green
- The green channel value of the color you wish to use (should
be between 0 and 255).blue
- The blue channel value of the color you wish to use (should
be between 0 and 255).alpha
- The alpha channel value of the color you wish to use (should
be between 0 and 255).
public boolean addVertices(float[] vertices)
vertices
- The vertex x,y pairs to be added.
true
if the DrawQueue had to resize to fit
vertices
, false
otherwise.
public boolean addVertices(java.util.List<org.lwjgl.util.vector.Vector2f> vertices)
vertices
- The vertices to be added.
true
if the DrawQueue had to resize to fit
vertices
, false
otherwise.
public boolean addVertex(float x, float y)
x
- The x coordinate of the vertex to be added.y
- The y coordinate of the vertex to be added.
true
if the DrawQueue had to resize to fit
vertex
, false
otherwise.
public boolean addVertex(org.lwjgl.util.vector.Vector2f vertex)
vertex
- The vertex to be added.
true
if the DrawQueue had to resize to fit
vertex
, false
otherwise.
public void finishShape(int shapeDrawMode)
shapeDrawMode
- The draw mode for this shape (what you would
normally call with GL11.glBegin(int)
).
public void finish()
draw()
, otherwise an exception will be thrown!
Once this method has been called, any further calls to
addVertices(float[])
will replace the
DrawQueue's existing contents, not add to them.
public void draw()
finish()
must be
called before using this. This method requires OpenGL client states
GL11.GL_VERTEX_ARRAY
and GL11.GL_COLOR_ARRAY
to be
enabled.