Demos (master): line-sample: add flat/smooth and blend toggles

Brian Paul brianp at kemper.freedesktop.org
Mon Jul 27 22:56:07 UTC 2015


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

Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jul 27 16:55:34 2015 -0600

line-sample: add flat/smooth and blend toggles

Press 'f' to toggle flat/smooth shading.
Press 'b' to toggle blending.
Clear window to gray instead of black.

---

 src/tests/line-sample.c |   23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/tests/line-sample.c b/src/tests/line-sample.c
index 70709b4..d55b076 100644
--- a/src/tests/line-sample.c
+++ b/src/tests/line-sample.c
@@ -18,6 +18,9 @@
 static int w, h;
 static float g, lw = 3.0;
 
+static GLboolean Blend = GL_TRUE;
+static GLboolean FlatShade = GL_TRUE;
+
 
 static void
 draw_line_sample(GLboolean smooth, GLboolean stipple, GLfloat width)
@@ -39,7 +42,10 @@ draw_line_sample(GLboolean smooth, GLboolean stipple, GLfloat width)
 
    if (smooth) {
       glEnable(GL_LINE_SMOOTH);
-      glEnable(GL_BLEND);
+      if (Blend)
+         glEnable(GL_BLEND);
+      else
+         glDisable(GL_BLEND);
     }
    else {
       glDisable(GL_LINE_SMOOTH);
@@ -54,7 +60,9 @@ draw_line_sample(GLboolean smooth, GLboolean stipple, GLfloat width)
       float x1 = r1 * cos(i * M_PI / 180.0);
       float y1 = r1 * sin(i * M_PI / 180.0);
 
+      glColor3f(.5, .5, 1);
       glVertex2f(x0, y0);
+      glColor3f(1, 1, 1);
       glVertex2f(x1, y1);
    }
    glEnd();
@@ -98,7 +106,7 @@ Init(void)
    fflush(stdout);
 
    glClearColor(0.0, 0.0, 0.0, 0.0);
-   glShadeModel(GL_FLAT);
+
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    /* pattern: |- -- --- ----   | */
    glLineStipple(2, 0x1eed);
@@ -113,8 +121,11 @@ Draw(void)
 {
    int i;
 
+   glClearColor(0.2, 0.2, 0.2, 0.2);
    glClear(GL_COLOR_BUFFER_BIT);
 
+   glShadeModel(FlatShade ? GL_FLAT : GL_SMOOTH);
+
    for (i = 0; i < 2; i++) {
       float width = i ? lw : 1.0;
       glViewport(0*w, i*h, w, h);
@@ -154,10 +165,16 @@ Key(unsigned char key, int x, int y)
    else if (key == 'W') {
       lw += g;
    }
+   else if (key == 'f') {
+      FlatShade = !FlatShade;
+   }
+   else if (key == 'b') {
+      Blend = !Blend;
+   }
    if (key == 27)
       exit(0);
 
-   printf("line width %.5f\n", lw);
+   printf("line width %.5f  FlatShade = %d  Blend = %d\n", lw, FlatShade, Blend);
    fflush(stdout);
 
    glutPostRedisplay();




More information about the mesa-commit mailing list