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 #define FREEGLUT_BUILDING_LIB
29 #include <GL/freeglut.h>
30 #include "freeglut_internal.h"
32 #if TARGET_HOST_POSIX_X11
33 #include <limits.h> /* LONG_MAX */
36 #if defined(_WIN32_WCE)
37 # include <Aygshell.h>
38 # ifdef FREEGLUT_LIB_PRAGMAS
39 # pragma comment( lib, "Aygshell.lib" )
41 #endif /* defined(_WIN32_WCE) */
44 #if TARGET_HOST_POSIX_X11
45 #ifndef GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB
46 #define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20B2
49 #ifndef GLX_CONTEXT_MAJOR_VERSION_ARB
50 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
53 #ifndef GLX_CONTEXT_MINOR_VERSION_ARB
54 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
57 #ifndef GLX_CONTEXT_FLAGS_ARB
58 #define GLX_CONTEXT_FLAGS_ARB 0x2094
61 #ifndef GLX_CONTEXT_PROFILE_MASK_ARB
62 #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
65 #ifndef GLX_CONTEXT_DEBUG_BIT_ARB
66 #define GLX_CONTEXT_DEBUG_BIT_ARB 0x0001
69 #ifndef GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
70 #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
73 #ifndef GLX_CONTEXT_CORE_PROFILE_BIT_ARB
74 #define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
77 #ifndef GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
78 #define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
81 #ifndef GLX_RGBA_FLOAT_TYPE
82 #define GLX_RGBA_FLOAT_TYPE 0x20B9
85 #ifndef GLX_RGBA_FLOAT_BIT
86 #define GLX_RGBA_FLOAT_BIT 0x00000004
88 #endif /* TARGET_HOST_POSIX_X11 */
91 #if TARGET_HOST_MS_WINDOWS
92 /* The following include file is available from SGI but is not standard:
93 * #include <GL/wglext.h>
94 * So we copy the necessary parts out of it.
95 * XXX: should local definitions for extensions be put in a separate include file?
97 typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
99 typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
101 #define WGL_DRAW_TO_WINDOW_ARB 0x2001
102 #define WGL_ACCELERATION_ARB 0x2003
103 #define WGL_SUPPORT_OPENGL_ARB 0x2010
104 #define WGL_DOUBLE_BUFFER_ARB 0x2011
105 #define WGL_COLOR_BITS_ARB 0x2014
106 #define WGL_ALPHA_BITS_ARB 0x201B
107 #define WGL_DEPTH_BITS_ARB 0x2022
108 #define WGL_STENCIL_BITS_ARB 0x2023
109 #define WGL_FULL_ACCELERATION_ARB 0x2027
111 #define WGL_SAMPLE_BUFFERS_ARB 0x2041
112 #define WGL_SAMPLES_ARB 0x2042
114 #define WGL_TYPE_RGBA_FLOAT_ARB 0x21A0
116 #define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9
118 #ifndef WGL_ARB_create_context
119 #define WGL_ARB_create_context 1
120 #ifdef WGL_WGLEXT_PROTOTYPES
121 extern HGLRC WINAPI wglCreateContextAttribsARB (HDC, HGLRC, const int *);
122 #endif /* WGL_WGLEXT_PROTOTYPES */
123 typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList);
125 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
126 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
127 #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
128 #define WGL_CONTEXT_FLAGS_ARB 0x2094
129 #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
131 #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
132 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
134 #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
135 #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
137 #define ERROR_INVALID_VERSION_ARB 0x2095
138 #define ERROR_INVALID_PROFILE_ARB 0x2096
141 #endif /* TARGET_HOST_MS_WINDOWS */
144 /* pushing attribute/value pairs into an array */
145 #define ATTRIB(a) attributes[where++]=(a)
146 #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);}
149 * TODO BEFORE THE STABLE RELEASE:
151 * fgChooseFBConfig() -- OK, but what about glutInitDisplayString()?
152 * fgSetupPixelFormat -- ignores the display mode settings
153 * fgOpenWindow() -- check the Win32 version, -iconic handling!
154 * fgCloseWindow() -- check the Win32 version
155 * glutCreateWindow() -- Check when default position and size is {-1,-1}
156 * glutCreateSubWindow() -- Check when default position and size is {-1,-1}
157 * glutDestroyWindow() -- check the Win32 version
158 * glutSetWindow() -- check the Win32 version
159 * glutGetWindow() -- OK
160 * glutSetWindowTitle() -- check the Win32 version
161 * glutSetIconTitle() -- check the Win32 version
162 * glutShowWindow() -- check the Win32 version
163 * glutHideWindow() -- check the Win32 version
164 * glutIconifyWindow() -- check the Win32 version
165 * glutReshapeWindow() -- check the Win32 version
166 * glutPositionWindow() -- check the Win32 version
167 * glutPushWindow() -- check the Win32 version
168 * glutPopWindow() -- check the Win32 version
171 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
173 static int fghIsLegacyContextVersionRequested( void )
175 return fgState.MajorVersion == 1 && fgState.MinorVersion == 0;
178 static int fghIsLegacyContextRequested( void )
180 return fghIsLegacyContextVersionRequested() &&
181 fgState.ContextFlags == 0 &&
182 fgState.ContextProfile == 0;
185 static int fghNumberOfAuxBuffersRequested( void )
187 if ( fgState.DisplayMode & GLUT_AUX4 ) {
190 if ( fgState.DisplayMode & GLUT_AUX3 ) {
193 if ( fgState.DisplayMode & GLUT_AUX2 ) {
196 if ( fgState.DisplayMode & GLUT_AUX1 ) { /* NOTE: Same as GLUT_AUX! */
197 return fgState.AuxiliaryBufferNumber;
202 static int fghMapBit( int mask, int from, int to )
204 return ( mask & from ) ? to : 0;
208 static void fghContextCreationError( void )
210 fgError( "Unable to create OpenGL %d.%d context (flags %x, profile %x)",
211 fgState.MajorVersion, fgState.MinorVersion, fgState.ContextFlags,
212 fgState.ContextProfile );
216 /* -- SYSTEM-DEPENDENT PRIVATE FUNCTIONS ------------------------------------ */
218 #if TARGET_HOST_POSIX_X11
220 * Chooses a visual basing on the current display mode settings
223 GLXFBConfig* fgChooseFBConfig( void )
225 GLboolean wantIndexedMode = GL_FALSE;
226 int attributes[ 100 ];
227 int where = 0, numAuxBuffers;
229 /* First we have to process the display mode settings... */
230 if( fgState.DisplayMode & GLUT_INDEX ) {
231 ATTRIB_VAL( GLX_BUFFER_SIZE, 8 );
232 /* Buffer size is selected later. */
234 ATTRIB_VAL( GLX_RENDER_TYPE, GLX_COLOR_INDEX_BIT );
235 wantIndexedMode = GL_TRUE;
237 ATTRIB_VAL( GLX_RED_SIZE, 1 );
238 ATTRIB_VAL( GLX_GREEN_SIZE, 1 );
239 ATTRIB_VAL( GLX_BLUE_SIZE, 1 );
240 if( fgState.DisplayMode & GLUT_ALPHA ) {
241 ATTRIB_VAL( GLX_ALPHA_SIZE, 1 );
245 if( fgState.DisplayMode & GLUT_DOUBLE ) {
246 ATTRIB_VAL( GLX_DOUBLEBUFFER, True );
249 if( fgState.DisplayMode & GLUT_STEREO ) {
250 ATTRIB_VAL( GLX_STEREO, True );
253 if( fgState.DisplayMode & GLUT_DEPTH ) {
254 ATTRIB_VAL( GLX_DEPTH_SIZE, 1 );
257 if( fgState.DisplayMode & GLUT_STENCIL ) {
258 ATTRIB_VAL( GLX_STENCIL_SIZE, 1 );
261 if( fgState.DisplayMode & GLUT_ACCUM ) {
262 ATTRIB_VAL( GLX_ACCUM_RED_SIZE, 1 );
263 ATTRIB_VAL( GLX_ACCUM_GREEN_SIZE, 1 );
264 ATTRIB_VAL( GLX_ACCUM_BLUE_SIZE, 1 );
265 if( fgState.DisplayMode & GLUT_ALPHA ) {
266 ATTRIB_VAL( GLX_ACCUM_ALPHA_SIZE, 1 );
270 numAuxBuffers = fghNumberOfAuxBuffersRequested();
271 if ( numAuxBuffers > 0 ) {
272 ATTRIB_VAL( GLX_AUX_BUFFERS, numAuxBuffers );
275 if( fgState.DisplayMode & GLUT_SRGB ) {
276 ATTRIB_VAL( GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB, True );
279 if (fgState.DisplayMode & GLUT_MULTISAMPLE) {
280 ATTRIB_VAL(GLX_SAMPLE_BUFFERS, 1);
281 ATTRIB_VAL(GLX_SAMPLES, fgState.SampleNumber);
284 /* Push a terminator at the end of the list */
288 GLXFBConfig * fbconfigArray; /* Array of FBConfigs */
289 GLXFBConfig * fbconfig; /* The FBConfig we want */
290 int fbconfigArraySize; /* Number of FBConfigs in the array */
293 /* Get all FBConfigs that match "attributes". */
294 fbconfigArray = glXChooseFBConfig( fgDisplay.Display,
297 &fbconfigArraySize );
299 if (fbconfigArray != NULL)
301 int result; /* Returned by glXGetFBConfigAttrib, not checked. */
304 if( wantIndexedMode )
307 * In index mode, we want the largest buffer size, i.e. visual
308 * depth. Here, FBConfigs are sorted by increasing buffer size
309 * first, so FBConfigs with the largest size come last.
312 int bufferSizeMin, bufferSizeMax;
314 /* Get bufferSizeMin. */
316 glXGetFBConfigAttrib( fgDisplay.Display,
320 /* Get bufferSizeMax. */
322 glXGetFBConfigAttrib( fgDisplay.Display,
323 fbconfigArray[fbconfigArraySize - 1],
327 if (bufferSizeMax > bufferSizeMin)
330 * Free and reallocate fbconfigArray, keeping only FBConfigs
331 * with the largest buffer size.
333 XFree(fbconfigArray);
335 /* Add buffer size token at the end of the list. */
337 ATTRIB_VAL( GLX_BUFFER_SIZE, bufferSizeMax );
340 fbconfigArray = glXChooseFBConfig( fgDisplay.Display,
343 &fbconfigArraySize );
348 * We now have an array of FBConfigs, the first one being the "best"
349 * one. So we should return only this FBConfig:
353 * - pick the XID of the FBConfig we want
354 * result = glXGetFBConfigAttrib( fgDisplay.Display,
360 * XFree(fbconfigArray);
362 * - reset "attributes" with the XID
364 * ATTRIB_VAL( GLX_FBCONFIG_ID, fbconfigXID );
367 * - get our FBConfig only
368 * fbconfig = glXChooseFBConfig( fgDisplay.Display,
371 * &fbconfigArraySize );
373 * However, for some configurations (for instance multisampling with
374 * Mesa 6.5.2 and ATI drivers), this does not work:
375 * glXChooseFBConfig returns NULL, whereas fbconfigXID is a valid
376 * XID. Further investigation is needed.
378 * So, for now, we return the whole array of FBConfigs. This should
379 * not produce any side effects elsewhere.
381 fbconfig = fbconfigArray;
393 static void fghFillContextAttributes( int *attributes ) {
394 int where = 0, contextFlags, contextProfile;
396 if ( !fghIsLegacyContextVersionRequested() ) {
397 ATTRIB_VAL( GLX_CONTEXT_MAJOR_VERSION_ARB, fgState.MajorVersion );
398 ATTRIB_VAL( GLX_CONTEXT_MINOR_VERSION_ARB, fgState.MinorVersion );
402 fghMapBit( fgState.ContextFlags, GLUT_DEBUG, GLX_CONTEXT_DEBUG_BIT_ARB ) |
403 fghMapBit( fgState.ContextFlags, GLUT_FORWARD_COMPATIBLE, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB );
404 if ( contextFlags != 0 ) {
405 ATTRIB_VAL( GLX_CONTEXT_FLAGS_ARB, contextFlags );
409 fghMapBit( fgState.ContextProfile, GLUT_CORE_PROFILE, GLX_CONTEXT_CORE_PROFILE_BIT_ARB ) |
410 fghMapBit( fgState.ContextProfile, GLUT_COMPATIBILITY_PROFILE, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB );
411 if ( contextProfile != 0 ) {
412 ATTRIB_VAL( GLX_CONTEXT_PROFILE_MASK_ARB, contextProfile );
418 typedef GLXContext (*CreateContextAttribsProc)(Display *dpy, GLXFBConfig config,
419 GLXContext share_list, Bool direct,
420 const int *attrib_list);
422 static GLXContext fghCreateNewContext( SFG_Window* window )
424 /* for color model calculation */
425 int menu = ( window->IsMenu && !fgStructure.MenuContext );
426 int index_mode = ( fgState.DisplayMode & GLUT_INDEX );
428 /* "classic" context creation */
429 Display *dpy = fgDisplay.Display;
430 GLXFBConfig config = *(window->Window.FBConfig);
431 int render_type = ( !menu && index_mode ) ? GLX_COLOR_INDEX_TYPE : GLX_RGBA_TYPE;
432 GLXContext share_list = NULL;
433 Bool direct = ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT );
436 /* new context creation */
438 CreateContextAttribsProc createContextAttribs;
440 /* If nothing fancy has been required, simply use the old context creation GLX API entry */
441 if ( fghIsLegacyContextRequested() )
443 context = glXCreateNewContext( dpy, config, render_type, share_list, direct );
444 if ( context == NULL ) {
445 fghContextCreationError();
450 /* color index mode is not available anymore with OpenGL 3.0 */
451 if ( render_type == GLX_COLOR_INDEX_TYPE ) {
452 fgWarning( "color index mode is deprecated, using RGBA mode" );
455 fghFillContextAttributes( attributes );
457 createContextAttribs = (CreateContextAttribsProc) fghGetProcAddress( "glXCreateContextAttribsARB" );
458 if ( createContextAttribs == NULL ) {
459 fgError( "glXCreateContextAttribsARB not found" );
462 context = createContextAttribs( dpy, config, share_list, direct, attributes );
463 if ( context == NULL ) {
464 fghContextCreationError();
470 #define _NET_WM_STATE_TOGGLE 2
471 static int fghResizeFullscrToggle(void)
473 XWindowAttributes attributes;
475 if(glutGet(GLUT_FULL_SCREEN)) {
476 /* restore original window size */
477 SFG_Window *win = fgStructure.CurrentWindow;
478 fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
479 fgStructure.CurrentWindow->State.Width = win->State.OldWidth;
480 fgStructure.CurrentWindow->State.Height = win->State.OldHeight;
483 /* resize the window to cover the entire screen */
484 XGetWindowAttributes(fgDisplay.Display,
485 fgStructure.CurrentWindow->Window.Handle,
489 * The "x" and "y" members of "attributes" are the window's coordinates
490 * relative to its parent, i.e. to the decoration window.
492 XMoveResizeWindow(fgDisplay.Display,
493 fgStructure.CurrentWindow->Window.Handle,
496 fgDisplay.ScreenWidth,
497 fgDisplay.ScreenHeight);
502 static int fghEwmhFullscrToggle(void)
505 long evmask = SubstructureRedirectMask | SubstructureNotifyMask;
507 if(!fgDisplay.State || !fgDisplay.StateFullScreen) {
511 xev.type = ClientMessage;
512 xev.xclient.window = fgStructure.CurrentWindow->Window.Handle;
513 xev.xclient.message_type = fgDisplay.State;
514 xev.xclient.format = 32;
515 xev.xclient.data.l[0] = _NET_WM_STATE_TOGGLE;
516 xev.xclient.data.l[1] = fgDisplay.StateFullScreen;
517 xev.xclient.data.l[2] = 0; /* no second property to toggle */
518 xev.xclient.data.l[3] = 1; /* source indication: application */
519 xev.xclient.data.l[4] = 0; /* unused */
521 if(!XSendEvent(fgDisplay.Display, fgDisplay.RootWindow, 0, evmask, &xev)) {
527 static int fghToggleFullscreen(void)
529 /* first try the EWMH (_NET_WM_STATE) method ... */
530 if(fghEwmhFullscrToggle() != -1) {
534 /* fall back to resizing the window */
535 if(fghResizeFullscrToggle() != -1) {
542 #endif /* TARGET_HOST_POSIX_X11 */
545 #if TARGET_HOST_MS_WINDOWS
547 * Setup the pixel format for a Win32 window
550 #if defined(_WIN32_WCE)
551 static wchar_t* fghWstrFromStr(const char* str)
553 int i,len=strlen(str);
554 wchar_t* wstr = (wchar_t*)malloc(2*len+2);
560 #endif /* defined(_WIN32_WCE) */
563 static void fghFillContextAttributes( int *attributes ) {
564 int where = 0, contextFlags, contextProfile;
566 if ( !fghIsLegacyContextVersionRequested() ) {
567 ATTRIB_VAL( WGL_CONTEXT_MAJOR_VERSION_ARB, fgState.MajorVersion );
568 ATTRIB_VAL( WGL_CONTEXT_MINOR_VERSION_ARB, fgState.MinorVersion );
572 fghMapBit( fgState.ContextFlags, GLUT_DEBUG, WGL_CONTEXT_DEBUG_BIT_ARB ) |
573 fghMapBit( fgState.ContextFlags, GLUT_FORWARD_COMPATIBLE, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB );
574 if ( contextFlags != 0 ) {
575 ATTRIB_VAL( WGL_CONTEXT_FLAGS_ARB, contextFlags );
579 fghMapBit( fgState.ContextProfile, GLUT_CORE_PROFILE, WGL_CONTEXT_CORE_PROFILE_BIT_ARB ) |
580 fghMapBit( fgState.ContextProfile, GLUT_COMPATIBILITY_PROFILE, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB );
581 if ( contextProfile != 0 ) {
582 ATTRIB_VAL( WGL_CONTEXT_PROFILE_MASK_ARB, contextProfile );
588 static int fghIsExtensionSupported( HDC hdc, const char *extension ) {
589 const char *pWglExtString;
590 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetEntensionsStringARB =
591 (PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB");
592 if ( wglGetEntensionsStringARB == NULL )
596 pWglExtString = wglGetEntensionsStringARB( hdc );
597 return ( pWglExtString != NULL ) && ( strstr(pWglExtString, extension) != NULL );
600 void fgNewWGLCreateContext( SFG_Window* window )
604 PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
606 /* If nothing fancy has been required, leave the context as it is */
607 if ( fghIsLegacyContextRequested() )
612 wglMakeCurrent( window->Window.Device, window->Window.Context );
614 if ( !fghIsExtensionSupported( window->Window.Device, "WGL_ARB_create_context" ) )
619 /* new context creation */
620 fghFillContextAttributes( attributes );
622 wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress( "wglCreateContextAttribsARB" );
623 if ( wglCreateContextAttribsARB == NULL )
625 fgError( "wglCreateContextAttribsARB not found" );
628 context = wglCreateContextAttribsARB( window->Window.Device, 0, attributes );
629 if ( context == NULL )
631 fghContextCreationError();
634 wglMakeCurrent( NULL, NULL );
635 wglDeleteContext( window->Window.Context );
636 window->Window.Context = context;
639 #if !defined(_WIN32_WCE)
641 static void fghFillPFD( PIXELFORMATDESCRIPTOR *ppfd, HDC hdc, unsigned char layer_type )
643 int flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
644 if ( fgState.DisplayMode & GLUT_DOUBLE ) {
645 flags |= PFD_DOUBLEBUFFER;
647 if ( fgState.DisplayMode & GLUT_STEREO ) {
651 #if defined(_MSC_VER)
652 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
655 /* Specify which pixel format do we opt for... */
656 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
658 ppfd->dwFlags = flags;
660 if( fgState.DisplayMode & GLUT_INDEX ) {
661 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
663 ppfd->cGreenBits = 0;
665 ppfd->cAlphaBits = 0;
667 ppfd->iPixelType = PFD_TYPE_RGBA;
669 ppfd->cGreenBits = 8;
671 ppfd->cAlphaBits = ( fgState.DisplayMode & GLUT_ALPHA ) ? 8 : 0;
674 ppfd->cColorBits = 24;
676 ppfd->cGreenShift = 0;
677 ppfd->cBlueShift = 0;
678 ppfd->cAlphaShift = 0;
679 ppfd->cAccumBits = 0;
680 ppfd->cAccumRedBits = 0;
681 ppfd->cAccumGreenBits = 0;
682 ppfd->cAccumBlueBits = 0;
683 ppfd->cAccumAlphaBits = 0;
685 /* Hmmm, or 32/0 instead of 24/8? */
686 ppfd->cDepthBits = 24;
687 ppfd->cStencilBits = 8;
689 ppfd->cAuxBuffers = fghNumberOfAuxBuffersRequested();
690 ppfd->iLayerType = layer_type;
692 ppfd->dwLayerMask = 0;
693 ppfd->dwVisibleMask = 0;
694 ppfd->dwDamageMask = 0;
696 ppfd->cColorBits = (BYTE) GetDeviceCaps( hdc, BITSPIXEL );
699 static void fghFillPixelFormatAttributes( int *attributes, const PIXELFORMATDESCRIPTOR *ppfd )
703 ATTRIB_VAL( WGL_DRAW_TO_WINDOW_ARB, GL_TRUE );
704 ATTRIB_VAL( WGL_SUPPORT_OPENGL_ARB, GL_TRUE );
705 ATTRIB_VAL( WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB );
707 ATTRIB_VAL( WGL_COLOR_BITS_ARB, ppfd->cColorBits );
708 ATTRIB_VAL( WGL_ALPHA_BITS_ARB, ppfd->cAlphaBits );
709 ATTRIB_VAL( WGL_DEPTH_BITS_ARB, ppfd->cDepthBits );
710 ATTRIB_VAL( WGL_STENCIL_BITS_ARB, ppfd->cStencilBits );
712 ATTRIB_VAL( WGL_DOUBLE_BUFFER_ARB, ( fgState.DisplayMode & GLUT_DOUBLE ) != 0 );
714 if ( fgState.DisplayMode & GLUT_SRGB ) {
715 ATTRIB_VAL( WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, TRUE );
718 ATTRIB_VAL( WGL_SAMPLE_BUFFERS_ARB, GL_TRUE );
719 ATTRIB_VAL( WGL_SAMPLES_ARB, fgState.SampleNumber );
724 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
725 unsigned char layer_type )
727 #if defined(_WIN32_WCE)
730 PIXELFORMATDESCRIPTOR pfd;
731 PIXELFORMATDESCRIPTOR* ppfd = &pfd;
734 fghFillPFD( ppfd, window->Window.Device, layer_type );
735 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
737 /* windows hack for multismapling/sRGB */
738 if ( ( fgState.DisplayMode & GLUT_MULTISAMPLE ) ||
739 ( fgState.DisplayMode & GLUT_SRGB ) )
741 HGLRC rc, rc_before=wglGetCurrentContext();
743 HDC hDC, hDC_before=wglGetCurrentDC();
746 /* create a dummy window */
747 ZeroMemory(&wndCls, sizeof(wndCls));
748 wndCls.lpfnWndProc = DefWindowProc;
749 wndCls.hInstance = fgDisplay.Instance;
750 wndCls.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
751 wndCls.lpszClassName = _T("FREEGLUT_dummy");
752 RegisterClass( &wndCls );
754 hWnd=CreateWindow(_T("FREEGLUT_dummy"), _T(""), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW , 0,0,0,0, 0, 0, fgDisplay.Instance, 0 );
756 SetPixelFormat( hDC, pixelformat, ppfd );
758 rc = wglCreateContext( hDC );
759 wglMakeCurrent(hDC, rc);
761 if ( fghIsExtensionSupported( hDC, "WGL_ARB_multisample" ) )
763 PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARBProc =
764 (PFNWGLCHOOSEPIXELFORMATARBPROC) wglGetProcAddress("wglChoosePixelFormatARB");
765 if ( wglChoosePixelFormatARBProc )
770 float fAttributes[] = { 0, 0 };
772 fghFillPixelFormatAttributes( attributes, ppfd );
773 bValid = wglChoosePixelFormatARBProc(window->Window.Device, attributes, fAttributes, 1, &iPixelFormat, &numFormats);
775 if ( bValid && numFormats > 0 )
777 pixelformat = iPixelFormat;
782 wglMakeCurrent( hDC_before, rc_before);
783 wglDeleteContext(rc);
784 ReleaseDC(hWnd, hDC);
786 UnregisterClass(_T("FREEGLUT_dummy"), fgDisplay.Instance);
789 return ( pixelformat != 0 ) && ( checkOnly || SetPixelFormat( window->Window.Device, pixelformat, ppfd ) );
790 #endif /* defined(_WIN32_WCE) */
793 #endif /* TARGET_HOST_MS_WINDOWS */
796 * Sets the OpenGL context and the fgStructure "Current Window" pointer to
797 * the window structure passed in.
799 void fgSetWindow ( SFG_Window *window )
801 #if TARGET_HOST_POSIX_X11
804 glXMakeContextCurrent(
806 window->Window.Handle,
807 window->Window.Handle,
808 window->Window.Context
811 #elif TARGET_HOST_MS_WINDOWS
812 if( fgStructure.CurrentWindow )
813 ReleaseDC( fgStructure.CurrentWindow->Window.Handle,
814 fgStructure.CurrentWindow->Window.Device );
818 window->Window.Device = GetDC( window->Window.Handle );
820 window->Window.Device,
821 window->Window.Context
825 fgStructure.CurrentWindow = window;
828 #if TARGET_HOST_MS_WINDOWS
836 static BOOL CALLBACK m_proc(HMONITOR mon,
841 m_proc_t *dp=(m_proc_t *)data;
844 info.cbSize=sizeof(info);
845 res=GetMonitorInfo(mon,(LPMONITORINFO)&info);
848 if( !strcmp(dp->name,info.szDevice) )
850 *(dp->x)=info.rcMonitor.left;
851 *(dp->y)=info.rcMonitor.top;
859 * this function is only used in fgOpenWindow. Currently it only sets
860 * its output parameters, if the DisplayName is set in fgDisplay
861 * (and if it is able to recognize the display)
864 static void get_display_origin(int *xp,int *yp)
866 if( fgDisplay.DisplayName )
871 st.name=fgDisplay.DisplayName;
872 EnumDisplayMonitors(0,0,m_proc,(LPARAM)&st);
880 * Opens a window. Requires a SFG_Window object created and attached
881 * to the freeglut structure. OpenGL context is created here.
883 void fgOpenWindow( SFG_Window* window, const char* title,
884 GLboolean positionUse, int x, int y,
885 GLboolean sizeUse, int w, int h,
886 GLboolean gameMode, GLboolean isSubWindow )
888 #if TARGET_HOST_POSIX_X11
889 XVisualInfo * visualInfo;
890 XSetWindowAttributes winAttr;
891 XTextProperty textProperty;
892 XSizeHints sizeHints;
895 unsigned int current_DisplayMode = fgState.DisplayMode ;
897 /* Save the display mode if we are creating a menu window */
898 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
899 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ;
901 window->Window.FBConfig = fgChooseFBConfig( );
903 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
904 fgState.DisplayMode = current_DisplayMode ;
906 if( ! window->Window.FBConfig )
909 * The "fgChooseFBConfig" returned a null meaning that the visual
910 * context is not available.
911 * Try a couple of variations to see if they will work.
913 if( !( fgState.DisplayMode & GLUT_DOUBLE ) )
915 fgState.DisplayMode |= GLUT_DOUBLE ;
916 window->Window.FBConfig = fgChooseFBConfig( );
917 fgState.DisplayMode &= ~GLUT_DOUBLE;
920 if( fgState.DisplayMode & GLUT_MULTISAMPLE )
922 fgState.DisplayMode &= ~GLUT_MULTISAMPLE ;
923 window->Window.FBConfig = fgChooseFBConfig( );
924 fgState.DisplayMode |= GLUT_MULTISAMPLE;
928 FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.FBConfig != NULL,
929 "FBConfig with necessary capabilities not found", "fgOpenWindow" );
931 /* Get the X visual. */
932 visualInfo = glXGetVisualFromFBConfig( fgDisplay.Display,
933 *(window->Window.FBConfig) );
936 * XXX HINT: the masks should be updated when adding/removing callbacks.
937 * XXX This might speed up message processing. Is that true?
939 * XXX A: Not appreciably, but it WILL make it easier to debug.
940 * XXX Try tracing old GLUT and try tracing freeglut. Old GLUT
941 * XXX turns off events that it doesn't need and is a whole lot
942 * XXX more pleasant to trace. (Think mouse-motion! Tons of
943 * XXX ``bonus'' GUI events stream in.)
946 StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
947 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
948 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
949 PointerMotionMask | ButtonMotionMask;
950 winAttr.background_pixmap = None;
951 winAttr.background_pixel = 0;
952 winAttr.border_pixel = 0;
954 winAttr.colormap = XCreateColormap(
955 fgDisplay.Display, fgDisplay.RootWindow,
956 visualInfo->visual, AllocNone
959 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
961 if( window->IsMenu || ( gameMode == GL_TRUE ) )
963 winAttr.override_redirect = True;
964 mask |= CWOverrideRedirect;
968 x = y = -1; /* default window position */
970 w = h = 300; /* default window size */
972 window->Window.Handle = XCreateWindow(
974 window->Parent == NULL ? fgDisplay.RootWindow :
975 window->Parent->Window.Handle,
977 visualInfo->depth, InputOutput,
978 visualInfo->visual, mask,
983 * The GLX context creation, possibly trying the direct context rendering
984 * or else use the current context if the user has so specified
990 * If there isn't already an OpenGL rendering context for menu
993 if( !fgStructure.MenuContext )
995 fgStructure.MenuContext =
996 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
997 fgStructure.MenuContext->MContext = fghCreateNewContext( window );
1000 /* window->Window.Context = fgStructure.MenuContext->MContext; */
1001 window->Window.Context = fghCreateNewContext( window );
1003 else if( fgState.UseCurrentContext )
1005 window->Window.Context = glXGetCurrentContext( );
1007 if( ! window->Window.Context )
1008 window->Window.Context = fghCreateNewContext( window );
1011 window->Window.Context = fghCreateNewContext( window );
1013 #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ )
1014 if( !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
1016 if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
1017 fgError( "Unable to force direct context rendering for window '%s'",
1023 * XXX Assume the new window is visible by default
1024 * XXX Is this a safe assumption?
1026 window->State.Visible = GL_TRUE;
1028 sizeHints.flags = 0;
1030 sizeHints.flags |= USPosition;
1032 sizeHints.flags |= USSize;
1035 * Fill in the size hints values now (the x, y, width and height
1036 * settings are obsolete, are there any more WMs that support them?)
1037 * Unless the X servers actually stop supporting these, we should
1038 * continue to fill them in. It is *not* our place to tell the user
1039 * that they should replace a window manager that they like, and which
1040 * works, just because *we* think that it's not "modern" enough.
1044 sizeHints.width = w;
1045 sizeHints.height = h;
1047 wmHints.flags = StateHint;
1048 wmHints.initial_state = fgState.ForceIconic ? IconicState : NormalState;
1049 /* Prepare the window and iconified window names... */
1050 XStringListToTextProperty( (char **) &title, 1, &textProperty );
1054 window->Window.Handle,
1063 XFree( textProperty.value );
1065 XSetWMProtocols( fgDisplay.Display, window->Window.Handle,
1066 &fgDisplay.DeleteWindow, 1 );
1068 glXMakeContextCurrent(
1070 window->Window.Handle,
1071 window->Window.Handle,
1072 window->Window.Context
1075 XMapWindow( fgDisplay.Display, window->Window.Handle );
1079 #elif TARGET_HOST_MS_WINDOWS
1085 int WindowStyle = 0;
1087 /* Grab the window class we have registered on glutInit(): */
1088 atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
1089 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Info Not Found",
1094 FREEGLUT_INTERNAL_ERROR_EXIT ( window->Parent == NULL,
1095 "Game mode being invoked on a subwindow",
1099 * Set the window creation flags appropriately to make the window
1102 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
1106 int worig = w, horig = h;
1108 #if !defined(_WIN32_WCE)
1109 if ( ( ! isSubWindow ) && ( ! window->IsMenu ) )
1112 * Update the window dimensions, taking account of window
1113 * decorations. "freeglut" is to create the window with the
1114 * outside of its border at (x,y) and with dimensions (w,h).
1116 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
1117 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 +
1118 GetSystemMetrics( SM_CYCAPTION );
1120 #endif /* defined(_WIN32_WCE) */
1127 /* setting State.Width/Height to call resize callback later */
1130 if( ! window->IsMenu )
1135 else /* fail safe - Windows can make a window of size (0, 0) */
1136 w = h = 300; /* default window size */
1137 window->State.Width = window->State.Height = -1;
1141 window->State.Width = worig;
1142 window->State.Height = horig;
1146 * There's a small difference between creating the top, child and
1149 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
1151 if ( window->IsMenu )
1154 exFlags |= WS_EX_TOOLWINDOW;
1156 #if !defined(_WIN32_WCE)
1157 else if( window->Parent == NULL )
1158 flags |= WS_OVERLAPPEDWINDOW;
1164 #if defined(_WIN32_WCE)
1166 wchar_t* wstr = fghWstrFromStr(title);
1168 window->Window.Handle = CreateWindow(
1171 WS_VISIBLE | WS_POPUP,
1181 SHFullScreen(window->Window.Handle, SHFS_HIDESTARTICON);
1182 SHFullScreen(window->Window.Handle, SHFS_HIDESIPBUTTON);
1183 SHFullScreen(window->Window.Handle, SHFS_HIDETASKBAR);
1184 MoveWindow(window->Window.Handle, 0, 0, 240, 320, TRUE);
1185 ShowWindow(window->Window.Handle, SW_SHOW);
1186 UpdateWindow(window->Window.Handle);
1190 /* xoff and yoff are used to place window relative to current display */
1191 /* The operation of gamemode also depends on this */
1193 get_display_origin(&xoff,&yoff);
1195 window->Window.Handle = CreateWindowEx(
1200 x+xoff, y+yoff, w, h,
1201 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
1207 #endif /* defined(_WIN32_WCE) */
1209 if( !( window->Window.Handle ) )
1210 fgError( "Failed to create a window (%s)!", title );
1212 /* Make a menu window always on top - fix Feature Request 947118 */
1213 if( window->IsMenu || gameMode )
1215 window->Window.Handle,
1218 SWP_NOMOVE | SWP_NOSIZE
1221 /* Hack to remove the caption (title bar) and/or border
1222 * and all the system menu controls.
1224 WindowStyle = GetWindowLong(window->Window.Handle, GWL_STYLE);
1225 if ( fgState.DisplayMode & GLUT_CAPTIONLESS )
1227 SetWindowLong ( window->Window.Handle, GWL_STYLE,
1228 WindowStyle & ~(WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX));
1230 else if ( fgState.DisplayMode & GLUT_BORDERLESS )
1232 SetWindowLong ( window->Window.Handle, GWL_STYLE,
1233 WindowStyle & ~(WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX));
1235 /* SetWindowPos(window->Window.Handle, NULL, 0, 0, 0, 0,
1236 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); */
1239 #if defined(_WIN32_WCE)
1240 ShowWindow( window->Window.Handle, SW_SHOW );
1242 ShowWindow( window->Window.Handle,
1243 fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
1244 #endif /* defined(_WIN32_WCE) */
1246 UpdateWindow( window->Window.Handle );
1247 ShowCursor( TRUE ); /* XXX Old comments say "hide cursor"! */
1251 fgSetWindow( window );
1253 window->Window.DoubleBuffered =
1254 ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
1256 if ( ! window->Window.DoubleBuffered )
1258 glDrawBuffer ( GL_FRONT );
1259 glReadBuffer ( GL_FRONT );
1264 * Closes a window, destroying the frame and OpenGL context
1266 void fgCloseWindow( SFG_Window* window )
1268 #if TARGET_HOST_POSIX_X11
1270 if( window->Window.Context )
1271 glXDestroyContext( fgDisplay.Display, window->Window.Context );
1272 XFree( window->Window.FBConfig );
1273 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
1274 /* XFlush( fgDisplay.Display ); */ /* XXX Shouldn't need this */
1276 #elif TARGET_HOST_MS_WINDOWS
1278 /* Make sure we don't close a window with current context active */
1279 if( fgStructure.CurrentWindow == window )
1280 wglMakeCurrent( NULL, NULL );
1283 * Step through the list of windows. If the rendering context
1284 * is not being used by another window, then we delete it.
1290 for( iter = (SFG_Window *)fgStructure.Windows.First;
1292 iter = (SFG_Window *)iter->Node.Next )
1294 if( ( iter->Window.Context == window->Window.Context ) &&
1295 ( iter != window ) )
1300 wglDeleteContext( window->Window.Context );
1303 DestroyWindow( window->Window.Handle );
1308 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1311 * Creates a new top-level freeglut window
1313 int FGAPIENTRY glutCreateWindow( const char* title )
1315 /* XXX GLUT does not exit; it simply calls "glutInit" quietly if the
1316 * XXX application has not already done so. The "freeglut" community
1317 * XXX decided not to go this route (freeglut-developer e-mail from
1318 * XXX Steve Baker, 12/16/04, 4:22 PM CST, "Re: [Freeglut-developer]
1319 * XXX Desired 'freeglut' behaviour when there is no current window"
1321 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateWindow" );
1323 return fgCreateWindow( NULL, title, fgState.Position.Use,
1324 fgState.Position.X, fgState.Position.Y,
1325 fgState.Size.Use, fgState.Size.X, fgState.Size.Y,
1326 GL_FALSE, GL_FALSE )->ID;
1329 #if TARGET_HOST_MS_WINDOWS
1330 int FGAPIENTRY __glutCreateWindowWithExit( const char *title, void (__cdecl *exit_function)(int) )
1332 __glutExitFunc = exit_function;
1333 return glutCreateWindow( title );
1338 * This function creates a sub window.
1340 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
1343 SFG_Window* window = NULL;
1344 SFG_Window* parent = NULL;
1346 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateSubWindow" );
1347 parent = fgWindowByID( parentID );
1348 freeglut_return_val_if_fail( parent != NULL, 0 );
1351 x = parent->State.Width + x ;
1352 if ( w >= 0 ) x -= w ;
1355 if ( w < 0 ) w = parent->State.Width - x + w ;
1364 y = parent->State.Height + y ;
1365 if ( h >= 0 ) y -= h ;
1368 if ( h < 0 ) h = parent->State.Height - y + h ;
1375 window = fgCreateWindow( parent, "", GL_TRUE, x, y, GL_TRUE, w, h, GL_FALSE, GL_FALSE );
1382 * Destroys a window and all of its subwindows
1384 void FGAPIENTRY glutDestroyWindow( int windowID )
1387 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDestroyWindow" );
1388 window = fgWindowByID( windowID );
1389 freeglut_return_if_fail( window != NULL );
1391 fgExecutionState ExecState = fgState.ExecState;
1392 fgAddToWindowDestroyList( window );
1393 fgState.ExecState = ExecState;
1398 * This function selects the current window
1400 void FGAPIENTRY glutSetWindow( int ID )
1402 SFG_Window* window = NULL;
1404 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindow" );
1405 if( fgStructure.CurrentWindow != NULL )
1406 if( fgStructure.CurrentWindow->ID == ID )
1409 window = fgWindowByID( ID );
1410 if( window == NULL )
1412 fgWarning( "glutSetWindow(): window ID %d not found!", ID );
1416 fgSetWindow( window );
1420 * This function returns the ID number of the current window, 0 if none exists
1422 int FGAPIENTRY glutGetWindow( void )
1424 SFG_Window *win = fgStructure.CurrentWindow;
1426 * Since GLUT did not throw an error if this function was called without a prior call to
1427 * "glutInit", this function shouldn't do so here. Instead let us return a zero.
1428 * See Feature Request "[ 1307049 ] glutInit check".
1430 if ( ! fgState.Initialised )
1433 while ( win && win->IsMenu )
1435 return win ? win->ID : 0;
1439 * This function makes the current window visible
1441 void FGAPIENTRY glutShowWindow( void )
1443 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" );
1444 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" );
1446 #if TARGET_HOST_POSIX_X11
1448 XMapWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1449 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1451 #elif TARGET_HOST_MS_WINDOWS
1453 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_SHOW );
1457 fgStructure.CurrentWindow->State.Redisplay = GL_TRUE;
1461 * This function hides the current window
1463 void FGAPIENTRY glutHideWindow( void )
1465 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" );
1466 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" );
1468 #if TARGET_HOST_POSIX_X11
1470 if( fgStructure.CurrentWindow->Parent == NULL )
1471 XWithdrawWindow( fgDisplay.Display,
1472 fgStructure.CurrentWindow->Window.Handle,
1475 XUnmapWindow( fgDisplay.Display,
1476 fgStructure.CurrentWindow->Window.Handle );
1477 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1479 #elif TARGET_HOST_MS_WINDOWS
1481 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_HIDE );
1485 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
1489 * Iconify the current window (top-level windows only)
1491 void FGAPIENTRY glutIconifyWindow( void )
1493 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" );
1494 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" );
1496 fgStructure.CurrentWindow->State.Visible = GL_FALSE;
1497 #if TARGET_HOST_POSIX_X11
1499 XIconifyWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
1501 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1503 #elif TARGET_HOST_MS_WINDOWS
1505 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_MINIMIZE );
1509 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
1513 * Set the current window's title
1515 void FGAPIENTRY glutSetWindowTitle( const char* title )
1517 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowTitle" );
1518 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" );
1519 if( ! fgStructure.CurrentWindow->Parent )
1521 #if TARGET_HOST_POSIX_X11
1525 text.value = (unsigned char *) title;
1526 text.encoding = XA_STRING;
1528 text.nitems = strlen( title );
1532 fgStructure.CurrentWindow->Window.Handle,
1536 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1538 #elif TARGET_HOST_MS_WINDOWS
1541 wchar_t* wstr = fghWstrFromStr(title);
1542 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
1546 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
1554 * Set the current window's iconified title
1556 void FGAPIENTRY glutSetIconTitle( const char* title )
1558 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" );
1559 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" );
1561 if( ! fgStructure.CurrentWindow->Parent )
1563 #if TARGET_HOST_POSIX_X11
1567 text.value = (unsigned char *) title;
1568 text.encoding = XA_STRING;
1570 text.nitems = strlen( title );
1574 fgStructure.CurrentWindow->Window.Handle,
1578 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1580 #elif TARGET_HOST_MS_WINDOWS
1583 wchar_t* wstr = fghWstrFromStr(title);
1584 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
1588 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
1596 * Change the current window's size
1598 void FGAPIENTRY glutReshapeWindow( int width, int height )
1600 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" );
1601 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" );
1603 if (glutGet(GLUT_FULL_SCREEN))
1605 /* Leave full screen state before resizing. */
1606 glutFullScreenToggle();
1609 fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
1610 fgStructure.CurrentWindow->State.Width = width ;
1611 fgStructure.CurrentWindow->State.Height = height;
1615 * Change the current window's position
1617 void FGAPIENTRY glutPositionWindow( int x, int y )
1619 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" );
1620 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" );
1622 if (glutGet(GLUT_FULL_SCREEN))
1624 /* Leave full screen state before moving. */
1625 glutFullScreenToggle();
1628 #if TARGET_HOST_POSIX_X11
1630 XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
1632 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1634 #elif TARGET_HOST_MS_WINDOWS
1639 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
1640 GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
1642 fgStructure.CurrentWindow->Window.Handle,
1645 winRect.right - winRect.left,
1646 winRect.bottom - winRect.top,
1655 * Lowers the current window (by Z order change)
1657 void FGAPIENTRY glutPushWindow( void )
1659 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPushWindow" );
1660 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPushWindow" );
1662 #if TARGET_HOST_POSIX_X11
1664 XLowerWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1666 #elif TARGET_HOST_MS_WINDOWS
1669 fgStructure.CurrentWindow->Window.Handle,
1672 SWP_NOSIZE | SWP_NOMOVE
1679 * Raises the current window (by Z order change)
1681 void FGAPIENTRY glutPopWindow( void )
1683 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" );
1684 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" );
1686 #if TARGET_HOST_POSIX_X11
1688 XRaiseWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1690 #elif TARGET_HOST_MS_WINDOWS
1693 fgStructure.CurrentWindow->Window.Handle,
1696 SWP_NOSIZE | SWP_NOMOVE
1703 * Resize the current window so that it fits the whole screen
1705 void FGAPIENTRY glutFullScreen( void )
1709 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" );
1710 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" );
1712 win = fgStructure.CurrentWindow;
1714 #if TARGET_HOST_POSIX_X11
1715 if(!glutGet(GLUT_FULL_SCREEN)) {
1716 if(fghToggleFullscreen() != -1) {
1717 win->State.IsFullscreen = GL_TRUE;
1721 #elif TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: what about WinCE */
1723 if (glutGet(GLUT_FULL_SCREEN))
1725 /* Leave full screen state before resizing. */
1726 glutFullScreenToggle();
1732 /* For fullscreen mode, force the top-left corner to 0,0
1733 * and adjust the window rectangle so that the client area
1734 * covers the whole screen.
1739 get_display_origin(&rect.left,&rect.top);
1740 rect.right = fgDisplay.ScreenWidth+rect.left;
1741 rect.bottom = fgDisplay.ScreenHeight+rect.top;
1743 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
1744 WS_CLIPCHILDREN, FALSE );
1747 * SWP_NOACTIVATE Do not activate the window
1748 * SWP_NOOWNERZORDER Do not change position in z-order
1749 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
1750 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
1753 SetWindowPos( fgStructure.CurrentWindow->Window.Handle,
1757 rect.right - rect.left,
1758 rect.bottom - rect.top,
1759 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
1763 win->State.IsFullscreen = GL_TRUE;
1769 * Toggle the window's full screen state.
1771 void FGAPIENTRY glutFullScreenToggle( void )
1775 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreenToggle" );
1776 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreenToggle" );
1778 win = fgStructure.CurrentWindow;
1780 #if TARGET_HOST_POSIX_X11
1781 if(fghToggleFullscreen() != -1) {
1782 win->State.IsFullscreen = !win->State.IsFullscreen;
1784 #elif TARGET_HOST_MS_WINDOWS
1786 win->State.IsFullscreen = !win->State.IsFullscreen;
1791 * A.Donev: Set and retrieve the window's user data
1793 void* FGAPIENTRY glutGetWindowData( void )
1795 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindowData" );
1796 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutGetWindowData" );
1797 return fgStructure.CurrentWindow->UserData;
1800 void FGAPIENTRY glutSetWindowData(void* data)
1802 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowData" );
1803 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowData" );
1804 fgStructure.CurrentWindow->UserData = data;
1807 /*** END OF FILE ***/