-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path003.c
More file actions
187 lines (168 loc) · 3.82 KB
/
003.c
File metadata and controls
187 lines (168 loc) · 3.82 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "screencasts.h"
/* Poor man's approximation of PI */
#define PI 3.1415926535898
/* Determine number of elements in an array */
#define Length(x) (sizeof (x) / sizeof *(x))
/* Globals */
double dim=2; /* dimension of orthogonal box */
char *windowName = "OpenGL screenscasts 3: Drawing points and lines";
int windowWidth=500;
int windowHeight=500;
/*
* Display the scene
*/
void display()
{
int i;
float angle;
GLfloat vert1[2] = {0.0,0.5};
GLfloat vert2[2] = {0.5,-0.5};
GLfloat vert3[2] = {-0.5,-0.5};
GLfloat vert4[4][2] = { {0.5,0.5},{0.5,-0.5},{-0.5,-0.5},{-0.5,0.5} };
GLfloat color4[4][3] = { {0.0,1.0,0.0},{0.0,0.0,1.0},
{1.0,1.0,0.0},{1.0,0.0,1.0} };
GLfloat color1[3] = {1.0,1.0,1.0};
GLfloat color23[2][3] = { {0.0,1.0,0.0},{0.0,0.0,1.0} };
/* Clear the image */
glClear(GL_COLOR_BUFFER_BIT);
/* Reset previous transforms */
glLoadIdentity();
/* Draw something here */
// GL_POINTS
/*
glPointSize(4.0);
glBegin(GL_POINTS);
glColor3fv( color1 );
glVertex2fv( vert1 );
glColor3fv( color23[0] );
glVertex2fv( vert2 );
glColor3fv( color23[1] );
glVertex2fv( vert3 );
glEnd();
*/
// GL_LINES
// 3 vertexes => 1 lines
/*
glBegin(GL_LINES);
glColor3f(1.0,1.0,1.0);
glVertex2f( 0.0, 0.5);
glColor3f(0.0,1.0,0.0);
glVertex2f( 0.5,-0.5);
glColor3f(0.0,0.0,1.0);
glVertex2f(-0.5,-0.5);
glEnd();
*/
// 4 vertexes => 2 lines
/*
glBegin(GL_LINES);
glColor3f(1.0,1.0,1.0);
glVertex2f( 0.5, 0.5);
glColor3f(0.0,1.0,0.0);
glVertex2f( 0.5,-0.5);
glColor3f(0.0,0.0,1.0);
glVertex2f(-0.5,-0.5);
glColor3f(0.0,1.0,1.0);
glVertex2f(-0.5,0.5);
glEnd();
*/
// GL_LINE_STRIP
/*
glBegin(GL_LINE_STRIP);
glColor3f(1.0,1.0,1.0);
glVertex2f( 0.5, 0.5);
glColor3f(0.0,1.0,0.0);
glVertex2f( 0.5,-0.5);
glColor3f(0.0,0.0,1.0);
glVertex2f(-0.5,-0.5);
glColor3f(0.0,1.0,1.0);
glVertex2f(-0.5,0.5);
glEnd();
*/
// GL_LINE_LOOP
/*
glBegin(GL_LINE_LOOP);
glColor3f(1.0,1.0,1.0);
glVertex2f( 0.5, 0.5);
glColor3f(0.0,1.0,0.0);
glVertex2f( 0.5,-0.5);
glColor3f(0.0,0.0,1.0);
glVertex2f(-0.5,-0.5);
glColor3f(0.0,1.0,1.0);
glVertex2f(-0.5,0.5);
glEnd();
*/
// Other constructs between glBegin and glEnd
/*
glBegin(GL_LINE_LOOP);
for (i = 0; i < Length(color4); i++) {
glColor3fv(color4[i]);
glVertex3fv(vert4[i]);
}
glEnd();
*/
/*
glBegin(GL_LINE_LOOP);
for (i = 0; i < 180; i++) {
angle = 2*PI*i/180;
glVertex2f(cos(angle), sin(angle));
}
glEnd();
*/
// additional functions
glLineWidth(3.0);
glEnable(GL_LINE_STIPPLE);
//glLineStipple(1, 0x00FF);
//glLineStipple(2, 0x00FF);
glLineStipple(3, 0x00FF);
glBegin(GL_LINE_LOOP);
glColor3f(1.0,1.0,1.0);
glVertex2f( 0.5, 0.5);
glColor3f(0.0,1.0,0.0);
glVertex2f( 0.5,-0.5);
glColor3f(0.0,0.0,1.0);
glVertex2f(-0.5,-0.5);
glColor3f(0.0,1.0,1.0);
glVertex2f(-0.5,0.5);
glEnd();
/* Flush and swap */
glFlush();
glutSwapBuffers();
}
/*
* GLUT calls this routine when the window is resized
*/
void reshape(int width,int height)
{
double w2h = (height>0) ? (double)width/height : 1;
glViewport(0,0, width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-dim*w2h,+dim*w2h, -dim,+dim, -dim,+dim);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/*
* windowKey
* ------
* GLUT calls this routine when a non-special key is pressed
*/
void windowKey(unsigned char key,int x,int y)
{
/* Exit on ESC */
if (key == 27) exit(0);
}
/*
* Start up GLUT and tell it what to do
*/
int main(int argc,char* argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(windowWidth,windowHeight);
glutCreateWindow(windowName);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(windowKey);
glutMainLoop();
return 0;
}