/** * Sets the GL lighting state to a white light originating from the eye position and pointed in the specified * direction, in model coordinates. The light direction is always relative to the current eye point and viewer * direction. If the direction is null, this the light direction defaults to (0, 0, -1), which points directly along * the forward vector form the eye point * * @param gl the GL context. * @param light the GL light name to set. * @param direction the light direction in model coordinates, may be null. * * @throws ArgumentException if the GL is null. */ public static void applyLightingDirectionalFromViewer(GL2 gl, int light, Vec4 direction) { if (gl == null) { String message = Logging.getMessage("nullValue.GLIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (direction == null) { direction = DEFAULT_LIGHT_DIRECTION; } float[] ambient = { 1f, 1f, 1f, 0f }; float[] diffuse = { 1f, 1f, 1f, 0f }; float[] specular = { 1f, 1f, 1f, 0f }; float[] position = { (float)direction.x, (float)direction.y, (float)direction.z, 0.0f }; gl.glLightfv(light, GL2.GL_AMBIENT, ambient, 0); gl.glLightfv(light, GL2.GL_DIFFUSE, diffuse, 0); gl.glLightfv(light, GL2.GL_SPECULAR, specular, 0); OGLStackHandler ogsh = new OGLStackHandler(); ogsh.pushModelviewIdentity(gl); try { gl.glLightfv(light, GL2.GL_POSITION, position, 0); } finally { ogsh.pop(gl); } }
protected static void applyStandardLightMaterial(GL2 gl, int light, Material material) { // The alpha value at a vertex is taken only from the diffuse material's alpha channel, without any // lighting computations applied. Therefore we specify alpha=0 for all lighting ambient, specular and // emission values. This will have no effect on material alpha. float[] ambient = new float[4]; float[] diffuse = new float[4]; float[] specular = new float[4]; material.getDiffuse().getRGBColorComponents(diffuse); material.getSpecular().getRGBColorComponents(specular); ambient[3] = diffuse[3] = specular[3] = 0.0f; gl.glLightfv(light, GL2.GL_AMBIENT, ambient, 0); gl.glLightfv(light, GL2.GL_DIFFUSE, diffuse, 0); gl.glLightfv(light, GL2.GL_SPECULAR, specular, 0); }
protected void applyStandardLightDirection(GL2 gl, int light, Vec4 direction) { // Setup the light as a directional light coming from the viewpoint. This requires two state changes // (a) Set the light position as direction x, y, z, and set the w-component to 0, which tells OpenGL this is // a directional light. // (b) Invoke the light position call with the identity matrix on the modelview stack. Since the position // is transformed by the Vec4 vec = direction.normalize3(); float[] parameters = new float[4]; parameters[0] = (float)vec.x; parameters[1] = (float)vec.y; parameters[2] = (float)vec.z; parameters[3] = 0.0f; gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glLightfv(light, GL2.GL_POSITION, parameters, 0); gl.glPopMatrix(); }