Results 1 to 6 of 6

Thread: specular lighting does nott wor

  1. #1
    Senior Member Regular Contributor
    Join Date
    Aug 2000
    Location
    Los Angeles, CA, USA
    Posts
    101

    specular lighting does nott wor

    Hi,

    The following code intends to test specular lighting but creates a scene totally dark. If I specify some ambient amount for material, I can see the model. Do I do anything wrong? Your help is appreciated. Tony

    GLfloat light_position0[] = { 0., 0., 100., 0.0 };
    GLfloat light_ambientDiffuse[] = { 0., .02, 0., 1.0};
    GLfloat light_specular[] = { 1., 1., 1., 1.0};

    glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambientDiffuse);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_ambientDiffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);

    glEnable(GL_LIGHT0);

    GLfloat mat_ambientDiffuse[] = { 0.0, 0.0, 0.0, 1.0};
    GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat mat_shininess[] = { 60.0 };
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_ambientDiffuse);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);

  2. #2
    Senior Member Regular Contributor
    Join Date
    Feb 2005
    Location
    South Tyrol, Italy
    Posts
    107

    Re: specular lighting does nott wor

    Since you specify a black color for ambient and diffuse the model will not be visible. Your specular setup looks fine as far as i can tell.
    Whether specular highlights show up depends on your model and camera and light setup.
    You specify a directional lightsource as w is 0 for light_position0. Maybe you can try could try -100 instead of 100 for you z coordinate in the light position and see if it changes anything (Don't know whether for directional lights position specifies a direction vector towards the origin or away from it)

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2002
    Location
    New Jersey
    Posts
    22

    Re: specular lighting does nott wor

    Did you by chance enable lighting by setting glEnable(GL_LIGHTING); ??

  4. #4
    Senior Member Regular Contributor
    Join Date
    Aug 2000
    Location
    Los Angeles, CA, USA
    Posts
    101

    Re: specular lighting does nott wor

    I intended to make ambient and diffuse inactive so that I can observe specular highlights independently. I also tried -100 as you said but nothing shows up. I tried to increase some amount to mat_ambientDiffuse and then the model showed up. It meant that the camera and light setup was ok, right?

    Tony

  5. #5
    V-man
    Guest

    Re: specular lighting does nott wor

    Maybe you need to call
    glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);

    If you aren't using texturing, that call doesn't matter.

    Also, remember that GL does per vertex lighting so it could be the reason why you won't see the specular highlight. It's best to make a highly detailed sphere in this case and it will be visible.

  6. #6
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: specular lighting does nott wor

    As V-man says, that exponent of 60 will give you a very small highlight which may miss a vertex.

    You could also try lowering the exponent to give you a broader specular highlight.

Similar Threads

  1. specular lighting
    By gl_Beginner in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-08-2012, 01:11 AM
  2. How to introduce Specular and Diffuse lighting into Bumped lighting
    By Liable in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 12-06-2004, 05:48 PM
  3. Specular Lighting
    By azcoder in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-11-2003, 09:18 AM
  4. Specular lighting
    By Old GLman in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 11-27-2002, 01:12 PM
  5. Own specular lighting
    By in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 10-29-2002, 04:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean