Created
October 7, 2017 17:46
-
-
Save monir-zaman/de986da9954488f12a5315f6c1e1b8bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef __APPLE__ | |
#include <GLUT/glut.h> | |
#else | |
#include <GL/glut.h> | |
#endif | |
#include <bits/stdc++.h> | |
using namespace std; | |
void initialize() | |
{ | |
glClearColor(0.0, 0.0, 0.0, 1.0); | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
gluOrtho2D (0.0, 640.0, 0.0, 480.0); | |
} | |
void BCDA() | |
{ | |
double xCenter = 300 ; | |
double yCenter = 200; | |
double radius = 100; | |
double x = 0; | |
double y = radius; | |
double d = 3 - 2*radius;//5/4 is rounded to 1 for integer radius | |
glBegin(GL_POINTS); | |
glColor3f(1.0, 0.0, 0.0); | |
glVertex2i(xCenter,yCenter); | |
glEnd(); | |
glColor3f(0.0, 1.0, 0.0); | |
while(x <= y) // iterates to draw the first sector | |
{ | |
x++; | |
if(d < 0){// the mid point is inside the circle | |
d = d + 4*x + 6; | |
} | |
else // the mid point is outside or at the circle | |
{ | |
y--; | |
d = d + 4*(x - y) + 10; | |
} | |
glBegin(GL_POINTS); | |
glVertex2i(xCenter + x, yCenter + y); | |
glVertex2i(xCenter - x, yCenter + y); | |
glVertex2i(xCenter + x, yCenter - y); | |
glVertex2i(xCenter - x, yCenter - y); | |
glVertex2i(xCenter + y, yCenter + x); | |
glVertex2i(xCenter - y, yCenter + x); | |
glVertex2i(xCenter + y, yCenter - x); | |
glVertex2i(xCenter - y, yCenter - x); | |
glEnd(); | |
} | |
} | |
void draw() | |
{ | |
glClear(GL_COLOR_BUFFER_BIT); | |
glColor3f(1.0, 10.0, 20.0); | |
double sz = 2; | |
//cin >> sz; | |
glPointSize(sz); | |
BCDA(); | |
glFlush(); // send all output to the display | |
} | |
int main(int argc, char** argv) | |
{ | |
glutInit(&argc, argv); | |
glutInitWindowSize(2000, 2000); // set the size of the window | |
glutInitWindowPosition(0, 0); // the position of the top-left of window | |
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); | |
glutCreateWindow("Bresenham ’s Line Drawing Algorithm"); | |
initialize(); | |
glutDisplayFunc(draw); // set the gl display callback function | |
glutMainLoop(); // enter the GL event loop | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment