Jump to content
  • Advertisement
Sign in to follow this  
Staticsoul

OpenGL OpenGL speedup

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Staticsoul
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


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

Share this post


Link to post
Share on other sites
Quote:
Original post by deadstar
This 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);
glutSolidSphere(vectSpheresHost.radius,20,20);
glPopMatrix();


}


glPopMatrix();

glutSwapBuffers();

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by deadstar
Also, 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 this post


Link to post
Share on other sites
thanks to all for the replies!


Quote:
Original post by dwahler
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.



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 this post


Link to post
Share on other sites
thanks to all for the replies!


Quote:
Original post by dwahler
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.



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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!