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_AUX4 )
137 ATTRIB_VAL(GLX_AUX_BUFFERS, 4);
139 else if( fgState.DisplayMode & GLUT_AUX3 )
141 ATTRIB_VAL(GLX_AUX_BUFFERS, 3);
143 else if( fgState.DisplayMode & GLUT_AUX2 )
145 ATTRIB_VAL(GLX_AUX_BUFFERS, 2);
147 else if( fgState.DisplayMode & GLUT_AUX1 ) /* NOTE: Same as GLUT_AUX! */
149 ATTRIB_VAL(GLX_AUX_BUFFERS, fgState.AuxiliaryBufferNumber);
152 if (fgState.DisplayMode & GLUT_MULTISAMPLE)
154 ATTRIB_VAL(GLX_SAMPLE_BUFFERS, 1)
155 ATTRIB_VAL(GLX_SAMPLES, fgState.SampleNumber)
158 /* Push a null at the end of the list */
162 GLXFBConfig * fbconfigArray; /* Array of FBConfigs */
163 GLXFBConfig * fbconfig; /* The FBConfig we want */
164 int fbconfigArraySize; /* Number of FBConfigs in the array */
167 /* Get all FBConfigs that match "attributes". */
168 fbconfigArray = glXChooseFBConfig( fgDisplay.Display,
171 &fbconfigArraySize );
173 if (fbconfigArray != NULL)
175 int result; /* Returned by glXGetFBConfigAttrib, not checked. */
178 if( wantIndexedMode )
181 * In index mode, we want the largest buffer size, i.e. visual
182 * depth. Here, FBConfigs are sorted by increasing buffer size
183 * first, so FBConfigs with the largest size come last.
186 int bufferSizeMin, bufferSizeMax;
188 /* Get bufferSizeMin. */
190 glXGetFBConfigAttrib( fgDisplay.Display,
194 /* Get bufferSizeMax. */
196 glXGetFBConfigAttrib( fgDisplay.Display,
197 fbconfigArray[fbconfigArraySize - 1],
201 if (bufferSizeMax > bufferSizeMin)
204 * Free and reallocate fbconfigArray, keeping only FBConfigs
205 * with the largest buffer size.
207 XFree(fbconfigArray);
209 /* Add buffer size token at the end of the list. */
211 ATTRIB_VAL( GLX_BUFFER_SIZE, bufferSizeMax );
214 fbconfigArray = glXChooseFBConfig( fgDisplay.Display,
217 &fbconfigArraySize );
222 * We now have an array of FBConfigs, the first one being the "best"
223 * one. So we should return only this FBConfig:
227 * - pick the XID of the FBConfig we want
228 * result = glXGetFBConfigAttrib( fgDisplay.Display,
234 * XFree(fbconfigArray);
236 * - reset "attributes" with the XID
238 * ATTRIB_VAL( GLX_FBCONFIG_ID, fbconfigXID );
241 * - get our FBConfig only
242 * fbconfig = glXChooseFBConfig( fgDisplay.Display,
245 * &fbconfigArraySize );
247 * However, for some configurations (for instance multisampling with
248 * Mesa 6.5.2 and ATI drivers), this does not work:
249 * glXChooseFBConfig returns NULL, whereas fbconfigXID is a valid
250 * XID. Further investigation is needed.
252 * So, for now, we return the whole array of FBConfigs. This should
253 * not produce any side effects elsewhere.
255 fbconfig = fbconfigArray;
265 #endif /* TARGET_HOST_POSIX_X11 */
268 * Setup the pixel format for a Win32 window
270 #if TARGET_HOST_MS_WINDOWS
271 /* The following include file is available from SGI but is not standard:
272 * #include <GL/wglext.h>
273 * So we copy the necessary parts out of it.
274 * XXX: should local definitions for extensions be put in a separate include file?
276 typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
278 typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
280 #define WGL_DRAW_TO_WINDOW_ARB 0x2001
281 #define WGL_ACCELERATION_ARB 0x2003
282 #define WGL_SUPPORT_OPENGL_ARB 0x2010
283 #define WGL_DOUBLE_BUFFER_ARB 0x2011
284 #define WGL_COLOR_BITS_ARB 0x2014
285 #define WGL_ALPHA_BITS_ARB 0x201B
286 #define WGL_DEPTH_BITS_ARB 0x2022
287 #define WGL_STENCIL_BITS_ARB 0x2023
288 #define WGL_FULL_ACCELERATION_ARB 0x2027
290 #define WGL_SAMPLE_BUFFERS_ARB 0x2041
291 #define WGL_SAMPLES_ARB 0x2042
294 #ifndef WGL_ARB_create_context
295 #define WGL_ARB_create_context 1
296 #ifdef WGL_WGLEXT_PROTOTYPES
297 extern HGLRC WINAPI wglCreateContextAttribsARB (HDC, HGLRC, const int *);
298 #endif /* WGL_WGLEXT_PROTOTYPES */
299 typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList);
301 #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
302 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
303 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
304 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
305 #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
306 #define WGL_CONTEXT_FLAGS_ARB 0x2094
307 #define ERROR_INVALID_VERSION_ARB 0x2095
311 void fgNewWGLCreateContext( SFG_Window* window )
313 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetEntensionsStringARB;
316 PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
317 const char * pWglExtString;
319 /* If nothing fancy has been required, leave the context as it is */
320 if ( fgState.MajorVersion == 1 && fgState.MinorVersion == 0 && fgState.ContextFlags == 0 )
325 wglMakeCurrent( window->Window.Device,
326 window->Window.Context );
328 wglGetEntensionsStringARB=(PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
329 if ( wglGetEntensionsStringARB == NULL )
334 pWglExtString=wglGetEntensionsStringARB(window->Window.Device);
335 if (( pWglExtString == NULL ) || ( strstr(pWglExtString, "WGL_ARB_create_context") == NULL ))
340 /* new context creation */
341 attribs[0] = WGL_CONTEXT_MAJOR_VERSION_ARB;
342 attribs[1] = fgState.MajorVersion;
343 attribs[2] = WGL_CONTEXT_MINOR_VERSION_ARB;
344 attribs[3] = fgState.MinorVersion;
345 attribs[4] = WGL_CONTEXT_FLAGS_ARB;
346 attribs[5] = ((fgState.ContextFlags & GLUT_DEBUG) ? WGL_CONTEXT_DEBUG_BIT_ARB : 0) |
347 ((fgState.ContextFlags & GLUT_FORWARD_COMPATIBLE) ? WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB : 0);
350 wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress( "wglCreateContextAttribsARB" );
351 if ( wglCreateContextAttribsARB == NULL )
353 fgError( "wglCreateContextAttribsARB not found" );
356 context = wglCreateContextAttribsARB( window->Window.Device, 0, attribs );
357 if ( context == NULL )
359 fgError( "Unable to create OpenGL %d.%d context (flags %x)",
360 fgState.MajorVersion, fgState.MinorVersion, fgState.ContextFlags );
363 wglMakeCurrent( NULL, NULL );
364 wglDeleteContext( window->Window.Context );
365 window->Window.Context = context;
369 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
370 unsigned char layer_type )
372 #if defined(_WIN32_WCE)
375 PIXELFORMATDESCRIPTOR* ppfd, pfd;
376 int flags, pixelformat;
378 freeglut_return_val_if_fail( window != NULL, 0 );
379 flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
380 if( fgState.DisplayMode & GLUT_DOUBLE )
381 flags |= PFD_DOUBLEBUFFER;
383 if( fgState.DisplayMode & GLUT_STEREO )
386 #if defined(_MSC_VER)
387 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
390 /* Specify which pixel format do we opt for... */
391 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
395 if( fgState.DisplayMode & GLUT_INDEX )
397 pfd.iPixelType = PFD_TYPE_COLORINDEX;
405 pfd.iPixelType = PFD_TYPE_RGBA;
409 if ( fgState.DisplayMode & GLUT_ALPHA )
421 pfd.cAccumRedBits = 0;
422 pfd.cAccumGreenBits = 0;
423 pfd.cAccumBlueBits = 0;
424 pfd.cAccumAlphaBits = 0;
427 pfd.cStencilBits = 0;
430 pfd.cStencilBits = 8;
432 if( fgState.DisplayMode & GLUT_AUX4 )
434 else if( fgState.DisplayMode & GLUT_AUX3 )
436 else if( fgState.DisplayMode & GLUT_AUX2 )
438 else if( fgState.DisplayMode & GLUT_AUX1 ) /* NOTE: Same as GLUT_AUX! */
439 pfd.cAuxBuffers = fgState.AuxiliaryBufferNumber;
443 pfd.iLayerType = layer_type;
446 pfd.dwVisibleMask = 0;
447 pfd.dwDamageMask = 0;
449 pfd.cColorBits = (BYTE) GetDeviceCaps( window->Window.Device, BITSPIXEL );
452 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
454 /* windows hack for multismapling */
455 if (fgState.DisplayMode&GLUT_MULTISAMPLE)
457 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetEntensionsStringARB=NULL;
458 HGLRC rc, rc_before=wglGetCurrentContext();
460 HDC hDC, hDC_before=wglGetCurrentDC();
463 /* create a dummy window */
464 ZeroMemory(&wndCls, sizeof(wndCls));
465 wndCls.lpfnWndProc = DefWindowProc;
466 wndCls.hInstance = fgDisplay.Instance;
467 wndCls.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
468 wndCls.lpszClassName = _T("FREEGLUT_dummy");
469 RegisterClass( &wndCls );
471 hWnd=CreateWindow(_T("FREEGLUT_dummy"), _T(""), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW , 0,0,0,0, 0, 0, fgDisplay.Instance, 0 );
473 SetPixelFormat( hDC, pixelformat, ppfd );
475 rc = wglCreateContext( hDC );
476 wglMakeCurrent(hDC, rc);
478 wglGetEntensionsStringARB=(PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
479 if (wglGetEntensionsStringARB)
481 const char * pWglExtString=wglGetEntensionsStringARB(hDC);
484 if (strstr(pWglExtString, "WGL_ARB_multisample"))
486 int pAttributes[100];
490 float fAttributes[] = {0,0};
492 PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARBProc=NULL;
494 wglChoosePixelFormatARBProc=(PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
495 if ( wglChoosePixelFormatARBProc )
497 pAttributes[iCounter++]=WGL_DRAW_TO_WINDOW_ARB; pAttributes[iCounter++]=GL_TRUE;
498 pAttributes[iCounter++]=WGL_SUPPORT_OPENGL_ARB; pAttributes[iCounter++]=GL_TRUE;
499 pAttributes[iCounter++]=WGL_ACCELERATION_ARB; pAttributes[iCounter++]=WGL_FULL_ACCELERATION_ARB;
501 pAttributes[iCounter++]=WGL_COLOR_BITS_ARB; pAttributes[iCounter++]=pfd.cColorBits ;
502 pAttributes[iCounter++]=WGL_ALPHA_BITS_ARB; pAttributes[iCounter++]=pfd.cAlphaBits;
503 pAttributes[iCounter++]=WGL_DEPTH_BITS_ARB; pAttributes[iCounter++]=pfd.cDepthBits;
504 pAttributes[iCounter++]=WGL_STENCIL_BITS_ARB; pAttributes[iCounter++]=pfd.cStencilBits;
506 pAttributes[iCounter++]=WGL_DOUBLE_BUFFER_ARB; pAttributes[iCounter++]=(fgState.DisplayMode & GLUT_DOUBLE)!=0;
507 pAttributes[iCounter++]=WGL_SAMPLE_BUFFERS_ARB; pAttributes[iCounter++]=GL_TRUE;
508 pAttributes[iCounter++]=WGL_SAMPLES_ARB; pAttributes[iCounter++]=fgState.SampleNumber;
509 pAttributes[iCounter++]=0; pAttributes[iCounter++]=0; /* terminator */
511 bValid = wglChoosePixelFormatARBProc(window->Window.Device,pAttributes,fAttributes,1,&iPixelFormat,&numFormats);
513 if (bValid && numFormats>0)
514 pixelformat=iPixelFormat;
517 wglMakeCurrent( hDC_before, rc_before);
518 wglDeleteContext(rc);
519 ReleaseDC(hWnd, hDC);
521 UnregisterClass(_T("FREEGLUT_dummy"), fgDisplay.Instance);
526 if( pixelformat == 0 )
531 return SetPixelFormat( window->Window.Device, pixelformat, ppfd );
532 #endif /* defined(_WIN32_WCE) */
534 #endif /* TARGET_HOST_MS_WINDOWS */
537 * Sets the OpenGL context and the fgStructure "Current Window" pointer to
538 * the window structure passed in.
540 void fgSetWindow ( SFG_Window *window )
542 #if TARGET_HOST_POSIX_X11
544 glXMakeContextCurrent(
546 window->Window.Handle,
547 window->Window.Handle,
548 window->Window.Context
550 #elif TARGET_HOST_MS_WINDOWS
551 if( fgStructure.CurrentWindow )
552 ReleaseDC( fgStructure.CurrentWindow->Window.Handle,
553 fgStructure.CurrentWindow->Window.Device );
557 window->Window.Device = GetDC( window->Window.Handle );
559 window->Window.Device,
560 window->Window.Context
564 fgStructure.CurrentWindow = window;
569 #if TARGET_HOST_POSIX_X11
571 #ifndef GLX_CONTEXT_MAJOR_VERSION_ARB
572 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
575 #ifndef GLX_CONTEXT_MINOR_VERSION_ARB
576 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
579 #ifndef GLX_CONTEXT_FLAGS_ARB
580 #define GLX_CONTEXT_FLAGS_ARB 0x2094
583 #ifndef GLX_CONTEXT_DEBUG_BIT_ARB
584 #define GLX_CONTEXT_DEBUG_BIT_ARB 0x0001
587 #ifndef GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
588 #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
591 typedef GLXContext (*CreateContextAttribsProc)(Display *dpy, GLXFBConfig config,
592 GLXContext share_list, Bool direct,
593 const int *attrib_list);
595 static GLXContext fghCreateNewContext( SFG_Window* window )
597 /* for color model calculation */
598 int menu = ( window->IsMenu && !fgStructure.MenuContext );
599 int index_mode = ( fgState.DisplayMode & GLUT_INDEX );
601 /* "classic" context creation */
602 Display *dpy = fgDisplay.Display;
603 GLXFBConfig config = *(window->Window.FBConfig);
604 int render_type = ( !menu && index_mode ) ? GLX_COLOR_INDEX_TYPE : GLX_RGBA_TYPE;
605 GLXContext share_list = NULL;
606 Bool direct = ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT );
609 /* new context creation */
611 CreateContextAttribsProc createContextAttribs;
613 /* If nothing fancy has been required, simply use the old context creation GLX API entry */
614 if ( fgState.MajorVersion == 1 && fgState.MinorVersion == 0 && fgState.ContextFlags == 0)
616 context = glXCreateNewContext( dpy, config, render_type, share_list, direct );
617 if ( context == NULL ) {
618 fgError( "could not create new OpenGL context" );
623 /* color index mode is not available anymore with OpenGL 3.0 */
624 if ( render_type == GLX_COLOR_INDEX_TYPE ) {
625 fgWarning( "color index mode is deprecated, using RGBA mode" );
628 attribs[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
629 attribs[1] = fgState.MajorVersion;
630 attribs[2] = GLX_CONTEXT_MINOR_VERSION_ARB;
631 attribs[3] = fgState.MinorVersion;
632 attribs[4] = GLX_CONTEXT_FLAGS_ARB;
633 attribs[5] = ((fgState.ContextFlags & GLUT_DEBUG) ? GLX_CONTEXT_DEBUG_BIT_ARB : 0) |
634 ((fgState.ContextFlags & GLUT_FORWARD_COMPATIBLE) ? GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB : 0);
637 createContextAttribs = (CreateContextAttribsProc) fghGetProcAddress( "glXCreateContextAttribsARB" );
638 if ( createContextAttribs == NULL ) {
639 fgError( "glXCreateContextAttribsARB not found" );
642 context = createContextAttribs( dpy, config, share_list, direct, attribs );
643 if ( context == NULL ) {
644 fgError( "could not create new OpenGL %d.%d context (flags %x)",
645 fgState.MajorVersion, fgState.MinorVersion, fgState.ContextFlags );
653 * Opens a window. Requires a SFG_Window object created and attached
654 * to the freeglut structure. OpenGL context is created here.
656 void fgOpenWindow( SFG_Window* window, const char* title,
657 GLboolean positionUse, int x, int y,
658 GLboolean sizeUse, int w, int h,
659 GLboolean gameMode, GLboolean isSubWindow )
661 #if TARGET_HOST_POSIX_X11
662 XVisualInfo * visualInfo;
663 XSetWindowAttributes winAttr;
664 XTextProperty textProperty;
665 XSizeHints sizeHints;
668 unsigned int current_DisplayMode = fgState.DisplayMode ;
670 /* Save the display mode if we are creating a menu window */
671 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
672 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ;
674 window->Window.FBConfig = fgChooseFBConfig( );
676 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
677 fgState.DisplayMode = current_DisplayMode ;
679 if( ! window->Window.FBConfig )
682 * The "fgChooseFBConfig" returned a null meaning that the visual
683 * context is not available.
684 * Try a couple of variations to see if they will work.
686 if( !( fgState.DisplayMode & GLUT_DOUBLE ) )
688 fgState.DisplayMode |= GLUT_DOUBLE ;
689 window->Window.FBConfig = fgChooseFBConfig( );
690 fgState.DisplayMode &= ~GLUT_DOUBLE;
693 if( fgState.DisplayMode & GLUT_MULTISAMPLE )
695 fgState.DisplayMode &= ~GLUT_MULTISAMPLE ;
696 window->Window.FBConfig = fgChooseFBConfig( );
697 fgState.DisplayMode |= GLUT_MULTISAMPLE;
701 FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.FBConfig != NULL,
702 "FBConfig with necessary capabilities not found", "fgOpenWindow" );
704 /* Get the X visual. */
705 visualInfo = glXGetVisualFromFBConfig( fgDisplay.Display,
706 *(window->Window.FBConfig) );
709 * XXX HINT: the masks should be updated when adding/removing callbacks.
710 * XXX This might speed up message processing. Is that true?
712 * XXX A: Not appreciably, but it WILL make it easier to debug.
713 * XXX Try tracing old GLUT and try tracing freeglut. Old GLUT
714 * XXX turns off events that it doesn't need and is a whole lot
715 * XXX more pleasant to trace. (Think mouse-motion! Tons of
716 * XXX ``bonus'' GUI events stream in.)
719 StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
720 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
721 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
722 PointerMotionMask | ButtonMotionMask;
723 winAttr.background_pixmap = None;
724 winAttr.background_pixel = 0;
725 winAttr.border_pixel = 0;
727 winAttr.colormap = XCreateColormap(
728 fgDisplay.Display, fgDisplay.RootWindow,
729 visualInfo->visual, AllocNone
732 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
734 if( window->IsMenu || ( gameMode == GL_TRUE ) )
736 winAttr.override_redirect = True;
737 mask |= CWOverrideRedirect;
741 x = y = -1; /* default window position */
743 w = h = 300; /* default window size */
745 window->Window.Handle = XCreateWindow(
747 window->Parent == NULL ? fgDisplay.RootWindow :
748 window->Parent->Window.Handle,
750 visualInfo->depth, InputOutput,
751 visualInfo->visual, mask,
756 * The GLX context creation, possibly trying the direct context rendering
757 * or else use the current context if the user has so specified
763 * If there isn't already an OpenGL rendering context for menu
766 if( !fgStructure.MenuContext )
768 fgStructure.MenuContext =
769 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
770 fgStructure.MenuContext->MContext = fghCreateNewContext( window );
773 /* window->Window.Context = fgStructure.MenuContext->MContext; */
774 window->Window.Context = fghCreateNewContext( window );
776 else if( fgState.UseCurrentContext )
778 window->Window.Context = glXGetCurrentContext( );
780 if( ! window->Window.Context )
781 window->Window.Context = fghCreateNewContext( window );
784 window->Window.Context = fghCreateNewContext( window );
786 #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ )
787 if( !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
789 if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
790 fgError( "Unable to force direct context rendering for window '%s'",
796 * XXX Assume the new window is visible by default
797 * XXX Is this a safe assumption?
799 window->State.Visible = GL_TRUE;
803 sizeHints.flags |= USPosition;
805 sizeHints.flags |= USSize;
808 * Fill in the size hints values now (the x, y, width and height
809 * settings are obsolete, are there any more WMs that support them?)
810 * Unless the X servers actually stop supporting these, we should
811 * continue to fill them in. It is *not* our place to tell the user
812 * that they should replace a window manager that they like, and which
813 * works, just because *we* think that it's not "modern" enough.
818 sizeHints.height = h;
820 wmHints.flags = StateHint;
821 wmHints.initial_state = fgState.ForceIconic ? IconicState : NormalState;
822 /* Prepare the window and iconified window names... */
823 XStringListToTextProperty( (char **) &title, 1, &textProperty );
827 window->Window.Handle,
836 XFree( textProperty.value );
838 XSetWMProtocols( fgDisplay.Display, window->Window.Handle,
839 &fgDisplay.DeleteWindow, 1 );
841 glXMakeContextCurrent(
843 window->Window.Handle,
844 window->Window.Handle,
845 window->Window.Context
848 XMapWindow( fgDisplay.Display, window->Window.Handle );
852 #elif TARGET_HOST_MS_WINDOWS
860 /* Grab the window class we have registered on glutInit(): */
861 atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
862 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Info Not Found",
867 FREEGLUT_INTERNAL_ERROR_EXIT ( window->Parent == NULL,
868 "Game mode being invoked on a subwindow",
872 * Set the window creation flags appropriately to make the window
875 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
879 int worig = w, horig = h;
881 #if !defined(_WIN32_WCE)
882 if ( ( ! isSubWindow ) && ( ! window->IsMenu ) )
885 * Update the window dimensions, taking account of window
886 * decorations. "freeglut" is to create the window with the
887 * outside of its border at (x,y) and with dimensions (w,h).
889 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
890 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 +
891 GetSystemMetrics( SM_CYCAPTION );
893 #endif /* defined(_WIN32_WCE) */
900 /* setting State.Width/Height to call resize callback later */
903 if( ! window->IsMenu )
908 else /* fail safe - Windows can make a window of size (0, 0) */
909 w = h = 300; /* default window size */
910 window->State.Width = window->State.Height = -1;
914 window->State.Width = worig;
915 window->State.Height = horig;
919 * There's a small difference between creating the top, child and
922 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
924 if ( window->IsMenu )
927 exFlags |= WS_EX_TOOLWINDOW;
929 #if !defined(_WIN32_WCE)
930 else if( window->Parent == NULL )
931 flags |= WS_OVERLAPPEDWINDOW;
937 #if defined(_WIN32_WCE)
939 wchar_t* wstr = fghWstrFromStr(title);
941 window->Window.Handle = CreateWindow(
944 WS_VISIBLE | WS_POPUP,
954 SHFullScreen(window->Window.Handle, SHFS_HIDESTARTICON);
955 SHFullScreen(window->Window.Handle, SHFS_HIDESIPBUTTON);
956 SHFullScreen(window->Window.Handle, SHFS_HIDETASKBAR);
957 MoveWindow(window->Window.Handle, 0, 0, 240, 320, TRUE);
958 ShowWindow(window->Window.Handle, SW_SHOW);
959 UpdateWindow(window->Window.Handle);
962 window->Window.Handle = CreateWindowEx(
968 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
973 #endif /* defined(_WIN32_WCE) */
975 if( !( window->Window.Handle ) )
976 fgError( "Failed to create a window (%s)!", title );
978 /* Make a menu window always on top - fix Feature Request 947118 */
979 if( window->IsMenu || gameMode )
981 window->Window.Handle,
984 SWP_NOMOVE | SWP_NOSIZE
987 /* Hack to remove the caption (title bar) and/or border
988 * and all the system menu controls.
990 WindowStyle = GetWindowLong(window->Window.Handle, GWL_STYLE);
991 if ( fgState.DisplayMode & GLUT_CAPTIONLESS )
993 SetWindowLong ( window->Window.Handle, GWL_STYLE,
994 WindowStyle & ~(WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX));
996 else if ( fgState.DisplayMode & GLUT_BORDERLESS )
998 SetWindowLong ( window->Window.Handle, GWL_STYLE,
999 WindowStyle & ~(WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX));
1001 /* SetWindowPos(window->Window.Handle, NULL, 0, 0, 0, 0,
1002 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); */
1005 #if defined(_WIN32_WCE)
1006 ShowWindow( window->Window.Handle, SW_SHOW );
1008 ShowWindow( window->Window.Handle,
1009 fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
1010 #endif /* defined(_WIN32_WCE) */
1012 UpdateWindow( window->Window.Handle );
1013 ShowCursor( TRUE ); /* XXX Old comments say "hide cursor"! */
1017 fgSetWindow( window );
1019 window->Window.DoubleBuffered =
1020 ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
1022 if ( ! window->Window.DoubleBuffered )
1024 glDrawBuffer ( GL_FRONT );
1025 glReadBuffer ( GL_FRONT );
1030 * Closes a window, destroying the frame and OpenGL context
1032 void fgCloseWindow( SFG_Window* window )
1034 #if TARGET_HOST_POSIX_X11
1036 if( window->Window.Context )
1037 glXDestroyContext( fgDisplay.Display, window->Window.Context );
1038 XFree( window->Window.FBConfig );
1039 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
1040 /* XFlush( fgDisplay.Display ); */ /* XXX Shouldn't need this */
1042 #elif TARGET_HOST_MS_WINDOWS
1044 /* Make sure we don't close a window with current context active */
1045 if( fgStructure.CurrentWindow == window )
1046 wglMakeCurrent( NULL, NULL );
1049 * Step through the list of windows. If the rendering context
1050 * is not being used by another window, then we delete it.
1056 for( iter = (SFG_Window *)fgStructure.Windows.First;
1058 iter = (SFG_Window *)iter->Node.Next )
1060 if( ( iter->Window.Context == window->Window.Context ) &&
1061 ( iter != window ) )
1066 wglDeleteContext( window->Window.Context );
1069 DestroyWindow( window->Window.Handle );
1074 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1077 * Creates a new top-level freeglut window
1079 int FGAPIENTRY glutCreateWindow( const char* title )
1081 /* XXX GLUT does not exit; it simply calls "glutInit" quietly if the
1082 * XXX application has not already done so. The "freeglut" community
1083 * XXX decided not to go this route (freeglut-developer e-mail from
1084 * XXX Steve Baker, 12/16/04, 4:22 PM CST, "Re: [Freeglut-developer]
1085 * XXX Desired 'freeglut' behaviour when there is no current window"
1087 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateWindow" );
1089 return fgCreateWindow( NULL, title, fgState.Position.Use,
1090 fgState.Position.X, fgState.Position.Y,
1091 fgState.Size.Use, fgState.Size.X, fgState.Size.Y,
1092 GL_FALSE, GL_FALSE )->ID;
1096 * This function creates a sub window.
1098 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
1101 SFG_Window* window = NULL;
1102 SFG_Window* parent = NULL;
1104 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateSubWindow" );
1105 parent = fgWindowByID( parentID );
1106 freeglut_return_val_if_fail( parent != NULL, 0 );
1109 x = parent->State.Width + x ;
1110 if ( w >= 0 ) x -= w ;
1113 if ( w < 0 ) w = parent->State.Width - x + w ;
1122 y = parent->State.Height + y ;
1123 if ( h >= 0 ) y -= h ;
1126 if ( h < 0 ) h = parent->State.Height - y + h ;
1133 window = fgCreateWindow( parent, "", GL_TRUE, x, y, GL_TRUE, w, h, GL_FALSE, GL_FALSE );
1140 * Destroys a window and all of its subwindows
1142 void FGAPIENTRY glutDestroyWindow( int windowID )
1145 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDestroyWindow" );
1146 window = fgWindowByID( windowID );
1147 freeglut_return_if_fail( window != NULL );
1149 fgExecutionState ExecState = fgState.ExecState;
1150 fgAddToWindowDestroyList( window );
1151 fgState.ExecState = ExecState;
1156 * This function selects the current window
1158 void FGAPIENTRY glutSetWindow( int ID )
1160 SFG_Window* window = NULL;
1162 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindow" );
1163 if( fgStructure.CurrentWindow != NULL )
1164 if( fgStructure.CurrentWindow->ID == ID )
1167 window = fgWindowByID( ID );
1168 if( window == NULL )
1170 fgWarning( "glutSetWindow(): window ID %d not found!", ID );
1174 fgSetWindow( window );
1178 * This function returns the ID number of the current window, 0 if none exists
1180 int FGAPIENTRY glutGetWindow( void )
1182 SFG_Window *win = fgStructure.CurrentWindow;
1184 * Since GLUT did not throw an error if this function was called without a prior call to
1185 * "glutInit", this function shouldn't do so here. Instead let us return a zero.
1186 * See Feature Request "[ 1307049 ] glutInit check".
1188 if ( ! fgState.Initialised )
1191 while ( win && win->IsMenu )
1193 return win ? win->ID : 0;
1197 * This function makes the current window visible
1199 void FGAPIENTRY glutShowWindow( void )
1201 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" );
1202 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" );
1204 #if TARGET_HOST_POSIX_X11
1206 XMapWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1207 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1209 #elif TARGET_HOST_MS_WINDOWS
1211 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_SHOW );
1215 fgStructure.CurrentWindow->State.Redisplay = GL_TRUE;
1219 * This function hides the current window
1221 void FGAPIENTRY glutHideWindow( void )
1223 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" );
1224 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" );
1226 #if TARGET_HOST_POSIX_X11
1228 if( fgStructure.CurrentWindow->Parent == NULL )
1229 XWithdrawWindow( fgDisplay.Display,
1230 fgStructure.CurrentWindow->Window.Handle,
1233 XUnmapWindow( fgDisplay.Display,
1234 fgStructure.CurrentWindow->Window.Handle );
1235 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1237 #elif TARGET_HOST_MS_WINDOWS
1239 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_HIDE );
1243 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
1247 * Iconify the current window (top-level windows only)
1249 void FGAPIENTRY glutIconifyWindow( void )
1251 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" );
1252 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" );
1254 fgStructure.CurrentWindow->State.Visible = GL_FALSE;
1255 #if TARGET_HOST_POSIX_X11
1257 XIconifyWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
1259 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1261 #elif TARGET_HOST_MS_WINDOWS
1263 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_MINIMIZE );
1267 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
1271 * Set the current window's title
1273 void FGAPIENTRY glutSetWindowTitle( const char* title )
1275 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowTitle" );
1276 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" );
1277 if( ! fgStructure.CurrentWindow->Parent )
1279 #if TARGET_HOST_POSIX_X11
1283 text.value = (unsigned char *) title;
1284 text.encoding = XA_STRING;
1286 text.nitems = strlen( title );
1290 fgStructure.CurrentWindow->Window.Handle,
1294 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1296 #elif TARGET_HOST_MS_WINDOWS
1299 wchar_t* wstr = fghWstrFromStr(title);
1300 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
1304 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
1312 * Set the current window's iconified title
1314 void FGAPIENTRY glutSetIconTitle( const char* title )
1316 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" );
1317 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" );
1319 if( ! fgStructure.CurrentWindow->Parent )
1321 #if TARGET_HOST_POSIX_X11
1325 text.value = (unsigned char *) title;
1326 text.encoding = XA_STRING;
1328 text.nitems = strlen( title );
1332 fgStructure.CurrentWindow->Window.Handle,
1336 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1338 #elif TARGET_HOST_MS_WINDOWS
1341 wchar_t* wstr = fghWstrFromStr(title);
1342 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
1346 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
1354 * Change the current window's size
1356 void FGAPIENTRY glutReshapeWindow( int width, int height )
1358 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" );
1359 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" );
1361 if (glutGet(GLUT_FULL_SCREEN))
1363 /* Leave full screen state before resizing. */
1364 glutFullScreenToggle();
1367 fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
1368 fgStructure.CurrentWindow->State.Width = width ;
1369 fgStructure.CurrentWindow->State.Height = height;
1373 * Change the current window's position
1375 void FGAPIENTRY glutPositionWindow( int x, int y )
1377 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" );
1378 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" );
1380 if (glutGet(GLUT_FULL_SCREEN))
1382 /* Leave full screen state before moving. */
1383 glutFullScreenToggle();
1386 #if TARGET_HOST_POSIX_X11
1388 XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
1390 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1392 #elif TARGET_HOST_MS_WINDOWS
1397 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
1398 GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
1400 fgStructure.CurrentWindow->Window.Handle,
1403 winRect.right - winRect.left,
1404 winRect.bottom - winRect.top,
1413 * Lowers the current window (by Z order change)
1415 void FGAPIENTRY glutPushWindow( void )
1417 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPushWindow" );
1418 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPushWindow" );
1420 #if TARGET_HOST_POSIX_X11
1422 XLowerWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1424 #elif TARGET_HOST_MS_WINDOWS
1427 fgStructure.CurrentWindow->Window.Handle,
1430 SWP_NOSIZE | SWP_NOMOVE
1437 * Raises the current window (by Z order change)
1439 void FGAPIENTRY glutPopWindow( void )
1441 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" );
1442 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" );
1444 #if TARGET_HOST_POSIX_X11
1446 XRaiseWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1448 #elif TARGET_HOST_MS_WINDOWS
1451 fgStructure.CurrentWindow->Window.Handle,
1454 SWP_NOSIZE | SWP_NOMOVE
1461 * Resize the current window so that it fits the whole screen
1463 void FGAPIENTRY glutFullScreen( void )
1465 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" );
1466 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" );
1468 if (glutGet(GLUT_FULL_SCREEN))
1470 /* Leave full screen state before resizing. */
1471 glutFullScreenToggle();
1475 #if TARGET_HOST_POSIX_X11
1477 Status status; /* Returned by XGetWindowAttributes(), not checked. */
1478 XWindowAttributes attributes;
1480 status = XGetWindowAttributes(fgDisplay.Display,
1481 fgStructure.CurrentWindow->Window.Handle,
1484 * The "x" and "y" members of "attributes" are the window's coordinates
1485 * relative to its parent, i.e. to the decoration window.
1487 XMoveResizeWindow(fgDisplay.Display,
1488 fgStructure.CurrentWindow->Window.Handle,
1491 fgDisplay.ScreenWidth,
1492 fgDisplay.ScreenHeight);
1494 #elif TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: what about WinCE */
1497 /* For fullscreen mode, force the top-left corner to 0,0
1498 * and adjust the window rectangle so that the client area
1499 * covers the whole screen.
1504 rect.right = fgDisplay.ScreenWidth;
1505 rect.bottom = fgDisplay.ScreenHeight;
1507 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
1508 WS_CLIPCHILDREN, FALSE );
1511 * SWP_NOACTIVATE Do not activate the window
1512 * SWP_NOOWNERZORDER Do not change position in z-order
1513 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
1514 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
1517 SetWindowPos( fgStructure.CurrentWindow->Window.Handle,
1521 rect.right - rect.left,
1522 rect.bottom - rect.top,
1523 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
1531 * Toggle the window's full screen state.
1533 void FGAPIENTRY glutFullScreenToggle( void )
1535 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreenToggle" );
1536 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreenToggle" );
1539 #if TARGET_HOST_POSIX_X11
1541 if (fgDisplay.StateFullScreen != None)
1547 xevent.type = ClientMessage;
1548 xevent.xclient.type = ClientMessage;
1549 xevent.xclient.serial = 0;
1550 xevent.xclient.send_event = True;
1551 xevent.xclient.display = fgDisplay.Display;
1552 xevent.xclient.window = fgStructure.CurrentWindow->Window.Handle;
1553 xevent.xclient.message_type = fgDisplay.State;
1554 xevent.xclient.format = 32;
1555 xevent.xclient.data.l[0] = 2; /* _NET_WM_STATE_TOGGLE */
1556 xevent.xclient.data.l[1] = fgDisplay.StateFullScreen;
1557 xevent.xclient.data.l[2] = 0;
1558 xevent.xclient.data.l[3] = 0;
1559 xevent.xclient.data.l[4] = 0;
1561 /*** Don't really understand how event masks work... ***/
1562 event_mask = SubstructureRedirectMask | SubstructureNotifyMask;
1564 status = XSendEvent(fgDisplay.Display,
1565 fgDisplay.RootWindow,
1569 FREEGLUT_INTERNAL_ERROR_EXIT(status != 0,
1570 "XSendEvent failed",
1571 "glutFullScreenToggle");
1577 * If the window manager is not Net WM compliant, fall back to legacy
1586 * A.Donev: Set and retrieve the window's user data
1588 void* FGAPIENTRY glutGetWindowData( void )
1590 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindowData" );
1591 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutGetWindowData" );
1592 return fgStructure.CurrentWindow->UserData;
1595 void FGAPIENTRY glutSetWindowData(void* data)
1597 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowData" );
1598 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowData" );
1599 fgStructure.CurrentWindow->UserData = data;
1602 /*** END OF FILE ***/