/* * Control the auto-repeat of keystrokes to the current window */ void FGAPIENTRY glutIgnoreKeyRepeat( int ignore ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIgnoreKeyRepeat" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIgnoreKeyRepeat" ); fgStructure.CurrentWindow->State.IgnoreKeyRepeat = ignore ? GL_TRUE : GL_FALSE; }
/* * Swaps the buffers for the current window (if any) */ void FGAPIENTRY glutSwapBuffers( void ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSwapBuffers" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSwapBuffers" ); /* * "glXSwapBuffers" already performs an implicit call to "glFlush". What * about "SwapBuffers"? */ glFlush( ); if( ! fgStructure.CurrentWindow->Window.DoubleBuffered ) return; fgPlatformGlutSwapBuffers( &fgDisplay.pDisplay, fgStructure.CurrentWindow ); /* GLUT_FPS env var support */ if( fgState.FPSInterval ) { GLint t = glutGet( GLUT_ELAPSED_TIME ); fgState.SwapCount++; if( fgState.SwapTime == 0 ) fgState.SwapTime = t; else if( t - fgState.SwapTime > fgState.FPSInterval ) { float time = 0.001f * ( t - fgState.SwapTime ); float fps = ( float )fgState.SwapCount / time; fprintf( stderr, "freeglut: %d frames in %.2f seconds = %.2f FPS\n", fgState.SwapCount, time, fps ); fgState.SwapTime = t; fgState.SwapCount = 0; } } }
/* * Moves the mouse pointer to given window coordinates */ void FGAPIENTRY glutWarpPointer( int x, int y ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWarpPointer" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutWarpPointer" ); fghWarpPointer ( x, y ); }
/* * Set the cursor image to be used for the current window */ void FGAPIENTRY glutSetCursor( int cursorID ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetCursor" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetCursor" ); fgSetCursor ( fgStructure.CurrentWindow, cursorID ); }
/* * Resize the current window so that it fits the whole screen */ void FGAPIENTRY glutFullScreen( void ) { SFG_Window *win; FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" ); win = fgStructure.CurrentWindow; if (win->Parent) { /* Child windows cannot be made fullscreen, consistent with GLUT's behavior * Also, what would it mean for a child window to be fullscreen, given that it * is confined to its parent? */ fgWarning("glutFullScreen called on a child window, ignoring..."); return; } else if (fgStructure.GameModeWindow != NULL && fgStructure.GameModeWindow->ID==win->ID && win->State.IsFullscreen) { /* Ignore fullscreen call on GameMode window, those are always fullscreen already * only exception is during first entering GameMode */ return; } fgPlatformGlutFullScreen ( win ); }
/* * Raises the current window (by Z order change) */ void FGAPIENTRY glutPopWindow( void ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" ); fgPlatformGlutPopWindow (); }
/* * Change the current window's position */ void FGAPIENTRY glutPositionWindow( int x, int y ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" ); #if TARGET_HOST_UNIX_X11 XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle, x, y ); XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE { RECT winRect; /* "GetWindowRect" returns the pixel coordinates of the outside of the window */ GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect ); MoveWindow( fgStructure.CurrentWindow->Window.Handle, x, y, winRect.right - winRect.left, winRect.bottom - winRect.top, TRUE ); } #endif }
/* * Moves the mouse pointer to given window coordinates */ void FGAPIENTRY glutWarpPointer( int x, int y ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWarpPointer" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutWarpPointer" ); #if TARGET_HOST_POSIX_X11 XWarpPointer( fgDisplay.Display, None, fgStructure.CurrentWindow->Window.Handle, 0, 0, 0, 0, x, y ); /* Make the warp visible immediately. */ XFlush( fgDisplay.Display ); #elif TARGET_HOST_MS_WINDOWS { POINT coords; coords.x = x; coords.y = y; /* ClientToScreen() translates {coords} for us. */ ClientToScreen( fgStructure.CurrentWindow->Window.Handle, &coords ); SetCursorPos( coords.x, coords.y ); } #endif }
/* * Iconify the current window (top-level windows only) */ void FGAPIENTRY glutIconifyWindow( void ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" ); fgPlatformGlutIconifyWindow (); fgStructure.CurrentWindow->State.Redisplay = GL_FALSE; }
/* * Set the current window's title */ void FGAPIENTRY glutSetWindowTitle( const char* title ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowTitle" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" ); if( ! fgStructure.CurrentWindow->Parent ) { fgPlatformGlutSetWindowTitle ( title ); } }
/* * Change the current window's size */ void FGAPIENTRY glutReshapeWindow( int width, int height ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" ); fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE; fgStructure.CurrentWindow->State.Width = width ; fgStructure.CurrentWindow->State.Height = height; }
/* * Toggle the window's full screen state. */ void FGAPIENTRY glutFullScreenToggle( void ) { SFG_Window *win; FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreenToggle" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreenToggle" ); win = fgStructure.CurrentWindow; fgPlatformGlutFullScreenToggle ( win ); }
/* * Change the current window's position */ void FGAPIENTRY glutPositionWindow( int x, int y ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" ); if (glutGet(GLUT_FULL_SCREEN)) { /* Leave full screen state before moving. */ glutLeaveFullScreen(); } fgPlatformGlutPositionWindow ( x, y ); }
/* * Change the current window's size */ void FGAPIENTRY glutReshapeWindow( int width, int height ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" ); if (glutGet(GLUT_FULL_SCREEN)) { /* Leave full screen state before resizing. */ glutLeaveFullScreen(); } fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE; fgStructure.CurrentWindow->State.Width = width ; fgStructure.CurrentWindow->State.Height = height; }
/* * This function makes the current window visible */ void FGAPIENTRY glutShowWindow( void ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" ); #if TARGET_HOST_UNIX_X11 XMapWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle ); XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_SHOW ); #endif fgStructure.CurrentWindow->State.Redisplay = GL_TRUE; }
/* * Raises the current window (by Z order change) */ void FGAPIENTRY glutPopWindow( void ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" ); #if TARGET_HOST_UNIX_X11 XRaiseWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle ); #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE SetWindowPos( fgStructure.CurrentWindow->Window.Handle, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE ); #endif }
/* * Iconify the current window (top-level windows only) */ void FGAPIENTRY glutIconifyWindow( void ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" ); fgStructure.CurrentWindow->State.Visible = GL_FALSE; #if TARGET_HOST_UNIX_X11 XIconifyWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle, fgDisplay.Screen ); XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_MINIMIZE ); #endif fgStructure.CurrentWindow->State.Redisplay = GL_FALSE; }
/* * Set the current window's iconified title */ void FGAPIENTRY glutSetIconTitle( const char* title ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" ); if( ! fgStructure.CurrentWindow->Parent ) { #if TARGET_HOST_UNIX_X11 XTextProperty text; text.value = (unsigned char *) title; text.encoding = XA_STRING; text.format = 8; text.nitems = strlen( title ); XSetWMIconName( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle, &text ); XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ #elif TARGET_HOST_WIN32 SetWindowTextA( fgStructure.CurrentWindow->Window.Handle, title ); #elif TARGET_HOST_WINCE { wchar_t* wstr = fghWstrFromStr(title); SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr ); free(wstr); } #endif } }
/* * This function hides the current window */ void FGAPIENTRY glutHideWindow( void ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" ); #if TARGET_HOST_UNIX_X11 if( fgStructure.CurrentWindow->Parent == NULL ) XWithdrawWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle, fgDisplay.Screen ); else XUnmapWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle ); XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_HIDE ); #endif fgStructure.CurrentWindow->State.Redisplay = GL_FALSE; }
/* * Resize the current window so that it fits the whole screen */ void FGAPIENTRY glutFullScreen( void ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" ); { #if TARGET_HOST_UNIX_X11 int x, y; Window w; XMoveResizeWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle, 0, 0, fgDisplay.ScreenWidth, fgDisplay.ScreenHeight ); XFlush( fgDisplay.Display ); /* This is needed */ XTranslateCoordinates( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle, fgDisplay.RootWindow, 0, 0, &x, &y, &w ); if (x || y) { XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle, -x, -y ); XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ } #elif TARGET_HOST_WIN32 RECT rect; /* For fullscreen mode, force the top-left corner to 0,0 * and adjust the window rectangle so that the client area * covers the whole screen. */ rect.left = 0; rect.top = 0; rect.right = fgDisplay.ScreenWidth; rect.bottom = fgDisplay.ScreenHeight; AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, FALSE ); /* * SWP_NOACTIVATE Do not activate the window * SWP_NOOWNERZORDER Do not change position in z-order * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message * SWP_NOZORDER Retains the current Z order (ignore 2nd param) */ SetWindowPos( fgStructure.CurrentWindow->Window.Handle, HWND_TOP, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_NOZORDER ); #endif } }
/* * A.Donev: Set and retrieve the window's user data */ void* FGAPIENTRY glutGetWindowData( void ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindowData" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutGetWindowData" ); return fgStructure.CurrentWindow->UserData; }
void FGAPIENTRY glutSetWindowData(void* data) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowData" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowData" ); fgStructure.CurrentWindow->UserData = data; }