OpenGL Super Bible! (Web host forum) Page 289 Listing 8-4 Function
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.