gl animation too slow
I am a beginner at openGL, but have managed to cobble together an otherwise quite nice program that is supposed to animate a number of spheres.
The trouble is that each frame takes a very long time to create (~1 sec). When I rotate the image, it moves quite smoothly, so I guess from that that it is definately my frame CREATION that takes too much time, not the rendering.
Here is my current code:
As you can see, m_ppf (this can often be ~1000) individual spheres are created in each frame.
void CAnimationDialog::buildFrame(int f)
int i, n;
GLUquadricObj *quadratic; // Storage For Our Quadratic Objects ( NEW )
double X, Y, Z;
float r = 0.1f;
quadratic = gluNewQuadric();
for(i=0; i<m_ppf; i++)
n = m_ppf*f + i;
X = m_x[n];
Y = m_y[n];
Z = m_z[n];
glTranslated(X, Y, Z);
gluSphere(quadratic, m_radius, 12, 12);
Am I doing this a silly, time-consumiing way? Any suggestions to speed it up?
Can I make use of the fact that all the spheres are the same? Or that they all exist in all frames (i.e. can I create them one, and then just move them)?
On a different topic, when I zoom out, all the spheres get very pale - which is the gl_command that controls this effect?
Thanks everyone - hope you can help,
It seems logical to me. 1 second is NOT a bad loadtime. In fact, it is good to do AS MUCH AS POSSIBLE at load time so you dont have to have so many calculations going on at runtime.
It is the fps at runtime you are worried about, not the loadtime. Think of how long it takes to load up some programs and games, or save games, or load a saved game, etc. etc.
Always remember to keep that in mind: Do as much as possible in load time. Do as little as possible in run time.
Loadtimes can be big, it does not matter. As long as you have some type of indicator to tell your user that the program is actually loading information and did not just stall, users will be happy, because they will receive faster runtime.
He said it takes 1 second to load each frame.
ok, well, i'm guessing the reason why it might be rendering slowly is the fact that you're rendering 1000 spheres :) It looks like you are learning from NeHe, judging by your code in the program, so what i'll suggest to you is looking in to gametutorials.com, which has tutorials on "frustum culling" which basically means avoiding sending objects through the rendering pipeline that won't even be seen. However, if you are just starting program OpenGL, then you might be overwhelmed with that stuff, so i'd suggest taking it slow.....or whatever
also, i'd advise trying not to create a new quadric each frame, but do it before hand, this should save some time in the rendering (not much, but a little amount)
DavidP:- As you can see from the other replies, my point is that I'm having trouble creating a moving world, not moving myself around a static world - that bit works fine.
Your point about doing as much beforehand as possible is well taken though, so how's about this: Could I create a big bunch of glists before I start the animation, and then just pump them out one after another? I imagine (though I could be wrong) that I'd have to save them to a file, since the memory would fill up pretty quickly.
Any hints on that idea, or similar work-arounds?
On the topic of frustum culling, can I take it that's only applicable to a stationary viewer? Really I want to be able to move about the world at the same time as watching it change. Although I suppose if I could get a dozen or so frames per second, I'd be effectively stationary in eacg frame. Seems a bit messy though...
Thanks everyone - any more?
I am sorry, I must have misread your original post.
The others have put forth good suggestions. backface culling, frustum culling, etc. would all work great.
You might also want to try using display lists. They are not always guaranteed to make your program go faster, but they are worth a shot.