OpenGL Super Bible! Page 363 // Reset coordinate
OpenGL Super Bible! Page 363 // Reset coordinate system glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Establish clipping volume (left, right, bottom, top, near, far) if (w <= h) glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange*2.0f, nRange*2.0f); else glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange*2.0f, nRange*2.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } Choosing the Lighting and Material Properties With the projection chosen, the next step is to select a lighting model for our view of the bolt. Listing 10-2 is the code to set up the rendering context including the lighting and material properties. We make sure the ambient light is bright enough to see all the features, and include a specular component to make it glisten just as a real metal bolt would. The single light source is positioned to the upper-left of the viewer. Listing 10-2 Setting up the rendering context and lighting conditions // This function does any needed initialization on the rendering // context. Here it sets up and initializes the lighting for // the scene. void SetupRC() { // Light values and coordinates GLfloat ambientLight[] = {0.4f, 0.4f, 0.4f, 1.0f }; GLfloat diffuseLight[] = {0.7f, 0.7f, 0.7f, 1.0f }; GLfloat specular[] = { 0.9f, 0.9f, 0.9f, 1.0f}; Glfloat lightPos[] = { -50.0f, 200.0f, 200.0f, 1.0f }; GLfloat specref[] = { 0.6f, 0.6f, 0.6f, 1.0f }; glEnable(GL_DEPTH_TEST); // Hidden surface removal glEnable(GL_CULL_FACE);// Do not calculate inside of solid object // Enable lighting glEnable(GL_LIGHTING); // Set up light 0 glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambientLight); glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight); glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight); glLightfv(GL_LIGHT0,GL_SPECULAR,specular); // Position and turn on the light glLightfv(GL_LIGHT0,GL_POSITION,lightPos); glEnable(GL_LIGHT0);
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.