-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnow.cpp
More file actions
205 lines (178 loc) · 6.11 KB
/
now.cpp
File metadata and controls
205 lines (178 loc) · 6.11 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* GL02Primitive.cpp: Vertex, Primitive and Color
* Draw Simple 2D colored Shapes: quad, triangle and polygon.
*/
#include <GL/glut.h> // GLUT, include glu.h and gl.h
/* Initialize OpenGL Graphics */
void initGL() {
// Set "clearing" or background color
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black and opaque
}
/* Handler for window-repaint event. Call back when the window first appears and
whenever the window needs to be re-painted. */
void display() {
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer with current clearing color
//# BORDER RECTANGLE BOX
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
double w = glutGet( GLUT_WINDOW_WIDTH );
double h = glutGet( GLUT_WINDOW_HEIGHT );
glOrtho( 0, w, 0, h, -1, 1);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
// important
glTranslatef( 0.5, 0.5, 0 );
float offset = 40;
glColor3ub( 255, 0, 0 );
glBegin(GL_LINE_LOOP);
glVertex2f( 0+offset, 0+offset );
glVertex2f( 0+offset, h-offset );
glVertex2f( w-offset, h-offset );
glVertex2f( w-offset, 0+offset );
glEnd();
glBegin(GL_LINES);
glColor3f(1.0,0.0,0.0);
glVertex2f(60,40);
glVertex2f(60,460);
glVertex2f(90,40);
glVertex2f(90,460);
glVertex2f(120,40);
glVertex2f(120,460);
glVertex2f(150,40);
glVertex2f(150,460);
glVertex2f(180,40);
glVertex2f(180,460);
glVertex2f(210,40);
glVertex2f(210,460);
glVertex2f(240,40);
glVertex2f(240,460);
glVertex2f(270,40);
glVertex2f(270,460);
glVertex2f(300,40);
glVertex2f(300,460);
glVertex2f(330,40);
glVertex2f(330,460);
glVertex2f(360,40);
glVertex2f(360,460);
glVertex2f(390,40);
glVertex2f(390,460);
glVertex2f(420,40);
glVertex2f(420,460);
glVertex2f(450,40);
glVertex2f(450,460);
glVertex2f(480,40);
glVertex2f(480,460);
glVertex2f(510,40);
glVertex2f(510,460);
glVertex2f(540,40);
glVertex2f(540,460);
glVertex2f(570,40);
glVertex2f(570,460);
glVertex2f(600,40);
glVertex2f(600,460);
glEnd();
glBegin(GL_LINES);
glColor3f(1.0,0.0,0.0);
glVertex2f(40,60);
glVertex2f(460,60);
glVertex2f(40,90);
glVertex2f(460,90);
glVertex2f(40,120);
glVertex2f(460,120);
glVertex2f(40,150);
glVertex2f(460,150);
glVertex2f(40,180);
glVertex2f(460,180);
glVertex2f(40,210);
glVertex2f(460,210);
glVertex2f(40,240);
glVertex2f(460,240);
glEnd();
////#######
// glBegin(GL_LINE);
// glVertex2f(-30.0,+30.0);
// glVertex2f(-30.0,80.0);
// glEnd();
////#######
// glMatrixMode( GL_PROJECTION );
// glLoadIdentity();
// double w = glutGet( GLUT_WINDOW_WIDTH );
// double h = glutGet( GLUT_WINDOW_HEIGHT );
// glOrtho( 0, w, 0, h, -1, 1);
// glMatrixMode( GL_MODELVIEW );
// glLoadIdentity();
// // important
// glTranslatef( 0.5, 0.5, 0 );
// float offset = 40;
// glColor3ub( 255, 0, 0 );
// glBegin(GL_LINE);
// glVertex2f( 0+offset, 0+offset );
// glVertex2f( 0+offset, h-offset );
// glVertex2f( w-offset, h-offset );
// glVertex2f( w-offset, 0+offset );
// glEnd();
//#DRAW DOTTED LINE
// glPushAttrib(GL_ENABLE_BIT);
// glLineStipple(1, 0xAAAA);
// glEnable(GL_LINE_STIPPLE);
// glBegin(GL_LINES);
// glVertex3f(-.5,.5,-.5);
// glVertex3f(.5,.5,-.5);
// glEnd();
// glPopAttrib();
/////
// Define shapes enclosed within a pair of glBegin and glEnd
// glBegin(GL_QUADS); // Each set of 4 vertices form a quad
// glColor3f(1.0f, 0.0f, 0.0f); // Red
// glVertex2f(-0.8f, 0.1f); // Define vertices in counter-clockwise (CCW) order
// glVertex2f(-0.2f, 0.1f); // so that the normal (front-face) is facing you
// glVertex2f(-0.2f, 0.7f);
// glVertex2f(-0.8f, 0.7f);
// glColor3f(0.0f, 1.0f, 0.0f); // Green
// glVertex2f(-0.7f, -0.6f);
// glVertex2f(-0.1f, -0.6f);
// glVertex2f(-0.1f, 0.0f);
// glVertex2f(-0.7f, 0.0f);
// glColor3f(0.2f, 0.2f, 0.2f); // Dark Gray
// glVertex2f(-0.9f, -0.7f);
// glColor3f(1.0f, 1.0f, 1.0f); // White
// glVertex2f(-0.5f, -0.7f);
// glColor3f(0.2f, 0.2f, 0.2f); // Dark Gray
// glVertex2f(-0.5f, -0.3f);
// glColor3f(1.0f, 1.0f, 1.0f); // White
// glVertex2f(-0.9f, -0.3f);
// glEnd();
// glBegin(GL_TRIANGLES); // Each set of 3 vertices form a triangle
// glColor3f(0.0f, 0.0f, 1.0f); // Blue
// glVertex2f(0.1f, -0.6f);
// glVertex2f(0.7f, -0.6f);
// glVertex2f(0.4f, -0.1f);
// glColor3f(1.0f, 0.0f, 0.0f); // Red
// glVertex2f(0.3f, -0.4f);
// glColor3f(0.0f, 1.0f, 0.0f); // Green
// glVertex2f(0.9f, -0.4f);
// glColor3f(0.0f, 0.0f, 1.0f); // Blue
// glVertex2f(0.6f, -0.9f);
// glEnd();
// glBegin(GL_POLYGON); // These vertices form a closed polygon
// glColor3f(1.0f, 1.0f, 0.0f); // Yellow
// glVertex2f(0.4f, 0.2f);
// glVertex2f(0.6f, 0.2f);
// glVertex2f(0.7f, 0.4f);
// glVertex2f(0.6f, 0.6f);
// glVertex2f(0.4f, 0.6f);
// glVertex2f(0.3f, 0.4f);
// glEnd();
glFlush(); // Render now
}
/* Main function: GLUT runs as a console application starting at main() */
int main(int argc, char** argv) {
glutInit(&argc, argv); // Initialize GLUT
glutCreateWindow("Vertex, Primitive & Color"); // Create window with the given title
glutInitWindowSize(500, 500); // Set the window's initial width & height
glutInitWindowPosition(500, 500); // Position the window's initial top-left corner
glutDisplayFunc(display); // Register callback handler for window re-paint event
initGL(); // Our own OpenGL initialization
glutMainLoop(); // Enter the event-processing loop
return 0;
}