iam trying to draw a rectangle in a window. In the following code. The following code does the job, but when i uncomment the commented line, the drawn rectangle changes in size(almost disappears). Can somebody explain whats happening ?
#include<GL/glut.h>
#include<GL/gl.h>
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT);
// glOrtho(-100,100,-100,100,-1,1);
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex3f(-25.0,25.0,0.0);
glVertex3f(25.0,25.0,0.0);
glVertex3f(25.0,-25.0,0.0);
glVertex3f(-25.0,-25.0,0.0);
glEnd();
glFlush();
}
void ChangeSize(GLsizei w,GLsizei h)
{
GLfloat aspectRatio;
if(h==0)
h=1;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
aspectRatio=(GLfloat)w/(GLfloat)h;
if(w<h)
glOrtho(-100.0,100.0,-100.0/aspectRatio,100.0/aspectRatio,1.0,-1.0);
else
glOrtho(-100.0*aspectRatio,100.0*aspectRatio,-100.0,100.0,1.0,-1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void SetupRC(void)
{
glClearColor(0.0,0.0,0.0,0.0);
}
int main(int argc,char* argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
glutInitWindowSize(200,200);
glutCreateWindow(“test”);
SetupRC();
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
glutMainLoop();
return 0;
}
Best,
Pradeep