openGPMP
Open Source Mathematics Package
openGL_torus.c
Go to the documentation of this file.
1 /*
2  * Drawing a simple 3 dimensional torus
3  */
4 #include <GL/glut.h>
5 #include <math.h>
6 #include <stdio.h>
7 
8 #define pi 3.142857
9 
10 void display() {
11  // setting every pixel in frame buffer to a clear color
12  glClear(GL_COLOR_BUFFER_BIT);
13 
14  glColor3f(1.0, 1.0, 1.0);
15  glutWireTorus(0.5, 3, 15, 30);
16 
17  // being drawing
18  glBegin(GL_POLYGON);
19  glColor3f(1, 0, 0);
20  glVertex3f(0, 0, 0);
21  glVertex3f(10, 0, 0);
22  glColor3f(0, 1, 0);
23  glVertex3f(0, 0, 0);
24  glVertex3f(0, 10, 0);
25  glColor3f(0, 0, 1);
26  glVertex3f(0, 0, 0);
27  glVertex3f(0, 0, 10);
28  glEnd();
29 
30  // flush the draw cmd to display image immediately
31  glFlush();
32 }
33 
34 void init() {
35  glClearColor(0.0, 0.0, 0.0, 1.0);
36  glColor3f(1.0, 1.0, 1.0);
37 
38  glMatrixMode(GL_PROJECTION);
39  glLoadIdentity();
40  gluPerspective(60.0, 4.0 / 3.0, 1, 40);
41 
42  glMatrixMode(GL_MODELVIEW);
43  glLoadIdentity();
44  gluLookAt(4, 6, 5, 0, 0, 0, 0, 1, 0);
45 }
46 
47 int main(int argc, char **argv) {
48  glutInit(&argc, argv);
49  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
50 
51  // Position window at (80,80)-(480,380) and give it a title.
52  glutInitWindowPosition(80, 80);
53  glutInitWindowSize(1000, 800);
54  glutCreateWindow("A Torus on a Plane");
55 
56  // Tell GLUT that whenever the main window needs to be repainted
57  // that it should call the function display().
58  glutDisplayFunc(display);
59  init();
60  glutMainLoop();
61 }
void init()
Definition: openGL_torus.c:34
void display()
Definition: openGL_torus.c:10
int main(int argc, char **argv)
Definition: openGL_torus.c:47