Archive for August, 2007

Page 334 OpenGL Super Bible! // Swap the (Web site hosting)

Friday, August 31st, 2007

Page 334 OpenGL Super Bible! // Swap the y coordinate positions temp = lastY; lastY = nextY; nextY = temp; } // Flush drawing commands glFlush(); } The WAVEY program has menu options to render just a wireframe image, do flat or smooth shading, and finally do the normal averaging. Figure 9-20 shows this folding image using flat shading, and Figure 9-21 is the same object with the normals averaged. You can see that the second image appears to have a smooth rippling effect across its surface. Figure 9-20 Bent surface with regular surface normals Figure 9-21 Bent surface with surface normals averaged together
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

OpenGL Super Bible! Page 333 (Web design seattle) // 3rd Vertices

Thursday, August 30th, 2007

OpenGL Super Bible! Page 333 // 3rd Vertices v[2][0] = x + 20.0f; // X coord for right v[2][1] = nextY; v[2][2] = -50.0f; // Z coord for front // 4th Vertices v[3][0] = x + 20.0f; // X coord for right v[3][1] = nextY; v[3][2] = 50.0f; // Z coord for back // Begin the polygon glBegin(GL_POLYGON); if(iState != AVERAGE) { // Calculate and set the normal vector, unless // averaging selected from the menu. calcNormal(v,normal); glNormal3fv(normal); } else // Average normals. Here we cheat because we know // the normal points either up or down { // Normal points straight up if(nextY == 10) glNormal3f(0.0f,1.0f, 0.0f); else // Normal points straight down glNormal3f(0.0f,-1.0f, 0.0f); } // Specify the left two verticies glVertex3fv(v[0]); glVertex3fv(v[1]); // Do the same, but the normal on the other side points // the other direction if(iState == AVERAGE) { if(nextY == 10) glNormal3f(0.0f,-1.0f, 0.0f); // points down else glNormal3f(0.0f,1.0f, 0.0f); // points up } // Specify the right two vertices glVertex3fv(v[2]); glVertex3fv(v[3]); glEnd();
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Page 332 OpenGL Super (Web design portfolio) Bible! Listing 9-7 The

Wednesday, August 29th, 2007

Page 332 OpenGL Super Bible! Listing 9-7 The rendering function from the WAVEY example program // Called to draw scene void RenderScene(void) { float normal[3]; // Storage for calculate normal float v[4][3]; // Storage for rectangle coordinates float lastY; // Left-hand side of rectangle float nextY; // Right-hand side of rectangle float temp; // Temporary storage for swapping float x; // X coordinate storage // Menu state specifies if wireframe or not if(iState == WIRE) glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); else glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); // Menu state specifies if smooth or flat shading if(iState == SMOOTH || iState == AVERAGE) glShadeModel(GL_SMOOTH); else glShadeModel(GL_FLAT); // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Reset viewing volume and viewport ChangeSize(lastWidth,lastHeight); // Rotate the image according to accumulated angle set // by the arrow key handlers glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); // Set surface color to blue glRGB(0,0,255); // Initialize the y steppings lastY = 0.0f; nextY = 10.0f; // Loop through x coordinate from left to right, build // a rectangle with alternating slopes upward and downward for(x = -60.0f; x < 60.0f; x+= 20.0f) { // 1st Vertices v[0][0] = x; // X coord for left v[0][1] = lastY; v[0][2] = 50.0f; // Z coord for back // 2nd vertices v[1][0] = x; // X coord for left v[1][1] = lastY; v[1][2] = - 50.0f; // Z coord for front
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

OpenGL Super Bible! Page 331 Figure 9-18 Jagged

Tuesday, August 28th, 2007

OpenGL Super Bible! Page 331 Figure 9-18 Jagged surface with the usual surface normals Although the normals are shown in between the corners, they are actually specified for each vertex. If you take into account that each vertex actually boarders another surface, you can specify the normal for that vertex as the average of the two normals at that point for each surface. Figure 9-19 shows that for two adjoining surfaces, their common corner would have a different normal specified as each surface is drawn. If we take the average of these two normals and use it when we specify each surface, the joining of the two surfaces will appear less sharp after OpenGL does its surface shading. Figure 9-19 Averaging the normals will make sharp corners appear softer Listing 9-7 shows the rendering function that creates the surface shown in Figure 9-18. (This code is from the example program WAVEY in the CD subdirectory for this chapter.) The surface is created by stepping from left to right for the x coordinates, and alternating up and down in the y coordinate direction. The z coordinates are constant, with 50 being the front of the image and 50 being at the back.
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

