I was working with a default picker for creating light objects. You would type something like:
LIGHT light0(AMBIENT);
and it would create an ambient light based off of preset values, and handle the rest of the code elsewhere.
The problem is when I was changing up the input variables for the lightfv( GL_AMBIENCE, float* ambience)
I ran into a problem.
The scene lighting would only work if the viewing position was somewhere near the origin. It didn't make sence. I messed with attenuation, trying to lower it, raise, it, remove it completely, and it didnt seem to have an effect on this issue.
Light just stops working once the camera moves more than just a few units from the origin.
Now if you know of this to be some sort of aspect of OpenGL and I'm just missing a line of code somewhere, let me know. if we're not so lucky keep reading for a few samples of the code and a the details of when this started happening.
Now the code for the light is something liek this
class LIGHT
{
vector3 pos;
color ambience;
color diffuse;
color specular
float shine;
float attenuation;
LIGHT(LIGHT_PRESET);
void Enable()
void Update()
};
I'm using a color code like this:
struct color
{
float r, g, b, a;
void Set(float, float, float);
float* pFloat(); // this returns an array of 4 numbers like the ones the light needs as input
};
float* color::pFloat()
{
float floater[] = {r, g, b, a};
return floater;
};
the vector code for light positioning works similarly
struct vector3
{
float x, y, z;
void Set(float, float, float);
float* pFloat();
};
float* color:pFloat()
{
float floater[] = {x, y, z};
return floater;
};
And the light takes those values as such
glLightfv(ID, GL_POSITION, position.pFloat());
glLightfv(ID, GL_DIFFUSE, diffuse.pFloat());
glLightfv(ID, GL_AMBIENT, ambient.pFloat());
The picker works, there was no problem there, but when I tried to change from setting the color values from this:
color[0] = .5;
color[1] = .2;
color[2] = .7;
position[0] = 10;
position[1] = 15;
position[0] = 10;
to something better like this
color.Set(.5, .2, .7);
position.Set(10, 15, 10);
The structs for color and position have functions to easily set themselves, and also produce the float* number array that openGl likes to use for it's light and position color values.
I got this working, and I've used this concept many times, but I ran into this other lighting problem that I just don't understand.
At first it seemed like it wasn't getting the correct positional values and just placing the lights at some far distance place,
then i noticed that it was placing them directly at the center, inside the test object I'm using to work with the lighting.
I output the values that would be directly sent into the openGl position input, and found them to be fine.
Does anyone have any idea why this is happening?