Archive for December, 2007

Page 448 OpenGL Super Bible! Defining the Terrain

Friday, December 21st, 2007

Page 448 OpenGL Super Bible! Defining the Terrain To keep things simple, we ll define our terrain as a grid of elevation points with a texture attribute such as this is water or this is a mountain. Each point in the grid will also have an associated lighting normal to add realism. #define TERRAIN_SIZE 21 int TerrainType[TERRAIN_SIZE][TERRAIN_SIZE]; GLfloat TerrainHeight[TERRAIN_SIZE][TERRAIN_SIZE]; GLfloat TerrainNormal[TERRAIN_SIZE][TERRAIN_SIZE][3]; Here the TerrainType array contains the type of terrain at each point and is assigned one of the following control IDs from our user-interface resource file: IDC_GRASS Grasslands IDC_WATER Water IDC_TREES Trees/woodland IDC_ROCKS Rocks/cliffs IDC_MOUNTAINS Mountains Drawing Terrain Our terrain drawing controls consist of a toolbar dialog window with five buttons that select the current type of terrain. To draw the terrain, you just click and drag in the main window (see Figure 12-4). Figure 12-4 Textured terrain editing window
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Starting a web site - OpenGL Super Bible! Page 447 To make your

Thursday, December 20th, 2007

OpenGL Super Bible! Page 447 To make your life a bit easier, the OpenGL utility library (GLU32.LIB) provides two functions that automatically generate mipmapped images based on a single, high-resolution texture. In the following code, the gluBuild1DMipmaps and gluBuild2DMipmaps functions take the place of glTexImage1D and glTexImage2D: /* 1D texture */ glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); gluBuild1DMipmaps(GL_TEXTURE_1D, 3, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, roygbiv_image); /* 2D texture */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, info->bmiHeader.biWidth, info- >bmiHeader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, rgb); Because the gluBuild1DMipmaps and gluBuild2DMipmaps functions create images from one image, the appearance of some textured images may not be accurate. It s like drawing text characters at different sizes scaling the bitmaps doesn t always generate good-looking results! When you run into this sort of problem, generate your mipmap images manually. A Terrain Viewing Program Our project for this chapter is a terrain viewing program that takes advantage of some of the texture-mapping features we have discussed. With this program, we ll want to accomplish the following: View textured terrain scenes Edit the terrain interactively in 3D Fly through the terrain Print the current scene Save the current scene to a .BMP file The entire terrain program is listed at the end of this chapter, just before the Reference Section. A copy of the program is in the CH12 source directory on your CD-ROM. Double- click on the TEXSCENE.EXE program icon to try it out!
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Page 446 OpenGL Super Bible! glTexImage1D(GL_TEXTURE_1D, 0, 3, (Tomcat web server)

Wednesday, December 19th, 2007

Page 446 OpenGL Super Bible! glTexImage1D(GL_TEXTURE_1D, 0, 3, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, roygbiv_image0); glTexImage1D(GL_TEXTURE_1D, 1, 3, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, roygbiv_image1); glTexImage1D(GL_TEXTURE_1D, 2, 3, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, roygbiv_image2); glTexImage1D(GL_TEXTURE_1D, 3, 3, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, roygbiv_image3); glTexImage1D(GL_TEXTURE_1D, 4, 3, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, roygbiv_image4); glEndList(); The image levels are specified in the first parameter to glTexImage1D(). The level 0 image is your primary, highest-resolution image for the texture. The level 1 image is half the size of the primary image, and so forth. When drawing polygons with a mipmapped texture, you need to use one of the minification filters (GL_TEXTURE_MIN_FILTER) in Table 12-3. Table 12-3 Minification Filters Filter Description GL_NEAREST_MIPMAP_NEAREST Use the image nearest to the screen (polygon) resolution. Use the GL_NEAREST filter when texturing with this image. GL_NEAREST_MIPMAP_LINEAR Use the image nearest to the screen (polygon) resolution. Use the GL_LINEAR filter when texturing with this image. GL_LINEAR_MIPMAP_NEAREST Linearly interpolate between the two images nearest to the screen (polygon) resolution. Use the GL_NEAREST filter when texturing with this image. GL_LINEAR_MIPMAP_LINEAR Linearly interpolate between the two images nearest to the screen (polygon) resolution. Use the GL_LINEAR filter when texturing with this image. The GL_LINEAR_MIPMAP_NEAREST and GL_LINEAR_MIPMAP_LINEAR filters can be very expensive in terms of display performance. GL_NEAREST_MIPMAP_NEAREST is roughly equivalent to GL_NEAREST in performance, but generally produces much better results. Mipmap images are chosen by comparing the size of the polygon as it will be drawn on the screen, to the sizes of the mipmap images.
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Sex offenders web site - OpenGL Super Bible! Page 445 If you use

Tuesday, December 18th, 2007

OpenGL Super Bible! Page 445 If you use GL_REPEAT instead, the texture image is tiled over the polygon. Texture coordinates are used modulo 1.0 that is, the texture image repeats at regular intervals. GL_REPEAT texturing can be used to reduce the size of texture images on repetitive surfaces. The challenge with these kinds of textures is to make the edges of each tile blend into the next. Automatically Generating Texture Coordinates: Generating texture coordinates can be a tedious task. Later in this chapter you ll learn about the glTexGen functions that can generate these coordinates automatically for you. Mipmapped Textures So far, we ve dealt exclusively with single-texture images. That is, whenever we draw a textured polygon, the polygon is painted with a single 1D or 2D image. This is fine for some scenes, but animated displays often need various levels of detail depending on the distance from the viewer. For example, when walking through a virtual room, you might want a high- resolution image of a picture close up, but only the outline at a distance. OpenGL supports textures with multiple images, called mipmapped textures. Mipmapping selects the texture image closest to the screen resolution for a polygon. Loading mipmapped textures takes slightly longer than standard textures, but the visual results are impressive. In addition, mipmapped textures can improve display performance by reducing the need for GL_LINEAR image filters. What Does the ‘Mip in ‘Mipmapped Mean?: ‘mip is latin for ‘many . ‘Mipmapping means ‘many images . Mipmapped textures are defined by providing a specific level parameter for each image. For the ROY-G-BIV texture in the previous example, you would use the following: static unsigned char roygbiv_image0[16][3]; static unsigned char roygbiv_image1[8][3]; static unsigned char roygbiv_image2[4][3]; static unsigned char roygbiv_image3[2][3]; static unsigned char roygbiv_image4[1][3]; glNewList(RainbowTexture = glGenLists(1), GL_COMPILE); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Page 444 OpenGL Super Bible! Listing 12-3 Drawing (Adelphia web hosting)

Monday, December 17th, 2007

Page 444 OpenGL Super Bible! Listing 12-3 Drawing a 1D textured rainbow glEnable(GL_TEXTURE_1D); glCallList(RainbowTexture); glBegin(GL_QUAD_STRIP); for (th = 0.0; th <= M_PI; th += (0.03125 * M_PI)) { /* * Bottom edge of rainbow */ x = cos(th) * 50.0; y= sin(th) * 50.0; z = -50.0; glTexCoord1f(0.0); glVertex3f(x, y, z); /* * Top edge of rainbow */ x = cos(th) * 55.0; y = sin(th) * 55.0; z = -50.0; glTexCoord1f(1.0); glVertex3f(x, y, z); }; glEnd(); To position the ROY-G-BIV texture on the rainbow, you call glTexCoord. For 1D textures, you call one of the glTexCoord1f, glTexCoord1d, glTexCoord1s, or glTexCoord1i functions. A value of 0.0 represents the leftmost pixel in the image, and 1.0 represents the rightmost pixel. Values outside this range are handled differently depending on the value of the GL_TEXTURE_WRAP_S parameter. If GL_TEXTURE_WRAP_S is set to GL_CLAMP (the default), then texture coordinates are restricted to a range of 0.0 to 1.0, inclusive. When a polygon strays from the texture image, it is drawn using the color(s) along the texture image s edges (see Figure 12-3) or the texture image border colors, if defined. Texture coordinates are traditionally referred to as S and T, or (s,t) instead of X and Y. Figure 12-3 GL_CLAMP textures
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

OpenGL Super Bible! Page 443 Drawing Textured Polygons (Web design portfolio)

Sunday, December 16th, 2007

OpenGL Super Bible! Page 443 Drawing Textured Polygons Once you have defined a texture, you still have to enable texturing. To enable 1D texturing, you d use the following: glDisable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_1D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); The glEnable call enables 1D texturing. If you forget to enable texturing, none of your polygons will be textured! The glTexEnvi function sets texturing to decal mode, meaning that images are overlaid directly upon the polygons. Other texturing modes are listed in Table 12-2. Table 12-2 Texture Modes for GL_TEXTURE_ENV_MODE Mode Description GL_MODULATE Texture pixels filter existing pixel colors on the screen. GL_DECAL Texture pixels replace existing pixels on the screen. GL_BLEND Texture pixels filter existing pixels colors and are combined with a constant color. The GL_MODULATE texture mode multiplies the current texture color (or luminance) by the color on the screen. For one-component (luminance) textures, this translates into a brightness filter that will vary the brightness of the screen image based upon the texture image. For three-component (RGB) textures, you can generate colored lens filter effects. Unlike GL_MODULATE texturing, GL_BLEND texturing allows you to blend a constant color into the scene based upon the texture image. You d use GL_BLEND texturing for things like clouds; the constant color would be off-white, and the texture image would be of a cloud. Once you have defined the texturing mode to use, you can then proceed with the drawing of your polygons. Listing 12-3 shows how to draw the rainbow in Figure 12-1.
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

