Code example for GL10

Methods: glEnable, glGetIntegerv, glLightf, glLightfv

0
	{ 
		if (!lightNode.isOn()) 
			return; 
 
		int nMaxLightMax[] = new int[1];
		gl.glGetIntegerv(GL10.GL_MAX_LIGHTS, nMaxLightMax, 0);
 
		if (nMaxLightMax[0] < gnLights) {
			gnLights++;
			return; 
		} 
 
		float	color[] = new float[4];
		float	pos[] = new float[4];
		float	attenuation[] = new float[3];
		float	direction[] = new float[3];
		float	intensity;
 
		if (lightNode.isPointLightNode()) {
			 
			PointLightNode pLight = (PointLightNode)lightNode;
 
			gl.glEnable(GL10.GL_LIGHT0+gnLights);
			 
			pLight.getAmbientColor(color);
			gl.glLightfv(GL10.GL_LIGHT0+gnLights, GL10.GL_AMBIENT, color, 0);
 
			pLight.getColor(color);
			intensity = pLight.getIntensity();
			color[0] *= intensity; 
			color[1] *= intensity; 
			color[2] *= intensity; 
			gl.glLightfv(GL10.GL_LIGHT0+gnLights, GL10.GL_DIFFUSE, color, 0);
			gl.glLightfv(GL10.GL_LIGHT0+gnLights, GL10.GL_SPECULAR, color, 0);
 
			pLight.getLocation(pos); pos[3] = 1.0f;
			gl.glLightfv(GL10.GL_LIGHT0+gnLights, GL10.GL_POSITION, pos, 0);
 
			direction[0] = 0.0f; direction[0] = 0.0f; direction[0] = 0.0f;
			gl.glLightfv(GL10.GL_LIGHT0+gnLights, GL10.GL_SPOT_DIRECTION, direction, 0);
			gl.glLightf(GL10.GL_LIGHT0+gnLights, GL10.GL_SPOT_EXPONENT, 0.0f);
			gl.glLightf(GL10.GL_LIGHT0+gnLights, GL10.GL_SPOT_CUTOFF, 180.0f);
 
			pLight.getAttenuation(attenuation);
			gl.glLightf(GL10.GL_LIGHT0+gnLights, GL10.GL_CONSTANT_ATTENUATION, attenuation[0]);
			gl.glLightf(GL10.GL_LIGHT0+gnLights, GL10.GL_LINEAR_ATTENUATION, attenuation[1]);
			gl.glLightf(GL10.GL_LIGHT0+gnLights, GL10.GL_QUADRATIC_ATTENUATION, attenuation[2]);
			 
			gnLights++;
		} 
		else if (lightNode.isDirectionalLightNode()) {
 
			DirectionalLightNode dLight = (DirectionalLightNode)lightNode;
			 
			gl.glEnable(GL10.GL_LIGHT0+gnLights);
			 
			dLight.getAmbientColor(color);
			gl.glLightfv(GL10.GL_LIGHT0+gnLights, GL10.GL_AMBIENT, color, 0);
 
			dLight.getColor(color);
			intensity = dLight.getIntensity();
			color[0] *= intensity; 
			color[1] *= intensity; 
			color[2] *= intensity; 
			gl.glLightfv(GL10.GL_LIGHT0+gnLights, GL10.GL_DIFFUSE, color, 0);
			gl.glLightfv(GL10.GL_LIGHT0+gnLights, GL10.GL_SPECULAR, color, 0);
 
			dLight.getDirection(pos); pos[3] = 0.0f;
			gl.glLightfv(GL10.GL_LIGHT0+gnLights, GL10.GL_POSITION, pos, 0);
 
			direction[0] = 0.0f; direction[0] = 0.0f; direction[0] = 0.0f;
			gl.glLightfv(GL10.GL_LIGHT0+gnLights, GL10.GL_SPOT_DIRECTION, direction, 0);
			gl.glLightf(GL10.GL_LIGHT0+gnLights, GL10.GL_SPOT_EXPONENT, 0.0f);
			gl.glLightf(GL10.GL_LIGHT0+gnLights, GL10.GL_SPOT_CUTOFF, 180.0f);
 
			gl.glLightf(GL10.GL_LIGHT0+gnLights, GL10.GL_CONSTANT_ATTENUATION, 1.0f);
			gl.glLightf(GL10.GL_LIGHT0+gnLights, GL10.GL_LINEAR_ATTENUATION, 0.0f);
			gl.glLightf(GL10.GL_LIGHT0+gnLights, GL10.GL_QUADRATIC_ATTENUATION, 0.0f);
 
			gnLights++;
		} 
		else if (lightNode.isSpotLightNode()) {
 
			SpotLightNode sLight = (SpotLightNode)lightNode;
 
			gl.glEnable(GL10.GL_LIGHT0+gnLights);
			 
			sLight.getAmbientColor(color);
			gl.glLightfv(GL10.GL_LIGHT0+gnLights, GL10.GL_AMBIENT, color, 0);
 
			sLight.getColor(color);
			intensity = sLight.getIntensity();
			color[0] *= intensity; 
			color[1] *= intensity; 
			color[2] *= intensity; 
			gl.glLightfv(GL10.GL_LIGHT0+gnLights, GL10.GL_DIFFUSE, color, 0);
			gl.glLightfv(GL10.GL_LIGHT0+gnLights, GL10.GL_SPECULAR, color, 0);
 
			sLight.getLocation(pos); pos[3] = 1.0f;
			gl.glLightfv(GL10.GL_LIGHT0+gnLights, GL10.GL_POSITION, pos, 0);
 
			sLight.getDirection(direction);
			gl.glLightfv(GL10.GL_LIGHT0+gnLights, GL10.GL_SPOT_DIRECTION, direction, 0);
 
			gl.glLightf(GL10.GL_LIGHT0+gnLights, GL10.GL_SPOT_EXPONENT, 0.0f);
			gl.glLightf(GL10.GL_LIGHT0+gnLights, GL10.GL_SPOT_CUTOFF, sLight.getCutOffAngle());
 
			sLight.getAttenuation(attenuation);
			gl.glLightf(GL10.GL_LIGHT0+gnLights, GL10.GL_CONSTANT_ATTENUATION, attenuation[0]);
			gl.glLightf(GL10.GL_LIGHT0+gnLights, GL10.GL_LINEAR_ATTENUATION, attenuation[1]);
			gl.glLightf(GL10.GL_LIGHT0+gnLights, GL10.GL_QUADRATIC_ATTENUATION, attenuation[2]);
 
			gnLights++;
		} 
	}