Graphics Reference
In-Depth Information
1
2
3
int main( int argc, char ** argv )
{
glutInit( &argc, argv ); // Boilerplate initialization
Next we request color support and depth buffering (also known as Z-buffering,
used for hidden-surface removal as described in Chapter 36):
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH );
Then, we call a sequence of three GLUT functions to create the window that
will be assigned to our application. The first two function calls allow us to specify
the optimal initial size and position for the new window.
1
2
3
4
5
6
// Specify window position (from top corner)
glutInitWindowPosition( 50, 50 );
// Specify window size in pixels (width, height)
glutInitWindowSize( 640, 480 );
// Create window and specify its title
glutCreateWindow( "OpenGL Example" );
The result is a window whose client area (see Section 2.2) has the specified
position and size. The application is free to further divide the client area into
different regions; for example, to include user-interface controls. In the following
call to glViewport , we reserve the entire client area for use as the 3D viewport:
1
2
3
glViewport(
/ * lower-left corner of the viewport * /
0, 0,
/ * width, height of the viewport * /
640, 480 );
OpenGL provides a variety of rendering effects, and with the function calls
shown below, we specify that the front side of each triangle be filled using
Gouraud's smooth shading. (Alternatively, we can make the pipeline act as a point
plotter or as a wireframe renderer, for example.)
1
2
3
4
5
// Specify Gouraud shading
glShadeModel( GL_SMOOTH );
// Specify solid (not wireframe) rendering
glPolygonMode( GL_FRONT, GL_FILL );
Initialization continues with calls to initialization routines that we will show
later:
1
2
setupCamera();
setupLighting();
The main function is near its end, and still nothing has been drawn. It is time
to register our application's display handler to ensure GLUT will know how to
trigger the generation of the initial image:
1
2
3
glutDisplayFunc(
drawEntireScene // the name of our display-event handler
);
 
Search WWH ::




Custom Search