Graphics Reference
In-Depth Information
This next example shows drawing gridlines on a terrain map. The
already-defined Heights[ ] array holds the terrain heights. This is a good
example of using the RestartPrimitive( ) method so that the next grid
line doesn't have to be in a new line strip. In this way, the entire grid is
saved as a single line strip and is drawn by blasting a single VA / VBO into
the graphics pipeline.
VertexArray *VA;
. . .
// this goes in the part of the program where graphics things
// get initialized once:
VA = new VertexArray( ); // create an instance of the class
// the real “constructor” is in the glBegin method
VA->CollapseCommonVertices( true );
VA->UseBufferObjects( true );
VA->SetTol( .001f );
int x, y; // loop indices
float ux, uy;// utm coords
VA->glBegin( GL_LINE_STRIP );
for( y = 0, uy = meteryMin; y < NumLats; y++, uy += meteryStep )
{
VA->RestartPrimitive( );
for( x = 0, ux = meterxMin; x < NumLngs x++, ux += meterxStep
)
{
float uz = Heights[ y*NumLngs + x ];
VA->glColor3f( 1., 1., 0. ); // single color = yellow
VA->glVertex3f( ux, uy, uz );
}
}
for( x = 0, ux = meterxMin; x < NumLngs; x++, ux += meterxStep )
{
VA->RestartPrimitive( );
for( y = 0, uy = meteryMin; y < NumLats; y++, uy +=
meteryStep )
{
float uz = Heights[ y*NumLngs + x ];
VA->glColor3f( 1., 1., 0. );
Search WWH ::




Custom Search