Results 1 to 3 of 3

Thread: Lighting Problem

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2009
    Location
    Invercargill, Southland, New Zealand
    Posts
    17

    Lighting Problem

    Hi. I can't seem to get my scene's lighting to work. I have enabled lighting with glEnable(GL_LIGHTING); .. and i think i have put in proper settings for light zero and done glEnable(GL_LIGHT0); Also tried glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Setting); with high values to see if it has any effect. But none.. what could I be doing wrong?

    Here is the code:

    void SetLighting(void)
    {
    GLfloat LightAmbient[]= { 0.4f, 0.4f, 0.4f, 1.0f };
    GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };
    glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
    GLfloat Pos0[]= { 0.0f, 0.0f, 0.0f};
    glLightfv(GL_LIGHT0, GL_POSITION, Pos0);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    float Setting[4] = {0.5f, 0.5f, 0.5f, 1.0f};
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Setting);
    }

    Thanks.

  2. #2
    Member Contributor
    Join Date
    Mar 2008
    Location
    Singapore
    Posts
    67

    Re: Lighting Problem

    Hi Blain,

    Can you try this:

    GLfloat Pos0[]= { 0.0f, 0.0f, 0.0f, 1.0f};

    Essentially we're sending in an additional value to the position vector besides the x,y,z position.

    The 4th value we send indicates that we want the light to be a "Positional" light as opposed to a "directional" light.


    I hope that works.

    ps: you might want to change your ambient settings to something like:

    GLfloat LightAmbient[]= { 0.4f, 0.0f, 0.0f, 1.0f };

    Then if you get a reddish tint, you'll know for sure you lighting condition is working.

  3. #3
    Senior Member Regular Contributor remdul's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands
    Posts
    346

    Re: Lighting Problem

    And don't forget glNormal!

Similar Threads

  1. Lighting problem
    By stefkos in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-09-2012, 11:36 AM
  2. Lighting problem,
    By dreamspaced in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-18-2005, 11:46 PM
  3. Replies: 4
    Last Post: 09-27-2004, 06:27 AM
  4. Odd problem with lighting...
    By Baltor in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 09-12-2004, 03:49 PM
  5. Lighting problem (opengl + shader lighting)
    By ox1d_47 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-19-2004, 09:43 PM

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