Game Development Reference
In-Depth Information
glVertex3f(10.0f, -10.0f, -10.0f);
glVertex3f(-10.0f, -10.0f, -10.0f);
glVertex3f(-10.0f, 10.0f, -10.0f);
glVertex3f(10.0f, 10.0f, -10.0f);
In the example, pressing F2 toggles drawing the vertices by toggling the
Boolean value m_drawVertices. Notice how the glBegin call uses GL_
POINTS instead of GL_QUADS. When GL_POINTS is used each vertex
is drawn individually. The size of the vertex is a single pixel by default. In
this example, 'glPointSize' is used to set the vertex size to three pixels.
If the depth buffer is temporarily disabled before the vertices are drawn,
then the hidden vertex will be drawn. In the example F5 toggles the use
of the depth buffer.
Highlighting the object by drawing edge outlines
Another technique to highlight the object is to redraw the object edges.
Here we can use several different methods. OpenGL can use either lines,
in which case each pair of vertices is connected by a line in the current
colour, or line strips where the first two vertices indicate the first line. After
that, each subsequent vertex is connected by a line to the previous. The
final option is to use line loops which behave like line strips with the
addition that the first vertex is connected to the last. In the example I have
used line loops to draw the front and back faces, then used simple lines
to connect these faces. If you experiment with the code, changing the
method of drawing from line loops to line strips, you will see that the front
and back polygons have only three edges highlighted. Activating or
deactivating the depth buffer using F5 will give a clear idea of the effect of
depth testing when displaying even such a simple scene. The section of
code that enables the wireframe drawing is given below. The Boolean
variable m_drawWireframe is toggled using the F3 key.
if (m_drawWireframe){
glColor3f(1.0f, 1.0f, 0.5f);
glVertex3f(-10.0f, -10.0f, 10.0f);
glVertex3f(10.0f, -10.0f, 10.0f);
glVertex3f(10.0f, 10.0f, 10.0f);
glVertex3f(-10.0f, 10.0f, 10.0f);
Search Nedrilad ::

Custom Search