Archive for July, 2007

Web design conference - Page 290 OpenGL Super Bible! (double)pPal->palPalEntry[i].peGreen * 255.0

Thursday, July 26th, 2007

Page 290 OpenGL Super Bible! (double)pPal->palPalEntry[i].peGreen * 255.0 /GreenRange); pPal->palPalEntry[i].peBlue = (i >> pfd.cBlueShift) & BlueRange; pPal- >palPalEntry[i].peBlue = (unsigned char)( (double)pPal->palPalEntry[i].peBlue * 255.0 / BlueRange); pPal->palPalEntry[i].peFlags = (unsigned char) NULL; } // Create the palette hRetPal = CreatePalette(pPal); // Go ahead and select and realize the palette for this device context SelectPalette(hDC,hRetPal,FALSE); RealizePalette(hDC); // Free the memory used for the logical palette structure free(pPal); // Return the handle to the new palette return hRetPal; } Palette Creation and Disposal The palette should be created and realized before the rendering context is created or made current. The function in Listing 8-4 requires only the device context, once the pixel format has been set. It will then return a handle to a palette if one is needed. Listing 8-5 shows the sequence of operations when the window is created and destroyed. This is similar to code presented previously for the creation and destruction of the rendering context, only now it also takes into account the possible existence of a palette. Listing 8-5 A palette is created and destroyed // Window creation, setup for OpenGL case WM_CREATE: // Store the device context hDC = GetDC(hWnd); // Select the pixel format SetDCPixelFormat(hDC); // Create the palette if needed hPalette = GetOpenGLPalette(hDC); // Create the rendering context and make it current hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); break;
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

OpenGL Super Bible! (Web host forum) Page 289 Listing 8-4 Function

Thursday, July 26th, 2007

OpenGL Super Bible! Page 289 Listing 8-4 Function to create a palette for OpenGL // If necessary, creates a 3-3-2 palette for the device context listed. HPALETTE GetOpenGLPalette(HDC hDC) { HPALETTE hRetPal = NULL; // Handle to palette to be created PIXELFORMATDESCRIPTOR pfd; // Pixel Format Descriptor LOGPALETTE *pPal; // Pointer to memory for logica l palette int nPixelFormat; // Pixel format index int nColors; // Number of entries in palette int i; // Counting variable BYTE RedRange,GreenRange,BlueRange; // Range for each color entry (7,7,and 3) // Get the pixel format index and retrieve the pixel format description nPixelFormat = GetPixelFormat(hDC); DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd); // Does this pixel format require a palette? If not, do not create a // palette and just return NULL if(!(pfd.dwFlags & PFD_NEED_PALETTE)) return NULL; // Number of entries in palette. 8 bits yields 256 entries nColors = 1 << pfd.cColorBits; // Allocate space for a logical palette structure plus all the palette // entries pPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) + nColors*sizeof(PALETTEENTRY)); // Fill in palette header pPal->palVersion = 0×300;// Windows 3.0 pPal- >palNumEntries = nColors; // table size // Build mask of all 1’s. This creates a number represented by having // the low order bits set, where = pfd.cRedBits, pfd.cGreenBits,and // pfd.cBlueBits. RedRange = (1 << pfd.cRedBits) -1; // 7 for 3-3-2 palettes GreenRange = (1 << pfd.cGreenBits) - 1; // 7 for 3-3-2 palettes BlueRange = (1 << pfd.cBlueBits) -1; // 3 for 3-3-2 palettes // Loop through all the palette entries for(i = 0; i < nColors; i++) { // Fill in the 8-bit equivalents for each component pPal->palPalEntry[i].peRed = (i >> pfd.cRedShift) & RedRange; pPal- >palPalEntry[i].peRed = (unsigned char)( (double) pPal->palPalEntry[i].peRed * 255.0 / RedRange); pPal->palPalEntry[i].peGreen = (i >> pfd.cGreenShift) & GreenRange; pPal- >palPalEntry[i].peGreen = (unsigned char)(
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

Page 288 OpenGL (Business web hosting) Super Bible! Table 8-1 A

Wednesday, July 25th, 2007

