Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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. – Sid Feb 13 '13 at 9:42
I already did that. – acer Feb 14 '13 at 1:57
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? – Justin Feb 14 '13 at 2:10
This might do the trick, glMaterial(GL_FRONT_AND_BACK, GL_AMBIENT, colorb); ....... Use "glLoadIdentity();" after glLight... Hope this helps :) – Sid Feb 14 '13 at 5:39
@Sid I have already done glMaterial (see above code) with no effect; glLoadIdentity makes the model dissapear. – acer Feb 15 '13 at 0:55

What Sid said.

What you are missing is:

share|improve this answer
I already did that earlier in my code. – 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.

share|improve this answer
up vote 0 down vote accepted

I have solved the problem by adding code from this example:

share|improve this answer
by using GL_LIGHT_MODEL_AMBIENT or GL_SHININESS ? – Sid Feb 15 '13 at 6:29
@Sid by enabling color materials, and by changing the light position. – 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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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