eeac0ac7c5c7226be0f881309c31780c55406261
[freeglut] / src / freeglut_display.c
1 /*
2  * freeglut_display.c
3  *
4  * Display message posting, context buffer swapping.
5  *
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
9  *
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:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Software.
19  *
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.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <GL/freeglut.h>
33 #include "freeglut_internal.h"
34
35
36 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
37
38 /*
39  * Marks the current window to have the redisplay performed when possible...
40  */
41 void FGAPIENTRY glutPostRedisplay( void )
42 {
43     freeglut_assert_ready;
44     freeglut_assert_window;
45     fgStructure.Window->State.Redisplay = GL_TRUE;
46 }
47
48 /*
49  * Swaps the buffers for the current window (if any)
50  */
51 void FGAPIENTRY glutSwapBuffers( void )
52 {
53     freeglut_assert_ready;
54     freeglut_assert_window;
55
56     glFlush( );
57     if( ! fgStructure.Window->Window.DoubleBuffered )
58         return;
59
60 #if TARGET_HOST_UNIX_X11
61     glXSwapBuffers( fgDisplay.Display, fgStructure.Window->Window.Handle );
62 #elif TARGET_HOST_WIN32
63     SwapBuffers( fgStructure.Window->Window.Device );
64 #endif
65
66     /* GLUT_FPS env var support */
67     if( fgState.FPSInterval )
68     {
69         GLint t = glutGet( GLUT_ELAPSED_TIME );
70         fgState.SwapCount++;
71         if( fgState.SwapTime == 0 )
72             fgState.SwapTime = t;
73         else if( t - fgState.SwapTime > fgState.FPSInterval )
74         {
75             float time = 0.001f * ( t - fgState.SwapTime );
76             float fps = ( float )fgState.SwapCount / time;
77             fprintf( stderr,
78                      "freeglut: %d frames in %.2f seconds = %.2f FPS\n",
79                      fgState.SwapCount, time, fps );
80             fgState.SwapTime = t;
81             fgState.SwapCount = 0;
82         }
83     }
84 }
85
86 /*
87  * Mark appropriate window to be displayed
88  */
89 void FGAPIENTRY glutPostWindowRedisplay( int windowID )
90 {
91     SFG_Window* window;
92
93     freeglut_assert_ready;
94     window = fgWindowByID( windowID );
95     freeglut_return_if_fail( window );
96     window->State.Redisplay = GL_TRUE;
97 }
98
99 /*** END OF FILE ***/