I'm working on opengl c++ and tried to make a code for rendering random polygons on an terminal. I'm using CodeBlocks 13.12.
int width=800;
int height=600;
void RandomPolygons()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
GLint x[100],y[100],n,r,g,b;
GLint i,j;
cout<<"Enter the sides of the polygon to be displayed:"<<endl;
cin>>n;
for(i=1;i<=n;i++)
{
x[i]=rand()%800;
cout<<"x["<<i<<"]= "<<x[i]<<endl;
y[i]=rand()%600;
cout<<"y["<<i<<"]= "<<y[i]<<endl;
}
x[i]=x[1];
cout<<"x["<<i<<"]= "<<x[i]<<endl;
y[i]=y[1];
cout<<"y["<<i<<"]= "<<y[i]<<endl;
r=rand()%2;
g=rand()%2;
b=rand()%2;
glColor3f(r,g,b);
glBegin(GL_POLYGON);
for(j=1;j<=n;j++)
{
glVertex2i(x[j],y[j]);
}
glVertex2i(x[j],y[j]);
glEnd();
glFlush();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DEPTH|GLUT_RGBA|GLUT_DOUBLE);
glutInitWindowSize(width,height);
glutInitWindowPosition(100,100);
glutCreateWindow("Random_Polygons!!!!");
glClearColor(0,0,0,0);
gluOrtho2D(0,800,0,600);
glutDisplayFunc(RandomPolygons);
glutIdleFunc(RandomPolygons);
glutMainLoop();
}
output
It's just not responding(Rendering screen) and on the other hand terminal is working fine....