Ok, so guys, could you please give me some general tips on code structure that can help maximize the speed of my program
Thanks
Saxon
Printable View
Ok, so guys, could you please give me some general tips on code structure that can help maximize the speed of my program
Thanks
Saxon
Ehm, plenty. What's the scenario? Are we talking general optimization or optimizing rendering? Are we talking C/C++ or other languages? Please be more specific when asking quetsitons!
Optimizing rendering..
C++..
An specific problems? You can't optimize unless you know where your bottelnecks are. Premature optimization is the root of all evil and high cholesterol!
No, I have just been playing around with code structure, and I was curious as to whether or not there are actually things that can be done in order to optimize the speed.
Sure you can. But optimization implies are sub-optimal state. Show us some code you wish to optimize.
ok, specifically
in the case of drawing a cube, what is faster, the following code,,
or a loop coupled with an algorithm that can change the the x, y and z variables to the corresponding values.
glBegin( GL_QUADS );
glVertex3f( x, y, z);
glVertex3f(-x, y, z);
glVertex3f(-x,-y, z);
glVertex3f( x,-y, z);
glVertex3f( x, y,-z);
glVertex3f(-x, y,-z);
glVertex3f(-x, y, z);
glVertex3f( x, y, z);
glVertex3f(-x, y,-z);
glVertex3f( x, y,-z);
glVertex3f( x,-y,-z);
glVertex3f(-x,-y,-z);
glVertex3f( x, y,-z);
glVertex3f( x, y, z);
glVertex3f( x,-y, z);
glVertex3f( x,-y,-z);
glVertex3f(-x, y, z);
glVertex3f(-x, y,-z);
glVertex3f(-x,-y,-z);
glVertex3f(-x,-y, z);
glVertex3f( x,-y, z);
glVertex3f(-x,-y, z);
glVertex3f(-x,-y,-z);
glVertex3f( x,-y,-z);
glEnd();
If the compiler unrolls the loop, there isn't a difference at all and in this case it very well might do that. You should check out how to render stuff nowadays. The code you posted is so 1992. It's not that tragic for a cube, but for mesh with a few hundrd or thousand vertices, your current method (called immediate mode) is the slowest possible.