implemented SUPER key/modifier support on windows
[freeglut] / progs / demos / shapes / shapes.c
index 8d69fc0..09fb5ef 100644 (file)
@@ -5,10 +5,10 @@
     in OpenGLUT.  It may also be useful to see which
     parameters control what behavior in the OpenGLUT
     objects.
     in OpenGLUT.  It may also be useful to see which
     parameters control what behavior in the OpenGLUT
     objects.
+
     Spinning wireframe and solid-shaded shapes are
     displayed.  Some parameters can be adjusted.
     Spinning wireframe and solid-shaded shapes are
     displayed.  Some parameters can be adjusted.
+
    Keys:
       -    <tt>Esc &nbsp;</tt> Quit
       -    <tt>q Q &nbsp;</tt> Quit
    Keys:
       -    <tt>Esc &nbsp;</tt> Quit
       -    <tt>q Q &nbsp;</tt> Quit
@@ -34,7 +34,7 @@
 
     \author  Portions Copyright (C) 2004, the OpenGLUT project contributors. <br>
              OpenGLUT branched from freeglut in February, 2004.
 
     \author  Portions Copyright (C) 2004, the OpenGLUT project contributors. <br>
              OpenGLUT branched from freeglut in February, 2004.
+
     \image   html openglut_shapes.png OpenGLUT Geometric Shapes Demonstration
     \include demos/shapes/shapes.c
 */
     \image   html openglut_shapes.png OpenGLUT Geometric Shapes Demonstration
     \include demos/shapes/shapes.c
 */
@@ -63,7 +63,7 @@ void checkError(const char *functionName)
 }
 
 /*
 }
 
 /*
- * OpenGL 2+ shader mode needs some function and macro definitions, 
+ * OpenGL 2+ shader mode needs some function and macro definitions,
  * avoiding a dependency on additional libraries like GLEW or the
  * GL/glext.h header
  */
  * avoiding a dependency on additional libraries like GLEW or the
  * GL/glext.h header
  */
@@ -283,10 +283,10 @@ GLint getAttribOrUniformLocation(const char* name, GLuint program, GLboolean isA
         GLint attrib = gl_GetAttribLocation(program, name);
         if (attrib == -1)
         {
         GLint attrib = gl_GetAttribLocation(program, name);
         if (attrib == -1)
         {
-            fprintf(stderr, "Warning: Could not bind attrib %s\n", name);  
+            fprintf(stderr, "Warning: Could not bind attrib %s\n", name);
         }
 
         }
 
-               checkError ("getAttribOrUniformLocation");
+        checkError ("getAttribOrUniformLocation");
         return attrib;
     }
     else
         return attrib;
     }
     else
@@ -294,16 +294,16 @@ GLint getAttribOrUniformLocation(const char* name, GLuint program, GLboolean isA
         GLint uniform = gl_GetUniformLocation(program, name);
         if (uniform == -1)
         {
         GLint uniform = gl_GetUniformLocation(program, name);
         if (uniform == -1)
         {
-            fprintf(stderr, "Warning: Could not bind uniform %s\n", name);  
+            fprintf(stderr, "Warning: Could not bind uniform %s\n", name);
         }
 
         }
 
-               checkError ("getAttribOrUniformLocation");
+        checkError ("getAttribOrUniformLocation");
         return uniform;
     }
 }
 
 GLuint program;
         return uniform;
     }
 }
 
 GLuint program;
-GLint attribute_fg_coord = -1, attribute_fg_normal = -1;  
+GLint attribute_fg_coord = -1, attribute_fg_normal = -1;
 GLint uniform_m = -1, uniform_p = -1, uniform_m_3x3_inv_transp = -1;
 GLint shaderReady = 0;  /* Set to 1 when all initialization went well, to -1 when shader somehow unusable. */
 
 GLint uniform_m = -1, uniform_p = -1, uniform_m_3x3_inv_transp = -1;
 GLint shaderReady = 0;  /* Set to 1 when all initialization went well, to -1 when shader somehow unusable. */
 
@@ -425,6 +425,7 @@ static GLboolean persProject = GL_TRUE;
 static GLboolean animateXRot = GL_FALSE;
 static GLboolean useShader   = GL_FALSE;
 static GLboolean visNormals  = GL_FALSE;
 static GLboolean animateXRot = GL_FALSE;
 static GLboolean useShader   = GL_FALSE;
 static GLboolean visNormals  = GL_FALSE;
+static GLboolean flat;
 
 /*
  * Enum to tell drawSizeInfo what to draw for each object
 
 /*
  * Enum to tell drawSizeInfo what to draw for each object
@@ -653,10 +654,15 @@ static void drawInfo()
         shapesPrintf (row++, 1, "Perspective projection (p)");
     else
         shapesPrintf (row++, 1, "Orthographic projection (p)");
         shapesPrintf (row++, 1, "Perspective projection (p)");
     else
         shapesPrintf (row++, 1, "Orthographic projection (p)");
-    if (useShader)
+    if (useShader) {
         shapesPrintf (row++, 1, "Using shader (s)");
         shapesPrintf (row++, 1, "Using shader (s)");
-    else
+    } else {
         shapesPrintf (row++, 1, "Using fixed function pipeline (s)");
         shapesPrintf (row++, 1, "Using fixed function pipeline (s)");
+        if (flat)
+            shapesPrintf (row++, 1, "Flat shading (f)");
+        else
+            shapesPrintf (row++, 1, "Smooth shading (f)");
+    }
     if (animateXRot)
         shapesPrintf (row++, 1, "2D rotation (r)");
     else
     if (animateXRot)
         shapesPrintf (row++, 1, "2D rotation (r)");
     else
@@ -683,6 +689,8 @@ static void display(void)
 
     glutSetOption(GLUT_GEOMETRY_VISUALIZE_NORMALS,visNormals);  /* Normals visualized or not? */
 
 
     glutSetOption(GLUT_GEOMETRY_VISUALIZE_NORMALS,visNormals);  /* Normals visualized or not? */
 
+    glShadeModel(flat ? GL_FLAT : GL_SMOOTH);  /* flat or gouraud shading */
+
     if (useShader && !shaderReady)
         initShader();
 
     if (useShader && !shaderReady)
         initShader();
 
@@ -800,10 +808,10 @@ key(unsigned char key, int x, int y)
     case '.':
     case '>': stacks++;                   break;
 
     case '.':
     case '>': stacks++;                   break;
 
-    case '9': 
+    case '9':
     case '(': if( depth > -1 ) depth--;   break;
 
     case '(': if( depth > -1 ) depth--;   break;
 
-    case '0': 
+    case '0':
     case ')': ++depth;                    break;
 
     case 'P':
     case ')': ++depth;                    break;
 
     case 'P':
@@ -820,6 +828,11 @@ key(unsigned char key, int x, int y)
                 function_index = 0;
         break;
 
                 function_index = 0;
         break;
 
+    case 'F':
+    case 'f':
+        flat ^= 1;
+        break;
+
     case 'N':
     case 'n': visNormals=!visNormals;     break;
 
     case 'N':
     case 'n': visNormals=!visNormals;     break;