JOGL Lighting - JOGL

What is JOGL Lighting?

This section clarifies you how to apply lighting effect to an object using JOGL.

To set lighting, firstly enable lighting using the glEnable() method. Then apply lighting for the objects, using the glLightfv(int light, int pname, float[] params, int params_offset) method of GLLightingFunc interface. This method takes four parameters.

The resulting table describes the parameters of gllightfv() method.

Sr.No.

Parameter Name and Description

1

Light

Specifies a light. The number of lights depends on the implementation, but at least eight lights are supported. It accepts ten values, those parameters are discussed in a separate table named Light Source Parameters given below.

2

Pname

Specifies a single valued light source parameter. For light source, there are ten parameters as discussed below.

3

Params

Specifies a pointer to the value or values that is set to the parameterpnameof light sourcelight.

4

Light source parameter

You can use any of the light source parameters given below.

Light source parameters

The following table shows the Light source parameters −

Sr.No.

Parameter and Description

1

GL_AMBIENT

It contains the parameters that specify the ambient intensity of the light.

2

GL_DIFFUSE

It contains the parameters that specify the diffuse intensity of the light.

3

GL_SPECULAR

It contains the parameters that specify the specular intensity of the light.

4

GL_POSITION

It contains four integer or floating-point values that specify the position of the light in homogeneous object coordinates.

5

GL_SPOT_DIRECTION

It contains parameters that specify the direction of light in homogeneous object coordinates.

6

GL_SPOT_EXPONENT

Its parameters specify the intensity distribution of light.

7

GL_SPOT_CUTOFF

The single parameter of this specifies the maximum spread angle of the light.

8

GL_CONSTANT_ATTENUATION or GL_LINEAR_ATTENUATION or GL_QUADRATIC_ATTENUATION

You can use any of these attenuation factors, which is represented by a single value.

Lighting is enabled or disabled using glEnable() and glDisable () methods with the argument GL_LIGHTING.
The resulting template is given for lighting –

Applying Light to a Rotating Polygon

Follow the given steps for applying light to a rotating polygon.

Rotate the polygon using glRotate() method


Let us go through the program to apply light to a rotating polygon –

If you compile and execute the overhead program, it makes the resulting output. At this time, you can detect numerous snapshots of a rotating polygon with lighting.

polygon_lighting

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JOGL Topics