Archive for October, 2007

Page 386 (Web server setup) OpenGL Super Bible! Reference Section glCallList

Monday, October 22nd, 2007

Page 386 OpenGL Super Bible! Reference Section glCallList Purpose Executes a display list. Include File Syntax void glCallList(GLuint list); Description Executes the display list identified by list. The OpenGL State Machine is not restored after this function is called, so it is a good idea to call glPushMatrix beforehand and glPopMatrix afterwards. Calls to glCallList may be nested. The function glGet with the argument GL_MAX_LIST_NESTING returns the maximum number of allowable nests. For Microsoft Windows, this value is 64. Parameters list GLuint: Identifies the display list to be executed. Returns None. Example The following code saves the matrix state before calling a display list. It then restores the state afterwards. This code is from the BOLTL example program from this chapter s subdirectory on the CD. // Save the current transform state glPushMatrix(); // Draw the bolt including nested display lists glCallList(BOLT_HEAD); // Restore state glPopMatrix(); See Also glCallLists, glDeleteLists, glGenLists, glNewList
We recommend high quality webhost to host and run your jsp application: christian web host services.

Web host sites - OpenGL Super Bible! Page 385 The Tank Simulator

Sunday, October 21st, 2007

OpenGL Super Bible! Page 385 The Tank Simulator Try the tank simulator as it stood after the last chapter, and compare it to the one for this chapter. This version, which makes heavy use of display lists, consists of many thousands of triangles, and you won t need any benchmarking program or stopwatch to know that the performance has been enhanced! Summary We used this chapter to slow down somewhat and just talk about how to build a three- dimensional object, starting with using the OpenGL primitives to create simple 3D pieces, and then assembling them into a larger and more complex object. Learning the API is the easy part, but your level of experience in assembling 3D objects and scenes will be what differentiates you from your peers. Once an object or scene is broken down into small and potentially reusable components, you can save building time by using display lists. You ll find many more functions for utilizing and managing display lists in the Reference Section. You also learned a simple way to benchmark your OpenGL programs so you can get firsthand experience of the effects of optimizing your code.
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

Page 384 OpenGL Super Bible! glCallList(SHAFT_LIST); glCallList(THREAD_LIST); // (Web server)

Saturday, October 20th, 2007

Page 384 OpenGL Super Bible! glCallList(SHAFT_LIST); glCallList(THREAD_LIST); // Translate back again for next pass glTranslatef(0.0f, 0.0f, -40.0f); // End Bolt list glEndList(); } // Called to draw the entire bolt void RenderScene(void) { glCallList(BOLT_LIST); // Flush drawing commands glFlush(); } You ll see that we defined some macros to identify the display lists more easily. These macros simply map to the numeric value that identifies the display list. Figure 10-10 shows the output from this new and improved spinning bolt program. The elapsed time for the example using display lists was just over 13 seconds, about a 2-second improvement. This may not seem like much, but wait a few chapters and come back and try it again with special effects such as texture mapping or NURBS surfaces. As mentioned earlier, 1,700 triangles is really a very small portion of what some larger and more complex scenes will consist of. Figure 10-10 Output from SLSTBOLT using display lists
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

OpenGL Super Bible! Page 383 display list for (Post office web site)

Friday, October 19th, 2007

OpenGL Super Bible! Page 383 display list for each part of the bolt, and then one display list that does all the coordinate transformations and calls the lists to create the completed bolt. Listing 10-10 New spinning bolt code using display lists #define HEAD_LIST #define SHAFT_LIST #define THREAD_LIST #define BOLT_LIST 1 2 3 4 // This function does any needed initialization on the rendering // context. Here it sets up and initializes the lighting for // the scene, and creates display lists used later void SetupRC() { // Create display list for Bolt head glNewList(HEAD_LIST,GL_COMPILE); RenderHead(); glEndList(); // Create display list for shaft glNewList(SHAFT_LIST,GL_COMPILE); RenderShaft(); glEndList(); // Create display list for thread glNewList(THREAD_LIST,GL_COMPILE); RenderThread(); glEndList(); // Create nested display list for entire bolt glNewList(BOLT_LIST,GL_COMPILE); // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Make sure we have the correct matrix mode glMatrixMode(GL_MODELVIEW); // Rotate and translate the coordinate system // Note this will be cumulative glRotatef(5.0f, 0.0f, 1.0f, 0.0f); // Translate and render the head glTranslatef(0.0f, 0.0f, 55.0f); glCallList(HEAD_LIST); // Translate back some and render the shaft and thread together glTranslatef(0.0f, 0.0f, -15.0f);
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Web server type - Page 382 OpenGL Super Bible! What we need

Friday, October 19th, 2007

