1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| int pf, maxpf;
PIXELFORMATDESCRIPTOR pfd;
LAYERPLANEDESCRIPTOR lpd; /* layer plane descriptor */
int nEntries = 2; /* number of entries in palette */
COLORREF crEntries[2] = { /* entries in custom palette */
0x00000000, /* black (ref #0 = transparent) */
0x00ff0000, /* blue */
};
/* get the maximum number of pixel formats */
maxpf = DescribePixelFormat(hDC, 0, 0, NULL);
/* find an overlay layer descriptor */
for(pf = 0; pf < maxpf; pf++) {
DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
/* the bReserved field of the PIXELFORMATDESCRIPTOR contains the
number of overlay/underlay planes */
if (pfd.bReserved > 0) {
/* aha! This format has overlays/underlays */
wglDescribeLayerPlane(hDC, pf, 1,
sizeof(LAYERPLANEDESCRIPTOR), &lpd);
if (lpd.dwFlags & LPD_SUPPORT_OPENGL && lpd.dwFlags & flags)
{
goto found;
}
}
}
found:
/* now get the "normal" pixel format descriptor for the layer */
DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
/* set the pixel format */
if(SetPixelFormat(hDC, pf, &pfd) == FALSE) {
MessageBox(NULL,
"SetPixelFormat() failed: Cannot set format specified.",
"Error", MB_OK);
return 0;
}
/* set up the layer palette */
wglSetLayerPaletteEntries(hDC, 1, 0, nEntries, crEntries);
/* realize the palette */
wglRealizeLayerPalette(hDC, 1, TRUE);
/* announce what we've got */
printf("Number of overlays = %d\n", pfd.bReserved);
printf("Color bits in the overlay = %d\n", lpd.cColorBits);
return pf; |
Partager