Bonjour à tous,

Je suis actuellement en train de travailler sur une simulation graphique où j'ai décidé d'utiliser GLFW. Je voudrais savoir comment régler le frame rate.

J'ai déjà eu l'occasion de me frotter à ces problèmes avec GLUT mais la solution était beaucoup plus simple puisque fourni dans la lib.

J'ai eu l'idée de créer un timer qui appelait la fonction swapbuffer mais ça n'a pas vraiment amélioré les choses.

voici le code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "main.h"
 
 
 
//----------------------------------------------------------------------
// openWindow() - Open a window to render.
//----------------------------------------------------------------------
 
int openWindow(void)
{
int ok = 0;
 
    ok = glfwOpenWindow(
        640, 480,          // Width and height of window
        8, 8, 8,           // Number of red, green, and blue bits for color buffer
        8,                 // Number of bits for alpha buffer
        24,                // Number of bits for depth buffer (Z-buffer)
        0,                 // Number of bits for stencil buffer
        GLFW_WINDOW        // We want a desktop window (could be GLFW_FULLSCREEN)
    );
 
return ok;
}
 
 
 
 
//----------------------------------------------------------------------
// initCamera() - Initialisation of view and camera system.
//----------------------------------------------------------------------
void initCamera(void)
{
    int    width, height;  // Window dimensions
 
 // Get window size
    glfwGetWindowSize( &width, &height );
 
    // Make sure that height is non-zero to avoid division by zero
    height = height < 1 ? 1 : height;
 
    // Set viewport
    glViewport( 0, 0, width, height );
 
    // Clear color and depht buffers
    glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
 
    // Set up projection matrix
    glMatrixMode( GL_PROJECTION );    // Select projection matrix
    glLoadIdentity();                 // Start with an identity matrix
    gluPerspective(                   // Set perspective view
        85.0,                         // Field of view = 65 degrees
        (double)width/(double)height, // Window aspect (assumes square pixels)
        1.0,                          // Near Z clipping plane
        100.0                         // Far Z clippling plane
    );
 
    // Set up modelview matrix
    glMatrixMode( GL_MODELVIEW );     // Select modelview matrix
    glLoadIdentity();                 // Start with an identity matrix
    gluLookAt(                        // Set camera position and orientation
        0.0, 0.0, 20.0,               // Camera position (x,y,z)
        0.0, 0.0, 0.0,                // View point (x,y,z)
        0.0, 1.0, 0.0                 // Up-vector (x,y,z)
    );
 
}    
 
 
 
 
 
 
//----------------------------------------------------------------------
// draw() - Main OpenGL drawing function that is called each frame
//----------------------------------------------------------------------
 
 
void drawSim( void )
{
 
    // ****Draw a Grille which is fading***
 
 
    // Now draw the quad
 
    if(colorR>=1.00)
    {
        down = 1;
        up = 0 ;
    }
    else if (colorR <= 0)
    {
        down = 0;
        up = 1 ;
    }
 
    if(up == 1)
        colorR += 0.001;  
    else if (down == 1)
        colorR -= 0.001;
 
 
    Burn.setGlobalLightness(colorR);
    Burn.draw();     
 
}
 
 
 
//----------------------------------------------------------------------
// main() - Program entry point
//----------------------------------------------------------------------
int main( int argc, char **argv )
{
    int    ok;             // Flag telling if the window was opened
    int    running;        // Flag telling if the program is running
 
    int    frames;
	double fps, time, t0;
	char   title[150];
 
	frames = 0;
	t0 = glfwGetTime();
 
 
    // Initialize GLFW
    glfwInit();
 
    // Open window
    ok = openWindow();
 
    // If we could not open a window, exit now
    if( !ok )
    {
        glfwTerminate();
        return 0;
    }
 
    // Set window title
    glfwSetWindowTitle( "cube 1.0" );
 
    // Enable sticky keys
    glfwEnable( GLFW_STICKY_KEYS );
 
    //Initialize camera
    initCamera();
 
 
    // Main rendering loop
    do
    {
                //get the current time
        time = glfwGetTime();
 
		// Calcul and display the FPS
        if((time-t0) > 1.0 || frames == 0)
        {
            fps = (double)frames / (time-t0);
            sprintf(title, "cube 1.0 (%.1f FPS)", fps);
            glfwSetWindowTitle(title);
            t0 = time;
            frames = 0;
        }
        frames ++;
 
 
 
 
        // Call our rendering function
        drawSim();
 
        //Limit the frameRate to 60fps.
       glfwSwapInterval(1);
 
 
        // Swap front and back buffers (we use a double buffered display)
 
         glfwSwapBuffers();
 
        // Check if the escape key was pressed, or if the window was closed
        running = !glfwGetKey( GLFW_KEY_ESC ) &&
                  glfwGetWindowParam( GLFW_OPENED );
    }
    while( running );
 
    // Terminate GLFW
    glfwTerminate();
 
    // Exit program
    return 0;
}
Une personne aurait-elle la moindre idée ??

Merci d'avance !