OpenGL Super Bible! Page 293 Using Color Index (Web host)

OpenGL Super Bible! Page 293 Using Color Index Mode To specify color index mode, all you need to do is set the iPixelType member of the PIXELFORMATDESCRIPTOR to PFD_TYPE_COLORINDEX. First, though, you need to create a palette. With color index mode, the palette is specific to the application. For our INDEX sample program, we want a palette consisting only of shades of red to do very smooth shading in an 8-bit color mode. Listing 8-6 is the code to create this palette. Listing 8-6 Code to create a palette consisting only of shades of red // Creates a color ramp from black to bright red HPALETTE GetRedPalette(HDC hDC) { HPALETTE hRetPal = NULL; // Handle to palette to be created LOGPALETTE *pPal; // Pointer to memory for logical palette int i; // Counting variable // Allocate space for a logical palette structure plus all the palette // entries pPal = {LOGPALETTE*)malloc(sizeof(LOGPALETTE)+256*sizeof(PALETTEENTRY)); // Fill in palette header pPal->palVersion = 0×300;// Windows 3.0 pPal- >palNumEntries = 256;// table size // Loop through all the palette entries, creating a graduated red // palette containing only shades of red for(i = 10; i < 246; i++) { pPal->palPalEntry[i].peRed = i;// Red intensity from 0 to 255 pPal- >palPalEntry[i].peGreen = 0; pPal->palPalEntry[i].peBlue = 0; 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; }
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Leave a Reply