1
\$\begingroup\$

this is my method for lighting:

private void lights(GL gl) {
    float[] LightPos = {0.0f, 0.0f, -1.0f, 1.0f};
    float[] LightAmb = {0.2f, 0.2f, 0.2f, 1.0f};
    float[] LightDif = {0.6f, 0.6f, 0.6f, 1.0f};
    float[] LightSpc = {0.9f, 0.9f, 0.9f, 1.0f};

    gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, LightPos, 0);
    gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, LightAmb, 0);
    gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, LightDif, 0);
    gl.glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, LightSpc, 0);

    gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, LightSpc, 0);

    gl.glEnable(GL.GL_LIGHT0);
    gl.glEnable(GL.GL_LIGHT1);
    gl.glShadeModel(GL.GL_SMOOTH);
    gl.glEnable(GL.GL_LIGHTING);  
}

and i see my objects flat, no specular light.. any ideas?

ps. to render my objects:

gl.glColor3f(1f,0f,0f);
gl.glBegin(GL.GL_TRIANGLES);
for(Triangle t : tubeModel.getTriangles()) {
    gl.glVertex3f(t.v1.x, t.v1.y, t.v1.z);
    gl.glVertex3f(t.v2.x, t.v2.y, t.v2.z);
    gl.glVertex3f(t.v3.x, t.v3.y, t.v3.z);
}
gl.glEnd();

this is what i'm looking for:alt text

this is what i get:alt text

well it's not all black but if i rotate it becomes grey-white

\$\endgroup\$
3
  • \$\begingroup\$ how do you set up material? Add it to your post please. \$\endgroup\$ Commented Jan 8, 2011 at 14:40
  • \$\begingroup\$ sorry i'm not able to log-in with that account and with few post i can't comment. i don't use material.. \$\endgroup\$ Commented Jan 8, 2011 at 17:01
  • \$\begingroup\$ I merged your two accounts you should be able to edit it now \$\endgroup\$ Commented Jan 8, 2011 at 17:41

2 Answers 2

1
\$\begingroup\$

You have to set up material.
Enable material:

glEnable(GL_COLOR_MATERIAL);

Set ambient and diffuse to read from what you set in glColor:

glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);

Setup specular. For complete specular you have to have defined specular reflective color and shinines.

float specReflection[] = { 0.8f, 0.8f, 0.8f, 1.0f };
glMaterialfv(GL_FRONT, GL_SPECULAR, specReflection)
glMateriali(GL_FRONT, GL_SHININESS, 56);

Shinines is between 1 - 128. Bigger value = more bright.

You can find more help on these links:
http://www.falloutsoftware.com/tutorials/gl/gl8.htm
http://www.ozone3d.net/tutorials/glsl_lighting_phong.php

\$\endgroup\$
7
  • \$\begingroup\$ did this answer help? \$\endgroup\$ Commented Jan 9, 2011 at 2:36
  • \$\begingroup\$ houch. thanks to your answer i understand that is not specular light that does not work but diffuse! \$\endgroup\$ Commented Jan 9, 2011 at 11:33
  • \$\begingroup\$ i added some screenshot to explain better! \$\endgroup\$ Commented Jan 9, 2011 at 11:39
  • 1
    \$\begingroup\$ Do you specify normal? \$\endgroup\$ Commented Jan 9, 2011 at 12:04
  • \$\begingroup\$ Do you have enabled depth buffer and correctly set up gl_cullface? I will post some code to help you, after i return from work (yeah workoholics works at sunday too :)) \$\endgroup\$ Commented Jan 9, 2011 at 13:13
2
\$\begingroup\$

Agree with notabene's answer, material needs to be specified.

But for correct lighting (diffuse and specular) you will also need to specify a normals for each vertex. Although the default normal may create (incorrect) specular reflections.

glNormal3f(x,y,z);
\$\endgroup\$
1
  • \$\begingroup\$ This is solved in comments under mine answer. But of course you are right ;) \$\endgroup\$ Commented Jan 12, 2011 at 17:51

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.