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.