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 if( (fgState.ContextFlags & GLUT_FORWARD_COMPATIBLE) &&
306 (fgState.MajorVersion > 2) )
308 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetEntensionsStringARB=NULL;
310 wglMakeCurrent( window->Window.Device,
311 window->Window.Context );
313 wglGetEntensionsStringARB=(PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
314 if (wglGetEntensionsStringARB)
316 const char * pWglExtString=wglGetEntensionsStringARB(window->Window.Device);
319 if (strstr(pWglExtString, "WGL_ARB_create_context"))
321 /* new context creation */
324 PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
326 attribs[0] = WGL_CONTEXT_MAJOR_VERSION_ARB;
327 attribs[1] = fgState.MajorVersion;
328 attribs[2] = WGL_CONTEXT_MINOR_VERSION_ARB;
329 attribs[3] = fgState.MinorVersion;
330 attribs[4] = WGL_CONTEXT_FLAGS_ARB;
331 attribs[5] = ((fgState.ContextFlags & GLUT_DEBUG) ? WGL_CONTEXT_DEBUG_BIT_ARB : 0) |
332 ((fgState.ContextFlags & GLUT_FORWARD_COMPATIBLE) ? WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB : 0);
335 wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress( "wglCreateContextAttribsARB" );
336 if ( wglCreateContextAttribsARB == NULL )
338 fgError( "wglCreateContextAttribsARB not found" );
341 context = wglCreateContextAttribsARB( window->Window.Device, 0, attribs );
342 if ( context == NULL )
344 fgError( "Unable to create OpenGL %d.%d context (flags %x)",
345 fgState.MajorVersion, fgState.MinorVersion, fgState.ContextFlags );
349 fgWarning( "Success 3.0" );
350 wglMakeCurrent( NULL, NULL );
351 wglDeleteContext( window->Window.Context );
352 window->Window.Context = context;
363 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
364 unsigned char layer_type )
366 #if defined(_WIN32_WCE)
369 PIXELFORMATDESCRIPTOR* ppfd, pfd;
370 int flags, pixelformat;
372 freeglut_return_val_if_fail( window != NULL, 0 );
373 flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
374 if( fgState.DisplayMode & GLUT_DOUBLE )
375 flags |= PFD_DOUBLEBUFFER;
377 if( fgState.DisplayMode & GLUT_STEREO )
380 #if defined(_MSC_VER)
381 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
384 /* Specify which pixel format do we opt for... */
385 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
389 if( fgState.DisplayMode & GLUT_INDEX )
391 pfd.iPixelType = PFD_TYPE_COLORINDEX;
399 pfd.iPixelType = PFD_TYPE_RGBA;
403 if ( fgState.DisplayMode & GLUT_ALPHA )
415 pfd.cAccumRedBits = 0;
416 pfd.cAccumGreenBits = 0;
417 pfd.cAccumBlueBits = 0;
418 pfd.cAccumAlphaBits = 0;
421 pfd.cStencilBits = 0;
424 pfd.cStencilBits = 8;
426 if( fgState.DisplayMode & GLUT_AUX4 )
428 else if( fgState.DisplayMode & GLUT_AUX3 )
430 else if( fgState.DisplayMode & GLUT_AUX2 )
432 else if( fgState.DisplayMode & GLUT_AUX1 )
437 pfd.iLayerType = layer_type;
440 pfd.dwVisibleMask = 0;
441 pfd.dwDamageMask = 0;
443 pfd.cColorBits = (BYTE) GetDeviceCaps( window->Window.Device, BITSPIXEL );
446 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
448 /* windows hack for multismapling */
449 if (fgState.DisplayMode&GLUT_MULTISAMPLE)
451 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetEntensionsStringARB=NULL;
452 HGLRC rc, rc_before=wglGetCurrentContext();
454 HDC hDC, hDC_before=wglGetCurrentDC();
457 /* create a dummy window */
458 ZeroMemory(&wndCls, sizeof(wndCls));
459 wndCls.lpfnWndProc = DefWindowProc;
460 wndCls.hInstance = fgDisplay.Instance;
461 wndCls.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
462 wndCls.lpszClassName = _T("FREEGLUT_dummy");
463 RegisterClass( &wndCls );
465 hWnd=CreateWindow(_T("FREEGLUT_dummy"), _T(""), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW , 0,0,0,0, 0, 0, fgDisplay.Instance, 0 );
467 SetPixelFormat( hDC, pixelformat, ppfd );
469 rc = wglCreateContext( hDC );
470 wglMakeCurrent(hDC, rc);
472 wglGetEntensionsStringARB=(PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
473 if (wglGetEntensionsStringARB)
475 const char * pWglExtString=wglGetEntensionsStringARB(hDC);
478 if (strstr(pWglExtString, "WGL_ARB_multisample"))
480 int pAttributes[100];
484 float fAttributes[] = {0,0};
486 PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARBProc=NULL;
488 wglChoosePixelFormatARBProc=(PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
489 if ( wglChoosePixelFormatARBProc )
491 pAttributes[iCounter++]=WGL_DRAW_TO_WINDOW_ARB; pAttributes[iCounter++]=GL_TRUE;
492 pAttributes[iCounter++]=WGL_SUPPORT_OPENGL_ARB; pAttributes[iCounter++]=GL_TRUE;
493 pAttributes[iCounter++]=WGL_ACCELERATION_ARB; pAttributes[iCounter++]=WGL_FULL_ACCELERATION_ARB;
495 pAttributes[iCounter++]=WGL_COLOR_BITS_ARB; pAttributes[iCounter++]=pfd.cColorBits ;
496 pAttributes[iCounter++]=WGL_ALPHA_BITS_ARB; pAttributes[iCounter++]=pfd.cAlphaBits;
497 pAttributes[iCounter++]=WGL_DEPTH_BITS_ARB; pAttributes[iCounter++]=pfd.cDepthBits;
498 pAttributes[iCounter++]=WGL_STENCIL_BITS_ARB; pAttributes[iCounter++]=pfd.cStencilBits;
500 pAttributes[iCounter++]=WGL_DOUBLE_BUFFER_ARB; pAttributes[iCounter++]=(fgState.DisplayMode & GLUT_DOUBLE)!=0;
501 pAttributes[iCounter++]=WGL_SAMPLE_BUFFERS_ARB; pAttributes[iCounter++]=GL_TRUE;
502 pAttributes[iCounter++]=WGL_SAMPLES_ARB; pAttributes[iCounter++]=4;
503 pAttributes[iCounter++]=0; pAttributes[iCounter++]=0; /* terminator */
505 bValid = wglChoosePixelFormatARBProc(window->Window.Device,pAttributes,fAttributes,1,&iPixelFormat,&numFormats);
507 if (bValid && numFormats>0)
508 pixelformat=iPixelFormat;
511 wglMakeCurrent( hDC_before, rc_before);
512 wglDeleteContext(rc);
513 ReleaseDC(hWnd, hDC);
515 UnregisterClass(_T("FREEGLUT_dummy"), fgDisplay.Instance);
520 if( pixelformat == 0 )
525 return SetPixelFormat( window->Window.Device, pixelformat, ppfd );
526 #endif /* defined(_WIN32_WCE) */
528 #endif /* TARGET_HOST_MS_WINDOWS */
531 * Sets the OpenGL context and the fgStructure "Current Window" pointer to
532 * the window structure passed in.
534 void fgSetWindow ( SFG_Window *window )
536 #if TARGET_HOST_POSIX_X11
538 glXMakeContextCurrent(
540 window->Window.Handle,
541 window->Window.Handle,
542 window->Window.Context
544 #elif TARGET_HOST_MS_WINDOWS
545 if( fgStructure.CurrentWindow )
546 ReleaseDC( fgStructure.CurrentWindow->Window.Handle,
547 fgStructure.CurrentWindow->Window.Device );
551 window->Window.Device = GetDC( window->Window.Handle );
553 window->Window.Device,
554 window->Window.Context
558 fgStructure.CurrentWindow = window;
563 #if TARGET_HOST_POSIX_X11
565 #ifndef GLX_CONTEXT_MAJOR_VERSION_ARB
566 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
569 #ifndef GLX_CONTEXT_MINOR_VERSION_ARB
570 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
573 #ifndef GLX_CONTEXT_FLAGS_ARB
574 #define GLX_CONTEXT_FLAGS_ARB 0x2094
577 #ifndef GLX_CONTEXT_DEBUG_BIT_ARB
578 #define GLX_CONTEXT_DEBUG_BIT_ARB 0x0001
581 #ifndef GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
582 #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
585 typedef GLXContext (*CreateContextAttribsProc)(Display *dpy, GLXFBConfig config,
586 GLXContext share_list, Bool direct,
587 const int *attrib_list);
589 static GLXContext fghCreateNewContext( SFG_Window* window )
591 /* for color model calculation */
592 int menu = ( window->IsMenu && !fgStructure.MenuContext );
593 int index_mode = ( fgState.DisplayMode & GLUT_INDEX );
595 /* "classic" context creation */
596 Display *dpy = fgDisplay.Display;
597 GLXFBConfig config = *(window->Window.FBConfig);
598 int render_type = ( !menu && index_mode ) ? GLX_COLOR_INDEX_TYPE : GLX_RGBA_TYPE;
599 GLXContext share_list = NULL;
600 Bool direct = ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT );
603 /* new context creation */
605 CreateContextAttribsProc createContextAttribs;
607 /* If nothing fancy has been required, simply use the old context creation GLX API entry */
608 if ( fgState.MajorVersion == 1 && fgState.MinorVersion == 0 && fgState.ContextFlags == 0)
610 context = glXCreateNewContext( dpy, config, render_type, share_list, direct );
611 if ( context == NULL ) {
612 fgError( "could not create new OpenGL context" );
617 /* color index mode is not available anymore with OpenGL 3.0 */
618 if ( render_type == GLX_COLOR_INDEX_TYPE ) {
619 fgWarning( "color index mode is deprecated, using RGBA mode" );
622 attribs[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
623 attribs[1] = fgState.MajorVersion;
624 attribs[2] = GLX_CONTEXT_MINOR_VERSION_ARB;
625 attribs[3] = fgState.MinorVersion;
626 attribs[4] = GLX_CONTEXT_FLAGS_ARB;
627 attribs[5] = ((fgState.ContextFlags & GLUT_DEBUG) ? GLX_CONTEXT_DEBUG_BIT_ARB : 0) |
628 ((fgState.ContextFlags & GLUT_FORWARD_COMPATIBLE) ? GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB : 0);
631 createContextAttribs = (CreateContextAttribsProc) fghGetProcAddress( "glXCreateContextAttribsARB" );
632 if ( createContextAttribs == NULL ) {
633 fgError( "glXCreateContextAttribsARB not found" );
636 context = createContextAttribs( dpy, config, share_list, direct, attribs );
637 if ( context == NULL ) {
638 fgError( "could not create new OpenGL %d.%d context (flags %x)",
639 fgState.MajorVersion, fgState.MinorVersion, fgState.ContextFlags );
647 * Opens a window. Requires a SFG_Window object created and attached
648 * to the freeglut structure. OpenGL context is created here.
650 void fgOpenWindow( SFG_Window* window, const char* title,
651 GLboolean positionUse, int x, int y,
652 GLboolean sizeUse, int w, int h,
653 GLboolean gameMode, GLboolean isSubWindow )
655 #if TARGET_HOST_POSIX_X11
656 XVisualInfo * visualInfo;
657 XSetWindowAttributes winAttr;
658 XTextProperty textProperty;
659 XSizeHints sizeHints;
662 unsigned int current_DisplayMode = fgState.DisplayMode ;
664 /* Save the display mode if we are creating a menu window */
665 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
666 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ;
668 window->Window.FBConfig = fgChooseFBConfig( );
670 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
671 fgState.DisplayMode = current_DisplayMode ;
673 if( ! window->Window.FBConfig )
676 * The "fgChooseFBConfig" returned a null meaning that the visual
677 * context is not available.
678 * Try a couple of variations to see if they will work.
680 if( !( fgState.DisplayMode & GLUT_DOUBLE ) )
682 fgState.DisplayMode |= GLUT_DOUBLE ;
683 window->Window.FBConfig = fgChooseFBConfig( );
684 fgState.DisplayMode &= ~GLUT_DOUBLE;
687 if( fgState.DisplayMode & GLUT_MULTISAMPLE )
689 fgState.DisplayMode &= ~GLUT_MULTISAMPLE ;
690 window->Window.FBConfig = fgChooseFBConfig( );
691 fgState.DisplayMode |= GLUT_MULTISAMPLE;
695 FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.FBConfig != NULL,
696 "FBConfig with necessary capabilities not found", "fgOpenWindow" );
698 /* Get the X visual. */
699 visualInfo = glXGetVisualFromFBConfig( fgDisplay.Display,
700 *(window->Window.FBConfig) );
703 * XXX HINT: the masks should be updated when adding/removing callbacks.
704 * XXX This might speed up message processing. Is that true?
706 * XXX A: Not appreciably, but it WILL make it easier to debug.
707 * XXX Try tracing old GLUT and try tracing freeglut. Old GLUT
708 * XXX turns off events that it doesn't need and is a whole lot
709 * XXX more pleasant to trace. (Think mouse-motion! Tons of
710 * XXX ``bonus'' GUI events stream in.)
713 StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
714 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
715 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
716 PointerMotionMask | ButtonMotionMask;
717 winAttr.background_pixmap = None;
718 winAttr.background_pixel = 0;
719 winAttr.border_pixel = 0;
721 winAttr.colormap = XCreateColormap(
722 fgDisplay.Display, fgDisplay.RootWindow,
723 visualInfo->visual, AllocNone
726 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
728 if( window->IsMenu || ( gameMode == GL_TRUE ) )
730 winAttr.override_redirect = True;
731 mask |= CWOverrideRedirect;
735 x = y = -1; /* default window position */
737 w = h = 300; /* default window size */
739 window->Window.Handle = XCreateWindow(
741 window->Parent == NULL ? fgDisplay.RootWindow :
742 window->Parent->Window.Handle,
744 visualInfo->depth, InputOutput,
745 visualInfo->visual, mask,
750 * The GLX context creation, possibly trying the direct context rendering
751 * or else use the current context if the user has so specified
757 * If there isn't already an OpenGL rendering context for menu
760 if( !fgStructure.MenuContext )
762 fgStructure.MenuContext =
763 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
764 fgStructure.MenuContext->MContext = fghCreateNewContext( window );
767 /* window->Window.Context = fgStructure.MenuContext->MContext; */
768 window->Window.Context = fghCreateNewContext( window );
770 else if( fgState.UseCurrentContext )
772 window->Window.Context = glXGetCurrentContext( );
774 if( ! window->Window.Context )
775 window->Window.Context = fghCreateNewContext( window );
778 window->Window.Context = fghCreateNewContext( window );
780 #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ )
781 if( !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
783 if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
784 fgError( "Unable to force direct context rendering for window '%s'",
790 * XXX Assume the new window is visible by default
791 * XXX Is this a safe assumption?
793 window->State.Visible = GL_TRUE;
797 sizeHints.flags |= USPosition;
799 sizeHints.flags |= USSize;
802 * Fill in the size hints values now (the x, y, width and height
803 * settings are obsolete, are there any more WMs that support them?)
804 * Unless the X servers actually stop supporting these, we should
805 * continue to fill them in. It is *not* our place to tell the user
806 * that they should replace a window manager that they like, and which
807 * works, just because *we* think that it's not "modern" enough.
812 sizeHints.height = h;
814 wmHints.flags = StateHint;
815 wmHints.initial_state = fgState.ForceIconic ? IconicState : NormalState;
816 /* Prepare the window and iconified window names... */
817 XStringListToTextProperty( (char **) &title, 1, &textProperty );
821 window->Window.Handle,
830 XFree( textProperty.value );
832 XSetWMProtocols( fgDisplay.Display, window->Window.Handle,
833 &fgDisplay.DeleteWindow, 1 );
835 glXMakeContextCurrent(
837 window->Window.Handle,
838 window->Window.Handle,
839 window->Window.Context
842 XMapWindow( fgDisplay.Display, window->Window.Handle );
846 #elif TARGET_HOST_MS_WINDOWS
854 /* Grab the window class we have registered on glutInit(): */
855 atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
856 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Info Not Found",
861 FREEGLUT_INTERNAL_ERROR_EXIT ( window->Parent == NULL,
862 "Game mode being invoked on a subwindow",
866 * Set the window creation flags appropriately to make the window
869 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
873 int worig = w, horig = h;
875 #if !defined(_WIN32_WCE)
876 if ( ( ! isSubWindow ) && ( ! window->IsMenu ) )
879 * Update the window dimensions, taking account of window
880 * decorations. "freeglut" is to create the window with the
881 * outside of its border at (x,y) and with dimensions (w,h).
883 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
884 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 +
885 GetSystemMetrics( SM_CYCAPTION );
887 #endif /* defined(_WIN32_WCE) */
894 /* setting State.Width/Height to call resize callback later */
897 if( ! window->IsMenu )
902 else /* fail safe - Windows can make a window of size (0, 0) */
903 w = h = 300; /* default window size */
904 window->State.Width = window->State.Height = -1;
908 window->State.Width = worig;
909 window->State.Height = horig;
913 * There's a small difference between creating the top, child and
916 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
918 if ( window->IsMenu )
921 exFlags |= WS_EX_TOOLWINDOW;
923 #if !defined(_WIN32_WCE)
924 else if( window->Parent == NULL )
925 flags |= WS_OVERLAPPEDWINDOW;
931 #if defined(_WIN32_WCE)
933 wchar_t* wstr = fghWstrFromStr(title);
935 window->Window.Handle = CreateWindow(
938 WS_VISIBLE | WS_POPUP,
948 SHFullScreen(window->Window.Handle, SHFS_HIDESTARTICON);
949 SHFullScreen(window->Window.Handle, SHFS_HIDESIPBUTTON);
950 SHFullScreen(window->Window.Handle, SHFS_HIDETASKBAR);
951 MoveWindow(window->Window.Handle, 0, 0, 240, 320, TRUE);
952 ShowWindow(window->Window.Handle, SW_SHOW);
953 UpdateWindow(window->Window.Handle);
956 window->Window.Handle = CreateWindowEx(
962 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
967 #endif /* defined(_WIN32_WCE) */
969 if( !( window->Window.Handle ) )
970 fgError( "Failed to create a window (%s)!", title );
972 /* Make a menu window always on top - fix Feature Request 947118 */
973 if( window->IsMenu || gameMode )
975 window->Window.Handle,
978 SWP_NOMOVE | SWP_NOSIZE
981 /* Hack to remove the caption (title bar) and/or border
982 * and all the system menu controls.
984 WindowStyle = GetWindowLong(window->Window.Handle, GWL_STYLE);
985 if ( fgState.DisplayMode & GLUT_CAPTIONLESS )
987 SetWindowLong ( window->Window.Handle, GWL_STYLE,
988 WindowStyle & ~(WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX));
990 else if ( fgState.DisplayMode & GLUT_BORDERLESS )
992 SetWindowLong ( window->Window.Handle, GWL_STYLE,
993 WindowStyle & ~(WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX));
995 /* SetWindowPos(window->Window.Handle, NULL, 0, 0, 0, 0,
996 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); */
999 #if defined(_WIN32_WCE)
1000 ShowWindow( window->Window.Handle, SW_SHOW );
1002 ShowWindow( window->Window.Handle,
1003 fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
1004 #endif /* defined(_WIN32_WCE) */
1006 UpdateWindow( window->Window.Handle );
1007 ShowCursor( TRUE ); /* XXX Old comments say "hide cursor"! */
1011 fgSetWindow( window );
1013 window->Window.DoubleBuffered =
1014 ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
1016 if ( ! window->Window.DoubleBuffered )
1018 glDrawBuffer ( GL_FRONT );
1019 glReadBuffer ( GL_FRONT );
1024 * Closes a window, destroying the frame and OpenGL context
1026 void fgCloseWindow( SFG_Window* window )
1028 #if TARGET_HOST_POSIX_X11
1030 glXDestroyContext( fgDisplay.Display, window->Window.Context );
1031 XFree( window->Window.FBConfig );
1032 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
1033 /* XFlush( fgDisplay.Display ); */ /* XXX Shouldn't need this */
1035 #elif TARGET_HOST_MS_WINDOWS
1037 /* Make sure we don't close a window with current context active */
1038 if( fgStructure.CurrentWindow == window )
1039 wglMakeCurrent( NULL, NULL );
1042 * Step through the list of windows. If the rendering context
1043 * is not being used by another window, then we delete it.
1049 for( iter = (SFG_Window *)fgStructure.Windows.First;
1051 iter = (SFG_Window *)iter->Node.Next )
1053 if( ( iter->Window.Context == window->Window.Context ) &&
1054 ( iter != window ) )
1059 wglDeleteContext( window->Window.Context );
1062 DestroyWindow( window->Window.Handle );
1067 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1070 * Creates a new top-level freeglut window
1072 int FGAPIENTRY glutCreateWindow( const char* title )
1074 /* XXX GLUT does not exit; it simply calls "glutInit" quietly if the
1075 * XXX application has not already done so. The "freeglut" community
1076 * XXX decided not to go this route (freeglut-developer e-mail from
1077 * XXX Steve Baker, 12/16/04, 4:22 PM CST, "Re: [Freeglut-developer]
1078 * XXX Desired 'freeglut' behaviour when there is no current window"
1080 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateWindow" );
1082 return fgCreateWindow( NULL, title, fgState.Position.Use,
1083 fgState.Position.X, fgState.Position.Y,
1084 fgState.Size.Use, fgState.Size.X, fgState.Size.Y,
1085 GL_FALSE, GL_FALSE )->ID;
1089 * This function creates a sub window.
1091 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
1094 SFG_Window* window = NULL;
1095 SFG_Window* parent = NULL;
1097 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateSubWindow" );
1098 parent = fgWindowByID( parentID );
1099 freeglut_return_val_if_fail( parent != NULL, 0 );
1102 x = parent->State.Width + x ;
1103 if ( w >= 0 ) x -= w ;
1106 if ( w < 0 ) w = parent->State.Width - x + w ;
1115 y = parent->State.Height + y ;
1116 if ( h >= 0 ) y -= h ;
1119 if ( h < 0 ) h = parent->State.Height - y + h ;
1126 window = fgCreateWindow( parent, "", GL_TRUE, x, y, GL_TRUE, w, h, GL_FALSE, GL_FALSE );
1133 * Destroys a window and all of its subwindows
1135 void FGAPIENTRY glutDestroyWindow( int windowID )
1138 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDestroyWindow" );
1139 window = fgWindowByID( windowID );
1140 freeglut_return_if_fail( window != NULL );
1142 fgExecutionState ExecState = fgState.ExecState;
1143 fgAddToWindowDestroyList( window );
1144 fgState.ExecState = ExecState;
1149 * This function selects the current window
1151 void FGAPIENTRY glutSetWindow( int ID )
1153 SFG_Window* window = NULL;
1155 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindow" );
1156 if( fgStructure.CurrentWindow != NULL )
1157 if( fgStructure.CurrentWindow->ID == ID )
1160 window = fgWindowByID( ID );
1161 if( window == NULL )
1163 fgWarning( "glutSetWindow(): window ID %d not found!", ID );
1167 fgSetWindow( window );
1171 * This function returns the ID number of the current window, 0 if none exists
1173 int FGAPIENTRY glutGetWindow( void )
1175 SFG_Window *win = fgStructure.CurrentWindow;
1177 * Since GLUT did not throw an error if this function was called without a prior call to
1178 * "glutInit", this function shouldn't do so here. Instead let us return a zero.
1179 * See Feature Request "[ 1307049 ] glutInit check".
1181 if ( ! fgState.Initialised )
1184 while ( win && win->IsMenu )
1186 return win ? win->ID : 0;
1190 * This function makes the current window visible
1192 void FGAPIENTRY glutShowWindow( void )
1194 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" );
1195 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" );
1197 #if TARGET_HOST_POSIX_X11
1199 XMapWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1200 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1202 #elif TARGET_HOST_MS_WINDOWS
1204 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_SHOW );
1208 fgStructure.CurrentWindow->State.Redisplay = GL_TRUE;
1212 * This function hides the current window
1214 void FGAPIENTRY glutHideWindow( void )
1216 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" );
1217 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" );
1219 #if TARGET_HOST_POSIX_X11
1221 if( fgStructure.CurrentWindow->Parent == NULL )
1222 XWithdrawWindow( fgDisplay.Display,
1223 fgStructure.CurrentWindow->Window.Handle,
1226 XUnmapWindow( fgDisplay.Display,
1227 fgStructure.CurrentWindow->Window.Handle );
1228 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1230 #elif TARGET_HOST_MS_WINDOWS
1232 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_HIDE );
1236 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
1240 * Iconify the current window (top-level windows only)
1242 void FGAPIENTRY glutIconifyWindow( void )
1244 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" );
1245 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" );
1247 fgStructure.CurrentWindow->State.Visible = GL_FALSE;
1248 #if TARGET_HOST_POSIX_X11
1250 XIconifyWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
1252 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1254 #elif TARGET_HOST_MS_WINDOWS
1256 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_MINIMIZE );
1260 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
1264 * Set the current window's title
1266 void FGAPIENTRY glutSetWindowTitle( const char* title )
1268 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowTitle" );
1269 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" );
1270 if( ! fgStructure.CurrentWindow->Parent )
1272 #if TARGET_HOST_POSIX_X11
1276 text.value = (unsigned char *) title;
1277 text.encoding = XA_STRING;
1279 text.nitems = strlen( title );
1283 fgStructure.CurrentWindow->Window.Handle,
1287 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1289 #elif TARGET_HOST_MS_WINDOWS
1292 wchar_t* wstr = fghWstrFromStr(title);
1293 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
1297 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
1305 * Set the current window's iconified title
1307 void FGAPIENTRY glutSetIconTitle( const char* title )
1309 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" );
1310 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" );
1312 if( ! fgStructure.CurrentWindow->Parent )
1314 #if TARGET_HOST_POSIX_X11
1318 text.value = (unsigned char *) title;
1319 text.encoding = XA_STRING;
1321 text.nitems = strlen( title );
1325 fgStructure.CurrentWindow->Window.Handle,
1329 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1331 #elif TARGET_HOST_MS_WINDOWS
1334 wchar_t* wstr = fghWstrFromStr(title);
1335 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
1339 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
1347 * Change the current window's size
1349 void FGAPIENTRY glutReshapeWindow( int width, int height )
1351 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" );
1352 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" );
1354 if (glutGet(GLUT_FULL_SCREEN))
1356 /* Leave full screen state before resizing. */
1357 glutFullScreenToggle();
1360 fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
1361 fgStructure.CurrentWindow->State.Width = width ;
1362 fgStructure.CurrentWindow->State.Height = height;
1366 * Change the current window's position
1368 void FGAPIENTRY glutPositionWindow( int x, int y )
1370 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" );
1371 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" );
1373 if (glutGet(GLUT_FULL_SCREEN))
1375 /* Leave full screen state before moving. */
1376 glutFullScreenToggle();
1379 #if TARGET_HOST_POSIX_X11
1381 XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
1383 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1385 #elif TARGET_HOST_MS_WINDOWS
1390 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
1391 GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
1393 fgStructure.CurrentWindow->Window.Handle,
1396 winRect.right - winRect.left,
1397 winRect.bottom - winRect.top,
1406 * Lowers the current window (by Z order change)
1408 void FGAPIENTRY glutPushWindow( void )
1410 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPushWindow" );
1411 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPushWindow" );
1413 #if TARGET_HOST_POSIX_X11
1415 XLowerWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1417 #elif TARGET_HOST_MS_WINDOWS
1420 fgStructure.CurrentWindow->Window.Handle,
1423 SWP_NOSIZE | SWP_NOMOVE
1430 * Raises the current window (by Z order change)
1432 void FGAPIENTRY glutPopWindow( void )
1434 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" );
1435 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" );
1437 #if TARGET_HOST_POSIX_X11
1439 XRaiseWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1441 #elif TARGET_HOST_MS_WINDOWS
1444 fgStructure.CurrentWindow->Window.Handle,
1447 SWP_NOSIZE | SWP_NOMOVE
1454 * Resize the current window so that it fits the whole screen
1456 void FGAPIENTRY glutFullScreen( void )
1458 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" );
1459 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" );
1461 if (glutGet(GLUT_FULL_SCREEN))
1463 /* Leave full screen state before resizing. */
1464 glutFullScreenToggle();
1468 #if TARGET_HOST_POSIX_X11
1470 Status status; /* Returned by XGetWindowAttributes(), not checked. */
1471 XWindowAttributes attributes;
1473 status = XGetWindowAttributes(fgDisplay.Display,
1474 fgStructure.CurrentWindow->Window.Handle,
1477 * The "x" and "y" members of "attributes" are the window's coordinates
1478 * relative to its parent, i.e. to the decoration window.
1480 XMoveResizeWindow(fgDisplay.Display,
1481 fgStructure.CurrentWindow->Window.Handle,
1484 fgDisplay.ScreenWidth,
1485 fgDisplay.ScreenHeight);
1487 #elif TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: what about WinCE */
1490 /* For fullscreen mode, force the top-left corner to 0,0
1491 * and adjust the window rectangle so that the client area
1492 * covers the whole screen.
1497 rect.right = fgDisplay.ScreenWidth;
1498 rect.bottom = fgDisplay.ScreenHeight;
1500 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
1501 WS_CLIPCHILDREN, FALSE );
1504 * SWP_NOACTIVATE Do not activate the window
1505 * SWP_NOOWNERZORDER Do not change position in z-order
1506 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
1507 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
1510 SetWindowPos( fgStructure.CurrentWindow->Window.Handle,
1514 rect.right - rect.left,
1515 rect.bottom - rect.top,
1516 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
1524 * Toggle the window's full screen state.
1526 void FGAPIENTRY glutFullScreenToggle( void )
1528 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreenToggle" );
1529 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreenToggle" );
1532 #if TARGET_HOST_POSIX_X11
1534 if (fgDisplay.StateFullScreen != None)
1540 xevent.type = ClientMessage;
1541 xevent.xclient.type = ClientMessage;
1542 xevent.xclient.serial = 0;
1543 xevent.xclient.send_event = True;
1544 xevent.xclient.display = fgDisplay.Display;
1545 xevent.xclient.window = fgStructure.CurrentWindow->Window.Handle;
1546 xevent.xclient.message_type = fgDisplay.State;
1547 xevent.xclient.format = 32;
1548 xevent.xclient.data.l[0] = 2; /* _NET_WM_STATE_TOGGLE */
1549 xevent.xclient.data.l[1] = fgDisplay.StateFullScreen;
1550 xevent.xclient.data.l[2] = 0;
1551 xevent.xclient.data.l[3] = 0;
1552 xevent.xclient.data.l[4] = 0;
1554 /*** Don't really understand how event masks work... ***/
1555 event_mask = SubstructureRedirectMask | SubstructureNotifyMask;
1557 status = XSendEvent(fgDisplay.Display,
1558 fgDisplay.RootWindow,
1562 FREEGLUT_INTERNAL_ERROR_EXIT(status != 0,
1563 "XSendEvent failed",
1564 "glutFullScreenToggle");
1570 * If the window manager is not Net WM compliant, fall back to legacy
1579 * A.Donev: Set and retrieve the window's user data
1581 void* FGAPIENTRY glutGetWindowData( void )
1583 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindowData" );
1584 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutGetWindowData" );
1585 return fgStructure.CurrentWindow->UserData;
1588 void FGAPIENTRY glutSetWindowData(void* data)
1590 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowData" );
1591 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowData" );
1592 fgStructure.CurrentWindow->UserData = data;
1595 /*** END OF FILE ***/