+ if( fgState.DisplayMode & GLUT_AUX4 )
+ pfd.cAuxBuffers = 4;
+ else if( fgState.DisplayMode & GLUT_AUX3 )
+ pfd.cAuxBuffers = 3;
+ else if( fgState.DisplayMode & GLUT_AUX2 )
+ pfd.cAuxBuffers = 2;
+ else if( fgState.DisplayMode & GLUT_AUX1 )
+ pfd.cAuxBuffers = 1;
+ else
+ pfd.cAuxBuffers = 0;
+
+ pfd.iLayerType = layer_type;
+ pfd.bReserved = 0;
+ pfd.dwLayerMask = 0;
+ pfd.dwVisibleMask = 0;
+ pfd.dwDamageMask = 0;
+
+ pfd.cColorBits = (BYTE) GetDeviceCaps( window->Window.Device, BITSPIXEL );
+ ppfd = &pfd;
+
+ pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
+
+ /* windows hack for multismapling */
+ if (fgState.DisplayMode&GLUT_MULTISAMPLE)
+ {
+ PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetEntensionsStringARB=NULL;
+ 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);
+
+ wglGetEntensionsStringARB=(PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
+ if (wglGetEntensionsStringARB)
+ {
+ const char * pWglExtString=wglGetEntensionsStringARB(hDC);
+ if (pWglExtString)
+ {
+ if (strstr(pWglExtString, "WGL_ARB_multisample"))
+ {
+ int pAttributes[100];
+ int iCounter=0;
+ int iPixelFormat;
+ BOOL bValid;
+ float fAttributes[] = {0,0};
+ UINT numFormats;
+ PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARBProc=NULL;
+
+ wglChoosePixelFormatARBProc=(PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
+ if ( wglChoosePixelFormatARBProc )
+ {
+ pAttributes[iCounter++]=WGL_DRAW_TO_WINDOW_ARB; pAttributes[iCounter++]=GL_TRUE;
+ pAttributes[iCounter++]=WGL_SUPPORT_OPENGL_ARB; pAttributes[iCounter++]=GL_TRUE;
+ pAttributes[iCounter++]=WGL_ACCELERATION_ARB; pAttributes[iCounter++]=WGL_FULL_ACCELERATION_ARB;
+
+ pAttributes[iCounter++]=WGL_COLOR_BITS_ARB; pAttributes[iCounter++]=pfd.cColorBits ;
+ pAttributes[iCounter++]=WGL_ALPHA_BITS_ARB; pAttributes[iCounter++]=pfd.cAlphaBits;
+ pAttributes[iCounter++]=WGL_DEPTH_BITS_ARB; pAttributes[iCounter++]=pfd.cDepthBits;
+ pAttributes[iCounter++]=WGL_STENCIL_BITS_ARB; pAttributes[iCounter++]=pfd.cStencilBits;
+
+ pAttributes[iCounter++]=WGL_DOUBLE_BUFFER_ARB; pAttributes[iCounter++]=(fgState.DisplayMode & GLUT_DOUBLE)!=0;
+ pAttributes[iCounter++]=WGL_SAMPLE_BUFFERS_ARB; pAttributes[iCounter++]=GL_TRUE;
+ pAttributes[iCounter++]=WGL_SAMPLES_ARB; pAttributes[iCounter++]=4;
+ pAttributes[iCounter++]=0; pAttributes[iCounter++]=0; /* terminator */
+
+ bValid = wglChoosePixelFormatARBProc(window->Window.Device,pAttributes,fAttributes,1,&iPixelFormat,&numFormats);
+
+ if (bValid && numFormats>0)
+ pixelformat=iPixelFormat;
+ }
+ }
+ wglMakeCurrent( hDC_before, rc_before);
+ wglDeleteContext(rc);
+ ReleaseDC(hWnd, hDC);
+ DestroyWindow(hWnd);
+ UnregisterClass(_T("FREEGLUT_dummy"), fgDisplay.Instance);
+ }
+ }
+ }
+
+ if( pixelformat == 0 )
+ return GL_FALSE;
+
+ if( checkOnly )
+ return GL_TRUE;
+ return SetPixelFormat( window->Window.Device, pixelformat, ppfd );
+#endif /* defined(_WIN32_WCE) */