5

I was drawing, simultaneously, a vertex colored cube next to a textured cube, with glDrawArrays(), and found that with lighting enabled the textured cube gets "slightly brighter".

After some debugging I found that the very first moment that glEnable(GL_COLOR_MATERIAL) is called, even if glDisable(GL_COLOR_MATERIAL) is immediately called thereafter, causes a "slightly brighter" effect on textured cube!

Here is the short-description:

glEnable(GL_COLOR_MATERIAL);
glDisable(GL_COLOR_MATERIAL);
(...)
glDrawArrays(GL_QUADS, 0, n);

If glEnable(GL_COLOR_MATERIAL) is not called at all, the cube is drawn with a yellow color. And if glEnable(GL_COLOR_MATERIAL) is called, even if followed by glDisable(GL_COLOR_MATERIAL), the cube is drawn slightly brighter yellow, and I can not switch back to the "initial darker yellow cube color".

Can you please tell me if this is the expected behavior?

Edric
  • 24,639
  • 13
  • 81
  • 91
luiez
  • 51
  • 1
  • 5
  • 1
    It certainly seems like a bug. What OS and what type of GPU (NVidia, ATI)? – user1118321 Jan 23 '12 at 01:30
  • WinXP SP3 Home Edition ATI Radeon HD4850 OpenGL Version 6.14.10.11251 Initialy I thought it was a bug but then tested with PFD_GENERIC_FORMAT and got the same result. It seems that after glEnable(GL_COLOR_MATERIAL) the OpenGL state color material is updated on the fly with "some" color. – luiez Jan 24 '12 at 00:36

1 Answers1

1

this is not exactly the expected behavior, but it should be easy to fix. The GL_COLOR_MATERIAL enables overwriting material properties with vertex colors. The bug is that the colors are not only being rewritten on vertex color specification, but also on color material enable (my guess is that it might have been done intentinaly to prevent bugs).

All you need to do to make your cube slightly darker again is to restore the default color material properties (that would probably be diffuse and ambient colors), using glMaterialfv(). You can find the default material colors here.

the swine
  • 10,713
  • 7
  • 58
  • 100