Page 330 OpenGL Super Bible! Listing (Web design software) 9-6 Setup

Monday, August 27th, 2007

Page 330 OpenGL Super Bible! Listing 9-6 Setup from SHINYJET to produce specular highlights on the jet // 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.3f, 0.3f, 0.3f, 1.0f }; GLfloat diffuseLight[] = { 0.7f, 0.7f, 0.7f, 1.0f }; GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f}; Glfloat lightPos[] = { 0.0f, 150.0f, 150.0f, 1.0f }; GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glEnable(GL_DEPTH_TEST); // Hidden surface removal glFrontFace(GL_CCW); // Counterclockwise polygons face out glEnable(GL_CULL_FACE); // Do not calculate inside of jet // Enable lighting glEnable(GL_LIGHTING); // Set up and enable light 0 glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight); glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight); glLightfv(GL_LIGHT0,GL_SPECULAR,specular); glLightfv(GL_LIGHT0,GL_POSITION,lightPos); glEnable(GL_LIGHT0); // Enable color tracking glEnable(GL_COLOR_MATERIAL); // Set Material properties to follow glColor values glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); // All materials hereafter have full specular reflectivity // with a high shine glMaterialfv(GL_FRONT, GL_SPECULAR,specref); glMateriali(GL_FRONT,GL_SHININESS,128); // Light blue background glClearColor(0.0f, 0.0f, 1.0f, 1.0f ); } Normal Averaging Earlier we mentioned that by tweaking your normals you can produce smooth surfaces with straight lines. This technique, known as normal averaging, produces some interesting optical illusions. Say you have a surface like that shown in Figure 9-18, with the usual surface normals.
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

Web site layout - OpenGL Super Bible! Page 329 except where the

Sunday, August 26th, 2007

OpenGL Super Bible! Page 329 except where the surface points away from the light source (in which case it would be black and unlit). To temper this effect, we use the next line of code after the specular component is specified, as follows: glMateriali(GL_FRONT,GL_SHININESS,128); The GL_SHININES property sets the specular exponent of the material, which specifies how small and focused the specular highlight is. A value of 0 specifies an unfocused specular highlight, which is actually what is producing the brightening of the colors evenly across the entire polygon. If you set this value, you reduce the size and increase the focus of the specular highlight, causing a shiny spot to appear. The larger the value, the more shiny and pronounced the surface. The range of this parameter is 1 128 for all implementations of OpenGL. Listing 9-6 shows the new SetupRC code in the sample program SHINYJET. This is the only code that changed from LITJET (other than the title of the window) to produce a very shiny and glistening jet. Figure 9-17 shows the output from this program, but to fully appreciate the effect, you should run the program and hold down one of the arrow keys to spin the jet about in the sunlight. Figure 9-17 Output from the SHINYJET program
We recommend high quality webhost to host and run your jsp application: christian web host services.

Page 328 OpenGL Super Bible! Specular Reflectance Adding (Web hosting rating)

Saturday, August 25th, 2007

