Demos (master): tests/backspecular: test two-sided lighting and specular color
Brian Paul
brianp at kemper.freedesktop.org
Mon Jan 20 14:38:23 UTC 2014
Module: Demos
Branch: master
Commit: 1e997aad626dfb51e1ffad1fe98e9666de1f0397
URL: http://cgit.freedesktop.org/mesa/demos/commit/?id=1e997aad626dfb51e1ffad1fe98e9666de1f0397
Author: Brian Paul <brianp at vmware.com>
Date: Wed Aug 14 07:19:07 2013 -0600
tests/backspecular: test two-sided lighting and specular color
This was sitting uncommitted in my local tree for a long time.
---
src/tests/CMakeLists.txt | 1 +
src/tests/Makefile.am | 1 +
src/tests/backspecular.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 113 insertions(+)
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index a5a66cf..fe2c24b 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -33,6 +33,7 @@ set (targets
arbvptorus
arbvpwarpmesh
arraytexture
+ backspecular
blendxor
blitfb
bufferobj
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index fccff1a..8f40799 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -66,6 +66,7 @@ noinst_PROGRAMS = \
arbvpwarpmesh \
arraytexture \
auxbuffer \
+ backspecular \
blendxor \
blitfb \
bufferobj \
diff --git a/src/tests/backspecular.c b/src/tests/backspecular.c
new file mode 100644
index 0000000..1a7387c
--- /dev/null
+++ b/src/tests/backspecular.c
@@ -0,0 +1,111 @@
+#include <stdlib.h>
+#include <GL/glut.h>
+
+
+static const float black[4] = { 0, 0, 0, 1 };
+static const float white[4] = { 1, 1, 1, 1 };
+static const float diffuse[4] = { 1, 0, 0, 1 };
+static const float diffuseb[4] = { 0, 1, 0, 1 };
+static const float specular[4] = { 0.5, 0.5, 0.5, 1 };
+static const float ambient[4] = { 0.2, 0.2, 0.2, 1 };
+static const float lightpos[4] = { 0, 0, 10, 0 };
+static const float shininess = 50;
+
+static double angle = 0.0;
+
+static int autorotate = 1;
+static double angle_delta = 1.0;
+static int timeout = 10;
+
+
+static void
+display(void)
+{
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glPushMatrix();
+ glRotated(angle, 0.0, 1.0, 0.0);
+
+ glBegin(GL_QUADS);
+ glColor3f(1, 1, 1);
+ glNormal3d(0, 0, 1);
+ glVertex3d(-1, -1, 0);
+ glVertex3d(+1, -1, 0);
+ glVertex3d(+1, +1, 0);
+ glVertex3d(-1, +1, 0);
+ glEnd();
+
+ glPopMatrix();
+
+ glutSwapBuffers();
+}
+
+
+static void
+timer(int value)
+{
+ angle += angle_delta;
+ glutTimerFunc(timeout, timer, 0);
+ glutPostRedisplay();
+}
+
+
+static void
+key(unsigned char key, int x, int y)
+{
+ if (key == 27) {
+ exit(0);
+ }
+}
+
+
+int
+main(int argc, char **argv)
+{
+ /* init glut */
+ glutInit(&argc, argv);
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
+ glutCreateWindow("Backface specular test");
+ glutDisplayFunc(display);
+ glutKeyboardFunc(key);
+ if (autorotate)
+ glutTimerFunc(timeout, timer, 0);
+
+ /* setup lighting */
+ glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
+ glMaterialfv(GL_BACK, GL_DIFFUSE, diffuseb);
+
+ glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
+ glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shininess);
+
+ glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
+ glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
+ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
+
+ glLightfv(GL_LIGHT0, GL_AMBIENT, black);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
+ glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
+ glLightfv(GL_LIGHT0, GL_SPECULAR, white);
+
+ glDisable(GL_CULL_FACE);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+
+ /* setup camera */
+ glMatrixMode(GL_PROJECTION);
+ gluPerspective(30.0, 1.0, 1.0, 10.0);
+ glMatrixMode(GL_MODELVIEW);
+ gluLookAt(0.0, 0.0, 5.0,
+ 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0);
+
+ /* setup misc */
+ glEnable(GL_DEPTH_TEST);
+ glClearColor(0, 0, 1, 1);
+
+ /* run */
+ glutMainLoop();
+
+ return 0;
+}
More information about the mesa-commit
mailing list