I have rendered a spinning model in LWJGL. I have calculated normals and enabled lighting. Now I make a light:

float lightpos[] = {0, 0, 0, 0}; 
FloatBuffer lightposb = BufferUtils.createFloatBuffer(8);
glLight(GL_LIGHT0, GL_POSITION, lightposb);
float light[] = {10, 10, 10, 1}; 
FloatBuffer lightb = BufferUtils.createFloatBuffer(8);
glLight(GL_LIGHT0, GL_SPECULAR, lightb);
glLight(GL_LIGHT0, GL_DIFFUSE, lightb);
glLight(GL_LIGHT0, GL_AMBIENT, lightb);

The model, instead of being lit up, is a dark gray. Also, no color appears on the model, even though I set its color to cyan:

    float color[] = {0,1,1,1};
    FloatBuffer colorb = BufferUtils.createFloatBuffer(8);
    glMaterial(GL_FRONT, GL_AMBIENT, colorb);

UPDATE: Even though I have calculated normals and set them with glNormal3f, the model still appears to be shaded flat.

UPDATE: I HAVE done glEnable(GL_LIGHTING) and glEnable(GL_LIGHT0); that is NOT the problem.

UPDATE: I reversed the order of the light code and the model code and now the model flashes white, then goes dark grey and stays there.

  • \$\begingroup\$ Hi, from your code I can see that lightning is not enabled in it. Try to put this line, glEnable(GL_LIGHTING); after "lightposb.put(lightpos);". Hope this will help you. \$\endgroup\$ – Siddharth-Verma Feb 13 '13 at 9:42
  • \$\begingroup\$ I already did that. \$\endgroup\$ – acer Feb 14 '13 at 1:57
  • \$\begingroup\$ If it is a dark grey and not just black, then you only need to adjust the light settings. If it is black, I cannot help because the code looks fine. Maybe you could include a little more for us? \$\endgroup\$ – Justin Feb 14 '13 at 2:10
  • \$\begingroup\$ This might do the trick, glMaterial(GL_FRONT_AND_BACK, GL_AMBIENT, colorb); ....... Use "glLoadIdentity();" after glLight... Hope this helps :) \$\endgroup\$ – Siddharth-Verma Feb 14 '13 at 5:39
  • \$\begingroup\$ @Sid I have already done glMaterial (see above code) with no effect; glLoadIdentity makes the model dissapear. \$\endgroup\$ – acer Feb 15 '13 at 0:55

What Sid said.

What you are missing is:

  • \$\begingroup\$ I already did that earlier in my code. \$\endgroup\$ – acer Feb 14 '13 at 1:57

In order to use both color and lighting you must activate openGL color materials using:


Hope that helps.


I have solved the problem by adding code from this example: http://forum.codecall.net/topic/66017-simple-lwjgl-lighting/

  • \$\begingroup\$ by using GL_LIGHT_MODEL_AMBIENT or GL_SHININESS ? \$\endgroup\$ – Siddharth-Verma Feb 15 '13 at 6:29
  • \$\begingroup\$ @Sid by enabling color materials, and by changing the light position. \$\endgroup\$ – acer Feb 16 '13 at 17:06

The model showing up as grey is a bi-product of lighting being enabled but no light actually being cast on the object aside from ambient.

Without seeing the where your object is being rendered it is possible that you are rendering within the object itself.

It is also possible that you missed enabling color materials.

Also as a general helper with lighting you might want to look through this to see if you missed anything.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.