Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

i'm on JOGL 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

share|improve this question
    
how do you set up material? Add it to your post please. –  Notabene Jan 8 '11 at 14:40
    
sorry i'm not able to log-in with that account and with few post i can't comment. i don't use material.. –  nkint Jan 8 '11 at 17:01
    
I merged your two accounts you should be able to edit it now –  Tetrad Jan 8 '11 at 17:41
    
@Tetrad thanks for account merging –  nkint Jan 9 '11 at 11:36

2 Answers 2

up vote 1 down vote accepted

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

share|improve this answer
    
did this answer help? –  Notabene Jan 9 '11 at 2:36
    
houch. thanks to your answer i understand that is not specular light that does not work but diffuse! –  nkint Jan 9 '11 at 11:33
    
i added some screenshot to explain better! –  nkint Jan 9 '11 at 11:39
1  
Do you specify normal? –  Notabene Jan 9 '11 at 12:04
    
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 :)) –  Notabene Jan 9 '11 at 13:13

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);
share|improve this answer
    
This is solved in comments under mine answer. But of course you are right ;) –  Notabene Jan 12 '11 at 17:51

Your Answer

 
discard

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.