-
glutIdleFunc() performance problem
Hi,
I have a problem with my project. If I activate glutIdleFunc() after several minutes I have a bad performance problem, slow framerate and I need to forced exit from the program.
I tried with a very simple idle func but I have always the same problem:
idle func:
voidSelectionScene::animate()
{
time = glutGet(GLUT_ELAPSED_TIME);
timediff = time - timeprec;
timeprec = time;
const float ySpeed =
1.0f;
yRotation += ySpeed *
timediff/
14;
if (
yRotation >
360.0f) {
yRotation -=
360.0f;
}
glutPostRedisplay();
}
main
void display();
void animate();
void reshape(
int width,
int height);
void mouseFunc(
int,
int,
int,
int);
void keyboardFunc(unsignedchar, int, int);
void specialKeyboardFunc(
int,
int,
int);
void changeScene();
//StartMenu start;
GameScene *game;
StartMenu *start;
SelectionScene *selection;
//GamePhase *game;
extern State CURRENTSTATE;
int main (
int argc,
char ** argv)
{
myWindow window1;
window1.
init(argc, argv);
StartMenu s;
SelectionScene sl;
GameScene g;
Debug d;
start = &s;
selection = &sl;
game = &g;
// debug = &d;
/* switch (CURRENTSTATE) {
case STARTMENU:
{
cout << "yes" << endl;
StartMenu start;
game = &start;
break;
}
case SELECTION:
{
SelectionScene selection;
game = &selection;
break;
}
case GAME:
{
GameScene g;
game = &g;
break;
}
default:
exit(1);
}*/
glutReshapeFunc(reshape);
glutIdleFunc(animate);
window1.
render(&
display);
window1.
mouse(&
mouseFunc);
window1.keyboard(&keyboardFunc);
window1.specialKeyboard(&specialKeyboardFunc);
// game->setTime(glutGet(GLUT_ELAPSED_TIME));
//glutIdleFunc(animate);
glutMainLoop();
return 0;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glLoadIdentity();
cout <<
glGetString(
GL_VENDOR) <<
endl;
cout <<
glGetString(
GL_RENDERER) <<
endl;
switch (CURRENTSTATE) {
case STARTMENU:
if(
start->
initialize()) {
start->
render();
}
break;
case SELECTION:
if(
selection->
initialize()) {
selection->
render();
}
break;
case GAME:
if(
game->
initialize()) {
game->
render();
}
break;
default:
exit(
1);
}
/* if(game->initialize()) {
game->render();
}*/
glutSwapBuffers();
sleep(
0.7);
}
void reshape(
int width,
int height)
{
switch (CURRENTSTATE) {
case STARTMENU:
start->
reshape(width, height);
break;
case SELECTION:
{
selection->
reshape(width, height);
break;
}
case GAME:
game->
reshape(width, height);
break;
case DEB:
// debug->reshape(width, height);
break;
default:
exit(
1);
}
// game->reshape(width, height);
}
void animate()
{
switch (CURRENTSTATE) {
case SELECTION:
selection->
animate();
break;
case GAME:
game->
animate();
break;
case DEB:
// debug->animate();
break;
default:
break;
}
// sleep(1);
// game->animate();
}
-
Advanced Member
Frequent Contributor
How is this different from your other performance issue thread? Please,don't open multiple threads for something like this!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules