Add support for X11+EGL.
[freeglut] / progs / demos / shapes / shapes.c
index 45f9944..3b1e98e 100644 (file)
@@ -13,6 +13,7 @@
       -    <tt>Esc &nbsp;</tt> Quit
       -    <tt>q Q &nbsp;</tt> Quit
       -    <tt>i I &nbsp;</tt> Show info
+      -    <tt>p P &nbsp;</tt> Toggle perspective or orthographic projection
       -    <tt>= + &nbsp;</tt> Increase \a slices
       -    <tt>- _ &nbsp;</tt> Decreate \a slices
       -    <tt>, < &nbsp;</tt> Decreate \a stacks
@@ -64,6 +65,8 @@ static double orad = 1.0;   /* doubles as size for objects other than Torus */
 static int depth = 4;
 static double offset[ 3 ] = { 0, 0, 0 };
 static GLboolean show_info = GL_TRUE;
+static float ar;
+static GLboolean persProject = GL_TRUE;
 
 /*
  * These one-liners draw particular objects, fetching appropriate
@@ -84,8 +87,6 @@ static void drawSolidIcosahedron(void)         { glutSolidIcosahedron ();
 static void drawWireIcosahedron(void)          { glutWireIcosahedron ();                         }
 static void drawSolidSierpinskiSponge(void)    { glutSolidSierpinskiSponge (depth, offset, orad);}  /* orad doubles as size input */
 static void drawWireSierpinskiSponge(void)     { glutWireSierpinskiSponge (depth, offset, orad); }  /* orad doubles as size input */
-static void drawSolidTeapot(void)              { glutSolidTeapot(orad);                          }  /* orad doubles as size input */
-static void drawWireTeapot(void)               { glutWireTeapot(orad);                           }  /* orad doubles as size input */
 static void drawSolidTorus(void)               { glutSolidTorus(irad,orad,slices,stacks);        }
 static void drawWireTorus(void)                { glutWireTorus (irad,orad,slices,stacks);        }
 static void drawSolidSphere(void)              { glutSolidSphere(orad,slices,stacks);            }  /* orad doubles as size input */
@@ -94,6 +95,24 @@ static void drawSolidCone(void)                { glutSolidCone(orad,orad,slices,
 static void drawWireCone(void)                 { glutWireCone(orad,orad,slices,stacks);          }  /* orad doubles as size input */
 static void drawSolidCylinder(void)            { glutSolidCylinder(orad,orad,slices,stacks);     }  /* orad doubles as size input */
 static void drawWireCylinder(void)             { glutWireCylinder(orad,orad,slices,stacks);      }  /* orad doubles as size input */
+static void drawSolidTeapot(void)
+{
+    /* per Glut manpage, it should be noted that the teapot is rendered
+     * with clockwise winding for front facing polygons...
+     */
+    glFrontFace(GL_CW);
+    glutSolidTeapot(orad);  /* orad doubles as size input */
+    glFrontFace(GL_CCW);
+}
+static void drawWireTeapot(void)
+{
+    /* per Glut manpage, it should be noted that the teapot is rendered
+     * with clockwise winding for front facing polygons...
+     */
+    glFrontFace(GL_CW);
+    glutWireTeapot(orad);  /* orad doubles as size input */
+    glFrontFace(GL_CCW);
+}
 
 #define RADIUS    1.0f
 
@@ -224,16 +243,9 @@ static void shapesPrintf (int row, int col, const char *fmt, ...)
 static void
 resize(int width, int height)
 {
-    const float ar = (float) width / (float) height;
+    ar = (float) width / (float) height;
 
     glViewport(0, 0, width, height);
-
-    glMatrixMode(GL_PROJECTION);
-    glLoadIdentity();
-    glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
-
-    glMatrixMode(GL_MODELVIEW);
-    glLoadIdentity() ;
 }
 
 static void display(void)
@@ -241,6 +253,15 @@ static void display(void)
     const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
     const double a = t*90.0;
 
+    glMatrixMode(GL_PROJECTION);
+    glLoadIdentity();
+    if (persProject)
+        glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
+    else
+        glOrtho(-ar*3, ar*3, -3.0, 3.0, 2.0, 100.0);
+    glMatrixMode(GL_MODELVIEW);
+    glLoadIdentity();
+
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
     glEnable(GL_LIGHTING);
@@ -309,6 +330,9 @@ key(unsigned char key, int x, int y)
     case '0': 
     case ')': ++depth;                    break;
 
+    case 'P':
+    case 'p': persProject=!persProject;   break;
+
     default:
         break;
     }