I am trying to get at least 120fps with an application, but it currently sits around 30fps. If I remove my sphere creating method, the fps goes to 120.
My sphere method checks every sphere to see if it is out of bounds. Using a struct did not improve performance.
xc = x coord
yc = y coord
zc = y coord
xd = x direction
yd = y direction
zd = z direction
Is there any way that I could drastically improve efficiency?
This code is called each frame.
void createSpheres()
{
for(int i = 0; i < spheres.size(); i+=6)
{
xc = spheres[i];
yc = spheres[i+1];
zc = spheres[i+2];
xd = spheres[i+3];
yd = spheres[i+4];
zd = spheres[i+5];
if((xc+xd)>= 45 || (xc+xd)<= -45)
{
xd = 0-xd;
}
if((yc+yd)>= 9.5 || (yc+yd)<= -9.5)
{
yd = 0-yd;
}
if((zc+zd)>= 45 || (zc+zd)<= -45)
{
zd = 0-zd;
}
glEnable(GL_TEXTURE_2D);
glBindTexture ( GL_TEXTURE_2D, texture_id[6] );
glPushMatrix();
glTranslatef( xc+(xd/10), yc+(yd/10), zc+(zd/10));
glRotatef( -80,1,0,0);
glScalef( 0.10f, 0.10f, 0.10f);
gluQuadricTexture(quadric,1);
gluSphere(quadric,10.0,72,72);
glPopMatrix();
glDisable(GL_TEXTURE_2D);
spheres[i] = xc+(xd/10);
spheres[i+1] = yc+(yd/10);
spheres[i+2] = zc+(zd/10);
spheres[i+3] = xd;
spheres[i+4] = yd;
spheres[i+5] = zd;
}
}