4 * Window management methods.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Fri Dec 3 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include <GL/freeglut.h>
29 #include "freeglut_internal.h"
31 #if TARGET_HOST_POSIX_X11
32 #include <limits.h> /* LONG_MAX */
35 #if defined(_WIN32_WCE)
36 # include <Aygshell.h>
37 # ifdef FREEGLUT_LIB_PRAGMAS
38 # pragma comment( lib, "Aygshell.lib" )
41 static wchar_t* fghWstrFromStr(const char* str)
43 int i,len=strlen(str);
44 wchar_t* wstr = (wchar_t*)malloc(2*len+2);
51 #endif /* defined(_WIN32_WCE) */
54 * TODO BEFORE THE STABLE RELEASE:
56 * fgChooseFBConfig() -- OK, but what about glutInitDisplayString()?
57 * fgSetupPixelFormat -- ignores the display mode settings
58 * fgOpenWindow() -- check the Win32 version, -iconic handling!
59 * fgCloseWindow() -- check the Win32 version
60 * glutCreateWindow() -- Check when default position and size is {-1,-1}
61 * glutCreateSubWindow() -- Check when default position and size is {-1,-1}
62 * glutDestroyWindow() -- check the Win32 version
63 * glutSetWindow() -- check the Win32 version
64 * glutGetWindow() -- OK
65 * glutSetWindowTitle() -- check the Win32 version
66 * glutSetIconTitle() -- check the Win32 version
67 * glutShowWindow() -- check the Win32 version
68 * glutHideWindow() -- check the Win32 version
69 * glutIconifyWindow() -- check the Win32 version
70 * glutReshapeWindow() -- check the Win32 version
71 * glutPositionWindow() -- check the Win32 version
72 * glutPushWindow() -- check the Win32 version
73 * glutPopWindow() -- check the Win32 version
76 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
79 * Chooses a visual basing on the current display mode settings
81 #if TARGET_HOST_POSIX_X11
83 GLXFBConfig* fgChooseFBConfig( void )
85 GLboolean wantIndexedMode = GL_FALSE;
89 /* First we have to process the display mode settings... */
91 * XXX Why is there a semi-colon in this #define? The code
92 * XXX that uses the macro seems to always add more semicolons...
94 #define ATTRIB(a) attributes[where++]=a;
95 #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);}
97 if( fgState.DisplayMode & GLUT_INDEX )
99 ATTRIB_VAL( GLX_BUFFER_SIZE, 8 );
100 /* Buffer size is selected later. */
102 ATTRIB_VAL( GLX_RENDER_TYPE, GLX_COLOR_INDEX_BIT );
103 wantIndexedMode = GL_TRUE;
107 ATTRIB_VAL( GLX_RED_SIZE, 1 );
108 ATTRIB_VAL( GLX_GREEN_SIZE, 1 );
109 ATTRIB_VAL( GLX_BLUE_SIZE, 1 );
110 if( fgState.DisplayMode & GLUT_ALPHA )
111 ATTRIB_VAL( GLX_ALPHA_SIZE, 1 );
114 if( fgState.DisplayMode & GLUT_DOUBLE )
115 ATTRIB_VAL( GLX_DOUBLEBUFFER, True );
117 if( fgState.DisplayMode & GLUT_STEREO )
118 ATTRIB_VAL( GLX_STEREO, True );
120 if( fgState.DisplayMode & GLUT_DEPTH )
121 ATTRIB_VAL( GLX_DEPTH_SIZE, 1 );
123 if( fgState.DisplayMode & GLUT_STENCIL )
124 ATTRIB_VAL( GLX_STENCIL_SIZE, 1 );
126 if( fgState.DisplayMode & GLUT_ACCUM )
128 ATTRIB_VAL( GLX_ACCUM_RED_SIZE, 1 );
129 ATTRIB_VAL( GLX_ACCUM_GREEN_SIZE, 1 );
130 ATTRIB_VAL( GLX_ACCUM_BLUE_SIZE, 1 );
131 if( fgState.DisplayMode & GLUT_ALPHA )
132 ATTRIB_VAL( GLX_ACCUM_ALPHA_SIZE, 1 );
135 if ((fgState.DisplayMode & GLUT_AUX)
136 || (fgState.DisplayMode & GLUT_AUX1)
137 || (fgState.DisplayMode & GLUT_AUX2)
138 || (fgState.DisplayMode & GLUT_AUX3)
139 || (fgState.DisplayMode & GLUT_AUX4))
141 ATTRIB_VAL(GLX_AUX_BUFFERS, fgState.AuxiliaryBufferNumber)
144 if (fgState.DisplayMode & GLUT_MULTISAMPLE)
146 ATTRIB_VAL(GLX_SAMPLE_BUFFERS, 1)
147 ATTRIB_VAL(GLX_SAMPLES, fgState.SampleNumber)
150 /* Push a null at the end of the list */
154 GLXFBConfig * fbconfigArray; /* Array of FBConfigs */
155 GLXFBConfig * fbconfig; /* The FBConfig we want */
156 int fbconfigArraySize; /* Number of FBConfigs in the array */
159 /* Get all FBConfigs that match "attributes". */
160 fbconfigArray = glXChooseFBConfig( fgDisplay.Display,
163 &fbconfigArraySize );
165 if (fbconfigArray != NULL)
167 int result; /* Returned by glXGetFBConfigAttrib, not checked. */
170 if( wantIndexedMode )
173 * In index mode, we want the largest buffer size, i.e. visual
174 * depth. Here, FBConfigs are sorted by increasing buffer size
175 * first, so FBConfigs with the largest size come last.
178 int bufferSizeMin, bufferSizeMax;
180 /* Get bufferSizeMin. */
182 glXGetFBConfigAttrib( fgDisplay.Display,
186 /* Get bufferSizeMax. */
188 glXGetFBConfigAttrib( fgDisplay.Display,
189 fbconfigArray[fbconfigArraySize - 1],
193 if (bufferSizeMax > bufferSizeMin)
196 * Free and reallocate fbconfigArray, keeping only FBConfigs
197 * with the largest buffer size.
199 XFree(fbconfigArray);
201 /* Add buffer size token at the end of the list. */
203 ATTRIB_VAL( GLX_BUFFER_SIZE, bufferSizeMax );
206 fbconfigArray = glXChooseFBConfig( fgDisplay.Display,
209 &fbconfigArraySize );
214 * We now have an array of FBConfigs, the first one being the "best"
215 * one. So we should return only this FBConfig:
219 * - pick the XID of the FBConfig we want
220 * result = glXGetFBConfigAttrib( fgDisplay.Display,
226 * XFree(fbconfigArray);
228 * - reset "attributes" with the XID
230 * ATTRIB_VAL( GLX_FBCONFIG_ID, fbconfigXID );
233 * - get our FBConfig only
234 * fbconfig = glXChooseFBConfig( fgDisplay.Display,
237 * &fbconfigArraySize );
239 * However, for some configurations (for instance multisampling with
240 * Mesa 6.5.2 and ATI drivers), this does not work:
241 * glXChooseFBConfig returns NULL, whereas fbconfigXID is a valid
242 * XID. Further investigation is needed.
244 * So, for now, we return the whole array of FBConfigs. This should
245 * not produce any side effects elsewhere.
247 fbconfig = fbconfigArray;
257 #endif /* TARGET_HOST_POSIX_X11 */
260 * Setup the pixel format for a Win32 window
262 #if TARGET_HOST_MS_WINDOWS
263 /* The following include file is available from SGI but is not standard:
264 * #include <GL/wglext.h>
265 * So we copy the necessary parts out of it.
266 * XXX: should local definitions for extensions be put in a separate include file?
268 typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
270 typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
272 #define WGL_DRAW_TO_WINDOW_ARB 0x2001
273 #define WGL_ACCELERATION_ARB 0x2003
274 #define WGL_SUPPORT_OPENGL_ARB 0x2010
275 #define WGL_DOUBLE_BUFFER_ARB 0x2011
276 #define WGL_COLOR_BITS_ARB 0x2014
277 #define WGL_ALPHA_BITS_ARB 0x201B
278 #define WGL_DEPTH_BITS_ARB 0x2022
279 #define WGL_STENCIL_BITS_ARB 0x2023
280 #define WGL_FULL_ACCELERATION_ARB 0x2027
282 #define WGL_SAMPLE_BUFFERS_ARB 0x2041
283 #define WGL_SAMPLES_ARB 0x2042
286 #ifndef WGL_ARB_create_context
287 #define WGL_ARB_create_context 1
288 #ifdef WGL_WGLEXT_PROTOTYPES
289 extern HGLRC WINAPI wglCreateContextAttribsARB (HDC, HGLRC, const int *);
290 #endif /* WGL_WGLEXT_PROTOTYPES */
291 typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList);
293 #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
294 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
295 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
296 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
297 #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
298 #define WGL_CONTEXT_FLAGS_ARB 0x2094
299 #define ERROR_INVALID_VERSION_ARB 0x2095
303 GLboolean fgNewWGLCreateContext( SFG_Window* window )
305 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetEntensionsStringARB;
307 if( (fgState.ContextFlags & GLUT_FORWARD_COMPATIBLE) &&
308 (fgState.MajorVersion > 2) )
313 wglMakeCurrent( window->Window.Device,
314 window->Window.Context );
316 wglGetEntensionsStringARB=(PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
317 if ( wglGetEntensionsStringARB == NULL )
322 const char * pWglExtString=wglGetEntensionsStringARB(window->Window.Device);
323 if ( pWglExtString == NULL )
328 if ( strstr(pWglExtString, "WGL_ARB_create_context") == NULL )
333 /* new context creation */
336 PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
338 attribs[0] = WGL_CONTEXT_MAJOR_VERSION_ARB;
339 attribs[1] = fgState.MajorVersion;
340 attribs[2] = WGL_CONTEXT_MINOR_VERSION_ARB;
341 attribs[3] = fgState.MinorVersion;
342 attribs[4] = WGL_CONTEXT_FLAGS_ARB;
343 attribs[5] = ((fgState.ContextFlags & GLUT_DEBUG) ? WGL_CONTEXT_DEBUG_BIT_ARB : 0) |
344 ((fgState.ContextFlags & GLUT_FORWARD_COMPATIBLE) ? WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB : 0);
347 wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress( "wglCreateContextAttribsARB" );
348 if ( wglCreateContextAttribsARB == NULL )
350 fgError( "wglCreateContextAttribsARB not found" );
353 context = wglCreateContextAttribsARB( window->Window.Device, 0, attribs );
354 if ( context == NULL )
356 fgError( "Unable to create OpenGL %d.%d context (flags %x)",
357 fgState.MajorVersion, fgState.MinorVersion, fgState.ContextFlags );
361 fgWarning( "Success 3.0" );
362 wglMakeCurrent( NULL, NULL );
363 wglDeleteContext( window->Window.Context );
364 window->Window.Context = context;
371 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
372 unsigned char layer_type )
374 #if defined(_WIN32_WCE)
377 PIXELFORMATDESCRIPTOR* ppfd, pfd;
378 int flags, pixelformat;
380 freeglut_return_val_if_fail( window != NULL, 0 );
381 flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
382 if( fgState.DisplayMode & GLUT_DOUBLE )
383 flags |= PFD_DOUBLEBUFFER;
385 if( fgState.DisplayMode & GLUT_STEREO )
388 #if defined(_MSC_VER)
389 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
392 /* Specify which pixel format do we opt for... */
393 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
397 if( fgState.DisplayMode & GLUT_INDEX )
399 pfd.iPixelType = PFD_TYPE_COLORINDEX;
407 pfd.iPixelType = PFD_TYPE_RGBA;
411 if ( fgState.DisplayMode & GLUT_ALPHA )
423 pfd.cAccumRedBits = 0;
424 pfd.cAccumGreenBits = 0;
425 pfd.cAccumBlueBits = 0;
426 pfd.cAccumAlphaBits = 0;
429 pfd.cStencilBits = 0;
432 pfd.cStencilBits = 8;
434 if( fgState.DisplayMode & GLUT_AUX4 )
436 else if( fgState.DisplayMode & GLUT_AUX3 )
438 else if( fgState.DisplayMode & GLUT_AUX2 )
440 else if( fgState.DisplayMode & GLUT_AUX1 )
445 pfd.iLayerType = layer_type;
448 pfd.dwVisibleMask = 0;
449 pfd.dwDamageMask = 0;
451 pfd.cColorBits = (BYTE) GetDeviceCaps( window->Window.Device, BITSPIXEL );
454 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
456 /* windows hack for multismapling */
457 if (fgState.DisplayMode&GLUT_MULTISAMPLE)
459 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetEntensionsStringARB=NULL;
460 HGLRC rc, rc_before=wglGetCurrentContext();
462 HDC hDC, hDC_before=wglGetCurrentDC();
465 /* create a dummy window */
466 ZeroMemory(&wndCls, sizeof(wndCls));
467 wndCls.lpfnWndProc = DefWindowProc;
468 wndCls.hInstance = fgDisplay.Instance;
469 wndCls.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
470 wndCls.lpszClassName = _T("FREEGLUT_dummy");
471 RegisterClass( &wndCls );
473 hWnd=CreateWindow(_T("FREEGLUT_dummy"), _T(""), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW , 0,0,0,0, 0, 0, fgDisplay.Instance, 0 );
475 SetPixelFormat( hDC, pixelformat, ppfd );
477 rc = wglCreateContext( hDC );
478 wglMakeCurrent(hDC, rc);
480 wglGetEntensionsStringARB=(PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
481 if (wglGetEntensionsStringARB)
483 const char * pWglExtString=wglGetEntensionsStringARB(hDC);
486 if (strstr(pWglExtString, "WGL_ARB_multisample"))
488 int pAttributes[100];
492 float fAttributes[] = {0,0};
494 PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARBProc=NULL;
496 wglChoosePixelFormatARBProc=(PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
497 if ( wglChoosePixelFormatARBProc )
499 pAttributes[iCounter++]=WGL_DRAW_TO_WINDOW_ARB; pAttributes[iCounter++]=GL_TRUE;
500 pAttributes[iCounter++]=WGL_SUPPORT_OPENGL_ARB; pAttributes[iCounter++]=GL_TRUE;
501 pAttributes[iCounter++]=WGL_ACCELERATION_ARB; pAttributes[iCounter++]=WGL_FULL_ACCELERATION_ARB;
503 pAttributes[iCounter++]=WGL_COLOR_BITS_ARB; pAttributes[iCounter++]=pfd.cColorBits ;
504 pAttributes[iCounter++]=WGL_ALPHA_BITS_ARB; pAttributes[iCounter++]=pfd.cAlphaBits;
505 pAttributes[iCounter++]=WGL_DEPTH_BITS_ARB; pAttributes[iCounter++]=pfd.cDepthBits;
506 pAttributes[iCounter++]=WGL_STENCIL_BITS_ARB; pAttributes[iCounter++]=pfd.cStencilBits;
508 pAttributes[iCounter++]=WGL_DOUBLE_BUFFER_ARB; pAttributes[iCounter++]=(fgState.DisplayMode & GLUT_DOUBLE)!=0;
509 pAttributes[iCounter++]=WGL_SAMPLE_BUFFERS_ARB; pAttributes[iCounter++]=GL_TRUE;
510 pAttributes[iCounter++]=WGL_SAMPLES_ARB; pAttributes[iCounter++]=4;
511 pAttributes[iCounter++]=0; pAttributes[iCounter++]=0; /* terminator */
513 bValid = wglChoosePixelFormatARBProc(window->Window.Device,pAttributes,fAttributes,1,&iPixelFormat,&numFormats);
515 if (bValid && numFormats>0)
516 pixelformat=iPixelFormat;
519 wglMakeCurrent( hDC_before, rc_before);
520 wglDeleteContext(rc);
521 ReleaseDC(hWnd, hDC);
523 UnregisterClass(_T("FREEGLUT_dummy"), fgDisplay.Instance);
528 if( pixelformat == 0 )
533 return SetPixelFormat( window->Window.Device, pixelformat, ppfd );
534 #endif /* defined(_WIN32_WCE) */
536 #endif /* TARGET_HOST_MS_WINDOWS */
539 * Sets the OpenGL context and the fgStructure "Current Window" pointer to
540 * the window structure passed in.
542 void fgSetWindow ( SFG_Window *window )
544 #if TARGET_HOST_POSIX_X11
546 glXMakeContextCurrent(
548 window->Window.Handle,
549 window->Window.Handle,
550 window->Window.Context
552 #elif TARGET_HOST_MS_WINDOWS
553 if( fgStructure.CurrentWindow )
554 ReleaseDC( fgStructure.CurrentWindow->Window.Handle,
555 fgStructure.CurrentWindow->Window.Device );
559 window->Window.Device = GetDC( window->Window.Handle );
561 window->Window.Device,
562 window->Window.Context
566 fgStructure.CurrentWindow = window;
571 #if TARGET_HOST_POSIX_X11
573 #ifndef GLX_CONTEXT_MAJOR_VERSION_ARB
574 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
577 #ifndef GLX_CONTEXT_MINOR_VERSION_ARB
578 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
581 #ifndef GLX_CONTEXT_FLAGS_ARB
582 #define GLX_CONTEXT_FLAGS_ARB 0x2094
585 #ifndef GLX_CONTEXT_DEBUG_BIT_ARB
586 #define GLX_CONTEXT_DEBUG_BIT_ARB 0x0001
589 #ifndef GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
590 #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
593 typedef GLXContext (*CreateContextAttribsProc)(Display *dpy, GLXFBConfig config,
594 GLXContext share_list, Bool direct,
595 const int *attrib_list);
597 static GLXContext fghCreateNewContext( SFG_Window* window )
599 /* for color model calculation */
600 int menu = ( window->IsMenu && !fgStructure.MenuContext );
601 int index_mode = ( fgState.DisplayMode & GLUT_INDEX );
603 /* "classic" context creation */
604 Display *dpy = fgDisplay.Display;
605 GLXFBConfig config = *(window->Window.FBConfig);
606 int render_type = ( !menu && index_mode ) ? GLX_COLOR_INDEX_TYPE : GLX_RGBA_TYPE;
607 GLXContext share_list = NULL;
608 Bool direct = ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT );
611 /* new context creation */
613 CreateContextAttribsProc createContextAttribs;
615 /* If nothing fancy has been required, simply use the old context creation GLX API entry */
616 if ( fgState.MajorVersion == 1 && fgState.MinorVersion == 0 && fgState.ContextFlags == 0)
618 context = glXCreateNewContext( dpy, config, render_type, share_list, direct );
619 if ( context == NULL ) {
620 fgError( "could not create new OpenGL context" );
625 /* color index mode is not available anymore with OpenGL 3.0 */
626 if ( render_type == GLX_COLOR_INDEX_TYPE ) {
627 fgWarning( "color index mode is deprecated, using RGBA mode" );
630 attribs[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
631 attribs[1] = fgState.MajorVersion;
632 attribs[2] = GLX_CONTEXT_MINOR_VERSION_ARB;
633 attribs[3] = fgState.MinorVersion;
634 attribs[4] = GLX_CONTEXT_FLAGS_ARB;
635 attribs[5] = ((fgState.ContextFlags & GLUT_DEBUG) ? GLX_CONTEXT_DEBUG_BIT_ARB : 0) |
636 ((fgState.ContextFlags & GLUT_FORWARD_COMPATIBLE) ? GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB : 0);
639 createContextAttribs = (CreateContextAttribsProc) fghGetProcAddress( "glXCreateContextAttribsARB" );
640 if ( createContextAttribs == NULL ) {
641 fgError( "glXCreateContextAttribsARB not found" );
644 context = createContextAttribs( dpy, config, share_list, direct, attribs );
645 if ( context == NULL ) {
646 fgError( "could not create new OpenGL %d.%d context (flags %x)",
647 fgState.MajorVersion, fgState.MinorVersion, fgState.ContextFlags );
655 * Opens a window. Requires a SFG_Window object created and attached
656 * to the freeglut structure. OpenGL context is created here.
658 void fgOpenWindow( SFG_Window* window, const char* title,
659 GLboolean positionUse, int x, int y,
660 GLboolean sizeUse, int w, int h,
661 GLboolean gameMode, GLboolean isSubWindow )
663 #if TARGET_HOST_POSIX_X11
664 XVisualInfo * visualInfo;
665 XSetWindowAttributes winAttr;
666 XTextProperty textProperty;
667 XSizeHints sizeHints;
670 unsigned int current_DisplayMode = fgState.DisplayMode ;
672 /* Save the display mode if we are creating a menu window */
673 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
674 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ;
676 window->Window.FBConfig = fgChooseFBConfig( );
678 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
679 fgState.DisplayMode = current_DisplayMode ;
681 if( ! window->Window.FBConfig )
684 * The "fgChooseFBConfig" returned a null meaning that the visual
685 * context is not available.
686 * Try a couple of variations to see if they will work.
688 if( !( fgState.DisplayMode & GLUT_DOUBLE ) )
690 fgState.DisplayMode |= GLUT_DOUBLE ;
691 window->Window.FBConfig = fgChooseFBConfig( );
692 fgState.DisplayMode &= ~GLUT_DOUBLE;
695 if( fgState.DisplayMode & GLUT_MULTISAMPLE )
697 fgState.DisplayMode &= ~GLUT_MULTISAMPLE ;
698 window->Window.FBConfig = fgChooseFBConfig( );
699 fgState.DisplayMode |= GLUT_MULTISAMPLE;
703 FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.FBConfig != NULL,
704 "FBConfig with necessary capabilities not found", "fgOpenWindow" );
706 /* Get the X visual. */
707 visualInfo = glXGetVisualFromFBConfig( fgDisplay.Display,
708 *(window->Window.FBConfig) );
711 * XXX HINT: the masks should be updated when adding/removing callbacks.
712 * XXX This might speed up message processing. Is that true?
714 * XXX A: Not appreciably, but it WILL make it easier to debug.
715 * XXX Try tracing old GLUT and try tracing freeglut. Old GLUT
716 * XXX turns off events that it doesn't need and is a whole lot
717 * XXX more pleasant to trace. (Think mouse-motion! Tons of
718 * XXX ``bonus'' GUI events stream in.)
721 StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
722 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
723 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
724 PointerMotionMask | ButtonMotionMask;
725 winAttr.background_pixmap = None;
726 winAttr.background_pixel = 0;
727 winAttr.border_pixel = 0;
729 winAttr.colormap = XCreateColormap(
730 fgDisplay.Display, fgDisplay.RootWindow,
731 visualInfo->visual, AllocNone
734 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
736 if( window->IsMenu || ( gameMode == GL_TRUE ) )
738 winAttr.override_redirect = True;
739 mask |= CWOverrideRedirect;
743 x = y = -1; /* default window position */
745 w = h = 300; /* default window size */
747 window->Window.Handle = XCreateWindow(
749 window->Parent == NULL ? fgDisplay.RootWindow :
750 window->Parent->Window.Handle,
752 visualInfo->depth, InputOutput,
753 visualInfo->visual, mask,
758 * The GLX context creation, possibly trying the direct context rendering
759 * or else use the current context if the user has so specified
765 * If there isn't already an OpenGL rendering context for menu
768 if( !fgStructure.MenuContext )
770 fgStructure.MenuContext =
771 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
772 fgStructure.MenuContext->MContext = fghCreateNewContext( window );
775 /* window->Window.Context = fgStructure.MenuContext->MContext; */
776 window->Window.Context = fghCreateNewContext( window );
778 else if( fgState.UseCurrentContext )
780 window->Window.Context = glXGetCurrentContext( );
782 if( ! window->Window.Context )
783 window->Window.Context = fghCreateNewContext( window );
786 window->Window.Context = fghCreateNewContext( window );
788 #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ )
789 if( !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
791 if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
792 fgError( "Unable to force direct context rendering for window '%s'",
798 * XXX Assume the new window is visible by default
799 * XXX Is this a safe assumption?
801 window->State.Visible = GL_TRUE;
805 sizeHints.flags |= USPosition;
807 sizeHints.flags |= USSize;
810 * Fill in the size hints values now (the x, y, width and height
811 * settings are obsolete, are there any more WMs that support them?)
812 * Unless the X servers actually stop supporting these, we should
813 * continue to fill them in. It is *not* our place to tell the user
814 * that they should replace a window manager that they like, and which
815 * works, just because *we* think that it's not "modern" enough.
820 sizeHints.height = h;
822 wmHints.flags = StateHint;
823 wmHints.initial_state = fgState.ForceIconic ? IconicState : NormalState;
824 /* Prepare the window and iconified window names... */
825 XStringListToTextProperty( (char **) &title, 1, &textProperty );
829 window->Window.Handle,
838 XFree( textProperty.value );
840 XSetWMProtocols( fgDisplay.Display, window->Window.Handle,
841 &fgDisplay.DeleteWindow, 1 );
843 glXMakeContextCurrent(
845 window->Window.Handle,
846 window->Window.Handle,
847 window->Window.Context
850 XMapWindow( fgDisplay.Display, window->Window.Handle );
854 #elif TARGET_HOST_MS_WINDOWS
862 /* Grab the window class we have registered on glutInit(): */
863 atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
864 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Info Not Found",
869 FREEGLUT_INTERNAL_ERROR_EXIT ( window->Parent == NULL,
870 "Game mode being invoked on a subwindow",
874 * Set the window creation flags appropriately to make the window
877 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
881 int worig = w, horig = h;
883 #if !defined(_WIN32_WCE)
884 if ( ( ! isSubWindow ) && ( ! window->IsMenu ) )
887 * Update the window dimensions, taking account of window
888 * decorations. "freeglut" is to create the window with the
889 * outside of its border at (x,y) and with dimensions (w,h).
891 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
892 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 +
893 GetSystemMetrics( SM_CYCAPTION );
895 #endif /* defined(_WIN32_WCE) */
902 /* setting State.Width/Height to call resize callback later */
905 if( ! window->IsMenu )
910 else /* fail safe - Windows can make a window of size (0, 0) */
911 w = h = 300; /* default window size */
912 window->State.Width = window->State.Height = -1;
916 window->State.Width = worig;
917 window->State.Height = horig;
921 * There's a small difference between creating the top, child and
924 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
926 if ( window->IsMenu )
929 exFlags |= WS_EX_TOOLWINDOW;
931 #if !defined(_WIN32_WCE)
932 else if( window->Parent == NULL )
933 flags |= WS_OVERLAPPEDWINDOW;
939 #if defined(_WIN32_WCE)
941 wchar_t* wstr = fghWstrFromStr(title);
943 window->Window.Handle = CreateWindow(
946 WS_VISIBLE | WS_POPUP,
956 SHFullScreen(window->Window.Handle, SHFS_HIDESTARTICON);
957 SHFullScreen(window->Window.Handle, SHFS_HIDESIPBUTTON);
958 SHFullScreen(window->Window.Handle, SHFS_HIDETASKBAR);
959 MoveWindow(window->Window.Handle, 0, 0, 240, 320, TRUE);
960 ShowWindow(window->Window.Handle, SW_SHOW);
961 UpdateWindow(window->Window.Handle);
964 window->Window.Handle = CreateWindowEx(
970 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
975 #endif /* defined(_WIN32_WCE) */
977 if( !( window->Window.Handle ) )
978 fgError( "Failed to create a window (%s)!", title );
980 /* Make a menu window always on top - fix Feature Request 947118 */
981 if( window->IsMenu || gameMode )
983 window->Window.Handle,
986 SWP_NOMOVE | SWP_NOSIZE
989 /* Hack to remove the caption (title bar) and/or border
990 * and all the system menu controls.
992 WindowStyle = GetWindowLong(window->Window.Handle, GWL_STYLE);
993 if ( fgState.DisplayMode & GLUT_CAPTIONLESS )
995 SetWindowLong ( window->Window.Handle, GWL_STYLE,
996 WindowStyle & ~(WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX));
998 else if ( fgState.DisplayMode & GLUT_BORDERLESS )
1000 SetWindowLong ( window->Window.Handle, GWL_STYLE,
1001 WindowStyle & ~(WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX));
1003 /* SetWindowPos(window->Window.Handle, NULL, 0, 0, 0, 0,
1004 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); */
1007 #if defined(_WIN32_WCE)
1008 ShowWindow( window->Window.Handle, SW_SHOW );
1010 ShowWindow( window->Window.Handle,
1011 fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
1012 #endif /* defined(_WIN32_WCE) */
1014 UpdateWindow( window->Window.Handle );
1015 ShowCursor( TRUE ); /* XXX Old comments say "hide cursor"! */
1019 fgSetWindow( window );
1021 window->Window.DoubleBuffered =
1022 ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
1024 if ( ! window->Window.DoubleBuffered )
1026 glDrawBuffer ( GL_FRONT );
1027 glReadBuffer ( GL_FRONT );
1032 * Closes a window, destroying the frame and OpenGL context
1034 void fgCloseWindow( SFG_Window* window )
1036 #if TARGET_HOST_POSIX_X11
1038 glXDestroyContext( fgDisplay.Display, window->Window.Context );
1039 XFree( window->Window.FBConfig );
1040 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
1041 /* XFlush( fgDisplay.Display ); */ /* XXX Shouldn't need this */
1043 #elif TARGET_HOST_MS_WINDOWS
1045 /* Make sure we don't close a window with current context active */
1046 if( fgStructure.CurrentWindow == window )
1047 wglMakeCurrent( NULL, NULL );
1050 * Step through the list of windows. If the rendering context
1051 * is not being used by another window, then we delete it.
1057 for( iter = (SFG_Window *)fgStructure.Windows.First;
1059 iter = (SFG_Window *)iter->Node.Next )
1061 if( ( iter->Window.Context == window->Window.Context ) &&
1062 ( iter != window ) )
1067 wglDeleteContext( window->Window.Context );
1070 DestroyWindow( window->Window.Handle );
1075 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1078 * Creates a new top-level freeglut window
1080 int FGAPIENTRY glutCreateWindow( const char* title )
1082 /* XXX GLUT does not exit; it simply calls "glutInit" quietly if the
1083 * XXX application has not already done so. The "freeglut" community
1084 * XXX decided not to go this route (freeglut-developer e-mail from
1085 * XXX Steve Baker, 12/16/04, 4:22 PM CST, "Re: [Freeglut-developer]
1086 * XXX Desired 'freeglut' behaviour when there is no current window"
1088 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateWindow" );
1090 return fgCreateWindow( NULL, title, fgState.Position.Use,
1091 fgState.Position.X, fgState.Position.Y,
1092 fgState.Size.Use, fgState.Size.X, fgState.Size.Y,
1093 GL_FALSE, GL_FALSE )->ID;
1097 * This function creates a sub window.
1099 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
1102 SFG_Window* window = NULL;
1103 SFG_Window* parent = NULL;
1105 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateSubWindow" );
1106 parent = fgWindowByID( parentID );
1107 freeglut_return_val_if_fail( parent != NULL, 0 );
1110 x = parent->State.Width + x ;
1111 if ( w >= 0 ) x -= w ;
1114 if ( w < 0 ) w = parent->State.Width - x + w ;
1123 y = parent->State.Height + y ;
1124 if ( h >= 0 ) y -= h ;
1127 if ( h < 0 ) h = parent->State.Height - y + h ;
1134 window = fgCreateWindow( parent, "", GL_TRUE, x, y, GL_TRUE, w, h, GL_FALSE, GL_FALSE );
1141 * Destroys a window and all of its subwindows
1143 void FGAPIENTRY glutDestroyWindow( int windowID )
1146 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDestroyWindow" );
1147 window = fgWindowByID( windowID );
1148 freeglut_return_if_fail( window != NULL );
1150 fgExecutionState ExecState = fgState.ExecState;
1151 fgAddToWindowDestroyList( window );
1152 fgState.ExecState = ExecState;
1157 * This function selects the current window
1159 void FGAPIENTRY glutSetWindow( int ID )
1161 SFG_Window* window = NULL;
1163 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindow" );
1164 if( fgStructure.CurrentWindow != NULL )
1165 if( fgStructure.CurrentWindow->ID == ID )
1168 window = fgWindowByID( ID );
1169 if( window == NULL )
1171 fgWarning( "glutSetWindow(): window ID %d not found!", ID );
1175 fgSetWindow( window );
1179 * This function returns the ID number of the current window, 0 if none exists
1181 int FGAPIENTRY glutGetWindow( void )
1183 SFG_Window *win = fgStructure.CurrentWindow;
1185 * Since GLUT did not throw an error if this function was called without a prior call to
1186 * "glutInit", this function shouldn't do so here. Instead let us return a zero.
1187 * See Feature Request "[ 1307049 ] glutInit check".
1189 if ( ! fgState.Initialised )
1192 while ( win && win->IsMenu )
1194 return win ? win->ID : 0;
1198 * This function makes the current window visible
1200 void FGAPIENTRY glutShowWindow( void )
1202 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" );
1203 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" );
1205 #if TARGET_HOST_POSIX_X11
1207 XMapWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1208 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1210 #elif TARGET_HOST_MS_WINDOWS
1212 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_SHOW );
1216 fgStructure.CurrentWindow->State.Redisplay = GL_TRUE;
1220 * This function hides the current window
1222 void FGAPIENTRY glutHideWindow( void )
1224 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" );
1225 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" );
1227 #if TARGET_HOST_POSIX_X11
1229 if( fgStructure.CurrentWindow->Parent == NULL )
1230 XWithdrawWindow( fgDisplay.Display,
1231 fgStructure.CurrentWindow->Window.Handle,
1234 XUnmapWindow( fgDisplay.Display,
1235 fgStructure.CurrentWindow->Window.Handle );
1236 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1238 #elif TARGET_HOST_MS_WINDOWS
1240 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_HIDE );
1244 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
1248 * Iconify the current window (top-level windows only)
1250 void FGAPIENTRY glutIconifyWindow( void )
1252 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" );
1253 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" );
1255 fgStructure.CurrentWindow->State.Visible = GL_FALSE;
1256 #if TARGET_HOST_POSIX_X11
1258 XIconifyWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
1260 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1262 #elif TARGET_HOST_MS_WINDOWS
1264 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_MINIMIZE );
1268 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
1272 * Set the current window's title
1274 void FGAPIENTRY glutSetWindowTitle( const char* title )
1276 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowTitle" );
1277 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" );
1278 if( ! fgStructure.CurrentWindow->Parent )
1280 #if TARGET_HOST_POSIX_X11
1284 text.value = (unsigned char *) title;
1285 text.encoding = XA_STRING;
1287 text.nitems = strlen( title );
1291 fgStructure.CurrentWindow->Window.Handle,
1295 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1297 #elif TARGET_HOST_MS_WINDOWS
1300 wchar_t* wstr = fghWstrFromStr(title);
1301 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
1305 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
1313 * Set the current window's iconified title
1315 void FGAPIENTRY glutSetIconTitle( const char* title )
1317 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" );
1318 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" );
1320 if( ! fgStructure.CurrentWindow->Parent )
1322 #if TARGET_HOST_POSIX_X11
1326 text.value = (unsigned char *) title;
1327 text.encoding = XA_STRING;
1329 text.nitems = strlen( title );
1333 fgStructure.CurrentWindow->Window.Handle,
1337 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1339 #elif TARGET_HOST_MS_WINDOWS
1342 wchar_t* wstr = fghWstrFromStr(title);
1343 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
1347 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
1355 * Change the current window's size
1357 void FGAPIENTRY glutReshapeWindow( int width, int height )
1359 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" );
1360 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" );
1362 if (glutGet(GLUT_FULL_SCREEN))
1364 /* Leave full screen state before resizing. */
1365 glutFullScreenToggle();
1368 fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
1369 fgStructure.CurrentWindow->State.Width = width ;
1370 fgStructure.CurrentWindow->State.Height = height;
1374 * Change the current window's position
1376 void FGAPIENTRY glutPositionWindow( int x, int y )
1378 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" );
1379 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" );
1381 if (glutGet(GLUT_FULL_SCREEN))
1383 /* Leave full screen state before moving. */
1384 glutFullScreenToggle();
1387 #if TARGET_HOST_POSIX_X11
1389 XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
1391 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1393 #elif TARGET_HOST_MS_WINDOWS
1398 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
1399 GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
1401 fgStructure.CurrentWindow->Window.Handle,
1404 winRect.right - winRect.left,
1405 winRect.bottom - winRect.top,
1414 * Lowers the current window (by Z order change)
1416 void FGAPIENTRY glutPushWindow( void )
1418 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPushWindow" );
1419 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPushWindow" );
1421 #if TARGET_HOST_POSIX_X11
1423 XLowerWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1425 #elif TARGET_HOST_MS_WINDOWS
1428 fgStructure.CurrentWindow->Window.Handle,
1431 SWP_NOSIZE | SWP_NOMOVE
1438 * Raises the current window (by Z order change)
1440 void FGAPIENTRY glutPopWindow( void )
1442 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" );
1443 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" );
1445 #if TARGET_HOST_POSIX_X11
1447 XRaiseWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1449 #elif TARGET_HOST_MS_WINDOWS
1452 fgStructure.CurrentWindow->Window.Handle,
1455 SWP_NOSIZE | SWP_NOMOVE
1462 * Resize the current window so that it fits the whole screen
1464 void FGAPIENTRY glutFullScreen( void )
1466 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" );
1467 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" );
1469 if (glutGet(GLUT_FULL_SCREEN))
1471 /* Leave full screen state before resizing. */
1472 glutFullScreenToggle();
1476 #if TARGET_HOST_POSIX_X11
1478 Status status; /* Returned by XGetWindowAttributes(), not checked. */
1479 XWindowAttributes attributes;
1481 status = XGetWindowAttributes(fgDisplay.Display,
1482 fgStructure.CurrentWindow->Window.Handle,
1485 * The "x" and "y" members of "attributes" are the window's coordinates
1486 * relative to its parent, i.e. to the decoration window.
1488 XMoveResizeWindow(fgDisplay.Display,
1489 fgStructure.CurrentWindow->Window.Handle,
1492 fgDisplay.ScreenWidth,
1493 fgDisplay.ScreenHeight);
1495 #elif TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: what about WinCE */
1498 /* For fullscreen mode, force the top-left corner to 0,0
1499 * and adjust the window rectangle so that the client area
1500 * covers the whole screen.
1505 rect.right = fgDisplay.ScreenWidth;
1506 rect.bottom = fgDisplay.ScreenHeight;
1508 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
1509 WS_CLIPCHILDREN, FALSE );
1512 * SWP_NOACTIVATE Do not activate the window
1513 * SWP_NOOWNERZORDER Do not change position in z-order
1514 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
1515 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
1518 SetWindowPos( fgStructure.CurrentWindow->Window.Handle,
1522 rect.right - rect.left,
1523 rect.bottom - rect.top,
1524 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
1532 * Toggle the window's full screen state.
1534 void FGAPIENTRY glutFullScreenToggle( void )
1536 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreenToggle" );
1537 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreenToggle" );
1540 #if TARGET_HOST_POSIX_X11
1542 if (fgDisplay.StateFullScreen != None)
1548 xevent.type = ClientMessage;
1549 xevent.xclient.type = ClientMessage;
1550 xevent.xclient.serial = 0;
1551 xevent.xclient.send_event = True;
1552 xevent.xclient.display = fgDisplay.Display;
1553 xevent.xclient.window = fgStructure.CurrentWindow->Window.Handle;
1554 xevent.xclient.message_type = fgDisplay.State;
1555 xevent.xclient.format = 32;
1556 xevent.xclient.data.l[0] = 2; /* _NET_WM_STATE_TOGGLE */
1557 xevent.xclient.data.l[1] = fgDisplay.StateFullScreen;
1558 xevent.xclient.data.l[2] = 0;
1559 xevent.xclient.data.l[3] = 0;
1560 xevent.xclient.data.l[4] = 0;
1562 /*** Don't really understand how event masks work... ***/
1563 event_mask = SubstructureRedirectMask | SubstructureNotifyMask;
1565 status = XSendEvent(fgDisplay.Display,
1566 fgDisplay.RootWindow,
1570 FREEGLUT_INTERNAL_ERROR_EXIT(status != 0,
1571 "XSendEvent failed",
1572 "glutFullScreenToggle");
1578 * If the window manager is not Net WM compliant, fall back to legacy
1587 * A.Donev: Set and retrieve the window's user data
1589 void* FGAPIENTRY glutGetWindowData( void )
1591 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindowData" );
1592 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutGetWindowData" );
1593 return fgStructure.CurrentWindow->UserData;
1596 void FGAPIENTRY glutSetWindowData(void* data)
1598 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowData" );
1599 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowData" );
1600 fgStructure.CurrentWindow->UserData = data;
1603 /*** END OF FILE ***/