Moving the source code files from 'src' to 'src/Common' as a first step towards separ...
[freeglut] / src / Common / freeglut_display.c
1 /*\r
2  * freeglut_display.c\r
3  *\r
4  * Display message posting, context buffer swapping.\r
5  *\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
9  *\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
16  *\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
19  *\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
26  */\r
27 \r
28 #include <GL/freeglut.h>\r
29 #include "freeglut_internal.h"\r
30 \r
31 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */\r
32 \r
33 /*\r
34  * Marks the current window to have the redisplay performed when possible...\r
35  */\r
36 void FGAPIENTRY glutPostRedisplay( void )\r
37 {\r
38     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPostRedisplay" );\r
39     if ( ! fgStructure.CurrentWindow )\r
40         {\r
41       fgError ( " ERROR:  Function <%s> called"\r
42                 " with no current window defined.", "glutPostRedisplay" ) ;\r
43         }\r
44 \r
45     fgStructure.CurrentWindow->State.Redisplay = GL_TRUE;\r
46 }\r
47 \r
48 /*\r
49  * Swaps the buffers for the current window (if any)\r
50  */\r
51 void FGAPIENTRY glutSwapBuffers( void )\r
52 {\r
53     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSwapBuffers" );\r
54     FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSwapBuffers" );\r
55 \r
56     /*\r
57      * "glXSwapBuffers" already performs an implicit call to "glFlush". What\r
58      * about "SwapBuffers"?\r
59      */\r
60     glFlush( );\r
61     if( ! fgStructure.CurrentWindow->Window.DoubleBuffered )\r
62         return;\r
63 \r
64 #if TARGET_HOST_POSIX_X11\r
65     glXSwapBuffers( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );\r
66 #elif TARGET_HOST_MS_WINDOWS\r
67     SwapBuffers( fgStructure.CurrentWindow->Window.Device );\r
68 #endif\r
69 \r
70     /* GLUT_FPS env var support */\r
71     if( fgState.FPSInterval )\r
72     {\r
73         GLint t = glutGet( GLUT_ELAPSED_TIME );\r
74         fgState.SwapCount++;\r
75         if( fgState.SwapTime == 0 )\r
76             fgState.SwapTime = t;\r
77         else if( t - fgState.SwapTime > fgState.FPSInterval )\r
78         {\r
79             float time = 0.001f * ( t - fgState.SwapTime );\r
80             float fps = ( float )fgState.SwapCount / time;\r
81             fprintf( stderr,\r
82                      "freeglut: %d frames in %.2f seconds = %.2f FPS\n",\r
83                      fgState.SwapCount, time, fps );\r
84             fgState.SwapTime = t;\r
85             fgState.SwapCount = 0;\r
86         }\r
87     }\r
88 }\r
89 \r
90 /*\r
91  * Mark appropriate window to be displayed\r
92  */\r
93 void FGAPIENTRY glutPostWindowRedisplay( int windowID )\r
94 {\r
95     SFG_Window* window;\r
96 \r
97     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPostWindowRedisplay" );\r
98     window = fgWindowByID( windowID );\r
99     freeglut_return_if_fail( window );\r
100     window->State.Redisplay = GL_TRUE;\r
101 }\r
102 \r
103 /*** END OF FILE ***/\r