Business web hosting - OpenGL Super Bible! Page 325 Specifying the Polygons

OpenGL Super Bible! Page 325 Specifying the Polygons The rendering code from the first two JET samples changes considerably now, to support the new lighting model. Listing 9-5 is taken from the RenderScene() function from LITJET. Listing 9-5 Code sample that sets color, calculates and specifies normals and polygons float normal[3]; // Storage for calculated surface normal // Set material color glRGB(0, 255, 0); glBegin(GL_TRIANGLES); glNormal3f(0.0f, -1.0f, 0.0f); glVertex3f(0.0f, 0.0f, 60.0f); glVertex3f(- 15.0f, 0.0f, 30.0f); glVertex3f(15.0f,0.0f,30.0f); //glEnd(); { // Vertices for this triangle float v[3][3] = {{ 15.0f, 0.0f, 30.0f}, { 0.0f, 15.0f, 30.0f}, { 0.0f, 0.0f, 60.0f}}; // Calculate the normal for the plane calcNormal(v,normal); // Draw the triangle using the plane normal // for all the vertices //glBegin(GL_TRIANGLES); glNormal3fv(normal); glVertex3fv(v[0]); glVertex3fv(v[1]); glVertex3fv(v[2]); //glEnd(); } You ll notice that we are calculating the normal vector using our code in Listing 9-3. Also, the material properties are now following the colors set by glColor (which is wrapped by our glRGB macro). One other thing you ll notice is that not every triangle is blocked by glBegin()/glEnd() functions. You can specify once that you are drawing triangles, and every three vertices will be used for a new triangle until you specify otherwise with glEnd(). For
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

Leave a Reply