# OpenGL OpenGL speedup

This topic is 3828 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi there! I've using OpenGL for sometime, but I'm no expert yet.... I'm writing a program that render a model using spheres, by using its vertex, the problem is that when I'm using a for cycle to run through an array with the position and the radius of the sphere; and finally use the glutSolidSphere to create the sphere. The problem is each time I rotate the model it is perceptible some slowness on the rendering. If someone could help, I will appreciate it very much.

##### Share on other sites
Quote:
 Original post by Staticsoulthe problem is that when I'm using a for cycle to run through an array with the position and the radius of the sphere

This is slightly confusing, how about a code snippet to clear things up? Post your render function.

##### Share on other sites
Quote:
 Original post by deadstarThis is slightly confusing, how about a code snippet to clear things up? Post your render function.

Sorry, I forgot to put it,

here it goes...

glPushMatrix();

glTranslatef(0.0, 0.0, translate_z);
glRotatef(rotate_x, 1.0, 0.0, 0.0);
glRotatef(rotate_y, 0.0, 1.0, 0.0);

for(int i=0;i<numvertex;i++){

glPushMatrix();
glTranslatef(vectSpheresHost.position.x, vectSpheresHost.position.y, vectSpheresHost.position.z);
glPopMatrix();

}

glPopMatrix();

glutSwapBuffers();

##### Share on other sites
So you're rendering small spheres to represent your vertices?

How big is 'numvertex'? Seems like the pause is while it runs through the loop, you might have to rethink this design.

Also, you don't need push/popmatrix inside the loop.

##### Share on other sites
The slowness comes from the fact that you're recomputing the sphere's geometry over and over again each time through the loop. Not only is this unnecessary computation, it causes a lot of extra data to be sent over the bus to the graphics card. To speed it up, generate the sphere once and store it in a display list or a vertex buffer. You can store a sphere of radius 1 and use glScale to alter the size of each instance.

##### Share on other sites
I have an example on my website showing how to render a sphere without needing to use glutSolidSphere if you are interested.

##### Share on other sites
Quote:
 Original post by deadstarAlso, you don't need push/popmatrix inside the loop.

Why not? He's translating the spheres inside the loop and without glPush/PopMatrix the translations would add up, which I think is not what he wants. [smile]

##### Share on other sites
thanks to all for the replies!

Quote:
 Original post by dwahlerThe slowness comes from the fact that you're recomputing the sphere's geometry over and over again each time through the loop. Not only is this unnecessary computation, it causes a lot of extra data to be sent over the bus to the graphics card. To speed it up, generate the sphere once and store it in a display list or a vertex buffer. You can store a sphere of radius 1 and use glScale to alter the size of each instance.

dwahler, I believe that your solution is the best way to do it, since i've already many programs that use vertex buffer to speed up the rendering.

the problem is, I've never used vertex buffers before, if you know any tutorial please let me know.

##### Share on other sites
thanks to all for the replies!

Quote:
 Original post by dwahlerThe slowness comes from the fact that you're recomputing the sphere's geometry over and over again each time through the loop. Not only is this unnecessary computation, it causes a lot of extra data to be sent over the bus to the graphics card. To speed it up, generate the sphere once and store it in a display list or a vertex buffer. You can store a sphere of radius 1 and use glScale to alter the size of each instance.

dwahler, I believe that your solution is the best way to do it, since i've already many programs that use vertex buffer to speed up the rendering.

the problem is, I've never used vertex buffers before, if someone know any tutorial that covers vertex buffers, and if possible covers spheres representing these method please let me know.

[Edited by - Staticsoul on June 20, 2008 10:43:57 AM]

##### Share on other sites
Opengl has spiffy things called Draw Lists too. You could construct a draw list that only contains the "Draw Sphere" function. After you translate, then fire off the draw list. It should give you noticeable speed increases, how ever it's highly OpwnGL bound.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633709
• Total Posts
3013481
×