PDA

View Full Version : Controlling apps



t3jem
08-02-2005, 07:37 PM
Hi, I use glut to make my programs and evertime I run my program my CPU usage goes up to 100%. Is there a way in glut to keep this from happening?

All replies are greatly appreciated

Hylke Donker
08-03-2005, 12:29 AM
What are you drawing?
Rotations, translations, scalings and lighting involves lots of calculations.
And how fast is you're CPU?
These things affect the cpu usage, I don't think GLUT is caussing the problem.

Relic
08-03-2005, 12:50 AM
Do not render in the idle callback.

t3jem
08-04-2005, 07:03 AM
ok,

I'm creating an entire scene that you can roam around in using a first person camera. Although this may seem to be the problem all of my apps take 100% CPU usage to try and get as many frames per second as possible. And I dont render in the idle function, I use glutDisplayFunc for rendering my scene.

Hlz
08-04-2005, 08:24 AM
Can you throw us a bone? :confused:

It's a good idea to wrap suspect code with profilers, so you'll always have a good idea where the time is spent. This way you can isolate problem areas within your app without guessing.

Relic
08-04-2005, 10:16 PM
"try and get as many frames per second as possible"

Well, that's a perfectly valid reason to get 100% CPU usage. If you continuously render (in whatever callback) you burn as much as your system can give.

t3jem
08-05-2005, 04:57 AM
My program is running as many frames per seconds as it can on the machine it is running on. A simple window has the same problem. Here's the code for just a window, but it will use 100% CPU


#include<glut.h>

void init()
{
glClearColor(0,0,0,0);
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT);

glFlush();
glutPostRedisplay();
glutSwapBuffers();
}

void main(int argc, char ** argv)
{
glutInit(&amp;argc, argv);
glutInitWindowPosition(10,20);
glutInitWindowSize(1000,700);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutCreateWindow(argc[0]);
init();
glutDisplayFunc(display);
glutMainLooop();
}This program itself will run using 100% CPU power on any machine, I would like to know if there is a way to keep it from happening.
}

Relic
08-05-2005, 05:49 AM
Yes, don't do glutPostRedisplay() in the display routine.
Do it when you need a repaint. If the image doesn't change, don't repaint it.
If it changes all the time, you're stuck.
You could limit the framerate (and CPU load) by sending the update from a timer callback.

If that's all not feasible for your case, I would at least put the glutPostRedisplay() at the end of that function for peace of mind. ;)

The glFlush is useless and only needed for single buffered pixelformats. Remove it for double buffered ones.

08-05-2005, 06:33 AM
ok, Thanks for all your help