Repository navigation
Expand file tree
/
Copy pathdrawline.cpp
More file actions
149 lines (120 loc) · 2.54 KB
/
Copy pathdrawline.cpp
File metadata and controls
149 lines (120 loc) · 2.54 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* GLUT Shapes Demo
*
* Written by Nigel Stewart November 2003
*
* This program is test harness for the sphere, cone
* and torus shapes in GLUT.
*
* Spinning wireframe and smooth shaded shapes are
* displayed until the ESC or q key is pressed. The
* number of geometry stacks and slices can be adjusted
* using the + and - keys.
*/
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
static int slices = 16;
static int stacks = 16;
/* GLUT callback Handlers */
static void resize(int width, int height)
{
const float ar = (float) width / (float) height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-320, 319, -240, 239, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}
void drawline_0(int x0,int y0,int x1, int y1)
{
int x=x0,y=y0;
int dx=x1-x0;
int dy= y1-y0;
int d= 2*dy -dx;
glVertex2i(x, y);
int dE=2*dy;
int dNE=2*(dy-dx);
while(x<x1)
{
if(d<=0)
{
x++ ;
d+=dE;
}
else if(d>0)
{
x++ ;
y++ ;
d+= dNE;
}
glVertex2i(x, y);
}
}
void linedraw(void)
{
drawline_0(-20,30,50,80);
}
static void display(void)
{
int x = 10, y = 20;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(1,1,1);
glBegin(GL_LINES);
glVertex2i(-320, 0);
glVertex2i(319, 0);
glVertex2i(0, -240);
glVertex2i(0, 239);
glEnd();
glBegin(GL_POINTS);
// glVertex2i(x, y+1); /// drawline ekhne call hbe drawpixel(x,y) er bodole glVertex2i likhboo
// glVertex2i(x, y); ///
linedraw();
glEnd();
glutSwapBuffers();
}
static void key(unsigned char key, int x, int y)
{
switch (key)
{
case 27 :
case 'q':
exit(0);
break;
case '+':
slices++;
stacks++;
break;
case '-':
if (slices>3 && stacks>3)
{
slices--;
stacks--;
}
break;
}
glutPostRedisplay();
}
static void idle(void)
{
glutPostRedisplay();
}
/* Program entry point */
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Experiment 01");
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutIdleFunc(idle);
glutMainLoop();
return EXIT_SUCCESS;
}