├── DDA
├── bin
│ └── Debug
│ │ └── DDA.exe
├── obj
│ └── Debug
│ │ └── main.o
├── DDA.layout
├── DDA.cbp
├── main.cpp
└── DDA.depend
├── c curve
├── obj
│ └── Debug
│ │ └── main.o
├── bin
│ └── Debug
│ │ └── curve.exe
├── curve.layout
├── curve.cbp
├── main.cpp
└── curve.depend
├── Koch Curve
├── obj
│ └── Debug
│ │ └── main.o
├── Koch2
│ ├── obj
│ │ └── Debug
│ │ │ └── main.o
│ ├── bin
│ │ └── Debug
│ │ │ └── Koch.exe
│ ├── Koch.layout
│ ├── Koch.cbp
│ ├── main.cpp
│ └── Koch.depend
├── bin
│ └── Debug
│ │ └── Koch Curve.exe
├── Koch Curve.layout
├── Koch Curve.cbp
├── main.cpp
└── Koch Curve.depend
├── Line Clipping
├── obj
│ └── Debug
│ │ └── main.o
├── bin
│ └── Debug
│ │ └── Line Clipping.exe
├── Line Clipping.layout
├── Line Clipping.cbp
├── main.cpp
└── Line Clipping.depend
├── Flood FIll Circle
├── obj
│ └── Debug
│ │ └── main.o
├── bin
│ └── Debug
│ │ └── Flood FIll Circle.exe
├── Flood FIll Circle.layout
├── Flood FIll Circle.cbp
├── main.cpp
└── Flood FIll Circle.depend
├── Flood Fill Sqaure
├── obj
│ └── Debug
│ │ └── main.o
├── bin
│ └── Debug
│ │ └── Flood Fill Sqaure.exe
├── Flood Fill Sqaure.layout
├── Flood Fill Sqaure.cbp
├── main.cpp
└── Flood Fill Sqaure.depend
├── Midpoint Ellipse
├── obj
│ └── Debug
│ │ └── main.o
├── bin
│ └── Debug
│ │ └── Midpoint Ellipse.exe
├── Midpoint Ellipse.layout
├── Midpoint Ellipse.cbp
├── main.cpp
└── Midpoint Ellipse.depend
├── Polygon Clipping
├── obj
│ └── Debug
│ │ └── main.o
├── bin
│ └── Debug
│ │ └── Polygon Clipping.exe
├── Polygon Clipping.layout
├── Polygon Clipping.cbp
├── main.cpp
└── Polygon Clipping.depend
├── Bound Fill Algorithm
├── obj
│ └── Debug
│ │ └── main.o
├── bin
│ └── Debug
│ │ └── Bound Fill Algorithm.exe
├── Bound Fill Algorithm.layout
├── Bound Fill Algorithm.cbp
├── main.cpp
└── Bound Fill Algorithm.depend
├── Boundary Fill Circle
├── obj
│ └── Debug
│ │ └── main.o
├── bin
│ └── Debug
│ │ └── Boundary Fill Circle.exe
├── Boundary Fill Circle.layout
├── Boundary Fill Circle.cbp
└── main.cpp
├── Boundary Fill Sqaure
├── obj
│ └── Debug
│ │ └── main.o
├── bin
│ └── Debug
│ │ └── Boundary Fill Sqaure.exe
├── Boundary Fill Sqaure.layout
├── Boundary Fill Sqaure.cbp
├── main.cpp
└── Boundary Fill Sqaure.depend
├── Cubic Bezier Curve
├── obj
│ └── Debug
│ │ └── main.o
├── bin
│ └── Debug
│ │ └── Cubic Bezier Curve.exe
├── Cubic Bezier Curve.layout
├── Cubic Bezier Curve.cbp
├── main.cpp
└── Cubic Bezier Curve.depend
├── Flood Fill Algorithm
├── obj
│ └── Debug
│ │ └── main.o
├── bin
│ └── Debug
│ │ └── Flood Fill Algorithm.exe
├── Flood Fill Algorithm.layout
├── Flood Fill Algorithm.cbp
├── main.cpp
└── Flood Fill Algorithm.depend
├── Bresenham Line Drawing
├── obj
│ └── Debug
│ │ └── main.o
├── bin
│ └── Debug
│ │ └── Bresenham Line Drawing.exe
├── Bresenham Line Drawing.layout
├── Bresenham Line Drawing.cbp
├── main.cpp
└── Bresenham Line Drawing.depend
├── Bresenham Circle Drawing
├── obj
│ └── Debug
│ │ └── main.o
├── bin
│ └── Debug
│ │ └── Bresenham Circle Drawing.exe
├── BCD2
│ ├── BCD.layout
│ ├── main.cpp
│ └── BCD.cbp
├── Bresenham Circle Drawing.layout
├── Bresenham Circle Drawing.cbp
├── main.cpp
└── Bresenham Circle Drawing.depend
├── Midpoint Circle Drawing
├── obj
│ └── Debug
│ │ └── main.o
├── bin
│ └── Debug
│ │ └── Midpoint Circle Drawing.exe
├── Midpoint Circle Drawing.layout
├── Midpoint Circle Drawing.cbp
├── main.cpp
└── Midpoint Circle Drawing.depend
└── LICENSE
/DDA/bin/Debug/DDA.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/DDA/bin/Debug/DDA.exe
--------------------------------------------------------------------------------
/DDA/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/DDA/obj/Debug/main.o
--------------------------------------------------------------------------------
/c curve/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/c curve/obj/Debug/main.o
--------------------------------------------------------------------------------
/Koch Curve/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Koch Curve/obj/Debug/main.o
--------------------------------------------------------------------------------
/c curve/bin/Debug/curve.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/c curve/bin/Debug/curve.exe
--------------------------------------------------------------------------------
/Line Clipping/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Line Clipping/obj/Debug/main.o
--------------------------------------------------------------------------------
/Flood FIll Circle/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Flood FIll Circle/obj/Debug/main.o
--------------------------------------------------------------------------------
/Flood Fill Sqaure/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Flood Fill Sqaure/obj/Debug/main.o
--------------------------------------------------------------------------------
/Koch Curve/Koch2/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Koch Curve/Koch2/obj/Debug/main.o
--------------------------------------------------------------------------------
/Midpoint Ellipse/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Midpoint Ellipse/obj/Debug/main.o
--------------------------------------------------------------------------------
/Polygon Clipping/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Polygon Clipping/obj/Debug/main.o
--------------------------------------------------------------------------------
/Bound Fill Algorithm/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Bound Fill Algorithm/obj/Debug/main.o
--------------------------------------------------------------------------------
/Boundary Fill Circle/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Boundary Fill Circle/obj/Debug/main.o
--------------------------------------------------------------------------------
/Boundary Fill Sqaure/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Boundary Fill Sqaure/obj/Debug/main.o
--------------------------------------------------------------------------------
/Cubic Bezier Curve/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Cubic Bezier Curve/obj/Debug/main.o
--------------------------------------------------------------------------------
/Flood Fill Algorithm/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Flood Fill Algorithm/obj/Debug/main.o
--------------------------------------------------------------------------------
/Koch Curve/Koch2/bin/Debug/Koch.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Koch Curve/Koch2/bin/Debug/Koch.exe
--------------------------------------------------------------------------------
/Koch Curve/bin/Debug/Koch Curve.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Koch Curve/bin/Debug/Koch Curve.exe
--------------------------------------------------------------------------------
/Bresenham Line Drawing/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Bresenham Line Drawing/obj/Debug/main.o
--------------------------------------------------------------------------------
/Bresenham Circle Drawing/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Bresenham Circle Drawing/obj/Debug/main.o
--------------------------------------------------------------------------------
/Line Clipping/bin/Debug/Line Clipping.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Line Clipping/bin/Debug/Line Clipping.exe
--------------------------------------------------------------------------------
/Midpoint Circle Drawing/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Midpoint Circle Drawing/obj/Debug/main.o
--------------------------------------------------------------------------------
/Midpoint Ellipse/bin/Debug/Midpoint Ellipse.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Midpoint Ellipse/bin/Debug/Midpoint Ellipse.exe
--------------------------------------------------------------------------------
/Polygon Clipping/bin/Debug/Polygon Clipping.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Polygon Clipping/bin/Debug/Polygon Clipping.exe
--------------------------------------------------------------------------------
/Flood FIll Circle/bin/Debug/Flood FIll Circle.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Flood FIll Circle/bin/Debug/Flood FIll Circle.exe
--------------------------------------------------------------------------------
/Flood Fill Sqaure/bin/Debug/Flood Fill Sqaure.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Flood Fill Sqaure/bin/Debug/Flood Fill Sqaure.exe
--------------------------------------------------------------------------------
/Cubic Bezier Curve/bin/Debug/Cubic Bezier Curve.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Cubic Bezier Curve/bin/Debug/Cubic Bezier Curve.exe
--------------------------------------------------------------------------------
/Bound Fill Algorithm/bin/Debug/Bound Fill Algorithm.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Bound Fill Algorithm/bin/Debug/Bound Fill Algorithm.exe
--------------------------------------------------------------------------------
/Boundary Fill Circle/bin/Debug/Boundary Fill Circle.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Boundary Fill Circle/bin/Debug/Boundary Fill Circle.exe
--------------------------------------------------------------------------------
/Boundary Fill Sqaure/bin/Debug/Boundary Fill Sqaure.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Boundary Fill Sqaure/bin/Debug/Boundary Fill Sqaure.exe
--------------------------------------------------------------------------------
/Flood Fill Algorithm/bin/Debug/Flood Fill Algorithm.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Flood Fill Algorithm/bin/Debug/Flood Fill Algorithm.exe
--------------------------------------------------------------------------------
/Bresenham Line Drawing/bin/Debug/Bresenham Line Drawing.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Bresenham Line Drawing/bin/Debug/Bresenham Line Drawing.exe
--------------------------------------------------------------------------------
/Midpoint Circle Drawing/bin/Debug/Midpoint Circle Drawing.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Midpoint Circle Drawing/bin/Debug/Midpoint Circle Drawing.exe
--------------------------------------------------------------------------------
/Bresenham Circle Drawing/bin/Debug/Bresenham Circle Drawing.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagar0710/Computer-Graphics-Algorithms/HEAD/Bresenham Circle Drawing/bin/Debug/Bresenham Circle Drawing.exe
--------------------------------------------------------------------------------
/DDA/DDA.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/c curve/curve.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Koch Curve/Koch2/Koch.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Koch Curve/Koch Curve.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Bresenham Circle Drawing/BCD2/BCD.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Line Clipping/Line Clipping.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Polygon Clipping/Polygon Clipping.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Flood FIll Circle/Flood FIll Circle.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Flood Fill Sqaure/Flood Fill Sqaure.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Midpoint Ellipse/Midpoint Ellipse.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Boundary Fill Sqaure/Boundary Fill Sqaure.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Cubic Bezier Curve/Cubic Bezier Curve.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Flood Fill Algorithm/Flood Fill Algorithm.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Bound Fill Algorithm/Bound Fill Algorithm.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Boundary Fill Circle/Boundary Fill Circle.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Bresenham Line Drawing/Bresenham Line Drawing.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Midpoint Circle Drawing/Midpoint Circle Drawing.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Bresenham Circle Drawing/Bresenham Circle Drawing.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Bresenham Circle Drawing/BCD2/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | void drawCircle(int x, int y, int xc, int yc);
5 | void main()
6 | {
7 | int gd = DETECT, gm;
8 | int r, xc, yc, pk, x, y;
9 | initgraph(&gd, &gm, "C:\\TC\\BGI");
10 | cout<<"Enter the center co-ordinates\n";
11 | cin>>xc>>yc;
12 | cout<<"Enter the radius of circle\n";
13 | cin>>r;
14 | pk = 3 - 2*r;
15 | x=0; y = r;
16 | drawCircle(x,y,xc,yc);
17 | while(x < y)
18 | {
19 | if(pk <= 0)
20 | {
21 | pk = pk + (4*x) + 6;
22 | drawCircle(++x,y,xc,yc);
23 | }
24 | else
25 | {
26 | pk = pk + (4*(x-y)) + 10;
27 | drawCircle(++x,--y,xc,yc);
28 | }
29 | }
30 |
31 | getch();
32 | closegraph();
33 | }
34 |
35 | void drawCircle(int x, int y, int xc, int yc)
36 | {
37 | putpixel(x+xc,y+yc,GREEN);
38 | putpixel(-x+xc,y+yc,GREEN);
39 | putpixel(x+xc, -y+yc,GREEN);
40 | putpixel(-x+xc, -y+yc, GREEN);
41 | putpixel(y+xc, x+yc, GREEN);
42 | putpixel(y+xc, -x+yc, GREEN);
43 | putpixel(-y+xc, x+yc, GREEN);
44 | putpixel(-y+xc, -x+yc, GREEN);
45 | }
46 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Md. Moinul Islam
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/c curve/curve.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/c curve/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | using namespace std;
5 | float x, y, len, alpha;
6 | int n;
7 |
8 | void line (float x1, float y1, float x2, float y2)
9 | {
10 | glVertex2f(x1,y1);
11 | glVertex2f(x2,y2);
12 | }
13 |
14 | void c_curve (float x, float y, float len, float alpha, int n)
15 | {
16 | if(n > 0){
17 | len = len / sqrt(2.0);
18 | c_curve(x, y, len, alpha+45, n-1);
19 |
20 | x += len*cos(alpha+45);
21 | y += len*sin(alpha+45);
22 | c_curve(x, y, len, alpha-45, n-1);
23 | }
24 | else{
25 | line(x, y, x+len*cos(alpha), y+len*sin(alpha));
26 | }
27 | }
28 |
29 | void myDisplay(void)
30 | {
31 | glClear(GL_COLOR_BUFFER_BIT);
32 | glColor3f (1.0, 0.0, 0.0);
33 | glPointSize(1);
34 | glBegin(GL_LINES);
35 | c_curve(x, y, len, alpha, n);
36 | glEnd();
37 | glFlush ();
38 | }
39 |
40 | void init (void)
41 | {
42 | glClear(GL_COLOR_BUFFER_BIT);
43 | glClearColor(0.7,0.7,0.7,0.7);
44 | glMatrixMode(GL_PROJECTION);
45 | glLoadIdentity();
46 | gluOrtho2D(-200,500,-200,500);
47 | }
48 |
49 | int main(int argc, char** argv)
50 | {
51 | cout<<"Co-ordinate of C(x,y): ";
52 | cin>>x>>y;
53 | cout<<"\nLength: ";
54 | cin>>len;
55 | cout<<"\nAngle: ";
56 | cin>>alpha;
57 | cout<<"\nValue of n: ";
58 | cin>>n;
59 |
60 | glutInit(&argc, argv);
61 | glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
62 | glutInitWindowSize(850, 600);
63 | glutInitWindowPosition(100, 50);
64 | glutCreateWindow("C CURVE");
65 | init();
66 | glutDisplayFunc(myDisplay);
67 | glutMainLoop();
68 |
69 | return 0;
70 | }
71 |
--------------------------------------------------------------------------------
/Midpoint Circle Drawing/Midpoint Circle Drawing.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/Line Clipping/Line Clipping.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/Koch Curve/Koch2/Koch.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/Bresenham Circle Drawing/BCD2/BCD.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/Flood FIll Circle/Flood FIll Circle.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/Koch Curve/Koch Curve.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/Flood Fill Algorithm/Flood Fill Algorithm.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/Bresenham Circle Drawing/Bresenham Circle Drawing.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/Midpoint Ellipse/Midpoint Ellipse.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/Polygon Clipping/Polygon Clipping.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/Flood Fill Sqaure/Flood Fill Sqaure.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/Cubic Bezier Curve/Cubic Bezier Curve.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/Bound Fill Algorithm/Bound Fill Algorithm.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/Boundary Fill Circle/Boundary Fill Circle.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/Boundary Fill Sqaure/Boundary Fill Sqaure.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/Bresenham Line Drawing/Bresenham Line Drawing.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/DDA/DDA.cbp:
--------------------------------------------------------------------------------
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 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/DDA/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | GLint x0,y0,xEnd,yEnd;
6 | inline GLint round(const GLfloat a)
7 | {
8 | return GLint(a+0.5);
9 | }
10 | void myInit(void)
11 | {
12 | glClearColor(0.0,1.0,1.0,0.0);
13 | glColor3f(1.0f,0.0f,0.0f);
14 | glPointSize(3.0);
15 | glMatrixMode(GL_PROJECTION);
16 | glLoadIdentity();
17 | gluOrtho2D(0.0,640.0,0.0,480.0);
18 | }
19 | void readInput()
20 | {
21 |
22 | printf("Enter x0, y0, xEnd, yEnd: ");
23 | scanf("%i %i %i %i",&x0,&y0,&xEnd,&yEnd);
24 |
25 | }
26 | void setPixel(GLint xcoordinate, GLint ycoordinate)
27 | {
28 | glBegin(GL_POINTS);
29 | glVertex2i(xcoordinate,ycoordinate);
30 | glEnd();
31 | glFlush(); //forces execution in finite time
32 | }
33 |
34 | void lineDDA(GLint x0,GLint y0,GLint xEnd,GLint yEnd)
35 | {
36 | GLint dx = abs(xEnd-x0);
37 | GLint dy = abs(yEnd-y0);
38 | GLint steps,k;
39 | GLfloat xIncrement,yIncrement,x=x0,y=y0;
40 |
41 | if(dx>dy)
42 | steps = dx;
43 | else
44 | steps = dy;
45 |
46 | xIncrement = GLfloat(dx) / GLfloat(steps);
47 | yIncrement = GLfloat(dy) / GLfloat(steps);
48 | setPixel(round(x),round(y));
49 |
50 | for(k=1;k
2 | #include
3 | #include
4 | #include
5 |
6 | GLint x0,y0,xEnd,yEnd;
7 | void init()
8 | {
9 |
10 | glClearColor(1.0,1.0,1.0,0.0); //clear values for RGBA
11 | glColor3f(1.0f,0.0f,0.0f); //set current color - RGB
12 | glPointSize(1.0);
13 | glMatrixMode(GL_PROJECTION); // specifies current matrix
14 | glLoadIdentity();
15 | gluOrtho2D(0.0,600.0,0.0,600.0);
16 | }
17 | void setPixel(GLint xcoordinate, GLint ycoordinate)
18 | {
19 | glBegin(GL_POINTS);
20 | glVertex2i(xcoordinate,ycoordinate);//specifies coordinates
21 | glEnd();
22 | glFlush();
23 | }
24 | void lineBA(GLint x0,GLint y0,GLint xEnd,GLint yEnd)
25 | {
26 | GLint dx = xEnd-x0;
27 | GLint dy = yEnd-y0;
28 | GLint steps,k;
29 | steps=dx;
30 | GLint x,y,p0=(2*dy)-dx;
31 | setPixel(x0,y0);
32 | x=x0;
33 | y=y0;
34 | for(k=0;k
2 | #include
3 | #include
4 | #include
5 |
6 | using namespace std;
7 | float x1,x2,y1,y2,n;
8 |
9 | void getdata()
10 | {
11 | cout<<"Enter Start & End Points of Line: ";
12 | cin>>x1>>y1>>x2>>y2;
13 | cout<<"Enter no. of Iteration: ";
14 | cin>>n;
15 | }
16 |
17 | void koch(float x1,float y1,float x2,float y2,float n)
18 | {
19 | float ang=60;ang=ang*3.14/180;
20 | float x3=(2*x1+x2)/3;
21 | float y3=(2*y1+y2)/3;
22 | float x4=(x1+2*x2)/3;
23 | float y4=(y1+2*y2)/3;
24 | float x=x3+(x4-x3)*0.5+(y4-y3)*0.8660;
25 | float y=y3-(x4-x3)*0.8660+(y4-y3)*0.5;
26 | if(n>0)
27 | {
28 | koch(x1,y1,x3,y3,n-1);
29 | koch(x3,y3,x,y,n-1);
30 | koch(x,y,x4,y4,n-1);
31 | koch(x4,y4,x2,y2,n-1);
32 | }
33 | else
34 | {
35 | glBegin(GL_LINE_STRIP);
36 | glClearColor(1.0,1.0,1.0,0.0);
37 | glColor3f(0.0,1.0,1.0);
38 | glVertex2f(x1,y1);
39 | glColor3f(0.0,1.0,1.0);
40 | glVertex2f(x3,y3);
41 | glColor3f(1.0,1.0,0.0);
42 | glVertex2f(x,y);
43 | glColor3f(1.0,0.0,1.0);
44 | glVertex2f(x4,y4);
45 | glColor3f(1.0,1.0,1.0);
46 | glVertex2f(x2,y2);
47 | glEnd();
48 | }
49 | }
50 |
51 | void Init()
52 | {
53 | glClearColor(0.0,0.0,0.0,0.0);
54 | glColor3f(0.0,0.0,0.0);
55 | gluOrtho2D(0.0,640.0,480.0,0.0);
56 | }
57 | void display()
58 | {
59 | glClear(GL_COLOR_BUFFER_BIT);
60 | koch(x1,y1,x2,y2,n);
61 | glFlush();
62 | }
63 | int main(int argv,char **argc)
64 | {
65 |
66 | getdata();
67 |
68 | glutInit(&argv,argc);
69 | glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
70 | glutInitWindowPosition(100,100);
71 | glutInitWindowSize(640,480);
72 | glutCreateWindow("Koch Curve Implementation");
73 | Init();
74 | glutDisplayFunc(display);
75 | glutMainLoop();
76 |
77 | return 0;
78 | }
79 |
--------------------------------------------------------------------------------
/Midpoint Ellipse/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | using namespace std;
6 |
7 | int xc,yc,a,b;
8 | void pp(int x,int y)
9 | {
10 | glBegin(GL_POINTS);
11 | glVertex2i(x,y);
12 | glEnd();
13 | }
14 | void getpixel(int x,int y)
15 | {
16 | pp(300+x,300+y);
17 | pp(300-x,300+y);
18 | pp(300-x,300-y);
19 | pp(300+x,300-y);
20 | }
21 |
22 | void display ()
23 | {
24 | glClear(GL_COLOR_BUFFER_BIT);
25 | int x=0;
26 | int y=b;
27 | int e=a*a;
28 | int g=b*b;
29 | int fx=0;
30 | int fy=2*e*b;
31 |
32 | int p0=g-e*b+0.25*e;
33 | while(fx0)
51 | {
52 | y--;
53 | fy=fy-2*e;
54 | if(p0>=0)
55 | p0=p0-fy+e;
56 | else{
57 | x++;
58 | fx=fx+2*e;
59 | p0=p0+fx-fy+e;
60 | }
61 | getpixel(x,y);
62 | }
63 | glFlush();
64 | }
65 |
66 | void init(void)
67 | {
68 | glClearColor(0.0,0.0,0.0,0.0); //clear values for RGBA
69 | glColor3f(1.0f,1.0f,1.0f); //set current color - RGB
70 | glPointSize(3.0); //diameters of rasterized points
71 | glMatrixMode(GL_PROJECTION); // specifies current matrix
72 | glLoadIdentity();
73 | gluOrtho2D(0.0,800.0,0.0,600.0); //left, right, top, bottom
74 | }
75 |
76 | int main (int argc, char **argv)
77 | {
78 | cout<<"enter values of a and b:"<>a>>b;
80 |
81 | glutInit(&argc,argv);
82 | glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
83 | glutInitWindowSize(800,600);
84 | glutInitWindowPosition(100,50);
85 | glutCreateWindow("MidPoint Ellipse Algorithm");
86 | init();
87 | glutDisplayFunc(display);
88 | glutMainLoop();
89 | }
90 |
--------------------------------------------------------------------------------
/Bound Fill Algorithm/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | using namespace std;
8 |
9 | void delay(float ms){
10 | clock_t goal = ms + clock();
11 | while(goal>clock());
12 | }
13 |
14 | void init(){
15 | glClearColor(0.0,1.0,1.0,0.0);
16 | glMatrixMode(GL_PROJECTION);
17 | gluOrtho2D(0,640,0,480);
18 | }
19 |
20 | void bound_it(int x, int y, float* fillColor, float* bc){
21 | float color[3];
22 | glReadPixels(x,y,1.0,1.0,GL_RGB,GL_FLOAT,color);
23 | if((color[0]!=bc[0] || color[1]!=bc[1] || color[2]!=bc[2])&&(
24 | color[0]!=fillColor[0] || color[1]!=fillColor[1] || color[2]!=fillColor[2])){
25 | glColor3f(fillColor[0],fillColor[1],fillColor[2]);
26 | glBegin(GL_POINTS);
27 | glVertex2i(x,y);
28 | glEnd();
29 | glFlush();
30 | bound_it(x+1,y,fillColor,bc);
31 | bound_it(x-2,y,fillColor,bc);
32 | bound_it(x,y+2,fillColor,bc);
33 | bound_it(x,y-2,fillColor,bc);
34 | }
35 | }
36 |
37 | void mouse(int btn, int state, int x, int y){
38 | y = 480-y;
39 | if(btn==GLUT_LEFT_BUTTON)
40 | {
41 | if(state==GLUT_DOWN)
42 | {
43 | float bCol[] = {1,0,0};
44 | float color[] = {0,0,1};
45 | //glReadPixels(x,y,1.0,1.0,GL_RGB,GL_FLOAT,intCol);
46 | bound_it(x,y,color,bCol);
47 | }
48 | }
49 | }
50 |
51 | void world(){
52 | glLineWidth(3);
53 | glPointSize(2);
54 | glClear(GL_COLOR_BUFFER_BIT);
55 | glColor3f(1,0,0);
56 | glBegin(GL_LINE_LOOP);
57 | glVertex2i(150,100);
58 | glVertex2i(300,300);
59 | glVertex2i(450,100);
60 | glEnd();
61 | glFlush();
62 | }
63 |
64 | int main(int argc, char** argv){
65 | glutInit(&argc, argv);
66 | glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
67 | glutInitWindowSize(640,480);
68 | glutInitWindowPosition(200,200);
69 | glutCreateWindow("Boundary Fill Algorithm Implementation");
70 | glutDisplayFunc(world);
71 | glutMouseFunc(mouse);
72 | init();
73 | glutMainLoop();
74 | return 0;
75 | }
76 |
--------------------------------------------------------------------------------
/Koch Curve/Koch2/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | using namespace std;
5 | int n;
6 | double xx, yy, lngth, aalpha;
7 |
8 |
9 | void line(double x1, double y1, double x2, double y2){
10 | glBegin(GL_LINES);
11 | glVertex2f(x1, y1);
12 | glVertex2f(x2, y2);
13 | glEnd();
14 | glFlush();
15 | }
16 | double radian(double degree){
17 | return acos(-1)*degree/180.0;
18 | }
19 | double cosine(double alpha){
20 | return cos(radian(alpha));
21 | }
22 | double sine(double alpha){
23 | return sin(radian(alpha));
24 | }
25 | void Koch_Curve(double x, double y, double len, double alpha, int n){
26 | if(n>0){
27 | len=len/3.0;
28 | Koch_Curve(x, y, len, alpha, n-1);
29 | x=x+len*cosine(alpha); y=y+len*sine(alpha);
30 | Koch_Curve(x, y, len, alpha-60, n-1);
31 | x=x+len*cosine(alpha-60); y=y+len*sine(alpha-60);
32 | Koch_Curve(x, y, len, alpha+60, n-1);
33 | x=x+len*cosine(alpha+60); y=y+len*sine(alpha+60);
34 | Koch_Curve(x, y, len, alpha, n-1);
35 | }
36 | else line(x, y, x+len*cosine(alpha), y+len*sine(alpha));
37 | }
38 |
39 | void display(void){
40 | //glClearColor(0, 0.0, 0.0, 0);
41 | glClear(GL_COLOR_BUFFER_BIT);
42 | Koch_Curve(xx, yy, lngth, aalpha, n);
43 | }
44 | void init(void){
45 | glClear(GL_COLOR_BUFFER_BIT);
46 | glClearColor(0.0, 1.0, 1.0, 0.0);
47 | glColor3f(1.0f,0.0f,0.0f);
48 | //glPointSize(2.0);
49 | glMatrixMode(GL_PROJECTION);
50 | glLoadIdentity();
51 | gluOrtho2D(0.0,800.0,0.0,600.0);
52 | }
53 | int main(int argc, char** argv)
54 | {
55 | cout<<"Enter Co-ordinate of (x,y): ";
56 | cin>>xx>>yy;
57 | cout<<"\nEnter Length: ";
58 | cin>>lngth;
59 | cout<<"\nEnter Degree of Angle: ";
60 | cin>>aalpha;
61 | cout<<"\nEnter No. of Iteration: ";
62 | cin>>n;
63 | glutInit(&argc, argv);
64 | glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
65 | glutInitWindowSize(800, 600);
66 | glutInitWindowPosition(100, 50);
67 | glutCreateWindow("Koch Curve");
68 | init();
69 | glutDisplayFunc(display);
70 | glutMainLoop();
71 |
72 | return 0;
73 | }
74 |
--------------------------------------------------------------------------------
/Bresenham Circle Drawing/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | // Center of the circle = (320, 240)
7 | int xc = 320, yc = 240;
8 |
9 | // Plot eight points using circle's symmetrical property
10 | void plot_point(int x, int y)
11 | {
12 | glBegin(GL_POINTS);
13 | glVertex2i(xc+x, yc+y);
14 | glVertex2i(xc+x, yc-y);
15 | glVertex2i(xc+y, yc+x);
16 | glVertex2i(xc+y, yc-x);
17 | glVertex2i(xc-x, yc-y);
18 | glVertex2i(xc-y, yc-x);
19 | glVertex2i(xc-x, yc+y);
20 | glVertex2i(xc-y, yc+x);
21 | glEnd();
22 | }
23 |
24 | // Function to draw a circle using bresenham's
25 | // circle drawing algorithm
26 | void bresenham_circle(int r)
27 | {
28 | int x=0,y=r;
29 | float pk=(5.0/4.0)-r;
30 |
31 | /* Plot the points */
32 | /* Plot the first point */
33 | plot_point(x,y);
34 | // int k;
35 | /* Find all vertices till x=y */
36 | while(x < y)
37 | {
38 | x = x + 1;
39 | if(pk < 0)
40 | pk = pk + 2*x+1;
41 | else
42 | {
43 | y = y - 1;
44 | pk = pk + 2*(x - y) + 1;
45 | }
46 | plot_point(x,y);
47 | }
48 | glFlush();
49 | }
50 |
51 | // Function to draw two concentric circles
52 | void concentric_circles(void)
53 | {
54 | //Clears buffers to preset values
55 | glClear(GL_COLOR_BUFFER_BIT);
56 | int radius = 100;
57 | bresenham_circle(radius);
58 |
59 | }
60 |
61 | void Init()
62 | {
63 | glClearColor(0.0,1.0,1.0,0.0); //clear values for RGBA
64 | glColor3f(1.0f,0.0f,0.0f); //set current color - RGB
65 | glPointSize(3.0); //diameters of rasterized points
66 | glMatrixMode(GL_PROJECTION); // specifies current matrix
67 | glLoadIdentity();
68 | gluOrtho2D(0.0,800.0,0.0,600.0);
69 | }
70 |
71 | int main(int argc, char **argv)
72 | {
73 | /* Initialise GLUT library */
74 | glutInit(&argc,argv);
75 | glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //Set the initial display mode
76 | glutInitWindowPosition(0,0);
77 | glutInitWindowSize(800,600);
78 | glutCreateWindow("Bresenham Circle Drawing");
79 | /* Initialize drawing colors */
80 | Init();
81 | /* Call the displaying function */
82 | glutDisplayFunc(concentric_circles);
83 | /* Keep displaying untill the program is closed */
84 | glutMainLoop();
85 | }
86 |
--------------------------------------------------------------------------------
/Flood FIll Circle/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | struct Point {
7 | GLint x;
8 | GLint y;
9 | };
10 |
11 | struct Color {
12 | GLfloat r;
13 | GLfloat g;
14 | GLfloat b;
15 | };
16 |
17 | void init() {
18 | glClearColor(1.0, 1.0, 1.0, 0.0);
19 | glColor3f(0.0, 0.0, 0.0);
20 | glPointSize(1.0);
21 | glMatrixMode(GL_PROJECTION);
22 | glLoadIdentity();
23 | gluOrtho2D(0, 640, 0, 480);
24 | }
25 |
26 | Color getPixelColor(GLint x, GLint y) {
27 | Color color;
28 | glReadPixels(x, y, 1, 1, GL_RGB, GL_FLOAT, &color);
29 | return color;
30 | }
31 |
32 | void setPixelColor(GLint x, GLint y, Color color) {
33 | glColor3f(color.r, color.g, color.b);
34 | glBegin(GL_POINTS);
35 | glVertex2i(x, y);
36 | glEnd();
37 | glFlush();
38 | }
39 |
40 | void floodFill(GLint x, GLint y, Color oldColor, Color newColor) {
41 | Color color;
42 | color = getPixelColor(x, y);
43 |
44 | if(color.r == oldColor.r && color.g == oldColor.g && color.b == oldColor.b)
45 | {
46 | setPixelColor(x, y, newColor);
47 | floodFill(x+1, y, oldColor, newColor);
48 | floodFill(x, y+1, oldColor, newColor);
49 | floodFill(x-1, y, oldColor, newColor);
50 | floodFill(x, y-1, oldColor, newColor);
51 | }
52 | return;
53 | }
54 |
55 | void onMouseClick(int button, int state, int x, int y)
56 | {
57 | Color newColor = {1.0f, 0.0f, 0.0f};
58 | Color oldColor = {1.0f, 1.0f, 1.0f};
59 |
60 | floodFill(320, 240, oldColor, newColor);
61 | }
62 |
63 | void draw_circle(Point pC, GLfloat radius) {
64 | GLfloat step = 1/radius;
65 | GLfloat x, y;
66 |
67 | for(GLfloat theta = 0; theta <= 360; theta += step) {
68 | x = pC.x + (radius * cos(theta));
69 | y = pC.y + (radius * sin(theta));
70 | glVertex2i(x, y);
71 | }
72 | }
73 |
74 | void display(void) {
75 | Point pt = {320, 240};
76 | GLfloat radius = 50;
77 |
78 | glClear(GL_COLOR_BUFFER_BIT);
79 | glBegin(GL_POINTS);
80 | draw_circle(pt, radius);
81 | glEnd();
82 | glFlush();
83 | }
84 |
85 | int main(int argc, char** argv)
86 | {
87 | glutInit(&argc, argv);
88 | glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
89 | glutInitWindowSize(640, 480);
90 | glutInitWindowPosition(200, 200);
91 | glutCreateWindow("Flood Fill Circle");
92 | init();
93 | glutDisplayFunc(display);
94 | glutMouseFunc(onMouseClick);
95 | glutMainLoop();
96 | return 0;
97 | }
98 |
--------------------------------------------------------------------------------
/Flood Fill Algorithm/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | using namespace std;
8 |
9 | void delay(float ms){
10 | clock_t goal = ms + clock();
11 | while(goal>clock());
12 | }
13 |
14 | void init(){
15 | glClearColor(1.0,1.0,1.0,1.0);
16 | glMatrixMode(GL_PROJECTION);
17 | gluOrtho2D(0,640,0,480);
18 | }
19 |
20 | void flood_it(int x, int y, float* fillColor, float* ic){
21 | float color[3];
22 | glReadPixels(x,y,1.0,1.0,GL_RGB,GL_FLOAT,color);
23 | if(color[0]==ic[0] && color[1]==ic[1] && color[2]==ic[2]){
24 | glColor3f(fillColor[0],fillColor[1],fillColor[2]);
25 | glBegin(GL_POINTS);
26 | glVertex2i(x,y);
27 | glEnd();
28 | glFlush();
29 | flood_it(x-2,y,fillColor,ic);
30 | flood_it(x+1,y,fillColor,ic);
31 | flood_it(x,y+1,fillColor,ic);
32 | flood_it(x,y-2,fillColor,ic);
33 | }
34 | }
35 |
36 | void mouse(int btn, int state, int x, int y){
37 | y = 480-y;
38 | if(btn==GLUT_LEFT_BUTTON)
39 | {
40 | if(state==GLUT_DOWN)
41 | {
42 | float intCol[] = {1,0,0};
43 | float color[] = {0,0,1};
44 | glReadPixels(x,y,1.0,1.0,GL_RGB,GL_FLOAT,intCol);
45 | flood_it(x,y,color,intCol);
46 | }
47 | }
48 | }
49 |
50 | void world(){
51 | glPointSize(2);
52 | glClear(GL_COLOR_BUFFER_BIT);
53 | glColor3f(1,0,0);
54 | glBegin(GL_POLYGON);
55 | glVertex2i(15,10);
56 | glVertex2i(155,200);
57 | glVertex2i(305,10);
58 | glEnd();
59 | glColor3f(0,1,0);
60 | glBegin(GL_POLYGON);
61 | glVertex2i(300,398);
62 | glVertex2i(150,198);
63 | glVertex2i(450,198);
64 | glEnd();
65 | glColor3f(0,0,1);
66 | glBegin(GL_POLYGON);
67 | glVertex2i(300,10);
68 | glVertex2i(600,10);
69 | glVertex2i(450,200);
70 | glEnd();
71 | glFlush();
72 | }
73 |
74 | int main(int argc, char** argv){
75 | glutInit(&argc, argv);
76 | glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
77 | glutInitWindowSize(640,480);
78 | glutInitWindowPosition(200,200);
79 | glutCreateWindow("Many Amaze Very GL WOW");
80 | glutDisplayFunc(world);
81 | glutMouseFunc(mouse);
82 | init();
83 | glutMainLoop();
84 | return 0;
85 | }
86 |
--------------------------------------------------------------------------------
/Midpoint Circle Drawing/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | GLint xc,yc,r;
5 | void myInit(void)
6 | {
7 | glClearColor(0.0,1.0,1.0,0.0); //clear values for RGBA
8 | glColor3f(1.0f,0.0f,0.0f); //set current color - RGB
9 | glPointSize(3.0); //diameters of rasterized points
10 | glMatrixMode(GL_PROJECTION); // specifies current matrix
11 | glLoadIdentity();
12 | gluOrtho2D(0.0,800.0,0.0,600.0); //left, right, top, bottom
13 | //glOrtho(-sizes/2,sizes/2,-sizes/2,sizes/2,-1,1);
14 | }
15 | void readInput()
16 | {
17 |
18 | printf("Enter xc, yc, radius: ");
19 | scanf("%i %i %i",&xc,&yc,&r);
20 |
21 | }
22 | void setPixel(GLint xcoordinate, GLint ycoordinate)
23 | {
24 | glBegin(GL_POINTS);
25 | glVertex2i(xcoordinate,ycoordinate);
26 | glEnd();
27 | glFlush();
28 | }
29 | /* void draw_axis()
30 | {
31 | GLint i=(-sizes)/2;
32 | for(;i<(sizes/2);i++)
33 | {
34 | setPixel(i,0);
35 | setPixel(0,i);
36 | }
37 |
38 | } */
39 | void draw_in_each_oct(GLint xk,GLint yk, GLint xc,GLint yc)
40 | {
41 | setPixel(xc+xk,yc+yk);
42 | setPixel(xc+yk,yc+xk);
43 | setPixel(xc-yk,yc+xk);
44 | setPixel(xc-xk,yc+yk);
45 | setPixel(xc-xk,yc-yk);
46 | setPixel(xc-yk,yc-xk);
47 | setPixel(xc+yk,yc-xk);
48 | setPixel(xc+xk,yc-yk);
49 | }
50 |
51 | void midPtCircle(GLint xc,GLint yc,GLint r)
52 | {
53 | GLint pk,xk,yk;
54 | pk=1-r;
55 | xk=0;
56 | yk=r;
57 | draw_in_each_oct(xk,yk,xc,yc);
58 | while(xk<=yk)
59 | {
60 | if(pk<0)
61 | {
62 | xk=xk+1;
63 | pk=pk+(2*xk)+1;
64 | }
65 | else
66 | {
67 | xk=xk+1;
68 | yk=yk-1;
69 | pk=pk+(2*xk)+1-(2*yk);
70 | }
71 | draw_in_each_oct(xk,yk,xc,yc);
72 | }
73 |
74 | }
75 |
76 |
77 | void Display(void)
78 | {
79 | glClear(GL_COLOR_BUFFER_BIT);
80 | //draw_axis();
81 | midPtCircle(xc,yc,r);
82 | }
83 |
84 | int main(int argc,char *argv[])
85 | {
86 | glutInit(&argc,argv);
87 | glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
88 | glutInitWindowSize(800,600);
89 | glutInitWindowPosition(100,50);
90 | glutCreateWindow("Mid Point Circle");
91 | readInput();
92 | glutDisplayFunc(Display);
93 | myInit();
94 | glutMainLoop();
95 | return 0;
96 | }
97 |
--------------------------------------------------------------------------------
/Boundary Fill Circle/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | struct Point {
7 | GLint x;
8 | GLint y;
9 | };
10 |
11 | struct Color {
12 | GLfloat r;
13 | GLfloat g;
14 | GLfloat b;
15 | };
16 |
17 | void init() {
18 | glClearColor(0.0, 1.0, 1.0, 0.0);
19 | glColor3f(1.0, 0.0, 0.0);
20 | glPointSize(3.0);
21 | glMatrixMode(GL_PROJECTION);
22 | glLoadIdentity();
23 | gluOrtho2D(0, 800, 0, 600);
24 | }
25 |
26 | Color getPixelColor(GLint x, GLint y) {
27 | Color color;
28 | glReadPixels(x, y, 1, 1, GL_RGB, GL_FLOAT, &color);
29 | return color;
30 | }
31 |
32 | void setPixelColor(GLint x, GLint y, Color color) {
33 | glColor3f(color.g, color.r, color.b);
34 | glBegin(GL_POINTS);
35 | glVertex2i(x, y);
36 | glEnd();
37 | glFlush();
38 |
39 | }
40 |
41 | void BoundaryFill(int x, int y, Color fillColor, Color boundaryColor) {
42 | Color currentColor = getPixelColor(x, y);
43 | if(currentColor.r != boundaryColor.r && currentColor.g != boundaryColor.g && currentColor.b != boundaryColor.b) {
44 | setPixelColor(x, y, fillColor);
45 | BoundaryFill(x+1, y, fillColor, boundaryColor);
46 | BoundaryFill(x-1, y, fillColor, boundaryColor);
47 | BoundaryFill(x, y+1, fillColor, boundaryColor);
48 | BoundaryFill(x, y-1, fillColor, boundaryColor);
49 | }
50 | }
51 |
52 | void onMouseClick(int button, int state, int x, int y)
53 | {
54 | Color fillColor = {1.0f, 0.0f, 0.0f}; // red color will be filled
55 | Color boundaryColor = {0.0f, 0.0f, 0.0f}; // black- boundary
56 |
57 | Point p = {321, 241}; // a point inside the circle
58 |
59 | BoundaryFill(p.x, p.y, fillColor, boundaryColor);
60 | }
61 |
62 | void draw_circle(Point pC, GLfloat radius) {
63 | GLfloat step = 1/radius;
64 | GLfloat x, y;
65 |
66 | for(GLfloat theta = 0; theta <= 360; theta += step) {
67 | x = pC.x + (radius * cos(theta));
68 | y = pC.y + (radius * sin(theta));
69 | glVertex2i(x, y);
70 | }
71 | }
72 |
73 | void display(void) {
74 | Point pt = {320, 240};
75 | GLfloat radius = 20;
76 |
77 | glClear(GL_COLOR_BUFFER_BIT);
78 | glBegin(GL_POINTS);
79 | draw_circle(pt, 50);
80 | glEnd();
81 | glFlush();
82 | }
83 |
84 | int main(int argc, char** argv)
85 | {
86 | glutInit(&argc, argv);
87 | glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
88 | glutInitWindowSize(800, 600);
89 | glutInitWindowPosition(200, 200);
90 | glutCreateWindow("Boundary Fill Circle");
91 | init();
92 | glutDisplayFunc(display);
93 | glutMouseFunc(onMouseClick);
94 | glutMainLoop();
95 | return 0;
96 | }
97 |
--------------------------------------------------------------------------------
/Cubic Bezier Curve/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #define CTRL_COUNT 100
6 | int ctrlPointsCount;
7 | int ctrlPointsX[CTRL_COUNT], ctrlPointsY[CTRL_COUNT];
8 | int X1[3]={20,25,20}, Y1[3]={5,24,38}; //first point(x1[0],y1[0]) second(x1[1],y1[1]) third(x1[2],y1[2])
9 |
10 | void myInit()
11 | {
12 | glClearColor(0.0,0.0,0.0,0.0);
13 | glColor3f(1.0,0.0,0.0);
14 | glPointSize(8.0);
15 | glMatrixMode(GL_PROJECTION);
16 | glLoadIdentity();
17 | gluOrtho2D(0.0,128.0,0.0,96.0);
18 | }
19 | //p(t)=(1-t)^3*p0+3t(1-t)^2*p1+3t^2(1-t)p2+t^3p3
20 | float getNextBezierPointX(float t)
21 | {
22 | float x=0.0;
23 |
24 | for(int i=0; i
2 | #include
3 | #include
4 | #include
5 |
6 | struct Point {
7 | GLint x;
8 | GLint y;
9 | };
10 |
11 | struct Color {
12 | GLfloat r;
13 | GLfloat g;
14 | GLfloat b;
15 | };
16 |
17 | void draw_dda(Point p1, Point p2) {
18 | GLfloat dx = p2.x - p1.x;
19 | GLfloat dy = p2.y - p1.y;
20 |
21 | GLfloat x1 = p1.x;
22 | GLfloat y1 = p1.y;
23 |
24 | GLfloat step = 0;
25 |
26 | if(abs(dx) > abs(dy)) {
27 | step = abs(dx);
28 | } else {
29 | step = abs(dy);
30 | }
31 |
32 | GLfloat xInc = dx/step;
33 | GLfloat yInc = dy/step;
34 |
35 | for(float i = 1; i <= step; i++) {
36 | glVertex2i(x1, y1);
37 | x1 += xInc;
38 | y1 += yInc;
39 | }
40 | }
41 |
42 | void init() {
43 | glClearColor(0.0, 1.0, 1.0, 0.0);
44 | glColor3f(0.0, 0.0, 0.0);
45 | glPointSize(1.0);
46 | glMatrixMode(GL_PROJECTION);
47 | glLoadIdentity();
48 | gluOrtho2D(0, 640, 0, 480);
49 | }
50 |
51 | Color getPixelColor(GLint x, GLint y) {
52 | Color color;
53 | glReadPixels(x, y, 1, 1, GL_RGB, GL_FLOAT, &color);
54 | return color;
55 | }
56 |
57 | void setPixelColor(GLint x, GLint y, Color color) {
58 | glColor3f(color.r, color.g, color.b);
59 | glBegin(GL_POINTS);
60 | glVertex2i(x, y);
61 | glEnd();
62 | glFlush();
63 | }
64 |
65 | void floodFill(GLint x, GLint y, Color oldColor, Color newColor) {
66 | Color color;
67 | color = getPixelColor(x, y);
68 |
69 | if(color.r == oldColor.r && color.g == oldColor.g && color.b == oldColor.b)
70 | {
71 | setPixelColor(x, y, newColor);
72 | floodFill(x+1, y, oldColor, newColor);
73 | floodFill(x, y+1, oldColor, newColor);
74 | floodFill(x-1, y, oldColor, newColor);
75 | floodFill(x, y-1, oldColor, newColor);
76 | }
77 | return;
78 | }
79 |
80 | void onMouseClick(int button, int state, int x, int y)
81 | {
82 | Color newColor = {1.0f, 0.0f, 0.0f};
83 | Color oldColor = {0.0f, 1.0f, 1.0f};
84 |
85 | floodFill(101, 199, oldColor, newColor);
86 | }
87 |
88 | void display(void) {
89 | Point p1 = {100, 100}, // bottom-right
90 | p2 = {200, 100}, // bottom-left
91 | p3 = {200, 200}, // top-right
92 | p4 = {100, 200}; // top-left
93 |
94 | glClear(GL_COLOR_BUFFER_BIT);
95 | glBegin(GL_POINTS);
96 | draw_dda(p1, p2);
97 | draw_dda(p2, p3);
98 | draw_dda(p3, p4);
99 | draw_dda(p4, p1);
100 | glEnd();
101 | glFlush();
102 | }
103 |
104 | int main(int argc, char** argv)
105 | {
106 | glutInit(&argc, argv);
107 | glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
108 | glutInitWindowSize(640, 480);
109 | glutInitWindowPosition(200, 200);
110 | glutCreateWindow("Flood Fill Square");
111 | init();
112 | glutDisplayFunc(display);
113 | glutMouseFunc(onMouseClick);
114 | glutMainLoop();
115 | return 0;
116 | }
117 |
--------------------------------------------------------------------------------
/Boundary Fill Sqaure/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | struct Point {
7 | GLint x;
8 | GLint y;
9 | };
10 |
11 | struct Color {
12 | GLfloat r;
13 | GLfloat g;
14 | GLfloat b;
15 | };
16 |
17 | void init() {
18 | glClearColor(1.0, 1.0, 1.0, 0.0);
19 | glColor3f(0.0, 0.0, 0.0);
20 | glPointSize(1.0);
21 | glMatrixMode(GL_PROJECTION);
22 | glLoadIdentity();
23 | gluOrtho2D(0, 800, 0, 600);
24 | }
25 |
26 | Color getPixelColor(GLint x, GLint y) {
27 | Color color;
28 | glReadPixels(x, y, 1, 1, GL_RGB, GL_FLOAT, &color);
29 | return color;
30 | }
31 |
32 | void setPixelColor(GLint x, GLint y, Color color) {
33 | glColor3f(color.r, color.g, color.b);
34 | glBegin(GL_POINTS);
35 | glVertex2i(x, y);
36 | glEnd();
37 | glFlush();
38 |
39 | }
40 |
41 | void BoundaryFill(int x, int y, Color fillColor, Color boundaryColor) {
42 | Color currentColor = getPixelColor(x, y);
43 | if(currentColor.r != boundaryColor.r && currentColor.g != boundaryColor.g && currentColor.b != boundaryColor.b) {
44 | setPixelColor(x, y, fillColor);
45 | BoundaryFill(x+1, y, fillColor, boundaryColor);
46 | BoundaryFill(x-1, y, fillColor, boundaryColor);
47 | BoundaryFill(x, y+1, fillColor, boundaryColor);
48 | BoundaryFill(x, y-1, fillColor, boundaryColor);
49 | }
50 | }
51 |
52 | void onMouseClick(int button, int state, int x, int y)
53 | {
54 | Color fillColor = {1.0f, 0.0f, 0.0f}; // Fill Color - Red
55 | Color boundaryColor = {0.0f, 0.0f, 0.0f}; // Boundary - black
56 |
57 | Point p = {321, 241};
58 |
59 | BoundaryFill(p.x, p.y, fillColor, boundaryColor);
60 | }
61 |
62 | void draw_dda(Point p1, Point p2) {
63 | GLfloat dx = p2.x - p1.x;
64 | GLfloat dy = p2.y - p1.y;
65 |
66 | GLfloat x1 = p1.x;
67 | GLfloat y1 = p1.y;
68 |
69 | GLfloat step = 100;
70 |
71 | if(abs(dx) > abs(dy)) {
72 | step = abs(dx);
73 | } else {
74 | step = abs(dy);
75 | }
76 |
77 | GLfloat xInc = dx/step;
78 | GLfloat yInc = dy/step;
79 |
80 | for(float i = 1; i <= step; i++) {
81 | glVertex2i(x1, y1);
82 | x1 += xInc;
83 | y1 += yInc;
84 | }
85 | }
86 |
87 | void draw_square(Point a, GLint length) {
88 | Point b = {a.x + length, a.y},
89 | c = {b.x, b.y+length},
90 | d = {c.x-length, c.y};
91 |
92 | draw_dda(a, b);
93 | draw_dda(b, c);
94 | draw_dda(c, d);
95 | draw_dda(d, a);
96 | }
97 |
98 | void display(void) {
99 | Point pt = {320, 240};
100 | GLfloat length = 100;
101 |
102 | glClear(GL_COLOR_BUFFER_BIT);
103 | glBegin(GL_POINTS);
104 | draw_square(pt, length);
105 | glEnd();
106 | glFlush();
107 | }
108 |
109 | int main(int argc, char** argv)
110 | {
111 | glutInit(&argc, argv);
112 | glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
113 | glutInitWindowSize(800, 600);
114 | glutInitWindowPosition(200, 200);
115 | glutCreateWindow("Boundary Fill Square");
116 | init();
117 | glutDisplayFunc(display);
118 | glutMouseFunc(onMouseClick);
119 | glutMainLoop();
120 | return 0;
121 | }
122 |
--------------------------------------------------------------------------------
/Line Clipping/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | void display();
8 | using namespace std;
9 | float xmin=-100;
10 | float ymin=-100;
11 | float xmax=100;
12 | float ymax=100;
13 | float xd1,yd1,xd2,yd2;
14 |
15 |
16 | void init(void)
17 | {
18 |
19 | glClearColor(0.0,0,0,0);
20 | glMatrixMode(GL_PROJECTION);
21 | gluOrtho2D(-300,300,-300,300);
22 |
23 | }
24 |
25 | int code(float x,float y)
26 | {
27 | int c=0;
28 | if(y>ymax)c=8;
29 | if(yxmax)c=2;
31 | if(x0)
41 | {
42 | if((c1 & c2)>0)
43 | {
44 | exit(0);
45 | }
46 |
47 | float xi=x1;float yi=y1;
48 | int c=c1;
49 | if(c==0)
50 | {
51 | c=c2;
52 | xi=x2;
53 | yi=y2;
54 | }
55 | float x,y;
56 | if((c & 8)>0)
57 | {
58 | y=ymax;
59 | x=xi+ 1.0/m*(ymax-yi);
60 | }
61 | else
62 | if((c & 4)>0)
63 | {
64 | y=ymin;
65 | x=xi+1.0/m*(ymin-yi);
66 | }
67 | else
68 | if((c & 2)>0)
69 | {
70 | x=xmax;
71 | y=yi+m*(xmax-xi);
72 | }
73 | else
74 | if((c & 1)>0)
75 | {
76 | x=xmin;
77 | y=yi+m*(xmin-xi);
78 | }
79 |
80 | if(c==c1)
81 | {
82 | xd1=x;
83 | yd1=y;
84 | c1=code(xd1,yd1);
85 | }
86 |
87 | if(c==c2)
88 | {
89 | xd2=x;
90 | yd2=y;
91 | c2=code(xd2,yd2);
92 | }
93 | }
94 |
95 | display();
96 |
97 | }
98 |
99 | void mykey(unsigned char key,int x,int y)
100 | {
101 | if(key=='c')
102 | {
103 | cohen_Line(xd1,yd1,xd2,yd2);
104 | glFlush();
105 | }
106 | }
107 | void display()
108 | {
109 |
110 | glClear(GL_COLOR_BUFFER_BIT);
111 | glColor3f(0.0,1.0,0.0);
112 |
113 | glBegin(GL_LINE_LOOP);
114 | glVertex2i(xmin,ymin);
115 | glVertex2i(xmin,ymax);
116 | glVertex2i(xmax,ymax);
117 | glVertex2i(xmax,ymin);
118 | glEnd();
119 | glColor3f(1.0,0.0,0.0);
120 | glBegin(GL_LINES);
121 | glVertex2i(xd1,yd1);
122 | glVertex2i(xd2,yd2);
123 | glEnd();
124 | glFlush();
125 |
126 |
127 | }
128 |
129 |
130 | int main(int argc,char** argv)
131 | {
132 | printf("Enter line co-ordinates:");
133 | cin>>xd1>>yd1>>xd2>>yd2;
134 | glutInit(&argc,argv);
135 | glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
136 | glutInitWindowSize(600,600);
137 | glutInitWindowPosition(0,0);
138 | glutCreateWindow("Line Clipping");
139 | glutDisplayFunc(display);
140 | glutKeyboardFunc(mykey);
141 | init();
142 | glutMainLoop();
143 | return 0;
144 | }
145 |
--------------------------------------------------------------------------------
/Polygon Clipping/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | struct Point{
5 | float x,y;
6 | } w[4],oVer[4];
7 | int Nout;
8 |
9 | void drawPoly(Point p[],int n){
10 | glBegin(GL_POLYGON);
11 | for(int i=0;i=w[0].x)&&(p.x<=w[2].x))
18 | if((p.y>=w[0].y)&&(p.y<=w[2].y))
19 | return true;
20 | return false;
21 | }
22 |
23 | void addVer(Point p){
24 | oVer[Nout]=p;
25 | Nout=Nout+1;
26 | }
27 |
28 | Point getInterSect(Point s,Point p,int edge){
29 | Point in;
30 | float m;
31 | if(w[edge].x==w[(edge+1)%4].x){ //Vertical Line
32 | m=(p.y-s.y)/(p.x-s.x);
33 | in.x=w[edge].x;
34 | in.y=in.x*m+s.y;
35 | }
36 | else{//Horizontal Line
37 | m=(p.y-s.y)/(p.x-s.x);
38 | in.y=w[edge].y;
39 | in.x=(in.y-s.y)/m;
40 | }
41 | return in;
42 | }
43 |
44 | void clipAndDraw(Point inVer[],int Nin){
45 | Point s,p,interSec;
46 | for(int i=0;i<4;i++)
47 | {
48 | Nout=0;
49 | s=inVer[Nin-1];
50 | for(int j=0;j
4 |
5 |
6 |
7 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\windows.h
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 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winresrc.h
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | 1301111164 c:\program files (x86)\codeblocks\mingw\include\winuser.h
46 |
47 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winnt.h
48 |
49 |
50 |
51 |
52 |
53 |
54 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winerror.h
55 |
56 | 1341006776 c:\program files (x86)\codeblocks\mingw\include\string.h
57 | <_mingw.h>
58 |
59 |
60 | 1341006770 c:\program files (x86)\codeblocks\mingw\include\_mingw.h
61 |
62 | 1301111148 c:\program files (x86)\codeblocks\mingw\include\basetsd.h
63 |
64 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\pshpack4.h
65 |
66 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\poppack.h
67 |
68 | 1301111164 c:\program files (x86)\codeblocks\mingw\include\winver.h
69 |
70 | 1301111148 c:\program files (x86)\codeblocks\mingw\include\dde.h
71 |
72 | 1301111150 c:\program files (x86)\codeblocks\mingw\include\dlgs.h
73 |
74 | 1301111148 c:\program files (x86)\codeblocks\mingw\include\commctrl.h
75 |
76 |
77 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\prsht.h
78 |
79 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\windef.h
80 |
81 |
82 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\wincon.h
83 |
84 | 1301111160 c:\program files (x86)\codeblocks\mingw\include\winbase.h
85 |
86 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\wingdi.h
87 |
88 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winnls.h
89 |
90 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winnetwk.h
91 |
92 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winreg.h
93 |
94 | 1301111164 c:\program files (x86)\codeblocks\mingw\include\winsvc.h
95 |
96 | 1301111148 c:\program files (x86)\codeblocks\mingw\include\cderr.h
97 |
98 | 1301111148 c:\program files (x86)\codeblocks\mingw\include\ddeml.h
99 |
100 | 1301111150 c:\program files (x86)\codeblocks\mingw\include\imm.h
101 |
102 | 1301111154 c:\program files (x86)\codeblocks\mingw\include\lzexpand.h
103 |
104 | 1301111154 c:\program files (x86)\codeblocks\mingw\include\mmsystem.h
105 |
106 | 1301111154 c:\program files (x86)\codeblocks\mingw\include\nb30.h
107 |
108 | 1301111158 c:\program files (x86)\codeblocks\mingw\include\rpc.h
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 | 1301111158 c:\program files (x86)\codeblocks\mingw\include\rpcdce.h
117 |
118 |
119 |
120 | 1301111148 c:\program files (x86)\codeblocks\mingw\include\basetyps.h
121 |
122 | 1301111158 c:\program files (x86)\codeblocks\mingw\include\rpcdcep.h
123 |
124 | 1301111158 c:\program files (x86)\codeblocks\mingw\include\rpcnsi.h
125 |
126 | 1301111158 c:\program files (x86)\codeblocks\mingw\include\rpcnterr.h
127 |
128 | 1341006772 c:\program files (x86)\codeblocks\mingw\include\excpt.h
129 | <_mingw.h>
130 |
131 |
132 | 1301111160 c:\program files (x86)\codeblocks\mingw\include\shellapi.h
133 |
134 |
135 |
136 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\pshpack2.h
137 |
138 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winperf.h
139 |
140 | 1301111148 c:\program files (x86)\codeblocks\mingw\include\commdlg.h
141 |
142 |
143 |
144 | 1301111160 c:\program files (x86)\codeblocks\mingw\include\unknwn.h
145 |
146 |
147 |
148 |
149 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\objfwd.h
150 |
151 |
152 | 1301111164 c:\program files (x86)\codeblocks\mingw\include\wtypes.h
153 |
154 |
155 |
156 | 1301111158 c:\program files (x86)\codeblocks\mingw\include\rpcndr.h
157 |
158 |
159 |
160 | 1301111158 c:\program files (x86)\codeblocks\mingw\include\rpcnsip.h
161 |
162 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winspool.h
163 |
164 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winsock2.h
165 |
166 |
167 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winsock.h
168 |
169 |
170 |
171 | 1301111154 c:\program files (x86)\codeblocks\mingw\include\mswsock.h
172 |
173 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\ole2.h
174 |
175 |
176 |
177 |
178 |
179 |
180 | 1301111154 c:\program files (x86)\codeblocks\mingw\include\objbase.h
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 | 1341006776 c:\program files (x86)\codeblocks\mingw\include\stdlib.h
191 | <_mingw.h>
192 |
193 |
194 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\objidl.h
195 |
196 |
197 | 1301111148 c:\program files (x86)\codeblocks\mingw\include\cguid.h
198 |
199 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\olectlid.h
200 |
201 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\oleauto.h
202 |
203 |
204 | 1301111154 c:\program files (x86)\codeblocks\mingw\include\oaidl.h
205 |
206 |
207 |
208 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\oleidl.h
209 |
210 |
211 | 976645372 c:\program files (x86)\codeblocks\mingw\include\gl\glut.h
212 |
213 |
214 |
215 |
216 | 1301111164 c:\program files (x86)\codeblocks\mingw\include\gl\gl.h
217 |
218 | 1301111164 c:\program files (x86)\codeblocks\mingw\include\gl\glu.h
219 |
220 |
221 |
222 |
--------------------------------------------------------------------------------
/Midpoint Ellipse/Midpoint Ellipse.depend:
--------------------------------------------------------------------------------
1 | # depslib dependency file v1.0
2 | 1550395789 source:c:\users\morol\documents\opengl\midpoint ellipse\main.cpp
3 |
4 |
5 |
6 |
7 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\windows.h
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 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winresrc.h
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | 1301111164 c:\program files (x86)\codeblocks\mingw\include\winuser.h
46 |
47 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winnt.h
48 |
49 |
50 |
51 |
52 |
53 |
54 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winerror.h
55 |
56 | 1341006776 c:\program files (x86)\codeblocks\mingw\include\string.h
57 | <_mingw.h>
58 |
59 |
60 | 1341006770 c:\program files (x86)\codeblocks\mingw\include\_mingw.h
61 |
62 | 1301111148 c:\program files (x86)\codeblocks\mingw\include\basetsd.h
63 |
64 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\pshpack4.h
65 |
66 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\poppack.h
67 |
68 | 1301111164 c:\program files (x86)\codeblocks\mingw\include\winver.h
69 |
70 | 1301111148 c:\program files (x86)\codeblocks\mingw\include\dde.h
71 |
72 | 1301111150 c:\program files (x86)\codeblocks\mingw\include\dlgs.h
73 |
74 | 1301111148 c:\program files (x86)\codeblocks\mingw\include\commctrl.h
75 |
76 |
77 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\prsht.h
78 |
79 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\windef.h
80 |
81 |
82 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\wincon.h
83 |
84 | 1301111160 c:\program files (x86)\codeblocks\mingw\include\winbase.h
85 |
86 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\wingdi.h
87 |
88 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winnls.h
89 |
90 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winnetwk.h
91 |
92 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winreg.h
93 |
94 | 1301111164 c:\program files (x86)\codeblocks\mingw\include\winsvc.h
95 |
96 | 1301111148 c:\program files (x86)\codeblocks\mingw\include\cderr.h
97 |
98 | 1301111148 c:\program files (x86)\codeblocks\mingw\include\ddeml.h
99 |
100 | 1301111150 c:\program files (x86)\codeblocks\mingw\include\imm.h
101 |
102 | 1301111154 c:\program files (x86)\codeblocks\mingw\include\lzexpand.h
103 |
104 | 1301111154 c:\program files (x86)\codeblocks\mingw\include\mmsystem.h
105 |
106 | 1301111154 c:\program files (x86)\codeblocks\mingw\include\nb30.h
107 |
108 | 1301111158 c:\program files (x86)\codeblocks\mingw\include\rpc.h
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 | 1301111158 c:\program files (x86)\codeblocks\mingw\include\rpcdce.h
117 |
118 |
119 |
120 | 1301111148 c:\program files (x86)\codeblocks\mingw\include\basetyps.h
121 |
122 | 1301111158 c:\program files (x86)\codeblocks\mingw\include\rpcdcep.h
123 |
124 | 1301111158 c:\program files (x86)\codeblocks\mingw\include\rpcnsi.h
125 |
126 | 1301111158 c:\program files (x86)\codeblocks\mingw\include\rpcnterr.h
127 |
128 | 1341006772 c:\program files (x86)\codeblocks\mingw\include\excpt.h
129 | <_mingw.h>
130 |
131 |
132 | 1301111160 c:\program files (x86)\codeblocks\mingw\include\shellapi.h
133 |
134 |
135 |
136 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\pshpack2.h
137 |
138 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winperf.h
139 |
140 | 1301111148 c:\program files (x86)\codeblocks\mingw\include\commdlg.h
141 |
142 |
143 |
144 | 1301111160 c:\program files (x86)\codeblocks\mingw\include\unknwn.h
145 |
146 |
147 |
148 |
149 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\objfwd.h
150 |
151 |
152 | 1301111164 c:\program files (x86)\codeblocks\mingw\include\wtypes.h
153 |
154 |
155 |
156 | 1301111158 c:\program files (x86)\codeblocks\mingw\include\rpcndr.h
157 |
158 |
159 |
160 | 1301111158 c:\program files (x86)\codeblocks\mingw\include\rpcnsip.h
161 |
162 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winspool.h
163 |
164 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winsock2.h
165 |
166 |
167 | 1301111162 c:\program files (x86)\codeblocks\mingw\include\winsock.h
168 |
169 |
170 |
171 | 1301111154 c:\program files (x86)\codeblocks\mingw\include\mswsock.h
172 |
173 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\ole2.h
174 |
175 |
176 |
177 |
178 |
179 |
180 | 1301111154 c:\program files (x86)\codeblocks\mingw\include\objbase.h
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 | 1341006776 c:\program files (x86)\codeblocks\mingw\include\stdlib.h
191 | <_mingw.h>
192 |
193 |
194 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\objidl.h
195 |
196 |
197 | 1301111148 c:\program files (x86)\codeblocks\mingw\include\cguid.h
198 |
199 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\olectlid.h
200 |
201 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\oleauto.h
202 |
203 |
204 | 1301111154 c:\program files (x86)\codeblocks\mingw\include\oaidl.h
205 |
206 |
207 |
208 | 1301111156 c:\program files (x86)\codeblocks\mingw\include\oleidl.h
209 |
210 |
211 | 976645372 c:\program files (x86)\codeblocks\mingw\include\gl\glut.h
212 |