Search code examples
openglshaderlwjgl

OpenGL Using built-in lighting or custom one with shaders


I just found out that OpenGL has built-in lighting which can be enabled with glEnable(GL_LIGHTING);. Why does tutorials etc. use custom one made with shaders? There must be a reason. What does built-in lighting do worse?


Solution

  • OpenGL has built-in lighting

    No, it does not. All such things were removed from OpenGL in 3.1 and put into the compatibility profile. Which is not required to be supported.

    What does built-in lighting do worse?

    Everything. It does everything worse.

    Fixed function lighting is per-vertex, while shader-based lighting can be whatever you want: per-vertex, per-fragment, whatever. Fixed-function lighting doesn't work with deferred rendering, lighting pre-passes, or various other rendering techniques. Fixed-function lighting can't handle HDR or gamma correct illumination.

    There is nothing that fixed-function lighting can do that user-defined lighting cannot. While there is a ton of stuff that user-defined lighting can do that fixed-function can't.

    It is good that modern OpenGL tutorials don't teach that outdated garbage.