Sie sind auf Seite 1von 1

#include<gl/glut.

h>
#include<math.h>
#include<stdio.h>
float X1=50,Y1=70,X2=200,Y2=300;
void lineDDA()
{
float dx=X2-X1,dy=Y2-Y1,steps;
float xinc,yinc,x=X1,y=Y1;
steps=(abs(dx)>abs(dy))?abs(dx):abs(dy);
xinc=dx/steps;
yinc=dy/steps;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
glVertex2d(x,y);
for(int k=0;k<steps;k++)
{
x+=xinc;
y+=yinc;
glVertex2d(x,y);
}
glEnd();
glFlush();
}
void init()
{
glClearColor(0.0,0.0,0.0,0);
glColor3f(1.0,0.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,640,0,480);
}
void main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(0,0);
glutCreateWindow("LINE DDA");
init();
glutDisplayFunc(lineDDA);
glutMainLoop();
}

Das könnte Ihnen auch gefallen