package object;

import javax.media.opengl.GL;

public class Light {

	private float position[] = {0, 0, 0, 0};

	private int index;

	public Light(int index) {

		if(index == 0)
			this.index = GL.GL_LIGHT0;

		if(index == 1)
			this.index = GL.GL_LIGHT1;

		if(index == 2)
			this.index = GL.GL_LIGHT2;

		if(index == 3)
			this.index = GL.GL_LIGHT3;

		if(index == 4)
			this.index = GL.GL_LIGHT4;

		if(index == 5)
			this.index = GL.GL_LIGHT5;

		if(index == 6)
			this.index = GL.GL_LIGHT6;

		if(index == 7)
			this.index = GL.GL_LIGHT7;
	}

	public void setPosition(float x, float y, float z) {	
		position[0] = x;
		position[1] = y;
		position[2] = z;
	}

	public void render(GL gl) {

		gl.glEnable(index);

		gl.glLightModeli(GL.GL_LIGHT_MODEL_TWO_SIDE,GL.GL_TRUE);

		gl.glEnable(GL.GL_COLOR_MATERIAL);
		gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE);

		gl.glLightfv(index, GL.GL_POSITION, position, 0);

		gl.glLightfv(index, GL.GL_DIFFUSE, new float[] {1.0f, 1.0f, 1.0f, 1.0f}, 0);
		gl.glLightfv(index, GL.GL_AMBIENT, new float[] {0.1f, 0.1f, 0.1f, 1.0f}, 0);
		gl.glLightfv(index, GL.GL_SPECULAR, new float[] {1.0f, 1.0f, 1.0f, 1.0f}, 0);
	}
}