Lighting Problem, need help

Member
Posts: 36
Joined: 2004.10
Post: #1
Hey,

Im trying to make a lighting that is like Daytime, and so i have a code set up to turn on lighting and enable it but my lighting isnt showing anywhere, i set teh ambient to red and diffuse to blue to actually test it if it works or not, so here is my code:

Code:
//Lighting
    
    GLfloat lightpos[]={0.0, 100.0, 0.0, 0.0};
    GLfloat lightColor[4] = {1, 0, 0, 1};
    GLfloat ambientColor[4] = {0, 0, 1, 1};



GLvoid InitGL(GLvoid)
{

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);        //background
    glClearDepth(1.0);            // Enables Clearing Of The Depth Buffer
    
    glDepthFunc(GL_LESS);            // The Type Of Depth Test To Do
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);    // Enables Depth Testing
    glEnable(GL_DEPTH_TEST);
    glShadeModel(GL_SMOOTH);            // Enables Smooth Color Shading


    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambientColor);
    glLightfv(GL_LIGHT0, GL_POSITION,lightpos);

    
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();                // Reset The Projection Matrix

    gluPerspective(45.0f,(GLfloat)kWindowWidth/(GLfloat)kWindowHeight,10.0,10000.0);
                                                                            
    glMatrixMode(GL_MODELVIEW);


}


// DrawGLScene

GLvoid DrawGLScene(GLvoid)
{    

  // LIGHT SET UP
    
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambientColor);
    glLightfv(GL_LIGHT0,GL_POSITION,lightpos);
        

    glutSwapBuffers();
    

}

So there is my code for lighting, and the lighting stuff are in INITGL and DRAWGLSCENE, so please help me and let me know whats wrong.


Thanks,
Quote this message in a reply
Puzzler183
Unregistered
 
Post: #2
Putting a light in a scene won't create a bright spot or anything... You need to add geoemtry to the scene to be lit. And also, that geometry must have its material set or have GL_COLOR_MATERIAL enabled and be colored.
Quote this message in a reply
Member
Posts: 36
Joined: 2004.10
Post: #3
ok i know that, and I have 3d models and walls and floors for my scenery which i didnt put here as my code and i have glEnable(GL_COLOR_MATERIAL); in my initgl, and my models are texture but the light isnt showing.

any other ideas?
:-)
thanks
Quote this message in a reply
Puzzler183
Unregistered
 
Post: #4
Well, when you say the light isn't showing, do you mean your scene is dark? Because like I said, there won't be a bright spot there or anything.

Assuming your scene is dark, do you have correct normal vectors for your polygons? Also, with a light position like that, if that's really far compared to the scale of your scene, it will only light polygons facing in the positive y direction really; others perpendicular to it will be barely lit.

It would be really helpful to see the minimum code that reproduces the problem (like some immediate mode polygons and all the other code).
Quote this message in a reply
Member
Posts: 36
Joined: 2004.10
Post: #5
ok here is all my code:

http://www.rafb.net/paste/results/rcY4PC49.html

Please see whats wrong with it, and please dont take any of my code, please.

thanks
Quote this message in a reply
Puzzler183
Unregistered
 
Post: #6
Hmmm, well right now that isn't working but it's probably because I'm behind a terrible proxy. I'll take a look later though and see what the deal isSmile.
Quote this message in a reply
Puzzler183
Unregistered
 
Post: #7
Ok, I glanced over the code and it looked legitimate... Are you sure the model has legitimate normals that are being loaded?

And what is being drawn? Nothing? Something dark? Something random?
Quote this message in a reply
Member
Posts: 36
Joined: 2004.10
Post: #8
well the obj file has normals already set so i load them in and put it in glNormal, and my model is being Drawn perfect, and so is everything else, and the scenery is pretty litted up, i know that its not dark, but the light is red and blue and i dont see a light of that colro anywhere.

Thanks :-)
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #9
nahid Wrote:[...] my model is being Drawn perfect, and so is everything else, and the scenery is pretty litted up, i know that its not dark, but the light is red and blue and i dont see a light of that colro anywhere.

Actually, in your code you have green and blue:

PHP Code:
GLfloat lightColor[4] = {0101};
GLfloat ambientColor[4] = {0011}; 


Check the scale of your model: are you sure the light is close enough? Maybe too close (inside the object)?

Try setting a key to enable/disable each individual light and see if there are any differences.
Quote this message in a reply
Member
Posts: 36
Joined: 2004.10
Post: #10
alright well,

I found the problem it was because of my textures if i remove the textures then th emlight is shinning but when i put textures on it doesnt, and someone told me to put on glColorMaterial(GL_FRONT, GL_DIFFUSE);

and i tried all the GL_FRONT, GL_BACK, GL_FRONT_AND_BACK and none of them worked, anyone got any other ideas?

thanks
Quote this message in a reply
Member
Posts: 36
Joined: 2004.10
Post: #11
I GOT IT WORKING
i had problems with teh GltexEnvf so now it works.

Well now i want to make it so the light touches Everything in the whole map which owuld be really far and so i have this for now:

GLfloat lightpos[]={0.0, 1000.0, 0.0, 1.0};

So thats 1000 up on the Y axis and so how would I make it so it goes everywhere on the map and not just one Spot.

thanks
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Lighting and Multitexturing problem Scribendi 0 2,633 Sep 25, 2005 09:22 PM
Last Post: Scribendi
  Strange lighting problem Duncanla 14 6,076 Mar 1, 2005 02:43 PM
Last Post: Duncanla