Game Development Reference
In-Depth Information
Setup2DGraphics(ClientSize.Width, ClientSize.Height);
_fastLoop = new FastLoop(GameLoop);
}
The projection matrix will need re-creating anytime the form changes size.
Therefore, a call to
Setup2DGraphics
should also be added to the
On-
ClientSizeChanged
callback.
protected override void OnClientSizeChanged(EventArgs e)
{
base.OnClientSizeChanged(e);
Gl.glViewport(0, 0, this.ClientSize.Width, this.ClientSize.Height);
Setup2DGraphics(ClientSize.Width, ClientSize.Height);
}
The title state renders a triangle, but the triangle's maximum width is only
1 OpenGL unit. The previous projection matrix had a width and height of 2 so the
triangle appeared a good size. The width and height of this new projection matrix
is 1280 and 720 so the triangle barely takes up a pixel and therefore cannot be seen!
An easy way to fix this is to make the triangle bigger. Find the triangle drawing
code and make the width and height 50 instead of 1.
Gl.glColor4d(1.0, 0.0, 0.0, 0.5);
Gl.glVertex3d(-50, 0, 0);
Gl.glColor3d(0.0, 1.0, 0.0);
Gl.glVertex3d(50, 0, 0);
Gl.glColor3d(0.0, 0.0, 1.0);
Gl.glVertex3d(0, 50, 0);
This will make the triangle visible once again. Most 2D graphics use two triangles
to make a quad. This quad then has a texture applied to it and forms the basis of
a 2D game or heads-up display.
The first step of creating a sprite is to create a quad. A triangle is made of three
vertices; a quad is made of four. See Figure 6.5. A sprite is a pretty basic game
element, and it's a good idea to make it into its own class. There will also be a
class responsible for drawing the sprites. This class will be called the
Renderer
.
Before implementing the
Renderer
and
Sprite
classes, it's useful to first
Search WWH ::
Custom Search