Archived

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

I can't get lighting to work

This topic is 5178 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a 3d maze with collision detection but i want to add some lights (I''m using OpenGL MFC). I used this code in InitGL(): glLightfv(GL_LIGHT1,GL_AMBIENT,ambient); glLightfv(GL_LIGHT1,GL_DIFFUSE,diffuse); glLightfv(GL_LIGHT1,GL_POSITION,position); glEnable(GL_LIGHT1); glEnable(GL_LIGHTING); But it still doesn''t work, what could be wrong? Eyes - fountains running blood... ...That''''s me

Share this post


Link to post
Share on other sites
I can't get any lighting at all... I tried to get my polygons and quads normals and to set them with glNormal3f() function but nothing changed...

Are these function correct for using for finding quad/polygon's normal?

struct VPoint{
float x,y,z;
VPoint(){}
VPoint(float X,float Y,float Z){
x=X; y=Y; z=Z;}
VPoint operator+(VPoint v){
return VPoint(x+v.x, y+v.y, z+v.z);}
VPoint operator-(VPoint v){
return VPoint(x-v.x, y-v.y, z-v.z);}
VPoint operator*(float v){
return VPoint(x*v, y*v, z*v);}
VPoint operator/(float v){
return VPoint(x/v,y/v,z/v);}
};

float Magn(VPoint n){
float m;
m=(float)sqrt((n.x*n.x)+(n.y*n.y)+(n.z*n.z));
return m;}

VPoint Normalise(VPoint n){
float m=Magn(n);
n.x/=m; n.y/=m; n.z/=m;
return n;}

VPoint cross(VPoint v1,VPoint v2){
VPoint normal;
normal.x=(v1.y*v2.z)-(v1.z*v2.y);
normal.y=(v1.z*v2.x)-(v1.x*v2.z);
normal.z=(v1.x*v2.y)-(v1.y*v2.x); return normal;}

/*The one i used like this:
VPoint n;
n=Normal(quad.points);
glNormal3f(n.x,n.y,n.z);

i=number of quad;
VPoint points;
*/
VPoint Normal(VPoint v[QUAD_P]){
VPoint v1=v[2]-v[0];
VPoint v2=v[1]-v[0];
VPoint n=cross(v1,v2);
n=Normalise(n); return n;}

Eyes - fountains running blood...

...That''s me


[edited by - IndrekSnt on October 12, 2003 3:05:56 PM]

Share this post


Link to post
Share on other sites
First - point out the obvious

When you say the lighting doesnt work do you mean everything is BLACK ie: no light source or everything is fully bright ie: lighting is disabled?


If it is black:

Are you directing the light towards the part of the world you are looking at? There is no point in the light being directed towards the camera - it will only lite the back faces.

Are you setting the colours correctly?

Try using GL_LIGHT0 (the default), just enable it - it is already configured for use.



If it is white:
Make sure your ambient light colour is NOT (1.0f,1.0f,1.0f,1.0f).
This will make everything fully-bright - nothing will be shaded.
- Again, try GL_LIGHT0

"Standardize this..."

_Adrenaline_@phayze.com

Share this post


Link to post
Share on other sites
It.s fully brightened and the variables are:

GLfloat ambient[]={0.5f,0.5f,0.5f,1.0f};
GLfloat diffuse[]={1.0f,1.0f,1.0f,1.0f};
GLfloat position[]={0.0f,0.0f,2.0f,1.0f};

Eyes - fountains running blood...

...That''''s me

Share this post


Link to post
Share on other sites
I got lighting working without any material setting. I had a glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); function and when i commented it, something started to work but all textures were green cause i printed some text onto the screen that used glColor3f(0.0f,255.0f,0.0f); ... And when i decided to use no colored fonts it started to work.

I still have 1 problem:
How could i add multible lights with their parameters in arrays. Everything turns black when i use 0 or 1 instead of GL_LIGHT0 in function glEnable(GL_LIGHT0); Does anyone have an idea how to solve this?

Eyes - fountains running blood...

...That''''s me

Share this post


Link to post
Share on other sites
Yes but i''m sure i''m not drawing over 8 lights at the time. This is too confusing for me, got to check some tutorials for portals i think...

Eyes - fountains running blood...

...That''''s me

Share this post


Link to post
Share on other sites