Page 328 OpenGL Super Bible! Specular Reflectance Adding specular reflectance to material properties is just as easy as adding the specular component to the light source. This next code segment shows the code from LITJET, again modified to add specular reflectance to the material properties. // Light values and coordinates GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f }; // Enable color tracking glEnable(GL_COLOR_MATERIAL); // Set Material properties to follow glColor values glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); // All materials hereafter have full specular reflectivity // with a high shine glMaterialfv(GL_FRONT, GL_SPECULAR,specref); glMateriali(GL_FRONT,GL_SHININESS,128); As before, we enable color tracking so that the ambient and diffuse reflectance of the materials follow the current color set by the glColor() functions. (Of course, we don t want the specular reflectance to track glColor, because we are specifying it separately and it doesn t change.) Now we ve added an array specref[] that contains the RGBA values for our specular reflectance. This array of all 1 s will produce a surface that reflects nearly all incident specular light. The line glMaterialfv(GL_FRONT, GL_SPECULAR,specref); sets the material properties for all subsequent polygons to have this reflectance. Since we do not call glMaterial again with the GL_SPECULAR property, all materials will have this property. We did this on purpose because we want the entire jet to appear made of metal or very shiny composites. What we have done here in our setup routine is important: We have specified that the ambient and diffuse reflective material properties of all future polygons (until we say otherwise with another call to glMaterial or glColorMaterial) will change as the current color changes, but that the specular reflective properties will remain the same. Specular Exponent As stated earlier, high specular light and reflectivity brighten the colors of the object. For this example, the present extremely high specular light (full intensity) and specular reflectivity (full reflectivity) will result in a jet that appears almost totally white or gray
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

Cpanel web hosting - OpenGL Super Bible! Page 327 material properties are

Friday, August 24th, 2007

OpenGL Super Bible! Page 327 material properties are all you need if you are modeling clay, wood, cardboard, cloth, or some other flatly colored object. But for metallic surfaces like the skin of an airplane, some shine is often necessary. Specular Highlights Specular lighting and material properties add needed gloss to the surface of your objects. This shininess has a whitening effect on an object s color and can produce specular highlights when the angle of incident light is sharp in relation to the viewer. A specular highlight is what occurs when nearly all the light striking the surface of an object is reflected away. The white sparkle on a shiny red ball in the sunlight is good example of a specular highlight. Specular Light Adding a specular component to a light source is very easily done. The following code shows the light source setup for the LITJET program, modified to add a specular component to the light. // Light values and coordinates // Light values and coordinates GLfloat ambientLight[] = { 0.3f, 0.3f, 0.3f, 1.0f }; GLfloat diffuseLight[] = { 0.7f, 0.7f, 0.7f, 1.0f }; GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f}; Glfloat lightPos[] = { 0.0f, 150.0f, 150.0f, 1.0f }; // Enable lighting glEnable(GL_LIGHTING); // Setup and enable light 0 glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight); glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight); glLightfv(GL_LIGHT0,GL_SPECULAR,specular); glLightfv(GL_LIGHT0,GL_POSITION,lightPos); glEnable(GL_LIGHT0); The specular[] array specifies a very bright white light source for the specular component of the light. Our purpose here is to model bright sunlight. The line glLightfv(GL_LIGHT0,GL_SPECULAR,specular); simply adds this specular component to the light source GL_LIGHT0. If this were the only change you made to LITJET, you wouldn t see any difference in the jet s appearance. This is because we haven t yet defined any specular reflectance properties for the material properties.
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Page 326 OpenGL Super Bible! very (Web site traffic) large numbers

Thursday, August 23rd, 2007

Page 326 OpenGL Super Bible! very large numbers of polygons, this can considerably boost performance by eliminating many unnecessary function calls. Figure 9-16 shows the output from the completed LITJET example program. By rotating the jet around with the arrow keys, you can see the dramatic shading effects as the surface of the jet moves in the light. Figure 9-16 Output from LITJET sample Performance Tip: The most obvious way to improve the performance of this code would be to calculate all the normal vectors ahead of time and store them for use in the Render function. Before you pursue this, read Chapter 10 s material on display lists. Display lists provide a means of storing calculated values not only for the normal vectors, but for the polygon data as well. Remember, these examples are meant to demonstrate the concepts. They are not necessarily the most efficient code possible. Lighting Effects The ambient and diffuse light from the LITJET example are sufficient to provide the illusion of lighting. The surface of the jet appears shaded according to the angle of the incident light. As the jet rotates, these angles change and you can see the lighting effects changing in such a way that you can easily guess where the light is coming from. We ignored the specular component of the light source, however, as well as the specular reflectivity of the material properties on the jet. Although the lighting effects are pronounced, the surface of the jet is rather flatly colored. Ambient and diffuse lighting and
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

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

Wednesday, August 22nd, 2007

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.