Lights

Hi,
it’s me again.

I found this Tutorial.

But if I use this 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
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) ?

  1. Can’t I make my model brighter than it is normally ?

  2. Why can’t I use specular light ?

  3. What is the difference between “ambient” and “diffuse” ?

  4. What does alpha ( 4. param of “ambient”) mean ?

  5. What does GL_SPOT_CUTOFF make ?

  6. 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 :(.

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.

  1. 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.

  1. 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.

  1. 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:

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.

  1. 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.

  1. 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.

  1. 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).