181c58d981e883c2e3d90f14077dabda02e3e6e0
[freeglut] / src / freeglut_window.c
1 /*
2  * freeglut_window.c
3  *
4  * Window management methods.
5  *
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
9  *
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:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Software.
19  *
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.
26  */
27
28 #include <GL/freeglut.h>
29 #include "freeglut_internal.h"
30
31 #if defined(_WIN32_WCE)
32 #   include <Aygshell.h>
33 #   ifdef FREEGLUT_LIB_PRAGMAS
34 #       pragma comment( lib, "Aygshell.lib" )
35 #   endif
36
37 static wchar_t* fghWstrFromStr(const char* str)
38 {
39     int i,len=strlen(str);
40     wchar_t* wstr = (wchar_t*)malloc(2*len+2);
41     for(i=0; i<len; i++)
42         wstr[i] = str[i];
43     wstr[len] = 0;
44     return wstr;
45 }
46
47 #endif /* defined(_WIN32_WCE) */
48
49 /*
50  * TODO BEFORE THE STABLE RELEASE:
51  *
52  *  fgChooseVisual()        -- OK, but what about glutInitDisplayString()?
53  *  fgSetupPixelFormat      -- ignores the display mode settings
54  *  fgOpenWindow()          -- check the Win32 version, -iconic handling!
55  *  fgCloseWindow()         -- check the Win32 version
56  *  glutCreateWindow()      -- Check when default position and size is {-1,-1}
57  *  glutCreateSubWindow()   -- Check when default position and size is {-1,-1}
58  *  glutDestroyWindow()     -- check the Win32 version
59  *  glutSetWindow()         -- check the Win32 version
60  *  glutGetWindow()         -- OK
61  *  glutSetWindowTitle()    -- check the Win32 version
62  *  glutSetIconTitle()      -- check the Win32 version
63  *  glutShowWindow()        -- check the Win32 version
64  *  glutHideWindow()        -- check the Win32 version
65  *  glutIconifyWindow()     -- check the Win32 version
66  *  glutReshapeWindow()     -- check the Win32 version
67  *  glutPositionWindow()    -- check the Win32 version
68  *  glutPushWindow()        -- check the Win32 version
69  *  glutPopWindow()         -- check the Win32 version
70  */
71
72 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
73
74 /*
75  * Chooses a visual basing on the current display mode settings
76  */
77 #if TARGET_HOST_POSIX_X11
78
79 XVisualInfo* fgChooseVisual( void )
80 {
81 #define BUFFER_SIZES 6
82     int bufferSize[BUFFER_SIZES] = { 16, 12, 8, 4, 2, 1 };
83     GLboolean wantIndexedMode = GL_FALSE;
84     int attributes[ 32 ];
85     int where = 0;
86
87     /* First we have to process the display mode settings... */
88 /*
89  * XXX Why is there a semi-colon in this #define?  The code
90  * XXX that uses the macro seems to always add more semicolons...
91  */
92 #define ATTRIB(a) attributes[where++]=a;
93 #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);}
94
95     if( fgState.DisplayMode & GLUT_INDEX )
96     {
97         ATTRIB_VAL( GLX_BUFFER_SIZE, 8 );
98         wantIndexedMode = GL_TRUE;
99     }
100     else
101     {
102         ATTRIB( GLX_RGBA );
103         ATTRIB_VAL( GLX_RED_SIZE,   1 );
104         ATTRIB_VAL( GLX_GREEN_SIZE, 1 );
105         ATTRIB_VAL( GLX_BLUE_SIZE,  1 );
106         if( fgState.DisplayMode & GLUT_ALPHA )
107             ATTRIB_VAL( GLX_ALPHA_SIZE, 1 );
108     }
109
110     if( fgState.DisplayMode & GLUT_DOUBLE )
111         ATTRIB( GLX_DOUBLEBUFFER );
112
113     if( fgState.DisplayMode & GLUT_STEREO )
114         ATTRIB( GLX_STEREO );
115
116     if( fgState.DisplayMode & GLUT_DEPTH )
117         ATTRIB_VAL( GLX_DEPTH_SIZE, 1 );
118
119     if( fgState.DisplayMode & GLUT_STENCIL )
120         ATTRIB_VAL( GLX_STENCIL_SIZE, 1 );
121
122     if( fgState.DisplayMode & GLUT_ACCUM )
123     {
124         ATTRIB_VAL( GLX_ACCUM_RED_SIZE,   1 );
125         ATTRIB_VAL( GLX_ACCUM_GREEN_SIZE, 1 );
126         ATTRIB_VAL( GLX_ACCUM_BLUE_SIZE,  1 );
127         if( fgState.DisplayMode & GLUT_ALPHA )
128             ATTRIB_VAL( GLX_ACCUM_ALPHA_SIZE, 1 );
129     }
130
131     if( fgState.DisplayMode & GLUT_AUX1 )
132         ATTRIB_VAL( GLX_AUX_BUFFERS, 1 );
133     if( fgState.DisplayMode & GLUT_AUX2 )
134         ATTRIB_VAL( GLX_AUX_BUFFERS, 2 );
135     if( fgState.DisplayMode & GLUT_AUX3 )
136         ATTRIB_VAL( GLX_AUX_BUFFERS, 3 );
137     if( fgState.DisplayMode & GLUT_AUX4 )
138         ATTRIB_VAL( GLX_AUX_BUFFERS, 4 );
139     if ( fgState.DisplayMode & GLUT_MULTISAMPLE )
140         ATTRIB_VAL( GLX_SAMPLES_SGIS, 4 );
141
142
143     /* Push a null at the end of the list */
144     ATTRIB( None );
145
146     if( ! wantIndexedMode )
147         return glXChooseVisual( fgDisplay.Display, fgDisplay.Screen,
148                                 attributes );
149     else
150     {
151         XVisualInfo* visualInfo;
152         int i;
153
154         /*
155          * In indexed mode, we need to check how many bits of depth can we
156          * achieve.  We do this by trying each possibility from the list
157          * given in the {bufferSize} array.  If we match, we return to caller.
158          */
159         for( i=0; i<BUFFER_SIZES; i++ )
160         {
161             attributes[ 1 ] = bufferSize[ i ];
162             visualInfo = glXChooseVisual( fgDisplay.Display, fgDisplay.Screen,
163                                           attributes );
164             if( visualInfo != NULL )
165                 return visualInfo;
166         }
167         return NULL;
168     }
169 }
170 #endif
171
172 /*
173  * Setup the pixel format for a Win32 window
174  */
175 #if TARGET_HOST_MS_WINDOWS
176 /* The following include file is available from SGI but is not standard:
177  *   #include <GL/wglext.h>
178  * So we copy the necessary parts out of it.
179  * XXX: should local definitions for extensions be put in a separate include file?
180  */
181 typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
182
183 typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
184
185 #define WGL_DRAW_TO_WINDOW_ARB         0x2001
186 #define WGL_ACCELERATION_ARB           0x2003
187 #define WGL_SUPPORT_OPENGL_ARB         0x2010
188 #define WGL_DOUBLE_BUFFER_ARB          0x2011
189 #define WGL_COLOR_BITS_ARB             0x2014
190 #define WGL_ALPHA_BITS_ARB             0x201B
191 #define WGL_DEPTH_BITS_ARB             0x2022
192 #define WGL_STENCIL_BITS_ARB           0x2023
193 #define WGL_FULL_ACCELERATION_ARB      0x2027
194
195 #define WGL_SAMPLE_BUFFERS_ARB         0x2041
196 #define WGL_SAMPLES_ARB                0x2042
197
198
199 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
200                               unsigned char layer_type )
201 {
202 #if defined(_WIN32_WCE)
203     return GL_TRUE;
204 #else
205     PIXELFORMATDESCRIPTOR* ppfd, pfd;
206     int flags, pixelformat;
207
208     freeglut_return_val_if_fail( window != NULL, 0 );
209     flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
210     if( fgState.DisplayMode & GLUT_DOUBLE )
211         flags |= PFD_DOUBLEBUFFER;
212
213     if( fgState.DisplayMode & GLUT_STEREO )
214         flags |= PFD_STEREO;
215
216 #if defined(_MSC_VER)
217 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
218 #endif
219
220     /* Specify which pixel format do we opt for... */
221     pfd.nSize           = sizeof(PIXELFORMATDESCRIPTOR);
222     pfd.nVersion        = 1;
223     pfd.dwFlags         = flags;
224
225     if( fgState.DisplayMode & GLUT_INDEX )
226     {
227         pfd.iPixelType = PFD_TYPE_COLORINDEX;
228         pfd.cRedBits                = 0;
229         pfd.cGreenBits            = 0;
230         pfd.cBlueBits             = 0;
231         pfd.cAlphaBits            = 0;
232     }
233     else
234     {
235         pfd.iPixelType      = PFD_TYPE_RGBA;
236         pfd.cRedBits                = 8;
237         pfd.cGreenBits            = 8;
238         pfd.cBlueBits             = 8;
239         if ( fgState.DisplayMode & GLUT_ALPHA )
240             pfd.cAlphaBits            = 8;
241         else
242             pfd.cAlphaBits            = 0;
243     }
244
245     pfd.cColorBits      = 24;
246     pfd.cRedShift       = 0;
247     pfd.cGreenShift     = 0;
248     pfd.cBlueShift      = 0;
249     pfd.cAlphaShift     = 0;
250     pfd.cAccumBits      = 0;
251     pfd.cAccumRedBits   = 0;
252     pfd.cAccumGreenBits = 0;
253     pfd.cAccumBlueBits  = 0;
254     pfd.cAccumAlphaBits = 0;
255 #if 0
256     pfd.cDepthBits      = 32;
257     pfd.cStencilBits    = 0;
258 #else
259     pfd.cDepthBits      = 24;
260     pfd.cStencilBits    = 8;
261 #endif
262     if( fgState.DisplayMode & GLUT_AUX4 )
263         pfd.cAuxBuffers = 4;
264     else if( fgState.DisplayMode & GLUT_AUX3 )
265         pfd.cAuxBuffers = 3;
266     else if( fgState.DisplayMode & GLUT_AUX2 )
267         pfd.cAuxBuffers = 2;
268     else if( fgState.DisplayMode & GLUT_AUX1 )
269         pfd.cAuxBuffers = 1;
270     else
271         pfd.cAuxBuffers = 0;
272
273     pfd.iLayerType      = layer_type;
274     pfd.bReserved       = 0;
275     pfd.dwLayerMask     = 0;
276     pfd.dwVisibleMask   = 0;
277     pfd.dwDamageMask    = 0;
278
279     pfd.cColorBits = (BYTE) GetDeviceCaps( window->Window.Device, BITSPIXEL );
280     ppfd = &pfd;
281
282     pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
283
284     /* windows hack for multismapling */
285     if (fgState.DisplayMode&GLUT_MULTISAMPLE)
286     {        
287         PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetEntensionsStringARB=NULL;
288         HGLRC rc, rc_before=wglGetCurrentContext();
289         HWND hWnd;
290         HDC hDC, hDC_before=wglGetCurrentDC();
291         WNDCLASS wndCls;
292         ATOM atom;
293
294         /* create a dummy window */
295         ZeroMemory(&wndCls, sizeof(wndCls));
296                 wndCls.lpfnWndProc        = DefWindowProc;
297                 wndCls.hInstance            = fgDisplay.Instance;
298                 wndCls.style                    = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
299                 wndCls.lpszClassName    = _T("FREEGLUT_dummy");
300         atom = RegisterClass( &wndCls );
301
302         hWnd=CreateWindow((LPCSTR)atom, _T(""), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW , 0,0,0,0, 0, 0, fgDisplay.Instance, 0 );
303         hDC=GetDC(hWnd);
304         SetPixelFormat( hDC, pixelformat, ppfd );
305         
306         rc = wglCreateContext( hDC );
307         wglMakeCurrent(hDC, rc);
308         
309         wglGetEntensionsStringARB=(PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
310         if (wglGetEntensionsStringARB)
311         {
312             const char * pWglExtString=wglGetEntensionsStringARB(hDC);
313             if (pWglExtString)
314             {
315                 if (strstr(pWglExtString, "WGL_ARB_multisample"))
316                 {
317                     int pAttributes[100];
318                     int iCounter=0;
319                     int iPixelFormat;
320                     BOOL bValid;
321                     float fAttributes[] = {0,0};
322                     UINT numFormats;
323                     PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARBProc=NULL;
324
325                     wglChoosePixelFormatARBProc=(PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
326                     if ( wglChoosePixelFormatARBProc )
327                     {
328                         pAttributes[iCounter++]=WGL_DRAW_TO_WINDOW_ARB;        pAttributes[iCounter++]=GL_TRUE;
329                         pAttributes[iCounter++]=WGL_SUPPORT_OPENGL_ARB;        pAttributes[iCounter++]=GL_TRUE;
330                         pAttributes[iCounter++]=WGL_ACCELERATION_ARB;        pAttributes[iCounter++]=WGL_FULL_ACCELERATION_ARB;
331
332                         pAttributes[iCounter++]=WGL_COLOR_BITS_ARB;            pAttributes[iCounter++]=pfd.cColorBits ;
333                         pAttributes[iCounter++]=WGL_ALPHA_BITS_ARB;            pAttributes[iCounter++]=pfd.cAlphaBits;
334                         pAttributes[iCounter++]=WGL_DEPTH_BITS_ARB;            pAttributes[iCounter++]=pfd.cDepthBits;
335                         pAttributes[iCounter++]=WGL_STENCIL_BITS_ARB;        pAttributes[iCounter++]=pfd.cStencilBits;
336
337                         pAttributes[iCounter++]=WGL_DOUBLE_BUFFER_ARB;        pAttributes[iCounter++]=(fgState.DisplayMode & GLUT_DOUBLE)!=0;
338                         pAttributes[iCounter++]=WGL_SAMPLE_BUFFERS_ARB;        pAttributes[iCounter++]=GL_TRUE;
339                         pAttributes[iCounter++]=WGL_SAMPLES_ARB;            pAttributes[iCounter++]=4;
340                         pAttributes[iCounter++]=0;                            pAttributes[iCounter++]=0;    /* terminator */
341
342                         bValid = wglChoosePixelFormatARBProc(window->Window.Device,pAttributes,fAttributes,1,&iPixelFormat,&numFormats);
343
344                         if (bValid && numFormats>0)
345                             pixelformat=iPixelFormat;
346                     }
347                 }
348                 wglMakeCurrent( hDC_before, rc_before);
349                 wglDeleteContext(rc);
350                 ReleaseDC(hWnd, hDC);
351                 DestroyWindow(hWnd);
352                 UnregisterClass(_T("FREEGLUT_dummy"), fgDisplay.Instance);
353             }
354         }
355     }
356
357     if( pixelformat == 0 )
358         return GL_FALSE;
359
360     if( checkOnly )
361         return GL_TRUE;
362     return SetPixelFormat( window->Window.Device, pixelformat, ppfd );
363 #endif /* defined(_WIN32_WCE) */
364 }
365 #endif /* TARGET_HOST_MS_WINDOWS */
366
367 /*
368  * Sets the OpenGL context and the fgStructure "Current Window" pointer to
369  * the window structure passed in.
370  */
371 void fgSetWindow ( SFG_Window *window )
372 {
373 #if TARGET_HOST_POSIX_X11
374     if ( window )
375         glXMakeCurrent(
376             fgDisplay.Display,
377             window->Window.Handle,
378             window->Window.Context
379         );
380 #elif TARGET_HOST_MS_WINDOWS
381     if( fgStructure.CurrentWindow )
382         ReleaseDC( fgStructure.CurrentWindow->Window.Handle,
383                    fgStructure.CurrentWindow->Window.Device );
384
385     if ( window )
386     {
387         window->Window.Device = GetDC( window->Window.Handle );
388         wglMakeCurrent(
389             window->Window.Device,
390             window->Window.Context
391         );
392     }
393 #endif
394     fgStructure.CurrentWindow = window;
395 }
396
397
398 /*
399  * Opens a window. Requires a SFG_Window object created and attached
400  * to the freeglut structure. OpenGL context is created here.
401  */
402 void fgOpenWindow( SFG_Window* window, const char* title,
403                    GLboolean positionUse, int x, int y,
404                    GLboolean sizeUse, int w, int h,
405                    GLboolean gameMode, GLboolean isSubWindow )
406 {
407 #if TARGET_HOST_POSIX_X11
408     XSetWindowAttributes winAttr;
409     XTextProperty textProperty;
410     XSizeHints sizeHints;
411     XWMHints wmHints;
412     unsigned long mask;
413     unsigned int current_DisplayMode = fgState.DisplayMode ;
414
415     /* Save the display mode if we are creating a menu window */
416     if( window->IsMenu && ( ! fgStructure.MenuContext ) )
417         fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ;
418
419     window->Window.VisualInfo = fgChooseVisual( );
420
421     if( window->IsMenu && ( ! fgStructure.MenuContext ) )
422         fgState.DisplayMode = current_DisplayMode ;
423
424     if( ! window->Window.VisualInfo )
425     {
426         /*
427          * The "fgChooseVisual" returned a null meaning that the visual
428          * context is not available.
429          * Try a couple of variations to see if they will work.
430          */
431         if( !( fgState.DisplayMode & GLUT_DOUBLE ) )
432         {
433             fgState.DisplayMode |= GLUT_DOUBLE ;
434             window->Window.VisualInfo = fgChooseVisual( );
435             fgState.DisplayMode &= ~GLUT_DOUBLE;
436         }
437
438         if( fgState.DisplayMode & GLUT_MULTISAMPLE )
439         {
440             fgState.DisplayMode &= ~GLUT_MULTISAMPLE ;
441             window->Window.VisualInfo = fgChooseVisual( );
442             fgState.DisplayMode |= GLUT_MULTISAMPLE;
443         }
444     }
445
446     FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.VisualInfo != NULL,
447                                   "Visual with necessary capabilities not found", "fgOpenWindow" );
448
449     /*
450      * XXX HINT: the masks should be updated when adding/removing callbacks.
451      * XXX       This might speed up message processing. Is that true?
452      * XXX
453      * XXX A: Not appreciably, but it WILL make it easier to debug.
454      * XXX    Try tracing old GLUT and try tracing freeglut.  Old GLUT
455      * XXX    turns off events that it doesn't need and is a whole lot
456      * XXX    more pleasant to trace.  (Think mouse-motion!  Tons of
457      * XXX    ``bonus'' GUI events stream in.)
458      */
459     winAttr.event_mask        =
460         StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
461         ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
462         VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
463         PointerMotionMask | ButtonMotionMask;
464     winAttr.background_pixmap = None;
465     winAttr.background_pixel  = 0;
466     winAttr.border_pixel      = 0;
467
468     winAttr.colormap = XCreateColormap(
469         fgDisplay.Display, fgDisplay.RootWindow,
470         window->Window.VisualInfo->visual, AllocNone
471     );
472
473     mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
474
475     if( window->IsMenu || ( gameMode == GL_TRUE ) )
476     {
477         winAttr.override_redirect = True;
478         mask |= CWOverrideRedirect;
479     }
480
481     if( ! positionUse )
482         x = y = -1; /* default window position */
483     if( ! sizeUse )
484         w = h = 300; /* default window size */
485
486     window->Window.Handle = XCreateWindow(
487         fgDisplay.Display,
488         window->Parent == NULL ? fgDisplay.RootWindow :
489         window->Parent->Window.Handle,
490         x, y, w, h, 0,
491         window->Window.VisualInfo->depth, InputOutput,
492         window->Window.VisualInfo->visual, mask,
493         &winAttr
494     );
495
496     /*
497      * The GLX context creation, possibly trying the direct context rendering
498      *  or else use the current context if the user has so specified
499      */
500     if( window->IsMenu )
501     {
502         /*
503          * If there isn't already an OpenGL rendering context for menu
504          * windows, make one
505          */
506         if( !fgStructure.MenuContext )
507         {
508             fgStructure.MenuContext =
509                 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
510             fgStructure.MenuContext->MVisualInfo = window->Window.VisualInfo;
511             fgStructure.MenuContext->MContext = glXCreateContext(
512                 fgDisplay.Display, fgStructure.MenuContext->MVisualInfo,
513                 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
514             );
515         }
516
517         /* window->Window.Context = fgStructure.MenuContext->MContext; */
518         window->Window.Context = glXCreateContext(
519             fgDisplay.Display, window->Window.VisualInfo,
520             NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
521         );
522     }
523     else if( fgState.UseCurrentContext )
524     {
525         window->Window.Context = glXGetCurrentContext( );
526
527         if( ! window->Window.Context )
528             window->Window.Context = glXCreateContext(
529                 fgDisplay.Display, window->Window.VisualInfo,
530                 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
531             );
532     }
533     else
534         window->Window.Context = glXCreateContext(
535             fgDisplay.Display, window->Window.VisualInfo,
536             NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
537         );
538
539 #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ )
540     if(  !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
541     {
542       if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
543         fgError( "Unable to force direct context rendering for window '%s'",
544                  title );
545       else if( fgState.DirectContext == GLUT_TRY_DIRECT_CONTEXT )
546         fgWarning( "Unable to create direct context rendering for window '%s'\nThis may hurt performance.",
547                  title );
548     }
549 #endif
550
551     /*
552      * XXX Assume the new window is visible by default
553      * XXX Is this a  safe assumption?
554      */
555     window->State.Visible = GL_TRUE;
556
557     sizeHints.flags = 0;
558     if ( positionUse )
559         sizeHints.flags |= USPosition;
560     if ( sizeUse )
561         sizeHints.flags |= USSize;
562
563     /*
564      * Fill in the size hints values now (the x, y, width and height
565      * settings are obsolete, are there any more WMs that support them?)
566      * Unless the X servers actually stop supporting these, we should
567      * continue to fill them in.  It is *not* our place to tell the user
568      * that they should replace a window manager that they like, and which
569      * works, just because *we* think that it's not "modern" enough.
570      */
571     sizeHints.x      = x;
572     sizeHints.y      = y;
573     sizeHints.width  = w;
574     sizeHints.height = h;
575
576     wmHints.flags = StateHint;
577     wmHints.initial_state = fgState.ForceIconic ? IconicState : NormalState;
578     /* Prepare the window and iconified window names... */
579     XStringListToTextProperty( (char **) &title, 1, &textProperty );
580
581     XSetWMProperties(
582         fgDisplay.Display,
583         window->Window.Handle,
584         &textProperty,
585         &textProperty,
586         0,
587         0,
588         &sizeHints,
589         &wmHints,
590         NULL
591     );
592     XFree( textProperty.value );
593
594     XSetWMProtocols( fgDisplay.Display, window->Window.Handle,
595                      &fgDisplay.DeleteWindow, 1 );
596
597     glXMakeCurrent(
598         fgDisplay.Display,
599         window->Window.Handle,
600         window->Window.Context
601     );
602
603     XMapWindow( fgDisplay.Display, window->Window.Handle );
604
605 #elif TARGET_HOST_MS_WINDOWS
606
607     WNDCLASS wc;
608     DWORD flags;
609     DWORD exFlags = 0;
610     ATOM atom;
611     int WindowStyle = 0;
612
613     /* Grab the window class we have registered on glutInit(): */
614     atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
615     FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Info Not Found",
616                                    "fgOpenWindow" );
617
618     if( gameMode )
619     {
620         FREEGLUT_INTERNAL_ERROR_EXIT ( window->Parent == NULL,
621                                        "Game mode being invoked on a subwindow",
622                                        "fgOpenWindow" );
623
624         /*
625          * Set the window creation flags appropriately to make the window
626          * entirely visible:
627          */
628         flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
629     }
630     else
631     {
632         int worig = w, horig = h;
633
634 #if !defined(_WIN32_WCE)
635         if ( ( ! isSubWindow ) && ( ! window->IsMenu ) )
636         {
637             /*
638              * Update the window dimensions, taking account of window
639              * decorations.  "freeglut" is to create the window with the
640              * outside of its border at (x,y) and with dimensions (w,h).
641              */
642             w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
643             h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 +
644                 GetSystemMetrics( SM_CYCAPTION );
645         }
646 #endif /* defined(_WIN32_WCE) */
647
648         if( ! positionUse )
649         {
650             x = CW_USEDEFAULT;
651             y = CW_USEDEFAULT;
652         }
653         /* setting State.Width/Height to call resize callback later */
654         if( ! sizeUse )
655         {
656             if( ! window->IsMenu )
657             {
658                 w = CW_USEDEFAULT;
659                 h = CW_USEDEFAULT;
660             }
661             else /* fail safe - Windows can make a window of size (0, 0) */
662                 w = h = 300; /* default window size */
663             window->State.Width = window->State.Height = -1;
664         }
665         else
666         {
667             window->State.Width = worig;
668             window->State.Height = horig;
669         }
670
671         /*
672          * There's a small difference between creating the top, child and
673          * game mode windows
674          */
675         flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
676
677         if ( window->IsMenu )
678         {
679             flags |= WS_POPUP;
680             exFlags |= WS_EX_TOOLWINDOW;
681         }
682 #if !defined(_WIN32_WCE)
683         else if( window->Parent == NULL )
684             flags |= WS_OVERLAPPEDWINDOW;
685 #endif
686         else
687             flags |= WS_CHILD;
688     }
689
690 #if defined(_WIN32_WCE)
691     {
692         wchar_t* wstr = fghWstrFromStr(title);
693
694         window->Window.Handle = CreateWindow(
695             _T("FREEGLUT"),
696             wstr,
697             WS_VISIBLE | WS_POPUP,
698             0,0, 240,320,
699             NULL,
700             NULL,
701             fgDisplay.Instance,
702             (LPVOID) window
703         );
704
705         free(wstr);
706
707         SHFullScreen(window->Window.Handle, SHFS_HIDESTARTICON);
708         SHFullScreen(window->Window.Handle, SHFS_HIDESIPBUTTON);
709         SHFullScreen(window->Window.Handle, SHFS_HIDETASKBAR);
710         MoveWindow(window->Window.Handle, 0, 0, 240, 320, TRUE);
711         ShowWindow(window->Window.Handle, SW_SHOW);
712         UpdateWindow(window->Window.Handle);
713     }
714 #else
715     window->Window.Handle = CreateWindowEx(
716         exFlags,
717         _T("FREEGLUT"),
718         title,
719         flags,
720         x, y, w, h,
721         (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
722         (HMENU) NULL,
723         fgDisplay.Instance,
724         (LPVOID) window
725     );
726 #endif /* defined(_WIN32_WCE) */
727
728     if( !( window->Window.Handle ) )
729         fgError( "Failed to create a window (%s)!", title );
730
731     /* Make a menu window always on top - fix Feature Request 947118 */
732     if( window->IsMenu || gameMode )
733         SetWindowPos(
734                         window->Window.Handle,
735                         HWND_TOPMOST,
736                         0, 0, 0, 0,
737                         SWP_NOMOVE | SWP_NOSIZE
738                     );
739
740     /* Hack to remove the caption (title bar) and/or border
741      * and all the system menu controls.
742      */
743     WindowStyle = GetWindowLong(window->Window.Handle, GWL_STYLE);
744     if ( fgState.DisplayMode & GLUT_CAPTIONLESS )
745     {
746         SetWindowLong ( window->Window.Handle, GWL_STYLE,
747                         WindowStyle & ~(WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX));
748     }
749     else if ( fgState.DisplayMode & GLUT_BORDERLESS )
750     {
751         SetWindowLong ( window->Window.Handle, GWL_STYLE,
752                         WindowStyle & ~(WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX));
753     }
754 //SetWindowPos(window->Window.Handle, NULL, 0, 0, 0, 0,
755 //   SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
756
757
758 #if defined(_WIN32_WCE)
759     ShowWindow( window->Window.Handle, SW_SHOW );
760 #else
761     ShowWindow( window->Window.Handle,
762                 fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
763 #endif /* defined(_WIN32_WCE) */
764
765     UpdateWindow( window->Window.Handle );
766     ShowCursor( TRUE );  /* XXX Old comments say "hide cursor"! */
767
768 #endif
769
770     fgSetWindow( window );
771
772     window->Window.DoubleBuffered =
773         ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
774
775     if ( ! window->Window.DoubleBuffered )
776     {
777         glDrawBuffer ( GL_FRONT );
778         glReadBuffer ( GL_FRONT );
779     }
780 }
781
782 /*
783  * Closes a window, destroying the frame and OpenGL context
784  */
785 void fgCloseWindow( SFG_Window* window )
786 {
787 #if TARGET_HOST_POSIX_X11
788
789     glXDestroyContext( fgDisplay.Display, window->Window.Context );
790     XFree( window->Window.VisualInfo );
791     XDestroyWindow( fgDisplay.Display, window->Window.Handle );
792     XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
793
794 #elif TARGET_HOST_MS_WINDOWS
795
796     /* Make sure we don't close a window with current context active */
797     if( fgStructure.CurrentWindow == window )
798         wglMakeCurrent( NULL, NULL );
799
800     /*
801      * Step through the list of windows.  If the rendering context
802      * is not being used by another window, then we delete it.
803      */
804     {
805         int used = FALSE ;
806         SFG_Window *iter ;
807
808         for( iter = (SFG_Window *)fgStructure.Windows.First;
809              iter;
810              iter = (SFG_Window *)iter->Node.Next )
811         {
812             if( ( iter->Window.Context == window->Window.Context ) &&
813                 ( iter != window ) )
814                 used = TRUE;
815         }
816
817         if( ! used )
818             wglDeleteContext( window->Window.Context );
819     }
820
821     DestroyWindow( window->Window.Handle );
822 #endif
823 }
824
825
826 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
827
828 /*
829  * Creates a new top-level freeglut window
830  */
831 int FGAPIENTRY glutCreateWindow( const char* title )
832 {
833     /* XXX GLUT does not exit; it simply calls "glutInit" quietly if the
834      * XXX application has not already done so.  The "freeglut" community
835      * XXX decided not to go this route (freeglut-developer e-mail from
836      * XXX Steve Baker, 12/16/04, 4:22 PM CST, "Re: [Freeglut-developer]
837      * XXX Desired 'freeglut' behaviour when there is no current window"
838      */
839     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateWindow" );
840
841     return fgCreateWindow( NULL, title, fgState.Position.Use,
842                            fgState.Position.X, fgState.Position.Y,
843                            fgState.Size.Use, fgState.Size.X, fgState.Size.Y,
844                            GL_FALSE, GL_FALSE )->ID;
845 }
846
847 /*
848  * This function creates a sub window.
849  */
850 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
851 {
852     int ret = 0;
853     SFG_Window* window = NULL;
854     SFG_Window* parent = NULL;
855
856     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateSubWindow" );
857     parent = fgWindowByID( parentID );
858     freeglut_return_val_if_fail( parent != NULL, 0 );
859     if ( x < 0 )
860     {
861         x = parent->State.Width + x ;
862         if ( w >= 0 ) x -= w ;
863     }
864
865     if ( w < 0 ) w = parent->State.Width - x + w ;
866     if ( w < 0 )
867     {
868         x += w ;
869         w = -w ;
870     }
871
872     if ( y < 0 )
873     {
874         y = parent->State.Height + y ;
875         if ( h >= 0 ) y -= h ;
876     }
877
878     if ( h < 0 ) h = parent->State.Height - y + h ;
879     if ( h < 0 )
880     {
881         y += h ;
882         h = -h ;
883     }
884
885     window = fgCreateWindow( parent, "", GL_TRUE, x, y, GL_TRUE, w, h, GL_FALSE, GL_FALSE );
886     ret = window->ID;
887
888     return ret;
889 }
890
891 /*
892  * Destroys a window and all of its subwindows
893  */
894 void FGAPIENTRY glutDestroyWindow( int windowID )
895 {
896     SFG_Window* window;
897     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDestroyWindow" );
898     window = fgWindowByID( windowID );
899     freeglut_return_if_fail( window != NULL );
900     {
901         fgExecutionState ExecState = fgState.ExecState;
902         fgAddToWindowDestroyList( window );
903         fgState.ExecState = ExecState;
904     }
905 }
906
907 /*
908  * This function selects the current window
909  */
910 void FGAPIENTRY glutSetWindow( int ID )
911 {
912     SFG_Window* window = NULL;
913
914     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindow" );
915     if( fgStructure.CurrentWindow != NULL )
916         if( fgStructure.CurrentWindow->ID == ID )
917             return;
918
919     window = fgWindowByID( ID );
920     if( window == NULL )
921     {
922         fgWarning( "glutSetWindow(): window ID %d not found!", ID );
923         return;
924     }
925
926     fgSetWindow( window );
927 }
928
929 /*
930  * This function returns the ID number of the current window, 0 if none exists
931  */
932 int FGAPIENTRY glutGetWindow( void )
933 {
934     SFG_Window *win = fgStructure.CurrentWindow;
935     /*
936      * Since GLUT did not throw an error if this function was called without a prior call to
937      * "glutInit", this function shouldn't do so here.  Instead let us return a zero.
938      * See Feature Request "[ 1307049 ] glutInit check".
939      */
940     if ( ! fgState.Initialised )
941         return 0;
942
943     while ( win && win->IsMenu )
944         win = win->Parent;
945     return win ? win->ID : 0;
946 }
947
948 /*
949  * This function makes the current window visible
950  */
951 void FGAPIENTRY glutShowWindow( void )
952 {
953     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" );
954     FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" );
955
956 #if TARGET_HOST_POSIX_X11
957
958     XMapWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
959     XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
960
961 #elif TARGET_HOST_MS_WINDOWS
962
963     ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_SHOW );
964
965 #endif
966
967     fgStructure.CurrentWindow->State.Redisplay = GL_TRUE;
968 }
969
970 /*
971  * This function hides the current window
972  */
973 void FGAPIENTRY glutHideWindow( void )
974 {
975     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" );
976     FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" );
977
978 #if TARGET_HOST_POSIX_X11
979
980     if( fgStructure.CurrentWindow->Parent == NULL )
981         XWithdrawWindow( fgDisplay.Display,
982                          fgStructure.CurrentWindow->Window.Handle,
983                          fgDisplay.Screen );
984     else
985         XUnmapWindow( fgDisplay.Display,
986                       fgStructure.CurrentWindow->Window.Handle );
987     XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
988
989 #elif TARGET_HOST_MS_WINDOWS
990
991     ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_HIDE );
992
993 #endif
994
995     fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
996 }
997
998 /*
999  * Iconify the current window (top-level windows only)
1000  */
1001 void FGAPIENTRY glutIconifyWindow( void )
1002 {
1003     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" );
1004     FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" );
1005
1006     fgStructure.CurrentWindow->State.Visible   = GL_FALSE;
1007 #if TARGET_HOST_POSIX_X11
1008
1009     XIconifyWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
1010                     fgDisplay.Screen );
1011     XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1012
1013 #elif TARGET_HOST_MS_WINDOWS
1014
1015     ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_MINIMIZE );
1016
1017 #endif
1018
1019     fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
1020 }
1021
1022 /*
1023  * Set the current window's title
1024  */
1025 void FGAPIENTRY glutSetWindowTitle( const char* title )
1026 {
1027     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowTitle" );
1028     FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" );
1029     if( ! fgStructure.CurrentWindow->Parent )
1030     {
1031 #if TARGET_HOST_POSIX_X11
1032
1033         XTextProperty text;
1034
1035         text.value = (unsigned char *) title;
1036         text.encoding = XA_STRING;
1037         text.format = 8;
1038         text.nitems = strlen( title );
1039
1040         XSetWMName(
1041             fgDisplay.Display,
1042             fgStructure.CurrentWindow->Window.Handle,
1043             &text
1044         );
1045
1046         XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1047
1048 #elif TARGET_HOST_MS_WINDOWS
1049 #    ifdef _WIN32_WCE
1050         {
1051             wchar_t* wstr = fghWstrFromStr(title);
1052             SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
1053             free(wstr);
1054         }
1055 #    else
1056         SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
1057 #    endif
1058
1059 #endif
1060     }
1061 }
1062
1063 /*
1064  * Set the current window's iconified title
1065  */
1066 void FGAPIENTRY glutSetIconTitle( const char* title )
1067 {
1068     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" );
1069     FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" );
1070
1071     if( ! fgStructure.CurrentWindow->Parent )
1072     {
1073 #if TARGET_HOST_POSIX_X11
1074
1075         XTextProperty text;
1076
1077         text.value = (unsigned char *) title;
1078         text.encoding = XA_STRING;
1079         text.format = 8;
1080         text.nitems = strlen( title );
1081
1082         XSetWMIconName(
1083             fgDisplay.Display,
1084             fgStructure.CurrentWindow->Window.Handle,
1085             &text
1086         );
1087
1088         XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1089
1090 #elif TARGET_HOST_MS_WINDOWS
1091 #    ifdef _WIN32_WCE
1092         {
1093             wchar_t* wstr = fghWstrFromStr(title);
1094             SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
1095             free(wstr);
1096         }
1097 #    else
1098         SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
1099 #    endif
1100
1101 #endif
1102     }
1103 }
1104
1105 /*
1106  * Change the current window's size
1107  */
1108 void FGAPIENTRY glutReshapeWindow( int width, int height )
1109 {
1110     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" );
1111     FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" );
1112
1113     fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
1114     fgStructure.CurrentWindow->State.Width  = width ;
1115     fgStructure.CurrentWindow->State.Height = height;
1116 }
1117
1118 /*
1119  * Change the current window's position
1120  */
1121 void FGAPIENTRY glutPositionWindow( int x, int y )
1122 {
1123     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" );
1124     FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" );
1125
1126 #if TARGET_HOST_POSIX_X11
1127
1128     XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
1129                  x, y );
1130     XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1131
1132 #elif TARGET_HOST_MS_WINDOWS
1133
1134     {
1135         RECT winRect;
1136
1137         /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
1138         GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
1139         MoveWindow(
1140             fgStructure.CurrentWindow->Window.Handle,
1141             x,
1142             y,
1143             winRect.right - winRect.left,
1144             winRect.bottom - winRect.top,
1145             TRUE
1146         );
1147     }
1148
1149 #endif
1150 }
1151
1152 /*
1153  * Lowers the current window (by Z order change)
1154  */
1155 void FGAPIENTRY glutPushWindow( void )
1156 {
1157     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPushWindow" );
1158     FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPushWindow" );
1159
1160 #if TARGET_HOST_POSIX_X11
1161
1162     XLowerWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1163
1164 #elif TARGET_HOST_MS_WINDOWS
1165
1166     SetWindowPos(
1167         fgStructure.CurrentWindow->Window.Handle,
1168         HWND_BOTTOM,
1169         0, 0, 0, 0,
1170         SWP_NOSIZE | SWP_NOMOVE
1171     );
1172
1173 #endif
1174 }
1175
1176 /*
1177  * Raises the current window (by Z order change)
1178  */
1179 void FGAPIENTRY glutPopWindow( void )
1180 {
1181     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" );
1182     FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" );
1183
1184 #if TARGET_HOST_POSIX_X11
1185
1186     XRaiseWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1187
1188 #elif TARGET_HOST_MS_WINDOWS
1189
1190     SetWindowPos(
1191         fgStructure.CurrentWindow->Window.Handle,
1192         HWND_TOP,
1193         0, 0, 0, 0,
1194         SWP_NOSIZE | SWP_NOMOVE
1195     );
1196
1197 #endif
1198 }
1199
1200 /*
1201  * Resize the current window so that it fits the whole screen
1202  */
1203 void FGAPIENTRY glutFullScreen( void )
1204 {
1205     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" );
1206     FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" );
1207
1208     {
1209 #if TARGET_HOST_POSIX_X11
1210         int x, y;
1211         Window w;
1212
1213         XMoveResizeWindow(
1214             fgDisplay.Display,
1215             fgStructure.CurrentWindow->Window.Handle,
1216             0, 0,
1217             fgDisplay.ScreenWidth,
1218             fgDisplay.ScreenHeight
1219         );
1220
1221         XFlush( fgDisplay.Display ); /* This is needed */
1222
1223         XTranslateCoordinates(
1224             fgDisplay.Display,
1225             fgStructure.CurrentWindow->Window.Handle,
1226             fgDisplay.RootWindow,
1227             0, 0, &x, &y, &w
1228         );
1229
1230         if (x || y)
1231         {
1232             XMoveWindow(
1233                 fgDisplay.Display,
1234                 fgStructure.CurrentWindow->Window.Handle,
1235                 -x, -y
1236             );
1237             XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1238         }
1239 #elif TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: what about WinCE */
1240         RECT rect;
1241
1242         /* For fullscreen mode, force the top-left corner to 0,0
1243          * and adjust the window rectangle so that the client area
1244          * covers the whole screen.
1245          */
1246
1247         rect.left   = 0;
1248         rect.top    = 0;
1249         rect.right  = fgDisplay.ScreenWidth;
1250         rect.bottom = fgDisplay.ScreenHeight;
1251
1252         AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
1253                                   WS_CLIPCHILDREN, FALSE );
1254
1255         /*
1256          * SWP_NOACTIVATE     Do not activate the window
1257          * SWP_NOOWNERZORDER  Do not change position in z-order
1258          * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
1259          * SWP_NOZORDER       Retains the current Z order (ignore 2nd param)
1260          */
1261
1262         SetWindowPos( fgStructure.CurrentWindow->Window.Handle,
1263                       HWND_TOP,
1264                       rect.left,
1265                       rect.top,
1266                       rect.right  - rect.left,
1267                       rect.bottom - rect.top,
1268                       SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
1269                       SWP_NOZORDER
1270                     );
1271 #endif
1272     }
1273 }
1274
1275 /*
1276  * A.Donev: Set and retrieve the window's user data
1277  */
1278 void* FGAPIENTRY glutGetWindowData( void )
1279 {
1280     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindowData" );
1281     FREEGLUT_EXIT_IF_NO_WINDOW ( "glutGetWindowData" );
1282     return fgStructure.CurrentWindow->UserData;
1283 }
1284
1285 void FGAPIENTRY glutSetWindowData(void* data)
1286 {
1287     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowData" );
1288     FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowData" );
1289     fgStructure.CurrentWindow->UserData = data;
1290 }
1291
1292 /*** END OF FILE ***/