Archive for May, 2007

OpenGL Super Bible! Page 67 Summary In this

Thursday, May 3rd, 2007

OpenGL Super Bible! Page 67 Summary In this chapter we have introduced the AUX library toolkit and presented the fundamentals of writing a program that uses OpenGL. We have used this library to show the easiest possible way to create a window and draw in it using OpenGL commands. You have learned to use the AUX library to create windows that can be resized, as well as to create simple animation. You have also been introduced to the process of using OpenGL to do drawing composing and selecting colors, clearing the screen, drawing a rectangle, and setting the viewport and clipping volume to scale images to match the window size. We ve also discussed the various OpenGL data types, and the headers and libraries required to build programs that use OpenGL. The Auxiliary library contains many other functions to handle keyboard and mouse input as well. Microsoft s implementation of the Aux library contains Windows- specific functions that enable access to window handles and device contexts. You are encouraged to explore the upcoming reference section of this chapter to discover other uses and features of the AUX library. You ll also want to examine and run the other Chapter 3 samples on the CD.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision j2ee hosting services

Page 66 OpenGL Super Bible! projection. The program (Web design conference)

Thursday, May 3rd, 2007

Page 66 OpenGL Super Bible! projection. The program that produced this image is found in this chapter s subdirectory on the CD in teapot.c. Figure 3-12 A wireframe teapot If you change the wire teapot to a solid teapot with the command auxSolidTeapot(50.0f); you ll see only a red outline of the teapot. In order to see relief in a solid- colored object, you will need to incorporate shading and lighting with other OpenGL commands that you ll learn about in Chapter 9 and later. For further study of the AUX library objects, see the samples AUXWIRE and AUXSOLID on the CD in this chapter s subdirectory. These samples make use of the glRotatef() function (explained in Chapter 7), which spins the objects around all three axes of the viewing volume. Some of these objects make use of the utility library, so be sure that you link with glu32.lib when using these objects yourself.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision j2ee hosting services

OpenGL Super Bible! Page 65 Figure 3-11 Bouncing (Web hosting rating)

Wednesday, May 2nd, 2007

OpenGL Super Bible! Page 65 Figure 3-11 Bouncing square Finally, Some 3D! Thus far, all our samples have been simple rectangles in the middle of the window; they either scaled to the new window size or bounced around off the walls. By now you may be bouncing off some walls of your own, waiting anxiously to see something in 3D. Wait no more! As mentioned earlier, we have been drawing in 3D all along, but our view of the rectangle has been perpendicular to the clipping volume. If we could just rotate the clipping volume with respect to the viewer, we might actually see something with a little depth. However, we aren t going to get into coordinate transformations and rotations until Chapter 7. And even if we started that work now, a flat rectangle isn t very interesting, even when viewed from an angle. To see some depth, we need to draw an object that is not flat. The AUX library contains nearly a dozen 3D objects from a sphere to a teapot that can be created with a single function call. These called functions are of the form auxSolidxxxx() or auxWirexxxx(), where xxxx names the solid or wireframe object that is created. For example, the following command draws a wireframe teapot of approximately 50.0 units in diameter: auxWireTeapot(50.0f); If we define a clipping volume that extends from -100 to 100 along all three axes, we ll get the wireframe teapot shown in Figure 3-12. The teapot is probably the best example at this point because the other objects still look two-dimensional when viewed from a parallel
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp web hosting services

Page 64 OpenGL Super Bible! // Set function (Multiple domain web hosting)

Wednesday, May 2nd, 2007

Page 64 OpenGL Super Bible! // Set function to call when program is idle auxIdleFunc(IdleFunction); // Start main loop auxMainLoop(RenderScene); } The animation produced by this example is very poor, even on very fast hardware. Because the window is being cleared each time before drawing the square, it flickers the entire time it s moving about, and you can easily see the square actually being drawn as two triangles. To produce smoother animation, you need to employ a feature known as double buffering. Double Buffering One of the most important features of any graphics packages is support for double buffering. This feature allows you to execute your drawing code while rendering to an off-screen buffer. Then a swap command places your drawing on screen instantly. Double buffering can serve two purposes. The first is that some complex drawings may take a long time to draw and you may not want each step of the image composition to be visible. Using double buffering, you can compose an image and display it only after it is complete. The user never sees a partial image; only after the entire image is ready is it blasted to the screen. A second use for double buffering is for animation. Each frame is drawn in the off-screen buffer and then swapped quickly to the screen when ready. The AUX library supports double-buffered windows. We need to make only two changes to the bounce.c program to produce a much smoother animation. First, change the line in main() that initializes the display mode to indicate that it should use double buffering: auxInitDisplayMode(AUX_DOUBLE | AUX_RGBA); This will cause all the drawing code to render in an off-screen buffer. Next, add a single line to the end of the Render() function: auxSwapBuffers(); The auxSwapBuffers() function causes the off-screen buffer used for drawing to be swapped to the screen. (The complete code for this is in the BOUNCE2 example on the CD.) This produces a very smooth animation of the red square bouncing around inside the window. See Figure 3-11.
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision professional web hosting services

