//Program to implement Basic Incremental Algorithm
    //Working on ubuntu
  #include <GL/glut.h>
  #include<stdlib.h>
  #include <stdio.h>

   GLfloat x0,x1,y0,y1; //Input variables taken as global 
   int flag=1;   //variable for display1()
   void init(void)
    {
         glClearColor(0.0,0.0,0.0,0.0);
         glMatrixMode(GL_PROJECTION);
         glLoadIdentity();
         gluOrtho2D(0.0,500.0,0.0,500.0);
    }
    void PutPixel(GLfloat x,GLfloat y)
    {
         glBegin(GL_POINTS);
         glVertex2f(x,y);      //To display pixels on-screen
         glEnd();
         glFlush();
    }
    void display1(void)
    {
         if (flag==1)   
         {
               glClear(GL_COLOR_BUFFER_BIT);
                glColor3f(0.7,1.0,1.0);
                GLfloat m,c,y;
                GLfloat i;                   //BIA algorithm
                m=(y1-y0)/((float)(x1-x0));
                c=y1-m*x1;
                for (i=x0; i<=x1; i+=0.01)
                 {
                      y=c+m*i;
                      PutPixel(i,y);
                  }
                flag++;
          }
     }
     void Input()
     {
        printf("Enter the co-ods\n");
        scanf("%f %f",&x0,&y0);
        scanf("%f %f",&x1,&y1);
     }
     int main(int argc, char **argv)
       {
         Input();
         glutInit(&argc,argv);
         glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
         glutInitWindowSize(500,500);
         glutInitWindowPosition(100,100);
         glutCreateWindow("BIA");
         init();
         glutDisplayFunc(display1);
         glutMainLoop();
         return 0;
        }

I have initailaized flag as a global variable in the beginning and set it to 1. flag is used in the display1() to ensure that it executes only once. This is just one way I was trying to ensure that the output gets displayed. Can anyone, please HELP!

After the prompt, how are you inputting the data for the or-ords? Like this?

10 10<enter>
20 20<enter>

Try:

void Input()
{
    printf("Enter the co-ods\n");
    scanf("%f %f %f %f",&x0,&y0,&x1,&y1);
}

with this as input instead: 10 10 20 20<enter> and see if that works. Also, you may need to add a decimal since these are floating point numbers, as in: 10.0 10.0 20.0 20.0<enter>

Note that <enter> above represents pressing the Enter key.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.