-
Notifications
You must be signed in to change notification settings - Fork 1
/
1-BresenhamLineDrawingAlgo.cpp
51 lines (44 loc) · 1.13 KB
/
1-BresenhamLineDrawingAlgo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <windows.h>
#include <gl/glut.h>
#include <iostream>
#include "./openGL-comp/HelperDrawerMethod.h"
#include "./algos/1-BresenhamLineAlgo.h"
using namespace std;
void myInit()
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
gluOrtho2D(0, 500.0, 0, 500.0);
}
void draw_line(int x0, int x1, int y0, int y1)
{
int dX = abs(x1 - x0), dY = abs(y1 - y0);
int offsetX = 250, offsetY = 250; // origin at (250,250)
RGBColor color(0, 0, 0, 1);
bool exchangeCord = true;
if (dX > dY)
{
exchangeCord = false;
}
drawPixels(BresenhamsLineDrawingAlgo(y0, y1, x0, x1), color, offsetX, offsetY, exchangeCord);
}
int x1, x2, uy1, y2;
void myDisplay()
{
draw_line(x1, x2, uy1, y2);
glFlush();
}
int main(int argc, char **argv)
{
cout << "Enter (x1, uy1, x2, y2)\n";
cin >> x1 >> uy1 >> x2 >> y2;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("- Bresenham's Line Drawing -");
myInit();
glutDisplayFunc(myDisplay);
glutMainLoop();
return 0;
}