Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Assignment

Course Code: 422


Course Title: Computer Graphics Lab

Submitted To:
Name: Mst. Israt Jahan
Lecture
Department of CSE
Daffodil International University

Submitted By:
Name: Monjur Hasan Milton
ID:171-15-9220
Section: O-7
Bresem

#include<windows.h>
#include<GL/glut.h>
#include <GL/gl.h>
#include<stdlib.h>
#include<stdio.h>>
float x1, y1, x2, y2;
void display (void)
{
float x,y,dx, dy, pk, step,i,Xinc,Yinc;
dx=x2-x1;
dy=y2-y1;
pk = 2*dy-dx;
x=x1;
y=y1;
glBegin(GL_POINT);
glVertex2i(x,y);
glEnd();
for (i=1;i<=dx;i++)
{
if(pk<0)
{
x++;
pk=pk+2*dy;
}
else
{
x++;
y++;
pk=pk+2*(dy-dx);
}
glBegin(GL_POINTS);
glVertex2i(x,y);
printf("%.2lf % .2lf\n",x,y);
glEnd();
}
glutSwapBuffers();
}
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
gluOrtho2D(-500,500,-400,400);
}
int main(int argc, char** argv)
{
printf(" x1: ");
scanf("%f",&x1);
printf(" y1: ");
scanf("%f",&y1);
printf(" x2: ");
scanf("%f",&x2);
printf(" y2: ");
scanf("%f",&y2);
glutInit(&argc, argv);
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE );
glutInitWindowSize (1000, 800);
glutInitWindowPosition (0, 0);
glutCreateWindow ("Milton");
init ();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

DDA
#include <windows.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <stdlib.h>
#include <stdio.h>

float x1, y1, x2, y2;


void display (void)
{
float x,y,dx, dy, step,i,Xinc,Yinc;

dx=x2-x1;
dy=y2-y1;

if (abs(dx)>= abs(dy))
{
step=abs(dx);}
else
{
step=abs(dy);
}

Xinc=dx/step;
Yinc=dy/step;

x=x1;
y=y1;

glBegin(GL_POINT);
glVertex2i(x,y);
glEnd();

for (i=1;i<=step;i++)
{
x=x+Xinc;
y=y+Yinc;
glBegin(GL_POINTS);
glVertex2i(x,y);
printf("%.2lf % .2lf\n",x,y);
glEnd();
}

glutSwapBuffers();
}
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);

glOrtho(0.0,100.0,0.0,100,0.0,100.0);
}

int main(int argc, char** argv)


{

printf(" x1: ");


scanf("%f",&x1);

printf(" y1: ");


scanf("%f",&y1);

printf(" x2: ");


scanf("%f",&x2);

printf(" y2: ");


scanf("%f",&y2);

glutInit(&argc, argv);
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE );
glutInitWindowSize (100, 100);
glutInitWindowPosition (100, 100);
glutCreateWindow ("DDA ");
init ();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

You might also like