Archive for April, 2007

Page 60 OpenGL (Florida web design) Super Bible! Figure 3-9 Cartesian

Monday, April 30th, 2007

Page 60 OpenGL Super Bible! Figure 3-9 Cartesian space Just before the code using glOrtho(), you ll notice a single call to glLoadIdentity(). This is needed because glOrtho() doesn t really establish the clipping volume, but rather modifies the existing clipping volume. It multiplies the matrix that describes the current clipping volume by the matrix that describes the clipping volume described in its arguments. The discussion of matrix manipulations and coordinate transformations is in Chapter 7. For now, you just need to know that glLoadIdentity() serves to reset the coordinate system to unity before any matrix manipulations are performed. Without this reset every time glOrtho() is called, each successive call to glOrtho() could result in a further corruption of our intended clipping volume, which may not even display our rectangle. Keeping a Square Square The following code does the actual work of keeping our square square. if (w <= h) glOrtho (0, 250, 0, 250*h/w, 1.0, -1.0); else glOrtho (0, 250*w/h, 0, 250, 1.0, -1.0); Our clipping volume (visible coordinate space) is modified so that the left-hand side is always at x = 0. The right-hand side extends to 250 unless the window is wider than it is tall. In that case, the right-hand side is extended by the aspect ratio of the window. The bottom is
Note: If you are looking for cheap webhost to host and run your apache application check Vision apache web hosting services

Disney web site - OpenGL Super Bible! Page 59 Figure 3-8 Viewport-to-window

Monday, April 30th, 2007

OpenGL Super Bible! Page 59 Figure 3-8 Viewport-to-window mapping Defining the Clipping Volume The last requirement of our ChangeSize() function is to redefine the clipping volume so that the aspect ratio remains square. The aspect ratio is the ratio of the number of pixels along a unit of length in the vertical direction to the number of pixels along the same unit of length in the horizontal direction. An aspect ratio of 1.0 would define a square aspect ratio. An aspect ratio of 0.5 would specify that for every two pixels in the horizontal direction for a unit of length, there is one pixel in the vertical direction for the same unit of length. If a viewport is specified that is not square and it is mapped to a square clipping volume, that will cause images to be distorted. For example, a viewport matching the window size and dimensions but mapped to a square clipping volume would cause images to appear tall and thin in tall and thin windows, and wide and short in wide and short windows. In this case, our square would only appear square when the window was sized to be a square. In our example, an orthographic projection is used for the clipping volume (see Chapter 2). The OpenGL command to create this projection is glOrtho(): void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far ); In 3D Cartesian space, the left and right values specify the minimum and maximum coordinate value displayed along the x-axis; bottom and top are for the y-axis. The near and far parameters are for the z-axis, generally with negative values extending away from the viewer (see Figure 3-9).
Note: If you are looking for high quality webhost to host and run your jsp application check Vision christian web host services

Page 58 OpenGL Super (Web server application) Bible! be centered vertically,

Sunday, April 29th, 2007

Page 58 OpenGL Super Bible! be centered vertically, far left of center. If you make the window tall vertically, the square will be centered horizontally, closer to the bottom of the window. Note that the rectangle always remains square. To see a square scaled as the window resizes, see Figure 3-7a and Figure 3-7b. Figure 3-7a Image scaled to match window size Figure 3-7b Square scaled as the window resizes Defining the Viewport To understand how the viewport definition is achieved, let s look more carefully at the ChangeSize() function. It first calls glViewport() with the new width and height of the window. The glViewport function is defined as void glViewport(GLint x, GLint y, GLsizei width, GLsizei height); The x and y parameters specify the lower-right corner of the viewport within the window, and the width and height parameters specify these dimensions in pixels. Usually x and y will both be zero, but you can use viewports to render more than one drawing in different areas of a window. The viewport defines the area within the window in actual screen coordinates that OpenGL can use to draw in (see Figure 3-8). The current clipping volume is then mapped to the new viewport. If you specify a viewport that is smaller than the window coordinates, the rendering will be scaled smaller, as you see in Figure 3-8.
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision shared web hosting services

OpenGL Super Bible! Page 57 We have chosen (Cpanel web hosting)

Sunday, April 29th, 2007

OpenGL Super Bible! Page 57 We have chosen ChangeSize as a descriptive name for this function and will use that name for our future examples. The ChangeSize() function will receive the new width and height whenever the window size changes. We can use this information to modify the mapping of our desired coordinate system to real screen coordinates, with the help of two OpenGL functions: glViewport() and glOrtho(). Listing 3-3 shows our previous example modified to account for various window sizes and dimensions. Only the changed main() function and our new ChangeSize() function are shown. Listing 3-3 Scaling in OpenGL // Scale.c // Scaling an OpenGL Window. // Called by AUX Library when the window has changed size void CALLBACK ChangeSize(GLsizei w, GLsizei h) { // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); // Reset coordinate system glLoadIdentity(); // Establish clipping volume (left, right, bottom, top, near, far) if (w <= h) glOrtho (0.0f, 250.0f, 0.0f, 250.0f*h/w, 1.0, -1.0); else glOrtho (0.0f, 250.0f*w/h, 0.0f, 250.0f, 1.0, -1.0); } void main(void) { // Set up and initialize AUX window auxInitDisplayMode(AUX_SINGLE | AUX_RGBA); auxInitPosition(100,100,250,250); auxInitWindow("Scaling Window"); // Set function to call when window changes size auxReshapeFunc(ChangeSize); // Set function to call when window needs updating auxMainLoop(RenderScene); } Now, when you change the size or dimensions of the window, the square will change size as well. A much larger window will have a much larger square and a much smaller window will have a much smaller square. If you make the window long horizontally, the square will
Note: If you are looking for high quality webhost to host and run your jsp application check Vision christian web host services

Jetty web server - Page 56 OpenGL Super Bible! the AUX library

Saturday, April 28th, 2007

Page 56 OpenGL Super Bible! the AUX library by default created a viewport that matched the window size exactly (0, 0, 250, 250). The clipping volume by default was set to be the first quadrant of Cartesian space, with the x- and y-axis extending the length and height of the window. The z-axis extends perpendicular to the viewer, giving a flat 2D appearance to objects drawn in the xy plane. Figure 3-6 illustrates this graphically. Figure 3-6 The viewport and clipping volume for friendly.c Although our drawing is a 2D flat rectangle, we are actually drawing in a 3D coordinate space. The glRectf() function draws the rectangle in the xy plane at z = 0. Your perspective is down along the positive z-axis to see the square rectangle at z = 0. Whenever the window size changes, the viewport and clipping volume must be redefined for the new window dimensions. Otherwise, you ll see the effect shown in Figure 3-5, where the mapping of the coordinate system to screen coordinates stays the same regardless of window size. Because window size changes are detected and handled differently under various environments, the AUX library provides the function auxReshapeFunc(), which registers a callback that the AUX library will call whenever the window dimensions change. The function you pass to auxReshapeFunc() is prototyped like this: void CALLBACK ChangeSize(GLsizei w, GLsizei h);
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision make web site services

Web site layout - OpenGL Super Bible! Page 55 screen extents of

Friday, April 27th, 2007

OpenGL Super Bible! Page 55 screen extents of the window change; however, the drawing code continues to place the rectangle at (100, 150, 150, 100). In the original window this was directly in the center; in a larger window these coordinates are located in the lower-left corner. See Figure 3-5. Figure 3-5 Effects of changing window size Scaling to the Window In nearly all windowing environments, the user may at any time change the size and dimensions of the window. When this happens, the window usually responds by redrawing its contents, taking into consideration the window s new dimensions. Sometimes you may wish to simply clip the drawing for smaller windows, or display the entire drawing at its original size in a larger window. For our purposes, we usually will want to scale the drawing to fit within the window, regardless of the size of the drawing or window. Thus a very small window would have a complete but very small drawing, and a larger window would have a similar but larger drawing. You see this in most drawing programs when you stretch a window as opposed to enlarging the drawing. Stretching a window usually doesn t change the drawing size, but magnifying the image will make it grow. Setting the Viewport and Clipping Volume In Chapter 2 we discussed how viewports and clipping volumes affect the coordinate range and scaling of 2D and 3D drawings in a 2D window on the computer screen. Now we will examine the setting of viewport and clipping volume coordinates in OpenGL. When we created our window with the function call auxInitPosition(100,100,250,250);
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision php5 hosting services

Page 54 OpenGL Super Bible! represent two coordinate (Web hosting ecommerce)

Friday, April 27th, 2007

Page 54 OpenGL Super Bible! represent two coordinate pairs (x1, y1) and (x2, y2). The first pair represents the upper-left corner of the rectangle, and the second pair represents the lower-right corner. See Figure 3-4 if you need a review of OpenGL coordinate mapping. Initialization The main body of friendly.c starts the same way as our first example: void main(void) { // AUX library window and mode setup auxInitDisplayMode(AUX_SINGLE | AUX_RGBA); auxInitPosition(100,100,250,250); auxInitWindow(”My second OpenGL Program”); // Set function to call when window needs updating auxMainLoop(RenderScene); } As before, the three auxInitxxx calls set up and display the window in which we ll be drawing. In the final line, auxMainLoop() takes the name of the function that does the drawing, RenderScene(). The AUX library s auxMainLoop() function simply keeps the program going until it s terminated by closing the window. This function s single argument is a pointer to another function it should call whenever the window needs updating. This callback function will be called when the window is first displayed, when the window is moved or resized, and when the window is uncovered by some other window. // Called by AUX library to draw scene void CALLBACK RenderScene(void) { // Set clear color to Blue glClearColor(0.0f, 0.0f, 1.0f, 1.0f); // Clear the window glClear(GL_COLOR_BUFFER_BIT); // Set current drawing color to red // R G B glColor3f(1.0f, 0.0f, 0.0f); // Draw a filled rectangle with current color glRectf(100.0f, 150.0f, 150.0f, 100.0f); glFlush(); } At this point, the program will display a red square in the middle of a blue window, because we used fixed locations for the square. If you make the window larger, the square will remain in the lower-left corner of the window. When you make the window smaller, the square may no longer fit in the client area. This is because as you resize the window, the
Note: If you are looking for cheap webhost to host and run your apache application check Vision jboss web hosting services

Business web hosting - OpenGL Super Bible! Page 53 The Rendering Function

Thursday, April 26th, 2007

OpenGL Super Bible! Page 53 The Rendering Function Next, you ll see we have created the function RenderScene(). // Called by AUX library to draw scene void CALLBACK RenderScene(void) { …} This is where we have moved all code that does the actual drawing in the window. The process of drawing with OpenGL is often referred to as rendering, so we used that descriptive name. In later examples we ll be putting most of our drawing code in this function. Make note of the CALLBACK statement in the function declaration. This is required because we re going to tell the AUX library to call this function whenever the window needs updating. Callback functions are simply functions that you write, which the AUX library will be calling in your behalf. You ll see how this works later. Drawing a Rectangle Previously, all our program did was clear the screen. We ve added the following two lines of drawing code: // Set current drawing color to red // R G B glColor3f(1.0f, 0.0f, 0.0f); // Draw a filled rectangle with current color glRectf(100.0f, 150.0f, 150.0f, 100.0f); These lines set the color used for future drawing operations (lines and filling) with the call to glColor3f(). Then glRectf() draws a filled rectangle. The glColor3f() function selects a color in the same manner as glClearColor(), but no alpha translucency component needs to be specified: void glColor3f(GLfloat red, GLfloat green, GLfloat blue); The glRectf () function takes floating point arguments, as denoted by the trailing f. The number of arguments is not used in the function name because all glRect variations take four arguments. The four arguments of glRectf(), void glRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2);
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp web hosting services

Page 52 OpenGL Super (Web hosting bandwidth) Bible! It may not

Thursday, April 26th, 2007

Page 52 OpenGL Super Bible! It may not be the most interesting OpenGL program in existence, but shortest.c demonstrates the very basics of getting a window up using the AUX library and it shows you how to specify a color and clear the window. Next we want to spruce up our program by adding some more AUX library and OpenGL functions. Drawing Shapes with OpenGL The shortest.c program made an empty window with a blue background. Let s do some drawing in the window. In addition, we want to be able to move and resize the window so that it behaves more like a Windows window. We will also dispense with using getch() to determine when to terminate the program. In Listing 3-2 you can see the modifications. The first change you ll notice is in the headers. The conio.h file is no longer included because we aren t using getch() or cprintf() anymore. Listing 3-2 A friendlier OpenGL program // friendly.c // A friendlier OpenGL program #include // Standard header for Windows #include // OpenGL library #include // AUX library // Called by AUX library to draw scene void CALLBACK RenderScene(void) { // Set clear color to blue glClearColor(0.0f, 0.0f, 1.0f, 1.0f); // Clear the window glClear(GL_COLOR_BUFFER_BIT); // Set current drawing color to red // R G B glColor3f(1.0f, 0.0f, 0.0f); // Draw a filled rectangle with current color glRectf(100.0f, 150.0f, 150.0f, 100.0f); glFlush(); } void main(void) { // AUX library window and mode setup auxInitDisplayMode(AUX_SINGLE | AUX_RGBA); auxInitPosition(100,100,250,250); auxInitWindow(”My second OpenGL Program”); // Set function to call when window needs updating auxMainLoop(RenderScene); }
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision virtual web hosting services

OpenGL Super Bible! Page 51 Actually Clear Now

Thursday, April 26th, 2007

OpenGL Super Bible! Page 51 Actually Clear Now that we have told OpenGL what color to use for clearing, we need an instruction to do the actual clearing. This accomplished by the line glClear(GL_COLOR_BUFFER_BIT); The glClear() function clears a particular buffer or combination of buffers. A buffer is a storage area for image information. The red, green, and blue components of a drawing actually have separate buffers, but they are usually collectively referred to as the color buffer. Buffers are a powerful feature of OpenGL and will be covered in detail in Chapter 15. For the next several chapters, all you really need to understand is that the color buffer is where the displayed image is stored internally, and that clearing the buffer with glClear removes the drawing from the window. Flush That Queue Our final OpenGL function call comes next: glFlush(); This line causes any unexecuted OpenGL commands to be executed we have two at this point: glClearColor() and glClear(). Internally, OpenGL uses a rendering pipeline that processes commands sequentially. OpenGL commands and statements often are queued up until the OpenGL server processes several requests at once. This improves performance, especially when constructing complex objects. Drawing is accelerated because the slower graphics hardware is accessed less often for a given set of drawing instructions. (When Win32 was first introduced, this same concept was added to the Windows GDI to improve graphics performance under Windows NT.) In our short program, the glFlush() function simply tells OpenGL that it should proceed with the drawing instructions supplied thus far before waiting for any more drawing commands. The last bit of code for this example // Stop and wait for a keypress cprintf(”Press any key to close the Windown”); getch(); } displays a message in the console window and stops the program until you press a key, at which point the program is terminated and the window is destroyed.
Note: If you are looking for reliable webhost to maintain and run your java application check Vision java hosting services