Page 382 OpenGL Super Bible! What we need is a way of storing all these vertices and normals as they are calculated, so we can reuse them rather than go back through all that trigonometry to calculate spiral paths and such. OpenGL has just what we need: display lists. With a display list, you can record OpenGL function calls (and their results) and play them back at a later time. Display lists are faster than just reexecuting the same OpenGL functions singly. Further, non-OpenGL calls such as our trigonometry and normal calculations are not stored, but their results, which are passed to the OpenGL functions, are. You should be getting an inkling of why display lists are such a good idea. Human Beings and Computer Performance A good rule of thumb in any type of software engineering is to work first on improvements that yield at least a 20% increase in performance. It is universally accepted that human beings, for the most part, have difficulty detecting an increase in software performance that is less than 20%. For OpenGL, this 20% value can often be attained quickly by using display lists when the number of polygons is high. It s a good idea to get in the habit of using them. Creating a Display List Creating a display list is a very straightforward process. Just as you delimit an OpenGL primitive with glBegin/glEnd, you delimit a display list with glNewList/glEndList. A display list, however, is named with an integer value that you supply. The following code represents a typical example of display list creation: glNewList(1,GL_COMPILE); // Some OpenGL Code glEndList(); As the second parameter to glNewList, you can specify GL_COMPILE or GL_COMPILE_AND_EXECUTE. This tells OpenGL whether to compile and store the OpenGL commands, or to compile, store, and execute the commands as they occur. Later, when you need to execute the display list, simply call glCallList(1); The identifier you supply is the same as that supplied in the corresponding call to glNewList. Listing 10-10 is the code for our new example, SLSTBOLT, which makes use of display lists to produce the spinning bolt. Notice that you can nest calls to display lists. The maximum number of nested calls is 64 to prevent infinite recursion. In this code, we create a
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Web server application - OpenGL Super Bible! Page 381 SetBkColor(hDC,RGB(0,0,255)); SetTextColor(hDC,RGB(255,255,0)); TextOut(hDC,0,cRect.bottom-20,cBuffer,strlen

Thursday, October 18th, 2007

OpenGL Super Bible! Page 381 SetBkColor(hDC,RGB(0,0,255)); SetTextColor(hDC,RGB(255,255,0)); TextOut(hDC,0,cRect.bottom-20,cBuffer,strlen (cBuffer)); // Do not validate, forcing a continuous repaint } break; This message handler gets the current system time and counts the number of times it is called. After 71 times, it gets the new time, subtracts the difference, and displays the lapsed time. Remember that our bolt is rotating 5 each time it is rendered, so this technique effectively measures the amount of time it takes to spin the bolt 360 . The function ulGetProfileTime simply gets the system time in clock ticks and converts it to thousandths of a second. (You can examine this yourself in the source listing if you want, but its operation is not germane to our discussion here.) SPINBOLT s output is shown in Figure 10-9. The time to spin the bolt around in this example was just under 15 seconds (on a 90MHz Pentium with no hardware 3D acceleration). Figure 10-9 Output from the SPINBOLT program Improving Performance You may have spotted a glaring performance problem with the WM_PAINT technique, however. Each time the bolt is drawn, a large number of calculations must be performed to redraw the thread, the shaft, and the bolt head. Among these calculations are some pretty expensive calls to sin() and cos().
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Page 380 OpenGL Super Bible! Listing 10-9 is (Web site template)

Wednesday, October 17th, 2007

Page 380 OpenGL Super Bible! Listing 10-9 is the WM_PAINT handler for our new program, SPINBOLT. Listing 10-9 WM_PAINT message handler for SPINBOLT // Storage for timing values static unsigned long ulStart = 0L; static unsigned long ulFinish = 0L; static double dTime = 0.0; // Storage for performance statistics char cBuffer[80]; RECT cRect; // The painting function. This message sent by Windows // whenever the screen needs updating. case WM_PAINT: { // Count how many times rendered static iRenderCount = 0; // Get time at beginning of spin if(iRenderCount == 0) ulStart = ulGetProfileTime(); // Call OpenGL drawing code RenderScene(); // Bring image to front SwapBuffers(hDC); // Increment count. If 71 or over get the finish time iRenderCount++; if(iRenderCount > 71) { iRenderCount = 0; ulFinish = ulGetProfileTime(); // Calculate the time in seconds dTime = ulFinish - ulStart; dTime /= 1000.0; } // Display time (be sure and set background colors) sprintf(cBuffer,”%3.1f Seconds for 360 degrees.”, dTime); GetClientRect(hWnd,&cRect);
Check Tomcat Web Hosting services for best quality webspace to host your web application.

OpenGL Super Bible! Page 379 This new rendering (Adelphia web hosting)

Tuesday, October 16th, 2007

OpenGL Super Bible! Page 379 This new rendering function does not save or restore the matrix state. We use glTranslate to manually restore the translation state of the matrix before leaving the function, but the effects of glRotate are cumulative. This causes the bolt to be rotated around its y-axis by 5 every time the bolt is rendered. One simple animation technique would be to create a timer, and when the WM_TIMER message is received, invalidate the window causing a redraw. In this manner we can speed up and slow down the animation as desired. Our goal is not simple animation, however, but to get a feel for the rate of the rotations. A reasonable criterion is the amount of time required to spin the bolt completely around the y-axis (360 ). Using WM_TIMER messages would be a poor choice for benchmarking for two reasons. First, your window is not guaranteed to receive all the WM_TIMER messages (the OS could be too busy). And second, if you specify the time intervals, what good does it do to then measure those intervals with any confidence that they truly indicate performance? What we really want to do is time the interval between the starting and stopping of rendering. This could provide a value that is too small for practical use, so we can just time the interval between a given number of renderings. By repeatedly rendering the scene a number of times and measuring the time it takes to perform these renderings, we have a fairly good benchmark. Caution: This Is Only an Approximation! This benchmark is very informal and uses a method of timing computer programs that s not accurate enough for publishing important results. We only use it here to demonstrate an easily detectable performance gain when using display lists. To compare your real programs (as well as the two presented here), you should at least have the rest of your system idle when running the test. Many factors can increase or decrease the values you get, but as long as conditions are more or less equal, you will see a time difference between the two bolt- spinning programs. You might be tempted to just stack together a bunch of calls to RenderScene and obtain the time before and after to calculate the elapsed time. This would work, but closing the application would be very difficult because it would not have the chance to service any other messages (such as WM_CLOSE). The best way to get a Windows program to repeatedly paint its client area is to omit validation of the client area when the WM_PAINT handler is finished. If the client area is still invalid, Windows will just keep posting WM_PAINT messages to your application forever. In the midst of these WM_PAINT messages, other messages such as WM_CLOSE will still appear and be processed.
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Page 378 OpenGL Super Bible! A Makeshift Benchmark (Simple web server)

Monday, October 15th, 2007

Page 378 OpenGL Super Bible! A Makeshift Benchmark Our final program produces a fairly good representation of the metal bolt we set out to model. Consisting of over 1,700 triangles, this is the most complex example in this book so far. Comparatively speaking, however, this number of triangles isn t anywhere close to the largest number of polygons you ll encounter when composing larger scenes and more complex objects. In fact, the latest 3D accelerated graphics cards are rated at hundreds of thousands of triangles per second, and that s for the cheap ones! One of the goals of this chapter is to introduce you to using display lists to optimize rendering speed. Before we can get into a comparison of rendering speeds, however, we will need a way to measure this a benchmark. When we get into the subject of display lists, we want you to be able to see that there is a performance difference rather than just take our word for it. So let s modify our BOLT program slightly. Rather than spinning the object about its axes when arrow keys are pressed, we ll have it spin repeatedly around just the y-axis in particular. As you might imagine, this turns the program into a continual triangle-generator that we can use to more easily see differences in performance. Listing 10-8 is the changed RenderScene() function used for SPINBOLT. Listing 10-8 New RenderScene() function to spin bolt around the y-axis // Called to draw the entire bolt void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Make sure we have the correct matrix mode glMatrixMode(GL_MODELVIEW); // Rotate and translate the coordinate system glRotatef(5.0f, 0.0f, 1.0f, 0.0f); // Translate and render the head glTranslatef(0.0f, 0.0f, 55.0f); RenderHead(); // Translate back some and render the shaft and thread glTranslatef(0.0f, 0.0f, -15.0f); RenderShaft(); RenderThread(); // Translate back some again for next pass glTranslatef(0.0f, 0.0f, -40.0f); // Flush drawing commands gl Flush(); }
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

OpenGL Super Bible! Page 377 // Save the (Anonymous web server)

Sunday, October 14th, 2007

OpenGL Super Bible! Page 377 // Save the matrix state and do the rotations glMatrixMode(GL_MODELVIEW); // Rotate and translate, then render the bolt head glPushMatrix(); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); glTranslatef(0.0f, 0.0f, 55.0f); RenderHead(); glPopMatrix(); // Save matrix state, rotate, translate and draw the // shaft and thread together glPushMatrix(); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); glTranslatef(0.0f, 0.0f, 40.0f); // Render just the hexagonal head of the nut RenderShaft(); RenderThread(); glPopMatrix(); // Flush drawing commands glFlush(); Figure 10-8 Output from the BOLT program
In case you need quality webspace to host and run your web applications, try our personal web hosting services.