i am writing a code that will rotate the polygon but it seem as if it is not working any help?

#include<iostream>
#include<Gl/glut.h>
#include<cstdlib>
using namespace std;

GLfloat fPent = 0.0; // for rotating pentagon;
GLfloat fSqr = 0.0; // for rotating square;

void handleKeyPress(unsigned char key, int x, int y)
{
		if(key == 26)
			exit(1);
}


 int InitGL(GLvoid)
{
	
	glShadeModel(GL_SMOOTH);//Enable smootheness
	glClearColor(0.0,0.0,0.0,0.5);//Clear any color to black
	glClearDepth(1.0f);//we clear depth.
	glEnable(GL_DEPTH_BUFFER_BIT);//we turn on depthness
	glDepthFunc(GL_LEQUAL);//the type of test we will use for depth test
	glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); // 
	glEnable(GL_COLOR_BUFFER_BIT);//we enable color buffer.
	
	return true;
}

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)	
{
	if(height == 0)
		height = 1;

	glViewport(0, 0, width, height);	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
	
}

void disp()
{
	 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth to what we set it before;
	 glMatrixMode(GL_MODELVIEW);
	 glLoadIdentity();

	glTranslatef(-1.0,0.0f,-6.0f);
	glRotatef(fPent,1.0f,0.0f,0.0f);

	glBegin(GL_TRIANGLES);					// Start Drawing A Triangle
		glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
		glVertex3f( 0.0f, 1.0f, 0.0f);			// First Point Of The Triangle
		glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
		glVertex3f(-1.0f,-1.0f, 0.0f);			// Second Point Of The Triangle
		glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
		glVertex3f( 1.0f,-1.0f, 0.0f);			// Third Point Of The Triangle
	glEnd();

		glLoadIdentity();

		glTranslatef(1.0f,0.0f,1.0f);
		glRotatef(fSqr,1.0f,0.0f,0.0f);

	glBegin(GL_QUADS);
	
		glColor3f(0.0f,0.0f,0.0f);
	glVertex3f(-1.0f, 1.0f, -10.0f);	
		glColor3f(0.0f,1.0f,0.0f);
	glVertex3f( 1.0f, 1.0f, -10.0f);	
		glColor3f(0.0f,0.0f,1.0f);
	glVertex3f( 1.0f,-1.0f, -10.0f);	
		glColor3f(0.6f,0.4f,1.0f);
	glVertex3f(-1.0f,-1.0f, -10.0f);	
		glEnd();

		

		glutSwapBuffers();
		
		fPent += 1.0;
		fSqr -= 0.4;
		

		glFlush();
		
}


int main(int argc,char**argv)
{
		glutInit(&argc,argv);
		glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
		glutInitWindowSize(500,500);
		glutInitWindowPosition(300,100);
		glutCreateWindow("My first polygons with colors and rotations");
		glEnable(GL_DEPTH_TEST);
		glutDisplayFunc(disp);
		glutKeyboardFunc(handleKeyPress);
		glutReshapeFunc(ReSizeGLScene);

		glutMainLoop();

		return 0;
}

you never redisplay the scene, for that kind of animation to work you have to redisplay for every frame.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.