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 #define G_LOG_DOMAIN "freeglut-window"
34 #include "../include/GL/freeglut.h"
35 #include "freeglut_internal.h"
38 * TODO BEFORE THE STABLE RELEASE:
40 * fgChooseVisual() -- OK, but what about glutInitDisplayString()?
41 * fgSetupPixelFormat -- ignores the display mode settings
42 * fgOpenWindow() -- check the Win32 version, -iconic handling!
43 * fgCloseWindow() -- check the Win32 version
44 * glutCreateWindow() -- see what happens when default position and size is {-1,-1}
45 * glutCreateSubWindow() -- see what happens when default position and size is {-1,-1}
46 * glutDestroyWindow() -- check the Win32 version
47 * glutSetWindow() -- check the Win32 version
48 * glutGetWindow() -- OK
49 * glutSetWindowTitle() -- check the Win32 version
50 * glutSetIconTitle() -- check the Win32 version
51 * glutShowWindow() -- check the Win32 version
52 * glutHideWindow() -- check the Win32 version
53 * glutIconifyWindow() -- check the Win32 version
54 * glutReshapeWindow() -- check the Win32 version
55 * glutPositionWindow() -- check the Win32 version
56 * glutPushWindow() -- check the Win32 version
57 * glutPopWindow() -- check the Win32 version
60 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
63 * Chooses a visual basing on the current display mode settings
65 #if TARGET_HOST_UNIX_X11
67 XVisualInfo* fgChooseVisual( void )
69 int bufferSize[] = { 16, 12, 8, 4, 2, 1 };
70 GLboolean wantIndexedMode = FALSE;
75 * First we have to process the display mode settings...
77 # define ATTRIB(a) attributes[where++]=a;
80 * Decide if we want a true or indexed color visual:
82 if( !(fgState.DisplayMode & GLUT_INDEX) )
85 * We are sure that there will be R, B and B components requested:
88 ATTRIB( GLX_RED_SIZE ); ATTRIB( 1 );
89 ATTRIB( GLX_GREEN_SIZE ); ATTRIB( 1 );
90 ATTRIB( GLX_BLUE_SIZE ); ATTRIB( 1 );
93 * Check if the A component is required, too:
95 if( fgState.DisplayMode & GLUT_ALPHA )
97 ATTRIB( GLX_ALPHA_SIZE ); ATTRIB( 1 );
103 * We've got an indexed color request
105 ATTRIB( GLX_BUFFER_SIZE ); ATTRIB( 8 );
108 * Set the 'I want indexed mode' switch
110 wantIndexedMode = TRUE;
114 * We can have double or single buffered contexts created
116 if( fgState.DisplayMode & GLUT_DOUBLE )
118 ATTRIB( GLX_DOUBLEBUFFER );
122 * Stereoscopy seems a nice thing to have
124 if( fgState.DisplayMode & GLUT_STEREO )
126 ATTRIB( GLX_STEREO );
130 * Depth buffer is almost always required
132 if( fgState.DisplayMode & GLUT_DEPTH )
134 ATTRIB( GLX_DEPTH_SIZE ); ATTRIB( 1 );
140 if( fgState.DisplayMode & GLUT_STENCIL )
142 ATTRIB( GLX_STENCIL_SIZE ); ATTRIB( 1 );
146 * And finally the accumulation buffers
148 if( fgState.DisplayMode & GLUT_ACCUM )
150 ATTRIB( GLX_ACCUM_RED_SIZE ); ATTRIB( 1 );
151 ATTRIB( GLX_ACCUM_GREEN_SIZE ); ATTRIB( 1 );
152 ATTRIB( GLX_ACCUM_BLUE_SIZE ); ATTRIB( 1 );
155 * Check if the A component is required, too:
157 if( fgState.DisplayMode & GLUT_ALPHA )
159 ATTRIB( GLX_ACCUM_ALPHA_SIZE ); ATTRIB( 1 );
164 * Push a null at the end of the list
169 * OKi now, we've got two cases -- RGB(A) and index mode visuals
171 if( wantIndexedMode == FALSE )
174 * The easier one. And more common, too.
176 return( glXChooseVisual( fgDisplay.Display, fgDisplay.Screen, attributes ) );
180 XVisualInfo* visualInfo;
184 * In indexed mode, we need to check how many bits of depth can we achieve
190 * The GLX_BUFFER_SIZE value comes always first, so:
192 attributes[ 1 ] = bufferSize[ i ];
195 * Check if such visual is possible
197 visualInfo = glXChooseVisual( fgDisplay.Display, fgDisplay.Screen, attributes );
200 * The buffer size are sorted in descendant order, so choose the first:
202 if( visualInfo != NULL )
203 return( visualInfo );
207 * If we are still here, it means that the visual info was not found
215 * Setup the pixel format for a Win32 window
217 #if TARGET_HOST_WIN32
218 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly, unsigned char layer_type )
220 PIXELFORMATDESCRIPTOR* ppfd, pfd;
221 int flags, pixelformat;
224 * Check if the window seems valid
226 freeglut_return_val_if_fail( window != NULL, 0 );
229 * The pixel format should allow us to draw to the window using OpenGL
231 flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
234 * It might be the case for us to use double buffering
236 if( fgState.DisplayMode & GLUT_DOUBLE )
237 flags |= PFD_DOUBLEBUFFER;
240 * Specify which pixel format do we opt for...
242 # pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
244 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
247 pfd.iPixelType = PFD_TYPE_RGBA;
258 pfd.cAccumRedBits = 0;
259 pfd.cAccumGreenBits = 0;
260 pfd.cAccumBlueBits = 0;
261 pfd.cAccumAlphaBits = 0;
264 pfd.cStencilBits = 0;
267 pfd.cStencilBits = 8;
270 pfd.iLayerType = layer_type;
273 pfd.dwVisibleMask = 0;
274 pfd.dwDamageMask = 0;
277 * Fill in the color bits...
279 pfd.cColorBits = (BYTE) GetDeviceCaps( window->Window.Device, BITSPIXEL );
283 * Choose the pixel format that matches our demand
285 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
286 if( pixelformat == 0 )
290 * We might have been called to check if the pixel format exists only
296 * Finally, set the window's pixel format
298 return ( SetPixelFormat( window->Window.Device, pixelformat, ppfd ) ) ;
303 * Sets the OpenGL context and the fgStructure "Current Window" pointer to the window
304 * structure passed in.
306 void fgSetWindow ( SFG_Window *window )
308 #if TARGET_HOST_UNIX_X11
312 * Make the selected window's GLX context the current one
316 window->Window.Handle,
317 window->Window.Context
320 #elif TARGET_HOST_WIN32
322 * Release the previous' context's device context
324 if( fgStructure.Window != NULL )
325 ReleaseDC( fgStructure.Window->Window.Handle, fgStructure.Window->Window.Device );
330 * We will care about releasing the device context later
332 window->Window.Device = GetDC( window->Window.Handle );
335 * Set the new current context:
338 window->Window.Device,
339 window->Window.Context
345 * Remember that we have changed the current window state
347 fgStructure.Window = window;
352 * Opens a window. Requires a SFG_Window object created and attached
353 * to the freeglut structure. OpenGL context is created here.
355 void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, int h, GLboolean gameMode, int isSubWindow )
357 #if TARGET_HOST_UNIX_X11
358 XSetWindowAttributes winAttr;
359 XTextProperty textProperty;
360 XSizeHints sizeHints;
364 freeglut_assert_ready;
367 * Here we are upon the stage. Have the visual selected.
369 if ( fgState.BuildingAMenu )
372 * If there isn't already an OpenGL rendering context for menu windows, make one
374 if ( !fgStructure.MenuContext )
376 unsigned int current_DisplayMode = fgState.DisplayMode ;
377 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ;
378 window->Window.VisualInfo = fgChooseVisual();
379 fgState.DisplayMode = current_DisplayMode ;
382 window->Window.VisualInfo = fgChooseVisual();
385 window->Window.VisualInfo = fgChooseVisual();
387 if ( ! window->Window.VisualInfo )
390 * The "fgChooseVisual" returned a null meaning that the visual context is not available.
391 * Try a couple of variations to see if they will work.
393 if ( ! ( fgState.DisplayMode & GLUT_DOUBLE ) )
396 * Single buffering--try it doubled
398 fgState.DisplayMode |= GLUT_DOUBLE ;
399 window->Window.VisualInfo = fgChooseVisual();
400 /* OK, we got a double-buffered window, but we only wanted
401 * single-buffered. Clear the double-buffer flag now.
403 fgState.DisplayMode &= ~GLUT_DOUBLE ;
407 * GLUT also checks for multi-sampling, but I don't see that anywhere else in FREEGLUT
408 * so I won't bother with it for the moment.
412 assert( window->Window.VisualInfo != NULL );
415 * Have the windows attributes set
417 * HINT: the masks should be updated when adding/removing callbacks.
418 * This might speed up message processing. Is that true?
420 winAttr.event_mask = StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
421 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyRelease |
422 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
423 PointerMotionMask | ButtonMotionMask;
424 winAttr.background_pixmap = None;
425 winAttr.background_pixel = 0;
426 winAttr.border_pixel = 0;
429 * The color map is required, too
431 winAttr.colormap = XCreateColormap(
432 fgDisplay.Display, fgDisplay.RootWindow,
433 window->Window.VisualInfo->visual, AllocNone
437 * This tells the XCreateWindow() what attributes are we supplying it with
439 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
442 * If this is a menu window we want the window manager to ignore it.
444 if ( fgState.BuildingAMenu )
446 winAttr.override_redirect = True;
447 mask |= CWOverrideRedirect;
451 * Have the window created now
453 window->Window.Handle = XCreateWindow(
455 window->Parent == NULL ? fgDisplay.RootWindow : window->Parent->Window.Handle,
457 window->Window.VisualInfo->depth, InputOutput,
458 window->Window.VisualInfo->visual, mask,
463 * The GLX context creation, possibly trying the direct context rendering
464 * or else use the current context if the user has so specified
466 if ( fgState.BuildingAMenu )
469 * If there isn't already an OpenGL rendering context for menu windows, make one
471 if ( !fgStructure.MenuContext )
473 fgStructure.MenuContext = (SFG_MenuContext *)malloc ( sizeof(SFG_MenuContext) ) ;
474 fgStructure.MenuContext->VisualInfo = window->Window.VisualInfo ;
475 fgStructure.MenuContext->Context = glXCreateContext(
476 fgDisplay.Display, fgStructure.MenuContext->VisualInfo,
477 NULL, fgState.ForceDirectContext | fgState.TryDirectContext
481 /* window->Window.Context = fgStructure.MenuContext->Context ; */
482 window->Window.Context = glXCreateContext(
483 fgDisplay.Display, window->Window.VisualInfo,
484 NULL, fgState.ForceDirectContext | fgState.TryDirectContext
487 else if ( fgState.UseCurrentContext == TRUE )
489 window->Window.Context = glXGetCurrentContext();
491 if ( ! window->Window.Context )
492 window->Window.Context = glXCreateContext(
493 fgDisplay.Display, window->Window.VisualInfo,
494 NULL, fgState.ForceDirectContext | fgState.TryDirectContext
498 window->Window.Context = glXCreateContext(
499 fgDisplay.Display, window->Window.VisualInfo,
500 NULL, fgState.ForceDirectContext | fgState.TryDirectContext
504 * Make sure the context is direct when the user wants it forced
506 if( fgState.ForceDirectContext && !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
507 fgError( "unable to force direct context rendering for window '%s'", title );
510 * Set the new context as the current one. That's all about the window creation.
514 window->Window.Handle,
515 window->Window.Context
519 * Assume the new window is visible by default
521 window->State.Visible = TRUE;
524 * For the position and size hints -- make sure we are passing valid values
528 if (fgState.Position.Use == TRUE) sizeHints.flags |= USPosition;
529 if (fgState.Size.Use == TRUE) sizeHints.flags |= USSize;
532 * Fill in the size hints values now (the x, y, width and height
533 * settings are obsolote, are there any more WMs that support them?)
535 sizeHints.x = x; sizeHints.y = y;
536 sizeHints.width = w; sizeHints.height = h;
539 * We can have forced all new windows start in iconified state:
541 wmHints.flags = StateHint;
542 wmHints.initial_state = (fgState.ForceIconic == FALSE) ? NormalState : IconicState;
545 * Prepare the window and iconified window names...
547 XStringListToTextProperty( (char **) &title, 1, &textProperty );
550 * Set the window's properties now
554 window->Window.Handle,
565 * Make sure we are informed about the window deletion commands
567 XSetWMProtocols( fgDisplay.Display, window->Window.Handle, &fgDisplay.DeleteWindow, 1 );
570 * Finally, have the window mapped to our display
572 XMapWindow( fgDisplay.Display, window->Window.Handle );
574 #elif TARGET_HOST_WIN32
580 freeglut_assert_ready;
583 * Grab the window class we have registered on glutInit():
585 atom = GetClassInfo( fgDisplay.Instance, "FREEGLUT", &wc );
588 if( gameMode == FALSE )
590 if ( ( !isSubWindow ) && ( ! window->IsMenu ) )
593 * Update the window dimensions, taking account of window decorations.
594 * "freeglut" is to create the window with the outside of its border at (x,y)
595 * and with dimensions (w,h).
597 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
598 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 + GetSystemMetrics( SM_CYCAPTION );
602 * Check if the user wants us to use the default position/size
604 if( fgState.Position.Use == FALSE ) { x = CW_USEDEFAULT; y = CW_USEDEFAULT; }
605 if( fgState.Size .Use == FALSE ) { w = CW_USEDEFAULT; h = CW_USEDEFAULT; }
608 * There's a small difference between creating the top, child and game mode windows
610 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
613 * If we're a menu, set our flags to include WS_POPUP to remove decorations
615 if ( window->IsMenu )
617 else if( window->Parent == NULL )
618 flags |= WS_OVERLAPPEDWINDOW;
625 * In game mode, the story is a little bit different...
627 assert( window->Parent == NULL );
630 * Set the window creation flags appropriately to make the window entirely visible:
632 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
636 * Create the window now, passing the freeglut window structure as the parameter
638 window->Window.Handle = CreateWindow(
643 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
650 * Make sure window was created
652 assert( window->Window.Handle != NULL );
655 * Show and update the main window. Hide the mouse cursor.
657 ShowWindow( window->Window.Handle, fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
658 UpdateWindow( window->Window.Handle );
664 * Save the window's single- or double-buffering state
666 window->Window.DoubleBuffered = ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0 ;
669 * If it's not double-buffered, make sure the rendering is done to the front buffer.
671 if ( ! window->Window.DoubleBuffered )
673 glDrawBuffer ( GL_FRONT ) ;
674 glReadBuffer ( GL_FRONT ) ;
678 * Set the newly created window as the current one
680 fgSetWindow( window );
684 * Closes a window, destroying the frame and OpenGL context
686 void fgCloseWindow( SFG_Window* window )
688 freeglut_assert_ready;
690 #if TARGET_HOST_UNIX_X11
692 * As easy as kill bunnies with axes. Destroy the context first:
694 glXDestroyContext( fgDisplay.Display, window->Window.Context );
697 * Then have the window killed:
699 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
702 * Finally, flush the rests down the stream
704 XFlush( fgDisplay.Display );
706 #elif TARGET_HOST_WIN32
708 * Send the WM_CLOSE message to the window now
711 window->Window.Handle,
721 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
724 * Creates a new top-level freeglut window
726 int FGAPIENTRY glutCreateWindow( const char* title )
729 * Create a new window and return its unique ID number
731 return( fgCreateWindow( NULL, title, fgState.Position.X, fgState.Position.Y,
732 fgState.Size.X, fgState.Size.Y, FALSE )->ID );
736 * This function creates a sub window.
738 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
740 SFG_Window* window = NULL;
741 SFG_Window* parent = NULL;
743 freeglut_assert_ready;
746 * Find a parent to the newly created window...
748 parent = fgWindowByID( parentID );
751 * Fail if the parent has not been found
753 freeglut_return_val_if_fail( parent != NULL, 0 );
756 * Create the new window
758 window = fgCreateWindow( parent, "", x, y, w, h, FALSE );
761 * Return the new window's ID
763 return( window->ID );
767 * Destroys a window and all of its subwindows
769 void FGAPIENTRY glutDestroyWindow( int windowID )
771 fgExecutionState ExecState = fgState.ExecState ;
774 * Grab the freeglut window pointer from the structure
776 SFG_Window* window = fgWindowByID( windowID );
777 freeglut_return_if_fail( window != NULL );
780 * There is a function that performs all needed steps
781 * defined in freeglut_structure.c. Let's use it:
783 fgAddToWindowDestroyList( window, TRUE );
786 * Since the "fgAddToWindowDestroyList" function could easily have set the "ExecState"
787 * to stop, let's set it back to what it was.
789 fgState.ExecState = ExecState ;
793 * This function selects the current window
795 void FGAPIENTRY glutSetWindow( int ID )
797 SFG_Window* window = NULL;
800 * Make sure we don't get called too early
802 freeglut_assert_ready;
805 * Be wise. Be wise. Be wise. Be quick.
807 if( fgStructure.Window != NULL )
808 if( fgStructure.Window->ID == ID )
812 * Now we are sure there is sense in looking for the window
814 window = fgWindowByID( ID );
817 * In the case of an utter failure...
822 * ...issue a warning message and keep rolling on
824 fgWarning( "glutSetWindow(): window ID %i not found!", ID );
828 fgSetWindow ( window ) ;
832 * This function returns the ID number of the current window, 0 if none exists
834 int FGAPIENTRY glutGetWindow( void )
836 freeglut_assert_ready;
839 * Do we have a current window selected?
841 if( fgStructure.Window == NULL )
844 * Nope. Return zero to mark the state.
850 * Otherwise, return the ID of the current window
852 return( fgStructure.Window->ID );
856 * This function makes the current window visible
858 void FGAPIENTRY glutShowWindow( void )
860 freeglut_assert_ready; freeglut_assert_window;
862 #if TARGET_HOST_UNIX_X11
864 * Showing the window is done via mapping under X
866 XMapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
867 XFlush( fgDisplay.Display );
869 #elif TARGET_HOST_WIN32
871 * Restore the window's originial position and size
873 ShowWindow( fgStructure.Window->Window.Handle, SW_SHOW );
878 * Since the window is visible, we need to redisplay it ...
880 fgStructure.Window->State.Redisplay = TRUE;
885 * This function hides the current window
887 void FGAPIENTRY glutHideWindow( void )
889 freeglut_assert_ready; freeglut_assert_window;
891 #if TARGET_HOST_UNIX_X11
893 * The way we hide a window depends on if we're dealing
894 * with a top-level or children one...
896 if( fgStructure.Window->Parent == NULL )
899 * This is a top-level window
901 XWithdrawWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, fgDisplay.Screen );
906 * Nope, it's a child window
908 XUnmapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
912 * Flush the X state now
914 XFlush( fgDisplay.Display );
916 #elif TARGET_HOST_WIN32
920 ShowWindow( fgStructure.Window->Window.Handle, SW_HIDE );
925 * Since the window is hidden, we don't need to redisplay it ...
927 fgStructure.Window->State.Redisplay = FALSE;
931 * Iconify the current window (top-level windows only)
933 void FGAPIENTRY glutIconifyWindow( void )
935 freeglut_assert_ready; freeglut_assert_window;
937 #if TARGET_HOST_UNIX_X11
939 * Iconify the window and flush the X state
941 XIconifyWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, fgDisplay.Screen );
942 XFlush( fgDisplay.Display );
944 #elif TARGET_HOST_WIN32
946 * Minimize the current window (this should be the same as X window iconifying)
948 ShowWindow( fgStructure.Window->Window.Handle, SW_MINIMIZE );
953 * Since the window is just an icon, we don't need to redisplay it ...
955 fgStructure.Window->State.Redisplay = FALSE;
960 * Set the current window's title
962 void FGAPIENTRY glutSetWindowTitle( const char* title )
964 freeglut_assert_ready; freeglut_assert_window;
967 * Works only for top-level windows
969 if( fgStructure.Window->Parent != NULL )
972 #if TARGET_HOST_UNIX_X11
977 * Prepare the text properties
979 text.value = (unsigned char *) title;
980 text.encoding = XA_STRING;
982 text.nitems = strlen( title );
989 fgStructure.Window->Window.Handle,
994 * Have the X display state flushed
996 XFlush( fgDisplay.Display );
999 #elif TARGET_HOST_WIN32
1001 * This seems to be a bit easier under Win32
1003 SetWindowText( fgStructure.Window->Window.Handle, title );
1009 * Set the current window's iconified title
1011 void FGAPIENTRY glutSetIconTitle( const char* title )
1013 freeglut_assert_ready; freeglut_assert_window;
1016 * Works only for top-level windows
1018 if( fgStructure.Window->Parent != NULL )
1021 #if TARGET_HOST_UNIX_X11
1026 * Prepare the text properties
1028 text.value = (unsigned char *) title;
1029 text.encoding = XA_STRING;
1031 text.nitems = strlen( title );
1038 fgStructure.Window->Window.Handle,
1043 * Have the X display state flushed
1045 XFlush( fgDisplay.Display );
1048 #elif TARGET_HOST_WIN32
1050 * This seems to be a bit easier under Win32
1052 SetWindowText( fgStructure.Window->Window.Handle, title );
1058 * Change the current window's size
1060 void FGAPIENTRY glutReshapeWindow( int width, int height )
1062 freeglut_assert_ready; freeglut_assert_window;
1064 #if TARGET_HOST_UNIX_X11
1066 * Resize the window and flush the X state
1068 XResizeWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, width, height );
1069 XFlush( fgDisplay.Display );
1071 #elif TARGET_HOST_WIN32
1077 * First off, grab the current window's position
1079 GetWindowRect( fgStructure.Window->Window.Handle, &winRect );
1083 if ( fgStructure.Window->Parent == NULL ) /* If this is not a subwindow ... */
1086 * Adjust the size of the window to allow for the size of the frame, if we are not a menu
1088 if ( ! fgStructure.Window->IsMenu )
1090 width += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
1091 height += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 + GetSystemMetrics( SM_CYCAPTION );
1094 else /* This is a subwindow, get the parent window's position and subtract it off */
1096 GetWindowRect ( fgStructure.Window->Parent->Window.Handle, &winRect ) ;
1097 x -= winRect.left + GetSystemMetrics( SM_CXSIZEFRAME ) ;
1098 y -= winRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) + GetSystemMetrics( SM_CYCAPTION ) ;
1102 * Resize the window, forcing a redraw to happen
1105 fgStructure.Window->Window.Handle,
1117 * Change the current window's position
1119 void FGAPIENTRY glutPositionWindow( int x, int y )
1121 freeglut_assert_ready; freeglut_assert_window;
1123 #if TARGET_HOST_UNIX_X11
1125 * Reposition the window and flush the X state
1127 XMoveWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, x, y );
1128 XFlush( fgDisplay.Display );
1130 #elif TARGET_HOST_WIN32
1135 * First off, grab the current window's position
1137 GetWindowRect( fgStructure.Window->Window.Handle, &winRect );
1140 * Reposition the window, forcing a redraw to happen
1143 fgStructure.Window->Window.Handle,
1146 winRect.right - winRect.left,
1147 winRect.bottom - winRect.top,
1156 * Lowers the current window (by Z order change)
1158 void FGAPIENTRY glutPushWindow( void )
1160 freeglut_assert_ready; freeglut_assert_window;
1162 #if TARGET_HOST_UNIX_X11
1164 * Lower the current window
1166 XLowerWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
1168 #elif TARGET_HOST_WIN32
1170 * Set the new window's Z position, not affecting the rest of the settings:
1173 fgStructure.Window->Window.Handle,
1176 SWP_NOSIZE | SWP_NOMOVE
1183 * Raises the current window (by Z order change)
1185 void FGAPIENTRY glutPopWindow( void )
1187 freeglut_assert_ready; freeglut_assert_window;
1189 #if TARGET_HOST_UNIX_X11
1191 * Raise the current window
1193 XRaiseWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
1195 #elif TARGET_HOST_WIN32
1197 * Set the new window's Z position, not affecting the rest of the settings:
1200 fgStructure.Window->Window.Handle,
1203 SWP_NOSIZE | SWP_NOMOVE
1210 * Resize the current window so that it fits the whole screen
1212 void FGAPIENTRY glutFullScreen( void )
1214 freeglut_assert_ready; freeglut_assert_window;
1216 #if TARGET_HOST_UNIX_X11
1223 fgStructure.Window->Window.Handle,
1225 fgDisplay.ScreenWidth,
1226 fgDisplay.ScreenHeight
1228 XFlush( fgDisplay.Display );
1230 XTranslateCoordinates(
1232 fgStructure.Window->Window.Handle,
1233 fgDisplay.RootWindow,
1241 fgStructure.Window->Window.Handle,
1244 XFlush( fgDisplay.Display );
1247 #elif TARGET_HOST_WIN32
1249 fgStructure.Window->Window.Handle,
1251 fgDisplay.ScreenWidth,
1252 fgDisplay.ScreenHeight,
1259 * A.Donev: Set and retrieve the window's user data
1261 void* FGAPIENTRY glutGetWindowData( void )
1263 return(fgStructure.Window->UserData);
1266 void FGAPIENTRY glutSetWindowData(void* data)
1268 fgStructure.Window->UserData=data;
1271 /*** END OF FILE ***/