Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

OpenGL program to draw a line

Below is the simple OpenGL Computer Graphics Program to draw Line. This is very basic OpenGL program, You can compare this with C "Hello World" program.

voidglClearColor(GLclampf red,  GLclampf green,  GLclampf blue, GLclampf alpha);
// It specifies value to clear color buffer.

voidglMatrixMode(GLenum mode);
// Initialize current matrix

void gluOrtho2D(GLdouble left, GLdouble right,  GLdouble bottom,  GLdouble top);
// Used to define orthographic projection of 2D matrix

voidglClear(GLbitfield  mask);
// clear preset values of buffer

voidglColor3f(colR,colG,colB);
//set colour

void glBegin(GLenum  mode);
//  delimit the vertices of a primitive or a group of like primitives

void glBegin(GLenum  mode);
//  delimit the vertices of a primitive or a group of like primitives 

void glEnd( void);
// delimit the vertices of a primitive or a group of like primitives

voidglutInitDisplayMode(unsigned int mode); 
// Used to set initial display mode. 

voidglutInitWindowSize(int width, int height); 
//it sets the size of window and position of window. 

void glutInitWindowPosition(int x, int y);
//initalize window size
voidglutDisplayFunc(void (*func)(void)); 
// it sets display callback for current window

OpenGL C Program to draw Line:
Title#include

void initialize2D( float r, float g, float b)
{
    glClearColor(r,g,b,0.0);
    glMatrixMode (GL_PROJECTION);
    gluOrtho2D (0.0, 205.0, 0.0, 155.0);
}

void displayLine(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 0.0, 0.0);

    glBegin(GL_POINTS);
    for(int j = 0; j     {
        glVertex2i(10+5*j,110);
    }
    glEnd();

    glBegin(GL_LINES);
        glVertex2i(10,10);
        glVertex2i(100,100);
    glEnd();

    glFlush();
}

void main(int iargc,char *iargv[])
{
    glutInit(&iargc,iargv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // initialize Display Mode
    glutInitWindowSize (500, 500); // initialize window size
    glutInitWindowPosition (100, 100); // initialize window position
    glutCreateWindow ("points and lines");
    initialize2D(0.0,0.0,0.0);
    glutDisplayFunc(displayLine); // call displayLine() function
    glutMainLoop();
}



This post first appeared on Ask For Program, please read the originial post: here

Share the post

OpenGL program to draw a line

×

Subscribe to Ask For Program

Get updates delivered right to your inbox!

Thank you for your subscription

×