setup opengl Lights - Java javax.media.opengl

Java examples for javax.media.opengl:Light

Description

setup opengl Lights

Demo Code


import javax.media.opengl.GL2;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.charset.Charset;

public class Main{
    public static void setupLights(GL2 gl, int firstLight,
            float[][][] lights) {
        for (int i = 0; i < lights.length; i++) {
            setupLight(gl, firstLight + i, lights[i]);
        }/*from w  ww . j  a v a2s  .c  o  m*/
    }
    public static void setupLight(GL2 gl, int light, float[][] lights) {
        float[] ambient = { lights[0][0], lights[0][1], lights[0][2],
                lights[0][3] };
        float[] diffuse = { lights[1][0], lights[1][1], lights[1][2],
                lights[1][3] };
        float[] specular = { lights[2][0], lights[2][1], lights[2][2],
                lights[2][3] };
        float[] position = { lights[3][0], lights[3][1], lights[3][2],
                lights[3][3] };

        gl.glLightfv(light, GL2.GL_AMBIENT, ambient, 0);
        gl.glLightfv(light, GL2.GL_DIFFUSE, diffuse, 0);
        gl.glLightfv(light, GL2.GL_SPECULAR, specular, 0);
        gl.glLightfv(light, GL2.GL_POSITION, position, 0);
    }
}

Related Tutorials