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.
32 #include <GL/freeglut.h>
33 #include "freeglut_internal.h"
37 #pragma comment( lib, "Aygshell.lib" )
39 static wchar_t* fghWstrFromStr(const char* str)
41 int i,len=strlen(str);
42 wchar_t* wstr = (wchar_t*)malloc(2*len+2);
50 #endif /* TARGET_HOST_WINCE */
53 * TODO BEFORE THE STABLE RELEASE:
55 * fgChooseVisual() -- OK, but what about glutInitDisplayString()?
56 * fgSetupPixelFormat -- ignores the display mode settings
57 * fgOpenWindow() -- check the Win32 version, -iconic handling!
58 * fgCloseWindow() -- check the Win32 version
59 * glutCreateWindow() -- Check when default position and size is {-1,-1}
60 * glutCreateSubWindow() -- Check when default position and size is {-1,-1}
61 * glutDestroyWindow() -- check the Win32 version
62 * glutSetWindow() -- check the Win32 version
63 * glutGetWindow() -- OK
64 * glutSetWindowTitle() -- check the Win32 version
65 * glutSetIconTitle() -- check the Win32 version
66 * glutShowWindow() -- check the Win32 version
67 * glutHideWindow() -- check the Win32 version
68 * glutIconifyWindow() -- check the Win32 version
69 * glutReshapeWindow() -- check the Win32 version
70 * glutPositionWindow() -- check the Win32 version
71 * glutPushWindow() -- check the Win32 version
72 * glutPopWindow() -- check the Win32 version
75 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
78 * Chooses a visual basing on the current display mode settings
80 #if TARGET_HOST_UNIX_X11
82 XVisualInfo* fgChooseVisual( void )
84 #define BUFFER_SIZES 6
85 int bufferSize[BUFFER_SIZES] = { 16, 12, 8, 4, 2, 1 };
86 GLboolean wantIndexedMode = GL_FALSE;
90 /* First we have to process the display mode settings... */
92 * XXX Why is there a semi-colon in this #define? The code
93 * XXX that uses the macro seems to always add more semicolons...
95 #define ATTRIB(a) attributes[where++]=a;
96 #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);}
98 if( fgState.DisplayMode & GLUT_INDEX )
100 ATTRIB_VAL( GLX_BUFFER_SIZE, 8 );
101 wantIndexedMode = GL_TRUE;
106 ATTRIB_VAL( GLX_RED_SIZE, 1 );
107 ATTRIB_VAL( GLX_GREEN_SIZE, 1 );
108 ATTRIB_VAL( GLX_BLUE_SIZE, 1 );
109 if( fgState.DisplayMode & GLUT_ALPHA )
110 ATTRIB_VAL( GLX_ALPHA_SIZE, 1 );
113 if( fgState.DisplayMode & GLUT_DOUBLE )
114 ATTRIB( GLX_DOUBLEBUFFER );
116 if( fgState.DisplayMode & GLUT_STEREO )
117 ATTRIB( GLX_STEREO );
119 if( fgState.DisplayMode & GLUT_DEPTH )
120 ATTRIB_VAL( GLX_DEPTH_SIZE, 1 );
122 if( fgState.DisplayMode & GLUT_STENCIL )
123 ATTRIB_VAL( GLX_STENCIL_SIZE, 1 );
125 if( fgState.DisplayMode & GLUT_ACCUM )
127 ATTRIB_VAL( GLX_ACCUM_RED_SIZE, 1 );
128 ATTRIB_VAL( GLX_ACCUM_GREEN_SIZE, 1 );
129 ATTRIB_VAL( GLX_ACCUM_BLUE_SIZE, 1 );
130 if( fgState.DisplayMode & GLUT_ALPHA )
131 ATTRIB_VAL( GLX_ACCUM_ALPHA_SIZE, 1 );
134 /* Push a null at the end of the list */
137 if( ! wantIndexedMode )
138 return glXChooseVisual( fgDisplay.Display, fgDisplay.Screen,
142 XVisualInfo* visualInfo;
146 * In indexed mode, we need to check how many bits of depth can we
147 * achieve. We do this by trying each possibility from the list
148 * given in the {bufferSize} array. If we match, we return to caller.
150 for( i=0; i<BUFFER_SIZES; i++ )
152 attributes[ 1 ] = bufferSize[ i ];
153 visualInfo = glXChooseVisual( fgDisplay.Display, fgDisplay.Screen,
155 if( visualInfo != NULL )
164 * Setup the pixel format for a Win32 window
166 #if TARGET_HOST_WIN32
167 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
168 unsigned char layer_type )
170 #if TARGET_HOST_WINCE
173 PIXELFORMATDESCRIPTOR* ppfd, pfd;
174 int flags, pixelformat;
176 freeglut_return_val_if_fail( window != NULL, 0 );
177 flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
178 if( fgState.DisplayMode & GLUT_DOUBLE )
179 flags |= PFD_DOUBLEBUFFER;
181 #if defined(_MSC_VER)
182 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
185 /* Specify which pixel format do we opt for... */
186 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
189 pfd.iPixelType = PFD_TYPE_RGBA;
200 pfd.cAccumRedBits = 0;
201 pfd.cAccumGreenBits = 0;
202 pfd.cAccumBlueBits = 0;
203 pfd.cAccumAlphaBits = 0;
206 pfd.cStencilBits = 0;
209 pfd.cStencilBits = 8;
212 pfd.iLayerType = layer_type;
215 pfd.dwVisibleMask = 0;
216 pfd.dwDamageMask = 0;
218 pfd.cColorBits = (BYTE) GetDeviceCaps( window->Window.Device, BITSPIXEL );
221 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
222 if( pixelformat == 0 )
227 return SetPixelFormat( window->Window.Device, pixelformat, ppfd );
228 #endif /* TARGET_HOST_WINCE */
233 * Sets the OpenGL context and the fgStructure "Current Window" pointer to
234 * the window structure passed in.
236 void fgSetWindow ( SFG_Window *window )
238 #if TARGET_HOST_UNIX_X11
242 window->Window.Handle,
243 window->Window.Context
245 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
246 if( fgStructure.Window )
247 ReleaseDC( fgStructure.Window->Window.Handle,
248 fgStructure.Window->Window.Device );
252 window->Window.Device = GetDC( window->Window.Handle );
254 window->Window.Device,
255 window->Window.Context
259 fgStructure.Window = window;
264 * Opens a window. Requires a SFG_Window object created and attached
265 * to the freeglut structure. OpenGL context is created here.
267 void fgOpenWindow( SFG_Window* window, const char* title,
268 int x, int y, int w, int h,
269 GLboolean gameMode, GLboolean isSubWindow )
271 #if TARGET_HOST_UNIX_X11
272 XSetWindowAttributes winAttr;
273 XTextProperty textProperty;
274 XSizeHints sizeHints;
277 unsigned int current_DisplayMode = fgState.DisplayMode ;
279 /* Save the display mode if we are creating a menu window */
280 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
281 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ;
283 window->Window.VisualInfo = fgChooseVisual( );
285 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
286 fgState.DisplayMode = current_DisplayMode ;
288 if( ! window->Window.VisualInfo )
291 * The "fgChooseVisual" returned a null meaning that the visual
292 * context is not available.
293 * Try a couple of variations to see if they will work.
295 if( !( fgState.DisplayMode & GLUT_DOUBLE ) )
297 fgState.DisplayMode |= GLUT_DOUBLE ;
298 window->Window.VisualInfo = fgChooseVisual( );
299 fgState.DisplayMode &= ~GLUT_DOUBLE;
303 * GLUT also checks for multi-sampling, but I don't see that
304 * anywhere else in FREEGLUT so I won't bother with it for the moment.
308 FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.VisualInfo != NULL,
309 "Unable to get window visual info", "fgOpenWindow" );
312 * XXX HINT: the masks should be updated when adding/removing callbacks.
313 * XXX This might speed up message processing. Is that true?
315 * XXX A: Not appreciably, but it WILL make it easier to debug.
316 * XXX Try tracing old GLUT and try tracing freeglut. Old GLUT
317 * XXX turns off events that it doesn't need and is a whole lot
318 * XXX more pleasant to trace. (Think mouse-motion! Tons of
319 * XXX ``bonus'' GUI events stream in.)
322 StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
323 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyRelease |
324 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
325 PointerMotionMask | ButtonMotionMask;
326 winAttr.background_pixmap = None;
327 winAttr.background_pixel = 0;
328 winAttr.border_pixel = 0;
330 winAttr.colormap = XCreateColormap(
331 fgDisplay.Display, fgDisplay.RootWindow,
332 window->Window.VisualInfo->visual, AllocNone
335 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
339 winAttr.override_redirect = True;
340 mask |= CWOverrideRedirect;
343 window->Window.Handle = XCreateWindow(
345 window->Parent == NULL ? fgDisplay.RootWindow :
346 window->Parent->Window.Handle,
348 window->Window.VisualInfo->depth, InputOutput,
349 window->Window.VisualInfo->visual, mask,
354 * The GLX context creation, possibly trying the direct context rendering
355 * or else use the current context if the user has so specified
360 * If there isn't already an OpenGL rendering context for menu
363 if( !fgStructure.MenuContext )
365 fgStructure.MenuContext =
366 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
367 fgStructure.MenuContext->VisualInfo = window->Window.VisualInfo;
368 fgStructure.MenuContext->Context = glXCreateContext(
369 fgDisplay.Display, fgStructure.MenuContext->VisualInfo,
370 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
374 /* window->Window.Context = fgStructure.MenuContext->Context; */
375 window->Window.Context = glXCreateContext(
376 fgDisplay.Display, window->Window.VisualInfo,
377 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
380 else if( fgState.UseCurrentContext )
382 window->Window.Context = glXGetCurrentContext( );
384 if( ! window->Window.Context )
385 window->Window.Context = glXCreateContext(
386 fgDisplay.Display, window->Window.VisualInfo,
387 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
391 window->Window.Context = glXCreateContext(
392 fgDisplay.Display, window->Window.VisualInfo,
393 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
396 #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ )
397 if( !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
399 if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
400 fgError( "Unable to force direct context rendering for window '%s'",
402 else if( fgState.DirectContext == GLUT_TRY_DIRECT_CONTEXT )
403 fgWarning( "Unable to create direct context rendering for window '%s'\nThis may hurt performance.",
410 window->Window.Handle,
411 window->Window.Context
415 * XXX Assume the new window is visible by default
416 * XXX Is this a safe assumption?
418 window->State.Visible = GL_TRUE;
421 if ( fgState.Position.Use )
422 sizeHints.flags |= USPosition;
423 if ( fgState.Size.Use )
424 sizeHints.flags |= USSize;
427 * Fill in the size hints values now (the x, y, width and height
428 * settings are obsolete, are there any more WMs that support them?)
429 * Unless the X servers actually stop supporting these, we should
430 * continue to fill them in. It is *not* our place to tell the user
431 * that they should replace a window manager that they like, and which
432 * works, just because *we* think that it's not "modern" enough.
437 sizeHints.height = h;
439 wmHints.flags = StateHint;
440 wmHints.initial_state = fgState.ForceIconic ? IconicState : NormalState;
441 /* Prepare the window and iconified window names... */
442 XStringListToTextProperty( (char **) &title, 1, &textProperty );
446 window->Window.Handle,
456 XSetWMProtocols( fgDisplay.Display, window->Window.Handle,
457 &fgDisplay.DeleteWindow, 1 );
459 XMapWindow( fgDisplay.Display, window->Window.Handle );
461 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
468 /* Grab the window class we have registered on glutInit(): */
469 atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
470 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Info Not Found",
475 FREEGLUT_INTERNAL_ERROR_EXIT ( window->Parent == NULL,
476 "Game mode being invoked on a subwindow",
480 * Set the window creation flags appropriately to make the window
483 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
487 #if !TARGET_HOST_WINCE
488 if ( ( ! isSubWindow ) && ( ! window->IsMenu ) )
491 * Update the window dimensions, taking account of window
492 * decorations. "freeglut" is to create the window with the
493 * outside of its border at (x,y) and with dimensions (w,h).
495 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
496 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 +
497 GetSystemMetrics( SM_CYCAPTION );
499 #endif /* TARGET_HOST_WINCE */
501 if( ! fgState.Position.Use )
506 if( ! fgState.Size.Use )
513 * There's a small difference between creating the top, child and
516 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
518 if ( window->IsMenu )
521 exFlags |= WS_EX_TOOLWINDOW;
523 #if !TARGET_HOST_WINCE
524 else if( window->Parent == NULL )
525 flags |= WS_OVERLAPPEDWINDOW;
531 #if TARGET_HOST_WINCE
533 wchar_t* wstr = fghWstrFromStr(title);
535 window->Window.Handle = CreateWindow(
538 WS_VISIBLE | WS_POPUP,
548 SHFullScreen(window->Window.Handle, SHFS_HIDESTARTICON);
549 SHFullScreen(window->Window.Handle, SHFS_HIDESIPBUTTON);
550 SHFullScreen(window->Window.Handle, SHFS_HIDETASKBAR);
551 MoveWindow(window->Window.Handle, 0, 0, 240, 320, TRUE);
552 ShowWindow(window->Window.Handle, SW_SHOW);
553 UpdateWindow(window->Window.Handle);
556 window->Window.Handle = CreateWindowEx(
562 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
567 #endif /* TARGET_HOST_WINCE */
569 if( !( window->Window.Handle ) )
570 fgError( "Failed to create a window (%s)!", title );
572 #if TARGET_HOST_WINCE
573 ShowWindow( window->Window.Handle, SW_SHOW );
575 ShowWindow( window->Window.Handle,
576 fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
577 #endif /* TARGET_HOST_WINCE */
579 UpdateWindow( window->Window.Handle );
580 ShowCursor( TRUE ); /* XXX Old comments say "hide cusror"! */
584 fgSetWindow( window );
586 window->Window.DoubleBuffered =
587 ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
589 if ( ! window->Window.DoubleBuffered )
591 glDrawBuffer ( GL_FRONT );
592 glReadBuffer ( GL_FRONT );
597 * Closes a window, destroying the frame and OpenGL context
599 void fgCloseWindow( SFG_Window* window )
601 #if TARGET_HOST_UNIX_X11
603 glXDestroyContext( fgDisplay.Display, window->Window.Context );
604 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
605 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
607 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
609 /* Make sure we don't close a window with current context active */
610 if( fgStructure.Window == window )
611 wglMakeCurrent( NULL, NULL );
614 * Step through the list of windows. If the rendering context
615 * is not being used by another window, then we delete it.
621 for( iter = (SFG_Window *)fgStructure.Windows.First;
623 iter = (SFG_Window *)iter->Node.Next )
625 if( ( iter->Window.Context == window->Window.Context ) &&
631 wglDeleteContext( window->Window.Context );
634 DestroyWindow( window->Window.Handle );
639 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
642 * Creates a new top-level freeglut window
644 int FGAPIENTRY glutCreateWindow( const char* title )
646 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateWindow" );
648 return fgCreateWindow( NULL, title, fgState.Position.X, fgState.Position.Y,
649 fgState.Size.X, fgState.Size.Y, GL_FALSE,
654 * This function creates a sub window.
656 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
659 SFG_Window* window = NULL;
660 SFG_Window* parent = NULL;
662 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateSubWindow" );
663 parent = fgWindowByID( parentID );
664 freeglut_return_val_if_fail( parent != NULL, 0 );
665 window = fgCreateWindow( parent, "", x, y, w, h, GL_FALSE, GL_FALSE );
672 * Destroys a window and all of its subwindows
674 void FGAPIENTRY glutDestroyWindow( int windowID )
677 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDestroyWindow" );
678 window = fgWindowByID( windowID );
679 freeglut_return_if_fail( window != NULL );
681 fgExecutionState ExecState = fgState.ExecState;
682 fgAddToWindowDestroyList( window );
683 fgState.ExecState = ExecState;
688 * This function selects the current window
690 void FGAPIENTRY glutSetWindow( int ID )
692 SFG_Window* window = NULL;
694 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindow" );
695 if( fgStructure.Window != NULL )
696 if( fgStructure.Window->ID == ID )
699 window = fgWindowByID( ID );
702 fgWarning( "glutSetWindow(): window ID %d not found!", ID );
706 fgSetWindow( window );
710 * This function returns the ID number of the current window, 0 if none exists
712 int FGAPIENTRY glutGetWindow( void )
714 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindow" );
715 if( fgStructure.Window == NULL )
717 return fgStructure.Window->ID;
721 * This function makes the current window visible
723 void FGAPIENTRY glutShowWindow( void )
725 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" );
726 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" );
728 #if TARGET_HOST_UNIX_X11
730 XMapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
731 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
733 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
735 ShowWindow( fgStructure.Window->Window.Handle, SW_SHOW );
739 fgStructure.Window->State.Redisplay = GL_TRUE;
743 * This function hides the current window
745 void FGAPIENTRY glutHideWindow( void )
747 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" );
748 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" );
750 #if TARGET_HOST_UNIX_X11
752 if( fgStructure.Window->Parent == NULL )
753 XWithdrawWindow( fgDisplay.Display,
754 fgStructure.Window->Window.Handle,
757 XUnmapWindow( fgDisplay.Display,
758 fgStructure.Window->Window.Handle );
759 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
761 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
763 ShowWindow( fgStructure.Window->Window.Handle, SW_HIDE );
767 fgStructure.Window->State.Redisplay = GL_FALSE;
771 * Iconify the current window (top-level windows only)
773 void FGAPIENTRY glutIconifyWindow( void )
775 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" );
776 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" );
778 fgStructure.Window->State.Visible = GL_FALSE;
779 #if TARGET_HOST_UNIX_X11
781 XIconifyWindow( fgDisplay.Display, fgStructure.Window->Window.Handle,
783 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
785 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
787 ShowWindow( fgStructure.Window->Window.Handle, SW_MINIMIZE );
791 fgStructure.Window->State.Redisplay = GL_FALSE;
795 * Set the current window's title
797 void FGAPIENTRY glutSetWindowTitle( const char* title )
799 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowTitle" );
800 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" );
801 if( ! fgStructure.Window->Parent )
803 #if TARGET_HOST_UNIX_X11
807 text.value = (unsigned char *) title;
808 text.encoding = XA_STRING;
810 text.nitems = strlen( title );
814 fgStructure.Window->Window.Handle,
818 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
820 #elif TARGET_HOST_WIN32
822 SetWindowText( fgStructure.Window->Window.Handle, title );
824 #elif TARGET_HOST_WINCE
826 wchar_t* wstr = fghWstrFromStr(title);
828 SetWindowText( fgStructure.Window->Window.Handle, wstr );
837 * Set the current window's iconified title
839 void FGAPIENTRY glutSetIconTitle( const char* title )
841 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" );
842 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" );
844 if( ! fgStructure.Window->Parent )
846 #if TARGET_HOST_UNIX_X11
850 text.value = (unsigned char *) title;
851 text.encoding = XA_STRING;
853 text.nitems = strlen( title );
857 fgStructure.Window->Window.Handle,
861 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
863 #elif TARGET_HOST_WIN32
865 SetWindowText( fgStructure.Window->Window.Handle, title );
867 #elif TARGET_HOST_WINCE
869 wchar_t* wstr = fghWstrFromStr(title);
871 SetWindowText( fgStructure.Window->Window.Handle, wstr );
880 * Change the current window's size
882 void FGAPIENTRY glutReshapeWindow( int width, int height )
884 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" );
885 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" );
887 fgStructure.Window->State.NeedToResize = GL_TRUE;
888 fgStructure.Window->State.Width = width ;
889 fgStructure.Window->State.Height = height;
893 * Change the current window's position
895 void FGAPIENTRY glutPositionWindow( int x, int y )
897 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" );
898 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" );
900 #if TARGET_HOST_UNIX_X11
902 XMoveWindow( fgDisplay.Display, fgStructure.Window->Window.Handle,
904 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
906 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
911 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
912 GetWindowRect( fgStructure.Window->Window.Handle, &winRect );
914 fgStructure.Window->Window.Handle,
917 winRect.right - winRect.left,
918 winRect.bottom - winRect.top,
927 * Lowers the current window (by Z order change)
929 void FGAPIENTRY glutPushWindow( void )
931 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPushWindow" );
932 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPushWindow" );
934 #if TARGET_HOST_UNIX_X11
936 XLowerWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
938 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
941 fgStructure.Window->Window.Handle,
944 SWP_NOSIZE | SWP_NOMOVE
951 * Raises the current window (by Z order change)
953 void FGAPIENTRY glutPopWindow( void )
955 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" );
956 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" );
958 #if TARGET_HOST_UNIX_X11
960 XRaiseWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
962 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
965 fgStructure.Window->Window.Handle,
968 SWP_NOSIZE | SWP_NOMOVE
975 * Resize the current window so that it fits the whole screen
977 void FGAPIENTRY glutFullScreen( void )
979 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" );
980 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" );
983 #if TARGET_HOST_UNIX_X11
989 fgStructure.Window->Window.Handle,
991 fgDisplay.ScreenWidth,
992 fgDisplay.ScreenHeight
995 XFlush( fgDisplay.Display ); /* This is needed */
997 XTranslateCoordinates(
999 fgStructure.Window->Window.Handle,
1000 fgDisplay.RootWindow,
1008 fgStructure.Window->Window.Handle,
1011 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1013 #elif TARGET_HOST_WIN32
1016 /* For fullscreen mode, force the top-left corner to 0,0
1017 * and adjust the window rectangle so that the client area
1018 * covers the whole screen.
1023 rect.right = fgDisplay.ScreenWidth;
1024 rect.bottom = fgDisplay.ScreenHeight;
1026 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
1027 WS_CLIPCHILDREN, FALSE );
1030 * SWP_NOACTIVATE Do not activate the window
1031 * SWP_NOOWNERZORDER Do not change position in z-order
1032 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
1033 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
1036 SetWindowPos( fgStructure.Window->Window.Handle,
1040 rect.right - rect.left,
1041 rect.bottom - rect.top,
1042 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
1050 * A.Donev: Set and retrieve the window's user data
1052 void* FGAPIENTRY glutGetWindowData( void )
1054 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindowData" );
1055 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutGetWindowData" );
1056 return fgStructure.Window->UserData;
1059 void FGAPIENTRY glutSetWindowData(void* data)
1061 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowData" );
1062 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowData" );
1063 fgStructure.Window->UserData = data;
1066 /*** END OF FILE ***/