Results 1 to 2 of 2

Thread: Lights

  1. #1
    Senior Member Regular Contributor
    Join Date
    Aug 2009
    Posts
    126

    Lights

    Hi,
    it's me again.

    I found this Tutorial.

    But if I use this code
    Code :
    	glEnable(GL_LIGHTING);
    	glEnable(GL_LIGHT0);
     
    GLfloat spot_direction[] = {0.0, 0.0, -5.0};
    glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION,
    spot_direction);
    glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 90);
    glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 0);
     
    GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
     
    GLfloat light_ambient[] = {1, 1, 1, 1.0};
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
     
    GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);

    1) If I rote my model, the light seems to rotate too
    Code :
    void render(void)	
    {
     
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
     
        static float fXrot = 0.0f;
        static float fYrot = 0.0f;
        static float fZrot = 0.0f;
     
        fXrot += 10.1f * g_fElpasedTime;
        fYrot += 10.2f * g_fElpasedTime;
        fZrot += 10.3f * g_fElpasedTime;
     
        glMatrixMode( GL_MODELVIEW );
        glLoadIdentity();
        glTranslatef( 0.0f, 0.0f, -5.0f );
        glRotatef( fYrot, 0.0f, 1.0f, 0.0f );
     
     
        glBindTexture( GL_TEXTURE_2D, g_textureID );
     
     
    	Model.Display();
     
    	SwapBuffers( g_hDC );
    }

    So what does fYrot do (why do I need it) ?

    2) Can't I make my model brighter than it is normally ?
    3) Why can't I use specular light ?
    4) What is the difference between "ambient" and "diffuse" ?
    5) What does alpha ( 4. param of "ambient") mean ?

    6) What does GL_SPOT_CUTOFF make ?
    7) What does GL_SPOT_EXPONENT make ?

    All my asked params didn't change anything if I canged them...

    Sorry for this long post and its questions, but I couldn't figure this out .


    ^^


  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,661

    Re: Lights

    Quote Originally Posted by DarkShadow44
    1) If I rote my model, the light seems to rotate too
    The MODELVIEW matrix that's active at the time your light source position (and direction vector for spot lights) is being set is used to transform the vector from the object space you give it in to eye space.

    If you don't want the light to be fixed in the same object space as the model you're rotating, you need to use a different MODELVIEW transform when setting the light position/direction than you're using for the model.

    2) Can't I make my model brighter than it is normally ?
    I'm sure you probably can. What are the ambient, diffuse, specular, and emission colors you're setting for your material?

    To see how bright you can get it, set your material EMISSION color to max. Also disable texturing, fogging, and anything else you might have enabled that might dim down your lighting result.

    3) Why can't I use specular light ?
    Sure you can. Why do you think you can't? In order to do so, you need to set your light source's specular color to a non-zero value (check), your material's specular color to a non-zero value (?), and your material's shininess to something reasonable (?).

    And as with any diffuse or specular lighting, you need to make sure you're setting decent vertex normals on your object.

    4) What is the difference between "ambient" and "diffuse" ?
    You need to read the lighting chapter in the OpenGL red book (such as here), and/or read this:

    * Lighting (Lighthouse3D)

    Click next a few times and read the Directional Light I and II pages too, and (especially) look at the pictures, especially the very first set on the first page. The next pages are on doing fragment lighting per pixel. Good info but I wouldn't bother with this yet. The Lighting chapter in the Red book is better for you at this point.

    Ambient is a directionless lighting addition. It's meant to capture multi-bounce lighting effects that the fixed-function pipeline's single bounce model doesn't capture.

    Diffuse is meant to simulate single-bounce highly scattered reflections such as you might get off a very matte ("non-shiny") surface.

    Specular is meant to simulate single-bounce less scattered reflections (more close to mirror reflections) that you might get off shiny surfaces such as plastic or some polished metals.

    5) What does alpha ( 4. param of "ambient") mean ?
    Generally when you see alpha, think "opacity". Typically 1.0 = opaque. 0.0 = fully transparent. Also keep in mind when evaluating the lighting equation, the only alpha that makes any difference is the diffuse term alpha.

    6) What does GL_SPOT_CUTOFF make ?
    Read the lighting chapter. This is the light cone half-angle for positional lights. Set it to 180.0 (the default) and it makes the light source omnidirectional (i.e. disables the light cone). Set it to 0..90, and it changes the width of the light cone.

    7) What does GL_SPOT_EXPONENT make ?
    This determines what the light profile looks like across the width of the light cone you set with SPOT_CUTOFF. Set it to 0 and the light intensity is uniform across the cone. Set it to bigger numbers and it clusters the light closer to the center of the cone, dimming the light toward the edge of the cone (the CUTOFF angle).

Similar Threads

  1. Speed of built in lights v.s. custom lights
    By STTrife in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-23-2013, 05:11 PM
  2. Can I use more than 8 lights?
    By AlexanderSK in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 09-29-2003, 03:02 AM
  3. lights and 3D
    By lara in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 11-11-2002, 07:11 AM
  4. Lights
    By PhireBat in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-07-2001, 06:13 PM
  5. Replies: 13
    Last Post: 11-29-2000, 02:19 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