Game Development Reference
In-Depth Information
void GameLoop(double elapsedTime)
{
_openGLControl.Refresh();
}
}
}
This game loop code is very similar to the code written before. Remember to add the
using Tao.OpenGl; statement or it won't have access to the OpenGL libraries.
GameLoop is called every frame. At the moment, it just refreshes the OpenGL
control. The refresh call tells the OpenGL control to update its graphics.
Running the program will give a boring black screen, but with the game loop set
up, that screen can now be changed.
void GameLoop(double elapsedTime)
{
Gl.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
Gl.glFinish();
_openGLControl.Refresh();
}
Three new lines have been added to the game loop. The first line tells OpenGL
what color to use to clear the screen. OpenGL represents colors as four values:
red, green, blue, and alpha. Alpha determines the transparency of the color:
1 is fully opaque, and 0 is fully transparent. Each value ranges from 0 to 1. In
this case, red has been set to 1, green and blue to zero, and alpha to 1 as well. This
will result in a bright red color. For the clear color, the alpha value is ignored.
The clear color only needs to be set once, but to keep all the new code together,
it's currently being set every frame.
The second line issues the clear command. This function uses the clear color we
set in the previous line to clear the screen. The final line, glFinish , tells
OpenGL that we've finished for this frame and to make sure all commands are
carried out.
Running the program will now give the window a new bright red background.
It's important to play with the library and get comfortable with it. Try switching
up the commands or changing the color. For example, review this code and try to
guess what will happen before running it.
 
Search WWH ::




Custom Search