Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: lighting basics

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2004
    Posts
    6

    lighting basics

    I am just starting to read about lighting. I don't understand it all just yet but I do have a question. If I have an object that is multi-colored, how do I preserve the colors in my scene when using opengl lighting? If I just enable lighting without setting parameters for the other functions, glLight and glMaterial, I lose all of the original color of my object. But when setting parameters to the functions, I can never get back to the original color scheme. All I want is a simple stationary white light.

    Thanks, Mike

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

    Re: lighting basics

    Hi !

    OpenGL does not preserve any information for you, every time you render a frame you have to setup everything again, light, colors, transformations and so on.

    Mikael

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2004
    Posts
    6

    Re: lighting basics

    So once I enable lighting the glColor() function calls made between glBegin(...) ... glEnd() become invalid?

    Mike

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

    Re: lighting basics

    Yes

  5. #5
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: lighting basics

    You have your choice.

    OpenGL has the glColorMaterial call to allow you to use these colors as part of the material or to ignore them. To use colors as the attribute(s) specified by the glColorMaterial you must call:

    glEnable(GL_COLOR_MATERIAL);

    In general OpenGL is a state machine, any change you make is permanent unless you change it later. Starting a new frame (with swapbuffers) will not erase old state. The new frame will begin with the same state that existed at the end of the old frame except the contents of the backbuffer will be undefined. State is not remembered however there are mechanisms like stacks you can push that are useful for remembering & restoring state like matrix transformations, calls like glPushMatrix glPopMatrix glPushAttrib and glPopAttrib.

    Display lists will also remember any state calls you send to them.

  6. #6

    Re: lighting basics

    Sorry to use someone else's topic, but i'm having this same problem.
    I don't get dorbie's explanation.. If i use glEnable(GL_COLOR_MATERIAL); it gets the colors again, but the light is gone...
    Could you explain this better or link me to a tut that descibes lighting while affecting it by colors/textures?
    Cheers.

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

    Re: lighting basics

    That tut with source seems pretty good :
    http://www.eecs.tulane.edu/www/Terry.../Lighting.html

  8. #8
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: lighting basics

    Mental, you need to enable lighting, have a light source on with an appropriate position and have

    glColorMaterial(GL_AMBIENT_AND_DIFFUSE);

    If you just want to test with no light source enable lighting and call

    glColorMaterial(GL_EMISSION);

    That should definitely give you something to look at but the color won't really look like it's affected by the light.

  9. #9

    Re: lighting basics

    Well i've taken a look at that tut and i've fixed it now.

  10. #10
    Junior Member Newbie
    Join Date
    Aug 2004
    Posts
    6

    Re: lighting basics

    mental would you post your code or send it to me?

    thanks. mike

Page 1 of 2 12 LastLast

Similar Threads

  1. Basics
    By chanakya.sun in forum OpenCL
    Replies: 7
    Last Post: 08-24-2011, 04:09 PM
  2. basics are confused
    By adhavan in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-30-2009, 12:28 PM
  3. BASICS
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-17-2003, 11:01 PM
  4. basics
    By ramym in forum OpenGL: General
    Replies: 1
    Last Post: 05-29-2003, 10:52 AM
  5. The very basics...
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-09-2001, 09:43 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