Hi guys,
i’m a newbie in OpenGl. I am trying to render a scene(essentially just a flat polygon square) using perspective projection. I am using gluPerspective() after loading the projection matrix. And using the gluLookAt() after the model view matrix. I just cant figure out why the polygon is not getting rendered. Please guys, tell me know what is wrong with my code.
The following is my code…
GLdouble WindowWidth ;
GLdouble WindowHeight ;
void Init()
{
glShadeModel(GL_SMOOTH) ;
glClearDepth(1.0f) ;
glEnable(GL_DEPTH_TEST) ;
glDisable(GL_CULL_FACE) ;
glFrontFace(GL_CCW) ;
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glClearColor(0.5f , 0.5f , 0.5f , 1.0f) ;
}
void ReShape(int Width , int Height)
{
WindowWidth = (GLdouble)Width ;
WindowHeight = (GLdouble)Height ;
if(Height == 0)
Height = 1 ;
glMatrixMode(GL_PROJECTION) ;
glLoadIdentity() ;
glViewport(0 , 0 , (GLsizei)Width , (GLsizei)Height) ;
gluPerspective(60.0 , (WindowWidth / WindowHeight) , 1.0f , 20.0f) ;
glMatrixMode(GL_MODELVIEW) ;
glLoadIdentity() ;
gluLookAt(0.0f , 0.0f , -5.0f , 2.0f , 2.0f , 0.0f , 0.0f , 1.0f , 0.0f) ;
}
void RenderScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
// gluLookAt(0.0f , 0.0f , -5.0f , 2.0f , 2.0f , 0.0f , 0.0f , 1.0f , 0.0f) ;
glTranslatef(0.0f , 0.0f , 0.0f) ;
glColor3f(0.1f , 0.2f , 0.5f) ;
glBegin(GL_POLYGON) ;
glVertex3f(1.0f , 0.0f , 0.0f) ;
glVertex3f(1.0f , 4.0f , 0.0f) ;
glVertex3f(5.0f , 4.0f , 0.0f) ;
glVertex3f(5.0f , 0.0f , 0.0f) ;
glEnd() ;
glFlush() ;
glutSwapBuffers() ;
}
void main()
{
glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA | GLUT_SINGLE) ;
glutCreateWindow(“Hello”) ;
glutInitWindowPosition(100 , 100) ;
glutInitWindowSize(500 , 500) ;
Init() ;
glutDisplayFunc(RenderScene) ;
glutReshapeFunc(ReShape) ;
glutMainLoop() ;
}
thanx in advance
yours
Siddharth