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;
218 pfd.iLayerType = layer_type;
221 pfd.dwVisibleMask = 0;
222 pfd.dwDamageMask = 0;
224 pfd.cColorBits = (BYTE) GetDeviceCaps( window->Window.Device, BITSPIXEL );
227 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
228 if( pixelformat == 0 )
233 return SetPixelFormat( window->Window.Device, pixelformat, ppfd );
234 #endif /* TARGET_HOST_WINCE */
239 * Sets the OpenGL context and the fgStructure "Current Window" pointer to
240 * the window structure passed in.
242 void fgSetWindow ( SFG_Window *window )
244 #if TARGET_HOST_UNIX_X11
248 window->Window.Handle,
249 window->Window.Context
251 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
252 if( fgStructure.Window )
253 ReleaseDC( fgStructure.Window->Window.Handle,
254 fgStructure.Window->Window.Device );
258 window->Window.Device = GetDC( window->Window.Handle );
260 window->Window.Device,
261 window->Window.Context
265 fgStructure.Window = window;
270 * Opens a window. Requires a SFG_Window object created and attached
271 * to the freeglut structure. OpenGL context is created here.
273 void fgOpenWindow( SFG_Window* window, const char* title,
274 int x, int y, int w, int h,
275 GLboolean gameMode, GLboolean isSubWindow )
277 #if TARGET_HOST_UNIX_X11
278 XSetWindowAttributes winAttr;
279 XTextProperty textProperty;
280 XSizeHints sizeHints;
283 unsigned int current_DisplayMode = fgState.DisplayMode ;
285 /* Save the display mode if we are creating a menu window */
286 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
287 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ;
289 window->Window.VisualInfo = fgChooseVisual( );
291 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
292 fgState.DisplayMode = current_DisplayMode ;
294 if( ! window->Window.VisualInfo )
297 * The "fgChooseVisual" returned a null meaning that the visual
298 * context is not available.
299 * Try a couple of variations to see if they will work.
301 if( !( fgState.DisplayMode & GLUT_DOUBLE ) )
303 fgState.DisplayMode |= GLUT_DOUBLE ;
304 window->Window.VisualInfo = fgChooseVisual( );
305 fgState.DisplayMode &= ~GLUT_DOUBLE;
309 * GLUT also checks for multi-sampling, but I don't see that
310 * anywhere else in FREEGLUT so I won't bother with it for the moment.
314 FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.VisualInfo != NULL,
315 "Visual with necessary capabilities not found", "fgOpenWindow" );
318 * XXX HINT: the masks should be updated when adding/removing callbacks.
319 * XXX This might speed up message processing. Is that true?
321 * XXX A: Not appreciably, but it WILL make it easier to debug.
322 * XXX Try tracing old GLUT and try tracing freeglut. Old GLUT
323 * XXX turns off events that it doesn't need and is a whole lot
324 * XXX more pleasant to trace. (Think mouse-motion! Tons of
325 * XXX ``bonus'' GUI events stream in.)
328 StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
329 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
330 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
331 PointerMotionMask | ButtonMotionMask;
332 winAttr.background_pixmap = None;
333 winAttr.background_pixel = 0;
334 winAttr.border_pixel = 0;
336 winAttr.colormap = XCreateColormap(
337 fgDisplay.Display, fgDisplay.RootWindow,
338 window->Window.VisualInfo->visual, AllocNone
341 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
345 winAttr.override_redirect = True;
346 mask |= CWOverrideRedirect;
349 window->Window.Handle = XCreateWindow(
351 window->Parent == NULL ? fgDisplay.RootWindow :
352 window->Parent->Window.Handle,
354 window->Window.VisualInfo->depth, InputOutput,
355 window->Window.VisualInfo->visual, mask,
360 * The GLX context creation, possibly trying the direct context rendering
361 * or else use the current context if the user has so specified
366 * If there isn't already an OpenGL rendering context for menu
369 if( !fgStructure.MenuContext )
371 fgStructure.MenuContext =
372 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
373 fgStructure.MenuContext->VisualInfo = window->Window.VisualInfo;
374 fgStructure.MenuContext->Context = glXCreateContext(
375 fgDisplay.Display, fgStructure.MenuContext->VisualInfo,
376 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
380 /* window->Window.Context = fgStructure.MenuContext->Context; */
381 window->Window.Context = glXCreateContext(
382 fgDisplay.Display, window->Window.VisualInfo,
383 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
386 else if( fgState.UseCurrentContext )
388 window->Window.Context = glXGetCurrentContext( );
390 if( ! window->Window.Context )
391 window->Window.Context = glXCreateContext(
392 fgDisplay.Display, window->Window.VisualInfo,
393 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
397 window->Window.Context = glXCreateContext(
398 fgDisplay.Display, window->Window.VisualInfo,
399 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
402 #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ )
403 if( !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
405 if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
406 fgError( "Unable to force direct context rendering for window '%s'",
408 else if( fgState.DirectContext == GLUT_TRY_DIRECT_CONTEXT )
409 fgWarning( "Unable to create direct context rendering for window '%s'\nThis may hurt performance.",
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 );
461 window->Window.Handle,
462 window->Window.Context
465 XMapWindow( fgDisplay.Display, window->Window.Handle );
467 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
474 /* Grab the window class we have registered on glutInit(): */
475 atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
476 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Info Not Found",
481 FREEGLUT_INTERNAL_ERROR_EXIT ( window->Parent == NULL,
482 "Game mode being invoked on a subwindow",
486 * Set the window creation flags appropriately to make the window
489 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
493 #if !TARGET_HOST_WINCE
494 if ( ( ! isSubWindow ) && ( ! window->IsMenu ) )
497 * Update the window dimensions, taking account of window
498 * decorations. "freeglut" is to create the window with the
499 * outside of its border at (x,y) and with dimensions (w,h).
501 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
502 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 +
503 GetSystemMetrics( SM_CYCAPTION );
505 #endif /* TARGET_HOST_WINCE */
507 if( ! fgState.Position.Use )
512 if( ! fgState.Size.Use )
519 * There's a small difference between creating the top, child and
522 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
524 if ( window->IsMenu )
527 exFlags |= WS_EX_TOOLWINDOW;
529 #if !TARGET_HOST_WINCE
530 else if( window->Parent == NULL )
531 flags |= WS_OVERLAPPEDWINDOW;
537 #if TARGET_HOST_WINCE
539 wchar_t* wstr = fghWstrFromStr(title);
541 window->Window.Handle = CreateWindow(
544 WS_VISIBLE | WS_POPUP,
554 SHFullScreen(window->Window.Handle, SHFS_HIDESTARTICON);
555 SHFullScreen(window->Window.Handle, SHFS_HIDESIPBUTTON);
556 SHFullScreen(window->Window.Handle, SHFS_HIDETASKBAR);
557 MoveWindow(window->Window.Handle, 0, 0, 240, 320, TRUE);
558 ShowWindow(window->Window.Handle, SW_SHOW);
559 UpdateWindow(window->Window.Handle);
562 window->Window.Handle = CreateWindowEx(
568 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
573 #endif /* TARGET_HOST_WINCE */
575 if( !( window->Window.Handle ) )
576 fgError( "Failed to create a window (%s)!", title );
578 #if TARGET_HOST_WINCE
579 ShowWindow( window->Window.Handle, SW_SHOW );
581 ShowWindow( window->Window.Handle,
582 fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
583 #endif /* TARGET_HOST_WINCE */
585 UpdateWindow( window->Window.Handle );
586 ShowCursor( TRUE ); /* XXX Old comments say "hide cusror"! */
590 fgSetWindow( window );
592 window->Window.DoubleBuffered =
593 ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
595 if ( ! window->Window.DoubleBuffered )
597 glDrawBuffer ( GL_FRONT );
598 glReadBuffer ( GL_FRONT );
603 * Closes a window, destroying the frame and OpenGL context
605 void fgCloseWindow( SFG_Window* window )
607 #if TARGET_HOST_UNIX_X11
609 glXDestroyContext( fgDisplay.Display, window->Window.Context );
610 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
611 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
613 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
615 /* Make sure we don't close a window with current context active */
616 if( fgStructure.Window == window )
617 wglMakeCurrent( NULL, NULL );
620 * Step through the list of windows. If the rendering context
621 * is not being used by another window, then we delete it.
627 for( iter = (SFG_Window *)fgStructure.Windows.First;
629 iter = (SFG_Window *)iter->Node.Next )
631 if( ( iter->Window.Context == window->Window.Context ) &&
637 wglDeleteContext( window->Window.Context );
640 DestroyWindow( window->Window.Handle );
645 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
648 * Creates a new top-level freeglut window
650 int FGAPIENTRY glutCreateWindow( const char* title )
652 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateWindow" );
654 return fgCreateWindow( NULL, title, fgState.Position.X, fgState.Position.Y,
655 fgState.Size.X, fgState.Size.Y, GL_FALSE,
660 * This function creates a sub window.
662 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
665 SFG_Window* window = NULL;
666 SFG_Window* parent = NULL;
668 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateSubWindow" );
669 parent = fgWindowByID( parentID );
670 freeglut_return_val_if_fail( parent != NULL, 0 );
671 window = fgCreateWindow( parent, "", x, y, w, h, GL_FALSE, GL_FALSE );
678 * Destroys a window and all of its subwindows
680 void FGAPIENTRY glutDestroyWindow( int windowID )
683 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDestroyWindow" );
684 window = fgWindowByID( windowID );
685 freeglut_return_if_fail( window != NULL );
687 fgExecutionState ExecState = fgState.ExecState;
688 fgAddToWindowDestroyList( window );
689 fgState.ExecState = ExecState;
694 * This function selects the current window
696 void FGAPIENTRY glutSetWindow( int ID )
698 SFG_Window* window = NULL;
700 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindow" );
701 if( fgStructure.Window != NULL )
702 if( fgStructure.Window->ID == ID )
705 window = fgWindowByID( ID );
708 fgWarning( "glutSetWindow(): window ID %d not found!", ID );
712 fgSetWindow( window );
716 * This function returns the ID number of the current window, 0 if none exists
718 int FGAPIENTRY glutGetWindow( void )
720 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindow" );
721 if( fgStructure.Window == NULL )
723 return fgStructure.Window->ID;
727 * This function makes the current window visible
729 void FGAPIENTRY glutShowWindow( void )
731 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" );
732 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" );
734 #if TARGET_HOST_UNIX_X11
736 XMapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
737 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
739 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
741 ShowWindow( fgStructure.Window->Window.Handle, SW_SHOW );
745 fgStructure.Window->State.Redisplay = GL_TRUE;
749 * This function hides the current window
751 void FGAPIENTRY glutHideWindow( void )
753 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" );
754 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" );
756 #if TARGET_HOST_UNIX_X11
758 if( fgStructure.Window->Parent == NULL )
759 XWithdrawWindow( fgDisplay.Display,
760 fgStructure.Window->Window.Handle,
763 XUnmapWindow( fgDisplay.Display,
764 fgStructure.Window->Window.Handle );
765 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
767 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
769 ShowWindow( fgStructure.Window->Window.Handle, SW_HIDE );
773 fgStructure.Window->State.Redisplay = GL_FALSE;
777 * Iconify the current window (top-level windows only)
779 void FGAPIENTRY glutIconifyWindow( void )
781 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" );
782 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" );
784 fgStructure.Window->State.Visible = GL_FALSE;
785 #if TARGET_HOST_UNIX_X11
787 XIconifyWindow( fgDisplay.Display, fgStructure.Window->Window.Handle,
789 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
791 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
793 ShowWindow( fgStructure.Window->Window.Handle, SW_MINIMIZE );
797 fgStructure.Window->State.Redisplay = GL_FALSE;
801 * Set the current window's title
803 void FGAPIENTRY glutSetWindowTitle( const char* title )
805 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowTitle" );
806 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" );
807 if( ! fgStructure.Window->Parent )
809 #if TARGET_HOST_UNIX_X11
813 text.value = (unsigned char *) title;
814 text.encoding = XA_STRING;
816 text.nitems = strlen( title );
820 fgStructure.Window->Window.Handle,
824 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
826 #elif TARGET_HOST_WIN32
828 SetWindowText( fgStructure.Window->Window.Handle, title );
830 #elif TARGET_HOST_WINCE
832 wchar_t* wstr = fghWstrFromStr(title);
834 SetWindowText( fgStructure.Window->Window.Handle, wstr );
843 * Set the current window's iconified title
845 void FGAPIENTRY glutSetIconTitle( const char* title )
847 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" );
848 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" );
850 if( ! fgStructure.Window->Parent )
852 #if TARGET_HOST_UNIX_X11
856 text.value = (unsigned char *) title;
857 text.encoding = XA_STRING;
859 text.nitems = strlen( title );
863 fgStructure.Window->Window.Handle,
867 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
869 #elif TARGET_HOST_WIN32
871 SetWindowText( fgStructure.Window->Window.Handle, title );
873 #elif TARGET_HOST_WINCE
875 wchar_t* wstr = fghWstrFromStr(title);
877 SetWindowText( fgStructure.Window->Window.Handle, wstr );
886 * Change the current window's size
888 void FGAPIENTRY glutReshapeWindow( int width, int height )
890 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" );
891 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" );
893 fgStructure.Window->State.NeedToResize = GL_TRUE;
894 fgStructure.Window->State.Width = width ;
895 fgStructure.Window->State.Height = height;
899 * Change the current window's position
901 void FGAPIENTRY glutPositionWindow( int x, int y )
903 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" );
904 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" );
906 #if TARGET_HOST_UNIX_X11
908 XMoveWindow( fgDisplay.Display, fgStructure.Window->Window.Handle,
910 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
912 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
917 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
918 GetWindowRect( fgStructure.Window->Window.Handle, &winRect );
920 fgStructure.Window->Window.Handle,
923 winRect.right - winRect.left,
924 winRect.bottom - winRect.top,
933 * Lowers the current window (by Z order change)
935 void FGAPIENTRY glutPushWindow( void )
937 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPushWindow" );
938 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPushWindow" );
940 #if TARGET_HOST_UNIX_X11
942 XLowerWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
944 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
947 fgStructure.Window->Window.Handle,
950 SWP_NOSIZE | SWP_NOMOVE
957 * Raises the current window (by Z order change)
959 void FGAPIENTRY glutPopWindow( void )
961 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" );
962 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" );
964 #if TARGET_HOST_UNIX_X11
966 XRaiseWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
968 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
971 fgStructure.Window->Window.Handle,
974 SWP_NOSIZE | SWP_NOMOVE
981 * Resize the current window so that it fits the whole screen
983 void FGAPIENTRY glutFullScreen( void )
985 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" );
986 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" );
989 #if TARGET_HOST_UNIX_X11
995 fgStructure.Window->Window.Handle,
997 fgDisplay.ScreenWidth,
998 fgDisplay.ScreenHeight
1001 XFlush( fgDisplay.Display ); /* This is needed */
1003 XTranslateCoordinates(
1005 fgStructure.Window->Window.Handle,
1006 fgDisplay.RootWindow,
1014 fgStructure.Window->Window.Handle,
1017 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1019 #elif TARGET_HOST_WIN32
1022 /* For fullscreen mode, force the top-left corner to 0,0
1023 * and adjust the window rectangle so that the client area
1024 * covers the whole screen.
1029 rect.right = fgDisplay.ScreenWidth;
1030 rect.bottom = fgDisplay.ScreenHeight;
1032 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
1033 WS_CLIPCHILDREN, FALSE );
1036 * SWP_NOACTIVATE Do not activate the window
1037 * SWP_NOOWNERZORDER Do not change position in z-order
1038 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
1039 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
1042 SetWindowPos( fgStructure.Window->Window.Handle,
1046 rect.right - rect.left,
1047 rect.bottom - rect.top,
1048 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
1056 * A.Donev: Set and retrieve the window's user data
1058 void* FGAPIENTRY glutGetWindowData( void )
1060 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindowData" );
1061 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutGetWindowData" );
1062 return fgStructure.Window->UserData;
1065 void FGAPIENTRY glutSetWindowData(void* data)
1067 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowData" );
1068 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowData" );
1069 fgStructure.Window->UserData = data;
1072 /*** END OF FILE ***/