Page 288 OpenGL Super Bible! Table 8-1 A Few Sample Palette Entries for a 3-3-2 Palette Palette Blue Component Green Component Red Entry Binary (B G R) Component 0 000 000 000000 0 0 0 1 00 000 001 0 0 1*255/7 2 00 000 010 0 0 2*255/7 3 00 000 011 0 0 3*255/7 9 00 001 001 0 1*255/7 1*255/7 10 00 001 010 0 1*255/7 2*255/7 137 10 001 001 2*255/3 1*255/7 1*255/7 138 10 001 010 2*255/7 1*255/7 2*255/3 255 11 111 111 3*255/3 7*255/7 7*255/7 Building the Palette Unfortunately, at this time OpenGL for Windows will only support 3-3-2 palettes in RGBA color mode. This is actually specified in the PIXELFORMATDESCRIPTOR returned by DescribePixelFormat(). The members cRedBits, cGreenBits, and cBluebits specify 3, 3, and 2, respectively, for the number of bits that can represent each component. Furthermore, the cRedShift, cGreenShift, and cBlueShift values specify how much to shift the respective component value to the left (in this case, 0, 3, and 6 for red, green, and blue shifts). These sets of values compose the palette index (Figure 8-14). Figure 8-14 3-3-2 palette packing The code in Listing 8-4 creates a palette if needed and returns its handle. This function makes use of the component bit counts and shift information in the PIXELFORMATDESCRIPTOR to accommodate any subsequent palette requirements, such as a 2-2-2 palette .
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

OpenGL Super Bible! Page 287 // entries pPal (Web hosting directory)

Wednesday, July 25th, 2007

OpenGL Super Bible! Page 287 // entries pPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) + nColors*sizeof(PALETTEENTRY)); Here, nColors specifies the number of colors to place in the palette, which for our purposes is always 256. Each entry in the palette then is a PALETTEENTRY structure, which is defined as follows: typedef struct tagPALETTEENTRY { // pe BYTE peRed; BYTE peGreen; BYTE peBlue; BYTE peFlags; } PALETTEENTRY; The peRed, peGreen, and peBlue members specify an 8-bit value that represents the relative intensities of each color component. In this way, each of the 256 palette entries contains a 24-color definition. The peFlags member describes advanced usage of the palette entries. For OpenGL purposes you can just set this to NULL. In addition to the 3-3-2 palette, Windows can support other 8-bit palettes for doing things such as specifying 200 shades of gray. The 3-3-2 Palette Now comes the tricky part. Not only must our 256 palette entries be spread evenly throughout the RGB color cube, but they must be in a certain order. It is this order that enables OpenGL to find the color it needs, or the closest available color in the palette. Remember that in an 8-bit color mode you have 3 bits each for red and green, and 2 bits for blue. This is commonly referred to as a 3-3-2 palette. So our RGB color cube measures 8 by 8 by 3 along the red, green, and blue axes, respectively. To find the color needed in the palette, an 8-8-8 color reference (the 24-bit color mode setup) is scaled to a 3-3-2 reference. This 8-bit value is then the index into our palette array. The red intensities of 0 7 in the 3-3-2 palette must correspond to the intensities 0 255 in the 8-8-8 palette. Figure 8-14 illustrates how the red, green, and blue components are combined to make the palette index. When we build the palette, we loop through all values from 0 to 255. We then decompose the index into the red, green, and blue intensities represented by these values (in terms of the 3-3-2 palette). Each component is multiplied by 255 and divided by the maximum value represented, which has the effect of smoothly stepping the intensities from 0 to 7 for red and green, and from 0 to 3 for the blue. Table 8-1 shows some sample palette entries, to demonstrate component calculation.
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Most popular web site - Page 286 OpenGL Super Bible! Do You Need

Tuesday, July 24th, 2007

Page 286 OpenGL Super Bible! Do You Need a Palette? To determine if your application needs a palette, you can call DescribePixelFormat() after you have set the pixel format. Test the dwFlags member of the PIXELFORMATDECRIPTOR returned by DescribePixelFormat(), for the bit value PFD_NEED_PALETTE. If this bit is set, you will need to create a palette for use by your application. Listing 8-3 shows the necessary code for this test. Listing 8-3 Testing to see if an application needs a palette PIXELFORMATDESCRIPTOR pfd; // Pixel Format Descriptor int nPixelFormat; // Pixel format index // Get the pixel format index and retrieve the pixel format description nPixelFormat = GetPixelFormat(hDC); DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd); // Does this pixel format require a palette? if(!(pfd.dwFlags & PFD_NEED_PALETTE)) return NULL;// Does not need a palette // Palette creation code The Palette s Structure To create a palette, you must first allocate memory for a LOGPALETTE structure. This structure is filled with the information that describes the palette, and then is passed to the Win32 function CreatePalette(). The LOGPALETTE structure is defined as follows: typedef struct tagLOGPALETTE { // lgpl WORD palVersion; WORD palNumEntries; PALETTEENTRY palPalEntry[1]; } LOGPALETTE; The first two members are the palette header and contain the palette version (always set to 0×300) and the number of color entries (256 for 8-bit modes). Each entry is then defined as a PALETTEENTRY structure that contains the RGB components of the color entry. The following code allocates space for the logical palette: LOGPALETTE *pPal; // Pointer to memory for logical palette // Allocate space for a logical palette structure plus all the palette
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Top ten web hosting - OpenGL Super Bible! Page 285 // This window

