Line Function in Opengl

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Computer Graphics (SEng 4103)

Lab-2: Line functions in OpenGL


#include <GL/glut.h>
void myInit(void) {
glClearColor(1.0, 1.0,1.0, 1.0); // white background
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}

void display(void) glLineWidth(2.0);


{ glBegin(GL_LINE_LOOP);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 1.0, 0.0);
GLint p1[] = {200, 100};
GLint p2[] = {50, 0}; glVertex2i(300, 200);
GLint p3[] = {100, 200}; glColor3f(1.0, 1.0, 0.0);
GLint p4[] = {150, 0};
glVertex2i(300, 50);
GLint p5[] = {0, 100};
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINES);
glVertex2i(500, 50);
glColor3f(1.0, 0, 0); //red
glVertex2i(200, 350); glEnd( );
glVertex2i(50, 250);
glVertex2i(100, 450); glFlush( ); // send all output to the display
glVertex2i(150, 250); }
glVertex2i(0, 350);
glEnd( ); int main(int argc, char *argv[ ])
{
glBegin(GL_LINE_STRIP); glutInit(&argc, argv);
glColor3f(0, 1.0, 0); //green glutInitWindowSize(640, 480);
glVertex2i(450, 250); glutInitWindowPosition(10, 10);
glVertex2i(300, 150);
glVertex2i(350, 350); glutCreateWindow("Basic primitives");
glVertex2i(400, 150); glutDisplayFunc(display);
glVertex2i(250, 250); myInit( );
glEnd();
glutMainLoop( );
}
glLineWidth(4.0);
glBegin(GL_LINE_LOOP);
glColor3f(0, 0, 1.0); //blue
glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p3);
glVertex2iv(p4);
glVertex2iv(p5);
glEnd( );

You might also like