Hi there, thanks for clicking into a beginner’s post.
I think this question is simple for you guys. But it really stuck me for a while. Here is the scenario,
I want to draw polygon in my scene.
Below is the simple program for that. i could’t identify the error?
Can any one help me in this?
#include<GL/glut.h>
//#include<Windows.h> // first include Windows.h header file which is required
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
// Init_OpenGL() function
void Init_OpenGL()
{
glClearColor(1, 1, 1, 1);
// load the identity of matrix by clearing it.
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0, 1000, 0, 1000);
glMatrixMode(GL_MODELVIEW);
}
void polyGon() {
/*glMatrixMode(GL_MODELVIEW);
glLoadIdentity();*/
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glVertex2d(100, 100);
glVertex2d(200, 100);
glVertex2d(200, 200);
glVertex2d(150, 250);
glVertex2d(100, 200);
glEnd;
glFlush();
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);// clearing the window or remove all drawn objects
glColor3f(1.0, 0.0, 0.0);
//glutDisplayFunc(polyGon);
/*lineSegment();*/
polyGon();
glutSwapBuffers(); //redraws the windoew and completes itn finite time
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);// initialize glut
glutInitWindowPosition(50, 50);// set window location
glutInitWindowSize(700, 500);// set window size
glutCreateWindow("Draw polyGon");
Init_OpenGL();// call Init_OpenGL() function
glutDisplayFunc(display);// call glutDisplayFunc() function & pass parameter as display() function
glutMainLoop();//glutMainLoop() is used to redisplay the objects
return 0;
}