4 * Window management methods.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Fri Dec 3 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #define FREEGLUT_BUILDING_LIB
29 #include <GL/freeglut.h>
30 #include "freeglut_internal.h"
32 #if TARGET_HOST_POSIX_X11
33 #include <limits.h> /* LONG_MAX */
36 #if defined(_WIN32_WCE)
37 # include <Aygshell.h>
38 # ifdef FREEGLUT_LIB_PRAGMAS
39 # pragma comment( lib, "Aygshell.lib" )
41 #endif /* defined(_WIN32_WCE) */
44 #if TARGET_HOST_POSIX_X11
45 #ifndef GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB
46 #define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20B2
49 #ifndef GLX_CONTEXT_MAJOR_VERSION_ARB
50 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
53 #ifndef GLX_CONTEXT_MINOR_VERSION_ARB
54 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
57 #ifndef GLX_CONTEXT_FLAGS_ARB
58 #define GLX_CONTEXT_FLAGS_ARB 0x2094
61 #ifndef GLX_CONTEXT_PROFILE_MASK_ARB
62 #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
65 #ifndef GLX_CONTEXT_DEBUG_BIT_ARB
66 #define GLX_CONTEXT_DEBUG_BIT_ARB 0x0001
69 #ifndef GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
70 #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
73 #ifndef GLX_CONTEXT_CORE_PROFILE_BIT_ARB
74 #define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
77 #ifndef GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
78 #define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
81 #ifndef GLX_RGBA_FLOAT_TYPE
82 #define GLX_RGBA_FLOAT_TYPE 0x20B9
85 #ifndef GLX_RGBA_FLOAT_BIT
86 #define GLX_RGBA_FLOAT_BIT 0x00000004
88 #endif /* TARGET_HOST_POSIX_X11 */
91 #if TARGET_HOST_MS_WINDOWS
92 /* The following include file is available from SGI but is not standard:
93 * #include <GL/wglext.h>
94 * So we copy the necessary parts out of it.
95 * XXX: should local definitions for extensions be put in a separate include file?
97 typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
99 typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
101 #define WGL_DRAW_TO_WINDOW_ARB 0x2001
102 #define WGL_ACCELERATION_ARB 0x2003
103 #define WGL_SUPPORT_OPENGL_ARB 0x2010
104 #define WGL_DOUBLE_BUFFER_ARB 0x2011
105 #define WGL_COLOR_BITS_ARB 0x2014
106 #define WGL_ALPHA_BITS_ARB 0x201B
107 #define WGL_DEPTH_BITS_ARB 0x2022
108 #define WGL_STENCIL_BITS_ARB 0x2023
109 #define WGL_FULL_ACCELERATION_ARB 0x2027
111 #define WGL_SAMPLE_BUFFERS_ARB 0x2041
112 #define WGL_SAMPLES_ARB 0x2042
114 #define WGL_TYPE_RGBA_FLOAT_ARB 0x21A0
116 #define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9
118 #ifndef WGL_ARB_create_context
119 #define WGL_ARB_create_context 1
120 #ifdef WGL_WGLEXT_PROTOTYPES
121 extern HGLRC WINAPI wglCreateContextAttribsARB (HDC, HGLRC, const int *);
122 #endif /* WGL_WGLEXT_PROTOTYPES */
123 typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList);
125 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
126 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
127 #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
128 #define WGL_CONTEXT_FLAGS_ARB 0x2094
129 #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
131 #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
132 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
134 #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
135 #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
137 #define ERROR_INVALID_VERSION_ARB 0x2095
138 #define ERROR_INVALID_PROFILE_ARB 0x2096
141 #endif /* TARGET_HOST_MS_WINDOWS */
144 /* pushing attribute/value pairs into an array */
145 #define ATTRIB(a) attributes[where++]=(a)
146 #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);}
149 * TODO BEFORE THE STABLE RELEASE:
151 * fgChooseFBConfig() -- OK, but what about glutInitDisplayString()?
152 * fgSetupPixelFormat -- ignores the display mode settings
153 * fgOpenWindow() -- check the Win32 version, -iconic handling!
154 * fgCloseWindow() -- check the Win32 version
155 * glutCreateWindow() -- Check when default position and size is {-1,-1}
156 * glutCreateSubWindow() -- Check when default position and size is {-1,-1}
157 * glutDestroyWindow() -- check the Win32 version
158 * glutSetWindow() -- check the Win32 version
159 * glutGetWindow() -- OK
160 * glutSetWindowTitle() -- check the Win32 version
161 * glutSetIconTitle() -- check the Win32 version
162 * glutShowWindow() -- check the Win32 version
163 * glutHideWindow() -- check the Win32 version
164 * glutIconifyWindow() -- check the Win32 version
165 * glutReshapeWindow() -- check the Win32 version
166 * glutPositionWindow() -- check the Win32 version
167 * glutPushWindow() -- check the Win32 version
168 * glutPopWindow() -- check the Win32 version
171 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
173 static int fghIsLegacyContextVersionRequested( void )
175 return fgState.MajorVersion == 1 && fgState.MinorVersion == 0;
178 static int fghIsLegacyContextRequested( void )
180 return fghIsLegacyContextVersionRequested() &&
181 fgState.ContextFlags == 0 &&
182 fgState.ContextProfile == 0;
185 static int fghNumberOfAuxBuffersRequested( void )
187 if ( fgState.DisplayMode & GLUT_AUX4 ) {
190 if ( fgState.DisplayMode & GLUT_AUX3 ) {
193 if ( fgState.DisplayMode & GLUT_AUX2 ) {
196 if ( fgState.DisplayMode & GLUT_AUX1 ) { /* NOTE: Same as GLUT_AUX! */
197 return fgState.AuxiliaryBufferNumber;
202 static int fghMapBit( int mask, int from, int to )
204 return ( mask & from ) ? to : 0;
208 static void fghContextCreationError( void )
210 fgError( "Unable to create OpenGL %d.%d context (flags %x, profile %x)",
211 fgState.MajorVersion, fgState.MinorVersion, fgState.ContextFlags,
212 fgState.ContextProfile );
216 /* -- SYSTEM-DEPENDENT PRIVATE FUNCTIONS ------------------------------------ */
218 #if TARGET_HOST_POSIX_X11
220 * Chooses a visual basing on the current display mode settings
223 GLXFBConfig* fgChooseFBConfig( int *numcfgs )
225 GLboolean wantIndexedMode = GL_FALSE;
226 int attributes[ 100 ];
227 int where = 0, numAuxBuffers;
229 /* First we have to process the display mode settings... */
230 if( fgState.DisplayMode & GLUT_INDEX ) {
231 ATTRIB_VAL( GLX_BUFFER_SIZE, 8 );
232 /* Buffer size is selected later. */
234 ATTRIB_VAL( GLX_RENDER_TYPE, GLX_COLOR_INDEX_BIT );
235 wantIndexedMode = GL_TRUE;
237 ATTRIB_VAL( GLX_RED_SIZE, 1 );
238 ATTRIB_VAL( GLX_GREEN_SIZE, 1 );
239 ATTRIB_VAL( GLX_BLUE_SIZE, 1 );
240 if( fgState.DisplayMode & GLUT_ALPHA ) {
241 ATTRIB_VAL( GLX_ALPHA_SIZE, 1 );
245 if( fgState.DisplayMode & GLUT_DOUBLE ) {
246 ATTRIB_VAL( GLX_DOUBLEBUFFER, True );
249 if( fgState.DisplayMode & GLUT_STEREO ) {
250 ATTRIB_VAL( GLX_STEREO, True );
253 if( fgState.DisplayMode & GLUT_DEPTH ) {
254 ATTRIB_VAL( GLX_DEPTH_SIZE, 1 );
257 if( fgState.DisplayMode & GLUT_STENCIL ) {
258 ATTRIB_VAL( GLX_STENCIL_SIZE, 1 );
261 if( fgState.DisplayMode & GLUT_ACCUM ) {
262 ATTRIB_VAL( GLX_ACCUM_RED_SIZE, 1 );
263 ATTRIB_VAL( GLX_ACCUM_GREEN_SIZE, 1 );
264 ATTRIB_VAL( GLX_ACCUM_BLUE_SIZE, 1 );
265 if( fgState.DisplayMode & GLUT_ALPHA ) {
266 ATTRIB_VAL( GLX_ACCUM_ALPHA_SIZE, 1 );
270 numAuxBuffers = fghNumberOfAuxBuffersRequested();
271 if ( numAuxBuffers > 0 ) {
272 ATTRIB_VAL( GLX_AUX_BUFFERS, numAuxBuffers );
275 if( fgState.DisplayMode & GLUT_SRGB ) {
276 ATTRIB_VAL( GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB, True );
279 if (fgState.DisplayMode & GLUT_MULTISAMPLE) {
280 ATTRIB_VAL(GLX_SAMPLE_BUFFERS, 1);
281 ATTRIB_VAL(GLX_SAMPLES, fgState.SampleNumber);
284 /* Push a terminator at the end of the list */
288 GLXFBConfig * fbconfigArray; /* Array of FBConfigs */
289 GLXFBConfig * fbconfig; /* The FBConfig we want */
290 int fbconfigArraySize; /* Number of FBConfigs in the array */
293 /* Get all FBConfigs that match "attributes". */
294 fbconfigArray = glXChooseFBConfig( fgDisplay.Display,
297 &fbconfigArraySize );
299 if (fbconfigArray != NULL)
301 int result; /* Returned by glXGetFBConfigAttrib, not checked. */
304 if( wantIndexedMode )
307 * In index mode, we want the largest buffer size, i.e. visual
308 * depth. Here, FBConfigs are sorted by increasing buffer size
309 * first, so FBConfigs with the largest size come last.
312 int bufferSizeMin, bufferSizeMax;
314 /* Get bufferSizeMin. */
316 glXGetFBConfigAttrib( fgDisplay.Display,
320 /* Get bufferSizeMax. */
322 glXGetFBConfigAttrib( fgDisplay.Display,
323 fbconfigArray[fbconfigArraySize - 1],
327 if (bufferSizeMax > bufferSizeMin)
330 * Free and reallocate fbconfigArray, keeping only FBConfigs
331 * with the largest buffer size.
333 XFree(fbconfigArray);
335 /* Add buffer size token at the end of the list. */
337 ATTRIB_VAL( GLX_BUFFER_SIZE, bufferSizeMax );
340 fbconfigArray = glXChooseFBConfig( fgDisplay.Display,
343 &fbconfigArraySize );
348 * We now have an array of FBConfigs, the first one being the "best"
349 * one. So we should return only this FBConfig:
353 * - pick the XID of the FBConfig we want
354 * result = glXGetFBConfigAttrib( fgDisplay.Display,
360 * XFree(fbconfigArray);
362 * - reset "attributes" with the XID
364 * ATTRIB_VAL( GLX_FBCONFIG_ID, fbconfigXID );
367 * - get our FBConfig only
368 * fbconfig = glXChooseFBConfig( fgDisplay.Display,
371 * &fbconfigArraySize );
373 * However, for some configurations (for instance multisampling with
374 * Mesa 6.5.2 and ATI drivers), this does not work:
375 * glXChooseFBConfig returns NULL, whereas fbconfigXID is a valid
376 * XID. Further investigation is needed.
378 * So, for now, we return the whole array of FBConfigs. This should
379 * not produce any side effects elsewhere.
381 fbconfig = fbconfigArray;
389 *numcfgs = fbconfigArraySize;
396 static void fghFillContextAttributes( int *attributes ) {
397 int where = 0, contextFlags, contextProfile;
399 if ( !fghIsLegacyContextVersionRequested() ) {
400 ATTRIB_VAL( GLX_CONTEXT_MAJOR_VERSION_ARB, fgState.MajorVersion );
401 ATTRIB_VAL( GLX_CONTEXT_MINOR_VERSION_ARB, fgState.MinorVersion );
405 fghMapBit( fgState.ContextFlags, GLUT_DEBUG, GLX_CONTEXT_DEBUG_BIT_ARB ) |
406 fghMapBit( fgState.ContextFlags, GLUT_FORWARD_COMPATIBLE, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB );
407 if ( contextFlags != 0 ) {
408 ATTRIB_VAL( GLX_CONTEXT_FLAGS_ARB, contextFlags );
412 fghMapBit( fgState.ContextProfile, GLUT_CORE_PROFILE, GLX_CONTEXT_CORE_PROFILE_BIT_ARB ) |
413 fghMapBit( fgState.ContextProfile, GLUT_COMPATIBILITY_PROFILE, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB );
414 if ( contextProfile != 0 ) {
415 ATTRIB_VAL( GLX_CONTEXT_PROFILE_MASK_ARB, contextProfile );
421 typedef GLXContext (*CreateContextAttribsProc)(Display *dpy, GLXFBConfig config,
422 GLXContext share_list, Bool direct,
423 const int *attrib_list);
425 static GLXContext fghCreateNewContext( SFG_Window* window )
427 /* for color model calculation */
428 int menu = ( window->IsMenu && !fgStructure.MenuContext );
429 int index_mode = ( fgState.DisplayMode & GLUT_INDEX );
431 /* "classic" context creation */
432 Display *dpy = fgDisplay.Display;
433 GLXFBConfig config = *(window->Window.FBConfig);
434 int render_type = ( !menu && index_mode ) ? GLX_COLOR_INDEX_TYPE : GLX_RGBA_TYPE;
435 GLXContext share_list = NULL;
436 Bool direct = ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT );
439 /* new context creation */
441 CreateContextAttribsProc createContextAttribs;
443 /* If nothing fancy has been required, simply use the old context creation GLX API entry */
444 if ( fghIsLegacyContextRequested() )
446 context = glXCreateNewContext( dpy, config, render_type, share_list, direct );
447 if ( context == NULL ) {
448 fghContextCreationError();
453 /* color index mode is not available anymore with OpenGL 3.0 */
454 if ( render_type == GLX_COLOR_INDEX_TYPE ) {
455 fgWarning( "color index mode is deprecated, using RGBA mode" );
458 fghFillContextAttributes( attributes );
460 createContextAttribs = (CreateContextAttribsProc) fghGetProcAddress( "glXCreateContextAttribsARB" );
461 if ( createContextAttribs == NULL ) {
462 fgError( "glXCreateContextAttribsARB not found" );
465 context = createContextAttribs( dpy, config, share_list, direct, attributes );
466 if ( context == NULL ) {
467 fghContextCreationError();
473 #define _NET_WM_STATE_TOGGLE 2
474 static int fghResizeFullscrToggle(void)
476 XWindowAttributes attributes;
478 if(glutGet(GLUT_FULL_SCREEN)) {
479 /* restore original window size */
480 SFG_Window *win = fgStructure.CurrentWindow;
481 fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
482 fgStructure.CurrentWindow->State.Width = win->State.OldWidth;
483 fgStructure.CurrentWindow->State.Height = win->State.OldHeight;
486 /* resize the window to cover the entire screen */
487 XGetWindowAttributes(fgDisplay.Display,
488 fgStructure.CurrentWindow->Window.Handle,
492 * The "x" and "y" members of "attributes" are the window's coordinates
493 * relative to its parent, i.e. to the decoration window.
495 XMoveResizeWindow(fgDisplay.Display,
496 fgStructure.CurrentWindow->Window.Handle,
499 fgDisplay.ScreenWidth,
500 fgDisplay.ScreenHeight);
505 static int fghEwmhFullscrToggle(void)
508 long evmask = SubstructureRedirectMask | SubstructureNotifyMask;
510 if(!fgDisplay.State || !fgDisplay.StateFullScreen) {
514 xev.type = ClientMessage;
515 xev.xclient.window = fgStructure.CurrentWindow->Window.Handle;
516 xev.xclient.message_type = fgDisplay.State;
517 xev.xclient.format = 32;
518 xev.xclient.data.l[0] = _NET_WM_STATE_TOGGLE;
519 xev.xclient.data.l[1] = fgDisplay.StateFullScreen;
520 xev.xclient.data.l[2] = 0; /* no second property to toggle */
521 xev.xclient.data.l[3] = 1; /* source indication: application */
522 xev.xclient.data.l[4] = 0; /* unused */
524 if(!XSendEvent(fgDisplay.Display, fgDisplay.RootWindow, 0, evmask, &xev)) {
530 static int fghToggleFullscreen(void)
532 /* first try the EWMH (_NET_WM_STATE) method ... */
533 if(fghEwmhFullscrToggle() != -1) {
537 /* fall back to resizing the window */
538 if(fghResizeFullscrToggle() != -1) {
545 #endif /* TARGET_HOST_POSIX_X11 */
548 #if TARGET_HOST_MS_WINDOWS
550 * Setup the pixel format for a Win32 window
553 #if defined(_WIN32_WCE)
554 static wchar_t* fghWstrFromStr(const char* str)
556 int i,len=strlen(str);
557 wchar_t* wstr = (wchar_t*)malloc(2*len+2);
563 #endif /* defined(_WIN32_WCE) */
566 static void fghFillContextAttributes( int *attributes ) {
567 int where = 0, contextFlags, contextProfile;
569 if ( !fghIsLegacyContextVersionRequested() ) {
570 ATTRIB_VAL( WGL_CONTEXT_MAJOR_VERSION_ARB, fgState.MajorVersion );
571 ATTRIB_VAL( WGL_CONTEXT_MINOR_VERSION_ARB, fgState.MinorVersion );
575 fghMapBit( fgState.ContextFlags, GLUT_DEBUG, WGL_CONTEXT_DEBUG_BIT_ARB ) |
576 fghMapBit( fgState.ContextFlags, GLUT_FORWARD_COMPATIBLE, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB );
577 if ( contextFlags != 0 ) {
578 ATTRIB_VAL( WGL_CONTEXT_FLAGS_ARB, contextFlags );
582 fghMapBit( fgState.ContextProfile, GLUT_CORE_PROFILE, WGL_CONTEXT_CORE_PROFILE_BIT_ARB ) |
583 fghMapBit( fgState.ContextProfile, GLUT_COMPATIBILITY_PROFILE, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB );
584 if ( contextProfile != 0 ) {
585 ATTRIB_VAL( WGL_CONTEXT_PROFILE_MASK_ARB, contextProfile );
591 static int fghIsExtensionSupported( HDC hdc, const char *extension ) {
592 const char *pWglExtString;
593 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetEntensionsStringARB =
594 (PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB");
595 if ( wglGetEntensionsStringARB == NULL )
599 pWglExtString = wglGetEntensionsStringARB( hdc );
600 return ( pWglExtString != NULL ) && ( strstr(pWglExtString, extension) != NULL );
603 void fgNewWGLCreateContext( SFG_Window* window )
607 PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
609 /* If nothing fancy has been required, leave the context as it is */
610 if ( fghIsLegacyContextRequested() )
615 wglMakeCurrent( window->Window.Device, window->Window.Context );
617 if ( !fghIsExtensionSupported( window->Window.Device, "WGL_ARB_create_context" ) )
622 /* new context creation */
623 fghFillContextAttributes( attributes );
625 wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress( "wglCreateContextAttribsARB" );
626 if ( wglCreateContextAttribsARB == NULL )
628 fgError( "wglCreateContextAttribsARB not found" );
631 context = wglCreateContextAttribsARB( window->Window.Device, 0, attributes );
632 if ( context == NULL )
634 fghContextCreationError();
637 wglMakeCurrent( NULL, NULL );
638 wglDeleteContext( window->Window.Context );
639 window->Window.Context = context;
642 #if !defined(_WIN32_WCE)
644 static void fghFillPFD( PIXELFORMATDESCRIPTOR *ppfd, HDC hdc, unsigned char layer_type )
646 int flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
647 if ( fgState.DisplayMode & GLUT_DOUBLE ) {
648 flags |= PFD_DOUBLEBUFFER;
650 if ( fgState.DisplayMode & GLUT_STEREO ) {
654 #if defined(_MSC_VER)
655 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
658 /* Specify which pixel format do we opt for... */
659 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
661 ppfd->dwFlags = flags;
663 if( fgState.DisplayMode & GLUT_INDEX ) {
664 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
666 ppfd->cGreenBits = 0;
668 ppfd->cAlphaBits = 0;
670 ppfd->iPixelType = PFD_TYPE_RGBA;
672 ppfd->cGreenBits = 8;
674 ppfd->cAlphaBits = ( fgState.DisplayMode & GLUT_ALPHA ) ? 8 : 0;
677 ppfd->cColorBits = 24;
679 ppfd->cGreenShift = 0;
680 ppfd->cBlueShift = 0;
681 ppfd->cAlphaShift = 0;
682 ppfd->cAccumBits = 0;
683 ppfd->cAccumRedBits = 0;
684 ppfd->cAccumGreenBits = 0;
685 ppfd->cAccumBlueBits = 0;
686 ppfd->cAccumAlphaBits = 0;
688 /* Hmmm, or 32/0 instead of 24/8? */
689 ppfd->cDepthBits = 24;
690 ppfd->cStencilBits = 8;
692 ppfd->cAuxBuffers = fghNumberOfAuxBuffersRequested();
693 ppfd->iLayerType = layer_type;
695 ppfd->dwLayerMask = 0;
696 ppfd->dwVisibleMask = 0;
697 ppfd->dwDamageMask = 0;
699 ppfd->cColorBits = (BYTE) GetDeviceCaps( hdc, BITSPIXEL );
702 static void fghFillPixelFormatAttributes( int *attributes, const PIXELFORMATDESCRIPTOR *ppfd )
706 ATTRIB_VAL( WGL_DRAW_TO_WINDOW_ARB, GL_TRUE );
707 ATTRIB_VAL( WGL_SUPPORT_OPENGL_ARB, GL_TRUE );
708 ATTRIB_VAL( WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB );
710 ATTRIB_VAL( WGL_COLOR_BITS_ARB, ppfd->cColorBits );
711 ATTRIB_VAL( WGL_ALPHA_BITS_ARB, ppfd->cAlphaBits );
712 ATTRIB_VAL( WGL_DEPTH_BITS_ARB, ppfd->cDepthBits );
713 ATTRIB_VAL( WGL_STENCIL_BITS_ARB, ppfd->cStencilBits );
715 ATTRIB_VAL( WGL_DOUBLE_BUFFER_ARB, ( fgState.DisplayMode & GLUT_DOUBLE ) != 0 );
717 if ( fgState.DisplayMode & GLUT_SRGB ) {
718 ATTRIB_VAL( WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, TRUE );
721 ATTRIB_VAL( WGL_SAMPLE_BUFFERS_ARB, GL_TRUE );
722 ATTRIB_VAL( WGL_SAMPLES_ARB, fgState.SampleNumber );
727 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
728 unsigned char layer_type )
730 #if defined(_WIN32_WCE)
733 PIXELFORMATDESCRIPTOR pfd;
734 PIXELFORMATDESCRIPTOR* ppfd = &pfd;
737 fghFillPFD( ppfd, window->Window.Device, layer_type );
738 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
740 /* windows hack for multismapling/sRGB */
741 if ( ( fgState.DisplayMode & GLUT_MULTISAMPLE ) ||
742 ( fgState.DisplayMode & GLUT_SRGB ) )
744 HGLRC rc, rc_before=wglGetCurrentContext();
746 HDC hDC, hDC_before=wglGetCurrentDC();
749 /* create a dummy window */
750 ZeroMemory(&wndCls, sizeof(wndCls));
751 wndCls.lpfnWndProc = DefWindowProc;
752 wndCls.hInstance = fgDisplay.Instance;
753 wndCls.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
754 wndCls.lpszClassName = _T("FREEGLUT_dummy");
755 RegisterClass( &wndCls );
757 hWnd=CreateWindow(_T("FREEGLUT_dummy"), _T(""), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW , 0,0,0,0, 0, 0, fgDisplay.Instance, 0 );
759 SetPixelFormat( hDC, pixelformat, ppfd );
761 rc = wglCreateContext( hDC );
762 wglMakeCurrent(hDC, rc);
764 if ( fghIsExtensionSupported( hDC, "WGL_ARB_multisample" ) )
766 PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARBProc =
767 (PFNWGLCHOOSEPIXELFORMATARBPROC) wglGetProcAddress("wglChoosePixelFormatARB");
768 if ( wglChoosePixelFormatARBProc )
773 float fAttributes[] = { 0, 0 };
775 fghFillPixelFormatAttributes( attributes, ppfd );
776 bValid = wglChoosePixelFormatARBProc(window->Window.Device, attributes, fAttributes, 1, &iPixelFormat, &numFormats);
778 if ( bValid && numFormats > 0 )
780 pixelformat = iPixelFormat;
785 wglMakeCurrent( hDC_before, rc_before);
786 wglDeleteContext(rc);
787 ReleaseDC(hWnd, hDC);
789 UnregisterClass(_T("FREEGLUT_dummy"), fgDisplay.Instance);
792 return ( pixelformat != 0 ) && ( checkOnly || SetPixelFormat( window->Window.Device, pixelformat, ppfd ) );
793 #endif /* defined(_WIN32_WCE) */
796 #endif /* TARGET_HOST_MS_WINDOWS */
799 * Sets the OpenGL context and the fgStructure "Current Window" pointer to
800 * the window structure passed in.
802 void fgSetWindow ( SFG_Window *window )
804 #if TARGET_HOST_POSIX_X11
807 glXMakeContextCurrent(
809 window->Window.Handle,
810 window->Window.Handle,
811 window->Window.Context
814 #elif TARGET_HOST_MS_WINDOWS
815 if( fgStructure.CurrentWindow )
816 ReleaseDC( fgStructure.CurrentWindow->Window.Handle,
817 fgStructure.CurrentWindow->Window.Device );
821 window->Window.Device = GetDC( window->Window.Handle );
823 window->Window.Device,
824 window->Window.Context
828 fgStructure.CurrentWindow = window;
831 #if TARGET_HOST_MS_WINDOWS
840 static BOOL CALLBACK m_proc(HMONITOR mon,
845 m_proc_t *dp=(m_proc_t *)data;
848 info.cbSize=sizeof(info);
849 res=GetMonitorInfo(mon,(LPMONITORINFO)&info);
852 if( !strcmp(dp->name,info.szDevice) )
854 *(dp->x)=info.rcMonitor.left;
855 *(dp->y)=info.rcMonitor.top;
863 * this function is only used in fgOpenWindow. Currently it only sets
864 * its output parameters, if the DisplayName is set in fgDisplay
865 * (and if it is able to recognize the display)
868 static void get_display_origin(int *xp,int *yp)
870 if( fgDisplay.DisplayName )
875 st.name=fgDisplay.DisplayName;
876 EnumDisplayMonitors(0,0,m_proc,(LPARAM)&st);
880 #pragma message( "-display parameter only works if compiled with WINVER >= 0x0500")
882 static void get_display_origin(int *xp,int *yp)
884 if( fgDisplay.DisplayName )
886 fgWarning( "for working -display support FreeGLUT must be compiled with WINVER >= 0x0500");
895 * Opens a window. Requires a SFG_Window object created and attached
896 * to the freeglut structure. OpenGL context is created here.
898 void fgOpenWindow( SFG_Window* window, const char* title,
899 GLboolean positionUse, int x, int y,
900 GLboolean sizeUse, int w, int h,
901 GLboolean gameMode, GLboolean isSubWindow )
903 #if TARGET_HOST_POSIX_X11
904 XVisualInfo * visualInfo;
905 XSetWindowAttributes winAttr;
906 XTextProperty textProperty;
907 XSizeHints sizeHints;
910 int num_FBConfigs, i;
911 unsigned int current_DisplayMode = fgState.DisplayMode ;
913 /* Save the display mode if we are creating a menu window */
914 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
915 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ;
917 window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs );
919 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
920 fgState.DisplayMode = current_DisplayMode ;
922 if( ! window->Window.FBConfig )
925 * The "fgChooseFBConfig" returned a null meaning that the visual
926 * context is not available.
927 * Try a couple of variations to see if they will work.
929 if( !( fgState.DisplayMode & GLUT_DOUBLE ) )
931 fgState.DisplayMode |= GLUT_DOUBLE ;
932 window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs );
933 fgState.DisplayMode &= ~GLUT_DOUBLE;
936 if( fgState.DisplayMode & GLUT_MULTISAMPLE )
938 fgState.DisplayMode &= ~GLUT_MULTISAMPLE ;
939 window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs );
940 fgState.DisplayMode |= GLUT_MULTISAMPLE;
944 FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.FBConfig != NULL,
945 "FBConfig with necessary capabilities not found", "fgOpenWindow" );
947 /* Get the X visual. */
948 for (i = 0; i < num_FBConfigs; i++) {
949 visualInfo = glXGetVisualFromFBConfig( fgDisplay.Display,
950 window->Window.FBConfig[i] );
955 FREEGLUT_INTERNAL_ERROR_EXIT( visualInfo != NULL,
956 "visualInfo could not be retrieved from FBConfig", "fgOpenWindow" );
959 * XXX HINT: the masks should be updated when adding/removing callbacks.
960 * XXX This might speed up message processing. Is that true?
962 * XXX A: Not appreciably, but it WILL make it easier to debug.
963 * XXX Try tracing old GLUT and try tracing freeglut. Old GLUT
964 * XXX turns off events that it doesn't need and is a whole lot
965 * XXX more pleasant to trace. (Think mouse-motion! Tons of
966 * XXX ``bonus'' GUI events stream in.)
969 StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
970 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
971 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
972 PointerMotionMask | ButtonMotionMask;
973 winAttr.background_pixmap = None;
974 winAttr.background_pixel = 0;
975 winAttr.border_pixel = 0;
977 winAttr.colormap = XCreateColormap(
978 fgDisplay.Display, fgDisplay.RootWindow,
979 visualInfo->visual, AllocNone
982 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
984 if( window->IsMenu || ( gameMode == GL_TRUE ) )
986 winAttr.override_redirect = True;
987 mask |= CWOverrideRedirect;
991 x = y = -1; /* default window position */
993 w = h = 300; /* default window size */
995 window->Window.Handle = XCreateWindow(
997 window->Parent == NULL ? fgDisplay.RootWindow :
998 window->Parent->Window.Handle,
1000 visualInfo->depth, InputOutput,
1001 visualInfo->visual, mask,
1006 * The GLX context creation, possibly trying the direct context rendering
1007 * or else use the current context if the user has so specified
1010 if( window->IsMenu )
1013 * If there isn't already an OpenGL rendering context for menu
1016 if( !fgStructure.MenuContext )
1018 fgStructure.MenuContext =
1019 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
1020 fgStructure.MenuContext->MContext = fghCreateNewContext( window );
1023 /* window->Window.Context = fgStructure.MenuContext->MContext; */
1024 window->Window.Context = fghCreateNewContext( window );
1026 else if( fgState.UseCurrentContext )
1028 window->Window.Context = glXGetCurrentContext( );
1030 if( ! window->Window.Context )
1031 window->Window.Context = fghCreateNewContext( window );
1034 window->Window.Context = fghCreateNewContext( window );
1036 #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ )
1037 if( !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
1039 if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
1040 fgError( "Unable to force direct context rendering for window '%s'",
1046 * XXX Assume the new window is visible by default
1047 * XXX Is this a safe assumption?
1049 window->State.Visible = GL_TRUE;
1051 sizeHints.flags = 0;
1053 sizeHints.flags |= USPosition;
1055 sizeHints.flags |= USSize;
1058 * Fill in the size hints values now (the x, y, width and height
1059 * settings are obsolete, are there any more WMs that support them?)
1060 * Unless the X servers actually stop supporting these, we should
1061 * continue to fill them in. It is *not* our place to tell the user
1062 * that they should replace a window manager that they like, and which
1063 * works, just because *we* think that it's not "modern" enough.
1067 sizeHints.width = w;
1068 sizeHints.height = h;
1070 wmHints.flags = StateHint;
1071 wmHints.initial_state = fgState.ForceIconic ? IconicState : NormalState;
1072 /* Prepare the window and iconified window names... */
1073 XStringListToTextProperty( (char **) &title, 1, &textProperty );
1077 window->Window.Handle,
1086 XFree( textProperty.value );
1088 XSetWMProtocols( fgDisplay.Display, window->Window.Handle,
1089 &fgDisplay.DeleteWindow, 1 );
1091 glXMakeContextCurrent(
1093 window->Window.Handle,
1094 window->Window.Handle,
1095 window->Window.Context
1098 XMapWindow( fgDisplay.Display, window->Window.Handle );
1102 #elif TARGET_HOST_MS_WINDOWS
1108 int WindowStyle = 0;
1110 /* Grab the window class we have registered on glutInit(): */
1111 atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
1112 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Info Not Found",
1117 FREEGLUT_INTERNAL_ERROR_EXIT ( window->Parent == NULL,
1118 "Game mode being invoked on a subwindow",
1122 * Set the window creation flags appropriately to make the window
1125 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
1129 int worig = w, horig = h;
1131 #if !defined(_WIN32_WCE)
1132 if ( ( ! isSubWindow ) && ( ! window->IsMenu ) )
1135 * Update the window dimensions, taking account of window
1136 * decorations. "freeglut" is to create the window with the
1137 * outside of its border at (x,y) and with dimensions (w,h).
1139 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
1140 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 +
1141 GetSystemMetrics( SM_CYCAPTION );
1143 #endif /* defined(_WIN32_WCE) */
1150 /* setting State.Width/Height to call resize callback later */
1153 if( ! window->IsMenu )
1158 else /* fail safe - Windows can make a window of size (0, 0) */
1159 w = h = 300; /* default window size */
1160 window->State.Width = window->State.Height = -1;
1164 window->State.Width = worig;
1165 window->State.Height = horig;
1169 * There's a small difference between creating the top, child and
1172 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
1174 if ( window->IsMenu )
1177 exFlags |= WS_EX_TOOLWINDOW;
1179 #if !defined(_WIN32_WCE)
1180 else if( window->Parent == NULL )
1181 flags |= WS_OVERLAPPEDWINDOW;
1187 #if defined(_WIN32_WCE)
1189 wchar_t* wstr = fghWstrFromStr(title);
1191 window->Window.Handle = CreateWindow(
1194 WS_VISIBLE | WS_POPUP,
1204 SHFullScreen(window->Window.Handle, SHFS_HIDESTARTICON);
1205 SHFullScreen(window->Window.Handle, SHFS_HIDESIPBUTTON);
1206 SHFullScreen(window->Window.Handle, SHFS_HIDETASKBAR);
1207 MoveWindow(window->Window.Handle, 0, 0, 240, 320, TRUE);
1208 ShowWindow(window->Window.Handle, SW_SHOW);
1209 UpdateWindow(window->Window.Handle);
1213 /* xoff and yoff are used to place window relative to current display */
1214 /* The operation of gamemode also depends on this */
1216 get_display_origin(&xoff,&yoff);
1218 window->Window.Handle = CreateWindowEx(
1223 x+xoff, y+yoff, w, h,
1224 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
1230 #endif /* defined(_WIN32_WCE) */
1232 if( !( window->Window.Handle ) )
1233 fgError( "Failed to create a window (%s)!", title );
1235 /* Make a menu window always on top - fix Feature Request 947118 */
1236 if( window->IsMenu || gameMode )
1238 window->Window.Handle,
1241 SWP_NOMOVE | SWP_NOSIZE
1244 /* Hack to remove the caption (title bar) and/or border
1245 * and all the system menu controls.
1247 WindowStyle = GetWindowLong(window->Window.Handle, GWL_STYLE);
1248 if ( fgState.DisplayMode & GLUT_CAPTIONLESS )
1250 SetWindowLong ( window->Window.Handle, GWL_STYLE,
1251 WindowStyle & ~(WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX));
1253 else if ( fgState.DisplayMode & GLUT_BORDERLESS )
1255 SetWindowLong ( window->Window.Handle, GWL_STYLE,
1256 WindowStyle & ~(WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX));
1258 /* SetWindowPos(window->Window.Handle, NULL, 0, 0, 0, 0,
1259 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); */
1262 #if defined(_WIN32_WCE)
1263 ShowWindow( window->Window.Handle, SW_SHOW );
1265 ShowWindow( window->Window.Handle,
1266 fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
1267 #endif /* defined(_WIN32_WCE) */
1269 UpdateWindow( window->Window.Handle );
1270 ShowCursor( TRUE ); /* XXX Old comments say "hide cursor"! */
1274 fgSetWindow( window );
1276 window->Window.DoubleBuffered =
1277 ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
1279 if ( ! window->Window.DoubleBuffered )
1281 glDrawBuffer ( GL_FRONT );
1282 glReadBuffer ( GL_FRONT );
1287 * Closes a window, destroying the frame and OpenGL context
1289 void fgCloseWindow( SFG_Window* window )
1291 #if TARGET_HOST_POSIX_X11
1293 if( window->Window.Context )
1294 glXDestroyContext( fgDisplay.Display, window->Window.Context );
1295 XFree( window->Window.FBConfig );
1297 if( window->Window.Handle ) {
1298 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
1300 /* XFlush( fgDisplay.Display ); */ /* XXX Shouldn't need this */
1302 #elif TARGET_HOST_MS_WINDOWS
1304 /* Make sure we don't close a window with current context active */
1305 if( fgStructure.CurrentWindow == window )
1306 wglMakeCurrent( NULL, NULL );
1309 * Step through the list of windows. If the rendering context
1310 * is not being used by another window, then we delete it.
1316 for( iter = (SFG_Window *)fgStructure.Windows.First;
1318 iter = (SFG_Window *)iter->Node.Next )
1320 if( ( iter->Window.Context == window->Window.Context ) &&
1321 ( iter != window ) )
1326 wglDeleteContext( window->Window.Context );
1329 DestroyWindow( window->Window.Handle );
1334 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1337 * Creates a new top-level freeglut window
1339 int FGAPIENTRY glutCreateWindow( const char* title )
1341 /* XXX GLUT does not exit; it simply calls "glutInit" quietly if the
1342 * XXX application has not already done so. The "freeglut" community
1343 * XXX decided not to go this route (freeglut-developer e-mail from
1344 * XXX Steve Baker, 12/16/04, 4:22 PM CST, "Re: [Freeglut-developer]
1345 * XXX Desired 'freeglut' behaviour when there is no current window"
1347 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateWindow" );
1349 return fgCreateWindow( NULL, title, fgState.Position.Use,
1350 fgState.Position.X, fgState.Position.Y,
1351 fgState.Size.Use, fgState.Size.X, fgState.Size.Y,
1352 GL_FALSE, GL_FALSE )->ID;
1355 #if TARGET_HOST_MS_WINDOWS
1356 int FGAPIENTRY __glutCreateWindowWithExit( const char *title, void (__cdecl *exit_function)(int) )
1358 __glutExitFunc = exit_function;
1359 return glutCreateWindow( title );
1364 * This function creates a sub window.
1366 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
1369 SFG_Window* window = NULL;
1370 SFG_Window* parent = NULL;
1372 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateSubWindow" );
1373 parent = fgWindowByID( parentID );
1374 freeglut_return_val_if_fail( parent != NULL, 0 );
1377 x = parent->State.Width + x ;
1378 if ( w >= 0 ) x -= w ;
1381 if ( w < 0 ) w = parent->State.Width - x + w ;
1390 y = parent->State.Height + y ;
1391 if ( h >= 0 ) y -= h ;
1394 if ( h < 0 ) h = parent->State.Height - y + h ;
1401 window = fgCreateWindow( parent, "", GL_TRUE, x, y, GL_TRUE, w, h, GL_FALSE, GL_FALSE );
1408 * Destroys a window and all of its subwindows
1410 void FGAPIENTRY glutDestroyWindow( int windowID )
1413 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDestroyWindow" );
1414 window = fgWindowByID( windowID );
1415 freeglut_return_if_fail( window != NULL );
1417 fgExecutionState ExecState = fgState.ExecState;
1418 fgAddToWindowDestroyList( window );
1419 fgState.ExecState = ExecState;
1424 * This function selects the current window
1426 void FGAPIENTRY glutSetWindow( int ID )
1428 SFG_Window* window = NULL;
1430 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindow" );
1431 if( fgStructure.CurrentWindow != NULL )
1432 if( fgStructure.CurrentWindow->ID == ID )
1435 window = fgWindowByID( ID );
1436 if( window == NULL )
1438 fgWarning( "glutSetWindow(): window ID %d not found!", ID );
1442 fgSetWindow( window );
1446 * This function returns the ID number of the current window, 0 if none exists
1448 int FGAPIENTRY glutGetWindow( void )
1450 SFG_Window *win = fgStructure.CurrentWindow;
1452 * Since GLUT did not throw an error if this function was called without a prior call to
1453 * "glutInit", this function shouldn't do so here. Instead let us return a zero.
1454 * See Feature Request "[ 1307049 ] glutInit check".
1456 if ( ! fgState.Initialised )
1459 while ( win && win->IsMenu )
1461 return win ? win->ID : 0;
1465 * This function makes the current window visible
1467 void FGAPIENTRY glutShowWindow( void )
1469 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" );
1470 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" );
1472 #if TARGET_HOST_POSIX_X11
1474 XMapWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1475 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1477 #elif TARGET_HOST_MS_WINDOWS
1479 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_SHOW );
1483 fgStructure.CurrentWindow->State.Redisplay = GL_TRUE;
1487 * This function hides the current window
1489 void FGAPIENTRY glutHideWindow( void )
1491 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" );
1492 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" );
1494 #if TARGET_HOST_POSIX_X11
1496 if( fgStructure.CurrentWindow->Parent == NULL )
1497 XWithdrawWindow( fgDisplay.Display,
1498 fgStructure.CurrentWindow->Window.Handle,
1501 XUnmapWindow( fgDisplay.Display,
1502 fgStructure.CurrentWindow->Window.Handle );
1503 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1505 #elif TARGET_HOST_MS_WINDOWS
1507 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_HIDE );
1511 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
1515 * Iconify the current window (top-level windows only)
1517 void FGAPIENTRY glutIconifyWindow( void )
1519 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" );
1520 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" );
1522 fgStructure.CurrentWindow->State.Visible = GL_FALSE;
1523 #if TARGET_HOST_POSIX_X11
1525 XIconifyWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
1527 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1529 #elif TARGET_HOST_MS_WINDOWS
1531 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_MINIMIZE );
1535 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
1539 * Set the current window's title
1541 void FGAPIENTRY glutSetWindowTitle( const char* title )
1543 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowTitle" );
1544 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" );
1545 if( ! fgStructure.CurrentWindow->Parent )
1547 #if TARGET_HOST_POSIX_X11
1551 text.value = (unsigned char *) title;
1552 text.encoding = XA_STRING;
1554 text.nitems = strlen( title );
1558 fgStructure.CurrentWindow->Window.Handle,
1562 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1564 #elif TARGET_HOST_MS_WINDOWS
1567 wchar_t* wstr = fghWstrFromStr(title);
1568 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
1572 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
1580 * Set the current window's iconified title
1582 void FGAPIENTRY glutSetIconTitle( const char* title )
1584 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" );
1585 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" );
1587 if( ! fgStructure.CurrentWindow->Parent )
1589 #if TARGET_HOST_POSIX_X11
1593 text.value = (unsigned char *) title;
1594 text.encoding = XA_STRING;
1596 text.nitems = strlen( title );
1600 fgStructure.CurrentWindow->Window.Handle,
1604 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1606 #elif TARGET_HOST_MS_WINDOWS
1609 wchar_t* wstr = fghWstrFromStr(title);
1610 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
1614 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
1622 * Change the current window's size
1624 void FGAPIENTRY glutReshapeWindow( int width, int height )
1626 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" );
1627 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" );
1629 if (glutGet(GLUT_FULL_SCREEN))
1631 /* Leave full screen state before resizing. */
1632 glutFullScreenToggle();
1635 fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
1636 fgStructure.CurrentWindow->State.Width = width ;
1637 fgStructure.CurrentWindow->State.Height = height;
1641 * Change the current window's position
1643 void FGAPIENTRY glutPositionWindow( int x, int y )
1645 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" );
1646 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" );
1648 if (glutGet(GLUT_FULL_SCREEN))
1650 /* Leave full screen state before moving. */
1651 glutFullScreenToggle();
1654 #if TARGET_HOST_POSIX_X11
1656 XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
1658 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1660 #elif TARGET_HOST_MS_WINDOWS
1665 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
1666 GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
1668 fgStructure.CurrentWindow->Window.Handle,
1671 winRect.right - winRect.left,
1672 winRect.bottom - winRect.top,
1681 * Lowers the current window (by Z order change)
1683 void FGAPIENTRY glutPushWindow( void )
1685 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPushWindow" );
1686 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPushWindow" );
1688 #if TARGET_HOST_POSIX_X11
1690 XLowerWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1692 #elif TARGET_HOST_MS_WINDOWS
1695 fgStructure.CurrentWindow->Window.Handle,
1698 SWP_NOSIZE | SWP_NOMOVE
1705 * Raises the current window (by Z order change)
1707 void FGAPIENTRY glutPopWindow( void )
1709 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" );
1710 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" );
1712 #if TARGET_HOST_POSIX_X11
1714 XRaiseWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1716 #elif TARGET_HOST_MS_WINDOWS
1719 fgStructure.CurrentWindow->Window.Handle,
1722 SWP_NOSIZE | SWP_NOMOVE
1729 * Resize the current window so that it fits the whole screen
1731 void FGAPIENTRY glutFullScreen( void )
1735 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" );
1736 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" );
1738 win = fgStructure.CurrentWindow;
1740 #if TARGET_HOST_POSIX_X11
1741 if(!glutGet(GLUT_FULL_SCREEN)) {
1742 if(fghToggleFullscreen() != -1) {
1743 win->State.IsFullscreen = GL_TRUE;
1747 #elif TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: what about WinCE */
1749 if (glutGet(GLUT_FULL_SCREEN))
1751 /* Leave full screen state before resizing. */
1752 glutFullScreenToggle();
1758 /* For fullscreen mode, force the top-left corner to 0,0
1759 * and adjust the window rectangle so that the client area
1760 * covers the whole screen.
1765 get_display_origin(&rect.left,&rect.top);
1766 rect.right = fgDisplay.ScreenWidth+rect.left;
1767 rect.bottom = fgDisplay.ScreenHeight+rect.top;
1769 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
1770 WS_CLIPCHILDREN, FALSE );
1773 * SWP_NOACTIVATE Do not activate the window
1774 * SWP_NOOWNERZORDER Do not change position in z-order
1775 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
1776 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
1779 SetWindowPos( fgStructure.CurrentWindow->Window.Handle,
1783 rect.right - rect.left,
1784 rect.bottom - rect.top,
1785 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
1789 win->State.IsFullscreen = GL_TRUE;
1795 * Toggle the window's full screen state.
1797 void FGAPIENTRY glutFullScreenToggle( void )
1801 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreenToggle" );
1802 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreenToggle" );
1804 win = fgStructure.CurrentWindow;
1806 #if TARGET_HOST_POSIX_X11
1807 if(fghToggleFullscreen() != -1) {
1808 win->State.IsFullscreen = !win->State.IsFullscreen;
1810 #elif TARGET_HOST_MS_WINDOWS
1812 win->State.IsFullscreen = !win->State.IsFullscreen;
1817 * A.Donev: Set and retrieve the window's user data
1819 void* FGAPIENTRY glutGetWindowData( void )
1821 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindowData" );
1822 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutGetWindowData" );
1823 return fgStructure.CurrentWindow->UserData;
1826 void FGAPIENTRY glutSetWindowData(void* data)
1828 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowData" );
1829 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowData" );
1830 fgStructure.CurrentWindow->UserData = data;
1833 /*** END OF FILE ***/