openGPMP
Open Source Mathematics Package
Macros | Functions
openGL_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 8 of file openGL_torus.c.

Function Documentation

◆ display()

void display ( void  )

Definition at line 10 of file openGL_torus.c.

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

Referenced by main().

◆ init()

void init ( )

Definition at line 34 of file openGL_torus.c.

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

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 47 of file openGL_torus.c.

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

References display(), and init().