Game Development Reference
In-Depth Information
Gl.glBegin(Gl.GL_TRIANGLES);
{
Gl.glVertex3d( x - halfWidth, y + halfHeight, z); // top left
Gl.glVertex3d( x + halfWidth, y + halfHeight, z); // top right
Gl.glVertex3d( x - halfWidth, y - halfHeight, z); // bottom left
Gl.glVertex3d(x + halfWidth, y + halfHeight, z); // top right
Gl.glVertex3d(x + halfWidth, y - halfHeight, z); // bottom right
Gl.glVertex3d(x - halfWidth, y - halfHeight, z); // bottom left
}
Gl.glEnd();
This is equivalent to the previous code, but now the x, y, and z positions can be
altered. The position represents the center of the quad. Try changing the x, y, and
z values and move the quad about.
Managing Textures with DevIl
Textures are very easy to apply to the quad we have. The tricky part of textures is
loading them from the hard disk into memory. A texture class needs to be cre-
ated to represent the textures in memory, as well as a TextureManager class to
store the textures. Internally, OpenGL references textures by an integer id; the
texture struct will just store that id and the width and height of the texture.
public struct Texture
{
public int Id { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public Texture(int id, int width, int height) : this()
{
Id = id;
Width = width;
Height = height;
}
}
The texture class is quite straightforward. Its constructor calls the this con-
structor because it's a struct type and needs to have the members initialized for
the autogenerated assessor methods to use.
 
Search WWH ::




Custom Search