Msn web hosting - Page 442 OpenGL Super Bible! bits = LoadDIBitmap(’textures/sky.bmp ,

Saturday, December 15th, 2007

Page 442 OpenGL Super Bible! bits = LoadDIBitmap(’textures/sky.bmp , &info); if (bits == NULL) return; rgb = ConvertRGB(info, bits); if (rgb == NULL) { free(info); free(bits); return; }; glNewList(SkyTexture = glGenLists(1), GL_COMPILE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINE AR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); /* * Define the 2D texture image. */ glPixelStorei(GL_UNPACK_ALIGNMENT, 4); /* Force 4-byte alignment */ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); glTexImage2D(GL_TEXTURE_2D, 0, 3, info->bmiHeader.biWidth, info- >bmiHeader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, rgb); glEndList(); /* * Free the bitmap and RGB images, then return 0 (no errors). */ free(rgb); free(info); free(bits); } A Note About Textures: You ll notice that all the examples presented in this chapter use display lists to store texture images. Display lists generally speed up the drawing of static graphics commands, and texture images are no exception. In addition, the forthcoming OpenGL 1.1 API includes texture object support that optimizes texture images stored in display lists by keeping them loaded in the graphics hardware texture memory if available.
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

OpenGL Super Bible! Page 441 Table 12-1 Texture (Web hosting providers)

