4 * Window management methods.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Fri Dec 3 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include <GL/freeglut.h>
29 #include "freeglut_internal.h"
33 #pragma comment( lib, "Aygshell.lib" )
35 static wchar_t* fghWstrFromStr(const char* str)
37 int i,len=strlen(str);
38 wchar_t* wstr = (wchar_t*)malloc(2*len+2);
46 #endif /* TARGET_HOST_WINCE */
49 * TODO BEFORE THE STABLE RELEASE:
51 * fgChooseVisual() -- OK, but what about glutInitDisplayString()?
52 * fgSetupPixelFormat -- ignores the display mode settings
53 * fgOpenWindow() -- check the Win32 version, -iconic handling!
54 * fgCloseWindow() -- check the Win32 version
55 * glutCreateWindow() -- Check when default position and size is {-1,-1}
56 * glutCreateSubWindow() -- Check when default position and size is {-1,-1}
57 * glutDestroyWindow() -- check the Win32 version
58 * glutSetWindow() -- check the Win32 version
59 * glutGetWindow() -- OK
60 * glutSetWindowTitle() -- check the Win32 version
61 * glutSetIconTitle() -- check the Win32 version
62 * glutShowWindow() -- check the Win32 version
63 * glutHideWindow() -- check the Win32 version
64 * glutIconifyWindow() -- check the Win32 version
65 * glutReshapeWindow() -- check the Win32 version
66 * glutPositionWindow() -- check the Win32 version
67 * glutPushWindow() -- check the Win32 version
68 * glutPopWindow() -- check the Win32 version
71 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
74 * Chooses a visual basing on the current display mode settings
76 #if TARGET_HOST_UNIX_X11
78 XVisualInfo* fgChooseVisual( void )
80 #define BUFFER_SIZES 6
81 int bufferSize[BUFFER_SIZES] = { 16, 12, 8, 4, 2, 1 };
82 GLboolean wantIndexedMode = GL_FALSE;
86 /* First we have to process the display mode settings... */
88 * XXX Why is there a semi-colon in this #define? The code
89 * XXX that uses the macro seems to always add more semicolons...
91 #define ATTRIB(a) attributes[where++]=a;
92 #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);}
94 if( fgState.DisplayMode & GLUT_INDEX )
96 ATTRIB_VAL( GLX_BUFFER_SIZE, 8 );
97 wantIndexedMode = GL_TRUE;
102 ATTRIB_VAL( GLX_RED_SIZE, 1 );
103 ATTRIB_VAL( GLX_GREEN_SIZE, 1 );
104 ATTRIB_VAL( GLX_BLUE_SIZE, 1 );
105 if( fgState.DisplayMode & GLUT_ALPHA )
106 ATTRIB_VAL( GLX_ALPHA_SIZE, 1 );
109 if( fgState.DisplayMode & GLUT_DOUBLE )
110 ATTRIB( GLX_DOUBLEBUFFER );
112 if( fgState.DisplayMode & GLUT_STEREO )
113 ATTRIB( GLX_STEREO );
115 if( fgState.DisplayMode & GLUT_DEPTH )
116 ATTRIB_VAL( GLX_DEPTH_SIZE, 1 );
118 if( fgState.DisplayMode & GLUT_STENCIL )
119 ATTRIB_VAL( GLX_STENCIL_SIZE, 1 );
121 if( fgState.DisplayMode & GLUT_ACCUM )
123 ATTRIB_VAL( GLX_ACCUM_RED_SIZE, 1 );
124 ATTRIB_VAL( GLX_ACCUM_GREEN_SIZE, 1 );
125 ATTRIB_VAL( GLX_ACCUM_BLUE_SIZE, 1 );
126 if( fgState.DisplayMode & GLUT_ALPHA )
127 ATTRIB_VAL( GLX_ACCUM_ALPHA_SIZE, 1 );
130 if( fgState.DisplayMode & GLUT_AUX1 )
131 ATTRIB_VAL( GLX_AUX_BUFFERS, 1 );
132 if( fgState.DisplayMode & GLUT_AUX2 )
133 ATTRIB_VAL( GLX_AUX_BUFFERS, 2 );
134 if( fgState.DisplayMode & GLUT_AUX3 )
135 ATTRIB_VAL( GLX_AUX_BUFFERS, 3 );
136 if( fgState.DisplayMode & GLUT_AUX4 )
137 ATTRIB_VAL( GLX_AUX_BUFFERS, 4 );
140 /* Push a null at the end of the list */
143 if( ! wantIndexedMode )
144 return glXChooseVisual( fgDisplay.Display, fgDisplay.Screen,
148 XVisualInfo* visualInfo;
152 * In indexed mode, we need to check how many bits of depth can we
153 * achieve. We do this by trying each possibility from the list
154 * given in the {bufferSize} array. If we match, we return to caller.
156 for( i=0; i<BUFFER_SIZES; i++ )
158 attributes[ 1 ] = bufferSize[ i ];
159 visualInfo = glXChooseVisual( fgDisplay.Display, fgDisplay.Screen,
161 if( visualInfo != NULL )
170 * Setup the pixel format for a Win32 window
172 #if TARGET_HOST_WIN32
173 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
174 unsigned char layer_type )
176 #if TARGET_HOST_WINCE
179 PIXELFORMATDESCRIPTOR* ppfd, pfd;
180 int flags, pixelformat;
182 freeglut_return_val_if_fail( window != NULL, 0 );
183 flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
184 if( fgState.DisplayMode & GLUT_DOUBLE )
185 flags |= PFD_DOUBLEBUFFER;
187 #if defined(_MSC_VER)
188 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
191 /* Specify which pixel format do we opt for... */
192 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
195 pfd.iPixelType = PFD_TYPE_RGBA;
206 pfd.cAccumRedBits = 0;
207 pfd.cAccumGreenBits = 0;
208 pfd.cAccumBlueBits = 0;
209 pfd.cAccumAlphaBits = 0;
212 pfd.cStencilBits = 0;
215 pfd.cStencilBits = 8;
217 if( fgState.DisplayMode & GLUT_AUX4 )
219 else if( fgState.DisplayMode & GLUT_AUX3 )
221 else if( fgState.DisplayMode & GLUT_AUX2 )
223 else if( fgState.DisplayMode & GLUT_AUX1 )
228 pfd.iLayerType = layer_type;
231 pfd.dwVisibleMask = 0;
232 pfd.dwDamageMask = 0;
234 pfd.cColorBits = (BYTE) GetDeviceCaps( window->Window.Device, BITSPIXEL );
237 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
238 if( pixelformat == 0 )
243 return SetPixelFormat( window->Window.Device, pixelformat, ppfd );
244 #endif /* TARGET_HOST_WINCE */
249 * Sets the OpenGL context and the fgStructure "Current Window" pointer to
250 * the window structure passed in.
252 void fgSetWindow ( SFG_Window *window )
254 #if TARGET_HOST_UNIX_X11
258 window->Window.Handle,
259 window->Window.Context
261 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
262 if( fgStructure.CurrentWindow )
263 ReleaseDC( fgStructure.CurrentWindow->Window.Handle,
264 fgStructure.CurrentWindow->Window.Device );
268 window->Window.Device = GetDC( window->Window.Handle );
270 window->Window.Device,
271 window->Window.Context
275 fgStructure.CurrentWindow = window;
280 * Opens a window. Requires a SFG_Window object created and attached
281 * to the freeglut structure. OpenGL context is created here.
283 void fgOpenWindow( SFG_Window* window, const char* title,
284 int x, int y, int w, int h,
285 GLboolean gameMode, GLboolean isSubWindow )
287 #if TARGET_HOST_UNIX_X11
288 XSetWindowAttributes winAttr;
289 XTextProperty textProperty;
290 XSizeHints sizeHints;
293 unsigned int current_DisplayMode = fgState.DisplayMode ;
295 /* Save the display mode if we are creating a menu window */
296 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
297 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ;
299 window->Window.VisualInfo = fgChooseVisual( );
301 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
302 fgState.DisplayMode = current_DisplayMode ;
304 if( ! window->Window.VisualInfo )
307 * The "fgChooseVisual" returned a null meaning that the visual
308 * context is not available.
309 * Try a couple of variations to see if they will work.
311 if( !( fgState.DisplayMode & GLUT_DOUBLE ) )
313 fgState.DisplayMode |= GLUT_DOUBLE ;
314 window->Window.VisualInfo = fgChooseVisual( );
315 fgState.DisplayMode &= ~GLUT_DOUBLE;
319 * GLUT also checks for multi-sampling, but I don't see that
320 * anywhere else in FREEGLUT so I won't bother with it for the moment.
324 FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.VisualInfo != NULL,
325 "Visual with necessary capabilities not found", "fgOpenWindow" );
328 * XXX HINT: the masks should be updated when adding/removing callbacks.
329 * XXX This might speed up message processing. Is that true?
331 * XXX A: Not appreciably, but it WILL make it easier to debug.
332 * XXX Try tracing old GLUT and try tracing freeglut. Old GLUT
333 * XXX turns off events that it doesn't need and is a whole lot
334 * XXX more pleasant to trace. (Think mouse-motion! Tons of
335 * XXX ``bonus'' GUI events stream in.)
338 StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
339 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
340 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
341 PointerMotionMask | ButtonMotionMask;
342 winAttr.background_pixmap = None;
343 winAttr.background_pixel = 0;
344 winAttr.border_pixel = 0;
346 winAttr.colormap = XCreateColormap(
347 fgDisplay.Display, fgDisplay.RootWindow,
348 window->Window.VisualInfo->visual, AllocNone
351 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
353 if( window->IsMenu || ( gameMode == GL_TRUE ) )
355 winAttr.override_redirect = True;
356 mask |= CWOverrideRedirect;
359 window->Window.Handle = XCreateWindow(
361 window->Parent == NULL ? fgDisplay.RootWindow :
362 window->Parent->Window.Handle,
364 window->Window.VisualInfo->depth, InputOutput,
365 window->Window.VisualInfo->visual, mask,
370 * The GLX context creation, possibly trying the direct context rendering
371 * or else use the current context if the user has so specified
376 * If there isn't already an OpenGL rendering context for menu
379 if( !fgStructure.MenuContext )
381 fgStructure.MenuContext =
382 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
383 fgStructure.MenuContext->MVisualInfo = window->Window.VisualInfo;
384 fgStructure.MenuContext->MContext = glXCreateContext(
385 fgDisplay.Display, fgStructure.MenuContext->MVisualInfo,
386 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
390 /* window->Window.Context = fgStructure.MenuContext->MContext; */
391 window->Window.Context = glXCreateContext(
392 fgDisplay.Display, window->Window.VisualInfo,
393 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
396 else if( fgState.UseCurrentContext )
398 window->Window.Context = glXGetCurrentContext( );
400 if( ! window->Window.Context )
401 window->Window.Context = glXCreateContext(
402 fgDisplay.Display, window->Window.VisualInfo,
403 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
407 window->Window.Context = glXCreateContext(
408 fgDisplay.Display, window->Window.VisualInfo,
409 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
412 #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ )
413 if( !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
415 if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
416 fgError( "Unable to force direct context rendering for window '%s'",
418 else if( fgState.DirectContext == GLUT_TRY_DIRECT_CONTEXT )
419 fgWarning( "Unable to create direct context rendering for window '%s'\nThis may hurt performance.",
425 * XXX Assume the new window is visible by default
426 * XXX Is this a safe assumption?
428 window->State.Visible = GL_TRUE;
431 if ( fgState.Position.Use )
432 sizeHints.flags |= USPosition;
433 if ( fgState.Size.Use )
434 sizeHints.flags |= USSize;
437 * Fill in the size hints values now (the x, y, width and height
438 * settings are obsolete, are there any more WMs that support them?)
439 * Unless the X servers actually stop supporting these, we should
440 * continue to fill them in. It is *not* our place to tell the user
441 * that they should replace a window manager that they like, and which
442 * works, just because *we* think that it's not "modern" enough.
447 sizeHints.height = h;
449 wmHints.flags = StateHint;
450 wmHints.initial_state = fgState.ForceIconic ? IconicState : NormalState;
451 /* Prepare the window and iconified window names... */
452 XStringListToTextProperty( (char **) &title, 1, &textProperty );
456 window->Window.Handle,
465 XFree( textProperty.value );
467 XSetWMProtocols( fgDisplay.Display, window->Window.Handle,
468 &fgDisplay.DeleteWindow, 1 );
472 window->Window.Handle,
473 window->Window.Context
476 XMapWindow( fgDisplay.Display, window->Window.Handle );
478 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
485 /* Grab the window class we have registered on glutInit(): */
486 atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
487 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Info Not Found",
492 FREEGLUT_INTERNAL_ERROR_EXIT ( window->Parent == NULL,
493 "Game mode being invoked on a subwindow",
497 * Set the window creation flags appropriately to make the window
500 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
504 #if !TARGET_HOST_WINCE
505 if ( ( ! isSubWindow ) && ( ! window->IsMenu ) )
508 * Update the window dimensions, taking account of window
509 * decorations. "freeglut" is to create the window with the
510 * outside of its border at (x,y) and with dimensions (w,h).
512 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
513 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 +
514 GetSystemMetrics( SM_CYCAPTION );
516 #endif /* TARGET_HOST_WINCE */
518 if( ! fgState.Position.Use )
523 if( ! fgState.Size.Use )
530 * There's a small difference between creating the top, child and
533 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
535 if ( window->IsMenu )
538 exFlags |= WS_EX_TOOLWINDOW;
540 #if !TARGET_HOST_WINCE
541 else if( window->Parent == NULL )
542 flags |= WS_OVERLAPPEDWINDOW;
548 #if TARGET_HOST_WINCE
550 wchar_t* wstr = fghWstrFromStr(title);
552 window->Window.Handle = CreateWindow(
555 WS_VISIBLE | WS_POPUP,
565 SHFullScreen(window->Window.Handle, SHFS_HIDESTARTICON);
566 SHFullScreen(window->Window.Handle, SHFS_HIDESIPBUTTON);
567 SHFullScreen(window->Window.Handle, SHFS_HIDETASKBAR);
568 MoveWindow(window->Window.Handle, 0, 0, 240, 320, TRUE);
569 ShowWindow(window->Window.Handle, SW_SHOW);
570 UpdateWindow(window->Window.Handle);
573 window->Window.Handle = CreateWindowEx(
579 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
584 #endif /* TARGET_HOST_WINCE */
586 if( !( window->Window.Handle ) )
587 fgError( "Failed to create a window (%s)!", title );
589 #if TARGET_HOST_WINCE
590 ShowWindow( window->Window.Handle, SW_SHOW );
592 ShowWindow( window->Window.Handle,
593 fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
594 #endif /* TARGET_HOST_WINCE */
596 UpdateWindow( window->Window.Handle );
597 ShowCursor( TRUE ); /* XXX Old comments say "hide cursor"! */
601 fgSetWindow( window );
603 window->Window.DoubleBuffered =
604 ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
606 if ( ! window->Window.DoubleBuffered )
608 glDrawBuffer ( GL_FRONT );
609 glReadBuffer ( GL_FRONT );
614 * Closes a window, destroying the frame and OpenGL context
616 void fgCloseWindow( SFG_Window* window )
618 #if TARGET_HOST_UNIX_X11
620 glXDestroyContext( fgDisplay.Display, window->Window.Context );
621 XFree( window->Window.VisualInfo );
622 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
623 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
625 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
627 /* Make sure we don't close a window with current context active */
628 if( fgStructure.CurrentWindow == window )
629 wglMakeCurrent( NULL, NULL );
632 * Step through the list of windows. If the rendering context
633 * is not being used by another window, then we delete it.
639 for( iter = (SFG_Window *)fgStructure.Windows.First;
641 iter = (SFG_Window *)iter->Node.Next )
643 if( ( iter->Window.Context == window->Window.Context ) &&
649 wglDeleteContext( window->Window.Context );
652 DestroyWindow( window->Window.Handle );
657 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
660 * Creates a new top-level freeglut window
662 int FGAPIENTRY glutCreateWindow( const char* title )
664 /* XXX GLUT does not exit; it simply calls "glutInit" quietly if the
665 * XXX application has not already done so. The "freeglut" community
666 * XXX decided not to go this route (freeglut-developer e-mail from
667 * XXX Steve Baker, 12/16/04, 4:22 PM CST, "Re: [Freeglut-developer]
668 * XXX Desired 'freeglut' behaviour when there is no current window"
670 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateWindow" );
672 return fgCreateWindow( NULL, title, fgState.Position.X, fgState.Position.Y,
673 fgState.Size.X, fgState.Size.Y, GL_FALSE,
678 * This function creates a sub window.
680 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
683 SFG_Window* window = NULL;
684 SFG_Window* parent = NULL;
686 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateSubWindow" );
687 parent = fgWindowByID( parentID );
688 freeglut_return_val_if_fail( parent != NULL, 0 );
691 x = parent->State.Width + x ;
692 if ( w >= 0 ) x -= w ;
695 if ( w < 0 ) w = parent->State.Width - x + w ;
704 y = parent->State.Height + y ;
705 if ( h >= 0 ) y -= h ;
708 if ( h < 0 ) h = parent->State.Height - y + h ;
715 window = fgCreateWindow( parent, "", x, y, w, h, GL_FALSE, GL_FALSE );
722 * Destroys a window and all of its subwindows
724 void FGAPIENTRY glutDestroyWindow( int windowID )
727 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDestroyWindow" );
728 window = fgWindowByID( windowID );
729 freeglut_return_if_fail( window != NULL );
731 fgExecutionState ExecState = fgState.ExecState;
732 fgAddToWindowDestroyList( window );
733 fgState.ExecState = ExecState;
738 * This function selects the current window
740 void FGAPIENTRY glutSetWindow( int ID )
742 SFG_Window* window = NULL;
744 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindow" );
745 if( fgStructure.CurrentWindow != NULL )
746 if( fgStructure.CurrentWindow->ID == ID )
749 window = fgWindowByID( ID );
752 fgWarning( "glutSetWindow(): window ID %d not found!", ID );
756 fgSetWindow( window );
760 * This function returns the ID number of the current window, 0 if none exists
762 int FGAPIENTRY glutGetWindow( void )
764 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindow" );
765 if( fgStructure.CurrentWindow == NULL )
767 return fgStructure.CurrentWindow->ID;
771 * This function makes the current window visible
773 void FGAPIENTRY glutShowWindow( void )
775 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" );
776 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" );
778 #if TARGET_HOST_UNIX_X11
780 XMapWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
781 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
783 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
785 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_SHOW );
789 fgStructure.CurrentWindow->State.Redisplay = GL_TRUE;
793 * This function hides the current window
795 void FGAPIENTRY glutHideWindow( void )
797 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" );
798 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" );
800 #if TARGET_HOST_UNIX_X11
802 if( fgStructure.CurrentWindow->Parent == NULL )
803 XWithdrawWindow( fgDisplay.Display,
804 fgStructure.CurrentWindow->Window.Handle,
807 XUnmapWindow( fgDisplay.Display,
808 fgStructure.CurrentWindow->Window.Handle );
809 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
811 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
813 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_HIDE );
817 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
821 * Iconify the current window (top-level windows only)
823 void FGAPIENTRY glutIconifyWindow( void )
825 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" );
826 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" );
828 fgStructure.CurrentWindow->State.Visible = GL_FALSE;
829 #if TARGET_HOST_UNIX_X11
831 XIconifyWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
833 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
835 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
837 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_MINIMIZE );
841 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
845 * Set the current window's title
847 void FGAPIENTRY glutSetWindowTitle( const char* title )
849 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowTitle" );
850 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" );
851 if( ! fgStructure.CurrentWindow->Parent )
853 #if TARGET_HOST_UNIX_X11
857 text.value = (unsigned char *) title;
858 text.encoding = XA_STRING;
860 text.nitems = strlen( title );
864 fgStructure.CurrentWindow->Window.Handle,
868 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
870 #elif TARGET_HOST_WIN32
872 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
874 #elif TARGET_HOST_WINCE
876 wchar_t* wstr = fghWstrFromStr(title);
878 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
887 * Set the current window's iconified title
889 void FGAPIENTRY glutSetIconTitle( const char* title )
891 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" );
892 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" );
894 if( ! fgStructure.CurrentWindow->Parent )
896 #if TARGET_HOST_UNIX_X11
900 text.value = (unsigned char *) title;
901 text.encoding = XA_STRING;
903 text.nitems = strlen( title );
907 fgStructure.CurrentWindow->Window.Handle,
911 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
913 #elif TARGET_HOST_WIN32
915 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
917 #elif TARGET_HOST_WINCE
919 wchar_t* wstr = fghWstrFromStr(title);
921 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
930 * Change the current window's size
932 void FGAPIENTRY glutReshapeWindow( int width, int height )
934 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" );
935 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" );
937 fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
938 fgStructure.CurrentWindow->State.Width = width ;
939 fgStructure.CurrentWindow->State.Height = height;
943 * Change the current window's position
945 void FGAPIENTRY glutPositionWindow( int x, int y )
947 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" );
948 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" );
950 #if TARGET_HOST_UNIX_X11
952 XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
954 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
956 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
961 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
962 GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
964 fgStructure.CurrentWindow->Window.Handle,
967 winRect.right - winRect.left,
968 winRect.bottom - winRect.top,
977 * Lowers the current window (by Z order change)
979 void FGAPIENTRY glutPushWindow( void )
981 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPushWindow" );
982 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPushWindow" );
984 #if TARGET_HOST_UNIX_X11
986 XLowerWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
988 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
991 fgStructure.CurrentWindow->Window.Handle,
994 SWP_NOSIZE | SWP_NOMOVE
1001 * Raises the current window (by Z order change)
1003 void FGAPIENTRY glutPopWindow( void )
1005 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" );
1006 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" );
1008 #if TARGET_HOST_UNIX_X11
1010 XRaiseWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1012 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1015 fgStructure.CurrentWindow->Window.Handle,
1018 SWP_NOSIZE | SWP_NOMOVE
1025 * Resize the current window so that it fits the whole screen
1027 void FGAPIENTRY glutFullScreen( void )
1029 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" );
1030 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" );
1033 #if TARGET_HOST_UNIX_X11
1039 fgStructure.CurrentWindow->Window.Handle,
1041 fgDisplay.ScreenWidth,
1042 fgDisplay.ScreenHeight
1045 XFlush( fgDisplay.Display ); /* This is needed */
1047 XTranslateCoordinates(
1049 fgStructure.CurrentWindow->Window.Handle,
1050 fgDisplay.RootWindow,
1058 fgStructure.CurrentWindow->Window.Handle,
1061 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1063 #elif TARGET_HOST_WIN32
1066 /* For fullscreen mode, force the top-left corner to 0,0
1067 * and adjust the window rectangle so that the client area
1068 * covers the whole screen.
1073 rect.right = fgDisplay.ScreenWidth;
1074 rect.bottom = fgDisplay.ScreenHeight;
1076 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
1077 WS_CLIPCHILDREN, FALSE );
1080 * SWP_NOACTIVATE Do not activate the window
1081 * SWP_NOOWNERZORDER Do not change position in z-order
1082 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
1083 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
1086 SetWindowPos( fgStructure.CurrentWindow->Window.Handle,
1090 rect.right - rect.left,
1091 rect.bottom - rect.top,
1092 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
1100 * A.Donev: Set and retrieve the window's user data
1102 void* FGAPIENTRY glutGetWindowData( void )
1104 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindowData" );
1105 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutGetWindowData" );
1106 return fgStructure.CurrentWindow->UserData;
1109 void FGAPIENTRY glutSetWindowData(void* data)
1111 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowData" );
1112 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowData" );
1113 fgStructure.CurrentWindow->UserData = data;
1116 /*** END OF FILE ***/