0

For some reason I get weird patchy lighting effects/flickering when using glutSolidSphere and the camera is relatively far away from the object. See below:

enter image description here

This also happens with glutSolidCube and I assume the others as well.

I've tried everything I could find in similar questions but no luck with that

I've tried enabling all of the below and different combinations of the below and tried doing so in multiple places

glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_NORMALIZE);
glDepthFunc(GL_LEQUAL);

And also removed all glEnable(GL_TEXTURE_2D); anyhere

The problem happens when I turn on lighting with glEnable(GL_LIGHT0); and occurs with glShadeModel(GL_SMOOTH) and glShadeModel(GL_FLAT) and also if I don't enable GL_COLOR_MATERIAL and even occurs with just a positional light like so:

float light_position[] = {100.0f, 100.0f, 100.0f, 1.0f};
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

What else could this be?

kmecpp
  • 2,371
  • 1
  • 23
  • 38

1 Answers1

0

Finally figured out the problem after forever. Apparently using a very low value (even if above zero) for zNear in the gluPerspective view causes this problem.

The following fixed the problem:

gluPerspective(90, (float) width / (float) height, 0.1f, Z_RANGE);

See: https://gamedev.stackexchange.com/a/55516

kmecpp
  • 2,371
  • 1
  • 23
  • 38