Game Development Reference
In-Depth Information
All the basic functionality to make the text class very usable has now been added.
Another good feature to add would be a scale; this would scale the text up and
down by a given amount.
longText.SetScale(0.5); // this would halve the text size
The MeasureText method could also be extended to take in a maxWidth
parameter. This way even if text is wrapped the width and height can be correctly
calculated.
Faster Rendering with glDrawArrays
Basic profiling using the frames per second count has shown that for 2D games,
the current code isn't that bad. But with only small changes, the performance can
be vastly improved.
public void DrawSprite(Sprite sprite)
{
Gl.glBegin(Gl.GL_TRIANGLES);
{
for (int i = 0; i < Sprite.VertexAmount; i++)
{
Gl.glBindTexture(Gl.GL_TEXTURE_2D, sprite.Texture.Id);
DrawImmediateModeVertex(
sprite.VertexPositions[i],
sprite.VertexColors[i],
sprite.VertexUVs[i]);
}
}
Gl.glEnd();
}
This is the current render code. It is executed once for each sprite. The problem
with the above code is that every time glEnd is called, everything is sent to the
graphics card and then the CPU stops; it does nothing until the graphics card
sends back a message saying it received all the vertices. With 10,000 sprites, that
mounts up to a lot of waiting. The more draw calls, the slower the game will run.
The solution to this problem is to draw as much as possible at once. Generally,
this is known as batching. Instead of the CPU talking to the GPU like ''Draw this,
now draw this sprite, now draw this sprite,'' it instead makes a list of all the
sprites and says to the GPU, ''Draw all these sprites.'' There is a lot less waiting so
 
 
Search WWH ::




Custom Search