Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Trouble with light

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    5

    Trouble with light

    I'm using this code for ambient light:
    Code :
    GLfloat light1_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
    	GLfloat light1_diffuse[] = { 0.0, 1.0, 1.0, 1.0 }; 
    	GLfloat light1_specular[] = { 1.0, 1.0, 1.0, 1.0 }; 
    	GLfloat light1_position[] = { 20.0, 0.0, 0.0}; 
    	GLfloat spot_direction[] = { 1.0, 0.0, 0.0 }; 
    	glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient); 
    	glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse); 
    	glLightfv(GL_LIGHT1, GL_SPECULAR, light1_specular);
    	glLightfv(GL_LIGHT1, GL_POSITION, light1_position); 
    	glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.5);
    	glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.5);
    	glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.2);
    	glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 45.0); 
    	glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_direction);
    	glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0);
    	glEnable(GL_LIGHTING);
    	glEnable(GL_LIGHT1);
    but my scene is almost completely dark except when I do not put the line glEnable(GL_LIGHTING).What am I doing wrong?

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: Trouble with light

    Either you use glColor and forgot this :
    glEnable(GL_COLOR_MATERIAL);

    Or you scaled the scene without normalizing the normals. In this case just use :
    glEnable(GL_NORMALIZE);

    EDIT : try without attenuation, by commenting out these lines:
    glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.5);
    glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.5);
    glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.2);

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    5

    Re: Trouble with light

    Ok there is improvement but my scene now looks like this:
    http://img143.imageshack.us/img143/4...ceneaq9.th.jpg
    Can you tell me why?

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: Trouble with light

    1) please don't link to a thumbnail ! Impossible to see anything.
    2) try with a white texture.
    3) use shaders to avoind clamping the color too early

  5. #5
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    5

    Re: Trouble with light

    Thanks!Problem solved.I checked the sphere normals again and corrected the problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •