Splitting the platform-specific "fgSystemTime" code into its own functions
[freeglut] / src / mswin / freeglut_window_mswin.c
1 /*\r
2  * freeglut_window_mswin.c\r
3  *\r
4  * The Windows-specific mouse cursor related stuff.\r
5  *\r
6  * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.\r
7  * Written by John F. Fay, <fayjf@sourceforge.net>\r
8  * Creation date: Sun Jan 22, 2012\r
9  *\r
10  * Permission is hereby granted, free of charge, to any person obtaining a\r
11  * copy of this software and associated documentation files (the "Software"),\r
12  * to deal in the Software without restriction, including without limitation\r
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
14  * and/or sell copies of the Software, and to permit persons to whom the\r
15  * Software is furnished to do so, subject to the following conditions:\r
16  *\r
17  * The above copyright notice and this permission notice shall be included\r
18  * in all copies or substantial portions of the Software.\r
19  *\r
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
23  * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
24  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
25  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
26  */\r
27 \r
28 #include <GL/freeglut.h>\r
29 #include "../Common/freeglut_internal.h"\r
30 \r
31 \r
32 /* The following include file is available from SGI but is not standard:\r
33  *   #include <GL/wglext.h>\r
34  * So we copy the necessary parts out of it.\r
35  * XXX: should local definitions for extensions be put in a separate include file?\r
36  */\r
37 typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);\r
38 \r
39 typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);\r
40 \r
41 #define WGL_DRAW_TO_WINDOW_ARB         0x2001\r
42 #define WGL_ACCELERATION_ARB           0x2003\r
43 #define WGL_SUPPORT_OPENGL_ARB         0x2010\r
44 #define WGL_DOUBLE_BUFFER_ARB          0x2011\r
45 #define WGL_COLOR_BITS_ARB             0x2014\r
46 #define WGL_ALPHA_BITS_ARB             0x201B\r
47 #define WGL_DEPTH_BITS_ARB             0x2022\r
48 #define WGL_STENCIL_BITS_ARB           0x2023\r
49 #define WGL_FULL_ACCELERATION_ARB      0x2027\r
50 \r
51 #define WGL_SAMPLE_BUFFERS_ARB         0x2041\r
52 #define WGL_SAMPLES_ARB                0x2042\r
53 \r
54 #define WGL_TYPE_RGBA_FLOAT_ARB        0x21A0\r
55 \r
56 #define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9\r
57 \r
58 #ifndef WGL_ARB_create_context\r
59 #define WGL_ARB_create_context 1\r
60 #ifdef WGL_WGLEXT_PROTOTYPES\r
61 extern HGLRC WINAPI wglCreateContextAttribsARB (HDC, HGLRC, const int *);\r
62 #endif /* WGL_WGLEXT_PROTOTYPES */\r
63 typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList);\r
64 \r
65 #define WGL_CONTEXT_MAJOR_VERSION_ARB  0x2091\r
66 #define WGL_CONTEXT_MINOR_VERSION_ARB  0x2092\r
67 #define WGL_CONTEXT_LAYER_PLANE_ARB    0x2093\r
68 #define WGL_CONTEXT_FLAGS_ARB          0x2094\r
69 #define WGL_CONTEXT_PROFILE_MASK_ARB   0x9126\r
70 \r
71 #define WGL_CONTEXT_DEBUG_BIT_ARB      0x0001\r
72 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002\r
73 \r
74 #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001\r
75 #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002\r
76 \r
77 #define ERROR_INVALID_VERSION_ARB      0x2095\r
78 #define ERROR_INVALID_PROFILE_ARB      0x2096\r
79 #endif\r
80 /* End of copying the necessary parts out of it. */\r
81 \r
82 /* pushing attribute/value pairs into an array */\r
83 #define ATTRIB(a) attributes[where++]=(a)\r
84 #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);}\r
85 \r
86 \r
87 extern int fghIsLegacyContextVersionRequested( void );\r
88 extern int fghMapBit( int mask, int from, int to );\r
89 extern int fghIsLegacyContextRequested( void );\r
90 extern void fghContextCreationError( void );\r
91 extern int fghNumberOfAuxBuffersRequested( void );\r
92 \r
93 #ifdef WM_TOUCH\r
94 typedef BOOL (WINAPI *pRegisterTouchWindow)(HWND,ULONG);\r
95 static pRegisterTouchWindow fghRegisterTouchWindow = (pRegisterTouchWindow)0xDEADBEEF;\r
96 #endif\r
97 \r
98 /* \r
99  * Helper functions for getting client area from the window rect\r
100  * and the window rect from the client area given the style of the window\r
101  * (or a valid window pointer from which the style can be queried).\r
102  */\r
103 extern void fghGetBorderWidth(const DWORD windowStyle, int* xBorderWidth, int* yBorderWidth);\r
104 \r
105 \r
106 /*\r
107  * Setup the pixel format for a Win32 window\r
108  */\r
109 \r
110 #if defined(_WIN32_WCE)\r
111 static wchar_t* fghWstrFromStr(const char* str)\r
112 {\r
113     int i,len=strlen(str);\r
114     wchar_t* wstr = (wchar_t*)malloc(2*len+2);\r
115     for(i=0; i<len; i++)\r
116         wstr[i] = str[i];\r
117     wstr[len] = 0;\r
118     return wstr;\r
119 }\r
120 #endif /* defined(_WIN32_WCE) */\r
121 \r
122 \r
123 static void fghFillContextAttributes( int *attributes ) {\r
124   int where = 0, contextFlags, contextProfile;\r
125 \r
126   if ( !fghIsLegacyContextVersionRequested() ) {\r
127     ATTRIB_VAL( WGL_CONTEXT_MAJOR_VERSION_ARB, fgState.MajorVersion );\r
128     ATTRIB_VAL( WGL_CONTEXT_MINOR_VERSION_ARB, fgState.MinorVersion );\r
129   }\r
130 \r
131   contextFlags =\r
132     fghMapBit( fgState.ContextFlags, GLUT_DEBUG, WGL_CONTEXT_DEBUG_BIT_ARB ) |\r
133     fghMapBit( fgState.ContextFlags, GLUT_FORWARD_COMPATIBLE, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB );\r
134   if ( contextFlags != 0 ) {\r
135     ATTRIB_VAL( WGL_CONTEXT_FLAGS_ARB, contextFlags );\r
136   }\r
137 \r
138   contextProfile =\r
139     fghMapBit( fgState.ContextProfile, GLUT_CORE_PROFILE, WGL_CONTEXT_CORE_PROFILE_BIT_ARB ) |\r
140     fghMapBit( fgState.ContextProfile, GLUT_COMPATIBILITY_PROFILE, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB );\r
141   if ( contextProfile != 0 ) {\r
142     ATTRIB_VAL( WGL_CONTEXT_PROFILE_MASK_ARB, contextProfile );\r
143   }\r
144 \r
145   ATTRIB( 0 );\r
146 }\r
147 \r
148 static int fghIsExtensionSupported( HDC hdc, const char *extension ) {\r
149     const char *pWglExtString;\r
150     PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetEntensionsStringARB =\r
151       (PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB");\r
152     if ( wglGetEntensionsStringARB == NULL )\r
153     {\r
154       return FALSE;\r
155     }\r
156     pWglExtString = wglGetEntensionsStringARB( hdc );\r
157     return ( pWglExtString != NULL ) && ( strstr(pWglExtString, extension) != NULL );\r
158 }\r
159 \r
160 void fgNewWGLCreateContext( SFG_Window* window )\r
161 {\r
162     HGLRC context;\r
163     int attributes[9];\r
164     PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;\r
165 \r
166     /* If nothing fancy has been required, leave the context as it is */\r
167     if ( fghIsLegacyContextRequested() )\r
168     {\r
169         return;\r
170     }\r
171 \r
172     wglMakeCurrent( window->Window.pContext.Device, window->Window.Context );\r
173 \r
174     if ( !fghIsExtensionSupported( window->Window.pContext.Device, "WGL_ARB_create_context" ) )\r
175     {\r
176         return;\r
177     }\r
178 \r
179     /* new context creation */\r
180     fghFillContextAttributes( attributes );\r
181 \r
182     wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress( "wglCreateContextAttribsARB" );\r
183     if ( wglCreateContextAttribsARB == NULL )\r
184     {\r
185         fgError( "wglCreateContextAttribsARB not found" );\r
186     }\r
187 \r
188     context = wglCreateContextAttribsARB( window->Window.pContext.Device, 0, attributes );\r
189     if ( context == NULL )\r
190     {\r
191         fghContextCreationError();\r
192     }\r
193 \r
194     wglMakeCurrent( NULL, NULL );\r
195     wglDeleteContext( window->Window.Context );\r
196     window->Window.Context = context;\r
197 }\r
198 \r
199 #if !defined(_WIN32_WCE)\r
200 \r
201 static void fghFillPFD( PIXELFORMATDESCRIPTOR *ppfd, HDC hdc, unsigned char layer_type )\r
202 {\r
203   int flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;\r
204   if ( fgState.DisplayMode & GLUT_DOUBLE ) {\r
205         flags |= PFD_DOUBLEBUFFER;\r
206   }\r
207   if ( fgState.DisplayMode & GLUT_STEREO ) {\r
208     flags |= PFD_STEREO;\r
209   }\r
210 \r
211 #if defined(_MSC_VER)\r
212 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )\r
213 #endif\r
214 \r
215   /* Specify which pixel format do we opt for... */\r
216   ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);\r
217   ppfd->nVersion = 1;\r
218   ppfd->dwFlags = flags;\r
219 \r
220   if( fgState.DisplayMode & GLUT_INDEX ) {\r
221     ppfd->iPixelType = PFD_TYPE_COLORINDEX;\r
222     ppfd->cRedBits = 0;\r
223     ppfd->cGreenBits = 0;\r
224     ppfd->cBlueBits = 0;\r
225     ppfd->cAlphaBits = 0;\r
226   } else {\r
227     ppfd->iPixelType = PFD_TYPE_RGBA;\r
228     ppfd->cRedBits = 8;\r
229     ppfd->cGreenBits = 8;\r
230     ppfd->cBlueBits = 8;\r
231     ppfd->cAlphaBits = ( fgState.DisplayMode & GLUT_ALPHA ) ? 8 : 0;\r
232   }\r
233 \r
234   ppfd->cColorBits = 24;\r
235   ppfd->cRedShift = 0;\r
236   ppfd->cGreenShift = 0;\r
237   ppfd->cBlueShift = 0;\r
238   ppfd->cAlphaShift = 0;\r
239   ppfd->cAccumBits = ( fgState.DisplayMode & GLUT_ACCUM ) ? 1 : 0;\r
240   ppfd->cAccumRedBits = 0;\r
241   ppfd->cAccumGreenBits = 0;\r
242   ppfd->cAccumBlueBits = 0;\r
243   ppfd->cAccumAlphaBits = 0;\r
244 \r
245   /* Hmmm, or 32/0 instead of 24/8? */\r
246   ppfd->cDepthBits = 24;\r
247   ppfd->cStencilBits = 8;\r
248 \r
249   ppfd->cAuxBuffers = fghNumberOfAuxBuffersRequested();\r
250   ppfd->iLayerType = layer_type;\r
251   ppfd->bReserved = 0;\r
252   ppfd->dwLayerMask = 0;\r
253   ppfd->dwVisibleMask = 0;\r
254   ppfd->dwDamageMask = 0;\r
255   \r
256   ppfd->cColorBits = (BYTE) GetDeviceCaps( hdc, BITSPIXEL );\r
257 }\r
258 \r
259 static void fghFillPixelFormatAttributes( int *attributes, const PIXELFORMATDESCRIPTOR *ppfd )\r
260 {\r
261   int where = 0;\r
262 \r
263   ATTRIB_VAL( WGL_DRAW_TO_WINDOW_ARB, GL_TRUE );\r
264   ATTRIB_VAL( WGL_SUPPORT_OPENGL_ARB, GL_TRUE );\r
265   ATTRIB_VAL( WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB );\r
266 \r
267   ATTRIB_VAL( WGL_COLOR_BITS_ARB, ppfd->cColorBits );\r
268   ATTRIB_VAL( WGL_ALPHA_BITS_ARB, ppfd->cAlphaBits );\r
269   ATTRIB_VAL( WGL_DEPTH_BITS_ARB, ppfd->cDepthBits );\r
270   ATTRIB_VAL( WGL_STENCIL_BITS_ARB, ppfd->cStencilBits );\r
271 \r
272   ATTRIB_VAL( WGL_DOUBLE_BUFFER_ARB, ( fgState.DisplayMode & GLUT_DOUBLE ) != 0 );\r
273 \r
274   if ( fgState.DisplayMode & GLUT_SRGB ) {\r
275     ATTRIB_VAL( WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, TRUE );\r
276   }\r
277 \r
278   ATTRIB_VAL( WGL_SAMPLE_BUFFERS_ARB, GL_TRUE );\r
279   ATTRIB_VAL( WGL_SAMPLES_ARB, fgState.SampleNumber );\r
280   ATTRIB( 0 );\r
281 }\r
282 #endif\r
283 \r
284 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,\r
285                               unsigned char layer_type )\r
286 {\r
287 #if defined(_WIN32_WCE)\r
288     return GL_TRUE;\r
289 #else\r
290     PIXELFORMATDESCRIPTOR pfd;\r
291     PIXELFORMATDESCRIPTOR* ppfd = &pfd;\r
292     int pixelformat;\r
293     HDC current_hDC;\r
294     GLboolean success;\r
295 \r
296     if (checkOnly)\r
297       current_hDC = CreateDC(TEXT("DISPLAY"), NULL ,NULL ,NULL);\r
298     else\r
299       current_hDC = window->Window.pContext.Device;\r
300 \r
301     fghFillPFD( ppfd, current_hDC, layer_type );\r
302     pixelformat = ChoosePixelFormat( current_hDC, ppfd );\r
303 \r
304     /* windows hack for multismapling/sRGB */\r
305     if ( ( fgState.DisplayMode & GLUT_MULTISAMPLE ) ||\r
306          ( fgState.DisplayMode & GLUT_SRGB ) )\r
307     {        \r
308         HGLRC rc, rc_before=wglGetCurrentContext();\r
309         HWND hWnd;\r
310         HDC hDC, hDC_before=wglGetCurrentDC();\r
311         WNDCLASS wndCls;\r
312 \r
313         /* create a dummy window */\r
314         ZeroMemory(&wndCls, sizeof(wndCls));\r
315         wndCls.lpfnWndProc = DefWindowProc;\r
316         wndCls.hInstance = fgDisplay.pDisplay.Instance;\r
317         wndCls.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;\r
318         wndCls.lpszClassName = _T("FREEGLUT_dummy");\r
319         RegisterClass( &wndCls );\r
320 \r
321         hWnd=CreateWindow(_T("FREEGLUT_dummy"), _T(""), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW , 0,0,0,0, 0, 0, fgDisplay.pDisplay.Instance, 0 );\r
322         hDC=GetDC(hWnd);\r
323         SetPixelFormat( hDC, pixelformat, ppfd );\r
324 \r
325         rc = wglCreateContext( hDC );\r
326         wglMakeCurrent(hDC, rc);\r
327 \r
328         if ( fghIsExtensionSupported( hDC, "WGL_ARB_multisample" ) )\r
329         {\r
330             PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARBProc =\r
331               (PFNWGLCHOOSEPIXELFORMATARBPROC) wglGetProcAddress("wglChoosePixelFormatARB");\r
332             if ( wglChoosePixelFormatARBProc )\r
333             {\r
334                 int attributes[100];\r
335                 int iPixelFormat;\r
336                 BOOL bValid;\r
337                 float fAttributes[] = { 0, 0 };\r
338                 UINT numFormats;\r
339                 fghFillPixelFormatAttributes( attributes, ppfd );\r
340                 bValid = wglChoosePixelFormatARBProc(hDC, attributes, fAttributes, 1, &iPixelFormat, &numFormats);\r
341 \r
342                 if ( bValid && numFormats > 0 )\r
343                 {\r
344                     pixelformat = iPixelFormat;\r
345                 }\r
346             }\r
347         }\r
348 \r
349         wglMakeCurrent( hDC_before, rc_before);\r
350         wglDeleteContext(rc);\r
351         ReleaseDC(hWnd, hDC);\r
352         DestroyWindow(hWnd);\r
353         UnregisterClass(_T("FREEGLUT_dummy"), fgDisplay.pDisplay.Instance);\r
354     }\r
355 \r
356     success = ( pixelformat != 0 ) && ( checkOnly || SetPixelFormat( current_hDC, pixelformat, ppfd ) );\r
357 \r
358     if (checkOnly)\r
359         DeleteDC(current_hDC);\r
360 \r
361     return success;\r
362 #endif /* defined(_WIN32_WCE) */\r
363 }\r
364 \r
365 \r
366 \r
367 void fgPlatformSetWindow ( SFG_Window *window )\r
368 {\r
369     if ( window != fgStructure.CurrentWindow )\r
370     {\r
371         if( fgStructure.CurrentWindow )\r
372             ReleaseDC( fgStructure.CurrentWindow->Window.Handle,\r
373                        fgStructure.CurrentWindow->Window.pContext.Device );\r
374 \r
375         if ( window )\r
376         {\r
377             window->Window.pContext.Device = GetDC( window->Window.Handle );\r
378             wglMakeCurrent(\r
379                 window->Window.pContext.Device,\r
380                 window->Window.Context\r
381             );\r
382         }\r
383     }\r
384 }\r
385 \r
386 \r
387 \r
388 /* Computes position of corners of window Rect (outer position including\r
389  * decorations) based on the provided client rect and based on the style\r
390  * of the window in question.\r
391  * If posIsOutside is set to true, the input client Rect is taken to follow\r
392  * freeGLUT's window specification convention in which the top-left corner\r
393  * is at the outside of the window, while the size\r
394  * (rect.right-rect.left,rect.bottom-rect.top) is the size of the drawable\r
395  * area.\r
396  */\r
397 void fghComputeWindowRectFromClientArea_UseStyle( const DWORD windowStyle, RECT *clientRect, BOOL posIsOutside )\r
398 {\r
399     int xBorderWidth = 0, yBorderWidth = 0;\r
400 \r
401     /* If window has title bar, correct rect for it */\r
402     if (windowStyle & WS_MAXIMIZEBOX) /* Need to query for WS_MAXIMIZEBOX to see if we have a title bar, the WS_CAPTION query is also true for a WS_DLGFRAME only... */\r
403         if (posIsOutside)\r
404             clientRect->bottom += GetSystemMetrics( SM_CYCAPTION );\r
405         else\r
406             clientRect->top -= GetSystemMetrics( SM_CYCAPTION );\r
407 \r
408     /* get width of window's borders (frame), correct rect for it.\r
409      * Note, borders can be of zero width if style does not specify borders\r
410      */\r
411     fghGetBorderWidth(windowStyle, &xBorderWidth, &yBorderWidth);\r
412     if (posIsOutside)\r
413     {\r
414         clientRect->right  += xBorderWidth * 2;\r
415         clientRect->bottom += yBorderWidth * 2;\r
416     }\r
417     else\r
418     {\r
419         clientRect->left   -= xBorderWidth;\r
420         clientRect->right  += xBorderWidth;\r
421         clientRect->top    -= yBorderWidth;\r
422         clientRect->bottom += yBorderWidth;\r
423     }\r
424 }\r
425 \r
426 /* Computes position of corners of window Rect (outer position including\r
427  * decorations) based on the provided client rect and based on the style\r
428  * of the window in question. If the window pointer or the window handle\r
429  * is NULL, a fully decorated window (caption and border) is assumed.\r
430  * Furthermore, if posIsOutside is set to true, the input client Rect is\r
431  * taken to follow freeGLUT's window specification convention in which the\r
432  * top-left corner is at the outside of the window, while the size\r
433  * (rect.right-rect.left,rect.bottom-rect.top) is the size of the drawable\r
434  * area.\r
435 */\r
436 void fghComputeWindowRectFromClientArea_QueryWindow( const SFG_Window *window, RECT *clientRect, BOOL posIsOutside )\r
437 {\r
438     DWORD windowStyle = 0;\r
439 \r
440     if (window && window->Window.Handle)\r
441         windowStyle = GetWindowLong(window->Window.Handle, GWL_STYLE);\r
442     else\r
443         windowStyle = WS_OVERLAPPEDWINDOW;\r
444 \r
445     fghComputeWindowRectFromClientArea_UseStyle(windowStyle, clientRect, posIsOutside);\r
446 }\r
447 \r
448 /* Computes position of corners of client area (drawable area) of a window\r
449  * based on the provided window Rect (outer position including decorations)\r
450  * and based on the style of the window in question. If the window pointer\r
451  * or the window handle is NULL, a fully decorated window (caption and\r
452  * border) is assumed.\r
453  * Furthermore, if wantPosOutside is set to true, the output client Rect\r
454  * will follow freeGLUT's window specification convention in which the\r
455  * top-left corner is at the outside of the window, the size\r
456  * (rect.right-rect.left,rect.bottom-rect.top) is the size of the drawable\r
457  * area.\r
458  */\r
459 void fghComputeClientAreaFromWindowRect( const SFG_Window *window, RECT *windowRect, BOOL wantPosOutside )\r
460 {\r
461     DWORD windowStyle = 0;\r
462     int xBorderWidth = 0, yBorderWidth = 0;\r
463 \r
464     if (window && window->Window.Handle)\r
465         windowStyle = GetWindowLong(window->Window.Handle, GWL_STYLE);\r
466     else\r
467         windowStyle = WS_OVERLAPPEDWINDOW;\r
468 \r
469     /* If window has title bar, correct rect for it */\r
470     if (windowStyle & WS_MAXIMIZEBOX) /* Need to query for WS_MAXIMIZEBOX to see if we have a title bar, the WS_CAPTION query is also true for a WS_DLGFRAME only... */\r
471         if (wantPosOutside)\r
472             windowRect->bottom -= GetSystemMetrics( SM_CYCAPTION );\r
473         else\r
474             windowRect->top    += GetSystemMetrics( SM_CYCAPTION );\r
475 \r
476     /* get width of window's borders (frame), correct rect for it.\r
477      * Note, borders can be of zero width if style does not specify borders\r
478      */\r
479     fghGetBorderWidth(windowStyle, &xBorderWidth, &yBorderWidth);\r
480     if (wantPosOutside)\r
481     {\r
482         windowRect->right  -= xBorderWidth * 2;\r
483         windowRect->bottom -= yBorderWidth * 2;\r
484     }\r
485     else\r
486     {\r
487         windowRect->left   += xBorderWidth;\r
488         windowRect->right  -= xBorderWidth;\r
489         windowRect->top    += yBorderWidth;\r
490         windowRect->bottom -= yBorderWidth;\r
491     }\r
492 }\r
493 \r
494 /* Gets the rect describing the client area (drawable area) of the\r
495  * specified window.\r
496  * Returns an empty rect if window pointer or window handle is NULL.\r
497  * If wantPosOutside is set to true, the output client Rect\r
498  * will follow freeGLUT's window specification convention in which the\r
499  * top-left corner is at the outside of the window, while the size\r
500  * (rect.right-rect.left,rect.bottom-rect.top) is the size of the drawable\r
501  * area.\r
502  */\r
503 RECT fghGetClientArea( const SFG_Window *window, BOOL wantPosOutside )\r
504 {\r
505     RECT windowRect = {0,0,0,0};\r
506 \r
507     freeglut_return_val_if_fail((window && window->Window.Handle),windowRect);\r
508     \r
509     /*\r
510      * call GetWindowRect()\r
511      * (this returns the pixel coordinates of the outside of the window)\r
512      */\r
513     GetWindowRect( window->Window.Handle, &windowRect );\r
514 \r
515     /* Then correct the results */\r
516     fghComputeClientAreaFromWindowRect(window, &windowRect, wantPosOutside);\r
517 \r
518     return windowRect;\r
519 }\r
520 \r
521 /* Returns the width of the window borders based on the window's style.\r
522  */\r
523 void fghGetBorderWidth(const DWORD windowStyle, int* xBorderWidth, int* yBorderWidth)\r
524 {\r
525     if (windowStyle & WS_THICKFRAME)\r
526     {\r
527         *xBorderWidth = GetSystemMetrics(SM_CXSIZEFRAME);\r
528         *yBorderWidth = GetSystemMetrics(SM_CYSIZEFRAME);\r
529     }\r
530     else if (windowStyle & WS_DLGFRAME)\r
531     {\r
532         *xBorderWidth = GetSystemMetrics(SM_CXFIXEDFRAME);\r
533         *yBorderWidth = GetSystemMetrics(SM_CYFIXEDFRAME);\r
534     }\r
535     else\r
536     {\r
537         *xBorderWidth = 0;\r
538         *yBorderWidth = 0;\r
539     }\r
540 }\r
541 \r
542 #if(WINVER >= 0x500)\r
543 typedef struct\r
544 {\r
545       int *x;\r
546       int *y;\r
547       const char *name;\r
548 } m_proc_t;\r
549 \r
550 static BOOL CALLBACK m_proc(HMONITOR mon,\r
551                             HDC hdc,\r
552                             LPRECT rect,\r
553                             LPARAM data)\r
554 {\r
555       m_proc_t *dp=(m_proc_t *)data;\r
556       MONITORINFOEX info;\r
557       BOOL res;\r
558       info.cbSize=sizeof(info);\r
559       res=GetMonitorInfo(mon,(LPMONITORINFO)&info);\r
560       if( res )\r
561       {\r
562           if( strcmp(dp->name,info.szDevice)==0 )\r
563           {\r
564               *(dp->x)=info.rcMonitor.left;\r
565               *(dp->y)=info.rcMonitor.top;\r
566               return FALSE;\r
567           }\r
568       }\r
569       return TRUE;\r
570 }\r
571 \r
572 /* \r
573  * this function returns the origin of the screen identified by\r
574  * fgDisplay.pDisplay.DisplayName, and 0 otherwise.\r
575  * This is used in fgOpenWindow to open the gamemode window on the screen\r
576  * identified by the -display command line argument. The function should\r
577  * not be called otherwise.\r
578  */\r
579 \r
580 static void get_display_origin(int *xp,int *yp)\r
581 {\r
582     *xp = 0;\r
583     *yp = 0;\r
584 \r
585     if( fgDisplay.pDisplay.DisplayName )\r
586     {\r
587         m_proc_t st;\r
588         st.x=xp;\r
589         st.y=yp;\r
590         st.name=fgDisplay.pDisplay.DisplayName;\r
591         EnumDisplayMonitors(0,0,m_proc,(LPARAM)&st);\r
592     }\r
593 }\r
594 #else\r
595 #pragma message( "-display parameter only works if compiled with WINVER >= 0x0500")\r
596 \r
597 static void get_display_origin(int *xp,int *yp)\r
598 {\r
599     *xp = 0;\r
600     *yp = 0;\r
601 \r
602     if( fgDisplay.pDisplay.DisplayName )\r
603     {\r
604         fgWarning( "for working -display support FreeGLUT must be compiled with WINVER >= 0x0500");\r
605     }\r
606 }\r
607 #endif\r
608 \r
609 \r
610 \r
611 /*\r
612  * Opens a window. Requires a SFG_Window object created and attached\r
613  * to the freeglut structure. OpenGL context is created here.\r
614  */\r
615 void fgPlatformOpenWindow( SFG_Window* window, const char* title,\r
616                            GLboolean positionUse, int x, int y,\r
617                            GLboolean sizeUse, int w, int h,\r
618                            GLboolean gameMode, GLboolean isSubWindow )\r
619 {\r
620 \r
621     WNDCLASS wc;\r
622     DWORD flags   = 0;\r
623     DWORD exFlags = 0;\r
624     ATOM atom;\r
625 \r
626     /* Grab the window class we have registered on glutInit(): */\r
627     atom = GetClassInfo( fgDisplay.pDisplay.Instance, _T("FREEGLUT"), &wc );\r
628     FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Info Not Found",\r
629                                    "fgOpenWindow" );\r
630 \r
631     /* Determine window style flags*/\r
632     if( gameMode )\r
633     {\r
634         FREEGLUT_INTERNAL_ERROR_EXIT ( window->Parent == NULL,\r
635                                        "Game mode being invoked on a subwindow",\r
636                                        "fgOpenWindow" );\r
637 \r
638         /*\r
639          * Set the window creation flags appropriately to make the window\r
640          * entirely visible:\r
641          */\r
642         flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;\r
643     }\r
644     else\r
645     {\r
646         flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;\r
647 \r
648         /*\r
649          * There's a small difference between creating the top, child and\r
650          * menu windows\r
651          */\r
652         if ( window->IsMenu )\r
653         {\r
654             flags |= WS_POPUP;\r
655             exFlags |= WS_EX_TOOLWINDOW;\r
656         }\r
657 #if defined(_WIN32_WCE)\r
658         /* no decorations for windows CE */\r
659 #else\r
660         /* if this is not a subwindow (child), set its style based on the requested display mode */\r
661         else if( window->Parent == NULL )\r
662             if ( fgState.DisplayMode & GLUT_BORDERLESS )\r
663             {\r
664                 /* no window decorations needed */\r
665             }\r
666             else if ( fgState.DisplayMode & GLUT_CAPTIONLESS )\r
667                 /* only window decoration is a border, no title bar or buttons */\r
668                 flags |= WS_DLGFRAME;\r
669             else\r
670                 /* window decoration are a border, title bar and buttons.\r
671                  * NB: we later query whether the window has a title bar or\r
672                  * not by testing for the maximize button, as the test for\r
673                  * WS_CAPTION can be true without the window having a title\r
674                  * bar. This style WS_OVERLAPPEDWINDOW gives you a maximize\r
675                  * button. */\r
676                 flags |= WS_OVERLAPPEDWINDOW;\r
677 #endif\r
678         else\r
679             /* subwindows always have no decoration, but are marked as a child window to the OS */\r
680             flags |= WS_CHILD;\r
681     }\r
682 \r
683     /* determine window size and position */\r
684     if( gameMode )\r
685     {\r
686         /* if in gamemode, query the origin of specified by the -display\r
687          * command line parameter (if any) and offset the upper-left corner\r
688          * of the window so we create the window on that screen.\r
689          * The -display argument doesn't do anything if not trying to enter\r
690          * gamemode.\r
691          */\r
692         int xoff=0, yoff=0;\r
693         get_display_origin(&xoff,&yoff);\r
694         x += xoff;\r
695         y += yoff;\r
696     }\r
697     if( !positionUse )\r
698     {\r
699         x = CW_USEDEFAULT;\r
700         y = CW_USEDEFAULT;\r
701     }\r
702     if( !sizeUse )\r
703     {\r
704         if( ! window->IsMenu )\r
705         {\r
706             w = CW_USEDEFAULT;\r
707             h = CW_USEDEFAULT;\r
708         }\r
709         else /* fail safe - Windows can make a window of size (0, 0) */\r
710             w = h = 300; /* default window size */\r
711     }\r
712     /* store requested client area width and height */\r
713     window->State.Width = w;\r
714     window->State.Height = h;\r
715 \r
716 #if !defined(_WIN32_WCE)    /* no decorations for windows CE */\r
717     if( sizeUse )\r
718     {\r
719         RECT windowRect;\r
720         /*\r
721          * Update the window dimensions, taking the window decorations\r
722          * into account.  FreeGLUT is to create the window with the\r
723          * topleft outside corner at (x,y) and with client area\r
724          * dimensions (w,h).\r
725          * note: don't need to do this when w=h=CW_USEDEFAULT, so in the\r
726          * if( sizeUse ) here is convenient.\r
727          */\r
728         windowRect.left     = x;\r
729         windowRect.top      = y;\r
730         windowRect.right    = x+w;\r
731         windowRect.bottom   = y+h;\r
732 \r
733         fghComputeWindowRectFromClientArea_UseStyle(flags,&windowRect,TRUE);\r
734 \r
735         w = windowRect.right - windowRect.left;\r
736         h = windowRect.bottom- windowRect.top;\r
737     }\r
738 #endif /* !defined(_WIN32_WCE) */\r
739 \r
740 #if defined(_WIN32_WCE)\r
741     {\r
742         wchar_t* wstr = fghWstrFromStr(title);\r
743 \r
744         window->Window.Handle = CreateWindow(\r
745             _T("FREEGLUT"),\r
746             wstr,\r
747             WS_VISIBLE | WS_POPUP,\r
748             0,0, 240,320,\r
749             NULL,\r
750             NULL,\r
751             fgDisplay.pDisplay.Instance,\r
752             (LPVOID) window\r
753         );\r
754 \r
755         free(wstr);\r
756 \r
757         SHFullScreen(window->Window.Handle, SHFS_HIDESTARTICON);\r
758         SHFullScreen(window->Window.Handle, SHFS_HIDESIPBUTTON);\r
759         SHFullScreen(window->Window.Handle, SHFS_HIDETASKBAR);\r
760         MoveWindow(window->Window.Handle, 0, 0, 240, 320, TRUE);\r
761         ShowWindow(window->Window.Handle, SW_SHOW);\r
762         UpdateWindow(window->Window.Handle);\r
763     }\r
764 #else\r
765     window->Window.Handle = CreateWindowEx(\r
766         exFlags,\r
767         _T("FREEGLUT"),\r
768         title,\r
769         flags,\r
770         x, y, w, h,\r
771         (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,\r
772         (HMENU) NULL,\r
773         fgDisplay.pDisplay.Instance,\r
774         (LPVOID) window\r
775     );\r
776 #endif /* defined(_WIN32_WCE) */\r
777 \r
778     if( !( window->Window.Handle ) )\r
779         fgError( "Failed to create a window (%s)!", title );\r
780 \r
781 #if !defined(_WIN32_WCE)\r
782     /* Need to set requested style again, apparently Windows doesn't listen when requesting windows without title bar or borders */\r
783     SetWindowLong(window->Window.Handle, GWL_STYLE, flags);\r
784     SetWindowPos(window->Window.Handle, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);\r
785 #endif /* defined(_WIN32_WCE) */\r
786 \r
787     /* Make a menu window always on top - fix Feature Request 947118 */\r
788     if( window->IsMenu || gameMode )\r
789         SetWindowPos(\r
790                         window->Window.Handle,\r
791                         HWND_TOPMOST,\r
792                         0, 0, 0, 0,\r
793                         SWP_NOMOVE | SWP_NOSIZE\r
794                     );\r
795 \r
796     /* Enable multitouch: additional flag TWF_FINETOUCH, TWF_WANTPALM */\r
797     #ifdef WM_TOUCH\r
798         if (fghRegisterTouchWindow == (pRegisterTouchWindow)0xDEADBEEF) \r
799                         fghRegisterTouchWindow = (pRegisterTouchWindow)GetProcAddress(GetModuleHandle("user32"),"RegisterTouchWindow");\r
800                 if (fghRegisterTouchWindow)\r
801              fghRegisterTouchWindow( window->Window.Handle, TWF_FINETOUCH | TWF_WANTPALM );\r
802     #endif\r
803 \r
804 #if defined(_WIN32_WCE)\r
805     ShowWindow( window->Window.Handle, SW_SHOW );\r
806 #else\r
807     ShowWindow( window->Window.Handle,\r
808                 fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );\r
809 #endif /* defined(_WIN32_WCE) */\r
810 \r
811     UpdateWindow( window->Window.Handle );\r
812     ShowCursor( TRUE );  /* XXX Old comments say "hide cursor"! */\r
813 \r
814 }\r
815 \r
816 \r
817 /*\r
818  * Closes a window, destroying the frame and OpenGL context\r
819  */\r
820 void fgPlatformCloseWindow( SFG_Window* window )\r
821 {\r
822     /* Make sure we don't close a window with current context active */\r
823     if( fgStructure.CurrentWindow == window )\r
824         wglMakeCurrent( NULL, NULL );\r
825 \r
826     /*\r
827      * Step through the list of windows.  If the rendering context\r
828      * is not being used by another window, then we delete it.\r
829      */\r
830     {\r
831         int used = FALSE ;\r
832         SFG_Window *iter ;\r
833 \r
834         for( iter = (SFG_Window *)fgStructure.Windows.First;\r
835              iter;\r
836              iter = (SFG_Window *)iter->Node.Next )\r
837         {\r
838             if( ( iter->Window.Context == window->Window.Context ) &&\r
839                 ( iter != window ) )\r
840                 used = TRUE;\r
841         }\r
842 \r
843         if( ! used )\r
844             wglDeleteContext( window->Window.Context );\r
845     }\r
846 \r
847     DestroyWindow( window->Window.Handle );\r
848 }\r
849 \r
850 \r
851 \r
852 /*\r
853  * This function makes the current window visible\r
854  */\r
855 void fgPlatformGlutShowWindow( void )\r
856 {\r
857     ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_SHOW );\r
858 }\r
859 \r
860 /*\r
861  * This function hides the current window\r
862  */\r
863 void fgPlatformGlutHideWindow( void )\r
864 {\r
865     ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_HIDE );\r
866 }\r
867 \r
868 /*\r
869  * Iconify the current window (top-level windows only)\r
870  */\r
871 void fgPlatformGlutIconifyWindow( void )\r
872 {\r
873     ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_MINIMIZE );\r
874 }\r
875 \r
876 /*\r
877  * Set the current window's title\r
878  */\r
879 void fgPlatformGlutSetWindowTitle( const char* title )\r
880 {\r
881 #ifdef _WIN32_WCE\r
882     {\r
883         wchar_t* wstr = fghWstrFromStr(title);\r
884         SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );\r
885         free(wstr);\r
886     }\r
887 #else\r
888     SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );\r
889 #endif\r
890 }\r
891 \r
892 /*\r
893  * Set the current window's iconified title\r
894  */\r
895 void fgPlatformGlutSetIconTitle( const char* title )\r
896 {\r
897 #ifdef _WIN32_WCE\r
898     {\r
899         wchar_t* wstr = fghWstrFromStr(title);\r
900         SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );\r
901         free(wstr);\r
902     }\r
903 #else\r
904     SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );\r
905 #endif\r
906 }\r
907 \r
908 /*\r
909  * Change the current window's position\r
910  */\r
911 void fgPlatformGlutPositionWindow( int x, int y )\r
912 {\r
913     RECT winRect;\r
914 \r
915     /* "GetWindowRect" returns the pixel coordinates of the outside of the window */\r
916     GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );\r
917     MoveWindow(\r
918         fgStructure.CurrentWindow->Window.Handle,\r
919         x,\r
920         y,\r
921         winRect.right - winRect.left,\r
922         winRect.bottom - winRect.top,\r
923         TRUE\r
924     );\r
925 }\r
926 \r
927 /*\r
928  * Lowers the current window (by Z order change)\r
929  */\r
930 void fgPlatformGlutPushWindow( void )\r
931 {\r
932     SetWindowPos(\r
933         fgStructure.CurrentWindow->Window.Handle,\r
934         HWND_BOTTOM,\r
935         0, 0, 0, 0,\r
936         SWP_NOSIZE | SWP_NOMOVE\r
937     );\r
938 }\r
939 \r
940 /*\r
941  * Raises the current window (by Z order change)\r
942  */\r
943 void fgPlatformGlutPopWindow( void )\r
944 {\r
945     SetWindowPos(\r
946         fgStructure.CurrentWindow->Window.Handle,\r
947         HWND_TOP,\r
948         0, 0, 0, 0,\r
949         SWP_NOSIZE | SWP_NOMOVE\r
950     );\r
951 }\r
952 \r
953 /*\r
954  * Resize the current window so that it fits the whole screen\r
955  */\r
956 void fgPlatformGlutFullScreen( SFG_Window *win )\r
957 {\r
958 #if !defined(_WIN32_WCE) /* FIXME: what about WinCE */\r
959 \r
960     if (glutGet(GLUT_FULL_SCREEN))\r
961     {\r
962         /*  Leave full screen state before entering fullscreen again (resizing?) */\r
963         glutLeaveFullScreen();\r
964     }\r
965 \r
966     {\r
967 #if(WINVER >= 0x0500) /* Windows 2000 or later */\r
968         DWORD s;\r
969         RECT rect;\r
970         HMONITOR hMonitor;\r
971         MONITORINFO mi;\r
972 \r
973         /* For fullscreen mode, first remove all window decoration\r
974          * and set style to popup so it will overlap the taskbar\r
975          * then force to maximize on the screen on which it has the most\r
976          * overlap.\r
977          */\r
978 \r
979         \r
980         /* store current window rect */\r
981         GetWindowRect( win->Window.Handle, &win->State.OldRect );\r
982 \r
983         /* store current window style */\r
984         win->State.OldStyle = s = GetWindowLong(win->Window.Handle, GWL_STYLE);\r
985 \r
986         /* remove decorations from style and add popup style*/\r
987         s &= ~WS_OVERLAPPEDWINDOW;\r
988         s |= WS_POPUP;\r
989         SetWindowLong(win->Window.Handle, GWL_STYLE, s);\r
990         SetWindowPos(win->Window.Handle, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);\r
991 \r
992         /* For fullscreen mode, find the monitor that is covered the most\r
993          * by the window and get its rect as the resize target.\r
994              */\r
995         hMonitor= MonitorFromRect(&win->State.OldRect, MONITOR_DEFAULTTONEAREST);\r
996         mi.cbSize = sizeof(mi);\r
997         GetMonitorInfo(hMonitor, &mi);\r
998         rect = mi.rcMonitor;\r
999 #else   /* if (WINVER >= 0x0500) */\r
1000         RECT rect;\r
1001 \r
1002         /* For fullscreen mode, force the top-left corner to 0,0\r
1003          * and adjust the window rectangle so that the client area\r
1004          * covers the whole screen.\r
1005          */\r
1006 \r
1007         rect.left   = 0;\r
1008         rect.top    = 0;\r
1009         rect.right  = fgDisplay.ScreenWidth;\r
1010         rect.bottom = fgDisplay.ScreenHeight;\r
1011 \r
1012         AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |\r
1013                                   WS_CLIPCHILDREN, FALSE );\r
1014 #endif  /* (WINVER >= 0x0500) */\r
1015 \r
1016         /*\r
1017          * then resize window\r
1018          * SWP_NOACTIVATE     Do not activate the window\r
1019          * SWP_NOOWNERZORDER  Do not change position in z-order\r
1020          * SWP_NOSENDCHANGING Suppress WM_WINDOWPOSCHANGING message\r
1021          * SWP_NOZORDER       Retains the current Z order (ignore 2nd param)\r
1022          */\r
1023         SetWindowPos( fgStructure.CurrentWindow->Window.Handle,\r
1024                       HWND_TOP,\r
1025                       rect.left,\r
1026                       rect.top,\r
1027                       rect.right  - rect.left,\r
1028                       rect.bottom - rect.top,\r
1029                       SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |\r
1030                       SWP_NOZORDER\r
1031                     );\r
1032 \r
1033         win->State.IsFullscreen = GL_TRUE;\r
1034     }\r
1035 #endif\r
1036 }\r
1037 \r
1038 /*\r
1039  * If we are fullscreen, resize the current window back to its original size\r
1040  */\r
1041 void fgPlatformGlutLeaveFullScreen( SFG_Window *win )\r
1042 {\r
1043 #if !defined(_WIN32_WCE) /* FIXME: what about WinCE */\r
1044     if (!glutGet(GLUT_FULL_SCREEN))\r
1045     {\r
1046         /* nothing to do */\r
1047         return;\r
1048     }\r
1049 \r
1050     /* restore style of window before making it fullscreen */\r
1051     SetWindowLong(win->Window.Handle, GWL_STYLE, win->State.OldStyle);\r
1052     SetWindowPos(win->Window.Handle, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);\r
1053 \r
1054     /* Then resize */\r
1055     SetWindowPos(win->Window.Handle,\r
1056         HWND_TOP,\r
1057         win->State.OldRect.left,\r
1058         win->State.OldRect.top,\r
1059         win->State.OldRect.right  - win->State.OldRect.left,\r
1060         win->State.OldRect.bottom - win->State.OldRect.top,\r
1061         SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |\r
1062         SWP_NOZORDER\r
1063         );\r
1064 \r
1065     win->State.IsFullscreen = GL_FALSE;\r
1066 #endif\r
1067 }\r
1068 \r
1069 /*\r
1070  * Toggle the window's full screen state.\r
1071  */\r
1072 void fgPlatformGlutFullScreenToggle( SFG_Window *win )\r
1073 {\r
1074     if (!win->State.IsFullscreen)\r
1075         glutFullScreen();\r
1076     else\r
1077         glutLeaveFullScreen();\r
1078 }\r
1079 \r
1080 \r
1081 /* -- PLATFORM-SPECIFIC INTERFACE FUNCTION -------------------------------------------------- */\r
1082 \r
1083 \r
1084 int FGAPIENTRY __glutCreateWindowWithExit( const char *title, void (__cdecl *exit_function)(int) )\r
1085 {\r
1086   __glutExitFunc = exit_function;\r
1087   return glutCreateWindow( title );\r
1088 }\r
1089 \r