100% found this document useful (1 vote)
93 views

Line Function in Opengl

This document discusses drawing different types of lines in OpenGL including lines, line strips, and line loops. It defines functions for initialization and drawing, sets the background color and projection, and draws various colored lines of different widths by specifying vertices and line types. The code samples show how to draw red, green, and blue lines individually as well as in connected line strips and closed line loops.

Uploaded by

Yibel Gashu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
93 views

Line Function in Opengl

This document discusses drawing different types of lines in OpenGL including lines, line strips, and line loops. It defines functions for initialization and drawing, sets the background color and projection, and draws various colored lines of different widths by specifying vertices and line types. The code samples show how to draw red, green, and blue lines individually as well as in connected line strips and closed line loops.

Uploaded by

Yibel Gashu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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