Game Development Reference
In-Depth Information
{
Gl.glEnable(Gl.GL_TEXTURE_2D);
Gl.glEnable(Gl.GL_BLEND);
Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
}
public void DrawImmediateModeVertex(Vector position, Color color,
Point uvs)
{
Gl.glColor4f(color.Red, color.Green, color.Blue, color.Alpha);
Gl.glTexCoord2f(uvs.X, uvs.Y);
Gl.glVertex3d(position.X, position.Y, position.Z);
}
public void DrawSprite(Sprite sprite)
{
Gl.glBegin(Gl.GL_TRIANGLES);
{
for(inti=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();
}
}
}
In the constructor, the Renderer sets up the relevant texture and blend modes.
These operations are now done once on start up rather than every frame as be-
fore. The DrawSprite function is responsible for taking a sprite and rendering
it. All the OpenGL calls are the same as before; there is one to set the texture and
then one for the color, texture, U,Vs, and position.
This leaves the sprite class itself. A lot of the functions can be inferred from its use
in the renderer. Games generally have a lot of sprites so it's important to make
the class as lightweight as possible and only include the most essential members.
 
Search WWH ::




Custom Search