0% found this document useful (0 votes)
4 views3 pages

CG

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

CG

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

//Atharva Pashilkar SE-A COMPS-59

#include<stdio.h>

#include<GL/glut.h>

#define sign(x) ((x>0)?1(x<0)?-1:0))

Int x1,Y1,x2,y2;

Void bres_general()

Int dx, dy, x, y, d, s1, s2, swap=0, temp;

glClearColor(1.0,1.0,1.0,0);

glColor3f(0.0,0.0,0.0);

glOrtho(0,640,0,480,0,480);

dx = abs(x2 – x1);

dy = abs(y2 – Y1);

s1 = sign(x2-x1);

s2 = sign(y2-Y1);

glClear(GL_COLOR_BUFFER_BIT);

if(dy > dx){temp = dx; dx = dy; dy = temp; swap = 1;}

d = 2 * dy – dx;

x = x1;

y = Y1;

glBegin(GL_POINTS);

int i;

for(i = 1; i <= dx; i++)

glVertex2i(x,y);

while(d >= 0)

If(swap) x = x + s1;
Else

Y = y + s2;

D = d – 2* dx;

If(swap) y = y + s2;

Else x = x + s1;

D = d + 2 * dy;

glEnd();

glFlush();

Void init() {

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

glutInitWindowPosition(200,200);

glutInitWindowSize(780, 640);

glutCreateWindow(“Bresenham Line”);

Int main(int argc, char **argv)

Printf(“\n Enter the first vertex coordinates”);

Scanf(“%d%d”,&x1,&Y1);

Printf(“\n Enter the second vertex coordinates”);

Scanf(“%d%d”,&x2,&y2);

glutInit(&argc, argv);

init();

glutDisplayFunc(bres_general);

glutMainLoop();
return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy