I tried to continously decrease the sphere radius using a loop, but it does not seem to work.The animation for increasing sphere size is working fine.
Not able to understand why decreasing radius is not rendered.
I request anyone to share any sample code that can help to smoothly animate the same.
Thank You.
What I have tried:
#include<windows.h>
#include<GL/glut.h>
int r=1,flag=0;
void drawSphere(int r1)
{
glutSolidSphere(r1,30,30);
glFlush();
}
void displaySolid()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(1,0,0);
drawSphere(100);
glFlush();
}
void animate(int btn,int state,int x,int y)
{
if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
{
for(r=200;r<400;r+=3)
{
drawSphere(r);
Sleep(100);
flag=1;
}
r=100;
}
if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
{
for(r=60;r>=30;r--)
{
drawSphere(r);
Sleep(100);
}
}
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(700,700);
glutInitWindowPosition(0,0);
glutCreateWindow("sphere test");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-500,500,-500,500,-500,500);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glutDisplayFunc(displaySolid);
glutMouseFunc(animate);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
return 0;
}