-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathellipse.cpp
62 lines (44 loc) · 1.46 KB
/
ellipse.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
52
53
54
55
56
57
58
59
60
61
62
/*
* Draw red ellipse
*/
#include <windows.h> // for MS Windows
#include <GL/glut.h> // GLUT, include glu.h and gl.h
#include <math.h>
#define PI 3.14
void display_ellipse() {
//glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0.0, 0.0);
for (int i = 0; i < 370; ++i) {
glVertex2f(2.0f*cos(PI*i / 180), sin(PI*i / 180));
}
glEnd();
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINES);
glVertex3f(0.0, -15, 0.0);
glVertex3f(0.0, 15, 0.0);
glVertex3f(-15, 0.0, 0.0);
glVertex3f(15, 0.0, 0.0);
glEnd();
glFlush();
}
/* Main function: GLUT runs as a console application starting at main() */
int main(int argc, char** argv) {
glutInit(&argc, argv); // Initialize GLUT
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
glutInitWindowSize(300, 300); // Set the window's initial width & height
glutInitWindowPosition(100, 100); // Position the window's initial top-left corner
glutCreateWindow("Vertex, Primitive & Color"); // Create window with the given title
glutDisplayFunc(display_ellipse); // Register callback handler for window re-paint event
//glutReshapeFunc(reshape);
glClearColor(0.0, 0.0, 0.0, 0.0);
glColor3f(1.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-2.5, 2.5, -2.5, 2.5);
//initGL(); // Our own OpenGL initialization
glutMainLoop(); // Enter the event-processing loop
return 0;
}