+#if defined(_MSC_VER)
+#pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
+#endif
+
+ /* Specify which pixel format do we opt for... */
+ ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
+ ppfd->nVersion = 1;
+ ppfd->dwFlags = flags;
+
+ if( fgState.DisplayMode & GLUT_INDEX ) {
+ ppfd->iPixelType = PFD_TYPE_COLORINDEX;
+ ppfd->cRedBits = 0;
+ ppfd->cGreenBits = 0;
+ ppfd->cBlueBits = 0;
+ ppfd->cAlphaBits = 0;
+ } else {
+ ppfd->iPixelType = PFD_TYPE_RGBA;
+ ppfd->cRedBits = 8;
+ ppfd->cGreenBits = 8;
+ ppfd->cBlueBits = 8;
+ ppfd->cAlphaBits = ( fgState.DisplayMode & GLUT_ALPHA ) ? 8 : 0;
+ }
+
+ ppfd->cColorBits = 24;
+ ppfd->cRedShift = 0;
+ ppfd->cGreenShift = 0;
+ ppfd->cBlueShift = 0;
+ ppfd->cAlphaShift = 0;
+ ppfd->cAccumBits = ( fgState.DisplayMode & GLUT_ACCUM ) ? 1 : 0;
+ ppfd->cAccumRedBits = 0;
+ ppfd->cAccumGreenBits = 0;
+ ppfd->cAccumBlueBits = 0;
+ ppfd->cAccumAlphaBits = 0;
+
+ /* Hmmm, or 32/0 instead of 24/8? */
+ ppfd->cDepthBits = 24;
+ ppfd->cStencilBits = 8;
+
+ ppfd->cAuxBuffers = fghNumberOfAuxBuffersRequested();
+ ppfd->iLayerType = layer_type;
+ ppfd->bReserved = 0;
+ ppfd->dwLayerMask = 0;
+ ppfd->dwVisibleMask = 0;
+ ppfd->dwDamageMask = 0;
+
+ ppfd->cColorBits = (BYTE) GetDeviceCaps( hdc, BITSPIXEL );
+}
+
+static void fghFillPixelFormatAttributes( int *attributes, const PIXELFORMATDESCRIPTOR *ppfd )
+{
+ int where = 0;
+
+ ATTRIB_VAL( WGL_DRAW_TO_WINDOW_ARB, GL_TRUE );
+ ATTRIB_VAL( WGL_SUPPORT_OPENGL_ARB, GL_TRUE );
+ ATTRIB_VAL( WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB );
+
+ ATTRIB_VAL( WGL_COLOR_BITS_ARB, ppfd->cColorBits );
+ ATTRIB_VAL( WGL_ALPHA_BITS_ARB, ppfd->cAlphaBits );
+ ATTRIB_VAL( WGL_DEPTH_BITS_ARB, ppfd->cDepthBits );
+ ATTRIB_VAL( WGL_STENCIL_BITS_ARB, ppfd->cStencilBits );
+
+ ATTRIB_VAL( WGL_DOUBLE_BUFFER_ARB, ( fgState.DisplayMode & GLUT_DOUBLE ) != 0 );
+
+ if ( fgState.DisplayMode & GLUT_SRGB ) {
+ ATTRIB_VAL( WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, TRUE );
+ }
+
+ ATTRIB_VAL( WGL_SAMPLE_BUFFERS_ARB, GL_TRUE );
+ ATTRIB_VAL( WGL_SAMPLES_ARB, fgState.SampleNumber );
+ ATTRIB( 0 );
+}
+#endif
+
+GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
+ unsigned char layer_type )
+{
+#if defined(_WIN32_WCE)
+ return GL_TRUE;
+#else
+ PIXELFORMATDESCRIPTOR pfd;
+ PIXELFORMATDESCRIPTOR* ppfd = &pfd;
+ int pixelformat;
+ HDC current_hDC;
+ GLboolean success;
+
+ if (checkOnly)
+ current_hDC = CreateDC(TEXT("DISPLAY"), NULL ,NULL ,NULL);
+ else
+ current_hDC = window->Window.Device;
+
+ fghFillPFD( ppfd, current_hDC, layer_type );
+ pixelformat = ChoosePixelFormat( current_hDC, ppfd );
+
+ /* windows hack for multismapling/sRGB */
+ if ( ( fgState.DisplayMode & GLUT_MULTISAMPLE ) ||
+ ( fgState.DisplayMode & GLUT_SRGB ) )
+ {
+ HGLRC rc, rc_before=wglGetCurrentContext();
+ HWND hWnd;
+ HDC hDC, hDC_before=wglGetCurrentDC();
+ WNDCLASS wndCls;
+
+ /* create a dummy window */
+ ZeroMemory(&wndCls, sizeof(wndCls));
+ wndCls.lpfnWndProc = DefWindowProc;
+ wndCls.hInstance = fgDisplay.Instance;
+ wndCls.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
+ wndCls.lpszClassName = _T("FREEGLUT_dummy");
+ RegisterClass( &wndCls );
+
+ hWnd=CreateWindow(_T("FREEGLUT_dummy"), _T(""), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW , 0,0,0,0, 0, 0, fgDisplay.Instance, 0 );
+ hDC=GetDC(hWnd);
+ SetPixelFormat( hDC, pixelformat, ppfd );
+
+ rc = wglCreateContext( hDC );
+ wglMakeCurrent(hDC, rc);
+
+ if ( fghIsExtensionSupported( hDC, "WGL_ARB_multisample" ) )
+ {
+ PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARBProc =
+ (PFNWGLCHOOSEPIXELFORMATARBPROC) wglGetProcAddress("wglChoosePixelFormatARB");
+ if ( wglChoosePixelFormatARBProc )
+ {
+ int attributes[100];
+ int iPixelFormat;
+ BOOL bValid;
+ float fAttributes[] = { 0, 0 };
+ UINT numFormats;
+ fghFillPixelFormatAttributes( attributes, ppfd );
+ bValid = wglChoosePixelFormatARBProc(hDC, attributes, fAttributes, 1, &iPixelFormat, &numFormats);
+
+ if ( bValid && numFormats > 0 )
+ {
+ pixelformat = iPixelFormat;
+ }
+ }