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 9 of 9

Thread: Settiing more than 1 Light Source Problem

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2002
    Location
    Kyyv, Kyyv, Ukraine
    Posts
    17

    Settiing more than 1 Light Source Problem

    I want to set 3 Light Sources. I define Array of 3 GLfloat - Position of each Source, and write simple "for" loop inside glBegin and glEnd, where I set Light Properties and write glEnable(LIGHT0 + i) for each source. BU-U-UT, It draws only the first source. Any propositions for rookie? Thnx.
    Best Regards from Kyyv.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,651

    Re: Settiing more than 1 Light Source Problem

    Hi !

    Have a peek at the docs, you can only use glVertex..., glColor... and a few other functions between glBegin and glEnd.

    Mikael

  3. #3
    Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Princeton, NJ
    Posts
    391

    Re: Settiing more than 1 Light Source Problem

    I may be completely misunderstanding you but if your code is

    for(int i=0; i<BLAH; i++)
    {
    //do stuff
    glEnable(GL_LIGHT0 + i)
    //do more
    }
    it won't work
    GL_LIGHT0, GL_LIGHT1 etc are all predefined constants and you cannot get from one to the other just by adding, try using a case statement
    ie
    switch(i)
    {
    case 0:
    glenable(GL_LIGHT0);
    break;
    etc...
    }

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2002
    Location
    Kyyv, Kyyv, Ukraine
    Posts
    17

    Re: Settiing more than 1 Light Source Problem

    Excuse me:
    (from gl.h)
    #define GL_LIGHT0 0x4000
    #define GL_LIGHT1 0x4001
    #define GL_LIGHT2 0x4002
    #define GL_LIGHT3 0x4003
    #define GL_LIGHT4 0x4004
    #define GL_LIGHT5 0x4005
    #define GL_LIGHT6 0x4006
    #define GL_LIGHT7 0x4007

    So, if I add 1 to GL_LIGHT0 I will get GL_LIGHT1
    0x4000 + 1 = 0x4001 (GL_LIGHT1)

    or there is a difference between:
    - 0x4000 + 1 = 0x4001 (GL_LIGHT1)
    and
    - 0x4000 + 0x1 = 0x4001 (GL_LIGHT1)

    sorry then....


    [This message has been edited by moxx (edited 01-13-2002).]

  5. #5
    Junior Member Newbie
    Join Date
    Sep 2001
    Location
    Ottawa, ON, Canada
    Posts
    21

    Re: Settiing more than 1 Light Source Problem

    Do it outside your glBegin and glEnd.

  6. #6
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: Settiing more than 1 Light Source Problem

    mox, your approach of incrementing the constant is correct. Robin Forster has your solution.

  7. #7
    Junior Member Newbie
    Join Date
    Jan 2002
    Location
    Kyyv, Kyyv, Ukraine
    Posts
    17

    Re: Settiing more than 1 Light Source Problem

    Actually, I Use glEnable(GL_LIGHT[i]) only inside "for", And I initialize All Light Attributes there (in the "for" loop), but it's enables only the first Souce (GL_LIGHT0)

  8. #8
    Guest

    Re: Settiing more than 1 Light Source Problem

    Are you setting the light properties properly? (Ex: GL_DIFFUSE, GL_AMBIENT) Because the default light for light0 is {1, 1, 1, 1} (RGBA) i.e white light and for all other light sources it is {0,0,0,1} i.e black. So even if you enable them there will be no difference.

    Hope this helps.

  9. #9
    Junior Member Newbie
    Join Date
    Jan 2002
    Location
    Kyyv, Kyyv, Ukraine
    Posts
    17

    Re: Settiing more than 1 Light Source Problem

    ... finally it works...
    thanx
    I only had to set diffuse, ambient and specular colors separetely.

    My teacher always told me: "max, you should think first then do something and ask somebody"

    thnx

Posting Permissions

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