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

Thread: lighting problem

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2002
    Posts
    28

    lighting problem

    Has anyone here ever had intermittent problems with lighting? I've written a small demo of a few balls spinning around, and occasionally a frame will either become extremely bright (the objects become almost completely white), or really dark. The balls are being drawn using gluSphere() with material properties set using glMaterialfv(). I have ruled out several possible problems:

    i) The normals are correct - after all, they are generated by gl.
    ii) I'm not incorrectly using the GL_PROJECTION matrix mode to set the camera position.
    iii) I don't use glScalef(), so I don't think the normals are being stretched. I tried enabling GL_NORMALIZE, but this did not help.

    The worrying thing is that the problem is intermittent, and I can't think of any reason it does not occur every frame. This also happens on several different machines running different OS's (win9x, 2k, and xp).

    Any suggestions?

    Jimmi

    p.s. I have read immy's post on the advanced board, which _may_ be a similar problem, but did not find a solution there.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Posts
    292

    Re: lighting problem

    What do you mean by normals are created by opengl?

  3. #3
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Nov 2010
    Posts
    2,466

    Re: lighting problem

    did u read the faq?, lots of advice there
    perhaps youre not updating the lights position after every time u position the 'camera'
    if the sphere is the same colour overall ie all black,all grey,all white. then u are supplying differnt normals for each vertice

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2002
    Posts
    28

    Re: lighting problem

    Hi Mancha,
    I am using quadrics to render the spheres with code similar to this:

    GLUQuadric* quad = gluNewQuadric();
    gluQuadricDrawStyle(quad, GLU_FILL);
    gluQuadricOrientation(quad, GLU_OUTSIDE);
    gluQuadricNormals(quad, GLU_SMOOTH);

    gluSphere(quad, 1.0, 20, 20);

    gluDeleteQuadric(quad);

    gluQuadricOrientation and gluQuadricNormals() define the direction of the generated normals (inside or outside) and how they are shaded (smooth, flat etc.). In this case you don't need to specify your own normals using glNormal3f() because the quadric object generates them for you.

    jimmi

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2002
    Posts
    28

    Re: lighting problem

    Hi Zed,
    I don't think that is the problem I set up my lights every time I render (although I shouldn't - inefficient ). The spheres may appear very dark or bright, but they are certainly being shaded. I might put a website up with examples.

    jimmi


    [This message has been edited by jimmi (edited 04-22-2002).]

  6. #6
    Junior Member Newbie
    Join Date
    Apr 2002
    Posts
    28

    Re: lighting problem

    I've put up examples of the problem at www.dcs.shef.ac.uk/~jedge/temp.html I should reiterate that the problem is intermittent - most of the frames are shaded normally, but occaisionally a frame is shaded extremely bright or dark. The only thing I do between frames is change the positions of the objects (rotate them around the origin) or change the manner in which they are shaded (flat/smooth, point/line/fill). After a couple of frames the object will return to normal shading.

    jimmi


    [This message has been edited by jimmi (edited 04-22-2002).]

  7. #7
    Junior Member Newbie
    Join Date
    Apr 2002
    Posts
    28

    Re: lighting problem

    oops ... put in a full stop which screwed the address: www.dcs.shef.ac.uk/~jedge/temp.html

    jimmi

  8. #8
    Senior Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Holland
    Posts
    179

    Re: lighting problem

    What kind of lights are you using, what are their positions and other properties? Directional or positional lights? What attenuation parameters?

    The highlights on the spheres seem to indicate multiple lights (otherwise i would expect the highlights to be elsewhere: the highlight on a sphere on the left side of the image should be more to the right than the highlight on a sphere on the right side of the image).

    Jean-Marc

  9. #9
    Junior Member Newbie
    Join Date
    Apr 2002
    Posts
    28

    Re: lighting problem

    Only one point light source to the right of the images, set using the following code:

    float pos[] = {1, 1, 1};
    float amb[] = {0.6f, 0.6f, 0.6f};

    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glLightfv(GL_LIGHT0, GL_AMBIENT, amb);

    jimmi

  10. #10
    Senior Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Holland
    Posts
    179

    Re: lighting problem

    Originally posted by jimmi:
    Only one point light source to the right of the images, set using the following code:

    float pos[] = {1, 1, 1};
    float amb[] = {0.6f, 0.6f, 0.6f};

    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glLightfv(GL_LIGHT0, GL_AMBIENT, amb);

    jimmi
    Please note: glLightfv expects four parameters for GL_POSITION and GL_AMBIENT, not three...

    If the w component of the position is negative, then unpredictable results may appear.

    HTH

    Jean-Marc

Page 1 of 2 12 LastLast

Similar Threads

  1. Lighting problem
    By stefkos in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-09-2012, 11:36 AM
  2. Lighting problem,
    By dreamspaced in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-18-2005, 11:46 PM
  3. Replies: 4
    Last Post: 09-27-2004, 06:27 AM
  4. Odd problem with lighting...
    By Baltor in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 09-12-2004, 03:49 PM
  5. Lighting problem (opengl + shader lighting)
    By ox1d_47 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-19-2004, 09:43 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