+ if ( !attribList )
+ {
+ ADD_ATTR( WGL_COLOR_BITS_ARB, 24 );
+ ADD_ATTR( WGL_ALPHA_BITS_ARB, 8 );
+ ADD_ATTR( WGL_DEPTH_BITS_ARB, 16 );
+ ADD_ATTR( WGL_STENCIL_BITS_ARB, 0 );
+ ADD_ATTR( WGL_DOUBLE_BUFFER_ARB, GL_TRUE );
+ ADD_ATTR( WGL_SAMPLE_BUFFERS_ARB, GL_TRUE );
+ ADD_ATTR( WGL_SAMPLES_ARB, 4 );
+ }
+ else // have custom attributes
+ {
+ #define ADD_ATTR_VALUE(attr) ADD_ATTR(attr, attribList[src++])
+
+ int src = 0;
+ while ( attribList[src] )
+ {
+ switch ( attribList[src++] )
+ {
+ case WX_GL_RGBA:
+ ADD_ATTR( WGL_COLOR_BITS_ARB, 24 );
+ ADD_ATTR( WGL_ALPHA_BITS_ARB, 8 );
+ break;
+
+ case WX_GL_BUFFER_SIZE:
+ ADD_ATTR_VALUE( WGL_COLOR_BITS_ARB);
+ break;
+
+ case WX_GL_LEVEL:
+ if ( attribList[src] > 0 )
+ {
+ ADD_ATTR( WGL_NUMBER_OVERLAYS_ARB, 1 );
+ }
+ else if ( attribList[src] <0 )
+ {
+ ADD_ATTR( WGL_NUMBER_UNDERLAYS_ARB, 1 );
+ }
+ //else: ignore it
+
+ src++; // skip the value in any case
+ break;
+
+ case WX_GL_DOUBLEBUFFER:
+ ADD_ATTR( WGL_DOUBLE_BUFFER_ARB, GL_TRUE );
+ break;
+
+ case WX_GL_STEREO:
+ ADD_ATTR( WGL_STEREO_ARB, GL_TRUE );
+ break;
+
+ case WX_GL_AUX_BUFFERS:
+ ADD_ATTR_VALUE( WGL_AUX_BUFFERS_ARB );
+ break;
+
+ case WX_GL_MIN_RED:
+ ADD_ATTR_VALUE( WGL_RED_BITS_ARB );
+ break;
+
+ case WX_GL_MIN_GREEN:
+ ADD_ATTR_VALUE( WGL_GREEN_BITS_ARB );
+ break;
+
+ case WX_GL_MIN_BLUE:
+ ADD_ATTR_VALUE( WGL_BLUE_BITS_ARB );
+ break;
+
+ case WX_GL_MIN_ALPHA:
+ ADD_ATTR_VALUE( WGL_ALPHA_BITS_ARB );
+ break;
+
+ case WX_GL_DEPTH_SIZE:
+ ADD_ATTR_VALUE( WGL_DEPTH_BITS_ARB );
+ break;
+
+ case WX_GL_STENCIL_SIZE:
+ ADD_ATTR_VALUE( WGL_STENCIL_BITS_ARB );
+ break;
+
+ case WX_GL_MIN_ACCUM_RED:
+ ADD_ATTR_VALUE( WGL_ACCUM_RED_BITS_ARB );
+ break;
+
+ case WX_GL_MIN_ACCUM_GREEN:
+ ADD_ATTR_VALUE( WGL_ACCUM_GREEN_BITS_ARB );
+ break;
+
+ case WX_GL_MIN_ACCUM_BLUE:
+ ADD_ATTR_VALUE( WGL_ACCUM_BLUE_BITS_ARB );
+ break;
+
+ case WX_GL_MIN_ACCUM_ALPHA:
+ ADD_ATTR_VALUE( WGL_ACCUM_ALPHA_BITS_ARB );
+ break;
+
+ case WX_GL_SAMPLE_BUFFERS:
+ ADD_ATTR_VALUE( WGL_SAMPLE_BUFFERS_ARB );
+ break;
+
+ case WX_GL_SAMPLES:
+ ADD_ATTR_VALUE( WGL_SAMPLES_ARB );
+ break;
+ }
+ }
+
+ #undef ADD_ATTR_VALUE
+ }
+
+ #undef ADD_ATTR
+
+ iAttributes[dst++] = 0;
+
+ int pf;
+ UINT numFormats = 0;
+
+ if ( !wglChoosePixelFormatARB(hdc, iAttributes, NULL, 1, &pf, &numFormats) )
+ {
+ wxLogLastError(wxT("wglChoosePixelFormatARB"));
+ return 0;
+ }
+
+ // Although TRUE is returned if no matching formats are found (see
+ // http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt), pf is
+ // not initialized in this case so we need to check for numFormats being
+ // not 0 explicitly (however this is not an error so don't call
+ // wxLogLastError() here).
+ if ( !numFormats )
+ pf = 0;
+
+ return pf;