Demos (master): line-smooth: add flat/smooth shading control

Brian Paul brianp at kemper.freedesktop.org
Wed Nov 28 23:56:16 UTC 2012


Module: Demos
Branch: master
Commit: 2c031fdd5bcf80d2f8603c7faf776ae6503cec2d
URL:    http://cgit.freedesktop.org/mesa/demos/commit/?id=2c031fdd5bcf80d2f8603c7faf776ae6503cec2d

Author: Brian Paul <brianp at vmware.com>
Date:   Wed Nov 28 16:54:25 2012 -0700

line-smooth: add flat/smooth shading control

---

 src/trivial/line-smooth.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/trivial/line-smooth.c b/src/trivial/line-smooth.c
index 8b462d2..f235308 100644
--- a/src/trivial/line-smooth.c
+++ b/src/trivial/line-smooth.c
@@ -36,6 +36,7 @@
 
 GLenum doubleBuffer;
 GLboolean smooth = GL_TRUE;
+GLboolean flat = GL_TRUE;
 GLfloat width = 1.0;
 
 
@@ -68,6 +69,9 @@ static void Reshape(int width, int height)
 static void Key(unsigned char key, int x, int y)
 {
    switch (key) {
+   case 'f':
+      flat = !flat;
+      break;
    case 'w':
       width -= 0.5;
       if (width < 0.5)
@@ -84,7 +88,7 @@ static void Key(unsigned char key, int x, int y)
    default:
       return;
    }
-   printf("LineWidth: %g\n", width);
+   printf("LineWidth: %g  FlatShade: %d\n", width, flat);
    glutPostRedisplay();
 }
 
@@ -103,14 +107,16 @@ static void Draw(void)
       glEnable(GL_LINE_SMOOTH);
    }
 
-   glColor3f(1, 1, 1);
+   glShadeModel(flat ? GL_FLAT : GL_SMOOTH);
 
    glBegin(GL_LINES);
    for (a = 0; a < 3.14159; a += 0.2) {
       float x = .9 * cos(a);
       float y = .9 * sin(a);
 
+      glColor3f(1, 0, 1);
       glVertex2f(-x, -y);
+      glColor3f(1, 1, 1);
       glVertex2f( x,  y);
    }
    glEnd();




More information about the mesa-commit mailing list