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)