Game Development Reference
In-Depth Information
Gl.glVertex3d( x - halfWidth, y - halfHeight, z); // bottom left
Gl.glTexCoord2d(rightUV, topUV);
Gl.glVertex3d(x + halfWidth, y + halfHeight, z); // top right
Gl.glTexCoord2d(rightUV, bottomUV);
Gl.glVertex3d(x + halfWidth, y - halfHeight, z); // bottom right
Gl.glTexCoord2d(leftUV, bottomUV);
Gl.glVertex3d(x - halfWidth, y - halfHeight, z); // bottom left
}
Gl.glEnd();
It is now easy to change around the UV coordinates. Set the top left to 0,0 and the
bottom right to 2,2. Then change the bottom right to
1. Play around with
different position for the top-left and bottom-right coordinates to see what
happens.
1,
Alpha Blending Sprites
It is very common to want to make part of a sprite transparent. There is a second
sprite called face_alpha.tif available on the CD in the Assets folder. This image
file has four channels, red, green, blue, and alpha. The alpha channel removes the
white border around the smiley face. The face_alpha file should be added to the
project in the same way as the previous texture. It then needs to be loaded into
the TextureManager .
// Load textures
_textureManager.LoadTexture("face", "face.tif");
_textureManager.LoadTexture("face_alpha", "face_alpha.tif");
In the Render call of DrawSpriteState , change the line
Texture texture = _textureManager.Get("face");
to
Texture texture = _textureManager.Get("face_alpha");
Running the code now will produce exactly the same image as before. This is
because OpenGL hasn't been told to deal with transparency yet. Transparency in
OpenGL is achieved by blending. OpenGL blends the pixels that have already
been drawn to the frame buffer with whatever pixels are about to be drawn to the
frame buffer.
 
Search WWH ::




Custom Search