Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: light

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

    light

    hi,

    still me I have a new problem. I create a light source and I would like that it stays at the same place after a translation or a rotation. Should I put glLightfv inside the display function or outside (in init function for example). If someone could show me a general structure of an openGL program(what in display, what in init,...) it would be great.

    thank you for any help you can give!!

  2. #2
    Intern Contributor
    Join Date
    Apr 2002
    Location
    Spain
    Posts
    66

    Re: light

    Originally posted by zip7000:
    I create a light source and I would like that it stays at the same place after a translation or a rotation. Should I put glLightfv inside the display function or outside (in init function for example).
    Light positions are modified by the modelview matrix, so translations and rotations affect them, as they were a simple point.

    You must call glLightfv once if you aren't going to change light's properties. That is: you don't need to call glLightfv() every frame.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2002
    Posts
    15

    Re: light

    [QUOTE]Originally posted by Azdo:
    [B] Light positions are modified by the modelview matrix, so translations and rotations affect them, as they were a simple point.

    is there a way so that the translation, and rotation doesn't affect the light?

  4. #4
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: light

    glPushMatrix();
    glLightfv(GL_LIGHTX, GL_POSITION, positionarray);
    glPopMatrix();

    glPushMatrix();
    renderObject1();
    glPopMatrix();

    and so on.

    or just keep modelview as identity.

    V-man
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

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

    Re: light

    Thank you V-man. I have another problem. I would like to apply materials property just for one object. I create a material function and I call this material function when I dra the object but all the objects are affected by the material properties. why?
    here is my materials function
    // materials
    void materials()
    {
    glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT, ambient);
    glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE, diffuse);
    glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR, specular);
    }

  6. #6
    Member Regular Contributor
    Join Date
    Jan 2002
    Location
    Kingston, Jamaica, W.I.
    Posts
    268

    Re: light

    Any call to glMaterial*() remain in effect until glMaterial*() is called again with parameters to change what was initially changed. So either you call glMaterial*() again to recover from the change or you use glPush/Pop() to preserve the material settings after you've finished drawing the desired object. Unfortunately I can't remember the actual Push/Pop combination. Its something like glPushAttrib/glPopAttrib(GL_CURRENT_BIT).

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: light

    Material properties belongs to the lighting attribute group, so
    Code :
    glPushAttrib(GL_LIGHTING_BIT);
    ...
    glPopAttrib();
    will save the current material color, including all other lighting related stuff of course.

    But, if you are unsure which attribute groupe a certain state belongs to, this will always work
    Code :
    glPushAttrib(GL_ALL_ATTRIB_BITS);
    ...
    glPopAttrib();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •