Game Development Reference
In-Depth Information
Texture texture = _textureManager.Get("face");
Gl.glEnable(Gl.GL_TEXTURE_2D);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture.Id);
Gl.glBegin(Gl.GL_TRIANGLES);
{
Gl.glTexCoord2d(0, 0);
Gl.glVertex3d( x - halfWidth, y + halfHeight, z); // top left
Gl.glTexCoord2d(1, 0);
Gl.glVertex3d( x + halfWidth, y + halfHeight, z); // top right
Gl.glTexCoord2d(0, 1);
Gl.glVertex3d( x - halfWidth, y - halfHeight, z); // bottom left
The second triangle's vertices are set in the same way.
Gl.glTexCoord2d(1, 0);
Gl.glVertex3d(x + halfWidth, y + halfHeight, z); // top right
Gl.glTexCoord2d(1, 1);
Gl.glVertex3d(x + halfWidth, y - halfHeight, z); // bottom right
Gl.glTexCoord2d(0, 1);
Gl.glVertex3d(x - halfWidth, y - halfHeight, z); // bottom left
This will now map the texture to a quad entirely. Try changing the size of the
quad to see what happens.
The texture has been applied using a lot of magic numbers and these should be
moved to variables according to the DRY principle. The U,V mapping for
the quad can be described by two coordinates, the top-left U,V positions and the
bottom-right U,V positions.
float topUV = 0;
float bottomUV = 1;
float leftUV = 0;
float rightUV = 1;
Gl.glBegin(Gl.GL_TRIANGLES);
{
Gl.glTexCoord2d(leftUV, topUV);
Gl.glVertex3d( x - halfWidth, y + halfHeight, z); // top left
Gl.glTexCoord2d(rightUV, topUV);
Gl.glVertex3d( x + halfWidth, y + halfHeight, z); // top right
Gl.glTexCoord2d(leftUV, bottomUV);
Search WWH ::




Custom Search