0
//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!

2
Contributors
1
Reply
4
Views
2 Years
Discussion Span
Last Post by rubberman
0

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.

Edited by rubberman

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.