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 /* Push a null at the end of the list */
133 if( ! wantIndexedMode )
134 return glXChooseVisual( fgDisplay.Display, fgDisplay.Screen,
138 XVisualInfo* visualInfo;
142 * In indexed mode, we need to check how many bits of depth can we
143 * achieve. We do this by trying each possibility from the list
144 * given in the {bufferSize} array. If we match, we return to caller.
146 for( i=0; i<BUFFER_SIZES; i++ )
148 attributes[ 1 ] = bufferSize[ i ];
149 visualInfo = glXChooseVisual( fgDisplay.Display, fgDisplay.Screen,
151 if( visualInfo != NULL )
160 * Setup the pixel format for a Win32 window
162 #if TARGET_HOST_WIN32
163 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
164 unsigned char layer_type )
166 #if TARGET_HOST_WINCE
169 PIXELFORMATDESCRIPTOR* ppfd, pfd;
170 int flags, pixelformat;
172 freeglut_return_val_if_fail( window != NULL, 0 );
173 flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
174 if( fgState.DisplayMode & GLUT_DOUBLE )
175 flags |= PFD_DOUBLEBUFFER;
177 #if defined(_MSC_VER)
178 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
181 /* Specify which pixel format do we opt for... */
182 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
185 pfd.iPixelType = PFD_TYPE_RGBA;
196 pfd.cAccumRedBits = 0;
197 pfd.cAccumGreenBits = 0;
198 pfd.cAccumBlueBits = 0;
199 pfd.cAccumAlphaBits = 0;
202 pfd.cStencilBits = 0;
205 pfd.cStencilBits = 8;
208 pfd.iLayerType = layer_type;
211 pfd.dwVisibleMask = 0;
212 pfd.dwDamageMask = 0;
214 pfd.cColorBits = (BYTE) GetDeviceCaps( window->Window.Device, BITSPIXEL );
217 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
218 if( pixelformat == 0 )
223 return SetPixelFormat( window->Window.Device, pixelformat, ppfd );
224 #endif /* TARGET_HOST_WINCE */
229 * Sets the OpenGL context and the fgStructure "Current Window" pointer to
230 * the window structure passed in.
232 void fgSetWindow ( SFG_Window *window )
234 #if TARGET_HOST_UNIX_X11
238 window->Window.Handle,
239 window->Window.Context
241 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
242 if( fgStructure.Window )
243 ReleaseDC( fgStructure.Window->Window.Handle,
244 fgStructure.Window->Window.Device );
248 window->Window.Device = GetDC( window->Window.Handle );
250 window->Window.Device,
251 window->Window.Context
255 fgStructure.Window = window;
260 * Opens a window. Requires a SFG_Window object created and attached
261 * to the freeglut structure. OpenGL context is created here.
263 void fgOpenWindow( SFG_Window* window, const char* title,
264 int x, int y, int w, int h,
265 GLboolean gameMode, GLboolean isSubWindow )
267 #if TARGET_HOST_UNIX_X11
268 XSetWindowAttributes winAttr;
269 XTextProperty textProperty;
270 XSizeHints sizeHints;
273 unsigned int current_DisplayMode = fgState.DisplayMode ;
275 /* Save the display mode if we are creating a menu window */
276 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
277 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ;
279 window->Window.VisualInfo = fgChooseVisual( );
281 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
282 fgState.DisplayMode = current_DisplayMode ;
284 if( ! window->Window.VisualInfo )
287 * The "fgChooseVisual" returned a null meaning that the visual
288 * context is not available.
289 * Try a couple of variations to see if they will work.
291 if( !( fgState.DisplayMode & GLUT_DOUBLE ) )
293 fgState.DisplayMode |= GLUT_DOUBLE ;
294 window->Window.VisualInfo = fgChooseVisual( );
295 fgState.DisplayMode &= ~GLUT_DOUBLE;
299 * GLUT also checks for multi-sampling, but I don't see that
300 * anywhere else in FREEGLUT so I won't bother with it for the moment.
304 FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.VisualInfo != NULL,
305 "Unable to get window visual info", "fgOpenWindow" );
308 * XXX HINT: the masks should be updated when adding/removing callbacks.
309 * XXX This might speed up message processing. Is that true?
311 * XXX A: Not appreciably, but it WILL make it easier to debug.
312 * XXX Try tracing old GLUT and try tracing freeglut. Old GLUT
313 * XXX turns off events that it doesn't need and is a whole lot
314 * XXX more pleasant to trace. (Think mouse-motion! Tons of
315 * XXX ``bonus'' GUI events stream in.)
318 StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
319 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyRelease |
320 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
321 PointerMotionMask | ButtonMotionMask;
322 winAttr.background_pixmap = None;
323 winAttr.background_pixel = 0;
324 winAttr.border_pixel = 0;
326 winAttr.colormap = XCreateColormap(
327 fgDisplay.Display, fgDisplay.RootWindow,
328 window->Window.VisualInfo->visual, AllocNone
331 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
335 winAttr.override_redirect = True;
336 mask |= CWOverrideRedirect;
339 window->Window.Handle = XCreateWindow(
341 window->Parent == NULL ? fgDisplay.RootWindow :
342 window->Parent->Window.Handle,
344 window->Window.VisualInfo->depth, InputOutput,
345 window->Window.VisualInfo->visual, mask,
350 * The GLX context creation, possibly trying the direct context rendering
351 * or else use the current context if the user has so specified
356 * If there isn't already an OpenGL rendering context for menu
359 if( !fgStructure.MenuContext )
361 fgStructure.MenuContext =
362 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
363 fgStructure.MenuContext->VisualInfo = window->Window.VisualInfo;
364 fgStructure.MenuContext->Context = glXCreateContext(
365 fgDisplay.Display, fgStructure.MenuContext->VisualInfo,
366 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
370 /* window->Window.Context = fgStructure.MenuContext->Context; */
371 window->Window.Context = glXCreateContext(
372 fgDisplay.Display, window->Window.VisualInfo,
373 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
376 else if( fgState.UseCurrentContext )
378 window->Window.Context = glXGetCurrentContext( );
380 if( ! window->Window.Context )
381 window->Window.Context = glXCreateContext(
382 fgDisplay.Display, window->Window.VisualInfo,
383 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
387 window->Window.Context = glXCreateContext(
388 fgDisplay.Display, window->Window.VisualInfo,
389 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
392 #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ )
393 if( !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
395 if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
396 fgError( "Unable to force direct context rendering for window '%s'",
398 else if( fgState.DirectContext == GLUT_TRY_DIRECT_CONTEXT )
399 fgWarning( "Unable to create direct context rendering for window '%s'\nThis may hurt performance.",
406 window->Window.Handle,
407 window->Window.Context
411 * XXX Assume the new window is visible by default
412 * XXX Is this a safe assumption?
414 window->State.Visible = GL_TRUE;
417 if ( fgState.Position.Use )
418 sizeHints.flags |= USPosition;
419 if ( fgState.Size.Use )
420 sizeHints.flags |= USSize;
423 * Fill in the size hints values now (the x, y, width and height
424 * settings are obsolete, are there any more WMs that support them?)
425 * Unless the X servers actually stop supporting these, we should
426 * continue to fill them in. It is *not* our place to tell the user
427 * that they should replace a window manager that they like, and which
428 * works, just because *we* think that it's not "modern" enough.
433 sizeHints.height = h;
435 wmHints.flags = StateHint;
436 wmHints.initial_state = fgState.ForceIconic ? IconicState : NormalState;
437 /* Prepare the window and iconified window names... */
438 XStringListToTextProperty( (char **) &title, 1, &textProperty );
442 window->Window.Handle,
452 XSetWMProtocols( fgDisplay.Display, window->Window.Handle,
453 &fgDisplay.DeleteWindow, 1 );
455 XMapWindow( fgDisplay.Display, window->Window.Handle );
457 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
464 /* Grab the window class we have registered on glutInit(): */
465 atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
466 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Info Not Found",
471 FREEGLUT_INTERNAL_ERROR_EXIT ( window->Parent == NULL,
472 "Game mode being invoked on a subwindow",
476 * Set the window creation flags appropriately to make the window
479 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
483 #if !TARGET_HOST_WINCE
484 if ( ( ! isSubWindow ) && ( ! window->IsMenu ) )
487 * Update the window dimensions, taking account of window
488 * decorations. "freeglut" is to create the window with the
489 * outside of its border at (x,y) and with dimensions (w,h).
491 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
492 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 +
493 GetSystemMetrics( SM_CYCAPTION );
495 #endif /* TARGET_HOST_WINCE */
497 if( ! fgState.Position.Use )
502 if( ! fgState.Size.Use )
509 * There's a small difference between creating the top, child and
512 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
514 if ( window->IsMenu )
517 exFlags |= WS_EX_TOOLWINDOW;
519 #if !TARGET_HOST_WINCE
520 else if( window->Parent == NULL )
521 flags |= WS_OVERLAPPEDWINDOW;
527 #if TARGET_HOST_WINCE
529 wchar_t* wstr = fghWstrFromStr(title);
531 window->Window.Handle = CreateWindow(
534 WS_VISIBLE | WS_POPUP,
544 SHFullScreen(window->Window.Handle, SHFS_HIDESTARTICON);
545 SHFullScreen(window->Window.Handle, SHFS_HIDESIPBUTTON);
546 SHFullScreen(window->Window.Handle, SHFS_HIDETASKBAR);
547 MoveWindow(window->Window.Handle, 0, 0, 240, 320, TRUE);
548 ShowWindow(window->Window.Handle, SW_SHOW);
549 UpdateWindow(window->Window.Handle);
552 window->Window.Handle = CreateWindowEx(
558 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
563 #endif /* TARGET_HOST_WINCE */
565 if( !( window->Window.Handle ) )
566 fgError( "Failed to create a window (%s)!", title );
568 #if TARGET_HOST_WINCE
569 ShowWindow( window->Window.Handle, SW_SHOW );
571 ShowWindow( window->Window.Handle,
572 fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
573 #endif /* TARGET_HOST_WINCE */
575 UpdateWindow( window->Window.Handle );
576 ShowCursor( TRUE ); /* XXX Old comments say "hide cusror"! */
580 fgSetWindow( window );
582 window->Window.DoubleBuffered =
583 ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
585 if ( ! window->Window.DoubleBuffered )
587 glDrawBuffer ( GL_FRONT );
588 glReadBuffer ( GL_FRONT );
593 * Closes a window, destroying the frame and OpenGL context
595 void fgCloseWindow( SFG_Window* window )
597 #if TARGET_HOST_UNIX_X11
599 glXDestroyContext( fgDisplay.Display, window->Window.Context );
600 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
601 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
603 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
605 /* Make sure we don't close a window with current context active */
606 if( fgStructure.Window == window )
607 wglMakeCurrent( NULL, NULL );
610 * Step through the list of windows. If the rendering context
611 * is not being used by another window, then we delete it.
617 for( iter = (SFG_Window *)fgStructure.Windows.First;
619 iter = (SFG_Window *)iter->Node.Next )
621 if( ( iter->Window.Context == window->Window.Context ) &&
627 wglDeleteContext( window->Window.Context );
630 DestroyWindow( window->Window.Handle );
635 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
638 * Creates a new top-level freeglut window
640 int FGAPIENTRY glutCreateWindow( const char* title )
642 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateWindow" );
644 return fgCreateWindow( NULL, title, fgState.Position.X, fgState.Position.Y,
645 fgState.Size.X, fgState.Size.Y, GL_FALSE,
650 * This function creates a sub window.
652 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
655 SFG_Window* window = NULL;
656 SFG_Window* parent = NULL;
658 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateSubWindow" );
659 parent = fgWindowByID( parentID );
660 freeglut_return_val_if_fail( parent != NULL, 0 );
661 window = fgCreateWindow( parent, "", x, y, w, h, GL_FALSE, GL_FALSE );
668 * Destroys a window and all of its subwindows
670 void FGAPIENTRY glutDestroyWindow( int windowID )
673 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDestroyWindow" );
674 window = fgWindowByID( windowID );
675 freeglut_return_if_fail( window != NULL );
677 fgExecutionState ExecState = fgState.ExecState;
678 fgAddToWindowDestroyList( window );
679 fgState.ExecState = ExecState;
684 * This function selects the current window
686 void FGAPIENTRY glutSetWindow( int ID )
688 SFG_Window* window = NULL;
690 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindow" );
691 if( fgStructure.Window != NULL )
692 if( fgStructure.Window->ID == ID )
695 window = fgWindowByID( ID );
698 fgWarning( "glutSetWindow(): window ID %d not found!", ID );
702 fgSetWindow( window );
706 * This function returns the ID number of the current window, 0 if none exists
708 int FGAPIENTRY glutGetWindow( void )
710 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindow" );
711 if( fgStructure.Window == NULL )
713 return fgStructure.Window->ID;
717 * This function makes the current window visible
719 void FGAPIENTRY glutShowWindow( void )
721 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" );
722 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" );
724 #if TARGET_HOST_UNIX_X11
726 XMapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
727 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
729 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
731 ShowWindow( fgStructure.Window->Window.Handle, SW_SHOW );
735 fgStructure.Window->State.Redisplay = GL_TRUE;
739 * This function hides the current window
741 void FGAPIENTRY glutHideWindow( void )
743 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" );
744 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" );
746 #if TARGET_HOST_UNIX_X11
748 if( fgStructure.Window->Parent == NULL )
749 XWithdrawWindow( fgDisplay.Display,
750 fgStructure.Window->Window.Handle,
753 XUnmapWindow( fgDisplay.Display,
754 fgStructure.Window->Window.Handle );
755 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
757 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
759 ShowWindow( fgStructure.Window->Window.Handle, SW_HIDE );
763 fgStructure.Window->State.Redisplay = GL_FALSE;
767 * Iconify the current window (top-level windows only)
769 void FGAPIENTRY glutIconifyWindow( void )
771 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" );
772 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" );
774 fgStructure.Window->State.Visible = GL_FALSE;
775 #if TARGET_HOST_UNIX_X11
777 XIconifyWindow( fgDisplay.Display, fgStructure.Window->Window.Handle,
779 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
781 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
783 ShowWindow( fgStructure.Window->Window.Handle, SW_MINIMIZE );
787 fgStructure.Window->State.Redisplay = GL_FALSE;
791 * Set the current window's title
793 void FGAPIENTRY glutSetWindowTitle( const char* title )
795 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowTitle" );
796 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" );
797 if( ! fgStructure.Window->Parent )
799 #if TARGET_HOST_UNIX_X11
803 text.value = (unsigned char *) title;
804 text.encoding = XA_STRING;
806 text.nitems = strlen( title );
810 fgStructure.Window->Window.Handle,
814 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
816 #elif TARGET_HOST_WIN32
818 SetWindowText( fgStructure.Window->Window.Handle, title );
820 #elif TARGET_HOST_WINCE
822 wchar_t* wstr = fghWstrFromStr(title);
824 SetWindowText( fgStructure.Window->Window.Handle, wstr );
833 * Set the current window's iconified title
835 void FGAPIENTRY glutSetIconTitle( const char* title )
837 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" );
838 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" );
840 if( ! fgStructure.Window->Parent )
842 #if TARGET_HOST_UNIX_X11
846 text.value = (unsigned char *) title;
847 text.encoding = XA_STRING;
849 text.nitems = strlen( title );
853 fgStructure.Window->Window.Handle,
857 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
859 #elif TARGET_HOST_WIN32
861 SetWindowText( fgStructure.Window->Window.Handle, title );
863 #elif TARGET_HOST_WINCE
865 wchar_t* wstr = fghWstrFromStr(title);
867 SetWindowText( fgStructure.Window->Window.Handle, wstr );
876 * Change the current window's size
878 void FGAPIENTRY glutReshapeWindow( int width, int height )
880 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" );
881 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" );
883 fgStructure.Window->State.NeedToResize = GL_TRUE;
884 fgStructure.Window->State.Width = width ;
885 fgStructure.Window->State.Height = height;
889 * Change the current window's position
891 void FGAPIENTRY glutPositionWindow( int x, int y )
893 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" );
894 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" );
896 #if TARGET_HOST_UNIX_X11
898 XMoveWindow( fgDisplay.Display, fgStructure.Window->Window.Handle,
900 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
902 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
907 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
908 GetWindowRect( fgStructure.Window->Window.Handle, &winRect );
910 fgStructure.Window->Window.Handle,
913 winRect.right - winRect.left,
914 winRect.bottom - winRect.top,
923 * Lowers the current window (by Z order change)
925 void FGAPIENTRY glutPushWindow( void )
927 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPushWindow" );
928 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPushWindow" );
930 #if TARGET_HOST_UNIX_X11
932 XLowerWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
934 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
937 fgStructure.Window->Window.Handle,
940 SWP_NOSIZE | SWP_NOMOVE
947 * Raises the current window (by Z order change)
949 void FGAPIENTRY glutPopWindow( void )
951 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" );
952 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" );
954 #if TARGET_HOST_UNIX_X11
956 XRaiseWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
958 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
961 fgStructure.Window->Window.Handle,
964 SWP_NOSIZE | SWP_NOMOVE
971 * Resize the current window so that it fits the whole screen
973 void FGAPIENTRY glutFullScreen( void )
975 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" );
976 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" );
979 #if TARGET_HOST_UNIX_X11
985 fgStructure.Window->Window.Handle,
987 fgDisplay.ScreenWidth,
988 fgDisplay.ScreenHeight
991 XFlush( fgDisplay.Display ); /* This is needed */
993 XTranslateCoordinates(
995 fgStructure.Window->Window.Handle,
996 fgDisplay.RootWindow,
1004 fgStructure.Window->Window.Handle,
1007 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1009 #elif TARGET_HOST_WIN32
1012 /* For fullscreen mode, force the top-left corner to 0,0
1013 * and adjust the window rectangle so that the client area
1014 * covers the whole screen.
1019 rect.right = fgDisplay.ScreenWidth;
1020 rect.bottom = fgDisplay.ScreenHeight;
1022 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
1023 WS_CLIPCHILDREN, FALSE );
1026 * SWP_NOACTIVATE Do not activate the window
1027 * SWP_NOOWNERZORDER Do not change position in z-order
1028 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
1029 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
1032 SetWindowPos( fgStructure.Window->Window.Handle,
1036 rect.right - rect.left,
1037 rect.bottom - rect.top,
1038 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
1046 * A.Donev: Set and retrieve the window's user data
1048 void* FGAPIENTRY glutGetWindowData( void )
1050 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindowData" );
1051 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutGetWindowData" );
1052 return fgStructure.Window->UserData;
1055 void FGAPIENTRY glutSetWindowData(void* data)
1057 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowData" );
1058 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowData" );
1059 fgStructure.Window->UserData = data;
1062 /*** END OF FILE ***/