Thread: open gl newbie issues

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

    open gl newbie issues

    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?
    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
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    You can cache the "m_ppf * f" calculation outside the for loop and avoid unneeded copies (assuming the compiler doesn't optimize it out).
    Code:
    int offset = m_ppf * f;
    for (i = 0; i < m_ppf; i++, offset++)
    {
        glPushMatrix();
            glTranslated(m_x[offset], m_y[offset], m_z[offset]); //may need to be casted
            gluSphere(quadratic, m_radius, 12, 12);
        glPopMatrix();
    }
    You could also remove the push and pop and re-design your m_x, m_y, and m_z values to be "from the last translation" (if that makes any sense).

    I'm assuming that most of the time is spent in gluSphere(). There may be "more efficient" gl code on the net for doing this. You can also try the game programming forum - some gl experts in there.

    gg

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    15
    Hmm.. Changing the m_ppf to an offset and putting it outside the loop doesn't really help much. You're right though that most of the time is spent in glusphere. Making it so I don't have to call push and pop also helps, but not much...

    Can I make use of the fact that the spheres are all identical, or that they don't move much between frames?

    Can I move a sphere to a new position, or must I always re-create it in its new position?

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    This is a good place to start a new thread in the game programming board where all the "gl" experts live.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Open GL issues
    By drdodirty2002 in forum C++ Programming
    Replies: 1
    Last Post: 12-15-2005, 03:57 PM
  2. open scene graph compile issues
    By ichijoji in forum Game Programming
    Replies: 1
    Last Post: 08-04-2005, 12:31 PM
  3. 2 Open GL problems
    By Isometric in forum Game Programming
    Replies: 0
    Last Post: 11-30-2003, 10:09 PM
  4. open gl coding, animating an object
    By chris285 in forum Game Programming
    Replies: 1
    Last Post: 11-18-2003, 10:51 AM
  5. open gl
    By nerdyneo in forum Game Programming
    Replies: 2
    Last Post: 11-14-2003, 04:33 PM