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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
|
/* $Id: toglWGL.c,v 1.1 2012/10/24 22:52:31 mgltools Exp $ */
/* vi:set sw=4 expandtab: */
/*
* Togl - a Tk OpenGL widget
*
* Copyright (C) 1996-2002 Brian Paul and Ben Bederson
* Copyright (C) 2005-2009 Greg Couch
* See the LICENSE file for copyright details.
*/
/* TODO: fullscreen support */
#include <windows.h>
#include <GL/gl.h>
#include <wingdi.h>
#include <tk.h>
#include <tkPlatDecls.h>
#include <GL/wglext.h>
#ifndef PFD_SUPPORT_COMPOSITION
/* for Vista -- not needed because we don't use PFD_SUPPORT_GDI/BITMAP */
# define PFD_SUPPORT_COMPOSITION 0x00008000
#endif
/* TODO: move these statics into global structure */
static PFNWGLGETEXTENSIONSSTRINGARBPROC getExtensionsString = NULL;
static PFNWGLCHOOSEPIXELFORMATARBPROC choosePixelFormat;
static PFNWGLGETPIXELFORMATATTRIBIVARBPROC getPixelFormatAttribiv;
static PFNWGLCREATEPBUFFERARBPROC createPbuffer = NULL;
static PFNWGLDESTROYPBUFFERARBPROC destroyPbuffer = NULL;
static PFNWGLGETPBUFFERDCARBPROC getPbufferDC = NULL;
static PFNWGLRELEASEPBUFFERDCARBPROC releasePbufferDC = NULL;
static PFNWGLQUERYPBUFFERARBPROC queryPbuffer = NULL;
static int hasMultisampling = FALSE;
static int hasPbuffer = FALSE;
static int hasARBPbuffer = FALSE;
static HWND
toglCreateTestWindow(HWND parent)
{
static char ClassName[] = "ToglTestWindow";
WNDCLASS wc;
HINSTANCE instance = GetModuleHandle(NULL);
HWND wnd;
HDC dc;
PIXELFORMATDESCRIPTOR pfd;
int pixelFormat;
wc.style = CS_OWNDC;
wc.lpfnWndProc = DefWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = instance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = ClassName;
if (!RegisterClass(&wc)) {
DWORD err = GetLastError();
if (err != ERROR_CLASS_ALREADY_EXISTS) {
fprintf(stderr, "Unable to register Togl Test Window class\n");
return NULL;
}
}
wnd = CreateWindow(ClassName, "test OpenGL capabilities",
WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
0, 0, 1, 1, parent, NULL, instance, NULL);
if (wnd == NULL) {
fprintf(stderr, "Unable to create temporary OpenGL window\n");
return NULL;
}
dc = GetDC(wnd);
memset(&pfd, 0, sizeof pfd);
pfd.nSize = sizeof pfd;
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 3;
pfd.iLayerType = PFD_MAIN_PLANE;
pixelFormat = ChoosePixelFormat(dc, &pfd);
if (pixelFormat == 0) {
fprintf(stderr, "Unable to choose simple pixel format\n");
ReleaseDC(wnd, dc);
return NULL;
}
if (!SetPixelFormat(dc, pixelFormat, &pfd)) {
fprintf(stderr, "Unable to set simple pixel format\n");
ReleaseDC(wnd, dc);
return NULL;
}
ShowWindow(wnd, SW_HIDE); // make sure it's hidden
ReleaseDC(wnd, dc);
return wnd;
}
struct FBInfo
{
int stereo;
int acceleration;
int colors;
int depth;
int samples;
int pixelFormat;
};
typedef struct FBInfo FBInfo;
static int FBAttribs[] = {
/* must match order in FBInfo structure */
WGL_STEREO_ARB,
WGL_ACCELERATION_ARB,
WGL_COLOR_BITS_ARB,
WGL_DEPTH_BITS_ARB,
WGL_SAMPLES_ARB,
};
#define NUM_FBAttribs (sizeof FBAttribs / sizeof FBAttribs[0])
static int
FBInfoCmp(const void *a, const void *b)
{
/*
* 1. stereo is better
* 2. full acceleration is better
* 3. greater color bits is better
* 4. greater depth bits is better
* 5. more multisampling is better
*/
const FBInfo *x = (const FBInfo *) a;
const FBInfo *y = (const FBInfo *) b;
if (x->stereo != y->stereo)
return y->stereo - x->stereo;
if (x->acceleration != y->acceleration)
return y->acceleration - x->acceleration;
if (x->colors != y->colors)
return y->colors - x->colors;
if (x->depth != y->depth)
return y->depth - x->depth;
if (x->samples != y->samples)
return y->samples - x->samples;
return 0;
}
static int
togl_pixelFormat(Togl *togl, HWND hwnd)
{
/* return 0 when pixel format is unavailable. */
int pixelformat = 0;
static int loadedOpenGL = FALSE;
int formats[256];
UINT numFormats;
FBInfo *info;
UINT i;
int attribs[128];
int na = 0;
if (!loadedOpenGL) {
HWND test = NULL;
HDC dc;
HGLRC rc;
if (wglGetCurrentContext() != NULL) {
dc = wglGetCurrentDC();
} else {
/* HWND hwnd = Tk_GetHWND(Tk_WindowId(togl->TkWin)); */
test = toglCreateTestWindow(hwnd);
if (test == NULL) {
Tcl_SetResult(togl->Interp,
TCL_STUPID "can't create dummy OpenGL window",
TCL_STATIC);
return 0;
}
dc = GetDC(test);
rc = wglCreateContext(dc);
wglMakeCurrent(dc, rc);
}
loadedOpenGL = TRUE;
/*
* Now that we have an OpenGL window, we can initialize all
* OpenGL information and figure out if multisampling is supported.
*/
getExtensionsString = (PFNWGLGETEXTENSIONSSTRINGARBPROC)
wglGetProcAddress("wglGetExtensionsStringARB");
if (getExtensionsString == NULL)
getExtensionsString = (PFNWGLGETEXTENSIONSSTRINGARBPROC)
wglGetProcAddress("wglGetExtensionsStringEXT");
if (getExtensionsString) {
const char *extensions = getExtensionsString(dc);
if (strstr(extensions, "WGL_ARB_multisample") != NULL
|| strstr(extensions, "WGL_EXT_multisample") != NULL)
hasMultisampling = TRUE;
if (strstr(extensions, "WGL_ARB_pixel_format") != NULL) {
choosePixelFormat = (PFNWGLCHOOSEPIXELFORMATARBPROC)
wglGetProcAddress("wglChoosePixelFormatARB");
getPixelFormatAttribiv = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
wglGetProcAddress("wglGetPixelFormatAttribivARB");
if (choosePixelFormat == NULL || getPixelFormatAttribiv == NULL) {
choosePixelFormat = NULL;
getPixelFormatAttribiv = NULL;
}
}
if (choosePixelFormat == NULL
&& strstr(extensions, "WGL_EXT_pixel_format") != NULL) {
choosePixelFormat = (PFNWGLCHOOSEPIXELFORMATARBPROC)
wglGetProcAddress("wglChoosePixelFormatEXT");
getPixelFormatAttribiv = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
wglGetProcAddress("wglGetPixelFormatAttribivEXT");
if (choosePixelFormat == NULL || getPixelFormatAttribiv == NULL) {
choosePixelFormat = NULL;
getPixelFormatAttribiv = NULL;
}
}
if (createPbuffer == NULL
&& strstr(extensions, "WGL_ARB_pbuffer") != NULL) {
createPbuffer = (PFNWGLCREATEPBUFFERARBPROC)
wglGetProcAddress("wglCreatePbufferARB");
destroyPbuffer = (PFNWGLDESTROYPBUFFERARBPROC)
wglGetProcAddress("wglDestroyPbufferARB");
getPbufferDC = (PFNWGLGETPBUFFERDCARBPROC)
wglGetProcAddress("wglGetPbufferDCARB");
releasePbufferDC = (PFNWGLRELEASEPBUFFERDCARBPROC)
wglGetProcAddress("wglReleasePbufferDCARB");
queryPbuffer = (PFNWGLQUERYPBUFFERARBPROC)
wglGetProcAddress("wglQueryPbufferARB");
if (createPbuffer == NULL || destroyPbuffer == NULL
|| getPbufferDC == NULL || releasePbufferDC == NULL
|| queryPbuffer == NULL) {
createPbuffer = NULL;
destroyPbuffer = NULL;
getPbufferDC = NULL;
releasePbufferDC = NULL;
queryPbuffer = NULL;
} else {
hasPbuffer = TRUE;
hasARBPbuffer = TRUE;
}
}
if (createPbuffer == NULL
&& strstr(extensions, "WGL_EXT_pbuffer") != NULL) {
createPbuffer = (PFNWGLCREATEPBUFFERARBPROC)
wglGetProcAddress("wglCreatePbufferEXT");
destroyPbuffer = (PFNWGLDESTROYPBUFFERARBPROC)
wglGetProcAddress("wglDestroyPbufferEXT");
getPbufferDC = (PFNWGLGETPBUFFERDCARBPROC)
wglGetProcAddress("wglGetPbufferDCEXT");
releasePbufferDC = (PFNWGLRELEASEPBUFFERDCARBPROC)
wglGetProcAddress("wglReleasePbufferDCEXT");
queryPbuffer = (PFNWGLQUERYPBUFFERARBPROC)
wglGetProcAddress("wglQueryPbufferEXT");
if (createPbuffer == NULL || destroyPbuffer == NULL
|| getPbufferDC == NULL || releasePbufferDC == NULL
|| queryPbuffer == NULL) {
createPbuffer = NULL;
destroyPbuffer = NULL;
getPbufferDC = NULL;
releasePbufferDC = NULL;
queryPbuffer = NULL;
} else {
hasPbuffer = TRUE;
}
}
}
/* No need to confirm multisampling is in glGetString(GL_EXTENSIONS)
* because OpenGL driver is local */
if (test != NULL) {
/* cleanup by removing temporary OpenGL window */
wglMakeCurrent(NULL, NULL);
wglDeleteContext(rc);
ReleaseDC(test, dc);
DestroyWindow(test);
}
}
if (togl->MultisampleFlag && !hasMultisampling) {
Tcl_SetResult(togl->Interp,
TCL_STUPID "multisampling not supported", TCL_STATIC);
return 0;
}
if (togl->PbufferFlag && !hasPbuffer) {
Tcl_SetResult(togl->Interp,
TCL_STUPID "pbuffers are not supported", TCL_STATIC);
return 0;
}
if (choosePixelFormat == NULL) {
PIXELFORMATDESCRIPTOR pfd;
/* Don't have the great wglChoosePixelFormatARB() function, so do it
* the old way. */
if (togl->MultisampleFlag) {
Tcl_SetResult(togl->Interp,
TCL_STUPID "multisampling not supported", TCL_STATIC);
return 0;
}
memset(&pfd, 0, sizeof pfd);
pfd.nSize = sizeof pfd;
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL
| PFD_SUPPORT_COMPOSITION;
if (togl->DoubleFlag) {
pfd.dwFlags |= PFD_DOUBLEBUFFER;
}
if (togl->Stereo == TOGL_STEREO_NATIVE) {
pfd.dwFlags |= PFD_STEREO;
}
pfd.iPixelType = togl->RgbaFlag ? PFD_TYPE_RGBA : PFD_TYPE_COLORINDEX;
pfd.cColorBits = togl->RgbaRed + togl->RgbaGreen + togl->RgbaBlue;
/* Alpha bitplanes are not supported in the current generic OpenGL
* implementation, but may be supported by specific hardware devices. */
pfd.cAlphaBits = togl->AlphaFlag ? togl->AlphaSize : 0;
pfd.cAccumBits = togl->AccumFlag ? (togl->AccumRed + togl->AccumGreen +
togl->AccumBlue + togl->AccumAlpha) : 0;
pfd.cDepthBits = togl->DepthFlag ? togl->DepthSize : 0;
pfd.cStencilBits = togl->StencilFlag ? togl->StencilSize : 0;
/* Auxiliary buffers are not supported in the current generic OpenGL
* implementation, but may be supported by specific hardware devices. */
pfd.cAuxBuffers = togl->AuxNumber;
pfd.iLayerType = PFD_MAIN_PLANE;
if ((pixelformat = ChoosePixelFormat(togl->tglGLHdc, &pfd)) == 0) {
Tcl_SetResult(togl->Interp,
TCL_STUPID "couldn't choose pixel format", TCL_STATIC);
return 0;
}
/* double check that we got the stereo format we requested */
if (togl->Stereo == TOGL_STEREO_NATIVE) {
DescribePixelFormat(togl->tglGLHdc, pixelformat, sizeof (pfd),
&pfd);
if ((pfd.dwFlags & PFD_STEREO) == 0) {
Tcl_SetResult(togl->Interp,
TCL_STUPID "couldn't choose stereo pixel format",
TCL_STATIC);
return 0;
}
}
return pixelformat;
}
// We have the new wglChoosePixelFormat!!
if (togl->MultisampleFlag && !hasMultisampling) {
Tcl_SetResult(togl->Interp,
TCL_STUPID "multisampling not supported", TCL_STATIC);
return 0;
}
if (togl->PbufferFlag)
attribs[na++] = WGL_DRAW_TO_PBUFFER_ARB;
else
attribs[na++] = WGL_DRAW_TO_WINDOW_ARB;
attribs[na++] = GL_TRUE;
attribs[na++] = WGL_SUPPORT_OPENGL_ARB;
attribs[na++] = GL_TRUE;
attribs[na++] = WGL_PIXEL_TYPE_ARB;
if (!togl->RgbaFlag) {
attribs[na++] = WGL_TYPE_COLORINDEX_ARB;
} else {
attribs[na++] = WGL_TYPE_RGBA_ARB;
attribs[na++] = WGL_RED_BITS_ARB;
attribs[na++] = togl->RgbaRed;
attribs[na++] = WGL_GREEN_BITS_ARB;
attribs[na++] = togl->RgbaGreen;
attribs[na++] = WGL_BLUE_BITS_ARB;
attribs[na++] = togl->RgbaBlue;
if (togl->AlphaFlag) {
attribs[na++] = WGL_ALPHA_BITS_ARB;
attribs[na++] = togl->AlphaSize;
}
}
if (togl->DepthFlag) {
attribs[na++] = WGL_DEPTH_BITS_ARB;
attribs[na++] = togl->DepthSize;
}
if (togl->DoubleFlag) {
attribs[na++] = WGL_DOUBLE_BUFFER_ARB;
attribs[na++] = GL_TRUE;
}
if (togl->StencilFlag) {
attribs[na++] = WGL_STENCIL_BITS_ARB;
attribs[na++] = togl->StencilSize;
}
if (togl->AccumFlag) {
attribs[na++] = WGL_ACCUM_RED_BITS_ARB;
attribs[na++] = togl->AccumRed;
attribs[na++] = WGL_ACCUM_GREEN_BITS_ARB;
attribs[na++] = togl->AccumGreen;
attribs[na++] = WGL_ACCUM_BLUE_BITS_ARB;
attribs[na++] = togl->AccumBlue;
if (togl->AlphaFlag) {
attribs[na++] = WGL_ACCUM_ALPHA_BITS_ARB;
attribs[na++] = togl->AccumAlpha;
}
}
if (togl->Stereo == TOGL_STEREO_NATIVE) {
attribs[na++] = WGL_STEREO_ARB;
attribs[na++] = GL_TRUE;
}
if (togl->MultisampleFlag) {
attribs[na++] = WGL_SAMPLE_BUFFERS_ARB;
attribs[na++] = 1;
attribs[na++] = WGL_SAMPLES_ARB;
attribs[na++] = 2;
}
if (togl->AuxNumber) {
attribs[na++] = WGL_AUX_BUFFERS_ARB;
attribs[na++] = togl->AuxNumber;
}
attribs[na++] = 0; // must be last
if (!choosePixelFormat(togl->tglGLHdc, &attribs[0], NULL, 256, formats,
&numFormats) || numFormats == 0) {
Tcl_SetResult(togl->Interp,
TCL_STUPID "couldn't choose pixel format", TCL_STATIC);
return 0;
}
/*
* Pick best format
*/
info = (FBInfo *) malloc(numFormats * sizeof (FBInfo));
for (i = 0; i != numFormats; ++i) {
info[i].pixelFormat = formats[i];
getPixelFormatAttribiv(togl->tglGLHdc, formats[i], 0,
NUM_FBAttribs, FBAttribs, &info[i].stereo);
/* revise attributes so larger is better */
if (!togl->DepthFlag)
info[i].depth = -info[i].depth;
if (!togl->MultisampleFlag)
info[i].samples = -info[i].samples;
if (togl->Stereo != TOGL_STEREO_NATIVE)
info[i].stereo = -info[i].stereo;
}
qsort(info, numFormats, sizeof info[0], FBInfoCmp);
pixelformat = info[0].pixelFormat;
/* double check that we got the stereo format we requested */
if (togl->Stereo == TOGL_STEREO_NATIVE && !info[0].stereo) {
Tcl_SetResult(togl->Interp,
TCL_STUPID "couldn't choose stereo pixel format", TCL_STATIC);
free(info);
return 0;
}
free(info);
return pixelformat;
}
static int
togl_describePixelFormat(Togl *togl)
{
if (getPixelFormatAttribiv == NULL) {
PIXELFORMATDESCRIPTOR pfd;
DescribePixelFormat(togl->tglGLHdc, (int) togl->PixelFormat,
sizeof (pfd), &pfd);
/* fill in flags normally passed in that affect behavior */
togl->RgbaFlag = pfd.iPixelType == PFD_TYPE_RGBA;
togl->DoubleFlag = (pfd.dwFlags & PFD_DOUBLEBUFFER) != 0;
togl->DepthFlag = (pfd.cDepthBits != 0);
togl->AccumFlag = (pfd.cAccumBits != 0);
togl->AlphaFlag = (pfd.cAlphaBits != 0);
togl->StencilFlag = (pfd.cStencilBits != 0);
if ((pfd.dwFlags & PFD_STEREO) != 0)
togl->Stereo = TOGL_STEREO_NATIVE;
else
togl->Stereo = TOGL_STEREO_NONE;
} else {
static int attribs[] = {
WGL_PIXEL_TYPE_ARB,
WGL_DOUBLE_BUFFER_ARB,
WGL_DEPTH_BITS_ARB,
WGL_ACCUM_RED_BITS_ARB,
WGL_ALPHA_BITS_ARB,
WGL_STENCIL_BITS_ARB,
WGL_STEREO_ARB,
WGL_SAMPLES_ARB
};
#define NUM_ATTRIBS (sizeof attribs / sizeof attribs[0])
int info[NUM_ATTRIBS];
getPixelFormatAttribiv(togl->tglGLHdc, (int) togl->PixelFormat, 0,
NUM_ATTRIBS, attribs, info);
#undef NUM_ATTRIBS
togl->RgbaFlag = info[0];
togl->DoubleFlag = info[1];
togl->DepthFlag = (info[2] != 0);
togl->AccumFlag = (info[3] != 0);
togl->AlphaFlag = (info[4] != 0);
togl->StencilFlag = (info[5] != 0);
togl->Stereo = info[6] ? TOGL_STEREO_NATIVE : TOGL_STEREO_NONE;
togl->MultisampleFlag = (info[7] != 0);
}
return True;
}
static HPBUFFERARB
togl_createPbuffer(Togl *togl)
{
int attribs[32];
int na = 0;
HPBUFFERARB pbuf;
if (togl->LargestPbufferFlag) {
attribs[na++] = WGL_PBUFFER_LARGEST_ARB;
attribs[na++] = 1;
}
attribs[na] = 0;
pbuf = createPbuffer(togl->tglGLHdc, (int) togl->PixelFormat, togl->Width,
togl->Height, attribs);
if (pbuf && togl->LargestPbufferFlag) {
queryPbuffer(pbuf, WGL_PBUFFER_WIDTH_ARB, &togl->Width);
queryPbuffer(pbuf, WGL_PBUFFER_HEIGHT_ARB, &togl->Height);
}
return pbuf;
}
static void
togl_destroyPbuffer(Togl *togl)
{
destroyPbuffer(togl->pbuf);
}
#if 0
// From nvidia.com
Multisampling requires WGL_ARB_extension_string and WGL_ARB_pixel_format
wglGetProcAddress("wglGetExtensionsStringARB")
// From msdn.microsoft.com, various ways to enumerate PixelFormats
void CPixForm::OnClickedLastPfd()
{
COpenGL gl;
PIXELFORMATDESCRIPTOR pfd;
//
// Get the hwnd of the view window.
//
HWND hwndview = GetViewHwnd();
//
// Get a DC associated with the view window.
//
HDC dc =::GetDC(hwndview);
int nID = (m_nNextID > 1) ? m_nNextID-- : 1;
//
// Get a description of the pixel format. If it is valid, then go and
// update the controls in the dialog box, otherwise do nothing.
//
if (gl.DescribePixelFormat(dc, nID, sizeof (PIXELFORMATDESCRIPTOR), &pfd))
UpdateDlg(&pfd);
//
// Release the DC.
//
::ReleaseDC(hwndview, dc);
}
----------------------
// local variables
int iMax;
PIXELFORMATDESCRIPTOR pfd;
int iPixelFormat;
// initialize a pixel format index variable
iPixelFormat = 1;
// keep obtaining and examining pixel format data...
do {
// try to obtain some pixel format data
iMax = DescribePixelFormat(dc, iPixelFormat, sizeof (pfd), &pfd);
// if there was some problem with that...
if (iMax == 0)
// return indicating failure
return (FALSE);
// we have successfully obtained pixel format data
// let's examine the pixel format data...
myPixelFormatExaminer(&pfd);
}
// ...until we've looked at all the device context's pixel formats
while (++iPixelFormat <= iMax);
#endif
|