Results 1 to 5 of 5

Thread: Lighting a single object

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    3

    Lighting a single object

    How can I go about this? I've done lots of reading, and I just can't find anything regarding it... I'm sure it's just something simple, but it's a surprisingly hard subject to search for.

    Thanks in advance!

    EDIT: I guess it's important to say I'm using PyOpenGL, though it shouldn't make a large difference.

    I've also been having some trouble regarding multiple lights, eg:

    Code :
        glEnable(GL_LIGHT0)
        glLight(GL_LIGHT0, GL_POSITION,  (0, 1, 1, 0))
        glEnable(GL_LIGHT1)
        glLight(GL_LIGHT1, GL_POSITION,  (0, 1, 1, 0))
     
        glLightfv(GL_LIGHT0, GL_POSITION,  (0, 1.5, 1, 0))
        glLightfv(GL_LIGHT1, GL_POSITION,  (0, 1.5, 1, 0))

    As you can see, the code is EXACTLY the same, but with only GL_LIGHT1 and the GL_LIGHT0 blocks commented out, no light appears. Is it necessary to enable 0 before 1 is accessible?

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    458

    Re: Lighting a single object

    Just enable lighting before drawing your object, and disable it, just after, that's all and enough

    So something like this:

    Code :
    drawUnlitObjets();
    glEnable (GL_LIGHTING);
    glenable (GL_LIGHT{X});
    drawLitObjects();
    glDisable (GL_LIGHT{X});
    glDisable (GL_LIGHTING);
    ...

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    3

    Re: Lighting a single object

    Quote Originally Posted by _arts_
    Just enable lighting before drawing your object, and disable it, just after, that's all and enough

    So something like this:

    Code :
    drawUnlitObjets();
    glEnable (GL_LIGHTING);
    glenable (GL_LIGHT{X});
    drawLitObjects();
    glDisable (GL_LIGHT{X});
    glDisable (GL_LIGHTING);
    ...
    I had actually tried that, so I suppose that links into my second problem... any help?

    Quote Originally Posted by Ledivin
    I've also been having some trouble regarding multiple lights, eg:

    Code :
        glEnable(GL_LIGHT0)
        glLight(GL_LIGHT0, GL_POSITION,  (0, 1, 1, 0))
        glEnable(GL_LIGHT1)
        glLight(GL_LIGHT1, GL_POSITION,  (0, 1, 1, 0))
     
        glLightfv(GL_LIGHT0, GL_POSITION,  (0, 1.5, 1, 0))
        glLightfv(GL_LIGHT1, GL_POSITION,  (0, 1.5, 1, 0))

    As you can see, the code is EXACTLY the same, but with only GL_LIGHT1 and the GL_LIGHT0 blocks commented out, no light appears. Is it necessary to enable 0 before 1 is accessible?

  4. #4
    Member Contributor
    Join Date
    Jan 2010
    Posts
    82

    Re: Lighting a single object

    Is it supposed to be a directional or point light?

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    3

    Re: Lighting a single object

    That was actually just me testing; in the end, I wanted one object to just be fully lit, which I couldn't find any simple method of doing, except to actually use a light, though I suppose I could also be wrong there.

    EDIT: Nevermind... I can't believe I never thought of it, but just disabling lighting while drawing the object does it.... hahaha whoops

Similar Threads

  1. Visual artifact with single object rotation
    By Savvy_Fox42 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-15-2014, 01:08 PM
  2. [Solved] Object with single x,y (C++, XCode)
    By toothyXdip in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 07-28-2010, 09:13 PM
  3. How to rotate a single object and not the scene?
    By mobilevisuals in forum OpenGL ES
    Replies: 1
    Last Post: 10-02-2009, 03:59 PM
  4. is it still bad to do all lighting in a single pass?
    By Vexator in forum OpenGL: GLSL
    Replies: 14
    Last Post: 05-13-2007, 10:53 AM
  5. Single sided lighting problem
    By maximian in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-18-2004, 10:12 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