Disable and enable of lights

This is a discussion on Disable and enable of lights within the Game Programming forums, part of the General Programming Boards category; I was just wondering if I would gain speed or loose it if I disabled lights with glDisable when there ...

  1. #1
    Banned
    Join Date
    Dec 2003
    Posts
    367

    Disable and enable of lights

    I was just wondering if I would gain speed or loose it if I disabled lights with glDisable when there isn't anything to fill their slots and then enable them again when there is, or if I should just give the unused lights some values to make them "dead".

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Well you should disable lighting when you are not using it. Otherwise the calculations will be done and will hender performance.

    Edit:

    Let me elaborate. You can disable/enable individual lights or lighting as a whole.

    Code:
    // Tell opengl we want to use the lighting equation with lights to evalute vertex colors.
    glEnable( GL_LIGHTING );
     
    // Disable the first light..
    glDisable( GL_LIGHT0 );
     
    // Enable the second light..
    glEnable( GL_LIGHT1 );
    In that example if you had both lights enabled it would be slower. I think that's fairly obvious. Another light is just more calculations that have to be performed.

    Code:
    // We don't want to use lights to evaluate vertex colors
    glDisable( GL_LIGHTING );
     
    // Enable the first light..
    glEnable( GL_LIGHT0 );
     
    // Enable the second light..
    glEnable( GL_LIGHT1 );
    In this example, it doesn't matter that both lights are enabled. They won't be contributing anything to the scene because LIGHTING is disabled. Thus leaving them enabled won't hender performance.
    Last edited by MrWizard; 06-02-2004 at 02:03 PM.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    If you are not using a light, absolutely, positively turn it off! Lights tend to use LOTS of processing power; why do you think OpenGL only allows 8 maximum?
    Do not make direct eye contact with me.

  4. #4
    Banned
    Join Date
    May 2004
    Posts
    129
    OpenGL allows 8 maximum but you can implement your own vertex shaders that does the same OpenGL lighting functionality with as many lights as you wants

  5. #5
    Banned
    Join Date
    Dec 2003
    Posts
    367
    Quote Originally Posted by MrWizard
    Well you should disable lighting when you are not using it. Otherwise the calculations will be done and will hender performance.

    Edit:

    Let me elaborate. You can disable/enable individual lights or lighting as a whole.

    Code:
      // Tell opengl we want to use the lighting equation with lights to evalute vertex colors.
      glEnable( GL_LIGHTING );
       
      // Disable the first light..
      glDisable( GL_LIGHT0 );
       
      // Enable the second light..
      glEnable( GL_LIGHT1 );
    In that example if you had both lights enabled it would be slower. I think that's fairly obvious. Another light is just more calculations that have to be performed.

    Code:
      // We don't want to use lights to evaluate vertex colors
      glDisable( GL_LIGHTING );
       
      // Enable the first light..
      glEnable( GL_LIGHT0 );
       
      // Enable the second light..
      glEnable( GL_LIGHT1 );
    In this example, it doesn't matter that both lights are enabled. They won't be contributing anything to the scene because LIGHTING is disabled. Thus leaving them enabled won't hender performance.
    Not trying to be rude, but I already know how OpenGL's lighting works . I was just wondering if I had a player run through a level and I was doing a lot of glDisable's and glEnable's for the lighting slots if it would be slower than just filling the lights with dead values when they weren't being used. Again, I wasn't trying to be rude. I'm just wondering how slow disabling and enabling lights is.

    Lurker: thx

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    No problem, but it wasn't clear how much you knew about OpenGL from your post. Anyways, what do you mean by "dead values" ? If the lights are enabled it doesn't matter what values you have in them they are going to add to the final pixel color through means of the lighting equation. You would have to disable the specific light so that OpenGL knows that the light source won't contribute to the scene.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  7. #7
    Banned
    Join Date
    Dec 2003
    Posts
    367
    I just meant values that would make the light seemingly nonexistent (it would, like you said, contribute to the final pixel colors theoritically though).

  8. #8
    Banned
    Join Date
    May 2004
    Posts
    129
    turn the lights off, it will be faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Change colour of screen and disable mouse
    By Meesa in forum C Programming
    Replies: 2
    Last Post: 05-18-2004, 07:55 AM
  2. how to disable the Keyboard?
    By alanair23 in forum C++ Programming
    Replies: 2
    Last Post: 02-04-2003, 02:56 PM
  3. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 03:59 PM
  4. HowTo disable button in MFC app
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 01-04-2002, 01:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21