4 * Window management methods.
\r
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
\r
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
\r
8 * Creation date: Fri Dec 3 1999
\r
10 * Permission is hereby granted, free of charge, to any person obtaining a
\r
11 * copy of this software and associated documentation files (the "Software"),
\r
12 * to deal in the Software without restriction, including without limitation
\r
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
\r
14 * and/or sell copies of the Software, and to permit persons to whom the
\r
15 * Software is furnished to do so, subject to the following conditions:
\r
17 * The above copyright notice and this permission notice shall be included
\r
18 * in all copies or substantial portions of the Software.
\r
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
\r
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
\r
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
28 #define FREEGLUT_BUILDING_LIB
\r
29 #include <GL/freeglut.h>
\r
30 #include "freeglut_internal.h"
\r
32 #if TARGET_HOST_POSIX_X11
\r
33 #include <limits.h> /* LONG_MAX */
\r
34 #include <unistd.h> /* usleep */
\r
37 #if defined(_WIN32_WCE)
\r
38 # include <Aygshell.h>
\r
39 # ifdef FREEGLUT_LIB_PRAGMAS
\r
40 # pragma comment( lib, "Aygshell.lib" )
\r
42 #endif /* defined(_WIN32_WCE) */
\r
45 #if TARGET_HOST_POSIX_X11
\r
46 #ifndef GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB
\r
47 #define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20B2
\r
50 #ifndef GLX_CONTEXT_MAJOR_VERSION_ARB
\r
51 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
\r
54 #ifndef GLX_CONTEXT_MINOR_VERSION_ARB
\r
55 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
\r
58 #ifndef GLX_CONTEXT_FLAGS_ARB
\r
59 #define GLX_CONTEXT_FLAGS_ARB 0x2094
\r
62 #ifndef GLX_CONTEXT_PROFILE_MASK_ARB
\r
63 #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
\r
66 #ifndef GLX_CONTEXT_DEBUG_BIT_ARB
\r
67 #define GLX_CONTEXT_DEBUG_BIT_ARB 0x0001
\r
70 #ifndef GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
\r
71 #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
\r
74 #ifndef GLX_CONTEXT_CORE_PROFILE_BIT_ARB
\r
75 #define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
\r
78 #ifndef GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
\r
79 #define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
\r
82 #ifndef GLX_RGBA_FLOAT_TYPE
\r
83 #define GLX_RGBA_FLOAT_TYPE 0x20B9
\r
86 #ifndef GLX_RGBA_FLOAT_BIT
\r
87 #define GLX_RGBA_FLOAT_BIT 0x00000004
\r
89 #endif /* TARGET_HOST_POSIX_X11 */
\r
92 #if TARGET_HOST_MS_WINDOWS
\r
93 /* The following include file is available from SGI but is not standard:
\r
94 * #include <GL/wglext.h>
\r
95 * So we copy the necessary parts out of it.
\r
96 * XXX: should local definitions for extensions be put in a separate include file?
\r
98 typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
\r
100 typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
\r
102 #define WGL_DRAW_TO_WINDOW_ARB 0x2001
\r
103 #define WGL_ACCELERATION_ARB 0x2003
\r
104 #define WGL_SUPPORT_OPENGL_ARB 0x2010
\r
105 #define WGL_DOUBLE_BUFFER_ARB 0x2011
\r
106 #define WGL_COLOR_BITS_ARB 0x2014
\r
107 #define WGL_ALPHA_BITS_ARB 0x201B
\r
108 #define WGL_DEPTH_BITS_ARB 0x2022
\r
109 #define WGL_STENCIL_BITS_ARB 0x2023
\r
110 #define WGL_FULL_ACCELERATION_ARB 0x2027
\r
112 #define WGL_SAMPLE_BUFFERS_ARB 0x2041
\r
113 #define WGL_SAMPLES_ARB 0x2042
\r
115 #define WGL_TYPE_RGBA_FLOAT_ARB 0x21A0
\r
117 #define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9
\r
119 #ifndef WGL_ARB_create_context
\r
120 #define WGL_ARB_create_context 1
\r
121 #ifdef WGL_WGLEXT_PROTOTYPES
\r
122 extern HGLRC WINAPI wglCreateContextAttribsARB (HDC, HGLRC, const int *);
\r
123 #endif /* WGL_WGLEXT_PROTOTYPES */
\r
124 typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList);
\r
126 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
\r
127 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
\r
128 #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
\r
129 #define WGL_CONTEXT_FLAGS_ARB 0x2094
\r
130 #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
\r
132 #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
\r
133 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
\r
135 #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
\r
136 #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
\r
138 #define ERROR_INVALID_VERSION_ARB 0x2095
\r
139 #define ERROR_INVALID_PROFILE_ARB 0x2096
\r
142 #endif /* TARGET_HOST_MS_WINDOWS */
\r
145 typedef BOOL (WINAPI *pRegisterTouchWindow)(HWND,ULONG);
\r
146 static pRegisterTouchWindow fghRegisterTouchWindow = (pRegisterTouchWindow)0xDEADBEEF;
\r
149 /* pushing attribute/value pairs into an array */
\r
150 #define ATTRIB(a) attributes[where++]=(a)
\r
151 #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);}
\r
154 * TODO BEFORE THE STABLE RELEASE:
\r
156 * fgChooseFBConfig() -- OK, but what about glutInitDisplayString()?
\r
157 * fgSetupPixelFormat -- ignores the display mode settings
\r
158 * fgOpenWindow() -- check the Win32 version, -iconic handling!
\r
159 * fgCloseWindow() -- check the Win32 version
\r
160 * glutCreateWindow() -- Check when default position and size is {-1,-1}
\r
161 * glutCreateSubWindow() -- Check when default position and size is {-1,-1}
\r
162 * glutDestroyWindow() -- check the Win32 version
\r
163 * glutSetWindow() -- check the Win32 version
\r
164 * glutGetWindow() -- OK
\r
165 * glutSetWindowTitle() -- check the Win32 version
\r
166 * glutSetIconTitle() -- check the Win32 version
\r
167 * glutShowWindow() -- check the Win32 version
\r
168 * glutHideWindow() -- check the Win32 version
\r
169 * glutIconifyWindow() -- check the Win32 version
\r
170 * glutReshapeWindow() -- check the Win32 version
\r
171 * glutPositionWindow() -- check the Win32 version
\r
172 * glutPushWindow() -- check the Win32 version
\r
173 * glutPopWindow() -- check the Win32 version
\r
176 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
\r
178 static int fghIsLegacyContextVersionRequested( void )
\r
180 return fgState.MajorVersion < 2 || (fgState.MajorVersion == 2 && fgState.MinorVersion <= 1);
\r
183 static int fghIsLegacyContextRequested( void )
\r
185 return fghIsLegacyContextVersionRequested() &&
\r
186 fgState.ContextFlags == 0 &&
\r
187 fgState.ContextProfile == 0;
\r
190 static int fghNumberOfAuxBuffersRequested( void )
\r
192 if ( fgState.DisplayMode & GLUT_AUX4 ) {
\r
195 if ( fgState.DisplayMode & GLUT_AUX3 ) {
\r
198 if ( fgState.DisplayMode & GLUT_AUX2 ) {
\r
201 if ( fgState.DisplayMode & GLUT_AUX1 ) { /* NOTE: Same as GLUT_AUX! */
\r
202 return fgState.AuxiliaryBufferNumber;
\r
207 static int fghMapBit( int mask, int from, int to )
\r
209 return ( mask & from ) ? to : 0;
\r
213 static void fghContextCreationError( void )
\r
215 fgError( "Unable to create OpenGL %d.%d context (flags %x, profile %x)",
\r
216 fgState.MajorVersion, fgState.MinorVersion, fgState.ContextFlags,
\r
217 fgState.ContextProfile );
\r
221 /* -- SYSTEM-DEPENDENT PRIVATE FUNCTIONS ------------------------------------ */
\r
223 #if TARGET_HOST_POSIX_X11
\r
225 * Chooses a visual basing on the current display mode settings
\r
228 GLXFBConfig* fgChooseFBConfig( int *numcfgs )
\r
230 GLboolean wantIndexedMode = GL_FALSE;
\r
231 int attributes[ 100 ];
\r
232 int where = 0, numAuxBuffers;
\r
234 /* First we have to process the display mode settings... */
\r
235 if( fgState.DisplayMode & GLUT_INDEX ) {
\r
236 ATTRIB_VAL( GLX_BUFFER_SIZE, 8 );
\r
237 /* Buffer size is selected later. */
\r
239 ATTRIB_VAL( GLX_RENDER_TYPE, GLX_COLOR_INDEX_BIT );
\r
240 wantIndexedMode = GL_TRUE;
\r
242 ATTRIB_VAL( GLX_RED_SIZE, 1 );
\r
243 ATTRIB_VAL( GLX_GREEN_SIZE, 1 );
\r
244 ATTRIB_VAL( GLX_BLUE_SIZE, 1 );
\r
245 if( fgState.DisplayMode & GLUT_ALPHA ) {
\r
246 ATTRIB_VAL( GLX_ALPHA_SIZE, 1 );
\r
250 if( fgState.DisplayMode & GLUT_DOUBLE ) {
\r
251 ATTRIB_VAL( GLX_DOUBLEBUFFER, True );
\r
254 if( fgState.DisplayMode & GLUT_STEREO ) {
\r
255 ATTRIB_VAL( GLX_STEREO, True );
\r
258 if( fgState.DisplayMode & GLUT_DEPTH ) {
\r
259 ATTRIB_VAL( GLX_DEPTH_SIZE, 1 );
\r
262 if( fgState.DisplayMode & GLUT_STENCIL ) {
\r
263 ATTRIB_VAL( GLX_STENCIL_SIZE, 1 );
\r
266 if( fgState.DisplayMode & GLUT_ACCUM ) {
\r
267 ATTRIB_VAL( GLX_ACCUM_RED_SIZE, 1 );
\r
268 ATTRIB_VAL( GLX_ACCUM_GREEN_SIZE, 1 );
\r
269 ATTRIB_VAL( GLX_ACCUM_BLUE_SIZE, 1 );
\r
270 if( fgState.DisplayMode & GLUT_ALPHA ) {
\r
271 ATTRIB_VAL( GLX_ACCUM_ALPHA_SIZE, 1 );
\r
275 numAuxBuffers = fghNumberOfAuxBuffersRequested();
\r
276 if ( numAuxBuffers > 0 ) {
\r
277 ATTRIB_VAL( GLX_AUX_BUFFERS, numAuxBuffers );
\r
280 if( fgState.DisplayMode & GLUT_SRGB ) {
\r
281 ATTRIB_VAL( GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB, True );
\r
284 if (fgState.DisplayMode & GLUT_MULTISAMPLE) {
\r
285 ATTRIB_VAL(GLX_SAMPLE_BUFFERS, 1);
\r
286 ATTRIB_VAL(GLX_SAMPLES, fgState.SampleNumber);
\r
289 /* Push a terminator at the end of the list */
\r
293 GLXFBConfig * fbconfigArray; /* Array of FBConfigs */
\r
294 GLXFBConfig * fbconfig; /* The FBConfig we want */
\r
295 int fbconfigArraySize; /* Number of FBConfigs in the array */
\r
298 /* Get all FBConfigs that match "attributes". */
\r
299 fbconfigArray = glXChooseFBConfig( fgDisplay.Display,
\r
302 &fbconfigArraySize );
\r
304 if (fbconfigArray != NULL)
\r
306 int result; /* Returned by glXGetFBConfigAttrib, not checked. */
\r
309 if( wantIndexedMode )
\r
312 * In index mode, we want the largest buffer size, i.e. visual
\r
313 * depth. Here, FBConfigs are sorted by increasing buffer size
\r
314 * first, so FBConfigs with the largest size come last.
\r
317 int bufferSizeMin, bufferSizeMax;
\r
319 /* Get bufferSizeMin. */
\r
321 glXGetFBConfigAttrib( fgDisplay.Display,
\r
325 /* Get bufferSizeMax. */
\r
327 glXGetFBConfigAttrib( fgDisplay.Display,
\r
328 fbconfigArray[fbconfigArraySize - 1],
\r
332 if (bufferSizeMax > bufferSizeMin)
\r
335 * Free and reallocate fbconfigArray, keeping only FBConfigs
\r
336 * with the largest buffer size.
\r
338 XFree(fbconfigArray);
\r
340 /* Add buffer size token at the end of the list. */
\r
342 ATTRIB_VAL( GLX_BUFFER_SIZE, bufferSizeMax );
\r
345 fbconfigArray = glXChooseFBConfig( fgDisplay.Display,
\r
348 &fbconfigArraySize );
\r
353 * We now have an array of FBConfigs, the first one being the "best"
\r
354 * one. So we should return only this FBConfig:
\r
358 * - pick the XID of the FBConfig we want
\r
359 * result = glXGetFBConfigAttrib( fgDisplay.Display,
\r
360 * fbconfigArray[0],
\r
365 * XFree(fbconfigArray);
\r
367 * - reset "attributes" with the XID
\r
369 * ATTRIB_VAL( GLX_FBCONFIG_ID, fbconfigXID );
\r
372 * - get our FBConfig only
\r
373 * fbconfig = glXChooseFBConfig( fgDisplay.Display,
\r
374 * fgDisplay.Screen,
\r
376 * &fbconfigArraySize );
\r
378 * However, for some configurations (for instance multisampling with
\r
379 * Mesa 6.5.2 and ATI drivers), this does not work:
\r
380 * glXChooseFBConfig returns NULL, whereas fbconfigXID is a valid
\r
381 * XID. Further investigation is needed.
\r
383 * So, for now, we return the whole array of FBConfigs. This should
\r
384 * not produce any side effects elsewhere.
\r
386 fbconfig = fbconfigArray;
\r
394 *numcfgs = fbconfigArraySize;
\r
401 static void fghFillContextAttributes( int *attributes ) {
\r
402 int where = 0, contextFlags, contextProfile;
\r
404 if ( !fghIsLegacyContextVersionRequested() ) {
\r
405 ATTRIB_VAL( GLX_CONTEXT_MAJOR_VERSION_ARB, fgState.MajorVersion );
\r
406 ATTRIB_VAL( GLX_CONTEXT_MINOR_VERSION_ARB, fgState.MinorVersion );
\r
410 fghMapBit( fgState.ContextFlags, GLUT_DEBUG, GLX_CONTEXT_DEBUG_BIT_ARB ) |
\r
411 fghMapBit( fgState.ContextFlags, GLUT_FORWARD_COMPATIBLE, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB );
\r
412 if ( contextFlags != 0 ) {
\r
413 ATTRIB_VAL( GLX_CONTEXT_FLAGS_ARB, contextFlags );
\r
417 fghMapBit( fgState.ContextProfile, GLUT_CORE_PROFILE, GLX_CONTEXT_CORE_PROFILE_BIT_ARB ) |
\r
418 fghMapBit( fgState.ContextProfile, GLUT_COMPATIBILITY_PROFILE, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB );
\r
419 if ( contextProfile != 0 ) {
\r
420 ATTRIB_VAL( GLX_CONTEXT_PROFILE_MASK_ARB, contextProfile );
\r
426 typedef GLXContext (*CreateContextAttribsProc)(Display *dpy, GLXFBConfig config,
\r
427 GLXContext share_list, Bool direct,
\r
428 const int *attrib_list);
\r
430 static GLXContext fghCreateNewContext( SFG_Window* window )
\r
432 /* for color model calculation */
\r
433 int menu = ( window->IsMenu && !fgStructure.MenuContext );
\r
434 int index_mode = ( fgState.DisplayMode & GLUT_INDEX );
\r
436 /* "classic" context creation */
\r
437 Display *dpy = fgDisplay.Display;
\r
438 GLXFBConfig config = *(window->Window.FBConfig);
\r
439 int render_type = ( !menu && index_mode ) ? GLX_COLOR_INDEX_TYPE : GLX_RGBA_TYPE;
\r
440 GLXContext share_list = NULL;
\r
441 Bool direct = ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT );
\r
442 GLXContext context;
\r
444 /* new context creation */
\r
446 CreateContextAttribsProc createContextAttribs = (CreateContextAttribsProc) fghGetProcAddress( "glXCreateContextAttribsARB" );
\r
448 /* glXCreateContextAttribsARB not found, yet the user has requested the new context creation */
\r
449 if ( !createContextAttribs && !fghIsLegacyContextRequested() ) {
\r
450 fgWarning( "OpenGL >2.1 context requested but glXCreateContextAttribsARB is not available! Falling back to legacy context creation" );
\r
451 fgState.MajorVersion = 2;
\r
452 fgState.MinorVersion = 1;
\r
455 /* If nothing fancy has been required, simply use the old context creation GLX API entry */
\r
456 if ( fghIsLegacyContextRequested() || !createContextAttribs )
\r
458 context = glXCreateNewContext( dpy, config, render_type, share_list, direct );
\r
459 if ( context == NULL ) {
\r
460 fghContextCreationError();
\r
465 /* color index mode is not available anymore with OpenGL 3.0 */
\r
466 if ( render_type == GLX_COLOR_INDEX_TYPE ) {
\r
467 fgWarning( "color index mode is deprecated, using RGBA mode" );
\r
470 fghFillContextAttributes( attributes );
\r
472 context = createContextAttribs( dpy, config, share_list, direct, attributes );
\r
473 if ( context == NULL ) {
\r
474 fghContextCreationError();
\r
480 #define _NET_WM_STATE_TOGGLE 2
\r
481 static int fghResizeFullscrToggle(void)
\r
483 XWindowAttributes attributes;
\r
485 if(glutGet(GLUT_FULL_SCREEN)) {
\r
486 /* restore original window size */
\r
487 SFG_Window *win = fgStructure.CurrentWindow;
\r
488 fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
\r
489 fgStructure.CurrentWindow->State.Width = win->State.OldWidth;
\r
490 fgStructure.CurrentWindow->State.Height = win->State.OldHeight;
\r
493 /* resize the window to cover the entire screen */
\r
494 XGetWindowAttributes(fgDisplay.Display,
\r
495 fgStructure.CurrentWindow->Window.Handle,
\r
499 * The "x" and "y" members of "attributes" are the window's coordinates
\r
500 * relative to its parent, i.e. to the decoration window.
\r
502 XMoveResizeWindow(fgDisplay.Display,
\r
503 fgStructure.CurrentWindow->Window.Handle,
\r
506 fgDisplay.ScreenWidth,
\r
507 fgDisplay.ScreenHeight);
\r
512 static int fghEwmhFullscrToggle(void)
\r
515 long evmask = SubstructureRedirectMask | SubstructureNotifyMask;
\r
517 if(!fgDisplay.State || !fgDisplay.StateFullScreen) {
\r
521 xev.type = ClientMessage;
\r
522 xev.xclient.window = fgStructure.CurrentWindow->Window.Handle;
\r
523 xev.xclient.message_type = fgDisplay.State;
\r
524 xev.xclient.format = 32;
\r
525 xev.xclient.data.l[0] = _NET_WM_STATE_TOGGLE;
\r
526 xev.xclient.data.l[1] = fgDisplay.StateFullScreen;
\r
527 xev.xclient.data.l[2] = 0; /* no second property to toggle */
\r
528 xev.xclient.data.l[3] = 1; /* source indication: application */
\r
529 xev.xclient.data.l[4] = 0; /* unused */
\r
531 if(!XSendEvent(fgDisplay.Display, fgDisplay.RootWindow, 0, evmask, &xev)) {
\r
537 static int fghToggleFullscreen(void)
\r
539 /* first try the EWMH (_NET_WM_STATE) method ... */
\r
540 if(fghEwmhFullscrToggle() != -1) {
\r
544 /* fall back to resizing the window */
\r
545 if(fghResizeFullscrToggle() != -1) {
\r
552 #endif /* TARGET_HOST_POSIX_X11 */
\r
555 #if TARGET_HOST_MS_WINDOWS
\r
557 * Setup the pixel format for a Win32 window
\r
560 #if defined(_WIN32_WCE)
\r
561 static wchar_t* fghWstrFromStr(const char* str)
\r
563 int i,len=strlen(str);
\r
564 wchar_t* wstr = (wchar_t*)malloc(2*len+2);
\r
565 for(i=0; i<len; i++)
\r
570 #endif /* defined(_WIN32_WCE) */
\r
573 static void fghFillContextAttributes( int *attributes ) {
\r
574 int where = 0, contextFlags, contextProfile;
\r
576 if ( !fghIsLegacyContextVersionRequested() ) {
\r
577 ATTRIB_VAL( WGL_CONTEXT_MAJOR_VERSION_ARB, fgState.MajorVersion );
\r
578 ATTRIB_VAL( WGL_CONTEXT_MINOR_VERSION_ARB, fgState.MinorVersion );
\r
582 fghMapBit( fgState.ContextFlags, GLUT_DEBUG, WGL_CONTEXT_DEBUG_BIT_ARB ) |
\r
583 fghMapBit( fgState.ContextFlags, GLUT_FORWARD_COMPATIBLE, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB );
\r
584 if ( contextFlags != 0 ) {
\r
585 ATTRIB_VAL( WGL_CONTEXT_FLAGS_ARB, contextFlags );
\r
589 fghMapBit( fgState.ContextProfile, GLUT_CORE_PROFILE, WGL_CONTEXT_CORE_PROFILE_BIT_ARB ) |
\r
590 fghMapBit( fgState.ContextProfile, GLUT_COMPATIBILITY_PROFILE, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB );
\r
591 if ( contextProfile != 0 ) {
\r
592 ATTRIB_VAL( WGL_CONTEXT_PROFILE_MASK_ARB, contextProfile );
\r
598 static int fghIsExtensionSupported( HDC hdc, const char *extension ) {
\r
599 const char *pWglExtString;
\r
600 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetEntensionsStringARB =
\r
601 (PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB");
\r
602 if ( wglGetEntensionsStringARB == NULL )
\r
606 pWglExtString = wglGetEntensionsStringARB( hdc );
\r
607 return ( pWglExtString != NULL ) && ( strstr(pWglExtString, extension) != NULL );
\r
610 void fgNewWGLCreateContext( SFG_Window* window )
\r
614 PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
\r
616 /* If nothing fancy has been required, leave the context as it is */
\r
617 if ( fghIsLegacyContextRequested() )
\r
622 wglMakeCurrent( window->Window.Device, window->Window.Context );
\r
624 if ( !fghIsExtensionSupported( window->Window.Device, "WGL_ARB_create_context" ) )
\r
629 /* new context creation */
\r
630 fghFillContextAttributes( attributes );
\r
632 wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress( "wglCreateContextAttribsARB" );
\r
633 if ( wglCreateContextAttribsARB == NULL )
\r
635 fgError( "wglCreateContextAttribsARB not found" );
\r
638 context = wglCreateContextAttribsARB( window->Window.Device, 0, attributes );
\r
639 if ( context == NULL )
\r
641 fghContextCreationError();
\r
644 wglMakeCurrent( NULL, NULL );
\r
645 wglDeleteContext( window->Window.Context );
\r
646 window->Window.Context = context;
\r
649 #if !defined(_WIN32_WCE)
\r
651 static void fghFillPFD( PIXELFORMATDESCRIPTOR *ppfd, HDC hdc, unsigned char layer_type )
\r
653 int flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
\r
654 if ( fgState.DisplayMode & GLUT_DOUBLE ) {
\r
655 flags |= PFD_DOUBLEBUFFER;
\r
657 if ( fgState.DisplayMode & GLUT_STEREO ) {
\r
658 flags |= PFD_STEREO;
\r
661 #if defined(_MSC_VER)
\r
662 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
\r
665 /* Specify which pixel format do we opt for... */
\r
666 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
\r
667 ppfd->nVersion = 1;
\r
668 ppfd->dwFlags = flags;
\r
670 if( fgState.DisplayMode & GLUT_INDEX ) {
\r
671 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
\r
672 ppfd->cRedBits = 0;
\r
673 ppfd->cGreenBits = 0;
\r
674 ppfd->cBlueBits = 0;
\r
675 ppfd->cAlphaBits = 0;
\r
677 ppfd->iPixelType = PFD_TYPE_RGBA;
\r
678 ppfd->cRedBits = 8;
\r
679 ppfd->cGreenBits = 8;
\r
680 ppfd->cBlueBits = 8;
\r
681 ppfd->cAlphaBits = ( fgState.DisplayMode & GLUT_ALPHA ) ? 8 : 0;
\r
684 ppfd->cColorBits = 24;
\r
685 ppfd->cRedShift = 0;
\r
686 ppfd->cGreenShift = 0;
\r
687 ppfd->cBlueShift = 0;
\r
688 ppfd->cAlphaShift = 0;
\r
689 ppfd->cAccumBits = ( fgState.DisplayMode & GLUT_ACCUM ) ? 1 : 0;
\r
690 ppfd->cAccumRedBits = 0;
\r
691 ppfd->cAccumGreenBits = 0;
\r
692 ppfd->cAccumBlueBits = 0;
\r
693 ppfd->cAccumAlphaBits = 0;
\r
695 /* Hmmm, or 32/0 instead of 24/8? */
\r
696 ppfd->cDepthBits = 24;
\r
697 ppfd->cStencilBits = 8;
\r
699 ppfd->cAuxBuffers = fghNumberOfAuxBuffersRequested();
\r
700 ppfd->iLayerType = layer_type;
\r
701 ppfd->bReserved = 0;
\r
702 ppfd->dwLayerMask = 0;
\r
703 ppfd->dwVisibleMask = 0;
\r
704 ppfd->dwDamageMask = 0;
\r
706 ppfd->cColorBits = (BYTE) GetDeviceCaps( hdc, BITSPIXEL );
\r
709 static void fghFillPixelFormatAttributes( int *attributes, const PIXELFORMATDESCRIPTOR *ppfd )
\r
713 ATTRIB_VAL( WGL_DRAW_TO_WINDOW_ARB, GL_TRUE );
\r
714 ATTRIB_VAL( WGL_SUPPORT_OPENGL_ARB, GL_TRUE );
\r
715 ATTRIB_VAL( WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB );
\r
717 ATTRIB_VAL( WGL_COLOR_BITS_ARB, ppfd->cColorBits );
\r
718 ATTRIB_VAL( WGL_ALPHA_BITS_ARB, ppfd->cAlphaBits );
\r
719 ATTRIB_VAL( WGL_DEPTH_BITS_ARB, ppfd->cDepthBits );
\r
720 ATTRIB_VAL( WGL_STENCIL_BITS_ARB, ppfd->cStencilBits );
\r
722 ATTRIB_VAL( WGL_DOUBLE_BUFFER_ARB, ( fgState.DisplayMode & GLUT_DOUBLE ) != 0 );
\r
724 if ( fgState.DisplayMode & GLUT_SRGB ) {
\r
725 ATTRIB_VAL( WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, TRUE );
\r
728 ATTRIB_VAL( WGL_SAMPLE_BUFFERS_ARB, GL_TRUE );
\r
729 ATTRIB_VAL( WGL_SAMPLES_ARB, fgState.SampleNumber );
\r
734 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
\r
735 unsigned char layer_type )
\r
737 #if defined(_WIN32_WCE)
\r
740 PIXELFORMATDESCRIPTOR pfd;
\r
741 PIXELFORMATDESCRIPTOR* ppfd = &pfd;
\r
747 current_hDC = CreateDC(TEXT("DISPLAY"), NULL ,NULL ,NULL);
\r
749 current_hDC = window->Window.Device;
\r
751 fghFillPFD( ppfd, current_hDC, layer_type );
\r
752 pixelformat = ChoosePixelFormat( current_hDC, ppfd );
\r
754 /* windows hack for multismapling/sRGB */
\r
755 if ( ( fgState.DisplayMode & GLUT_MULTISAMPLE ) ||
\r
756 ( fgState.DisplayMode & GLUT_SRGB ) )
\r
758 HGLRC rc, rc_before=wglGetCurrentContext();
\r
760 HDC hDC, hDC_before=wglGetCurrentDC();
\r
763 /* create a dummy window */
\r
764 ZeroMemory(&wndCls, sizeof(wndCls));
\r
765 wndCls.lpfnWndProc = DefWindowProc;
\r
766 wndCls.hInstance = fgDisplay.Instance;
\r
767 wndCls.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
\r
768 wndCls.lpszClassName = _T("FREEGLUT_dummy");
\r
769 RegisterClass( &wndCls );
\r
771 hWnd=CreateWindow(_T("FREEGLUT_dummy"), _T(""), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW , 0,0,0,0, 0, 0, fgDisplay.Instance, 0 );
\r
773 SetPixelFormat( hDC, pixelformat, ppfd );
\r
775 rc = wglCreateContext( hDC );
\r
776 wglMakeCurrent(hDC, rc);
\r
778 if ( fghIsExtensionSupported( hDC, "WGL_ARB_multisample" ) )
\r
780 PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARBProc =
\r
781 (PFNWGLCHOOSEPIXELFORMATARBPROC) wglGetProcAddress("wglChoosePixelFormatARB");
\r
782 if ( wglChoosePixelFormatARBProc )
\r
784 int attributes[100];
\r
787 float fAttributes[] = { 0, 0 };
\r
789 fghFillPixelFormatAttributes( attributes, ppfd );
\r
790 bValid = wglChoosePixelFormatARBProc(hDC, attributes, fAttributes, 1, &iPixelFormat, &numFormats);
\r
792 if ( bValid && numFormats > 0 )
\r
794 pixelformat = iPixelFormat;
\r
799 wglMakeCurrent( hDC_before, rc_before);
\r
800 wglDeleteContext(rc);
\r
801 ReleaseDC(hWnd, hDC);
\r
802 DestroyWindow(hWnd);
\r
803 UnregisterClass(_T("FREEGLUT_dummy"), fgDisplay.Instance);
\r
806 success = ( pixelformat != 0 ) && ( checkOnly || SetPixelFormat( current_hDC, pixelformat, ppfd ) );
\r
809 DeleteDC(current_hDC);
\r
812 #endif /* defined(_WIN32_WCE) */
\r
815 #endif /* TARGET_HOST_MS_WINDOWS */
\r
818 * Sets the OpenGL context and the fgStructure "Current Window" pointer to
\r
819 * the window structure passed in.
\r
821 void fgSetWindow ( SFG_Window *window )
\r
823 #if TARGET_HOST_POSIX_X11
\r
826 glXMakeContextCurrent(
\r
828 window->Window.Handle,
\r
829 window->Window.Handle,
\r
830 window->Window.Context
\r
833 #elif TARGET_HOST_MS_WINDOWS
\r
834 if ( window != fgStructure.CurrentWindow )
\r
836 if( fgStructure.CurrentWindow )
\r
837 ReleaseDC( fgStructure.CurrentWindow->Window.Handle,
\r
838 fgStructure.CurrentWindow->Window.Device );
\r
842 window->Window.Device = GetDC( window->Window.Handle );
\r
844 window->Window.Device,
\r
845 window->Window.Context
\r
850 fgStructure.CurrentWindow = window;
\r
853 #if TARGET_HOST_MS_WINDOWS
\r
855 /* Computes position of corners of window Rect (outer position including
\r
856 * decorations) based on the provided client rect and based on the style
\r
857 * of the window in question.
\r
858 * If posIsOutside is set to true, the input client Rect is taken to follow
\r
859 * freeGLUT's window specification convention in which the top-left corner
\r
860 * is at the outside of the window, while the size
\r
861 * (rect.right-rect.left,rect.bottom-rect.top) is the size of the drawable
\r
864 void fghComputeWindowRectFromClientArea_UseStyle( const DWORD windowStyle, RECT *clientRect, BOOL posIsOutside )
\r
866 int xBorderWidth = 0, yBorderWidth = 0;
\r
868 /* If window has title bar, correct rect for it */
\r
869 if (windowStyle & WS_MAXIMIZEBOX) /* Need to query for WS_MAXIMIZEBOX to see if we have a title bar, the WS_CAPTION query is also true for a WS_DLGFRAME only... */
\r
871 clientRect->bottom += GetSystemMetrics( SM_CYCAPTION );
\r
873 clientRect->top -= GetSystemMetrics( SM_CYCAPTION );
\r
875 /* get width of window's borders (frame), correct rect for it.
\r
876 * Note, borders can be of zero width if style does not specify borders
\r
878 fghGetBorderWidth(windowStyle, &xBorderWidth, &yBorderWidth);
\r
881 clientRect->right += xBorderWidth * 2;
\r
882 clientRect->bottom += yBorderWidth * 2;
\r
886 clientRect->left -= xBorderWidth;
\r
887 clientRect->right += xBorderWidth;
\r
888 clientRect->top -= yBorderWidth;
\r
889 clientRect->bottom += yBorderWidth;
\r
893 /* Computes position of corners of window Rect (outer position including
\r
894 * decorations) based on the provided client rect and based on the style
\r
895 * of the window in question. If the window pointer or the window handle
\r
896 * is NULL, a fully decorated window (caption and border) is assumed.
\r
897 * Furthermore, if posIsOutside is set to true, the input client Rect is
\r
898 * taken to follow freeGLUT's window specification convention in which the
\r
899 * top-left corner is at the outside of the window, while the size
\r
900 * (rect.right-rect.left,rect.bottom-rect.top) is the size of the drawable
\r
903 void fghComputeWindowRectFromClientArea_QueryWindow( const SFG_Window *window, RECT *clientRect, BOOL posIsOutside )
\r
905 DWORD windowStyle = 0;
\r
907 if (window && window->Window.Handle)
\r
908 windowStyle = GetWindowLong(window->Window.Handle, GWL_STYLE);
\r
910 windowStyle = WS_OVERLAPPEDWINDOW;
\r
912 fghComputeWindowRectFromClientArea_UseStyle(windowStyle, clientRect, posIsOutside);
\r
915 /* Computes position of corners of client area (drawable area) of a window
\r
916 * based on the provided window Rect (outer position including decorations)
\r
917 * and based on the style of the window in question. If the window pointer
\r
918 * or the window handle is NULL, a fully decorated window (caption and
\r
919 * border) is assumed.
\r
920 * Furthermore, if wantPosOutside is set to true, the output client Rect
\r
921 * will follow freeGLUT's window specification convention in which the
\r
922 * top-left corner is at the outside of the window, the size
\r
923 * (rect.right-rect.left,rect.bottom-rect.top) is the size of the drawable
\r
926 void fghComputeClientAreaFromWindowRect( const SFG_Window *window, RECT *windowRect, BOOL wantPosOutside )
\r
928 DWORD windowStyle = 0;
\r
929 int xBorderWidth = 0, yBorderWidth = 0;
\r
931 if (window && window->Window.Handle)
\r
932 windowStyle = GetWindowLong(window->Window.Handle, GWL_STYLE);
\r
934 windowStyle = WS_OVERLAPPEDWINDOW;
\r
936 /* If window has title bar, correct rect for it */
\r
937 if (windowStyle & WS_MAXIMIZEBOX) /* Need to query for WS_MAXIMIZEBOX to see if we have a title bar, the WS_CAPTION query is also true for a WS_DLGFRAME only... */
\r
938 if (wantPosOutside)
\r
939 windowRect->bottom -= GetSystemMetrics( SM_CYCAPTION );
\r
941 windowRect->top += GetSystemMetrics( SM_CYCAPTION );
\r
943 /* get width of window's borders (frame), correct rect for it.
\r
944 * Note, borders can be of zero width if style does not specify borders
\r
946 fghGetBorderWidth(windowStyle, &xBorderWidth, &yBorderWidth);
\r
947 if (wantPosOutside)
\r
949 windowRect->right -= xBorderWidth * 2;
\r
950 windowRect->bottom -= yBorderWidth * 2;
\r
954 windowRect->left += xBorderWidth;
\r
955 windowRect->right -= xBorderWidth;
\r
956 windowRect->top += yBorderWidth;
\r
957 windowRect->bottom -= yBorderWidth;
\r
961 /* Gets the rect describing the client area (drawable area) of the
\r
962 * specified window.
\r
963 * Returns an empty rect if window pointer or window handle is NULL.
\r
964 * If wantPosOutside is set to true, the output client Rect
\r
965 * will follow freeGLUT's window specification convention in which the
\r
966 * top-left corner is at the outside of the window, while the size
\r
967 * (rect.right-rect.left,rect.bottom-rect.top) is the size of the drawable
\r
970 RECT fghGetClientArea( const SFG_Window *window, BOOL wantPosOutside )
\r
972 RECT windowRect = {0,0,0,0};
\r
974 freeglut_return_val_if_fail((window && window->Window.Handle),windowRect);
\r
977 * call GetWindowRect()
\r
978 * (this returns the pixel coordinates of the outside of the window)
\r
980 GetWindowRect( window->Window.Handle, &windowRect );
\r
982 /* Then correct the results */
\r
983 fghComputeClientAreaFromWindowRect(window, &windowRect, wantPosOutside);
\r
988 /* Returns the width of the window borders based on the window's style.
\r
990 void fghGetBorderWidth(const DWORD windowStyle, int* xBorderWidth, int* yBorderWidth)
\r
992 if (windowStyle & WS_THICKFRAME)
\r
994 *xBorderWidth = GetSystemMetrics(SM_CXSIZEFRAME);
\r
995 *yBorderWidth = GetSystemMetrics(SM_CYSIZEFRAME);
\r
997 else if (windowStyle & WS_DLGFRAME)
\r
999 *xBorderWidth = GetSystemMetrics(SM_CXFIXEDFRAME);
\r
1000 *yBorderWidth = GetSystemMetrics(SM_CYFIXEDFRAME);
\r
1004 *xBorderWidth = 0;
\r
1005 *yBorderWidth = 0;
\r
1009 #if(WINVER >= 0x500)
\r
1017 static BOOL CALLBACK m_proc(HMONITOR mon,
\r
1022 m_proc_t *dp=(m_proc_t *)data;
\r
1023 MONITORINFOEX info;
\r
1025 info.cbSize=sizeof(info);
\r
1026 res=GetMonitorInfo(mon,(LPMONITORINFO)&info);
\r
1029 if( strcmp(dp->name,info.szDevice)==0 )
\r
1031 *(dp->x)=info.rcMonitor.left;
\r
1032 *(dp->y)=info.rcMonitor.top;
\r
1040 * this function returns the origin of the screen identified by
\r
1041 * fgDisplay.DisplayName, and 0 otherwise.
\r
1042 * This is used in fgOpenWindow to open the gamemode window on the screen
\r
1043 * identified by the -display command line argument. The function should
\r
1044 * not be called otherwise.
\r
1047 static void get_display_origin(int *xp,int *yp)
\r
1052 if( fgDisplay.DisplayName )
\r
1057 st.name=fgDisplay.DisplayName;
\r
1058 EnumDisplayMonitors(0,0,m_proc,(LPARAM)&st);
\r
1062 #pragma message( "-display parameter only works if compiled with WINVER >= 0x0500")
\r
1064 static void get_display_origin(int *xp,int *yp)
\r
1069 if( fgDisplay.DisplayName )
\r
1071 fgWarning( "for working -display support FreeGLUT must be compiled with WINVER >= 0x0500");
\r
1078 #if TARGET_HOST_POSIX_X11
\r
1079 static Bool fghWindowIsVisible( Display *display, XEvent *event, XPointer arg)
\r
1081 Window window = (Window)arg;
\r
1082 return (event->type == MapNotify) && (event->xmap.window == window);
\r
1088 * Opens a window. Requires a SFG_Window object created and attached
\r
1089 * to the freeglut structure. OpenGL context is created here.
\r
1091 void fgOpenWindow( SFG_Window* window, const char* title,
\r
1092 GLboolean positionUse, int x, int y,
\r
1093 GLboolean sizeUse, int w, int h,
\r
1094 GLboolean gameMode, GLboolean isSubWindow )
\r
1096 #if TARGET_HOST_POSIX_X11
\r
1097 XVisualInfo * visualInfo = NULL;
\r
1098 XSetWindowAttributes winAttr;
\r
1099 XTextProperty textProperty;
\r
1100 XSizeHints sizeHints;
\r
1102 XEvent eventReturnBuffer; /* return buffer required for a call */
\r
1103 unsigned long mask;
\r
1104 int num_FBConfigs, i;
\r
1105 unsigned int current_DisplayMode = fgState.DisplayMode ;
\r
1107 /* Save the display mode if we are creating a menu window */
\r
1108 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
\r
1109 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ;
\r
1111 window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs );
\r
1113 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
\r
1114 fgState.DisplayMode = current_DisplayMode ;
\r
1116 if( ! window->Window.FBConfig )
\r
1119 * The "fgChooseFBConfig" returned a null meaning that the visual
\r
1120 * context is not available.
\r
1121 * Try a couple of variations to see if they will work.
\r
1123 if( !( fgState.DisplayMode & GLUT_DOUBLE ) )
\r
1125 fgState.DisplayMode |= GLUT_DOUBLE ;
\r
1126 window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs );
\r
1127 fgState.DisplayMode &= ~GLUT_DOUBLE;
\r
1130 if( fgState.DisplayMode & GLUT_MULTISAMPLE )
\r
1132 fgState.DisplayMode &= ~GLUT_MULTISAMPLE ;
\r
1133 window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs );
\r
1134 fgState.DisplayMode |= GLUT_MULTISAMPLE;
\r
1138 FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.FBConfig != NULL,
\r
1139 "FBConfig with necessary capabilities not found", "fgOpenWindow" );
\r
1141 /* Get the X visual. */
\r
1142 for (i = 0; i < num_FBConfigs; i++) {
\r
1143 visualInfo = glXGetVisualFromFBConfig( fgDisplay.Display,
\r
1144 window->Window.FBConfig[i] );
\r
1149 FREEGLUT_INTERNAL_ERROR_EXIT( visualInfo != NULL,
\r
1150 "visualInfo could not be retrieved from FBConfig", "fgOpenWindow" );
\r
1153 * XXX HINT: the masks should be updated when adding/removing callbacks.
\r
1154 * XXX This might speed up message processing. Is that true?
\r
1156 * XXX A: Not appreciably, but it WILL make it easier to debug.
\r
1157 * XXX Try tracing old GLUT and try tracing freeglut. Old GLUT
\r
1158 * XXX turns off events that it doesn't need and is a whole lot
\r
1159 * XXX more pleasant to trace. (Think mouse-motion! Tons of
\r
1160 * XXX ``bonus'' GUI events stream in.)
\r
1162 winAttr.event_mask =
\r
1163 StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
\r
1164 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
\r
1165 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
\r
1166 PointerMotionMask | ButtonMotionMask;
\r
1167 winAttr.background_pixmap = None;
\r
1168 winAttr.background_pixel = 0;
\r
1169 winAttr.border_pixel = 0;
\r
1171 winAttr.colormap = XCreateColormap(
\r
1172 fgDisplay.Display, fgDisplay.RootWindow,
\r
1173 visualInfo->visual, AllocNone
\r
1176 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
\r
1178 if( window->IsMenu || ( gameMode == GL_TRUE ) )
\r
1180 winAttr.override_redirect = True;
\r
1181 mask |= CWOverrideRedirect;
\r
1184 if( ! positionUse )
\r
1185 x = y = -1; /* default window position */
\r
1187 w = h = 300; /* default window size */
\r
1189 window->Window.Handle = XCreateWindow(
\r
1190 fgDisplay.Display,
\r
1191 window->Parent == NULL ? fgDisplay.RootWindow :
\r
1192 window->Parent->Window.Handle,
\r
1194 visualInfo->depth, InputOutput,
\r
1195 visualInfo->visual, mask,
\r
1200 * The GLX context creation, possibly trying the direct context rendering
\r
1201 * or else use the current context if the user has so specified
\r
1204 if( window->IsMenu )
\r
1207 * If there isn't already an OpenGL rendering context for menu
\r
1208 * windows, make one
\r
1210 if( !fgStructure.MenuContext )
\r
1212 fgStructure.MenuContext =
\r
1213 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
\r
1214 fgStructure.MenuContext->MContext = fghCreateNewContext( window );
\r
1217 /* window->Window.Context = fgStructure.MenuContext->MContext; */
\r
1218 window->Window.Context = fghCreateNewContext( window );
\r
1220 else if( fgState.UseCurrentContext )
\r
1222 window->Window.Context = glXGetCurrentContext( );
\r
1224 if( ! window->Window.Context )
\r
1225 window->Window.Context = fghCreateNewContext( window );
\r
1228 window->Window.Context = fghCreateNewContext( window );
\r
1230 #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ )
\r
1231 if( !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
\r
1233 if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
\r
1234 fgError( "Unable to force direct context rendering for window '%s'",
\r
1240 * XXX Assume the new window is visible by default
\r
1241 * XXX Is this a safe assumption?
\r
1243 window->State.Visible = GL_TRUE;
\r
1245 sizeHints.flags = 0;
\r
1246 if ( positionUse )
\r
1247 sizeHints.flags |= USPosition;
\r
1249 sizeHints.flags |= USSize;
\r
1252 * Fill in the size hints values now (the x, y, width and height
\r
1253 * settings are obsolete, are there any more WMs that support them?)
\r
1254 * Unless the X servers actually stop supporting these, we should
\r
1255 * continue to fill them in. It is *not* our place to tell the user
\r
1256 * that they should replace a window manager that they like, and which
\r
1257 * works, just because *we* think that it's not "modern" enough.
\r
1261 sizeHints.width = w;
\r
1262 sizeHints.height = h;
\r
1264 wmHints.flags = StateHint;
\r
1265 wmHints.initial_state = fgState.ForceIconic ? IconicState : NormalState;
\r
1266 /* Prepare the window and iconified window names... */
\r
1267 XStringListToTextProperty( (char **) &title, 1, &textProperty );
\r
1270 fgDisplay.Display,
\r
1271 window->Window.Handle,
\r
1280 XFree( textProperty.value );
\r
1282 XSetWMProtocols( fgDisplay.Display, window->Window.Handle,
\r
1283 &fgDisplay.DeleteWindow, 1 );
\r
1285 glXMakeContextCurrent(
\r
1286 fgDisplay.Display,
\r
1287 window->Window.Handle,
\r
1288 window->Window.Handle,
\r
1289 window->Window.Context
\r
1292 /* register extension events _before_ window is mapped */
\r
1293 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
\r
1294 fgRegisterDevices( fgDisplay.Display, &(window->Window.Handle) );
\r
1297 XMapWindow( fgDisplay.Display, window->Window.Handle );
\r
1299 XFree(visualInfo);
\r
1302 XPeekIfEvent( fgDisplay.Display, &eventReturnBuffer, &fghWindowIsVisible, (XPointer)(window->Window.Handle) );
\r
1304 #elif TARGET_HOST_MS_WINDOWS
\r
1308 DWORD exFlags = 0;
\r
1311 /* Grab the window class we have registered on glutInit(): */
\r
1312 atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
\r
1313 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Info Not Found",
\r
1316 /* Determine window style flags*/
\r
1319 FREEGLUT_INTERNAL_ERROR_EXIT ( window->Parent == NULL,
\r
1320 "Game mode being invoked on a subwindow",
\r
1324 * Set the window creation flags appropriately to make the window
\r
1325 * entirely visible:
\r
1327 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
\r
1331 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
\r
1334 * There's a small difference between creating the top, child and
\r
1337 if ( window->IsMenu )
\r
1339 flags |= WS_POPUP;
\r
1340 exFlags |= WS_EX_TOOLWINDOW;
\r
1342 #if defined(_WIN32_WCE)
\r
1343 /* no decorations for windows CE */
\r
1345 /* if this is not a subwindow (child), set its style based on the requested display mode */
\r
1346 else if( window->Parent == NULL )
\r
1347 if ( fgState.DisplayMode & GLUT_BORDERLESS )
\r
1349 /* no window decorations needed */
\r
1351 else if ( fgState.DisplayMode & GLUT_CAPTIONLESS )
\r
1352 /* only window decoration is a border, no title bar or buttons */
\r
1353 flags |= WS_DLGFRAME;
\r
1355 /* window decoration are a border, title bar and buttons.
\r
1356 * NB: we later query whether the window has a title bar or
\r
1357 * not by testing for the maximize button, as the test for
\r
1358 * WS_CAPTION can be true without the window having a title
\r
1359 * bar. This style WS_OVERLAPPEDWINDOW gives you a maximize
\r
1361 flags |= WS_OVERLAPPEDWINDOW;
\r
1364 /* subwindows always have no decoration, but are marked as a child window to the OS */
\r
1365 flags |= WS_CHILD;
\r
1368 /* determine window size and position */
\r
1371 /* if in gamemode, query the origin of specified by the -display
\r
1372 * command line parameter (if any) and offset the upper-left corner
\r
1373 * of the window so we create the window on that screen.
\r
1374 * The -display argument doesn't do anything if not trying to enter
\r
1377 int xoff=0, yoff=0;
\r
1378 get_display_origin(&xoff,&yoff);
\r
1382 if( !positionUse )
\r
1384 x = CW_USEDEFAULT;
\r
1385 y = CW_USEDEFAULT;
\r
1389 if( ! window->IsMenu )
\r
1391 w = CW_USEDEFAULT;
\r
1392 h = CW_USEDEFAULT;
\r
1394 else /* fail safe - Windows can make a window of size (0, 0) */
\r
1395 w = h = 300; /* default window size */
\r
1397 /* store requested client area width and height */
\r
1398 window->State.Width = w;
\r
1399 window->State.Height = h;
\r
1401 #if !defined(_WIN32_WCE) /* no decorations for windows CE */
\r
1406 * Update the window dimensions, taking the window decorations
\r
1407 * into account. FreeGLUT is to create the window with the
\r
1408 * topleft outside corner at (x,y) and with client area
\r
1409 * dimensions (w,h).
\r
1410 * note: don't need to do this when w=h=CW_USEDEFAULT, so in the
\r
1411 * if( sizeUse ) here is convenient.
\r
1413 windowRect.left = x;
\r
1414 windowRect.top = y;
\r
1415 windowRect.right = x+w;
\r
1416 windowRect.bottom = y+h;
\r
1418 fghComputeWindowRectFromClientArea_UseStyle(flags,&windowRect,TRUE);
\r
1420 w = windowRect.right - windowRect.left;
\r
1421 h = windowRect.bottom- windowRect.top;
\r
1423 #endif /* !defined(_WIN32_WCE) */
\r
1425 #if defined(_WIN32_WCE)
\r
1427 wchar_t* wstr = fghWstrFromStr(title);
\r
1429 window->Window.Handle = CreateWindow(
\r
1432 WS_VISIBLE | WS_POPUP,
\r
1436 fgDisplay.Instance,
\r
1442 SHFullScreen(window->Window.Handle, SHFS_HIDESTARTICON);
\r
1443 SHFullScreen(window->Window.Handle, SHFS_HIDESIPBUTTON);
\r
1444 SHFullScreen(window->Window.Handle, SHFS_HIDETASKBAR);
\r
1445 MoveWindow(window->Window.Handle, 0, 0, 240, 320, TRUE);
\r
1446 ShowWindow(window->Window.Handle, SW_SHOW);
\r
1447 UpdateWindow(window->Window.Handle);
\r
1450 window->Window.Handle = CreateWindowEx(
\r
1456 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
\r
1458 fgDisplay.Instance,
\r
1461 #endif /* defined(_WIN32_WCE) */
\r
1463 if( !( window->Window.Handle ) )
\r
1464 fgError( "Failed to create a window (%s)!", title );
\r
1466 #if !defined(_WIN32_WCE)
\r
1467 /* Need to set requested style again, apparently Windows doesn't listen when requesting windows without title bar or borders */
\r
1468 SetWindowLong(window->Window.Handle, GWL_STYLE, flags);
\r
1469 SetWindowPos(window->Window.Handle, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
\r
1470 #endif /* defined(_WIN32_WCE) */
\r
1472 /* Make a menu window always on top - fix Feature Request 947118 */
\r
1473 if( window->IsMenu || gameMode )
\r
1475 window->Window.Handle,
\r
1478 SWP_NOMOVE | SWP_NOSIZE
\r
1481 /* Enable multitouch: additional flag TWF_FINETOUCH, TWF_WANTPALM */
\r
1483 if (fghRegisterTouchWindow == (pRegisterTouchWindow)0xDEADBEEF)
\r
1484 fghRegisterTouchWindow = (pRegisterTouchWindow)GetProcAddress(GetModuleHandle("user32"),"RegisterTouchWindow");
\r
1485 if (fghRegisterTouchWindow)
\r
1486 fghRegisterTouchWindow( window->Window.Handle, TWF_FINETOUCH | TWF_WANTPALM );
\r
1489 #if defined(_WIN32_WCE)
\r
1490 ShowWindow( window->Window.Handle, SW_SHOW );
\r
1492 ShowWindow( window->Window.Handle,
\r
1493 fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
\r
1494 #endif /* defined(_WIN32_WCE) */
\r
1496 UpdateWindow( window->Window.Handle );
\r
1497 ShowCursor( TRUE ); /* XXX Old comments say "hide cursor"! */
\r
1501 fgSetWindow( window );
\r
1503 window->Window.DoubleBuffered =
\r
1504 ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
\r
1506 if ( ! window->Window.DoubleBuffered )
\r
1508 glDrawBuffer ( GL_FRONT );
\r
1509 glReadBuffer ( GL_FRONT );
\r
1514 * Closes a window, destroying the frame and OpenGL context
\r
1516 void fgCloseWindow( SFG_Window* window )
\r
1518 /* if we're in gamemode and we're closing the gamemode window,
\r
1519 * call glutLeaveGameMode first to make sure the gamemode is
\r
1520 * properly closed before closing the window
\r
1522 if (fgStructure.GameModeWindow != NULL && fgStructure.GameModeWindow->ID==window->ID)
\r
1523 glutLeaveGameMode();
\r
1525 #if TARGET_HOST_POSIX_X11
\r
1527 if( window->Window.Context )
\r
1528 glXDestroyContext( fgDisplay.Display, window->Window.Context );
\r
1529 XFree( window->Window.FBConfig );
\r
1531 if( window->Window.Handle ) {
\r
1532 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
\r
1534 /* XFlush( fgDisplay.Display ); */ /* XXX Shouldn't need this */
\r
1536 #elif TARGET_HOST_MS_WINDOWS
\r
1538 /* Make sure we don't close a window with current context active */
\r
1539 if( fgStructure.CurrentWindow == window )
\r
1540 wglMakeCurrent( NULL, NULL );
\r
1543 * Step through the list of windows. If the rendering context
\r
1544 * is not being used by another window, then we delete it.
\r
1547 int used = FALSE ;
\r
1548 SFG_Window *iter ;
\r
1550 for( iter = (SFG_Window *)fgStructure.Windows.First;
\r
1552 iter = (SFG_Window *)iter->Node.Next )
\r
1554 if( ( iter->Window.Context == window->Window.Context ) &&
\r
1555 ( iter != window ) )
\r
1560 wglDeleteContext( window->Window.Context );
\r
1563 DestroyWindow( window->Window.Handle );
\r
1568 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
\r
1571 * Creates a new top-level freeglut window
\r
1573 int FGAPIENTRY glutCreateWindow( const char* title )
\r
1575 /* XXX GLUT does not exit; it simply calls "glutInit" quietly if the
\r
1576 * XXX application has not already done so. The "freeglut" community
\r
1577 * XXX decided not to go this route (freeglut-developer e-mail from
\r
1578 * XXX Steve Baker, 12/16/04, 4:22 PM CST, "Re: [Freeglut-developer]
\r
1579 * XXX Desired 'freeglut' behaviour when there is no current window"
\r
1581 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateWindow" );
\r
1583 return fgCreateWindow( NULL, title, fgState.Position.Use,
\r
1584 fgState.Position.X, fgState.Position.Y,
\r
1585 fgState.Size.Use, fgState.Size.X, fgState.Size.Y,
\r
1586 GL_FALSE, GL_FALSE )->ID;
\r
1589 #if TARGET_HOST_MS_WINDOWS
\r
1590 int FGAPIENTRY __glutCreateWindowWithExit( const char *title, void (__cdecl *exit_function)(int) )
\r
1592 __glutExitFunc = exit_function;
\r
1593 return glutCreateWindow( title );
\r
1598 * This function creates a sub window.
\r
1600 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
\r
1603 SFG_Window* window = NULL;
\r
1604 SFG_Window* parent = NULL;
\r
1606 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateSubWindow" );
\r
1607 parent = fgWindowByID( parentID );
\r
1608 freeglut_return_val_if_fail( parent != NULL, 0 );
\r
1611 x = parent->State.Width + x ;
\r
1612 if ( w >= 0 ) x -= w ;
\r
1615 if ( w < 0 ) w = parent->State.Width - x + w ;
\r
1624 y = parent->State.Height + y ;
\r
1625 if ( h >= 0 ) y -= h ;
\r
1628 if ( h < 0 ) h = parent->State.Height - y + h ;
\r
1635 window = fgCreateWindow( parent, "", GL_TRUE, x, y, GL_TRUE, w, h, GL_FALSE, GL_FALSE );
\r
1642 * Destroys a window and all of its subwindows
\r
1644 void FGAPIENTRY glutDestroyWindow( int windowID )
\r
1646 SFG_Window* window;
\r
1647 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDestroyWindow" );
\r
1648 window = fgWindowByID( windowID );
\r
1649 freeglut_return_if_fail( window != NULL );
\r
1651 fgExecutionState ExecState = fgState.ExecState;
\r
1652 fgAddToWindowDestroyList( window );
\r
1653 fgState.ExecState = ExecState;
\r
1658 * This function selects the current window
\r
1660 void FGAPIENTRY glutSetWindow( int ID )
\r
1662 SFG_Window* window = NULL;
\r
1664 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindow" );
\r
1665 if( fgStructure.CurrentWindow != NULL )
\r
1666 if( fgStructure.CurrentWindow->ID == ID )
\r
1669 window = fgWindowByID( ID );
\r
1670 if( window == NULL )
\r
1672 fgWarning( "glutSetWindow(): window ID %d not found!", ID );
\r
1676 fgSetWindow( window );
\r
1680 * This function returns the ID number of the current window, 0 if none exists
\r
1682 int FGAPIENTRY glutGetWindow( void )
\r
1684 SFG_Window *win = fgStructure.CurrentWindow;
\r
1686 * Since GLUT did not throw an error if this function was called without a prior call to
\r
1687 * "glutInit", this function shouldn't do so here. Instead let us return a zero.
\r
1688 * See Feature Request "[ 1307049 ] glutInit check".
\r
1690 if ( ! fgState.Initialised )
\r
1693 while ( win && win->IsMenu )
\r
1694 win = win->Parent;
\r
1695 return win ? win->ID : 0;
\r
1699 * This function makes the current window visible
\r
1701 void FGAPIENTRY glutShowWindow( void )
\r
1703 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" );
\r
1704 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" );
\r
1706 #if TARGET_HOST_POSIX_X11
\r
1708 XMapWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
\r
1709 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
\r
1711 #elif TARGET_HOST_MS_WINDOWS
\r
1713 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_SHOW );
\r
1717 fgStructure.CurrentWindow->State.Redisplay = GL_TRUE;
\r
1721 * This function hides the current window
\r
1723 void FGAPIENTRY glutHideWindow( void )
\r
1725 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" );
\r
1726 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" );
\r
1728 #if TARGET_HOST_POSIX_X11
\r
1730 if( fgStructure.CurrentWindow->Parent == NULL )
\r
1731 XWithdrawWindow( fgDisplay.Display,
\r
1732 fgStructure.CurrentWindow->Window.Handle,
\r
1733 fgDisplay.Screen );
\r
1735 XUnmapWindow( fgDisplay.Display,
\r
1736 fgStructure.CurrentWindow->Window.Handle );
\r
1737 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
\r
1739 #elif TARGET_HOST_MS_WINDOWS
\r
1741 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_HIDE );
\r
1745 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
\r
1749 * Iconify the current window (top-level windows only)
\r
1751 void FGAPIENTRY glutIconifyWindow( void )
\r
1753 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" );
\r
1754 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" );
\r
1756 fgStructure.CurrentWindow->State.Visible = GL_FALSE;
\r
1757 #if TARGET_HOST_POSIX_X11
\r
1759 XIconifyWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
\r
1760 fgDisplay.Screen );
\r
1761 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
\r
1763 #elif TARGET_HOST_MS_WINDOWS
\r
1765 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_MINIMIZE );
\r
1769 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
\r
1773 * Set the current window's title
\r
1775 void FGAPIENTRY glutSetWindowTitle( const char* title )
\r
1777 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowTitle" );
\r
1778 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" );
\r
1779 if( ! fgStructure.CurrentWindow->Parent )
\r
1781 #if TARGET_HOST_POSIX_X11
\r
1783 XTextProperty text;
\r
1785 text.value = (unsigned char *) title;
\r
1786 text.encoding = XA_STRING;
\r
1788 text.nitems = strlen( title );
\r
1791 fgDisplay.Display,
\r
1792 fgStructure.CurrentWindow->Window.Handle,
\r
1796 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
\r
1798 #elif TARGET_HOST_MS_WINDOWS
\r
1799 # ifdef _WIN32_WCE
\r
1801 wchar_t* wstr = fghWstrFromStr(title);
\r
1802 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
\r
1806 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
\r
1814 * Set the current window's iconified title
\r
1816 void FGAPIENTRY glutSetIconTitle( const char* title )
\r
1818 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" );
\r
1819 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" );
\r
1821 if( ! fgStructure.CurrentWindow->Parent )
\r
1823 #if TARGET_HOST_POSIX_X11
\r
1825 XTextProperty text;
\r
1827 text.value = (unsigned char *) title;
\r
1828 text.encoding = XA_STRING;
\r
1830 text.nitems = strlen( title );
\r
1833 fgDisplay.Display,
\r
1834 fgStructure.CurrentWindow->Window.Handle,
\r
1838 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
\r
1840 #elif TARGET_HOST_MS_WINDOWS
\r
1841 # ifdef _WIN32_WCE
\r
1843 wchar_t* wstr = fghWstrFromStr(title);
\r
1844 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
\r
1848 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
\r
1856 * Change the current window's size
\r
1858 void FGAPIENTRY glutReshapeWindow( int width, int height )
\r
1860 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" );
\r
1861 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" );
\r
1863 if (glutGet(GLUT_FULL_SCREEN))
\r
1865 /* Leave full screen state before resizing. */
\r
1866 glutLeaveFullScreen();
\r
1869 fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
\r
1870 fgStructure.CurrentWindow->State.Width = width ;
\r
1871 fgStructure.CurrentWindow->State.Height = height;
\r
1875 * Change the current window's position
\r
1877 void FGAPIENTRY glutPositionWindow( int x, int y )
\r
1879 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" );
\r
1880 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" );
\r
1882 if (glutGet(GLUT_FULL_SCREEN))
\r
1884 /* Leave full screen state before moving. */
\r
1885 glutLeaveFullScreen();
\r
1888 #if TARGET_HOST_POSIX_X11
\r
1890 XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
\r
1892 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
\r
1894 #elif TARGET_HOST_MS_WINDOWS
\r
1899 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
\r
1900 GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
\r
1902 fgStructure.CurrentWindow->Window.Handle,
\r
1905 winRect.right - winRect.left,
\r
1906 winRect.bottom - winRect.top,
\r
1915 * Lowers the current window (by Z order change)
\r
1917 void FGAPIENTRY glutPushWindow( void )
\r
1919 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPushWindow" );
\r
1920 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPushWindow" );
\r
1922 #if TARGET_HOST_POSIX_X11
\r
1924 XLowerWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
\r
1926 #elif TARGET_HOST_MS_WINDOWS
\r
1929 fgStructure.CurrentWindow->Window.Handle,
\r
1932 SWP_NOSIZE | SWP_NOMOVE
\r
1939 * Raises the current window (by Z order change)
\r
1941 void FGAPIENTRY glutPopWindow( void )
\r
1943 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" );
\r
1944 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" );
\r
1946 #if TARGET_HOST_POSIX_X11
\r
1948 XRaiseWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
\r
1950 #elif TARGET_HOST_MS_WINDOWS
\r
1953 fgStructure.CurrentWindow->Window.Handle,
\r
1956 SWP_NOSIZE | SWP_NOMOVE
\r
1963 * Resize the current window so that it fits the whole screen
\r
1965 void FGAPIENTRY glutFullScreen( void )
\r
1969 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" );
\r
1970 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" );
\r
1972 win = fgStructure.CurrentWindow;
\r
1976 /* Child windows cannot be made fullscreen, consistent with GLUT's behavior
\r
1977 * Also, what would it mean for a child window to be fullscreen, given that it
\r
1978 * is confined to its parent?
\r
1980 fgWarning("glutFullScreen called on a child window, ignoring...");
\r
1983 else if (fgStructure.GameModeWindow != NULL && fgStructure.GameModeWindow->ID==win->ID)
\r
1985 /* Ignore fullscreen call on GameMode window, those are always fullscreen already */
\r
1989 #if TARGET_HOST_POSIX_X11
\r
1990 if(!glutGet(GLUT_FULL_SCREEN)) {
\r
1991 if(fghToggleFullscreen() != -1) {
\r
1992 win->State.IsFullscreen = GL_TRUE;
\r
1996 #elif TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: what about WinCE */
\r
1998 if (glutGet(GLUT_FULL_SCREEN))
\r
2000 /* Leave full screen state before entering fullscreen again (resizing?) */
\r
2001 glutLeaveFullScreen();
\r
2005 #if(WINVER >= 0x0500) /* Windows 2000 or later */
\r
2008 HMONITOR hMonitor;
\r
2011 /* For fullscreen mode, first remove all window decoration
\r
2012 * and set style to popup so it will overlap the taskbar
\r
2013 * then force to maximize on the screen on which it has the most
\r
2018 /* store current window rect */
\r
2019 GetWindowRect( win->Window.Handle, &win->State.OldRect );
\r
2021 /* store current window style */
\r
2022 win->State.OldStyle = s = GetWindowLong(win->Window.Handle, GWL_STYLE);
\r
2024 /* remove decorations from style and add popup style*/
\r
2025 s &= ~WS_OVERLAPPEDWINDOW;
\r
2027 SetWindowLong(win->Window.Handle, GWL_STYLE, s);
\r
2028 SetWindowPos(win->Window.Handle, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
\r
2030 /* For fullscreen mode, find the monitor that is covered the most
\r
2031 * by the window and get its rect as the resize target.
\r
2033 hMonitor= MonitorFromRect(&win->State.OldRect, MONITOR_DEFAULTTONEAREST);
\r
2034 mi.cbSize = sizeof(mi);
\r
2035 GetMonitorInfo(hMonitor, &mi);
\r
2036 rect = mi.rcMonitor;
\r
2037 #else /* if (WINVER >= 0x0500) */
\r
2040 /* For fullscreen mode, force the top-left corner to 0,0
\r
2041 * and adjust the window rectangle so that the client area
\r
2042 * covers the whole screen.
\r
2047 rect.right = fgDisplay.ScreenWidth;
\r
2048 rect.bottom = fgDisplay.ScreenHeight;
\r
2050 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
\r
2051 WS_CLIPCHILDREN, FALSE );
\r
2052 #endif /* (WINVER >= 0x0500) */
\r
2055 * then resize window
\r
2056 * SWP_NOACTIVATE Do not activate the window
\r
2057 * SWP_NOOWNERZORDER Do not change position in z-order
\r
2058 * SWP_NOSENDCHANGING Suppress WM_WINDOWPOSCHANGING message
\r
2059 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
\r
2061 SetWindowPos( fgStructure.CurrentWindow->Window.Handle,
\r
2065 rect.right - rect.left,
\r
2066 rect.bottom - rect.top,
\r
2067 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
\r
2071 win->State.IsFullscreen = GL_TRUE;
\r
2077 * If we are fullscreen, resize the current window back to its original size
\r
2079 void FGAPIENTRY glutLeaveFullScreen( void )
\r
2083 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" );
\r
2084 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" );
\r
2086 win = fgStructure.CurrentWindow;
\r
2088 #if TARGET_HOST_POSIX_X11
\r
2089 if(glutGet(GLUT_FULL_SCREEN)) {
\r
2090 if(fghToggleFullscreen() != -1) {
\r
2091 win->State.IsFullscreen = GL_FALSE;
\r
2095 #elif TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: what about WinCE */
\r
2096 if (!glutGet(GLUT_FULL_SCREEN))
\r
2098 /* nothing to do */
\r
2102 /* restore style of window before making it fullscreen */
\r
2103 SetWindowLong(win->Window.Handle, GWL_STYLE, win->State.OldStyle);
\r
2104 SetWindowPos(win->Window.Handle, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
\r
2107 SetWindowPos(win->Window.Handle,
\r
2109 win->State.OldRect.left,
\r
2110 win->State.OldRect.top,
\r
2111 win->State.OldRect.right - win->State.OldRect.left,
\r
2112 win->State.OldRect.bottom - win->State.OldRect.top,
\r
2113 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
\r
2117 win->State.IsFullscreen = GL_FALSE;
\r
2122 * Toggle the window's full screen state.
\r
2124 void FGAPIENTRY glutFullScreenToggle( void )
\r
2128 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreenToggle" );
\r
2129 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreenToggle" );
\r
2131 win = fgStructure.CurrentWindow;
\r
2133 #if TARGET_HOST_POSIX_X11
\r
2134 if(fghToggleFullscreen() != -1) {
\r
2135 win->State.IsFullscreen = !win->State.IsFullscreen;
\r
2137 #elif TARGET_HOST_MS_WINDOWS
\r
2138 if (!win->State.IsFullscreen)
\r
2141 glutLeaveFullScreen();
\r
2146 * A.Donev: Set and retrieve the window's user data
\r
2148 void* FGAPIENTRY glutGetWindowData( void )
\r
2150 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindowData" );
\r
2151 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutGetWindowData" );
\r
2152 return fgStructure.CurrentWindow->UserData;
\r
2155 void FGAPIENTRY glutSetWindowData(void* data)
\r
2157 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowData" );
\r
2158 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowData" );
\r
2159 fgStructure.CurrentWindow->UserData = data;
\r
2162 /*** END OF FILE ***/
\r