Could anybody help me with my code, please? It’s not displaying the triangle. I can’t figure out what have I left or have written wrong in it.
Here’s the code :
#include <GL/freeglut.h>
void reclear()
{
glClearColor(DEF_WHITE, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
}
/* Called every single frame */
void display()
{
reclear();
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(-1.0,-1.0, 0.0);
glVertex3f(0.0,1.0,0.0);
glVertex3f(1.0, -1.0, 0.0);
glEnd();
glutSwapBuffers();
}
/* Called whenever the window's dimensions change */
void reshape(int w, int h)
{
float w2h = (h>0)? (double)w/h: 1;
glViewport(0, 0, w, h);
}
/* Called when there's no interaction with the window and the event queue is empty */
void idle()
{
display();
}
void initDisplay(int *argc, char **argv, int width, int height)
{
glutInit(argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(width, height);
glutCreateWindow("Project L3");
glViewport(0, 0, width, height);
}
int main(int argc, char** argv)
{
initDisplay(&argc, argv, WIDTH, HEIGHT);
glutDisplayFunc(display);
glutIdleFunc(idle);
glutReshapeFunc(reshape);
glutMainLoop();
}