Results 1 to 6 of 6

Thread: Lighting Confusion

  1. #1
    Senior Member Regular Contributor
    Join Date
    Sep 2005
    Location
    Dayton
    Posts
    148

    Lighting Confusion

    I am having problems with using lighting. I am drawing a simple 3x3 image that is 3-dimensional. I have successfully drawn it as a wireframe object but when I try to draw it as GL_POLYGON I get a bright white object. I have a sample program that my friend gave me that successfully lights an icosahedron in another program. He said I could use his lighting method in my program to draw the image. Unfortunately, his lighting produces this bright white object for me. Here is what I do to do my lighting:

    In an init function:
    Code :
        mat_specular[0] = 1.0;
       mat_specular[1] = 1.0;
       mat_specular[2] = 1.0;
       mat_specular[3] = 0.15;
       mat_shininess[0] = 50.0;
       mat_solid[0] = 0.75;
       mat_solid[1] = 0.75;
       mat_solid[2] = 0.0;
       mat_solid[3] = 1.0;
    			/* These are properties of light. */
       position[0] = 10.0;
       position[1] = 10.0;
       position[2] = 5.0;
       position[3] = 0.0;
       light_diffuse[0] = 1.0;
       light_diffuse[1] = 1.0;
       light_diffuse[2] = 1.0;
       light_diffuse[3] = 1.0;
       light_specular[0] = 1.0;
       light_specular[1] = 1.0;
       light_specular[2] = 1.0;
       light_specular[3] = 1.0;
     
       glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_solid );
       glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular );
       glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess );
     
       glLightfv( GL_LIGHT0, GL_POSITION, position );
       glLightfv( GL_LIGHT0, GL_DIFFUSE, light_diffuse );
       glLightfv( GL_LIGHT0, GL_SPECULAR, light_specular );
     
       glEnable( GL_LIGHTING );
       glEnable( GL_LIGHT0 );
       glEnable( GL_DEPTH_TEST );
       glEnable( GL_NORMALIZE );
       //glEnable( GL_CULL_FACE );
     
       glFrontFace(GL_CW);
    When I draw my polygons, I do this:
    Code :
                    calcNormal( v, normal );
                   glBegin( GL_POLYGON );
                      glNormal3fv( normal );
                      glVertex3fv( v[0] );
                      glVertex3fv( v[1] );
                      glVertex3fv( v[2] );
                   glEnd( );
    This code is in a loop to draw multiple polygons. Why am I getting bright white objects all the time and not a shaded yellow-ish object like in my sample program. The sample program did not color the polygons at any time. Thanks for your help!!!!

  2. #2
    Senior Member Frequent Contributor Mars_999's Avatar
    Join Date
    Mar 2001
    Location
    Sioux Falls, SD, USA
    Posts
    519

    Re: Lighting Confusion

    Well start with
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_solid );

    and see if that works? If so you are rendering the back side of your polygons. Just a thought off the top of my head....

  3. #3
    Senior Member Regular Contributor
    Join Date
    Sep 2005
    Location
    Dayton
    Posts
    148

    Re: Lighting Confusion

    That didn't help any. It is still just a bright white object. Does it appear something is being done incorrectly? Thanks!

  4. #4
    Senior Member Frequent Contributor
    Join Date
    May 2005
    Location
    Prague, Czech Republic
    Posts
    913

    Re: Lighting Confusion

    What happens if you set specular contribution of light to zero? Do you use textures?

  5. #5
    Senior Member Regular Contributor
    Join Date
    Sep 2005
    Location
    Dayton
    Posts
    148

    Re: Lighting Confusion

    Actually, my problem seems to have come that I initialized my lighting before creating my window. Now that I create my window first and then initialize everything, it appears to be lighting properly. Any idea why this would be that way though? Thanks!

  6. #6
    Senior Member Frequent Contributor
    Join Date
    May 2005
    Location
    Prague, Czech Republic
    Posts
    913

    Re: Lighting Confusion

    The OGL functions needs valid OGL context. Otherwise they do not work.

Similar Threads

  1. Normal Mapping and Lighting space confusion
    By jafrbc in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-20-2014, 08:14 AM
  2. Confusion!
    By Sidney in forum OpenGL: General
    Replies: 2
    Last Post: 07-21-2009, 01:28 AM
  3. Color/Lighting confusion
    By Neelima in forum OpenGL ES
    Replies: 2
    Last Post: 06-15-2004, 09:32 PM
  4. VAR confusion
    By Jan in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 12-14-2002, 02:20 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