Problem: The spotlight I've set up with OpenGL won't light up anything behind it, no matter what values I set for GL_SPOT_DIRECTION

    float[] LightDir = new float[]{0,0,-1,0};         
    float[] LightPos = new float[]{0,0,15f,1};

Initialization code for lighting

        glLightModel(GL_LIGHT_MODEL_AMBIENT,asFlippedFloatBuffer(new float[]{0.1f, 0.1f, 0.1f, 1f}));
        glLight(GL_LIGHT0,GL_DIFFUSE,asFlippedFloatBuffer(new float[]{0.5f, 0.5f, 0.5f, 1f}));
        glLight(GL_LIGHT0, GL_POSITION, asFlippedFloatBuffer(new float[]{0, 0, 0, 1}));


Lighting code ran every loop


The Following shows: enter image description here

To try and change the direction I hit a key that does


The angle of the light goes up as expected, but seems to stop turning once it's pointed straight up. Which looks like enter image description here

Which is the problem, it wont turn around. Iv'e tried every possible value for LightDir in all it's values, but I cannot get it to illuminate the back pf the tube. I've even tried to transform to light around the scene with glRotate and glTranslate. The light is supposed to function as a flashlight. Is this something that would be potentially solved with Shaders? Thanks in advance!


Anytime LightDir[2] goes above 0 the light goes dark.

  • \$\begingroup\$ Seems to be caused by per-vertex lighting instead of per-fragment (per-pixel) \$\endgroup\$
    – Kromster
    Jun 3, 2015 at 5:59

1 Answer 1


You're not actually rotating the light - at least not in the direction you think you are.

You said you're using LightDir[1]++ to change the direction of the light. The direction starts as (0, 0, -1) - the negative Z direction (which appears to be towards the camera, in your program).

After you press the "rotate light" key a bunch of times, the light direction will be something like (0, 50, -1) - which is almost straight up (and not normalized).

In other words, it's not "no matter what values I set for GL_SPOT_DIRECTION" - your program doesn't tell OpenGL to make the light point backwards, only to make it point forwards and up. The direction (0, 0, 1) would be backwards.

  • \$\begingroup\$ Understanding that GL_SPOT_DIRECTION is a vector ( right?, just put that toghether after reading your answer. ), I've tried changing all values of the Array, not just LightDir[1], Changing LightDir[2] and LightDir[0] seemed to still cause the same problem \$\endgroup\$ Jun 3, 2015 at 10:17
  • \$\begingroup\$ @WhiteDevelopmentStudios Yes, it's a vector. What did you try changing it to? \$\endgroup\$ Jun 3, 2015 at 19:31
  • \$\begingroup\$ I tried several values for every index. Anytime LightDir[2] goes above one though, it doesn't produce any light. {0,0,-1,0} and {0,0,1,0} don't produce opposite results like they should. I've confirmed this on 2 different computers. \$\endgroup\$ Jun 3, 2015 at 19:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .