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 10 of 10

Thread: Lighting Switching Not Wanted

  1. #1
    Intern Contributor
    Join Date
    Aug 2002
    Location
    SomeWhere Lost In France
    Posts
    75

    Lighting Switching Not Wanted

    I've got a problem with OpenGL lighting.
    My problem is that all the lights switch off when my objects are in a given position.
    When I start my app, everything is Ok I got a model (MD2) drawn in front of me and I can rotate it along Y axis (vertical). So at about 60° the lights are sitched off (I can just see the shape of model) everything is black.
    When I resume the rotate and it comes back to the begnning the light is switched on.
    I look at the light status and I told me that it's ON.
    But I must have a problem with glLookAt()..and the rotating translating methods.
    But I've followed somes exemples and my code is the same...
    I must be something so easy that I can see it in my jungle Code
    So if someone had ever seen that...help me
    Thanks for all and sorry for my poor english.
    I'm 4 and I draw

  2. #2
    Junior Member Newbie
    Join Date
    May 2002
    Posts
    26

    Re: Lighting Switching Not Wanted

    you might want to check you light's position.

  3. #3
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,453

    Re: Lighting Switching Not Wanted

    ... esp. when you set it!
    If you set the light's position AFTER you have specified the modelview matrix for your object, the light's position or direction vector will be transformed by that matrix.
    To get a light in a fixed position or direction specify it while your modelview matrix is identity, that is, outside your object's transform operations.

  4. #4
    Intern Contributor
    Join Date
    Aug 2002
    Location
    SomeWhere Lost In France
    Posts
    75

    Re: Lighting Switching Not Wanted

    I don't know what it's wrong in my code.
    Let's see my render function (it's only in this function that I would like to implement light):
    Void RenderAll()
    {
    //Var decl...
    glLoadIdentity();
    gluLookAt(source.x,source.y,source.z,destination.x ,destination.y,destination.z,sin(tilt_angle/180.0*VXE_PI),cos(tilt_angle/180.0*VXE_PI),0.0);

    if(orientation!=NULL)
    {
    //Final:Translation
    glTranslatef(orientation->location.x,orientation->location.y,orientation->location.z);
    //Second:Rotation
    glRotatef(orientation->rotation.x,1.0f,0.0f,0.0f);
    glRotatef(orientation->rotation.y,0.0f,1.0f,0.0f);
    glRotatef(orientation->rotation.z,0.0f,0.0f,1.0f);
    //First:Scaling
    glScalef(orientation->scale.x,orientation->scale.y,orientation->scale.z);
    }
    glEnable(GL_TEXTURE_2D);
    glDisableClientState(GL_EDGE_FLAG_ARRAY);
    glDisableClientState(GL_INDEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);

    glBindTexture(GL_TEXTURE_2D, VXE_GlobalConfig.texture_list[VXE_GlobalConfig.material_list[seg->face_list[0].frontmaterial_id]->texture_number[0]]->GL_id);
    glTexCoordPointer(2,GL_FLOAT,0,seg->mapping_list[0]);
    glNormalPointer(GL_FLOAT,0,seg->normal_list);
    glVertexPointer(3,GL_FLOAT,0,seg->vertex_list);
    glDrawElements(seg->RDS.faceType,seg->RDS.num_vertices * seg->num_faces,GL_UNSIGNED_INT,seg->faceindex_list);
    glEnd();// Done The Faces
    glDisable(GL_TEXTURE_2D);
    }

    I would like to have a light that shine my model and that d'ont move when my "camera" and my object move.
    If my object rotates the light is fixed to the world and it shines the model only on faces that are exposed to the light (want a fixed light at a position that shine my world)
    Please let me see where you put the ligth code and how it works ...
    Because I put my light code everywhere I can and I never had what I want.
    Thanks anyway
    I'm 4 and I draw

  5. #5
    Intern Contributor
    Join Date
    Aug 2002
    Location
    SomeWhere Lost In France
    Posts
    75

    Re: Lighting Switching Not Wanted

    I've found the problem listed A the top concerning Light Switching (it was due to 2 mistake glEnbale(GL_NORMALIZE) that I was thinking Enabled by default and by the fourth parameter of my position light(forgotten).
    But my light still moves with my point of vue.
    How to correct that??
    EveryWhere I place the light, it's not what I want.
    Please Help a poor mouse
    I'm 4 and I draw

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,755

    Re: Lighting Switching Not Wanted

    Have you tried positioning the light just after the "camera" transformations, or with an identity matrix? When you call glLightfv to set the position, that position will be affected by the current modelview matrix.
    Deiussum
    Software Engineer and OpenGL enthusiast

  7. #7
    Intern Contributor
    Join Date
    Aug 2002
    Location
    SomeWhere Lost In France
    Posts
    75

    Re: Lighting Switching Not Wanted

    Yes I've already done this:

    gluLookAt(....);
    glLightfv(GL_LIGHT0,GL_POSITION,light_position);
    if(orientation!=NULL){......

    Then it ligth correclty my object the camera doesn't affect my light: BUT when I rotate my object just after, it's all the time the same faces that are lighted.

    if I put this line after objectif translation and rotation it's the same.
    I don't know why but Rotating my light position=(x=0,y=0,z=15) with GlRotate just before the line has no effect on the lighting.

    I Don't know how to get object moving indépendant of light.
    I'm 4 and I draw

  8. #8
    Intern Contributor
    Join Date
    Aug 2002
    Location
    SomeWhere Lost In France
    Posts
    75

    Re: Lighting Switching Not Wanted

    It seems that glRotate doesn't affect GL_POSITION of light parameter!!!
    Is that true?

    Doing :
    glRotate(3,1,0,0);
    glLightfv(GL_LIGHT0,GL_POSITION,light_position);
    is with no effect on light position??
    If it's true tell me.
    If it's that my problem is basic
    Please can anyone answer that?
    Thanks
    I'm 4 and I draw

  9. #9
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,755

    Re: Lighting Switching Not Wanted

    It should have an effect depending on where you placed your light. A 3 degree rotation isn't a lot, so depending on where you set the light it might not be very apparent. And if you're light is at 0,0,0 you won't notice any change at all.

    For your problem, have you also tried putting the light positioning BEFORE gluLookAt? gluLookAt will also affect your current matrix.
    Deiussum
    Software Engineer and OpenGL enthusiast

  10. #10
    Intern Contributor
    Join Date
    Aug 2002
    Location
    SomeWhere Lost In France
    Posts
    75

    Re: Lighting Switching Not Wanted

    Yes I've already think about that (a little translation form 0,0,0 isn't quite enough to be seen)
    But...
    Thanks for all, I've found my problem
    It was a mistake in my pointer normal area.
    The pointer as been confused with color area.
    So by chance (or evil lol) when the object was moving , the normals affect the lightning as if the light was moving.
    Aouch
    Stupid mistake of mine, that kept me out.
    I was nearly thinking that I had understood no more thant a bit in OpenGL
    Thanks for all 'cause you drive me to found my mistake with your checking list.
    I'm 4 and I draw

Posting Permissions

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