Home > Mobile >  Line Not Showing
Line Not Showing

Time:04-25

I have written this code for displaying the line segment but I am not able to understand why the line is not getting displayed. Can someone please help?

#include<GL/glut.h>
#include<iostream>
void init()
{
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glMatrixMode(GL_PROJECTION);
    gluOrtho2D(0.0, 200.0, 0.0, 150.0);
}
void line_segment()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 0.0, 0.0);
    glBegin(GL_LINE);
    glVertex2i(180, 15);
    glVertex2i(10, 145);
    glEnd();
    glFlush();
}
void main(int argc, char** argv)
{
    glutInit(&argc, argv);
    // optional
    glutInitWindowSize(400, 300);
    glutInitWindowPosition(50, 100);
    // Till here
    glutCreateWindow("Window.....");
    init();
    glutDisplayFunc(line_segment);
    // without infinite loop window onl displayed for a very short time
    glutMainLoop();

}

OUTPUT

CodePudding user response:

GL_LINE is not a valid line primitive type. GL_LINE is a polygon mode (see glPolygonMode). The primitive type you want to use is GL_LINES:

glBegin(GL_LINE);

glBegin(GL_LINES);
  • Related