OpenGL Diffuse Lighting bug/question

I am currently doing a flashlight/torchlight using diffuse lighting.
my lighting on chair and table is working. [can’t post url somehow]

But when i shift away and faces my skybox, it turns pitch black with no lighting.

my lighting code:


//Torchlight
    glLightfv(GL_LIGHT7, GL_DIFFUSE, gTorchlightColor);
    glLightfv(GL_LIGHT7, GL_SPECULAR, gSpecularMaterial);
    glLightf(GL_LIGHT7, GL_SPOT_CUTOFF, 10.0f);
    glLightf(GL_LIGHT7, GL_SPOT_EXPONENT, 50.0f);

skybox code:


void skybox2()
{
    glPushMatrix();
    GLfloat properties[] = { 0.2f, 0.2f, 0.2f, 1.0f };
    //
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, properties);
    glBindTexture(GL_TEXTURE_2D, skyboxtexture[FRONT].id);
    //FRONT
    glBegin(GL_QUADS);
    glNormal3f(1, 0, 0);
    glTexCoord2f(0, 0); glVertex3f(100, -25, -75); //bottom left
    glTexCoord2f(0, 1); glVertex3f(100, 75, -75); //upper left
    glTexCoord2f(1, 1); glVertex3f(100, 75, 75); // upper right
    glTexCoord2f(1, 0); glVertex3f(100, -25, 75); //bottom right
    glEnd();

    glBindTexture(GL_TEXTURE_2D, skyboxtexture[RIGHT].id);
    //RIGHT
    glBegin(GL_QUADS);
    glNormal3f(0, 0, 1);
    glTexCoord2f(0, 0); glVertex3f(100, -25, 75); //bottom left
    glTexCoord2f(0, 1); glVertex3f(100, 75, 75); //upper left
    glTexCoord2f(1, 1); glVertex3f(-100, 75, 75); //upper right
    glTexCoord2f(1, 0); glVertex3f(-100, -25, 75); // bottom right
    
    glEnd();

    glBindTexture(GL_TEXTURE_2D, skyboxtexture[BACK].id);
    //BACK
    glBegin(GL_QUADS);
    glNormal3f(-1, 0, 0);
    glTexCoord2f(0, 0); glVertex3f(-100, -25, 75); //bottom left
    glTexCoord2f(0, 1); glVertex3f(-100, 75, 75); //upper left
    glTexCoord2f(1, 1); glVertex3f(-100, 75, -75); //upper right
    glTexCoord2f(1, 0); glVertex3f(-100, -25, -75); //bottom right
    glEnd();

    glBindTexture(GL_TEXTURE_2D, skyboxtexture[LEFT].id);
    //LEFT
    glBegin(GL_QUADS);
    glNormal3f(0, 0, -1);
    glTexCoord2f(0, 0);    glVertex3f(-100, -25, -75); //bottom left
    glTexCoord2f(0, 1); glVertex3f(-100, 75, -75); //upper left
    glTexCoord2f(1, 1); glVertex3f(100, 75, -75); //upper right
    glTexCoord2f(1, 0); glVertex3f(100, -25, -75); //bottom right
    glEnd();

    glBindTexture(GL_TEXTURE_2D, skyboxtexture[BOTTOM].id);
    //BOTTOM
    glBegin(GL_QUADS);
    glNormal3f(0, -1, 0);
    glTexCoord2f(0, 0); glVertex3f(-100, -25, -75); //bottom left
    glTexCoord2f(0, 1); glVertex3f(100, -25, -75); //upper left
    glTexCoord2f(1, 1); glVertex3f(100, -25, 75); //upper right
    glTexCoord2f(1, 0); glVertex3f(-100, -25, 75); //bottom right
    glEnd();

    glBindTexture(GL_TEXTURE_2D, skyboxtexture[TOP].id);
    //TOP
    glBegin(GL_QUADS);
    glNormal3f(0, -1, 0);
    glTexCoord2f(0, 0);    glVertex3f(-100, 75, -75); //bottom left
    glTexCoord2f(0, 1); glVertex3f(100, 75, -75); //upper left
    glTexCoord2f(1, 1); glVertex3f(100, 75, 75); //upper right
    glTexCoord2f(1, 0); glVertex3f(-100, 75, 75); //bottom right
    glEnd();

    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, gNone);
    glPopMatrix();

    glBindTexture( GL_TEXTURE_2D, 0 );
}

