-\r
-#endif /* TARGET_HOST_POSIX_X11 */\r
-\r
-\r
-#if TARGET_HOST_MS_WINDOWS\r
-/*\r
- * Setup the pixel format for a Win32 window\r
- */\r
-\r
-#if defined(_WIN32_WCE)\r
-static wchar_t* fghWstrFromStr(const char* str)\r
-{\r
- int i,len=strlen(str);\r
- wchar_t* wstr = (wchar_t*)malloc(2*len+2);\r
- for(i=0; i<len; i++)\r
- wstr[i] = str[i];\r
- wstr[len] = 0;\r
- return wstr;\r
-}\r
-#endif /* defined(_WIN32_WCE) */\r
-\r
-\r
-static void fghFillContextAttributes( int *attributes ) {\r
- int where = 0, contextFlags, contextProfile;\r
-\r
- if ( !fghIsLegacyContextVersionRequested() ) {\r
- ATTRIB_VAL( WGL_CONTEXT_MAJOR_VERSION_ARB, fgState.MajorVersion );\r
- ATTRIB_VAL( WGL_CONTEXT_MINOR_VERSION_ARB, fgState.MinorVersion );\r
- }\r
-\r
- contextFlags =\r
- fghMapBit( fgState.ContextFlags, GLUT_DEBUG, WGL_CONTEXT_DEBUG_BIT_ARB ) |\r
- fghMapBit( fgState.ContextFlags, GLUT_FORWARD_COMPATIBLE, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB );\r
- if ( contextFlags != 0 ) {\r
- ATTRIB_VAL( WGL_CONTEXT_FLAGS_ARB, contextFlags );\r
- }\r
-\r
- contextProfile =\r
- fghMapBit( fgState.ContextProfile, GLUT_CORE_PROFILE, WGL_CONTEXT_CORE_PROFILE_BIT_ARB ) |\r
- fghMapBit( fgState.ContextProfile, GLUT_COMPATIBILITY_PROFILE, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB );\r
- if ( contextProfile != 0 ) {\r
- ATTRIB_VAL( WGL_CONTEXT_PROFILE_MASK_ARB, contextProfile );\r
- }\r
-\r
- ATTRIB( 0 );\r
-}\r
-\r
-static int fghIsExtensionSupported( HDC hdc, const char *extension ) {\r
- const char *pWglExtString;\r
- PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetEntensionsStringARB =\r
- (PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB");\r
- if ( wglGetEntensionsStringARB == NULL )\r
- {\r
- return FALSE;\r
- }\r
- pWglExtString = wglGetEntensionsStringARB( hdc );\r
- return ( pWglExtString != NULL ) && ( strstr(pWglExtString, extension) != NULL );\r
-}\r
-\r
-void fgNewWGLCreateContext( SFG_Window* window )\r
-{\r
- HGLRC context;\r
- int attributes[9];\r
- PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;\r
-\r
- /* If nothing fancy has been required, leave the context as it is */\r
- if ( fghIsLegacyContextRequested() )\r
- {\r
- return;\r
- }\r
-\r
- wglMakeCurrent( window->Window.Device, window->Window.Context );\r
-\r
- if ( !fghIsExtensionSupported( window->Window.Device, "WGL_ARB_create_context" ) )\r
- {\r
- return;\r
- }\r
-\r
- /* new context creation */\r
- fghFillContextAttributes( attributes );\r
-\r
- wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress( "wglCreateContextAttribsARB" );\r
- if ( wglCreateContextAttribsARB == NULL )\r
- {\r
- fgError( "wglCreateContextAttribsARB not found" );\r
- }\r
-\r
- context = wglCreateContextAttribsARB( window->Window.Device, 0, attributes );\r
- if ( context == NULL )\r
- {\r
- fghContextCreationError();\r
- }\r
-\r
- wglMakeCurrent( NULL, NULL );\r
- wglDeleteContext( window->Window.Context );\r
- window->Window.Context = context;\r
-}\r
-\r
-#if !defined(_WIN32_WCE)\r
-\r
-static void fghFillPFD( PIXELFORMATDESCRIPTOR *ppfd, HDC hdc, unsigned char layer_type )\r
-{\r
- int flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;\r
- if ( fgState.DisplayMode & GLUT_DOUBLE ) {\r
- flags |= PFD_DOUBLEBUFFER;\r
- }\r
- if ( fgState.DisplayMode & GLUT_STEREO ) {\r
- flags |= PFD_STEREO;\r
- }\r
-\r
-#if defined(_MSC_VER)\r
-#pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )\r
-#endif\r
-\r
- /* Specify which pixel format do we opt for... */\r
- ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);\r
- ppfd->nVersion = 1;\r
- ppfd->dwFlags = flags;\r
-\r
- if( fgState.DisplayMode & GLUT_INDEX ) {\r
- ppfd->iPixelType = PFD_TYPE_COLORINDEX;\r
- ppfd->cRedBits = 0;\r
- ppfd->cGreenBits = 0;\r
- ppfd->cBlueBits = 0;\r
- ppfd->cAlphaBits = 0;\r
- } else {\r
- ppfd->iPixelType = PFD_TYPE_RGBA;\r
- ppfd->cRedBits = 8;\r
- ppfd->cGreenBits = 8;\r
- ppfd->cBlueBits = 8;\r
- ppfd->cAlphaBits = ( fgState.DisplayMode & GLUT_ALPHA ) ? 8 : 0;\r
- }\r
-\r
- ppfd->cColorBits = 24;\r
- ppfd->cRedShift = 0;\r
- ppfd->cGreenShift = 0;\r
- ppfd->cBlueShift = 0;\r
- ppfd->cAlphaShift = 0;\r
- ppfd->cAccumBits = ( fgState.DisplayMode & GLUT_ACCUM ) ? 1 : 0;\r
- ppfd->cAccumRedBits = 0;\r
- ppfd->cAccumGreenBits = 0;\r
- ppfd->cAccumBlueBits = 0;\r
- ppfd->cAccumAlphaBits = 0;\r
-\r
- /* Hmmm, or 32/0 instead of 24/8? */\r
- ppfd->cDepthBits = 24;\r
- ppfd->cStencilBits = 8;\r
-\r
- ppfd->cAuxBuffers = fghNumberOfAuxBuffersRequested();\r
- ppfd->iLayerType = layer_type;\r
- ppfd->bReserved = 0;\r
- ppfd->dwLayerMask = 0;\r
- ppfd->dwVisibleMask = 0;\r
- ppfd->dwDamageMask = 0;\r
- \r
- ppfd->cColorBits = (BYTE) GetDeviceCaps( hdc, BITSPIXEL );\r
-}\r
-\r
-static void fghFillPixelFormatAttributes( int *attributes, const PIXELFORMATDESCRIPTOR *ppfd )\r
-{\r
- int where = 0;\r
-\r
- ATTRIB_VAL( WGL_DRAW_TO_WINDOW_ARB, GL_TRUE );\r
- ATTRIB_VAL( WGL_SUPPORT_OPENGL_ARB, GL_TRUE );\r
- ATTRIB_VAL( WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB );\r
-\r
- ATTRIB_VAL( WGL_COLOR_BITS_ARB, ppfd->cColorBits );\r
- ATTRIB_VAL( WGL_ALPHA_BITS_ARB, ppfd->cAlphaBits );\r
- ATTRIB_VAL( WGL_DEPTH_BITS_ARB, ppfd->cDepthBits );\r
- ATTRIB_VAL( WGL_STENCIL_BITS_ARB, ppfd->cStencilBits );\r
-\r
- ATTRIB_VAL( WGL_DOUBLE_BUFFER_ARB, ( fgState.DisplayMode & GLUT_DOUBLE ) != 0 );\r
-\r
- if ( fgState.DisplayMode & GLUT_SRGB ) {\r
- ATTRIB_VAL( WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, TRUE );\r
- }\r
-\r
- ATTRIB_VAL( WGL_SAMPLE_BUFFERS_ARB, GL_TRUE );\r
- ATTRIB_VAL( WGL_SAMPLES_ARB, fgState.SampleNumber );\r
- ATTRIB( 0 );\r
-}\r
-#endif\r
-\r
-GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,\r
- unsigned char layer_type )\r
-{\r
-#if defined(_WIN32_WCE)\r
- return GL_TRUE;\r
-#else\r
- PIXELFORMATDESCRIPTOR pfd;\r
- PIXELFORMATDESCRIPTOR* ppfd = &pfd;\r
- int pixelformat;\r
- HDC current_hDC;\r
- GLboolean success;\r
-\r
- if (checkOnly)\r
- current_hDC = CreateDC(TEXT("DISPLAY"), NULL ,NULL ,NULL);\r
- else\r
- current_hDC = window->Window.Device;\r
-\r
- fghFillPFD( ppfd, current_hDC, layer_type );\r
- pixelformat = ChoosePixelFormat( current_hDC, ppfd );\r
-\r
- /* windows hack for multismapling/sRGB */\r
- if ( ( fgState.DisplayMode & GLUT_MULTISAMPLE ) ||\r
- ( fgState.DisplayMode & GLUT_SRGB ) )\r
- { \r
- HGLRC rc, rc_before=wglGetCurrentContext();\r
- HWND hWnd;\r
- HDC hDC, hDC_before=wglGetCurrentDC();\r
- WNDCLASS wndCls;\r
-\r
- /* create a dummy window */\r
- ZeroMemory(&wndCls, sizeof(wndCls));\r
- wndCls.lpfnWndProc = DefWindowProc;\r
- wndCls.hInstance = fgDisplay.Instance;\r
- wndCls.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;\r
- wndCls.lpszClassName = _T("FREEGLUT_dummy");\r
- RegisterClass( &wndCls );\r
-\r
- hWnd=CreateWindow(_T("FREEGLUT_dummy"), _T(""), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW , 0,0,0,0, 0, 0, fgDisplay.Instance, 0 );\r
- hDC=GetDC(hWnd);\r
- SetPixelFormat( hDC, pixelformat, ppfd );\r
-\r
- rc = wglCreateContext( hDC );\r
- wglMakeCurrent(hDC, rc);\r
-\r
- if ( fghIsExtensionSupported( hDC, "WGL_ARB_multisample" ) )\r
- {\r
- PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARBProc =\r
- (PFNWGLCHOOSEPIXELFORMATARBPROC) wglGetProcAddress("wglChoosePixelFormatARB");\r
- if ( wglChoosePixelFormatARBProc )\r
- {\r
- int attributes[100];\r
- int iPixelFormat;\r
- BOOL bValid;\r
- float fAttributes[] = { 0, 0 };\r
- UINT numFormats;\r
- fghFillPixelFormatAttributes( attributes, ppfd );\r
- bValid = wglChoosePixelFormatARBProc(hDC, attributes, fAttributes, 1, &iPixelFormat, &numFormats);\r
-\r
- if ( bValid && numFormats > 0 )\r
- {\r
- pixelformat = iPixelFormat;\r
- }\r
- }\r
- }\r
-\r
- wglMakeCurrent( hDC_before, rc_before);\r
- wglDeleteContext(rc);\r
- ReleaseDC(hWnd, hDC);\r
- DestroyWindow(hWnd);\r
- UnregisterClass(_T("FREEGLUT_dummy"), fgDisplay.Instance);\r
- }\r
-\r
- success = ( pixelformat != 0 ) && ( checkOnly || SetPixelFormat( current_hDC, pixelformat, ppfd ) );\r
-\r
- if (checkOnly)\r
- DeleteDC(current_hDC);\r
-\r
- return success;\r
-#endif /* defined(_WIN32_WCE) */\r
-}\r
-\r
-#endif /* TARGET_HOST_MS_WINDOWS */\r
-\r
-/*\r
- * Sets the OpenGL context and the fgStructure "Current Window" pointer to\r
- * the window structure passed in.\r
- */\r
-void fgSetWindow ( SFG_Window *window )\r