openGPMP
Open Source Mathematics Package
torus.c
Go to the documentation of this file.
1 /*************************************************************************
2  *
3  * Project
4  * _____ _____ __ __ _____
5  * / ____| __ \| \/ | __ \
6  * ___ _ __ ___ _ __ | | __| |__) | \ / | |__) |
7  * / _ \| '_ \ / _ \ '_ \| | |_ | ___/| |\/| | ___/
8  *| (_) | |_) | __/ | | | |__| | | | | | | |
9  * \___/| .__/ \___|_| |_|\_____|_| |_| |_|_|
10  * | |
11  * |_|
12  *
13  * Copyright (C) Akiel Aries, <akiel@akiel.org>, et al.
14  *
15  * This software is licensed as described in the file LICENSE, which
16  * you should have received as part of this distribution. The terms
17  * among other details are referenced in the official documentation
18  * seen here : https://akielaries.github.io/openGPMP/ along with
19  * important files seen in this project.
20  *
21  * You may opt to use, copy, modify, merge, publish, distribute
22  * and/or sell copies of the Software, and permit persons to whom
23  * the Software is furnished to do so, under the terms of the
24  * LICENSE file.
25  *
26  *
27  *
28  * This software is distributed on an AS IS basis, WITHOUT
29  * WARRANTY OF ANY KIND, either express or implied.
30  *
31  ************************************************************************/
32 
33 /*
34  * Drawing a simple 3 dimensional torus
35  */
36 #include <GL/glut.h>
37 #include <math.h>
38 #include <stdio.h>
39 
40 #define pi 3.142857
41 
42 void display() {
43  // setting every pixel in frame buffer to a clear color
44  glClear(GL_COLOR_BUFFER_BIT);
45 
46  glColor3f(1.0, 1.0, 1.0);
47  glutWireTorus(0.5, 3, 15, 30);
48 
49  // being drawing
50  glBegin(GL_POLYGON);
51  glColor3f(1, 0, 0);
52  glVertex3f(0, 0, 0);
53  glVertex3f(10, 0, 0);
54  glColor3f(0, 1, 0);
55  glVertex3f(0, 0, 0);
56  glVertex3f(0, 10, 0);
57  glColor3f(0, 0, 1);
58  glVertex3f(0, 0, 0);
59  glVertex3f(0, 0, 10);
60  glEnd();
61 
62  // flush the draw cmd to display image immediately
63  glFlush();
64 }
65 
66 void init() {
67  glClearColor(0.0, 0.0, 0.0, 1.0);
68  glColor3f(1.0, 1.0, 1.0);
69 
70  glMatrixMode(GL_PROJECTION);
71  glLoadIdentity();
72  gluPerspective(60.0, 4.0 / 3.0, 1, 40);
73 
74  glMatrixMode(GL_MODELVIEW);
75  glLoadIdentity();
76  gluLookAt(4, 6, 5, 0, 0, 0, 0, 1, 0);
77 }
78 
79 int main(int argc, char **argv) {
80  glutInit(&argc, argv);
81  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
82 
83  // Position window at (80,80)-(480,380) and give it a title.
84  glutInitWindowPosition(80, 80);
85  glutInitWindowSize(1000, 800);
86  glutCreateWindow("A Torus on a Plane");
87 
88  // Tell GLUT that whenever the main window needs to be repainted
89  // that it should call the function display().
90  glutDisplayFunc(display);
91  init();
92  glutMainLoop();
93 }
void init()
Definition: torus.c:66
void display()
Definition: torus.c:42
int main(int argc, char **argv)
Definition: torus.c:79