c++openglline

How to draw line in OpenGL?


I want to draw a line in OpenGL.

glBegin(GL_LINES);
    glVertex2f(.25,0.25);
    glVertex2f(.75,.75);
glEnd();

This code draws the line, but if I want to draw a line from coordinate (10,10) to coordinate (20,20) what should I do?

What do (.25, .25) and (.75, .75) mean?


Solution

  • (.25, .25) and (.75,.75) are line's start and end point.

    To draw a line from (10,10) to (20,20):

    glBegin(GL_LINES);
        glVertex2f(10, 10);
        glVertex2f(20, 20);
    glEnd();