OpenGL Super Bible! Page 63 void CALLBACK RenderScene(void) (Web hosting script)

Tuesday, May 1st, 2007

OpenGL Super Bible! Page 63 void CALLBACK RenderScene(void) { // Set background clearing color to blue glClearColor(0.0f, 0.0f, 1.0f, 1.0f); // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT); // Set drawing color to red, and draw rectangle at // current position. glColor3f(1.0f, 0.0f, 0.0f); glRectf(x1, y1, x1+rsize, y1+rsize); glFlush(); } // Called by AUX library when idle (window not being // resized or moved) void CALLBACK IdleFunction(void) { // Reverse direction when you reach left or right edge if(x1 > windowWidth- rsize || x1 < 0) xstep = -xstep; // Reverse direction when you reach top or bottom edge if(y1 > windowHeight- rsize || y1 < 0) ystep = -ystep; // Check bounds. This is in case the window is made // smaller and the rectangle is outside the new // clipping volume if(x1 > windowWidth-rsize) x1 = windowWidth-rsize-1; if(y1 > windowHeight-rsize) y1 = windowHeight-rsize-1; // Actually move the square x1 += xstep; y1 += ystep; // Redraw the scene with new coordinates RenderScene(); } // Main body of program void main(void) { // AUX window setup and initialization auxInitDisplayMode(AUX_SINGLE | AUX_RGBA); auxInitPosition(100,100,250,250); auxInitWindow(”Simple 2D Animation”); // Set function to call when window is resized auxReshapeFunc(ChangeSize);
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision php5 hosting services

Web host forum - Page 62 OpenGL Super Bible! Listing 3-4 Animated

Tuesday, May 1st, 2007

Page 62 OpenGL Super Bible! Listing 3-4 Animated bouncing square // bounce.c // Bouncing square #include // Standard windows include #include // OpenGL library #include // AUX library // Initial square position and size GLfloat x1 = 100.0f; GLfloat y1 = 150.0f; GLsizei rsize = 50; // Step size in x and y directions // (number of pixels to move each time) GLfloat xstep = 1.0f; GLfloat ystep = 1.0f; // Keep track of window s changing width and height GLfloat windowWidth; GLfloat windowHeight; // Called by AUX library when the window has changed size void CALLBACK ChangeSize(GLsizei w, GLsizei h) { // Prevent a divide by zero, when window is too short // (you can t make a window of zero width) if(h == 0) h = 1; // Set the viewport to be the entire window glViewport(0, 0, w, h); // Reset the coordinate system before modifying glLoadIdentity(); // Keep the square square, this time, save calculated // width and height for later use if (w <= h) { windowHeight = 250.0f*h/w; windowWidth = 250.0f; } else { windowWidth = 250.0f*w/h; windowHeight = 250.0f; } // Set the clipping volume glOrtho(0.0f, windowWidth, 0.0f, windowHeight, 1.0f, -1.0f); } // Called by AUX library to update window
Note: If you are looking for high quality webhost to host and run your jsp application check Vision florida web design services

OpenGL Super Bible! Page 61 always at y

Tuesday, May 1st, 2007

OpenGL Super Bible! Page 61 always at y = 0, and extends upward to 250 unless the window is taller than it is wide. In that case the upper coordinate is extended by the aspect ratio. This serves to keep a square coordinate region 250 x 250 available regardless of the shape of the window. Figure 3-10 shows how this works. Figure 3-10 Clipping region for three different windows Animation with AUX Thus far, we ve discussed the basics of using the AUX library for creating a window and using OpenGL commands for the actual drawing. You will often want to move or rotate your images and scenes, creating an animated effect. Let s take the previous example, which draws a square, and make the square bounce off the sides of the window. You could create a loop that continually changes your object s coordinates before calling the RenderScene() function. This would cause the square to appear to move around within the window. The AUX library provides a function that makes it much easier to set up a simple animated sequence. This function, auxIdleFunc(), takes the name of a function to call continually while your program sits idle. The function to perform your idle processing is prototyped like this: void CALLBACK IdleFunction(void); This function is then called repeatedly by the AUX library unless the window is being moved or resized. If we change the hard-coded values for the location of our rectangle to variables, and then constantly modify those variables in the IdleFunction(), the rectangle will appear to move across the window. Let s look at an example of this kind of animation. In Listing 3-4, we ll modify Listing 3-3 to bounce the square around off the inside borders of the window. We ll need to keep track of the position and size of the rectangle as we go along, and account for any changes in window size.
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision php5 hosting services