0% found this document useful (0 votes)
20 views2 pages

Dda

This document contains a C++ program that uses OpenGL and GLUT to draw lines using the Digital Differential Analyzer (DDA) algorithm. It initializes a window and displays lines between specified coordinates, with color and point size settings. The program sets up the OpenGL environment and enters the main loop to render the graphics.

Uploaded by

sd.nath13158
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

Dda

This document contains a C++ program that uses OpenGL and GLUT to draw lines using the Digital Differential Analyzer (DDA) algorithm. It initializes a window and displays lines between specified coordinates, with color and point size settings. The program sets up the OpenGL environment and enters the main loop to render the graphics.

Uploaded by

sd.nath13158
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<windows.

h>
#include<GL/glut.h>
#include<stdio.h>
float x,y,x1,y1,x2,y2,dx,dy,m;
void display(float x1,float y1,float x2,float y2)
{
glColor3f(2,2,0);// for yellow color
glPointSize(2);
int i=1;
dx=x2-x1;
dy=y2-y1;
m=dy/dx;
if(m<=1)
{
int step=abs(dx);
x=x1;
y=y1;
while(i<=step)
{
x=x+1;
y=y+m;
glBegin(GL_POINTS);
glVertex2f(x,y);
i++;
}
}
else
{
int step=abs(dy);
x=x1;
y=y1;

while(i<=step)
{
x=x+(1/m);
y=y+1;
i++;
glBegin(GL_POINTS);
glVertex2f(x,y);
}
}
glEnd();
glFlush();
}
void init(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0,0,0,0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-100,100,-100,100);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("DDA");
init();
glutDisplayFunc([]()
{
display(0,0,20,0);
display(20,0,20,20);
display(0,20,20,20);
display(0,-1,0,20);

});
glutMainLoop();
return 0;
}

You might also like