openGPMP
Open Source Mathematics Package
Macros | Functions
torus.c File Reference
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>

Go to the source code of this file.

Macros

#define pi   3.142857
 

Functions

void display ()
 
void init ()
 
int main (int argc, char **argv)
 

Macro Definition Documentation

◆ pi

#define pi   3.142857

Definition at line 40 of file torus.c.

Function Documentation

◆ display()

void display ( void  )

Definition at line 42 of file torus.c.

42  {
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 }

Referenced by main().

◆ init()

void init ( )

Definition at line 66 of file torus.c.

66  {
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 }

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 79 of file torus.c.

79  {
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

References display(), and init().