Hi
I try to write something to show rotation, but I cannot understand why the whole rotating process is repeated again and again when I run the project.
I run it on Windows using codeblocks. Can anyone please help me?
Here is my code:
#include <GL/glut.h>
#include <stdlib.h>
#include <Windows.h>
void init (void)
{
glClearColor (1.0, 1.0, 1.0, 0.0);
glMatrixMode (GL_PROJECTION);
gluOrtho2D (-5.0, 5.0, -5.0, 5.0);
glMatrixMode (GL_MODELVIEW);
}
void drawSquare(void)
{
glBegin (GL_POLYGON);
glVertex2f (-1.0f,-1.0f);
glVertex2f (1.0f,-1.0f);
glVertex2f (1.0f, 1.0f);
// glVertex2f (0.0f, 1.2f);
glVertex2f (-1.0f,1.0f);
glEnd ( );
}
void rotate()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glColor3f(1.0, 0.0, 0.0);
drawSquare();
glFlush();
Sleep(1000);
glClear(GL_COLOR_BUFFER_BIT);
for(int i = 0; i < 30; i++)
{
glTranslatef(2.0 / 30, 3.0 / 30, 0.0);
glRotatef(1, 0.0, 0.0, 1.0);
glColor3f(0.0, 1.0, 0.0);
drawSquare();
glFlush();
Sleep(100);
glClear(GL_COLOR_BUFFER_BIT);
}
}
int main (int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition (100, 100);
glutInitWindowSize (600, 600);
glutCreateWindow ("Geometrical Transfromation");
init();
glutDisplayFunc (rotate);
glutMainLoop ( );
}