why the glRoatatef() is so slow???
I render about 500 solidsphere by using glutSolidSphere(1.0,30.0,30.0)
after that, I made mouse callback function to rotate 500 spheres using mouse drag,,,,,,but you know,its ssssoooo slow my computer,Im using AMD 1.5G.
I want to do more faster glRotatef(),..please reply me...=!
Are you absolutely sure it''s glRotate that''s causing the slowdown, and not the mouse callback? Post some code.
yeah,,maybe the mouse callback cause slow...but I think
sin(),cos() calculation also makes slow,,, im not sure..
source code like that.....
/*----------------------------------------------------------
Mouse callback function
----------------------------------------------------------*/
static void Opengl_Rotation(int x,int y)
{
xx=x-prex;
yy=y-prey;
MainCtrlRam.xrot=(float)yy/5;
MainCtrlRam.yrot=(float)xx/5;
prex=x;
prey=y;
rotx_mat(m_matModel, MainCtrlRam.xrot/1000);
roty_mat(m_matModel, MainCtrlRam.yrot/1000);
glutPostRedisplay();
}
void MouseCtrl(int button,int state,int x,int y)
{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN){
prex=x;
prey=y;
glutMotionFunc(Opengl_Rotation);
}
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef(yrot,0.0,1.0,0.0);
glRotatef(xrot,1.0,0.0,0.0);
DrawClassRam.main(); // render 500 solidspheres,,
glutSwapBuffers();
}
sin(),cos() calculation also makes slow,,, im not sure..
source code like that.....
/*----------------------------------------------------------
Mouse callback function
----------------------------------------------------------*/
static void Opengl_Rotation(int x,int y)
{
xx=x-prex;
yy=y-prey;
MainCtrlRam.xrot=(float)yy/5;
MainCtrlRam.yrot=(float)xx/5;
prex=x;
prey=y;
rotx_mat(m_matModel, MainCtrlRam.xrot/1000);
roty_mat(m_matModel, MainCtrlRam.yrot/1000);
glutPostRedisplay();
}
void MouseCtrl(int button,int state,int x,int y)
{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN){
prex=x;
prey=y;
glutMotionFunc(Opengl_Rotation);
}
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef(yrot,0.0,1.0,0.0);
glRotatef(xrot,1.0,0.0,0.0);
DrawClassRam.main(); // render 500 solidspheres,,
glutSwapBuffers();
}
Your code doesn''t say much. Comment out small parts of the code, for exeample two calls to glRotate, the mouse callbacks, those rot_mat-functions, and try to identify what is causing it.
did i catch that within that one function you are rendering 500 seperate spheres in OGL? i am sorry, but no matter how fast your comp is, rendering 500 spheres is going to take a LOT of processor time. That is most likely the problem, not glRotatef(), which is usually VERY fast. Try cutting down on the amount of spheres you render by maybe taking a picture of one sphere(pre-compilation), saving it to a bitmap (using PrntScrn and Photo editor), and then rendering 500 seperate particles using 1 picture of a sphere. 30 stacks by 30 slices by 500 spheres= 450,000 polys! instead, you could have 1 poly per particle * 500 particles = 500 polys. Much Faster!
I could be totally off base, but i tried, so good luck
I could be totally off base, but i tried, so good luck
Thanks Steve132 !! I will try what you said..
I just wanted to make a some kind of molecule 3d simulation using opengl. you know, some molecule has about 500 atoms!! thats why I asked.
I just wanted to make a some kind of molecule 3d simulation using opengl. you know, some molecule has about 500 atoms!! thats why I asked.
Sorry, but 30 rows by 30 columns by 500 spheres is 900 000 triangles, not 450 000.
With that amount of triangles, most of your CPU time is probably spent in glutSolidSphere itself. Have you tried profiling it? Did you put it in a display list, to avoid having the CPU recomputing each sphere each frame?
In any case your bottleneck certainly has NOTHING to do with glRotatef.
Y.
With that amount of triangles, most of your CPU time is probably spent in glutSolidSphere itself. Have you tried profiling it? Did you put it in a display list, to avoid having the CPU recomputing each sphere each frame?
In any case your bottleneck certainly has NOTHING to do with glRotatef.
Y.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement