summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2015-07-27 16:55:34 -0600
committerBrian Paul <brianp@vmware.com>2015-07-27 16:56:18 -0600
commit398c2ee54e7673f4361c138bc48a4066d62966ee (patch)
treed564247b3bb1eab4bf4464f61329982252a658a9
parentd658af70f5bc2c187688d59162f5e1f9db277a2d (diff)
downloadmesa-demos-398c2ee54e7673f4361c138bc48a4066d62966ee.zip
mesa-demos-398c2ee54e7673f4361c138bc48a4066d62966ee.tar.xz
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.
-rw-r--r--src/tests/line-sample.c23
1 files 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();