WAP for DDA
#include<GL/glut.h>
#include<stdio.h>
#include<stdlib.h>
void plot(int xa,int ya,int xb, int yb)
{
int dx=xb-xa;
int dy=yb-ya;
int steps,k;
float xIncrement,yIncrement;
float x=xa,y=ya;
glPointSize(5);
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 0.0);
if(abs(dx)>abs(dy))
steps=abs(dx);
else
steps=abs(dy);
xIncrement=dx/(float)steps;
yIncrement=dy/(float)steps;
glBegin(GL_POINTS);
glVertex2i(x,y);
for(k=0;k<steps;k++)
{
x+=xIncrement;
y+=yIncrement;
glVertex2i(x,y);
}
glEnd();
glFlush();
}
void init()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-10,10,-10,10);
}
void disp()
{
plot(0,0,6,4); // End points of line(x0,y0,x1,y1)
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_SINGLE);
glutInitWindowSize(100,100);
glutCreateWindow("Point");
init();
glutDisplayFunc(disp);
glutMainLoop();
return 0;
}
#include<stdio.h>
#include<stdlib.h>
void plot(int xa,int ya,int xb, int yb)
{
int dx=xb-xa;
int dy=yb-ya;
int steps,k;
float xIncrement,yIncrement;
float x=xa,y=ya;
glPointSize(5);
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 0.0);
if(abs(dx)>abs(dy))
steps=abs(dx);
else
steps=abs(dy);
xIncrement=dx/(float)steps;
yIncrement=dy/(float)steps;
glBegin(GL_POINTS);
glVertex2i(x,y);
for(k=0;k<steps;k++)
{
x+=xIncrement;
y+=yIncrement;
glVertex2i(x,y);
}
glEnd();
glFlush();
}
void init()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-10,10,-10,10);
}
void disp()
{
plot(0,0,6,4); // End points of line(x0,y0,x1,y1)
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_SINGLE);
glutInitWindowSize(100,100);
glutCreateWindow("Point");
init();
glutDisplayFunc(disp);
glutMainLoop();
return 0;
}