Hello,
I have a slight issue: I’m trying to draw a gradient in the background of an OpenGL scene. To do that, the first thing I draw is a GL_QUADS with four vertices of different colours. Now, the tricky thing is that this gradient doesn’t appear on screen, unless there has previously been a call to gluSphere(), even if the sphere is of size zero (I discovered that because I “debugged” the problem by marking the origin of the coordinate system with a sphere).
So, I’m thinking I am probably missing a call to some gl* function, that gluSphere() makes; but I can’t figure out what call I’m missing (and I’ve fiddle a bit with ktrace, but that didn’t help). So, here’s my code: if you comment out the call to gluSphere(), the gradient doesn’t show up any more. Does that ring a bell to someone? Many thanks.
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (-1, 1, -1, 1, -10, 10);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
glClearColor (0, 0, 0, 1);
glShadeModel (GL_SMOOTH);
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
GLfloat mat_shininess[] = { 50.0 };
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
GLfloat light_ambient[] = { 1.0, 1.0, 1.0, 1.0};
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
GLfloat light_position[] = { -3.0, -3.0, 10.0, 0.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
GLUquadric * s = gluNewQuadric();
gluSphere (s, 0.0, 2, 1);
gluDeleteQuadric (s);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_MULTISAMPLE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Draw the gradient
glBegin (GL_QUADS);
float color1[4] = { 0.4, 0.4, 0.4, 1.0 };
float color2[4] = { 0.9, 0.9, 0.9, 1.0 };
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color2);
glVertex3f ( x, -y, -9.9);
glVertex3f (-x, -y, -9.9);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color1);
glVertex3f (-x, y, -9.9);
glVertex3f ( x, y, -9.9);
glEnd ();
glFlush();
PS: I hope it’s not something too common, but I’ve tried googling and reading and could not explain this.