Wednesday, 6 November 2013

DDA Line Drawing Algorithm using OPEN GL | Computer Graphics Lab Manual | Anna University Chennai | Final Year IT Department




11:PROGRAM:

#include
#include
#include
inline GLint round(const GLfloat a)
{
            return GLint (a+0.5);
}
void init(void)
{
            glClearColor(1.0,1.0,1.0,0.0);
            glMatrixMode(GL_PROJECTION);
            gluOrtho2D(0.0,300.0,0.0,300.0);
}
void setPixel(GLint xCoord,GLint yCoord)
{
            glBegin(GL_POINTS);
            glVertex2i(xCoord,yCoord);
            glEnd();
            glFlush();
}
void lineDDA(GLint x0,GLint y0,GLint xend,GLint yend)
{
            GLint dx=xend-x0;
            GLint dy=yend-y0;
            GLint steps,k;
            GLfloat xIncrement,yIncrement,x=x0,y=y0;
            if(fabs(dx)>fabs(dy))
                        steps=fabs(dx);
            else
                        steps=fabs(dy);
            xIncrement=GLfloat(dx)/GLfloat(steps);
            yIncrement=GLfloat(dy)/GLfloat(steps);
            setPixel(round(x),round(y));
            for(k=0;k
            {
                        x+=xIncrement;
                        y+=yIncrement;
                        setPixel(round(x),round(y));
            }
}
void drawMyLine(void)
{
            glClear(GL_COLOR_BUFFER_BIT);
            glColor3f(1.0,0.0,0.0);
            glPointSize(4.0);
            GLint x0=100;
            GLint y0=100;
            GLint xend=200;
            GLint yend=200;
            lineDDA(x0,y0,xend,yend);
}
void main(int argc,char** argv)
{
            glutInit(&argc,argv);
            glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
            glutInitWindowSize(500,500);
            glutInitWindowPosition(0,0);
            glutCreateWindow("DDA algorithm");
            init();
            glutDisplayFunc(drawMyLine);
            glutMainLoop();
}


No comments:

Don't You Think this Awesome Post should be shared ??
| DDA Line Drawing Algorithm using OPEN GL | Computer Graphics Lab Manual | Anna University Chennai | Final Year IT Department |
Back To Top Related Posts Plugin for WordPress, Blogger...