All I am trying to do is load up a simple polygon but all I get is a blank screen.
Everything compiles correctly and runs but I just don’t get my polygon coming up.
I have created a window 200 x 300 and created my 2d matrix with the glOrtho2D() function.
#include <stdlib.h>
#include <GL/glut.h>
void myinit(void) // simple initialisation function
{
glClearColor(1.0, 1.0, 1.0, 0.0) ; // sets clearing (background) colour
glMatrixMode(GL_PROJECTION); // Projects the matrix
gluOrtho2D(-8.8, 8.8, -8.8, 8.8); // sets the 2D projection matrix area
}
void polygon(void)
{
glColor3f(1.0,0.0,0.0); // polygon set to red
glBegin(GL_POLYGON);
glVertex2f(0.0, 0.0);
glVertex2f(0.0, 3.0);
glVertex2f(4.0, 3.0);
glVertex2f(6.0, 1.5);
glVertex2f(4.0, 0.0);
glEnd();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
polygon();
//popmatrix()
//pushmatrix()
//translate() //moves the object
//polygon()
//glFlush();
}
main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(200, 300);
glutInitWindowPosition(0,0);
glutCreateWindow(“Assignment 2 polyogon”);
glutDisplayFunc(display);
myinit();
glutMainLoop();
return 0 ;
}
Can you please help as I am struggling to understand why?