CS405 Lab 4: Illumination
                               


Highlights of this lab:

    This lab is an introduction to illumination

Assignment:

    After the lab lecture, you have approximately two weeks of time to:

Online OpenGL Manual


A. Overview of Colors, Materials and Lights

Please refer to glLight*( ) Description.

  • Creating a scene with multiple light sources

    We'll use multiple lights to create a scene. The source code for this can be found in the "Lighting3" subdirectory. Figure 6 shows a rendering of the scene.

    Figure 6: 3D text demonstrating chrome text with colored lights

    The following is the RenderScene( ) member function:


    BOOL CLightingView::RenderScene( void )
    {
    
            // Need to add a check for the font here before assuming it's there...
    //      static GLuint myFont = GenerateDisplayListForFont( "Avalon Quest", 0.2f
    );
            static GLuint myFont = GenerateDisplayListForFont( "Impact", 0.2f );
    
            GLfloat materialSpecular[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
            GLfloat materialShininess[1] = { 128.0f };
            GLfloat materialAmbient[4] = { 0.25f, 0.25f, 0.25f, 1.0f };
            GLfloat materialDiffuse[4] = { 0.4f, 0.4f, 0.4f, 1.0f };
    
        GLfloat local_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
       
            ::glEnable(GL_DEPTH_TEST);
        ::glDepthFunc(GL_LESS);
    
    
        ::glLightModelfv(GL_LIGHT_MODEL_AMBIENT, local_ambient);
    
        GLfloat ambient0[] =  { 0.0f, 0.0f, 0.0f, 1.0f };
        GLfloat diffuse0[] =  { 1.0f, 0.0f, 0.0f, 1.0f };
        GLfloat specular0[] = { 1.0f, 0.0f, 0.0f, 1.0f };
        GLfloat position0[] = { 2.0f, -1.5f, -1.5f, 1.0f };
    
        GLfloat ambient1[] =  { 0.0f, 0.0f, 0.0f, 1.0f };
        GLfloat diffuse1[] =  { 1.0f, 1.0f, 1.0f, 1.0f };
        GLfloat specular1[] = { 0.5f, 0.5f, 0.5f, 1.0f };
        GLfloat position1[] = { 2.0f, 1.0f, -1.0f, 0.0f };
    
        GLfloat ambient2[] =  { 0.0f, 0.0f, 0.0f, 1.0f };
        GLfloat diffuse2[] =  { 0.0f, 0.0f, 1.0f, 1.0f };
        GLfloat specular2[] = { 0.0f, 0.0f, 1.0f, 1.0f };
        GLfloat position2[] = { -0.5f, -0.5f, -1.0f, 1.0f };
    
            GLfloat ambient3[] =  { 0.0f, 0.0f, 0.0f, 1.0f };
        GLfloat diffuse3[] =  { 1.0f, 1.0f, 1.0f, 1.0f };
        GLfloat specular3[] = { 0.0f, 0.0f, 0.0f, 1.0f };
        GLfloat position3[] = { 2.0f, 0.5f, 0.5f, 0.0f };
    
    
            // Disable lighting to draw some simple spheres that
            // represent the lights
            ::glDisable( GL_LIGHTING );
    
            ::glPushMatrix();
            ::glColor3fv( diffuse0 );
            ::glTranslatef( position0[0], position0[1], position0[2] );
            ::auxWireSphere( 0.15f );
    
            ::glPopMatrix();
    
            ::glPushMatrix();
            ::glColor3fv( diffuse1 );
            ::glTranslatef( position1[0], position1[1], position1[2] );
    //      ::auxWireSphere( 0.15f );
            ::glPopMatrix();
    
            ::glPushMatrix();
            ::glColor3fv( diffuse2 );
            ::glTranslatef( position2[0], position2[1], position2[2] );
            ::auxWireSphere( 0.15f );
    
            ::glPopMatrix();
    
            ::glPushMatrix();
            ::glColor3fv( diffuse3 );
            ::glTranslatef( position3[0], position3[1], position3[2] );
    //      ::auxWireSphere( 0.15f );
            ::glPopMatrix();
    
            ::glEnable( GL_LIGHTING );
    
        ::glEnable(GL_LIGHT0);
        ::glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);
        ::glLightfv(GL_LIGHT0, GL_POSITION, position0);
        ::glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);
        ::glLightfv(GL_LIGHT0, GL_SPECULAR, specular0);
    
        ::glEnable(GL_LIGHT1);
        ::glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1);
        ::glLightfv(GL_LIGHT1, GL_POSITION, position1);
        ::glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1);
        ::glLightfv(GL_LIGHT1, GL_SPECULAR, specular1);
    
        ::glEnable(GL_LIGHT2);
        ::glLightfv(GL_LIGHT2, GL_AMBIENT, ambient2);
        ::glLightfv(GL_LIGHT2, GL_POSITION, position2);
        ::glLightfv(GL_LIGHT2, GL_DIFFUSE, diffuse2);
        ::glLightfv(GL_LIGHT2, GL_SPECULAR, specular2);
    
        ::glEnable(GL_LIGHT3);
        ::glLightfv(GL_LIGHT3, GL_AMBIENT, ambient3);
        ::glLightfv(GL_LIGHT3, GL_POSITION, position3);
        ::glLightfv(GL_LIGHT3, GL_DIFFUSE, diffuse3);
        ::glLightfv(GL_LIGHT3, GL_SPECULAR, specular3);
    
            ::glMaterialfv( GL_FRONT, GL_SPECULAR, materialSpecular );
            ::glMaterialfv( GL_FRONT, GL_SHININESS, materialShininess );
            ::glMaterialfv( GL_FRONT, GL_DIFFUSE, materialDiffuse );
            ::glMaterialfv( GL_FRONT, GL_AMBIENT, materialAmbient );
    
            ::glPushMatrix();
            ::glTranslatef( -3.0f, 0.0f, 0.0f );
            GLTextOut( myFont, "OpenGL & Windows" );
            ::glPopMatrix();
    
            return TRUE;
    }
    


    B. A Color Cube Example "color.dsw"
    C. A Lighting Example "LIGHT1.DSW"
    D. Assignment