Tuesday, July 24th, 2007

OpenGL Super Bible! Page 285 // This window may set the palette, even though it is not the // currently active window. case WM_PALETTECHANGED: // Don’t do anything if the palette does not exist, or if // this is the window that changed the palette. if((hPalette != NULL) && ((HWND)wParam != hWnd)) { // Select the palette into the device context SelectPalette(hDC,hPalette,FALSE); // Map entries to system palette RealizePalette(hDC); // Remap the current colors to the newly realized palette UpdateColors(hDC); return 0; } break; Another message sent by Windows for palette realization is WM_PALETTECHANGED. This message is sent to windows that can realize their palette but may not have the current focus. When this message is sent, you must also check the value of wParam. If wParam contains the handle to the current window receiving the message, then WM_QUERYNEWPALETTE has already been processed, and the palette does not need to be realized again. Note also in Listing 8-2 that the value of hPalette is checked against NULL before either of these palette-realization messages is processed. If the application is not running in 8-bit color mode, then no palette needs to be created or realized by these functions. Structuring your code in this way makes it useful for displays that don t use palettes as well as those that do. Creating a Palette Unfortunately, palette considerations are a necessary evil if your application is to run on the 8-bit hardware that s still in use in some environments. So what do you do if your code is executing on a machine that only supports 256 colors? For image reproduction, we recommend selecting a range of colors that closely match the original colors. For OpenGL rendering under most circumstances, however, you want the widest possible range of colors for general-purpose use. The trick is to select the palette colors so that they re evenly distributed throughout the color cube. Then, whenever a color is specified that is not already in the palette, Windows will select the nearest color in the color cube. As mentioned earlier, this is not ideal for some applications, but for OpenGL rendered scenes it is the best we can do. Unless there is substantial texture mapping in the scene with a wide variety of colors, results are usually acceptable.
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Page 284 OpenGL Super Bible! Palette (Web hosting billing) Arbitration Windows

Monday, July 23rd, 2007

Page 284 OpenGL Super Bible! Palette Arbitration Windows multitasking allows many applications to be on screen at once. The hardware supports only 256 colors on screen at once, however, so all applications must share the same system palette. If one application changes the system palette, images in the other windows may have scrambled colors, producing some undesired psychedelic effects. To arbitrate palette usage among applications, Windows sends a set of messages. Applications are notified when another application has changed the system palette, and they are notified when their window has received focus and palette modification is possible. When an application receives keyboard or mouse input focus, Windows sends a WM_QUERYNEWPALETTE message to the main window of the application. This message asks the application if it wants to realize a new palette. Realizing a palette means the application copies the palette entries from its private palette to the system palette. To do this, the application must first select the palette into the device context for the window being updated, and then call RealizePalette. Listing 8-2 presents the code for this message handler; it will be in all subsequent examples from this book. Listing 8-2 Typical palette-arbitration code for Windows-based applications static HPALETTE hPalette = NULL; // Permenant palette handle // Palette is created and referenced by hPalette // Windows is telling the application that it may modify // the system palette. This message in essance asks the // application for a new palette. case WM_QUERYNEWPALETTE: // If the palette was created. if(hPalette) { int nRet; // Selects the palette into the current device context SelectPalette(hDC, hPalette, FALSE); // Map entries from the currently selected palette to // the system palette. The return value is the number // of palette entries modified. nRet = RealizePalette(hDC); // Repaint, forces remap of palette in current window InvalidateRect(hWnd,NULL,FALSE); return nRet; } break;
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

OpenGL Super Bible! Page 283 Windows uses dithering (Top web site)

Monday, July 23rd, 2007

OpenGL Super Bible! Page 283 Windows uses dithering to produce colors not available in the current palette. In 16-color mode, image quality is typically very poor for more complex scenes. Figure 8-12 is a vivid demonstration of Windows dithering; we attempted to produce the RGB triangle on a system with only 16 colors. Generally, Windows does not perform dithering for OpenGL. OpenGL can also do its own dithering, providing the command glEnable(GL_DITHER); This can sometimes improve image quality substantially in 8- and 15-bit color modes. You can see dithering in action in the example program DITHER from this chapter s subdirectory on the CD. This program draws a cube with sides of various colors and allows dithering to be enabled or disabled from the menu. When run in 8-bit color mode or better, dithering has little effect, but in the 4-bit, 16-color mode the dithered scene is remarkably different. Advantages of a Palette in 8-Bit Mode The 8-bit color modes can display 256 colors, and this results in a remarkable improvement for color graphics. When Windows is running in a color mode that supports 256 colors, it would make sense if those colors were evenly distributed across RGB color space. Then all applications would have a relatively wide choice of colors, and when a color was selected, the nearest available color would be used. Unfortunately, this is not very practical in the real world. Since the 256 colors in the palette for the device can be selected from over 16 million different colors, an application can substantially improve the quality of its graphics by carefully selecting those colors and many do. For example, to produce a seascape, additional shades of blue will be needed. CAD and modeling applications modify the palette to produce smooth shading of a surface of a particular single color. For example, the scene may require as many as 200 shades of gray to accurately render the image of a pipe s cross section. Thus, applications for the PC typically change this palette to meet their needs, resulting in near-photographic quality for many images and scenes. For 256 color bitmaps, the Windows .bmp format even has an array that s 256 entries long, containing 24-bit RGB values specifying the palette for the stored image. An application can create a palette with the CreatePalette function, identifying the palette by a handle of type HPALETTE. This function takes a logical palette structure (LOGPALETTE) that contains 256 entries, each specifying 8-bit values for red, green, and blue components. But before we examine palette creation, let s take a look at how multitasked applications can share the single system palette in 8-bit color mode.
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

Page 282 OpenGL Super Bible! If the PC (Affordable web design)

Monday, July 23rd, 2007

Page 282 OpenGL Super Bible! If the PC graphics card is in 24-bit color mode, then each pixel is displayed precisely in the color specified by the 24-bit value (three 8-bit intensities). In the 15- and 16-bit color modes, Windows passes the 24-bit color value to the display driver, which converts the color to a 15- or 16-bit color value before displaying it. In 24-bit color mode, the RGB color cube measured 255 (or 8 bits) per side. In 15- or 16-bit color mode, the color cube measures 32 (5 bits) or 64 (6 bits) on a side. The device driver then matches the 24-bit color value to the nearest color match in the 15 or 16-bit color cube. Figure 8-13 shows how an 8-bit red value might be mapped to a 5-bit red value. Figure 8-13 A medium-intensity red being mapped from an 8-bit value to a 5-bit value At the low end of the scale, 4-bit color mode can only display 16 colors. These colors are fixed and cannot be modified. Internally, Windows still represents each color with a 24-bit RGB value. When you specify a color to use for drawing operations using the RGB macro or glColor3ub, Windows uses the nearest color of the 16 available to fulfill the request. If the color is being used for fill operations, the color is approximated by dithering the available colors. Dithering Having only 16 colors to work with makes the 4-bit color modes poorly suited for graphics. One thing the Windows GDI will do to help is to perform dithering on solid shapes and objects in this mode. Dithering is a means of placing different colors close together to produce the illusion of another composite color. For example, if you place yellow and blue squares together in a checkerboard pattern, the pattern will take on a greenish appearance. Without actually mixing the colors, the green would have a grainy appearance. By changing the proportion of yellow to green squares, you are effectively changing the intensities of yellow and green.
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

OpenGL Super Bible! Page 281 Figure 8-12a Output (Simple web server)

Sunday, July 22nd, 2007

OpenGL Super Bible! Page 281 Figure 8-12a Output of the TRIANGLES sample with 16 colors Figure 8-12b With 16 million colors the triangle is much smoother Color Matching What happens when you try to draw a pixel of a particular color using the RGB values we have discussed? Internally, Windows defines a color using 8 bits each for the red, green, and blue components using the RGB macro, and you can use glColor3ub to duplicate this functionality within OpenGL.
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.