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" )
42 static wchar_t* fghWstrFromStr(const char* str)
44 int i,len=strlen(str);
45 wchar_t* wstr = (wchar_t*)malloc(2*len+2);
52 #endif /* defined(_WIN32_WCE) */
54 /* pushing attribute/value pairs into an array */
55 #define ATTRIB(a) attributes[where++]=(a)
56 #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);}
59 * TODO BEFORE THE STABLE RELEASE:
61 * fgChooseFBConfig() -- OK, but what about glutInitDisplayString()?
62 * fgSetupPixelFormat -- ignores the display mode settings
63 * fgOpenWindow() -- check the Win32 version, -iconic handling!
64 * fgCloseWindow() -- check the Win32 version
65 * glutCreateWindow() -- Check when default position and size is {-1,-1}
66 * glutCreateSubWindow() -- Check when default position and size is {-1,-1}
67 * glutDestroyWindow() -- check the Win32 version
68 * glutSetWindow() -- check the Win32 version
69 * glutGetWindow() -- OK
70 * glutSetWindowTitle() -- check the Win32 version
71 * glutSetIconTitle() -- check the Win32 version
72 * glutShowWindow() -- check the Win32 version
73 * glutHideWindow() -- check the Win32 version
74 * glutIconifyWindow() -- check the Win32 version
75 * glutReshapeWindow() -- check the Win32 version
76 * glutPositionWindow() -- check the Win32 version
77 * glutPushWindow() -- check the Win32 version
78 * glutPopWindow() -- check the Win32 version
81 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
83 static int fghIsLegacyContextVersionRequested( void )
85 return fgState.MajorVersion == 1 && fgState.MinorVersion == 0;
88 static int fghIsLegacyContextRequested( void )
90 return fghIsLegacyContextVersionRequested() &&
91 fgState.ContextFlags == 0 &&
92 fgState.ContextProfile == 0;
95 static int fghNumberOfAuxBuffersRequested( void )
97 if ( fgState.DisplayMode & GLUT_AUX4 ) {
100 if ( fgState.DisplayMode & GLUT_AUX3 ) {
103 if ( fgState.DisplayMode & GLUT_AUX2 ) {
106 if ( fgState.DisplayMode & GLUT_AUX1 ) { /* NOTE: Same as GLUT_AUX! */
107 return fgState.AuxiliaryBufferNumber;
112 static int fghMapBit( int mask, int from, int to )
114 return ( mask & from ) ? to : 0;
118 static void fghContextCreationError( void )
120 fgError( "Unable to create OpenGL %d.%d context (flags %x, profile %x)",
121 fgState.MajorVersion, fgState.MinorVersion, fgState.ContextFlags,
122 fgState.ContextProfile );
126 * Chooses a visual basing on the current display mode settings
128 #if TARGET_HOST_POSIX_X11
130 #ifndef GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB
131 #define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20B2
134 GLXFBConfig* fgChooseFBConfig( void )
136 GLboolean wantIndexedMode = GL_FALSE;
137 int attributes[ 100 ];
138 int where = 0, numAuxBuffers;
140 /* First we have to process the display mode settings... */
141 if( fgState.DisplayMode & GLUT_INDEX ) {
142 ATTRIB_VAL( GLX_BUFFER_SIZE, 8 );
143 /* Buffer size is selected later. */
145 ATTRIB_VAL( GLX_RENDER_TYPE, GLX_COLOR_INDEX_BIT );
146 wantIndexedMode = GL_TRUE;
148 ATTRIB_VAL( GLX_RED_SIZE, 1 );
149 ATTRIB_VAL( GLX_GREEN_SIZE, 1 );
150 ATTRIB_VAL( GLX_BLUE_SIZE, 1 );
151 if( fgState.DisplayMode & GLUT_ALPHA ) {
152 ATTRIB_VAL( GLX_ALPHA_SIZE, 1 );
156 if( fgState.DisplayMode & GLUT_DOUBLE ) {
157 ATTRIB_VAL( GLX_DOUBLEBUFFER, True );
160 if( fgState.DisplayMode & GLUT_STEREO ) {
161 ATTRIB_VAL( GLX_STEREO, True );
164 if( fgState.DisplayMode & GLUT_DEPTH ) {
165 ATTRIB_VAL( GLX_DEPTH_SIZE, 1 );
168 if( fgState.DisplayMode & GLUT_STENCIL ) {
169 ATTRIB_VAL( GLX_STENCIL_SIZE, 1 );
172 if( fgState.DisplayMode & GLUT_ACCUM ) {
173 ATTRIB_VAL( GLX_ACCUM_RED_SIZE, 1 );
174 ATTRIB_VAL( GLX_ACCUM_GREEN_SIZE, 1 );
175 ATTRIB_VAL( GLX_ACCUM_BLUE_SIZE, 1 );
176 if( fgState.DisplayMode & GLUT_ALPHA ) {
177 ATTRIB_VAL( GLX_ACCUM_ALPHA_SIZE, 1 );
181 numAuxBuffers = fghNumberOfAuxBuffersRequested();
182 if ( numAuxBuffers > 0 ) {
183 ATTRIB_VAL( GLX_AUX_BUFFERS, numAuxBuffers );
186 if( fgState.DisplayMode & GLUT_SRGB ) {
187 ATTRIB_VAL( GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB, True );
190 if (fgState.DisplayMode & GLUT_MULTISAMPLE) {
191 ATTRIB_VAL(GLX_SAMPLE_BUFFERS, 1);
192 ATTRIB_VAL(GLX_SAMPLES, fgState.SampleNumber);
195 /* Push a terminator at the end of the list */
199 GLXFBConfig * fbconfigArray; /* Array of FBConfigs */
200 GLXFBConfig * fbconfig; /* The FBConfig we want */
201 int fbconfigArraySize; /* Number of FBConfigs in the array */
204 /* Get all FBConfigs that match "attributes". */
205 fbconfigArray = glXChooseFBConfig( fgDisplay.Display,
208 &fbconfigArraySize );
210 if (fbconfigArray != NULL)
212 int result; /* Returned by glXGetFBConfigAttrib, not checked. */
215 if( wantIndexedMode )
218 * In index mode, we want the largest buffer size, i.e. visual
219 * depth. Here, FBConfigs are sorted by increasing buffer size
220 * first, so FBConfigs with the largest size come last.
223 int bufferSizeMin, bufferSizeMax;
225 /* Get bufferSizeMin. */
227 glXGetFBConfigAttrib( fgDisplay.Display,
231 /* Get bufferSizeMax. */
233 glXGetFBConfigAttrib( fgDisplay.Display,
234 fbconfigArray[fbconfigArraySize - 1],
238 if (bufferSizeMax > bufferSizeMin)
241 * Free and reallocate fbconfigArray, keeping only FBConfigs
242 * with the largest buffer size.
244 XFree(fbconfigArray);
246 /* Add buffer size token at the end of the list. */
248 ATTRIB_VAL( GLX_BUFFER_SIZE, bufferSizeMax );
251 fbconfigArray = glXChooseFBConfig( fgDisplay.Display,
254 &fbconfigArraySize );
259 * We now have an array of FBConfigs, the first one being the "best"
260 * one. So we should return only this FBConfig:
264 * - pick the XID of the FBConfig we want
265 * result = glXGetFBConfigAttrib( fgDisplay.Display,
271 * XFree(fbconfigArray);
273 * - reset "attributes" with the XID
275 * ATTRIB_VAL( GLX_FBCONFIG_ID, fbconfigXID );
278 * - get our FBConfig only
279 * fbconfig = glXChooseFBConfig( fgDisplay.Display,
282 * &fbconfigArraySize );
284 * However, for some configurations (for instance multisampling with
285 * Mesa 6.5.2 and ATI drivers), this does not work:
286 * glXChooseFBConfig returns NULL, whereas fbconfigXID is a valid
287 * XID. Further investigation is needed.
289 * So, for now, we return the whole array of FBConfigs. This should
290 * not produce any side effects elsewhere.
292 fbconfig = fbconfigArray;
302 #endif /* TARGET_HOST_POSIX_X11 */
305 * Setup the pixel format for a Win32 window
307 #if TARGET_HOST_MS_WINDOWS
308 /* The following include file is available from SGI but is not standard:
309 * #include <GL/wglext.h>
310 * So we copy the necessary parts out of it.
311 * XXX: should local definitions for extensions be put in a separate include file?
313 typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
315 typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
317 #define WGL_DRAW_TO_WINDOW_ARB 0x2001
318 #define WGL_ACCELERATION_ARB 0x2003
319 #define WGL_SUPPORT_OPENGL_ARB 0x2010
320 #define WGL_DOUBLE_BUFFER_ARB 0x2011
321 #define WGL_COLOR_BITS_ARB 0x2014
322 #define WGL_ALPHA_BITS_ARB 0x201B
323 #define WGL_DEPTH_BITS_ARB 0x2022
324 #define WGL_STENCIL_BITS_ARB 0x2023
325 #define WGL_FULL_ACCELERATION_ARB 0x2027
327 #define WGL_SAMPLE_BUFFERS_ARB 0x2041
328 #define WGL_SAMPLES_ARB 0x2042
330 #define WGL_TYPE_RGBA_FLOAT_ARB 0x21A0
332 #define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9
334 #ifndef WGL_ARB_create_context
335 #define WGL_ARB_create_context 1
336 #ifdef WGL_WGLEXT_PROTOTYPES
337 extern HGLRC WINAPI wglCreateContextAttribsARB (HDC, HGLRC, const int *);
338 #endif /* WGL_WGLEXT_PROTOTYPES */
339 typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList);
341 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
342 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
343 #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
344 #define WGL_CONTEXT_FLAGS_ARB 0x2094
345 #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
347 #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
348 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
350 #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
351 #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
353 #define ERROR_INVALID_VERSION_ARB 0x2095
354 #define ERROR_INVALID_PROFILE_ARB 0x2096
357 static void fghFillContextAttributes( int *attributes ) {
358 int where = 0, contextFlags, contextProfile;
360 if ( !fghIsLegacyContextVersionRequested() ) {
361 ATTRIB_VAL( WGL_CONTEXT_MAJOR_VERSION_ARB, fgState.MajorVersion );
362 ATTRIB_VAL( WGL_CONTEXT_MINOR_VERSION_ARB, fgState.MinorVersion );
366 fghMapBit( fgState.ContextFlags, GLUT_DEBUG, WGL_CONTEXT_DEBUG_BIT_ARB ) |
367 fghMapBit( fgState.ContextFlags, GLUT_FORWARD_COMPATIBLE, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB );
368 if ( contextFlags != 0 ) {
369 ATTRIB_VAL( WGL_CONTEXT_FLAGS_ARB, contextFlags );
373 fghMapBit( fgState.ContextProfile, GLUT_CORE_PROFILE, WGL_CONTEXT_CORE_PROFILE_BIT_ARB ) |
374 fghMapBit( fgState.ContextProfile, GLUT_COMPATIBILITY_PROFILE, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB );
375 if ( contextProfile != 0 ) {
376 ATTRIB_VAL( WGL_CONTEXT_PROFILE_MASK_ARB, contextProfile );
382 static int fghIsExtensionSupported( HDC hdc, const char *extension ) {
383 const char *pWglExtString;
384 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetEntensionsStringARB =
385 (PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB");
386 if ( wglGetEntensionsStringARB == NULL )
390 pWglExtString = wglGetEntensionsStringARB( hdc );
391 return ( pWglExtString != NULL ) && ( strstr(pWglExtString, extension) != NULL );
394 void fgNewWGLCreateContext( SFG_Window* window )
398 PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
400 /* If nothing fancy has been required, leave the context as it is */
401 if ( fghIsLegacyContextRequested() )
406 wglMakeCurrent( window->Window.Device, window->Window.Context );
408 if ( !fghIsExtensionSupported( window->Window.Device, "WGL_ARB_create_context" ) )
413 /* new context creation */
414 fghFillContextAttributes( attributes );
416 wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress( "wglCreateContextAttribsARB" );
417 if ( wglCreateContextAttribsARB == NULL )
419 fgError( "wglCreateContextAttribsARB not found" );
422 context = wglCreateContextAttribsARB( window->Window.Device, 0, attributes );
423 if ( context == NULL )
425 fghContextCreationError();
428 wglMakeCurrent( NULL, NULL );
429 wglDeleteContext( window->Window.Context );
430 window->Window.Context = context;
433 #if !defined(_WIN32_WCE)
435 static void fghFillPFD( PIXELFORMATDESCRIPTOR *ppfd, HDC hdc, unsigned char layer_type )
437 int flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
438 if ( fgState.DisplayMode & GLUT_DOUBLE ) {
439 flags |= PFD_DOUBLEBUFFER;
441 if ( fgState.DisplayMode & GLUT_STEREO ) {
445 #if defined(_MSC_VER)
446 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
449 /* Specify which pixel format do we opt for... */
450 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
452 ppfd->dwFlags = flags;
454 if( fgState.DisplayMode & GLUT_INDEX ) {
455 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
457 ppfd->cGreenBits = 0;
459 ppfd->cAlphaBits = 0;
461 ppfd->iPixelType = PFD_TYPE_RGBA;
463 ppfd->cGreenBits = 8;
465 ppfd->cAlphaBits = ( fgState.DisplayMode & GLUT_ALPHA ) ? 8 : 0;
468 ppfd->cColorBits = 24;
470 ppfd->cGreenShift = 0;
471 ppfd->cBlueShift = 0;
472 ppfd->cAlphaShift = 0;
473 ppfd->cAccumBits = 0;
474 ppfd->cAccumRedBits = 0;
475 ppfd->cAccumGreenBits = 0;
476 ppfd->cAccumBlueBits = 0;
477 ppfd->cAccumAlphaBits = 0;
479 /* Hmmm, or 32/0 instead of 24/8? */
480 ppfd->cDepthBits = 24;
481 ppfd->cStencilBits = 8;
483 ppfd->cAuxBuffers = fghNumberOfAuxBuffersRequested();
484 ppfd->iLayerType = layer_type;
486 ppfd->dwLayerMask = 0;
487 ppfd->dwVisibleMask = 0;
488 ppfd->dwDamageMask = 0;
490 ppfd->cColorBits = (BYTE) GetDeviceCaps( hdc, BITSPIXEL );
493 static void fghFillPixelFormatAttributes( int *attributes, const PIXELFORMATDESCRIPTOR *ppfd )
497 ATTRIB_VAL( WGL_DRAW_TO_WINDOW_ARB, GL_TRUE );
498 ATTRIB_VAL( WGL_SUPPORT_OPENGL_ARB, GL_TRUE );
499 ATTRIB_VAL( WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB );
501 ATTRIB_VAL( WGL_COLOR_BITS_ARB, ppfd->cColorBits );
502 ATTRIB_VAL( WGL_ALPHA_BITS_ARB, ppfd->cAlphaBits );
503 ATTRIB_VAL( WGL_DEPTH_BITS_ARB, ppfd->cDepthBits );
504 ATTRIB_VAL( WGL_STENCIL_BITS_ARB, ppfd->cStencilBits );
506 ATTRIB_VAL( WGL_DOUBLE_BUFFER_ARB, ( fgState.DisplayMode & GLUT_DOUBLE ) != 0 );
508 if ( fgState.DisplayMode & GLUT_SRGB ) {
509 ATTRIB_VAL( WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, TRUE );
512 ATTRIB_VAL( WGL_SAMPLE_BUFFERS_ARB, GL_TRUE );
513 ATTRIB_VAL( WGL_SAMPLES_ARB, fgState.SampleNumber );
518 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
519 unsigned char layer_type )
521 #if defined(_WIN32_WCE)
524 PIXELFORMATDESCRIPTOR pfd;
525 PIXELFORMATDESCRIPTOR* ppfd = &pfd;
528 fghFillPFD( ppfd, window->Window.Device, layer_type );
529 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
531 /* windows hack for multismapling/sRGB */
532 if ( ( fgState.DisplayMode & GLUT_MULTISAMPLE ) ||
533 ( fgState.DisplayMode & GLUT_SRGB ) )
535 HGLRC rc, rc_before=wglGetCurrentContext();
537 HDC hDC, hDC_before=wglGetCurrentDC();
540 /* create a dummy window */
541 ZeroMemory(&wndCls, sizeof(wndCls));
542 wndCls.lpfnWndProc = DefWindowProc;
543 wndCls.hInstance = fgDisplay.Instance;
544 wndCls.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
545 wndCls.lpszClassName = _T("FREEGLUT_dummy");
546 RegisterClass( &wndCls );
548 hWnd=CreateWindow(_T("FREEGLUT_dummy"), _T(""), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW , 0,0,0,0, 0, 0, fgDisplay.Instance, 0 );
550 SetPixelFormat( hDC, pixelformat, ppfd );
552 rc = wglCreateContext( hDC );
553 wglMakeCurrent(hDC, rc);
555 if ( fghIsExtensionSupported( hDC, "WGL_ARB_multisample" ) )
557 PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARBProc =
558 (PFNWGLCHOOSEPIXELFORMATARBPROC) wglGetProcAddress("wglChoosePixelFormatARB");
559 if ( wglChoosePixelFormatARBProc )
564 float fAttributes[] = { 0, 0 };
566 fghFillPixelFormatAttributes( attributes, ppfd );
567 bValid = wglChoosePixelFormatARBProc(window->Window.Device, attributes, fAttributes, 1, &iPixelFormat, &numFormats);
569 if ( bValid && numFormats > 0 )
571 pixelformat = iPixelFormat;
576 wglMakeCurrent( hDC_before, rc_before);
577 wglDeleteContext(rc);
578 ReleaseDC(hWnd, hDC);
580 UnregisterClass(_T("FREEGLUT_dummy"), fgDisplay.Instance);
583 return ( pixelformat != 0 ) && ( checkOnly || SetPixelFormat( window->Window.Device, pixelformat, ppfd ) );
584 #endif /* defined(_WIN32_WCE) */
586 #endif /* TARGET_HOST_MS_WINDOWS */
589 * Sets the OpenGL context and the fgStructure "Current Window" pointer to
590 * the window structure passed in.
592 void fgSetWindow ( SFG_Window *window )
594 #if TARGET_HOST_POSIX_X11
596 glXMakeContextCurrent(
598 window->Window.Handle,
599 window->Window.Handle,
600 window->Window.Context
602 #elif TARGET_HOST_MS_WINDOWS
603 if( fgStructure.CurrentWindow )
604 ReleaseDC( fgStructure.CurrentWindow->Window.Handle,
605 fgStructure.CurrentWindow->Window.Device );
609 window->Window.Device = GetDC( window->Window.Handle );
611 window->Window.Device,
612 window->Window.Context
616 fgStructure.CurrentWindow = window;
621 #if TARGET_HOST_POSIX_X11
623 #ifndef GLX_CONTEXT_MAJOR_VERSION_ARB
624 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
627 #ifndef GLX_CONTEXT_MINOR_VERSION_ARB
628 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
631 #ifndef GLX_CONTEXT_FLAGS_ARB
632 #define GLX_CONTEXT_FLAGS_ARB 0x2094
635 #ifndef GLX_CONTEXT_PROFILE_MASK_ARB
636 #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
639 #ifndef GLX_CONTEXT_DEBUG_BIT_ARB
640 #define GLX_CONTEXT_DEBUG_BIT_ARB 0x0001
643 #ifndef GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
644 #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
647 #ifndef GLX_CONTEXT_CORE_PROFILE_BIT_ARB
648 #define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
651 #ifndef GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
652 #define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
655 #ifndef GLX_RGBA_FLOAT_TYPE
656 #define GLX_RGBA_FLOAT_TYPE 0x20B9
659 #ifndef GLX_RGBA_FLOAT_BIT
660 #define GLX_RGBA_FLOAT_BIT 0x00000004
663 static void fghFillContextAttributes( int *attributes ) {
664 int where = 0, contextFlags, contextProfile;
666 if ( !fghIsLegacyContextVersionRequested() ) {
667 ATTRIB_VAL( GLX_CONTEXT_MAJOR_VERSION_ARB, fgState.MajorVersion );
668 ATTRIB_VAL( GLX_CONTEXT_MINOR_VERSION_ARB, fgState.MinorVersion );
672 fghMapBit( fgState.ContextFlags, GLUT_DEBUG, GLX_CONTEXT_DEBUG_BIT_ARB ) |
673 fghMapBit( fgState.ContextFlags, GLUT_FORWARD_COMPATIBLE, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB );
674 if ( contextFlags != 0 ) {
675 ATTRIB_VAL( GLX_CONTEXT_FLAGS_ARB, contextFlags );
679 fghMapBit( fgState.ContextProfile, GLUT_CORE_PROFILE, GLX_CONTEXT_CORE_PROFILE_BIT_ARB ) |
680 fghMapBit( fgState.ContextProfile, GLUT_COMPATIBILITY_PROFILE, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB );
681 if ( contextProfile != 0 ) {
682 ATTRIB_VAL( GLX_CONTEXT_PROFILE_MASK_ARB, contextProfile );
688 typedef GLXContext (*CreateContextAttribsProc)(Display *dpy, GLXFBConfig config,
689 GLXContext share_list, Bool direct,
690 const int *attrib_list);
692 static GLXContext fghCreateNewContext( SFG_Window* window )
694 /* for color model calculation */
695 int menu = ( window->IsMenu && !fgStructure.MenuContext );
696 int index_mode = ( fgState.DisplayMode & GLUT_INDEX );
698 /* "classic" context creation */
699 Display *dpy = fgDisplay.Display;
700 GLXFBConfig config = *(window->Window.FBConfig);
701 int render_type = ( !menu && index_mode ) ? GLX_COLOR_INDEX_TYPE : GLX_RGBA_TYPE;
702 GLXContext share_list = NULL;
703 Bool direct = ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT );
706 /* new context creation */
708 CreateContextAttribsProc createContextAttribs;
710 /* If nothing fancy has been required, simply use the old context creation GLX API entry */
711 if ( fghIsLegacyContextRequested() )
713 context = glXCreateNewContext( dpy, config, render_type, share_list, direct );
714 if ( context == NULL ) {
715 fghContextCreationError();
720 /* color index mode is not available anymore with OpenGL 3.0 */
721 if ( render_type == GLX_COLOR_INDEX_TYPE ) {
722 fgWarning( "color index mode is deprecated, using RGBA mode" );
725 fghFillContextAttributes( attributes );
727 createContextAttribs = (CreateContextAttribsProc) fghGetProcAddress( "glXCreateContextAttribsARB" );
728 if ( createContextAttribs == NULL ) {
729 fgError( "glXCreateContextAttribsARB not found" );
732 context = createContextAttribs( dpy, config, share_list, direct, attributes );
733 if ( context == NULL ) {
734 fghContextCreationError();
742 * Opens a window. Requires a SFG_Window object created and attached
743 * to the freeglut structure. OpenGL context is created here.
745 void fgOpenWindow( SFG_Window* window, const char* title,
746 GLboolean positionUse, int x, int y,
747 GLboolean sizeUse, int w, int h,
748 GLboolean gameMode, GLboolean isSubWindow )
750 #if TARGET_HOST_POSIX_X11
751 XVisualInfo * visualInfo;
752 XSetWindowAttributes winAttr;
753 XTextProperty textProperty;
754 XSizeHints sizeHints;
757 unsigned int current_DisplayMode = fgState.DisplayMode ;
759 /* Save the display mode if we are creating a menu window */
760 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
761 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ;
763 window->Window.FBConfig = fgChooseFBConfig( );
765 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
766 fgState.DisplayMode = current_DisplayMode ;
768 if( ! window->Window.FBConfig )
771 * The "fgChooseFBConfig" returned a null meaning that the visual
772 * context is not available.
773 * Try a couple of variations to see if they will work.
775 if( !( fgState.DisplayMode & GLUT_DOUBLE ) )
777 fgState.DisplayMode |= GLUT_DOUBLE ;
778 window->Window.FBConfig = fgChooseFBConfig( );
779 fgState.DisplayMode &= ~GLUT_DOUBLE;
782 if( fgState.DisplayMode & GLUT_MULTISAMPLE )
784 fgState.DisplayMode &= ~GLUT_MULTISAMPLE ;
785 window->Window.FBConfig = fgChooseFBConfig( );
786 fgState.DisplayMode |= GLUT_MULTISAMPLE;
790 FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.FBConfig != NULL,
791 "FBConfig with necessary capabilities not found", "fgOpenWindow" );
793 /* Get the X visual. */
794 visualInfo = glXGetVisualFromFBConfig( fgDisplay.Display,
795 *(window->Window.FBConfig) );
798 * XXX HINT: the masks should be updated when adding/removing callbacks.
799 * XXX This might speed up message processing. Is that true?
801 * XXX A: Not appreciably, but it WILL make it easier to debug.
802 * XXX Try tracing old GLUT and try tracing freeglut. Old GLUT
803 * XXX turns off events that it doesn't need and is a whole lot
804 * XXX more pleasant to trace. (Think mouse-motion! Tons of
805 * XXX ``bonus'' GUI events stream in.)
808 StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
809 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
810 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
811 PointerMotionMask | ButtonMotionMask;
812 winAttr.background_pixmap = None;
813 winAttr.background_pixel = 0;
814 winAttr.border_pixel = 0;
816 winAttr.colormap = XCreateColormap(
817 fgDisplay.Display, fgDisplay.RootWindow,
818 visualInfo->visual, AllocNone
821 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
823 if( window->IsMenu || ( gameMode == GL_TRUE ) )
825 winAttr.override_redirect = True;
826 mask |= CWOverrideRedirect;
830 x = y = -1; /* default window position */
832 w = h = 300; /* default window size */
834 window->Window.Handle = XCreateWindow(
836 window->Parent == NULL ? fgDisplay.RootWindow :
837 window->Parent->Window.Handle,
839 visualInfo->depth, InputOutput,
840 visualInfo->visual, mask,
845 * The GLX context creation, possibly trying the direct context rendering
846 * or else use the current context if the user has so specified
852 * If there isn't already an OpenGL rendering context for menu
855 if( !fgStructure.MenuContext )
857 fgStructure.MenuContext =
858 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
859 fgStructure.MenuContext->MContext = fghCreateNewContext( window );
862 /* window->Window.Context = fgStructure.MenuContext->MContext; */
863 window->Window.Context = fghCreateNewContext( window );
865 else if( fgState.UseCurrentContext )
867 window->Window.Context = glXGetCurrentContext( );
869 if( ! window->Window.Context )
870 window->Window.Context = fghCreateNewContext( window );
873 window->Window.Context = fghCreateNewContext( window );
875 #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ )
876 if( !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
878 if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
879 fgError( "Unable to force direct context rendering for window '%s'",
885 * XXX Assume the new window is visible by default
886 * XXX Is this a safe assumption?
888 window->State.Visible = GL_TRUE;
892 sizeHints.flags |= USPosition;
894 sizeHints.flags |= USSize;
897 * Fill in the size hints values now (the x, y, width and height
898 * settings are obsolete, are there any more WMs that support them?)
899 * Unless the X servers actually stop supporting these, we should
900 * continue to fill them in. It is *not* our place to tell the user
901 * that they should replace a window manager that they like, and which
902 * works, just because *we* think that it's not "modern" enough.
907 sizeHints.height = h;
909 wmHints.flags = StateHint;
910 wmHints.initial_state = fgState.ForceIconic ? IconicState : NormalState;
911 /* Prepare the window and iconified window names... */
912 XStringListToTextProperty( (char **) &title, 1, &textProperty );
916 window->Window.Handle,
925 XFree( textProperty.value );
927 XSetWMProtocols( fgDisplay.Display, window->Window.Handle,
928 &fgDisplay.DeleteWindow, 1 );
930 glXMakeContextCurrent(
932 window->Window.Handle,
933 window->Window.Handle,
934 window->Window.Context
937 XMapWindow( fgDisplay.Display, window->Window.Handle );
941 #elif TARGET_HOST_MS_WINDOWS
949 /* Grab the window class we have registered on glutInit(): */
950 atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
951 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Info Not Found",
956 FREEGLUT_INTERNAL_ERROR_EXIT ( window->Parent == NULL,
957 "Game mode being invoked on a subwindow",
961 * Set the window creation flags appropriately to make the window
964 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
968 int worig = w, horig = h;
970 #if !defined(_WIN32_WCE)
971 if ( ( ! isSubWindow ) && ( ! window->IsMenu ) )
974 * Update the window dimensions, taking account of window
975 * decorations. "freeglut" is to create the window with the
976 * outside of its border at (x,y) and with dimensions (w,h).
978 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
979 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 +
980 GetSystemMetrics( SM_CYCAPTION );
982 #endif /* defined(_WIN32_WCE) */
989 /* setting State.Width/Height to call resize callback later */
992 if( ! window->IsMenu )
997 else /* fail safe - Windows can make a window of size (0, 0) */
998 w = h = 300; /* default window size */
999 window->State.Width = window->State.Height = -1;
1003 window->State.Width = worig;
1004 window->State.Height = horig;
1008 * There's a small difference between creating the top, child and
1011 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
1013 if ( window->IsMenu )
1016 exFlags |= WS_EX_TOOLWINDOW;
1018 #if !defined(_WIN32_WCE)
1019 else if( window->Parent == NULL )
1020 flags |= WS_OVERLAPPEDWINDOW;
1026 #if defined(_WIN32_WCE)
1028 wchar_t* wstr = fghWstrFromStr(title);
1030 window->Window.Handle = CreateWindow(
1033 WS_VISIBLE | WS_POPUP,
1043 SHFullScreen(window->Window.Handle, SHFS_HIDESTARTICON);
1044 SHFullScreen(window->Window.Handle, SHFS_HIDESIPBUTTON);
1045 SHFullScreen(window->Window.Handle, SHFS_HIDETASKBAR);
1046 MoveWindow(window->Window.Handle, 0, 0, 240, 320, TRUE);
1047 ShowWindow(window->Window.Handle, SW_SHOW);
1048 UpdateWindow(window->Window.Handle);
1051 window->Window.Handle = CreateWindowEx(
1057 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
1062 #endif /* defined(_WIN32_WCE) */
1064 if( !( window->Window.Handle ) )
1065 fgError( "Failed to create a window (%s)!", title );
1067 /* Make a menu window always on top - fix Feature Request 947118 */
1068 if( window->IsMenu || gameMode )
1070 window->Window.Handle,
1073 SWP_NOMOVE | SWP_NOSIZE
1076 /* Hack to remove the caption (title bar) and/or border
1077 * and all the system menu controls.
1079 WindowStyle = GetWindowLong(window->Window.Handle, GWL_STYLE);
1080 if ( fgState.DisplayMode & GLUT_CAPTIONLESS )
1082 SetWindowLong ( window->Window.Handle, GWL_STYLE,
1083 WindowStyle & ~(WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX));
1085 else if ( fgState.DisplayMode & GLUT_BORDERLESS )
1087 SetWindowLong ( window->Window.Handle, GWL_STYLE,
1088 WindowStyle & ~(WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX));
1090 /* SetWindowPos(window->Window.Handle, NULL, 0, 0, 0, 0,
1091 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); */
1094 #if defined(_WIN32_WCE)
1095 ShowWindow( window->Window.Handle, SW_SHOW );
1097 ShowWindow( window->Window.Handle,
1098 fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
1099 #endif /* defined(_WIN32_WCE) */
1101 UpdateWindow( window->Window.Handle );
1102 ShowCursor( TRUE ); /* XXX Old comments say "hide cursor"! */
1106 fgSetWindow( window );
1108 window->Window.DoubleBuffered =
1109 ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
1111 if ( ! window->Window.DoubleBuffered )
1113 glDrawBuffer ( GL_FRONT );
1114 glReadBuffer ( GL_FRONT );
1119 * Closes a window, destroying the frame and OpenGL context
1121 void fgCloseWindow( SFG_Window* window )
1123 #if TARGET_HOST_POSIX_X11
1125 if( window->Window.Context )
1126 glXDestroyContext( fgDisplay.Display, window->Window.Context );
1127 XFree( window->Window.FBConfig );
1128 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
1129 /* XFlush( fgDisplay.Display ); */ /* XXX Shouldn't need this */
1131 #elif TARGET_HOST_MS_WINDOWS
1133 /* Make sure we don't close a window with current context active */
1134 if( fgStructure.CurrentWindow == window )
1135 wglMakeCurrent( NULL, NULL );
1138 * Step through the list of windows. If the rendering context
1139 * is not being used by another window, then we delete it.
1145 for( iter = (SFG_Window *)fgStructure.Windows.First;
1147 iter = (SFG_Window *)iter->Node.Next )
1149 if( ( iter->Window.Context == window->Window.Context ) &&
1150 ( iter != window ) )
1155 wglDeleteContext( window->Window.Context );
1158 DestroyWindow( window->Window.Handle );
1163 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1166 * Creates a new top-level freeglut window
1168 int FGAPIENTRY glutCreateWindow( const char* title )
1170 /* XXX GLUT does not exit; it simply calls "glutInit" quietly if the
1171 * XXX application has not already done so. The "freeglut" community
1172 * XXX decided not to go this route (freeglut-developer e-mail from
1173 * XXX Steve Baker, 12/16/04, 4:22 PM CST, "Re: [Freeglut-developer]
1174 * XXX Desired 'freeglut' behaviour when there is no current window"
1176 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateWindow" );
1178 return fgCreateWindow( NULL, title, fgState.Position.Use,
1179 fgState.Position.X, fgState.Position.Y,
1180 fgState.Size.Use, fgState.Size.X, fgState.Size.Y,
1181 GL_FALSE, GL_FALSE )->ID;
1184 #if TARGET_HOST_MS_WINDOWS
1185 int FGAPIENTRY __glutCreateWindowWithExit( const char *title, void (__cdecl *exit_function)(int) )
1187 __glutExitFunc = exit_function;
1188 return glutCreateWindow( title );
1193 * This function creates a sub window.
1195 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
1198 SFG_Window* window = NULL;
1199 SFG_Window* parent = NULL;
1201 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateSubWindow" );
1202 parent = fgWindowByID( parentID );
1203 freeglut_return_val_if_fail( parent != NULL, 0 );
1206 x = parent->State.Width + x ;
1207 if ( w >= 0 ) x -= w ;
1210 if ( w < 0 ) w = parent->State.Width - x + w ;
1219 y = parent->State.Height + y ;
1220 if ( h >= 0 ) y -= h ;
1223 if ( h < 0 ) h = parent->State.Height - y + h ;
1230 window = fgCreateWindow( parent, "", GL_TRUE, x, y, GL_TRUE, w, h, GL_FALSE, GL_FALSE );
1237 * Destroys a window and all of its subwindows
1239 void FGAPIENTRY glutDestroyWindow( int windowID )
1242 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDestroyWindow" );
1243 window = fgWindowByID( windowID );
1244 freeglut_return_if_fail( window != NULL );
1246 fgExecutionState ExecState = fgState.ExecState;
1247 fgAddToWindowDestroyList( window );
1248 fgState.ExecState = ExecState;
1253 * This function selects the current window
1255 void FGAPIENTRY glutSetWindow( int ID )
1257 SFG_Window* window = NULL;
1259 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindow" );
1260 if( fgStructure.CurrentWindow != NULL )
1261 if( fgStructure.CurrentWindow->ID == ID )
1264 window = fgWindowByID( ID );
1265 if( window == NULL )
1267 fgWarning( "glutSetWindow(): window ID %d not found!", ID );
1271 fgSetWindow( window );
1275 * This function returns the ID number of the current window, 0 if none exists
1277 int FGAPIENTRY glutGetWindow( void )
1279 SFG_Window *win = fgStructure.CurrentWindow;
1281 * Since GLUT did not throw an error if this function was called without a prior call to
1282 * "glutInit", this function shouldn't do so here. Instead let us return a zero.
1283 * See Feature Request "[ 1307049 ] glutInit check".
1285 if ( ! fgState.Initialised )
1288 while ( win && win->IsMenu )
1290 return win ? win->ID : 0;
1294 * This function makes the current window visible
1296 void FGAPIENTRY glutShowWindow( void )
1298 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" );
1299 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" );
1301 #if TARGET_HOST_POSIX_X11
1303 XMapWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1304 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1306 #elif TARGET_HOST_MS_WINDOWS
1308 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_SHOW );
1312 fgStructure.CurrentWindow->State.Redisplay = GL_TRUE;
1316 * This function hides the current window
1318 void FGAPIENTRY glutHideWindow( void )
1320 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" );
1321 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" );
1323 #if TARGET_HOST_POSIX_X11
1325 if( fgStructure.CurrentWindow->Parent == NULL )
1326 XWithdrawWindow( fgDisplay.Display,
1327 fgStructure.CurrentWindow->Window.Handle,
1330 XUnmapWindow( fgDisplay.Display,
1331 fgStructure.CurrentWindow->Window.Handle );
1332 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1334 #elif TARGET_HOST_MS_WINDOWS
1336 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_HIDE );
1340 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
1344 * Iconify the current window (top-level windows only)
1346 void FGAPIENTRY glutIconifyWindow( void )
1348 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" );
1349 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" );
1351 fgStructure.CurrentWindow->State.Visible = GL_FALSE;
1352 #if TARGET_HOST_POSIX_X11
1354 XIconifyWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
1356 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1358 #elif TARGET_HOST_MS_WINDOWS
1360 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_MINIMIZE );
1364 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
1368 * Set the current window's title
1370 void FGAPIENTRY glutSetWindowTitle( const char* title )
1372 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowTitle" );
1373 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" );
1374 if( ! fgStructure.CurrentWindow->Parent )
1376 #if TARGET_HOST_POSIX_X11
1380 text.value = (unsigned char *) title;
1381 text.encoding = XA_STRING;
1383 text.nitems = strlen( title );
1387 fgStructure.CurrentWindow->Window.Handle,
1391 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1393 #elif TARGET_HOST_MS_WINDOWS
1396 wchar_t* wstr = fghWstrFromStr(title);
1397 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
1401 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
1409 * Set the current window's iconified title
1411 void FGAPIENTRY glutSetIconTitle( const char* title )
1413 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" );
1414 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" );
1416 if( ! fgStructure.CurrentWindow->Parent )
1418 #if TARGET_HOST_POSIX_X11
1422 text.value = (unsigned char *) title;
1423 text.encoding = XA_STRING;
1425 text.nitems = strlen( title );
1429 fgStructure.CurrentWindow->Window.Handle,
1433 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1435 #elif TARGET_HOST_MS_WINDOWS
1438 wchar_t* wstr = fghWstrFromStr(title);
1439 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
1443 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
1451 * Change the current window's size
1453 void FGAPIENTRY glutReshapeWindow( int width, int height )
1455 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" );
1456 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" );
1458 if (glutGet(GLUT_FULL_SCREEN))
1460 /* Leave full screen state before resizing. */
1461 glutFullScreenToggle();
1464 fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
1465 fgStructure.CurrentWindow->State.Width = width ;
1466 fgStructure.CurrentWindow->State.Height = height;
1470 * Change the current window's position
1472 void FGAPIENTRY glutPositionWindow( int x, int y )
1474 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" );
1475 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" );
1477 if (glutGet(GLUT_FULL_SCREEN))
1479 /* Leave full screen state before moving. */
1480 glutFullScreenToggle();
1483 #if TARGET_HOST_POSIX_X11
1485 XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
1487 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1489 #elif TARGET_HOST_MS_WINDOWS
1494 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
1495 GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
1497 fgStructure.CurrentWindow->Window.Handle,
1500 winRect.right - winRect.left,
1501 winRect.bottom - winRect.top,
1510 * Lowers the current window (by Z order change)
1512 void FGAPIENTRY glutPushWindow( void )
1514 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPushWindow" );
1515 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPushWindow" );
1517 #if TARGET_HOST_POSIX_X11
1519 XLowerWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1521 #elif TARGET_HOST_MS_WINDOWS
1524 fgStructure.CurrentWindow->Window.Handle,
1527 SWP_NOSIZE | SWP_NOMOVE
1534 * Raises the current window (by Z order change)
1536 void FGAPIENTRY glutPopWindow( void )
1538 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" );
1539 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" );
1541 #if TARGET_HOST_POSIX_X11
1543 XRaiseWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1545 #elif TARGET_HOST_MS_WINDOWS
1548 fgStructure.CurrentWindow->Window.Handle,
1551 SWP_NOSIZE | SWP_NOMOVE
1558 * Resize the current window so that it fits the whole screen
1560 void FGAPIENTRY glutFullScreen( void )
1562 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" );
1563 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" );
1565 if (glutGet(GLUT_FULL_SCREEN))
1567 /* Leave full screen state before resizing. */
1568 glutFullScreenToggle();
1572 #if TARGET_HOST_POSIX_X11
1574 Status status; /* Returned by XGetWindowAttributes(), not checked. */
1575 XWindowAttributes attributes;
1577 status = XGetWindowAttributes(fgDisplay.Display,
1578 fgStructure.CurrentWindow->Window.Handle,
1581 * The "x" and "y" members of "attributes" are the window's coordinates
1582 * relative to its parent, i.e. to the decoration window.
1584 XMoveResizeWindow(fgDisplay.Display,
1585 fgStructure.CurrentWindow->Window.Handle,
1588 fgDisplay.ScreenWidth,
1589 fgDisplay.ScreenHeight);
1591 #elif TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: what about WinCE */
1594 /* For fullscreen mode, force the top-left corner to 0,0
1595 * and adjust the window rectangle so that the client area
1596 * covers the whole screen.
1601 rect.right = fgDisplay.ScreenWidth;
1602 rect.bottom = fgDisplay.ScreenHeight;
1604 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
1605 WS_CLIPCHILDREN, FALSE );
1608 * SWP_NOACTIVATE Do not activate the window
1609 * SWP_NOOWNERZORDER Do not change position in z-order
1610 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
1611 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
1614 SetWindowPos( fgStructure.CurrentWindow->Window.Handle,
1618 rect.right - rect.left,
1619 rect.bottom - rect.top,
1620 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
1628 * Toggle the window's full screen state.
1630 void FGAPIENTRY glutFullScreenToggle( void )
1632 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreenToggle" );
1633 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreenToggle" );
1636 #if TARGET_HOST_POSIX_X11
1638 if (fgDisplay.StateFullScreen != None)
1644 xevent.type = ClientMessage;
1645 xevent.xclient.type = ClientMessage;
1646 xevent.xclient.serial = 0;
1647 xevent.xclient.send_event = True;
1648 xevent.xclient.display = fgDisplay.Display;
1649 xevent.xclient.window = fgStructure.CurrentWindow->Window.Handle;
1650 xevent.xclient.message_type = fgDisplay.State;
1651 xevent.xclient.format = 32;
1652 xevent.xclient.data.l[0] = 2; /* _NET_WM_STATE_TOGGLE */
1653 xevent.xclient.data.l[1] = fgDisplay.StateFullScreen;
1654 xevent.xclient.data.l[2] = 0;
1655 xevent.xclient.data.l[3] = 0;
1656 xevent.xclient.data.l[4] = 0;
1658 /*** Don't really understand how event masks work... ***/
1659 event_mask = SubstructureRedirectMask | SubstructureNotifyMask;
1661 status = XSendEvent(fgDisplay.Display,
1662 fgDisplay.RootWindow,
1666 FREEGLUT_INTERNAL_ERROR_EXIT(status != 0,
1667 "XSendEvent failed",
1668 "glutFullScreenToggle");
1674 * If the window manager is not Net WM compliant, fall back to legacy
1683 * A.Donev: Set and retrieve the window's user data
1685 void* FGAPIENTRY glutGetWindowData( void )
1687 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindowData" );
1688 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutGetWindowData" );
1689 return fgStructure.CurrentWindow->UserData;
1692 void FGAPIENTRY glutSetWindowData(void* data)
1694 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowData" );
1695 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowData" );
1696 fgStructure.CurrentWindow->UserData = data;
1699 /*** END OF FILE ***/