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 #define FREEGLUT_BUILDING_LIB
29 #include <GL/freeglut.h>
30 #include "freeglut_internal.h"
32 #if TARGET_HOST_POSIX_X11
33 #include <limits.h> /* LONG_MAX */
36 #if defined(_WIN32_WCE)
37 # include <Aygshell.h>
38 # ifdef FREEGLUT_LIB_PRAGMAS
39 # pragma comment( lib, "Aygshell.lib" )
42 static wchar_t* fghWstrFromStr(const char* str)
44 int i,len=strlen(str);
45 wchar_t* wstr = (wchar_t*)malloc(2*len+2);
52 #endif /* defined(_WIN32_WCE) */
55 * TODO BEFORE THE STABLE RELEASE:
57 * fgChooseFBConfig() -- OK, but what about glutInitDisplayString()?
58 * fgSetupPixelFormat -- ignores the display mode settings
59 * fgOpenWindow() -- check the Win32 version, -iconic handling!
60 * fgCloseWindow() -- check the Win32 version
61 * glutCreateWindow() -- Check when default position and size is {-1,-1}
62 * glutCreateSubWindow() -- Check when default position and size is {-1,-1}
63 * glutDestroyWindow() -- check the Win32 version
64 * glutSetWindow() -- check the Win32 version
65 * glutGetWindow() -- OK
66 * glutSetWindowTitle() -- check the Win32 version
67 * glutSetIconTitle() -- check the Win32 version
68 * glutShowWindow() -- check the Win32 version
69 * glutHideWindow() -- check the Win32 version
70 * glutIconifyWindow() -- check the Win32 version
71 * glutReshapeWindow() -- check the Win32 version
72 * glutPositionWindow() -- check the Win32 version
73 * glutPushWindow() -- check the Win32 version
74 * glutPopWindow() -- check the Win32 version
77 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
80 * Chooses a visual basing on the current display mode settings
82 #if TARGET_HOST_POSIX_X11
84 GLXFBConfig* fgChooseFBConfig( void )
86 GLboolean wantIndexedMode = GL_FALSE;
90 /* First we have to process the display mode settings... */
92 * XXX Why is there a semi-colon in this #define? The code
93 * XXX that uses the macro seems to always add more semicolons...
95 #define ATTRIB(a) attributes[where++]=a;
96 #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);}
98 if( fgState.DisplayMode & GLUT_INDEX )
100 ATTRIB_VAL( GLX_BUFFER_SIZE, 8 );
101 /* Buffer size is selected later. */
103 ATTRIB_VAL( GLX_RENDER_TYPE, GLX_COLOR_INDEX_BIT );
104 wantIndexedMode = GL_TRUE;
108 ATTRIB_VAL( GLX_RED_SIZE, 1 );
109 ATTRIB_VAL( GLX_GREEN_SIZE, 1 );
110 ATTRIB_VAL( GLX_BLUE_SIZE, 1 );
111 if( fgState.DisplayMode & GLUT_ALPHA )
112 ATTRIB_VAL( GLX_ALPHA_SIZE, 1 );
115 if( fgState.DisplayMode & GLUT_DOUBLE )
116 ATTRIB_VAL( GLX_DOUBLEBUFFER, True );
118 if( fgState.DisplayMode & GLUT_STEREO )
119 ATTRIB_VAL( GLX_STEREO, True );
121 if( fgState.DisplayMode & GLUT_DEPTH )
122 ATTRIB_VAL( GLX_DEPTH_SIZE, 1 );
124 if( fgState.DisplayMode & GLUT_STENCIL )
125 ATTRIB_VAL( GLX_STENCIL_SIZE, 1 );
127 if( fgState.DisplayMode & GLUT_ACCUM )
129 ATTRIB_VAL( GLX_ACCUM_RED_SIZE, 1 );
130 ATTRIB_VAL( GLX_ACCUM_GREEN_SIZE, 1 );
131 ATTRIB_VAL( GLX_ACCUM_BLUE_SIZE, 1 );
132 if( fgState.DisplayMode & GLUT_ALPHA )
133 ATTRIB_VAL( GLX_ACCUM_ALPHA_SIZE, 1 );
136 if( fgState.DisplayMode & GLUT_AUX4 )
138 ATTRIB_VAL(GLX_AUX_BUFFERS, 4);
140 else if( fgState.DisplayMode & GLUT_AUX3 )
142 ATTRIB_VAL(GLX_AUX_BUFFERS, 3);
144 else if( fgState.DisplayMode & GLUT_AUX2 )
146 ATTRIB_VAL(GLX_AUX_BUFFERS, 2);
148 else if( fgState.DisplayMode & GLUT_AUX1 ) /* NOTE: Same as GLUT_AUX! */
150 ATTRIB_VAL(GLX_AUX_BUFFERS, fgState.AuxiliaryBufferNumber);
153 if (fgState.DisplayMode & GLUT_MULTISAMPLE)
155 ATTRIB_VAL(GLX_SAMPLE_BUFFERS, 1)
156 ATTRIB_VAL(GLX_SAMPLES, fgState.SampleNumber)
159 /* Push a null at the end of the list */
163 GLXFBConfig * fbconfigArray; /* Array of FBConfigs */
164 GLXFBConfig * fbconfig; /* The FBConfig we want */
165 int fbconfigArraySize; /* Number of FBConfigs in the array */
168 /* Get all FBConfigs that match "attributes". */
169 fbconfigArray = glXChooseFBConfig( fgDisplay.Display,
172 &fbconfigArraySize );
174 if (fbconfigArray != NULL)
176 int result; /* Returned by glXGetFBConfigAttrib, not checked. */
179 if( wantIndexedMode )
182 * In index mode, we want the largest buffer size, i.e. visual
183 * depth. Here, FBConfigs are sorted by increasing buffer size
184 * first, so FBConfigs with the largest size come last.
187 int bufferSizeMin, bufferSizeMax;
189 /* Get bufferSizeMin. */
191 glXGetFBConfigAttrib( fgDisplay.Display,
195 /* Get bufferSizeMax. */
197 glXGetFBConfigAttrib( fgDisplay.Display,
198 fbconfigArray[fbconfigArraySize - 1],
202 if (bufferSizeMax > bufferSizeMin)
205 * Free and reallocate fbconfigArray, keeping only FBConfigs
206 * with the largest buffer size.
208 XFree(fbconfigArray);
210 /* Add buffer size token at the end of the list. */
212 ATTRIB_VAL( GLX_BUFFER_SIZE, bufferSizeMax );
215 fbconfigArray = glXChooseFBConfig( fgDisplay.Display,
218 &fbconfigArraySize );
223 * We now have an array of FBConfigs, the first one being the "best"
224 * one. So we should return only this FBConfig:
228 * - pick the XID of the FBConfig we want
229 * result = glXGetFBConfigAttrib( fgDisplay.Display,
235 * XFree(fbconfigArray);
237 * - reset "attributes" with the XID
239 * ATTRIB_VAL( GLX_FBCONFIG_ID, fbconfigXID );
242 * - get our FBConfig only
243 * fbconfig = glXChooseFBConfig( fgDisplay.Display,
246 * &fbconfigArraySize );
248 * However, for some configurations (for instance multisampling with
249 * Mesa 6.5.2 and ATI drivers), this does not work:
250 * glXChooseFBConfig returns NULL, whereas fbconfigXID is a valid
251 * XID. Further investigation is needed.
253 * So, for now, we return the whole array of FBConfigs. This should
254 * not produce any side effects elsewhere.
256 fbconfig = fbconfigArray;
266 #endif /* TARGET_HOST_POSIX_X11 */
269 * Setup the pixel format for a Win32 window
271 #if TARGET_HOST_MS_WINDOWS
272 /* The following include file is available from SGI but is not standard:
273 * #include <GL/wglext.h>
274 * So we copy the necessary parts out of it.
275 * XXX: should local definitions for extensions be put in a separate include file?
277 typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
279 typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
281 #define WGL_DRAW_TO_WINDOW_ARB 0x2001
282 #define WGL_ACCELERATION_ARB 0x2003
283 #define WGL_SUPPORT_OPENGL_ARB 0x2010
284 #define WGL_DOUBLE_BUFFER_ARB 0x2011
285 #define WGL_COLOR_BITS_ARB 0x2014
286 #define WGL_ALPHA_BITS_ARB 0x201B
287 #define WGL_DEPTH_BITS_ARB 0x2022
288 #define WGL_STENCIL_BITS_ARB 0x2023
289 #define WGL_FULL_ACCELERATION_ARB 0x2027
291 #define WGL_SAMPLE_BUFFERS_ARB 0x2041
292 #define WGL_SAMPLES_ARB 0x2042
295 #ifndef WGL_ARB_create_context
296 #define WGL_ARB_create_context 1
297 #ifdef WGL_WGLEXT_PROTOTYPES
298 extern HGLRC WINAPI wglCreateContextAttribsARB (HDC, HGLRC, const int *);
299 #endif /* WGL_WGLEXT_PROTOTYPES */
300 typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList);
302 #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
303 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
304 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
305 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
306 #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
307 #define WGL_CONTEXT_FLAGS_ARB 0x2094
308 #define ERROR_INVALID_VERSION_ARB 0x2095
312 void fgNewWGLCreateContext( SFG_Window* window )
314 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetEntensionsStringARB;
317 PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
318 const char * pWglExtString;
320 /* If nothing fancy has been required, leave the context as it is */
321 if ( fgState.MajorVersion == 1 && fgState.MinorVersion == 0 && fgState.ContextFlags == 0 )
326 wglMakeCurrent( window->Window.Device,
327 window->Window.Context );
329 wglGetEntensionsStringARB=(PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
330 if ( wglGetEntensionsStringARB == NULL )
335 pWglExtString=wglGetEntensionsStringARB(window->Window.Device);
336 if (( pWglExtString == NULL ) || ( strstr(pWglExtString, "WGL_ARB_create_context") == NULL ))
341 /* new context creation */
342 attribs[0] = WGL_CONTEXT_MAJOR_VERSION_ARB;
343 attribs[1] = fgState.MajorVersion;
344 attribs[2] = WGL_CONTEXT_MINOR_VERSION_ARB;
345 attribs[3] = fgState.MinorVersion;
346 attribs[4] = WGL_CONTEXT_FLAGS_ARB;
347 attribs[5] = ((fgState.ContextFlags & GLUT_DEBUG) ? WGL_CONTEXT_DEBUG_BIT_ARB : 0) |
348 ((fgState.ContextFlags & GLUT_FORWARD_COMPATIBLE) ? WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB : 0);
351 wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress( "wglCreateContextAttribsARB" );
352 if ( wglCreateContextAttribsARB == NULL )
354 fgError( "wglCreateContextAttribsARB not found" );
357 context = wglCreateContextAttribsARB( window->Window.Device, 0, attribs );
358 if ( context == NULL )
360 fgError( "Unable to create OpenGL %d.%d context (flags %x)",
361 fgState.MajorVersion, fgState.MinorVersion, fgState.ContextFlags );
364 wglMakeCurrent( NULL, NULL );
365 wglDeleteContext( window->Window.Context );
366 window->Window.Context = context;
370 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
371 unsigned char layer_type )
373 #if defined(_WIN32_WCE)
376 PIXELFORMATDESCRIPTOR* ppfd, pfd;
377 int flags, pixelformat;
379 freeglut_return_val_if_fail( window != NULL, 0 );
380 flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
381 if( fgState.DisplayMode & GLUT_DOUBLE )
382 flags |= PFD_DOUBLEBUFFER;
384 if( fgState.DisplayMode & GLUT_STEREO )
387 #if defined(_MSC_VER)
388 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
391 /* Specify which pixel format do we opt for... */
392 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
396 if( fgState.DisplayMode & GLUT_INDEX )
398 pfd.iPixelType = PFD_TYPE_COLORINDEX;
406 pfd.iPixelType = PFD_TYPE_RGBA;
410 if ( fgState.DisplayMode & GLUT_ALPHA )
422 pfd.cAccumRedBits = 0;
423 pfd.cAccumGreenBits = 0;
424 pfd.cAccumBlueBits = 0;
425 pfd.cAccumAlphaBits = 0;
428 pfd.cStencilBits = 0;
431 pfd.cStencilBits = 8;
433 if( fgState.DisplayMode & GLUT_AUX4 )
435 else if( fgState.DisplayMode & GLUT_AUX3 )
437 else if( fgState.DisplayMode & GLUT_AUX2 )
439 else if( fgState.DisplayMode & GLUT_AUX1 ) /* NOTE: Same as GLUT_AUX! */
440 pfd.cAuxBuffers = fgState.AuxiliaryBufferNumber;
444 pfd.iLayerType = layer_type;
447 pfd.dwVisibleMask = 0;
448 pfd.dwDamageMask = 0;
450 pfd.cColorBits = (BYTE) GetDeviceCaps( window->Window.Device, BITSPIXEL );
453 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
455 /* windows hack for multismapling */
456 if (fgState.DisplayMode&GLUT_MULTISAMPLE)
458 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetEntensionsStringARB=NULL;
459 HGLRC rc, rc_before=wglGetCurrentContext();
461 HDC hDC, hDC_before=wglGetCurrentDC();
464 /* create a dummy window */
465 ZeroMemory(&wndCls, sizeof(wndCls));
466 wndCls.lpfnWndProc = DefWindowProc;
467 wndCls.hInstance = fgDisplay.Instance;
468 wndCls.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
469 wndCls.lpszClassName = _T("FREEGLUT_dummy");
470 RegisterClass( &wndCls );
472 hWnd=CreateWindow(_T("FREEGLUT_dummy"), _T(""), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW , 0,0,0,0, 0, 0, fgDisplay.Instance, 0 );
474 SetPixelFormat( hDC, pixelformat, ppfd );
476 rc = wglCreateContext( hDC );
477 wglMakeCurrent(hDC, rc);
479 wglGetEntensionsStringARB=(PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
480 if (wglGetEntensionsStringARB)
482 const char * pWglExtString=wglGetEntensionsStringARB(hDC);
485 if (strstr(pWglExtString, "WGL_ARB_multisample"))
487 int pAttributes[100];
491 float fAttributes[] = {0,0};
493 PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARBProc=NULL;
495 wglChoosePixelFormatARBProc=(PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
496 if ( wglChoosePixelFormatARBProc )
498 pAttributes[iCounter++]=WGL_DRAW_TO_WINDOW_ARB; pAttributes[iCounter++]=GL_TRUE;
499 pAttributes[iCounter++]=WGL_SUPPORT_OPENGL_ARB; pAttributes[iCounter++]=GL_TRUE;
500 pAttributes[iCounter++]=WGL_ACCELERATION_ARB; pAttributes[iCounter++]=WGL_FULL_ACCELERATION_ARB;
502 pAttributes[iCounter++]=WGL_COLOR_BITS_ARB; pAttributes[iCounter++]=pfd.cColorBits ;
503 pAttributes[iCounter++]=WGL_ALPHA_BITS_ARB; pAttributes[iCounter++]=pfd.cAlphaBits;
504 pAttributes[iCounter++]=WGL_DEPTH_BITS_ARB; pAttributes[iCounter++]=pfd.cDepthBits;
505 pAttributes[iCounter++]=WGL_STENCIL_BITS_ARB; pAttributes[iCounter++]=pfd.cStencilBits;
507 pAttributes[iCounter++]=WGL_DOUBLE_BUFFER_ARB; pAttributes[iCounter++]=(fgState.DisplayMode & GLUT_DOUBLE)!=0;
508 pAttributes[iCounter++]=WGL_SAMPLE_BUFFERS_ARB; pAttributes[iCounter++]=GL_TRUE;
509 pAttributes[iCounter++]=WGL_SAMPLES_ARB; pAttributes[iCounter++]=fgState.SampleNumber;
510 pAttributes[iCounter++]=0; pAttributes[iCounter++]=0; /* terminator */
512 bValid = wglChoosePixelFormatARBProc(window->Window.Device,pAttributes,fAttributes,1,&iPixelFormat,&numFormats);
514 if (bValid && numFormats>0)
515 pixelformat=iPixelFormat;
518 wglMakeCurrent( hDC_before, rc_before);
519 wglDeleteContext(rc);
520 ReleaseDC(hWnd, hDC);
522 UnregisterClass(_T("FREEGLUT_dummy"), fgDisplay.Instance);
527 if( pixelformat == 0 )
532 return SetPixelFormat( window->Window.Device, pixelformat, ppfd );
533 #endif /* defined(_WIN32_WCE) */
535 #endif /* TARGET_HOST_MS_WINDOWS */
538 * Sets the OpenGL context and the fgStructure "Current Window" pointer to
539 * the window structure passed in.
541 void fgSetWindow ( SFG_Window *window )
543 #if TARGET_HOST_POSIX_X11
545 glXMakeContextCurrent(
547 window->Window.Handle,
548 window->Window.Handle,
549 window->Window.Context
551 #elif TARGET_HOST_MS_WINDOWS
552 if( fgStructure.CurrentWindow )
553 ReleaseDC( fgStructure.CurrentWindow->Window.Handle,
554 fgStructure.CurrentWindow->Window.Device );
558 window->Window.Device = GetDC( window->Window.Handle );
560 window->Window.Device,
561 window->Window.Context
565 fgStructure.CurrentWindow = window;
570 #if TARGET_HOST_POSIX_X11
572 #ifndef GLX_CONTEXT_MAJOR_VERSION_ARB
573 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
576 #ifndef GLX_CONTEXT_MINOR_VERSION_ARB
577 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
580 #ifndef GLX_CONTEXT_FLAGS_ARB
581 #define GLX_CONTEXT_FLAGS_ARB 0x2094
584 #ifndef GLX_CONTEXT_DEBUG_BIT_ARB
585 #define GLX_CONTEXT_DEBUG_BIT_ARB 0x0001
588 #ifndef GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
589 #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
592 typedef GLXContext (*CreateContextAttribsProc)(Display *dpy, GLXFBConfig config,
593 GLXContext share_list, Bool direct,
594 const int *attrib_list);
596 static GLXContext fghCreateNewContext( SFG_Window* window )
598 /* for color model calculation */
599 int menu = ( window->IsMenu && !fgStructure.MenuContext );
600 int index_mode = ( fgState.DisplayMode & GLUT_INDEX );
602 /* "classic" context creation */
603 Display *dpy = fgDisplay.Display;
604 GLXFBConfig config = *(window->Window.FBConfig);
605 int render_type = ( !menu && index_mode ) ? GLX_COLOR_INDEX_TYPE : GLX_RGBA_TYPE;
606 GLXContext share_list = NULL;
607 Bool direct = ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT );
610 /* new context creation */
612 CreateContextAttribsProc createContextAttribs;
614 /* If nothing fancy has been required, simply use the old context creation GLX API entry */
615 if ( fgState.MajorVersion == 1 && fgState.MinorVersion == 0 && fgState.ContextFlags == 0)
617 context = glXCreateNewContext( dpy, config, render_type, share_list, direct );
618 if ( context == NULL ) {
619 fgError( "could not create new OpenGL context" );
624 /* color index mode is not available anymore with OpenGL 3.0 */
625 if ( render_type == GLX_COLOR_INDEX_TYPE ) {
626 fgWarning( "color index mode is deprecated, using RGBA mode" );
629 attribs[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
630 attribs[1] = fgState.MajorVersion;
631 attribs[2] = GLX_CONTEXT_MINOR_VERSION_ARB;
632 attribs[3] = fgState.MinorVersion;
633 attribs[4] = GLX_CONTEXT_FLAGS_ARB;
634 attribs[5] = ((fgState.ContextFlags & GLUT_DEBUG) ? GLX_CONTEXT_DEBUG_BIT_ARB : 0) |
635 ((fgState.ContextFlags & GLUT_FORWARD_COMPATIBLE) ? GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB : 0);
638 createContextAttribs = (CreateContextAttribsProc) fghGetProcAddress( "glXCreateContextAttribsARB" );
639 if ( createContextAttribs == NULL ) {
640 fgError( "glXCreateContextAttribsARB not found" );
643 context = createContextAttribs( dpy, config, share_list, direct, attribs );
644 if ( context == NULL ) {
645 fgError( "could not create new OpenGL %d.%d context (flags %x)",
646 fgState.MajorVersion, fgState.MinorVersion, fgState.ContextFlags );
654 * Opens a window. Requires a SFG_Window object created and attached
655 * to the freeglut structure. OpenGL context is created here.
657 void fgOpenWindow( SFG_Window* window, const char* title,
658 GLboolean positionUse, int x, int y,
659 GLboolean sizeUse, int w, int h,
660 GLboolean gameMode, GLboolean isSubWindow )
662 #if TARGET_HOST_POSIX_X11
663 XVisualInfo * visualInfo;
664 XSetWindowAttributes winAttr;
665 XTextProperty textProperty;
666 XSizeHints sizeHints;
669 unsigned int current_DisplayMode = fgState.DisplayMode ;
671 /* Save the display mode if we are creating a menu window */
672 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
673 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ;
675 window->Window.FBConfig = fgChooseFBConfig( );
677 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
678 fgState.DisplayMode = current_DisplayMode ;
680 if( ! window->Window.FBConfig )
683 * The "fgChooseFBConfig" returned a null meaning that the visual
684 * context is not available.
685 * Try a couple of variations to see if they will work.
687 if( !( fgState.DisplayMode & GLUT_DOUBLE ) )
689 fgState.DisplayMode |= GLUT_DOUBLE ;
690 window->Window.FBConfig = fgChooseFBConfig( );
691 fgState.DisplayMode &= ~GLUT_DOUBLE;
694 if( fgState.DisplayMode & GLUT_MULTISAMPLE )
696 fgState.DisplayMode &= ~GLUT_MULTISAMPLE ;
697 window->Window.FBConfig = fgChooseFBConfig( );
698 fgState.DisplayMode |= GLUT_MULTISAMPLE;
702 FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.FBConfig != NULL,
703 "FBConfig with necessary capabilities not found", "fgOpenWindow" );
705 /* Get the X visual. */
706 visualInfo = glXGetVisualFromFBConfig( fgDisplay.Display,
707 *(window->Window.FBConfig) );
710 * XXX HINT: the masks should be updated when adding/removing callbacks.
711 * XXX This might speed up message processing. Is that true?
713 * XXX A: Not appreciably, but it WILL make it easier to debug.
714 * XXX Try tracing old GLUT and try tracing freeglut. Old GLUT
715 * XXX turns off events that it doesn't need and is a whole lot
716 * XXX more pleasant to trace. (Think mouse-motion! Tons of
717 * XXX ``bonus'' GUI events stream in.)
720 StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
721 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
722 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
723 PointerMotionMask | ButtonMotionMask;
724 winAttr.background_pixmap = None;
725 winAttr.background_pixel = 0;
726 winAttr.border_pixel = 0;
728 winAttr.colormap = XCreateColormap(
729 fgDisplay.Display, fgDisplay.RootWindow,
730 visualInfo->visual, AllocNone
733 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
735 if( window->IsMenu || ( gameMode == GL_TRUE ) )
737 winAttr.override_redirect = True;
738 mask |= CWOverrideRedirect;
742 x = y = -1; /* default window position */
744 w = h = 300; /* default window size */
746 window->Window.Handle = XCreateWindow(
748 window->Parent == NULL ? fgDisplay.RootWindow :
749 window->Parent->Window.Handle,
751 visualInfo->depth, InputOutput,
752 visualInfo->visual, mask,
757 * The GLX context creation, possibly trying the direct context rendering
758 * or else use the current context if the user has so specified
764 * If there isn't already an OpenGL rendering context for menu
767 if( !fgStructure.MenuContext )
769 fgStructure.MenuContext =
770 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
771 fgStructure.MenuContext->MContext = fghCreateNewContext( window );
774 /* window->Window.Context = fgStructure.MenuContext->MContext; */
775 window->Window.Context = fghCreateNewContext( window );
777 else if( fgState.UseCurrentContext )
779 window->Window.Context = glXGetCurrentContext( );
781 if( ! window->Window.Context )
782 window->Window.Context = fghCreateNewContext( window );
785 window->Window.Context = fghCreateNewContext( window );
787 #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ )
788 if( !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
790 if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
791 fgError( "Unable to force direct context rendering for window '%s'",
797 * XXX Assume the new window is visible by default
798 * XXX Is this a safe assumption?
800 window->State.Visible = GL_TRUE;
804 sizeHints.flags |= USPosition;
806 sizeHints.flags |= USSize;
809 * Fill in the size hints values now (the x, y, width and height
810 * settings are obsolete, are there any more WMs that support them?)
811 * Unless the X servers actually stop supporting these, we should
812 * continue to fill them in. It is *not* our place to tell the user
813 * that they should replace a window manager that they like, and which
814 * works, just because *we* think that it's not "modern" enough.
819 sizeHints.height = h;
821 wmHints.flags = StateHint;
822 wmHints.initial_state = fgState.ForceIconic ? IconicState : NormalState;
823 /* Prepare the window and iconified window names... */
824 XStringListToTextProperty( (char **) &title, 1, &textProperty );
828 window->Window.Handle,
837 XFree( textProperty.value );
839 XSetWMProtocols( fgDisplay.Display, window->Window.Handle,
840 &fgDisplay.DeleteWindow, 1 );
842 glXMakeContextCurrent(
844 window->Window.Handle,
845 window->Window.Handle,
846 window->Window.Context
849 XMapWindow( fgDisplay.Display, window->Window.Handle );
853 #elif TARGET_HOST_MS_WINDOWS
861 /* Grab the window class we have registered on glutInit(): */
862 atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
863 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Info Not Found",
868 FREEGLUT_INTERNAL_ERROR_EXIT ( window->Parent == NULL,
869 "Game mode being invoked on a subwindow",
873 * Set the window creation flags appropriately to make the window
876 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
880 int worig = w, horig = h;
882 #if !defined(_WIN32_WCE)
883 if ( ( ! isSubWindow ) && ( ! window->IsMenu ) )
886 * Update the window dimensions, taking account of window
887 * decorations. "freeglut" is to create the window with the
888 * outside of its border at (x,y) and with dimensions (w,h).
890 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
891 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 +
892 GetSystemMetrics( SM_CYCAPTION );
894 #endif /* defined(_WIN32_WCE) */
901 /* setting State.Width/Height to call resize callback later */
904 if( ! window->IsMenu )
909 else /* fail safe - Windows can make a window of size (0, 0) */
910 w = h = 300; /* default window size */
911 window->State.Width = window->State.Height = -1;
915 window->State.Width = worig;
916 window->State.Height = horig;
920 * There's a small difference between creating the top, child and
923 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
925 if ( window->IsMenu )
928 exFlags |= WS_EX_TOOLWINDOW;
930 #if !defined(_WIN32_WCE)
931 else if( window->Parent == NULL )
932 flags |= WS_OVERLAPPEDWINDOW;
938 #if defined(_WIN32_WCE)
940 wchar_t* wstr = fghWstrFromStr(title);
942 window->Window.Handle = CreateWindow(
945 WS_VISIBLE | WS_POPUP,
955 SHFullScreen(window->Window.Handle, SHFS_HIDESTARTICON);
956 SHFullScreen(window->Window.Handle, SHFS_HIDESIPBUTTON);
957 SHFullScreen(window->Window.Handle, SHFS_HIDETASKBAR);
958 MoveWindow(window->Window.Handle, 0, 0, 240, 320, TRUE);
959 ShowWindow(window->Window.Handle, SW_SHOW);
960 UpdateWindow(window->Window.Handle);
963 window->Window.Handle = CreateWindowEx(
969 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
974 #endif /* defined(_WIN32_WCE) */
976 if( !( window->Window.Handle ) )
977 fgError( "Failed to create a window (%s)!", title );
979 /* Make a menu window always on top - fix Feature Request 947118 */
980 if( window->IsMenu || gameMode )
982 window->Window.Handle,
985 SWP_NOMOVE | SWP_NOSIZE
988 /* Hack to remove the caption (title bar) and/or border
989 * and all the system menu controls.
991 WindowStyle = GetWindowLong(window->Window.Handle, GWL_STYLE);
992 if ( fgState.DisplayMode & GLUT_CAPTIONLESS )
994 SetWindowLong ( window->Window.Handle, GWL_STYLE,
995 WindowStyle & ~(WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX));
997 else if ( fgState.DisplayMode & GLUT_BORDERLESS )
999 SetWindowLong ( window->Window.Handle, GWL_STYLE,
1000 WindowStyle & ~(WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX));
1002 /* SetWindowPos(window->Window.Handle, NULL, 0, 0, 0, 0,
1003 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); */
1006 #if defined(_WIN32_WCE)
1007 ShowWindow( window->Window.Handle, SW_SHOW );
1009 ShowWindow( window->Window.Handle,
1010 fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
1011 #endif /* defined(_WIN32_WCE) */
1013 UpdateWindow( window->Window.Handle );
1014 ShowCursor( TRUE ); /* XXX Old comments say "hide cursor"! */
1018 fgSetWindow( window );
1020 window->Window.DoubleBuffered =
1021 ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
1023 if ( ! window->Window.DoubleBuffered )
1025 glDrawBuffer ( GL_FRONT );
1026 glReadBuffer ( GL_FRONT );
1031 * Closes a window, destroying the frame and OpenGL context
1033 void fgCloseWindow( SFG_Window* window )
1035 #if TARGET_HOST_POSIX_X11
1037 if( window->Window.Context )
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;
1096 #if TARGET_HOST_MS_WINDOWS
1097 int FGAPIENTRY __glutCreateWindowWithExit( const char *title, void (__cdecl *exit_function)(int) )
1099 __glutExitFunc = exit_function;
1100 return glutCreateWindow( title );
1105 * This function creates a sub window.
1107 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
1110 SFG_Window* window = NULL;
1111 SFG_Window* parent = NULL;
1113 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateSubWindow" );
1114 parent = fgWindowByID( parentID );
1115 freeglut_return_val_if_fail( parent != NULL, 0 );
1118 x = parent->State.Width + x ;
1119 if ( w >= 0 ) x -= w ;
1122 if ( w < 0 ) w = parent->State.Width - x + w ;
1131 y = parent->State.Height + y ;
1132 if ( h >= 0 ) y -= h ;
1135 if ( h < 0 ) h = parent->State.Height - y + h ;
1142 window = fgCreateWindow( parent, "", GL_TRUE, x, y, GL_TRUE, w, h, GL_FALSE, GL_FALSE );
1149 * Destroys a window and all of its subwindows
1151 void FGAPIENTRY glutDestroyWindow( int windowID )
1154 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDestroyWindow" );
1155 window = fgWindowByID( windowID );
1156 freeglut_return_if_fail( window != NULL );
1158 fgExecutionState ExecState = fgState.ExecState;
1159 fgAddToWindowDestroyList( window );
1160 fgState.ExecState = ExecState;
1165 * This function selects the current window
1167 void FGAPIENTRY glutSetWindow( int ID )
1169 SFG_Window* window = NULL;
1171 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindow" );
1172 if( fgStructure.CurrentWindow != NULL )
1173 if( fgStructure.CurrentWindow->ID == ID )
1176 window = fgWindowByID( ID );
1177 if( window == NULL )
1179 fgWarning( "glutSetWindow(): window ID %d not found!", ID );
1183 fgSetWindow( window );
1187 * This function returns the ID number of the current window, 0 if none exists
1189 int FGAPIENTRY glutGetWindow( void )
1191 SFG_Window *win = fgStructure.CurrentWindow;
1193 * Since GLUT did not throw an error if this function was called without a prior call to
1194 * "glutInit", this function shouldn't do so here. Instead let us return a zero.
1195 * See Feature Request "[ 1307049 ] glutInit check".
1197 if ( ! fgState.Initialised )
1200 while ( win && win->IsMenu )
1202 return win ? win->ID : 0;
1206 * This function makes the current window visible
1208 void FGAPIENTRY glutShowWindow( void )
1210 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" );
1211 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" );
1213 #if TARGET_HOST_POSIX_X11
1215 XMapWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1216 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1218 #elif TARGET_HOST_MS_WINDOWS
1220 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_SHOW );
1224 fgStructure.CurrentWindow->State.Redisplay = GL_TRUE;
1228 * This function hides the current window
1230 void FGAPIENTRY glutHideWindow( void )
1232 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" );
1233 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" );
1235 #if TARGET_HOST_POSIX_X11
1237 if( fgStructure.CurrentWindow->Parent == NULL )
1238 XWithdrawWindow( fgDisplay.Display,
1239 fgStructure.CurrentWindow->Window.Handle,
1242 XUnmapWindow( fgDisplay.Display,
1243 fgStructure.CurrentWindow->Window.Handle );
1244 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1246 #elif TARGET_HOST_MS_WINDOWS
1248 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_HIDE );
1252 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
1256 * Iconify the current window (top-level windows only)
1258 void FGAPIENTRY glutIconifyWindow( void )
1260 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" );
1261 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" );
1263 fgStructure.CurrentWindow->State.Visible = GL_FALSE;
1264 #if TARGET_HOST_POSIX_X11
1266 XIconifyWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
1268 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1270 #elif TARGET_HOST_MS_WINDOWS
1272 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_MINIMIZE );
1276 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
1280 * Set the current window's title
1282 void FGAPIENTRY glutSetWindowTitle( const char* title )
1284 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowTitle" );
1285 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" );
1286 if( ! fgStructure.CurrentWindow->Parent )
1288 #if TARGET_HOST_POSIX_X11
1292 text.value = (unsigned char *) title;
1293 text.encoding = XA_STRING;
1295 text.nitems = strlen( title );
1299 fgStructure.CurrentWindow->Window.Handle,
1303 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1305 #elif TARGET_HOST_MS_WINDOWS
1308 wchar_t* wstr = fghWstrFromStr(title);
1309 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
1313 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
1321 * Set the current window's iconified title
1323 void FGAPIENTRY glutSetIconTitle( const char* title )
1325 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" );
1326 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" );
1328 if( ! fgStructure.CurrentWindow->Parent )
1330 #if TARGET_HOST_POSIX_X11
1334 text.value = (unsigned char *) title;
1335 text.encoding = XA_STRING;
1337 text.nitems = strlen( title );
1341 fgStructure.CurrentWindow->Window.Handle,
1345 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1347 #elif TARGET_HOST_MS_WINDOWS
1350 wchar_t* wstr = fghWstrFromStr(title);
1351 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
1355 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
1363 * Change the current window's size
1365 void FGAPIENTRY glutReshapeWindow( int width, int height )
1367 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" );
1368 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" );
1370 if (glutGet(GLUT_FULL_SCREEN))
1372 /* Leave full screen state before resizing. */
1373 glutFullScreenToggle();
1376 fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
1377 fgStructure.CurrentWindow->State.Width = width ;
1378 fgStructure.CurrentWindow->State.Height = height;
1382 * Change the current window's position
1384 void FGAPIENTRY glutPositionWindow( int x, int y )
1386 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" );
1387 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" );
1389 if (glutGet(GLUT_FULL_SCREEN))
1391 /* Leave full screen state before moving. */
1392 glutFullScreenToggle();
1395 #if TARGET_HOST_POSIX_X11
1397 XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
1399 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1401 #elif TARGET_HOST_MS_WINDOWS
1406 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
1407 GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
1409 fgStructure.CurrentWindow->Window.Handle,
1412 winRect.right - winRect.left,
1413 winRect.bottom - winRect.top,
1422 * Lowers the current window (by Z order change)
1424 void FGAPIENTRY glutPushWindow( void )
1426 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPushWindow" );
1427 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPushWindow" );
1429 #if TARGET_HOST_POSIX_X11
1431 XLowerWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1433 #elif TARGET_HOST_MS_WINDOWS
1436 fgStructure.CurrentWindow->Window.Handle,
1439 SWP_NOSIZE | SWP_NOMOVE
1446 * Raises the current window (by Z order change)
1448 void FGAPIENTRY glutPopWindow( void )
1450 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" );
1451 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" );
1453 #if TARGET_HOST_POSIX_X11
1455 XRaiseWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1457 #elif TARGET_HOST_MS_WINDOWS
1460 fgStructure.CurrentWindow->Window.Handle,
1463 SWP_NOSIZE | SWP_NOMOVE
1470 * Resize the current window so that it fits the whole screen
1472 void FGAPIENTRY glutFullScreen( void )
1474 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" );
1475 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" );
1477 if (glutGet(GLUT_FULL_SCREEN))
1479 /* Leave full screen state before resizing. */
1480 glutFullScreenToggle();
1484 #if TARGET_HOST_POSIX_X11
1486 Status status; /* Returned by XGetWindowAttributes(), not checked. */
1487 XWindowAttributes attributes;
1489 status = XGetWindowAttributes(fgDisplay.Display,
1490 fgStructure.CurrentWindow->Window.Handle,
1493 * The "x" and "y" members of "attributes" are the window's coordinates
1494 * relative to its parent, i.e. to the decoration window.
1496 XMoveResizeWindow(fgDisplay.Display,
1497 fgStructure.CurrentWindow->Window.Handle,
1500 fgDisplay.ScreenWidth,
1501 fgDisplay.ScreenHeight);
1503 #elif TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: what about WinCE */
1506 /* For fullscreen mode, force the top-left corner to 0,0
1507 * and adjust the window rectangle so that the client area
1508 * covers the whole screen.
1513 rect.right = fgDisplay.ScreenWidth;
1514 rect.bottom = fgDisplay.ScreenHeight;
1516 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
1517 WS_CLIPCHILDREN, FALSE );
1520 * SWP_NOACTIVATE Do not activate the window
1521 * SWP_NOOWNERZORDER Do not change position in z-order
1522 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
1523 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
1526 SetWindowPos( fgStructure.CurrentWindow->Window.Handle,
1530 rect.right - rect.left,
1531 rect.bottom - rect.top,
1532 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
1540 * Toggle the window's full screen state.
1542 void FGAPIENTRY glutFullScreenToggle( void )
1544 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreenToggle" );
1545 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreenToggle" );
1548 #if TARGET_HOST_POSIX_X11
1550 if (fgDisplay.StateFullScreen != None)
1556 xevent.type = ClientMessage;
1557 xevent.xclient.type = ClientMessage;
1558 xevent.xclient.serial = 0;
1559 xevent.xclient.send_event = True;
1560 xevent.xclient.display = fgDisplay.Display;
1561 xevent.xclient.window = fgStructure.CurrentWindow->Window.Handle;
1562 xevent.xclient.message_type = fgDisplay.State;
1563 xevent.xclient.format = 32;
1564 xevent.xclient.data.l[0] = 2; /* _NET_WM_STATE_TOGGLE */
1565 xevent.xclient.data.l[1] = fgDisplay.StateFullScreen;
1566 xevent.xclient.data.l[2] = 0;
1567 xevent.xclient.data.l[3] = 0;
1568 xevent.xclient.data.l[4] = 0;
1570 /*** Don't really understand how event masks work... ***/
1571 event_mask = SubstructureRedirectMask | SubstructureNotifyMask;
1573 status = XSendEvent(fgDisplay.Display,
1574 fgDisplay.RootWindow,
1578 FREEGLUT_INTERNAL_ERROR_EXIT(status != 0,
1579 "XSendEvent failed",
1580 "glutFullScreenToggle");
1586 * If the window manager is not Net WM compliant, fall back to legacy
1595 * A.Donev: Set and retrieve the window's user data
1597 void* FGAPIENTRY glutGetWindowData( void )
1599 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindowData" );
1600 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutGetWindowData" );
1601 return fgStructure.CurrentWindow->UserData;
1604 void FGAPIENTRY glutSetWindowData(void* data)
1606 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowData" );
1607 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowData" );
1608 fgStructure.CurrentWindow->UserData = data;
1611 /*** END OF FILE ***/