Colored OpenGL Lights and lighting stuff

Hello

I’m learning OpenGL lighting and I can’t seem to figure out couple of things. I’ve tried many tutorials and googled, but it’s all so much theory in general and no details and examples. My questions are:

1) how is radius of the light determined?
I noticed it grows with moving light on z-axis away from x=0, y=0 plane, but also when changing light attenuation (falloff) formula and also light color values… so is there a simple rule of thumb how to lit 100 pixels / units or something like that?

2) why diffuse and other color values are fully strong even beyond 1.0f for RGB values?
I thought 1.0 is the max… but you can put more

3) how to do colored lights?
for example for the bottom light in the screenshot I wanted to be green, but it came out weird only few pixels of the ship showing green (engines) and others are dark red…

Thank you all for your time… and now screenshot and code that made lights in it is below the screenshot

For creating light in 2d game (Kev’s space invaders 104 lwjgl example) I use the code at the end, which produces this result:

            GL11.glEnable(GL11.GL_LIGHTING);
            FloatBuffer ltDiffuse = allocFloats(new float[] { 2.0f, 2.0f, 2.0f, 1.0f });
            FloatBuffer ltAmbient = allocFloats(new float[] { 0.0f, 0.0f, 0.0f, 0.0f });
            FloatBuffer ltSpecular = allocFloats(new float[] { 0.0f, 0.0f, 0.0f, 1.0f });
            FloatBuffer ltPosition = allocFloats(new float[] { 250.0f, 120.0f, 10.0f, 1.0f });
//          GL11.glLightf(GL11.GL_LIGHT0, GL11.GL_SPOT_CUTOFF, 70);
            GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, ltDiffuse); // color of the direct illumination
            GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, ltSpecular); // color of the highlight
            GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, ltAmbient); // color of the reflected light
            GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, ltPosition);
            GL11.glLightf(GL11.GL_LIGHT0, GL11.GL_CONSTANT_ATTENUATION, 0.0f);
            GL11.glLightf(GL11.GL_LIGHT0, GL11.GL_LINEAR_ATTENUATION, 0.0f);
            GL11.glLightf(GL11.GL_LIGHT0, GL11.GL_QUADRATIC_ATTENUATION, 0.00001f);
            GL11.glEnable(GL11.GL_LIGHT0); // Enable the light (GL_LIGHT1 - 7)

            FloatBuffer ltDiffuse2 = allocFloats(new float[] { 0.5f, 5.0f, 0.5f, 1.0f });
            FloatBuffer ltAmbient2 = allocFloats(new float[] { 0.01f, 0.01f, 0.01f, 1.0f });
            FloatBuffer ltSpecular2 = allocFloats(new float[] { 0.0f, 5.01f, 0.0f, 1.0f });
            FloatBuffer ltPosition2 = allocFloats(new float[] { 500.0f, 400.0f, 10.0f, 1.0f });
            GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, ltDiffuse2); // color of the direct illumination
            GL11.glLight(GL11.GL_LIGHT1, GL11.GL_SPECULAR, ltSpecular2); // color of the highlight
            GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, ltAmbient2); // color of the reflected light
            GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION, ltPosition2);
            GL11.glLightf(GL11.GL_LIGHT1, GL11.GL_CONSTANT_ATTENUATION, 0.8f);
//            GL11.glLightf(GL11.GL_LIGHT1, GL11.GL_LINEAR_ATTENUATION, 0.0f);
//            GL11.glLightf(GL11.GL_LIGHT1, GL11.GL_QUADRATIC_ATTENUATION, 0.00001f);
            GL11.glEnable(GL11.GL_LIGHT1); // Enable the light (GL_LIGHT1 - 7)

As GL_LIGHT is outdated I was pointed to use shaders … so nevermind about light questions but I’ll leave it in case somebody else with similar problems stumbles upon it

            FloatBuffer ltDiffuse2 = allocFloats(new float[] { 0.5f, 5.0f, 0.5f, 1.0f });

This line was causing your problem: red and blue were multiplied by 0.5, hence red and blue tints showed up in the rendering.

BTW: green was just multiplied by 1.0, not 5.0

yes but I wanted a light that would show an object, but in a greenish color, not to hide everything that is not green. Like if you have lamp with a green lightbulb.

not true, values beyond 1.0 are not cut off and are multiplied so you get a larger radius / intensity of the light, just tested it. With 1.0 I see 3x3 of ships, with 5.0 I see ships like on screenshot that have green engines.

You seem to be misinformed on how light works.

If you have a completely black (dark) room, with a 100% red sphere and you’d turn on a 100% blue light, the sphere would remain to appear black, not some color with a blue-ish tint.

For a real world example: sodium (orange) street lights emit light at of very specific wavelength. You’ll have a very hard time determining the color of say, a car: you absolutely cannot see whether a car is green, blue or gray, only the brightness varies, and that’s solely because the paint of the car is not 100% one color, so it will reflect a range (or set) of wavelengths. Everything looks grayscale orangescale if those sodium lights are the only light source.

Anyway, long story short: OpenGL is doing the correct thing. It multiplies the color of the object with the color of the light.