+ /* new context creation */
+ int attributes[9];
+ CreateContextAttribsProc createContextAttribs;
+
+ /* If nothing fancy has been required, simply use the old context creation GLX API entry */
+ if ( fghIsLegacyContextRequested() )
+ {
+ context = glXCreateNewContext( dpy, config, render_type, share_list, direct );
+ if ( context == NULL ) {
+ fghContextCreationError();
+ }
+ return context;
+ }
+
+ /* color index mode is not available anymore with OpenGL 3.0 */
+ if ( render_type == GLX_COLOR_INDEX_TYPE ) {
+ fgWarning( "color index mode is deprecated, using RGBA mode" );
+ }
+
+ fghFillContextAttributes( attributes );
+
+ createContextAttribs = (CreateContextAttribsProc) fghGetProcAddress( "glXCreateContextAttribsARB" );
+ if ( createContextAttribs == NULL ) {
+ fgError( "glXCreateContextAttribsARB not found" );
+ }
+
+ context = createContextAttribs( dpy, config, share_list, direct, attributes );
+ if ( context == NULL ) {
+ fghContextCreationError();
+ }
+ return context;
+}
+
+
+#define _NET_WM_STATE_TOGGLE 2
+static int fghResizeFullscrToggle(void)
+{
+ XWindowAttributes attributes;
+
+ if(glutGet(GLUT_FULL_SCREEN)) {
+ /* restore original window size */
+ SFG_Window *win = fgStructure.CurrentWindow;
+ fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
+ fgStructure.CurrentWindow->State.Width = win->State.OldWidth;
+ fgStructure.CurrentWindow->State.Height = win->State.OldHeight;
+
+ } else {
+ /* resize the window to cover the entire screen */
+ XGetWindowAttributes(fgDisplay.Display,
+ fgStructure.CurrentWindow->Window.Handle,
+ &attributes);
+
+ /*
+ * The "x" and "y" members of "attributes" are the window's coordinates
+ * relative to its parent, i.e. to the decoration window.
+ */
+ XMoveResizeWindow(fgDisplay.Display,
+ fgStructure.CurrentWindow->Window.Handle,
+ -attributes.x,
+ -attributes.y,
+ fgDisplay.ScreenWidth,
+ fgDisplay.ScreenHeight);
+ }
+ return 0;
+}
+
+static int fghEwmhFullscrToggle(void)
+{
+ XEvent xev;
+ long evmask = SubstructureRedirectMask | SubstructureNotifyMask;
+
+ if(!fgDisplay.State || !fgDisplay.StateFullScreen) {
+ return -1;
+ }
+
+ xev.type = ClientMessage;
+ xev.xclient.window = fgStructure.CurrentWindow->Window.Handle;
+ xev.xclient.message_type = fgDisplay.State;
+ xev.xclient.format = 32;
+ xev.xclient.data.l[0] = _NET_WM_STATE_TOGGLE;
+ xev.xclient.data.l[1] = fgDisplay.StateFullScreen;
+ xev.xclient.data.l[2] = 0; /* no second property to toggle */
+ xev.xclient.data.l[3] = 1; /* source indication: application */
+ xev.xclient.data.l[4] = 0; /* unused */
+
+ if(!XSendEvent(fgDisplay.Display, fgDisplay.RootWindow, 0, evmask, &xev)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int fghToggleFullscreen(void)
+{
+ /* first try the EWMH (_NET_WM_STATE) method ... */
+ if(fghEwmhFullscrToggle() != -1) {
+ return 0;
+ }
+
+ /* fall back to resizing the window */
+ if(fghResizeFullscrToggle() != -1) {
+ return 0;
+ }
+ return -1;
+}
+
+
+#endif /* TARGET_HOST_POSIX_X11 */
+
+
+#if TARGET_HOST_MS_WINDOWS
+/*
+ * Setup the pixel format for a Win32 window
+ */
+
+#if defined(_WIN32_WCE)
+static wchar_t* fghWstrFromStr(const char* str)
+{
+ int i,len=strlen(str);
+ wchar_t* wstr = (wchar_t*)malloc(2*len+2);
+ for(i=0; i<len; i++)
+ wstr[i] = str[i];
+ wstr[len] = 0;
+ return wstr;
+}
+#endif /* defined(_WIN32_WCE) */