gl animation too slow

This is a discussion on gl animation too slow within the Game Programming forums, part of the General Programming Boards category; Dear All, I am a beginner at openGL, but have managed to cobble together an otherwise quite nice program that ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    15

    gl animation too slow

    Dear All,

    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:

    Code:
    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();
    
    	::glNewList(1,GL_COMPILE_AND_EXECUTE);
    
    	glColor3f(1.0f,1.0f,1.0f);
    
    	for(i=0; i<m_ppf; i++)
    	{
    		n = m_ppf*f + i;
    		X = m_x[n];
    		Y = m_y[n];
    		Z = m_z[n];
    		glPushMatrix();
    			glTranslated(X, Y, Z);
    			gluSphere(quadratic, m_radius, 12, 12);
    		glPopMatrix();
    	}
    
    	::glEndList();
    }
    As you can see, m_ppf (this can often be ~1000) individual spheres are created in each frame.
    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,

    Phil

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    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.
    My Website

    "Circular logic is good because it is."

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    He said it takes 1 second to load each frame.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904
    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)

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    15
    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?

    Phil

  6. #6
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    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.
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Threads in MFC
    By VirtualAce in forum Windows Programming
    Replies: 4
    Last Post: 12-28-2005, 06:03 PM
  2. Animation class not working
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 03-02-2005, 06:48 AM
  3. 3D animation (difficult?)
    By maes in forum Game Programming
    Replies: 3
    Last Post: 09-08-2003, 11:44 PM
  4. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 05:10 AM
  5. Dx, Sdl, Open-gl
    By dayknight in forum Game Programming
    Replies: 26
    Last Post: 12-28-2002, 02:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21