-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtorus.cpp
More file actions
67 lines (56 loc) · 2.17 KB
/
torus.cpp
File metadata and controls
67 lines (56 loc) · 2.17 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
// This is a simple introductory program; its main window contains a static
// picture of a torus. The program illustrates viewing by choosing a camera
// setup with gluLookAt(), which is conceptually simpler than transforming
// objects to move into a predefined view volume.
#ifdef __APPLE_CC__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
// Clears the window and draws the torus.
void display() {
glClear(GL_COLOR_BUFFER_BIT);
// Draw a white torus of outer radius 3, inner radius 0.5 with 15 stacks
// and 30 slices.
glColor3f(1.0, 1.0, 1.0);
glutWireTorus(0.5, 3, 15, 30);
// Draw a red x-axis, a green y-axis, and a blue z-axis. Each of the
// axes are ten units long.
glBegin(GL_LINES);
glColor3f(1, 0, 0); glVertex3f(0, 0, 0); glVertex3f(10, 0, 0);
glColor3f(0, 1, 0); glVertex3f(0, 0, 0); glVertex3f(0, 10, 0);
glColor3f(0, 0, 1); glVertex3f(0, 0, 0); glVertex3f(0, 0, 10);
glEnd();
glFlush();
}
// Sets up global attributes like clear color and drawing color, and sets up
// the desired projection and modelview matrices.
void init() {
// Set the current clear color to black and the current drawing color to
// white.
glClearColor(0.0, 0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
// Set the camera lens to have a 60 degree (vertical) field of view, an
// aspect ratio of 4/3, and have everything closer than 1 unit to the
// camera and greater than 40 units distant clipped away.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 4.0/3.0, 1, 40);
// Position camera at (4, 6, 5) looking at (0, 0, 0) with the vector
// <0, 1, 0> pointing upward.
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(4, 6, 5, 0, 0, 0, 0, 1, 0);
}
// Initializes GLUT, the display mode, and main window; registers callbacks;
// does application initialization; enters the main event loop.
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(80, 80);
glutInitWindowSize(800, 600);
glutCreateWindow("A Simple Torus");
glutDisplayFunc(display);
init();
glutMainLoop();
}