I’ve noticed that when I shade an object with diffuse reflection, there is sometimes a colour flipping effect that could be a bug… if you compile the code below you can see the colour flipping occuring on the low-res sphere above. I don’t think there should be any change in surface colour because the light isn’t moving relative to the objects.
I’d really like to get rid of this colour changing artefact… any suggestions?
(I’m using Mesa 3.4.2-10 / Redhat)
Thanks,
Josh.
#include <GL/glut.h>
GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0}; /* Red diffuse light. /
GLfloat light_specular[] = {0.0, 0.0, 0.0, 0.0};
GLfloat light_ambient[] = {0.0, 0.0, 0.0, 0.0};
GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; / Infinite light location. */
float theta = 0;
void
display(void)
{ float s, c;
s = sin(theta);
c = cos(theta);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(5c, 0.0, 5s,
0.0, 0.0, 0.0,
0.0, 1.0, 0.);
// Put infinite light source
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
// Draw spheres
glTranslatef(0,1,0);
glutSolidSphere(1,3,2);
glTranslatef(0,-2,0);
glutSolidSphere(1,20,20);
glutSwapBuffers();
}
void
init(void)
{
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
gluPerspective(40.0, 1.0, 1.0, 10.0);
}
void idle() {
theta += 0.01;
glutPostRedisplay();
}
int
main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow(“Sphere”);
glutDisplayFunc(display);
glutIdleFunc(idle);
glShadeModel(GL_FLAT);
init();
glutMainLoop();
return 0; }