Possible Duplicate:
Changing projection in OpenGL
I want to find a way to keep the same size of the object. I have this square which moves from upper left to right bottom of screen. When I resize the output window the size of the square increases as well.
Below is my display and reshape function.
void Changesize(int w,int h)
{
ww=w;
wh=h;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity() ;
glMatrixMode(GL_MODELVIEW);
}
void display(void)
{
printf("i=%f & j=%f \n",i,j);
glClear (GL_COLOR_BUFFER_BIT);
glColor3i (rand(), rand(), rand());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
glBegin(GL_POLYGON);
glColor3i (rand(), rand(), rand());
glVertex3f (i, j-0.125, 0.0);
glVertex3f (i+0.125, j-0.125, 0.0);
glVertex3f (i+0.125, j , 0.0);
glVertex3f (i, j, 0.0);
glEnd();
glFlush ();
usleep(100000);
i=i+0.0125;
j=j-0.0125;
if (i>0.999999)
{
i=0;
j=1;
}
glutSwapBuffers();
glutPostRedisplay();
}
Give this a shot: