Archived

This topic is now archived and is closed to further replies.

Kiroke

Lighning problem

Recommended Posts

Kiroke    122
Hi! i got a little problem while lighting a couple of things in my scene. I want a red moving light to influence the color of objects in the scene. The main objects are a cylinder in the bottom of the scene and blocks that are in the upper part of the screen. The blocks are little quads and are facing the camera (they are bidimensionnal). Well... ill show u the code i do for initialising the program. lighPosition[] is global and is definined before. The light is moving correctly. { //initialize lightning stuff glEnable(GL_LIGHTING); float diffuseLight[] = { 1.0f, 1.0f, 1.0f, 1.0f}; float specularLight[] = { 1.0f, 1.0f, 1.0f, 1.0f}; float lightPosition[] = { 0.0f, 0.0f, 10.0f, 0.0f}; //ambient light glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); //ball float diffuseLight1[] = { 1.0f, 0.3f, 0.0f, 1.0f}; float specularLight1[] = { 1.0f, 0.3f, 0.0f, 1.0f}; glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseLight1); glLightfv(GL_LIGHT1, GL_SPECULAR, specularLight1); glLightfv(GL_LIGHT1, GL_POSITION, lightPosition1); glMaterialfv(GL_FRONT, GL_SPECULAR, specularLight1); glMateriali(GL_FRONT, GL_SHININESS, 128); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); } I got the feeling that the code is not the problem here but maybe a thing i didnt though of in the concept. Thx alot

Share this post


Link to post
Share on other sites
vincoof    514
Huh, what''s your prob ? Don''t you have any question ?


Here are my comments for your code :

The light GL_LIGHT0 is a directional light. It''s not the exact definition of an ambient light because it does not enlight the whole scene, but it adds some light anyway.
Its diffuse and specular colours are pure white.

The light GL_LIGHT1 position is erroneaous : You did not define any lightPosition1 !!
Its diffuse and specular colours are red-orange.

The object''s specularity is the same red-orange, and any further call to glColor will set both ambient and diffuse components of the object (the ball I presume).

Share this post


Link to post
Share on other sites
Kiroke    122
hehe ok ill ask my true question... why dont i see any color change on my blocks while i see it on the cylinder?? ive defined lighPosition1[] as global

Share this post


Link to post
Share on other sites
vincoof    514
Need... more... details...

That depends on how you move your light (how you change lightPosition1), on where are the planes and the cylinder , and where the objects are facing to (where the normals point).

In fact, for the cylinder it''s not a problem. But if the blocks (quads) have all the normals facing the directional light, then there will be absolutely no change, since they''ll receive full white light. That may be that.
If the quads are white (from directional light), add some red (from moving light) and they''re still white.

Btw, do you set the normals (using glNormal) for your blocks ? You need the normals for lighting.

Share this post


Link to post
Share on other sites
Kiroke    122
yeah ive set normals...the normals are facing the light so ill try to change the full white ligh or to change its direction...thx alot ill repost if any problems and if ur not bored of me :-)

Share this post


Link to post
Share on other sites