Game Development Reference
In-Depth Information
Random r ¼ new Random();
Gl.glClearColor((float)r.NextDouble(), (float)r.NextDouble(), (float)
r.NextDouble(), 1.0f);
Vertices
Vertices are the building blocks that make up virtual worlds. At their most basic
they are position information; x and y for a two-dimensional world; x, y, and z
for a three-dimensional world.
It's easy to introduce vertices in OpenGL using immediate mode. Immediate
mode is a way of telling the graphics card what to draw. These commands need
to be sent every frame, even if nothing has changed. It's not the fastest way to do
OpenGL programming, but it is the easiest way to learn.
Let's begin by drawing a point.
void GameLoop(double elapsedTime)
{
Gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
Gl.glBegin(Gl.GL_POINTS);
{
Gl.glVertex3d(0, 0, 0);
}
Gl.glEnd();
Gl.glFinish();
_openGLControl.Refresh();
}
There are three new OpenGL commands here. glBegin tells the graphics
card that you will be drawing something. glBegin takes one argument;
this describes what you will be drawing. The value passed in is GL_POINTS ;
this tells OpenGL to render any vertices as points (as opposed to triangles or
quads).
glBegin must be followed by glEnd . Immediately after glBegin , there is an
opening brace. This isn't strictly necessary; it just provides indentation so that
it's clear where the glEnd should go. In between the parentheses is a glVertex
command; the command ends in 3d . The 3 means it will use three dimensions—
an x, y, and z—to make up the position. The d means the positions are expected
to be doubles.
 
Search WWH ::




Custom Search