Game Development Reference
In-Depth Information
The batch collects Sprites and the function it uses to do this is AddSprite .
AddSprite first checks if adding this sprite will make the batch too big. If that's
the case, it forces the current batch to be drawn and emptied. The sprite vertex
information is then iterated through and added to the batch arrays.
Two more functions handle the drawing of the batch.
const int VertexDimensions = 3;
const int ColorDimensions = 4;
const int UVDimensions = 2;
void SetupPointers()
{
Gl.glEnableClientState(Gl.GL_COLOR_ARRAY);
Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY);
Gl.glVertexPointer(VertexDimensions, Gl.GL_DOUBLE, 0,
_vertexPositions);
Gl.glColorPointer(ColorDimensions, Gl.GL_FLOAT, 0, _vertexColors);
Gl.glTexCoordPointer(UVDimensions, Gl.GL_FLOAT, 0, _vertexUVs);
}
public void Draw()
{
if (_batchSize == 0)
{
return;
}
SetupPointers();
Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, _batchSize);
_batchSize = 0;
}
The Draw function is the more important of the two here. If the batch is empty, the
Draw function does nothing. Otherwise, it calls the SetupPointers function.
SetupPointers first describes the vertex format using glEnableClient-
State . In this case, the vertex described has color, position, and U,V information.
Once this is done, OpenGL is told where this information exists using the
glPointer calls.
All glPointer calls are of the same general format. The first argument is the
number of elements. The glVertexPointer controls the position and has
three elements; one each for X, Y, and Z. Texture is defined with two elements,
 
Search WWH ::




Custom Search