I am out of ideas for this situation, can anyone provide me guidance? Thanks a lot!

If the chair and the table are lit correctly, then I would suggest you to use smaller triangles for your skybox.

Hmm, i have no idea why my ambient light is able to work, but diffuse lighting on it doesn’t.

What does it mean when only I point towards corner of each quads, then it lights up with the forchlight effect? If I shift away from the corners, the light is gone.

As I just said, split your quads into smaller ones (or into small triangles). This will work far better.

Ambient light applies the same everywhere. It does not depend on distance neither any angles.

So I will need to subdivide my quads? Can I get any tips/idea on it? Can’t really seem to understand subdividing a quad.

Well, that’s just basic mathematics / logics.

Just have a function that draw a 1*1 quad from a given position, and call this function as much as you need, with incrementing your x and y position. Do the same for the other dimensions.

[QUOTE=Silence;1284605]Well, that’s just basic mathematics / logics.

Just have a function that draw a 1*1 quad from a given position, and call this function as much as you need, with incrementing your x and y position. Do the same for the other dimensions.[/QUOTE]

Stuck doing this approach right now. Can you give me an example?

Come on. It’s just a matter of doing some loops over what you did.

I am sorry for being a nuisance . Managed to do it, but the texcoord loop is giving me problem now.

Perfect !

For the texture coordinates, it should vary between 0 and 1 over the whole quad. You would generally do something like:


tex_coord = relative_current_position_of_vertex / overall_size

And for both directions.

You can post your code so that people can check.

[QUOTE=Silence;1284617]Perfect !

For the texture coordinates, it should vary between 0 and 1 over the whole quad. You would generally do something like:


tex_coord = relative_current_position_of_vertex / overall_size

And for both directions.

[/QUOTE]

I am super lost at this right now.

how do I go about mapping to it, i am lost. Tried many ways but it just mapping all over.

for (int z = 0; z < 75; ++z)
{
for (int y = 0; y < 25; ++y)
{
glTexCoord2f(1, 0);
glNormal3f(-1, 0, 0); glVertex3f(100, -y, z); //bottom right
glTexCoord2f(1, 1);
glNormal3f(-1, 0, 0); glVertex3f(100, z, z); // upper right
glTexCoord2f(0, 1);
glNormal3f(-1, 0, 0); glVertex3f(100, z, -z); //upper left
glTexCoord2f(0, 0);
glNormal3f(-1, 0, 0); glVertex3f(100, -y, -z); //bottom left
}
}

[QUOTE=Silence;1284617]Perfect !

For the texture coordinates, it should vary between 0 and 1 over the whole quad. You would generally do something like:


tex_coord = relative_current_position_of_vertex / overall_size

And for both directions.

You can post your code so that people can check.[/QUOTE]

Okay. New update, after postponing the quad for awhile, went to do other small stuff like blending, I MANAGED TO DO IT TODAY!

for (int i = 0; i < subDiv; ++i)
{
for (int j = 0; j < subDiv; ++j)
{
glTexCoord2f((iunitUV) + unitUV, j * unitUV);
glNormal3f(-1, 0, 0); glVertex3f(100, -25 + (j * testY), -75 + (i + 1) * testZ); //bottom right
glTexCoord2f((i
unitUV) + unitUV, (junitUV) + unitUV);
glNormal3f(-1, 0, 0); glVertex3f(100, -25 + ((j + 1) * testY), -75 + (i + 1) * testZ); // upper right
glTexCoord2f(i * unitUV, (j
unitUV) + unitUV);
glNormal3f(-1, 0, 0); glVertex3f(100, -25 + ((j + 1) * testY), -75 + (i)testZ); //upper left
glTexCoord2f(i
unitUV, j*unitUV);
glNormal3f(-1, 0, 0); glVertex3f(100, -25 + (j * testY), -75 + (i)*testZ); //bottom left
}
}

Now the texture is mapped in one piece! I want to thank you for helping me, really appreciate it!