Friday, December 14th, 2007

OpenGL Super Bible! Page 441 Table 12-1 Texture Image Filters Filter Description GL_NEAREST Nearest-neighbor filtering. GL_LINEAR Linear interpolation. GL_NEAREST_MIPMAP_NEAREST Nearest-neighbor mipmapped filtering. GL_NEAREST_MIPMAP_LINEAR Linear interpolated mipmaps. GL_LINEAR_MIPMAP_NEAREST Linear interpolation of mipmaps. Linear interpolation of interpolated GL_LINEAR_MIPMAP_LINEAR mipmaps. GL_NEAREST filtering takes the closest pixel in the texture image rather than interpolating between pixels. You ll learn more about mipmap filtering later in the chapter. Defining 2D Textures To define a 2D texture image in OpenGL, you call glTexImage2D. The glTexImage2D function takes a height argument in addition to the ones that glTexImage1D uses, as follows: void glTexImage2D(GLenum target, GLint level, GLint components, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) Like glTexImage1D, the width and height arguments must be a power of 2. Listing 12-2 shows how to load a sky texture image complete with clouds. Listing 12-2 Defining a 2D texure image void LoadAllTextures(void) { BITMAPINFO *info; /* Bitmap information */ void *bits; /* Bitmap pixel bits */ GLubyte *rgb; /* Bitmap RGB p ixels */ /* * Try loading the bitmap and converting it to RGB */
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Web design - Page 440 OpenGL Super Bible! The width parameter

Thursday, December 13th, 2007

Page 440 OpenGL Super Bible! The width parameter specifies the width of the main texture image (without the border pixels) and must be a power of 2. The format argument indicates the type of color values to expect GL_COLOR_INDEX, GL_LUMINANCE, GL_RGB, or GL_RGBA. You ll find an example of defining a 1D texture in Listing 12-1 and in the example code CH12TEX1D.C on the source code CD-ROM. Listing 12-1 Defining a 1D texture image void LoadAllTextures(void) { static unsigned char roygbiv_image[8][3] = { { 0×3f, 0×00, 0×3f }, /* Dark Violet (for 8 colors ) */ { 0×7f, 0×00, 0×7f }, /* Violet */ { 0xbf, 0×00, 0xbf }, /* Indigo */ { 0×00, 0×00, 0xff }, /* Blue */ { 0×00, 0xff, 0×00 }, /* Green */ { 0xff, 0xff, 0×00 }, /* Yellow */ { 0xff, 0×7f, 0×00 }, /* Orange */ { 0xff, 0×00, 0×00 } /* Red */ }; glNewList(RainbowTexture = glGenLists(1), GL_COMPILE); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage1D(GL_TEXTURE_1D, 0, 3, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, roygbiv_image); glEndList(); } The example code creates a display list containing the texture image and the desired magnification and minification filter, GL_LINEAR. The minification filter is used when the polygon to be drawn is smaller than the texture image, in this case 8 pixels. The magnification filter is used when the polygon is larger than the texture image. By designating the GL_LINEAR filter, you tell OpenGL to linearly interpolate color values in the texture image before drawing anything on the screen. The other filters you can use for GL_TEXTURE_MIN_FILTER are listed in Table 12-1.
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

OpenGL Super Bible! Page 439 The 1D and (Web hosting packages)

Wednesday, December 12th, 2007

OpenGL Super Bible! Page 439 The 1D and 2D textures you ve seen so far are composed of RGB color values. Textures can also be composed of color indices or luminance (gray) levels, and can include alpha (transparency) values. The latter is useful for defining natural objects such as trees, because the alpha value can be used to make the tree visible but let the background show through. You ll learn more about this in Chapter 16. Some hardware also supports 3D (volume) textures with OpenGL. Volume textures are used for viewing CAT, MRI, and other 3D scans. Unfortunately, even a small 256 x 256 x 256 grayscale texture image will need a whopping 16 MB of memory. Currently an extension to OpenGL, 3D texturing may be included as a required feature in the OpenGL 1.1 specification. Defining Texture Images Naturally, you must define a texture image before you can draw textured polygons in OpenGL. Texture images follow the same storage rules as bitmaps (discussed in Chapter 11). A Note About Texture Images: The OpenGL standard requires that texture images dimensions must be a power of 2. Texture images can also have 1 or 2 border pixels around their edges to define the color of polygons that fall outside the texture image. Defining 1D Textures OpenGL provides a single function for defining 1D textures: glTexImage1D. The glTexImage1D function accepts eight arguments: void glTexImage1D(GLenum target, GLint level, GLint components, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels) The target argument specifies which texture should be defined; this argument must be GL_TEXTURE_1D. The level argument indicates the texture image s level of detail and is usually 0. Other values are used for mipmapped textures (described later in this chapter). The components argument specifies the number of color values used for each pixel. For color index textures, components must be 1. Values of 3 and 4 are used for RGB and RGBA texture images, respectively. Width and border specify the size of the texture image. The border value controls the number of border pixels OpenGL should expect (and use) and may have a value of 0, 1, or 2.
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.