lighting examplined;
as summarized from this article
The light source has two main properties; light color and surface color.
The light color is comprised of diffuse light, specular light and ambient light. Each of these components have material properties comprised of color values. These values determine how light is reflected off of the material surface. Besides color value, there is a shininess material setting that defines the amount of reflection from a material surface.
The surface color further defines the light by “filtering” the light color. The light source directs light color through the surface color. Once the light color has passed through the surface color, the light color carries the properties of the surface color. If a light source is white, and it is passing through a dim green surface color, the diffuse, specular and ambient lights will appear a brighter green.
Diffuse light is best described as light rays direct from the source;
Ambient light is light reflected off a shiny surface;
Specular light is light scattered from the environment.
“”"”"”
How to simplify light and material:
To define a light:
set diffuse to the color you want the light to be
set specular equal to diffuse
set ambient to 1/4 of diffuse.
To define a material:
set diffuse to the color you want the material to be,
set specular to a gray (white is brightest reflection, black is no reflection)
set ambient to 1/4 of diffuse
“”"”"”"”
I was just messing around,, I have a lot of questions::


code for first image::
package classwork;
import javax.media.opengl.*;
import jocode.*;
import jomodel.*;
/**
*
* Use glEnable(GL.GL_NORMALIZE) to force all normals to a length of 1.
* This is critical to insure consistent lighting when spheres are
* scaled to different sizes (normals will be scaled too!).
*
* Use the EMISSIVE material property to create a glowing sphere.
*
* Use a display list to optimize the sphere rendering.
*/
public class ClemmoLight extends JOApp {
float rotation = 0f;
// Material for planet
JOMaterial material = new JOMaterial();
// Material, glowing (for “light”)
JOMaterial materialE = new JOMaterial();
//JOMaterial materialLeft = new JOMaterial();
//JOMaterial materialRight = new JOMaterial();
// Light position: if last value is 0, then this describes light direction. If 1, then light position.
float lightPosition1[]= { 0f, 0f, -5f, 1f }; //position
float lightPosition2[]= { 0f, 10f, -5f, 0f }; //direction
float lightPosition3[]= { 5f, 0f, -5f, 0f }; //direction
float lightPosition4[]= { 5f, 10f, -5f, 1f }; //direction
//position vs direction? if I want the lighton the left to shine on the left side, would I make this a directional light that is calculated with a negative x axis number?
int goldTextureHandle = 0;
/**
* Main function just creates and runs the application.
*/
public static void main(String args[]) {
ClemmoLight app = new ClemmoLight();
app.run();
}
/**
* Initialize OpenGL
*
*/
public void setup() {
// load gold texture
goldTextureHandle = makeTexture(“images/soapColor.jpg”);
// Set a basic perspective view
setPerspective();
// turn depth testing on
gl.glEnable(GL.GL_DEPTH_TEST);
// turn lighting on (does not create a light, have to do that below)
gl.glEnable(GL.GL_LIGHTING);
gl.glEnable(GL.GL_LIGHT1);
gl.glEnable(GL.GL_LIGHT2);
gl.glEnable(GL.GL_LIGHT3);
gl.glEnable(GL.GL_LIGHT4);
// How to shade faces:
// GL_FLAT — each face has same lighting (looks faceted)
// GL_SMOOTH — lighting is blended across face
gl.glShadeModel(GL.GL_FLAT);
// Tell OpenGL to force all normal lengths to 1,
// so light illuminates all surfaces evenly
gl.glEnable(GL.GL_NORMALIZE);
//———————————————–
// Create light
//———————————————–
// Create a point light (white)middle sphere
setLight(GL.GL_LIGHT1,
new float[] { 1.0f, 1.0f, 1.0f, 1.0f }, // diffuse color
new float[] { 0.2f, 0.2f, 0.2f, 1.0f }, // ambient
new float[] { 1.0f, 1.0f, 1.0f, 1.0f }, // specular
lightPosition1); // position
// Create a point light (Green+Blue)left sphere
setLight(GL.GL_LIGHT2,
new float[] { 0f, 1.0f, 1.0f, 1.0f }, // diffuse color
new float[] { 0.2f, 0.2f, 0.2f, 1.0f }, // ambient
new float[] { 0f, 1.0f, 1.0f, 1.0f }, // specular
lightPosition2); // position
// Create a point light (Red) right sphere
setLight(GL.GL_LIGHT3,
new float[] { 1.0f, 0f, 0f, 1.0f }, // diffuse color
new float[] { 0.2f, 0.2f, 0.2f, 1.0f }, // ambient
new float[] { 1.0f, 0f, 1.0f, 1.0f }, // specular
lightPosition3);
// Create a point light (Red) right sphere
setLight(GL.GL_LIGHT4,
new float[] { 1.0f, 1f, 1f, 1.0f }, // diffuse color
new float[] { 0.5f, 0.5f, 0.5f, 1.0f }, // ambient
new float[] { 1.0f, 1f, 1.0f, 1.0f }, // specular
lightPosition4);
// overall scene lighting
float ambient[] = new float[] { 1f, 1f, 1f, 0f };
setAmbientLight(ambient);
//———————————————–
// Create 2 Materials
//———————————————–
// Red material settings
float mtlDiffuse[] = { 1f, 1f, 1f, 1f }; //blue
float mtlAmbient[] = { 0f, .5f, 0f, 1f }; // red
float mtlSpecular[] = { 1f, 1f, 1f, 1f }; // light gray: reflective
float mtlShininess = 127f; // 0=no highlight, 127=sharp highlight
material.setDiffuse(mtlDiffuse);//reflecting off what is directly lit
material.setAmbient(mtlAmbient);
material.setSpecular(mtlSpecular);
material.setShininess(mtlShininess);
material.apply();
// make a glowing material for the “light”
float mtlEmissive[] = { 1f, 1f, 1f, 1f }; // yellow/white
materialE.setEmission(mtlEmissive);
}
/**
* Render the scene.
*/
public void draw() {
rotation += .5f;
// Clear screen and depth buffer
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
// Select The Modelview Matrix (controls model orientation)
gl.glMatrixMode(GL.GL_MODELVIEW);
// Reset the Modelview matrix
// this resets the coordinate system to center of screen
gl.glLoadIdentity();
// Where is the ‘eye’
glu.gluLookAt(
0f, 2f, 20f, // eye position
0f, 0f, 0f, // target to look at
0f, 1f, 0f); // which way is up
////////////////////////////////////////////////////////////////////////middle sphere
gl.glPushMatrix();
// shiny dark blue material
setMaterial(new float[] {0f, 1f, 1f, 1.0f}, .9f);
// set blue light at same spot as blue sphere
//setLightPosition(GL.GL_LIGHT1, lightPosition1);
{ gl.glTranslatef(0f, 0f, -5f);
gl.glScalef(4f, 4f, 4f);
renderSphere(50);
}
gl.glPopMatrix();
///////////////////////////////////////////////////////////////////////left sphere
gl.glPushMatrix();
// shiny dark blue material
setMaterial(new float[] {1f, 1f, 0f, 1.0f}, 1f);
// set blue light at same spot as blue sphere
setLightPosition(GL.GL_LIGHT2, lightPosition2);
{ gl.glTranslatef(-10f, 0f, -10f);
gl.glScalef(3f, 3f, 3f);
renderSphere(50);
}
gl.glPopMatrix();
///////////////////////////////////////////////////////////////////////right sphere
gl.glPushMatrix();
setMaterial(new float[] {1f, 0f, 1f, 1.0f}, .9f);
// set blue light at same spot as blue sphere
setLightPosition(GL.GL_LIGHT3, lightPosition3);
{ gl.glTranslatef(10f, 0f, -10f);
gl.glScalef(3f, 3f, 3f);
renderSphere(50);
}
gl.glPopMatrix();
///////////////////////////////////////////////////////////////////////table
gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
gl.glPushMatrix();
// shiny dark blue material
setMaterial(new float[] {.5f, 1f, .5f, 1f}, .9f);
// set blue light at same spot as blue sphere
setLightPosition(GL.GL_LIGHT1, lightPosition1);
{ gl.glTranslatef(0f, -70f, -150f);
gl.glScalef(3f, 3f, 10f);
renderCube(10,40);
}
gl.glPopMatrix();
gl.glPushMatrix();
//shiny dark blue material
setMaterial(new float[] {1f, .5f, 1f, 1f}, .9f);
//set blue light at same spot as blue sphere
setLightPosition(GL.GL_LIGHT3, lightPosition3);
{ gl.glTranslatef(80f, -70f, -170f);
gl.glScalef(3f, 3f, 7f);
renderCube(10,40);
}
gl.glPopMatrix();
gl.glPushMatrix();
//shiny dark blue material
setMaterial(new float[] {.7f, .7f, .2f, 1f}, .9f);
//set blue light at same spot as blue sphere
setLightPosition(GL.GL_LIGHT4, lightPosition4);
{ gl.glTranslatef(-80f, -70f, -170f);
gl.glScalef(3f, 3f, 7f);
renderCube(10,40);
}
gl.glPopMatrix();
}
/**
* Reshape() is called when window is resized. Reset the viewport to the new window
* dimensions and call setPerspective() to reset the perspective view. This will use
* the new aspect ratio of the window so the scene will not be squashed or stretched.
*/
public void reshape(int newDisplayWidth, int newDisplayHeight) {
setViewport(0,0,newDisplayWidth,newDisplayHeight);
setPerspective();
}
}