0
\$\begingroup\$

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);
lightposb.put(lightpos);
glLight(GL_LIGHT0, GL_POSITION, lightposb);
float light[] = {10, 10, 10, 1}; 
FloatBuffer lightb = BufferUtils.createFloatBuffer(8);
lightb.put(light);
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);
    colorb.put(color);
    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.

\$\endgroup\$
7
  • \$\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\$ Feb 13, 2013 at 9:42
  • \$\begingroup\$ I already did that. \$\endgroup\$
    – acer
    Feb 14, 2013 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, 2013 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\$ Feb 14, 2013 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, 2013 at 0:55

4 Answers 4

1
\$\begingroup\$

What Sid said.

What you are missing is:

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
\$\endgroup\$
1
  • \$\begingroup\$ I already did that earlier in my code. \$\endgroup\$
    – acer
    Feb 14, 2013 at 1:57
1
\$\begingroup\$

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

glEnable(GL_COLOR_MATERIAL);

Hope that helps.

\$\endgroup\$
0
\$\begingroup\$

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

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

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.

\$\endgroup\$

You must log in to answer this question.

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