Porting Lighting and Materials Functions

Porting Lighting and Materials Functions

OpenGL functions for lighting and materials differ substantially from the IRIS GL functions. Unlike IRIS GL, OpenGL has separate functions for setting lights, light models and materials.

Keep the following points in mind when porting lighting and materials functions:

  • OpenGL has no table of stored definitions. You can use display lists to mimic the IRIS GL def/bind mechanism. For more information on defs and binds, see Porting Defs, Binds, and Sets.
  • With OpenGL, attenuation is associated with each light source, rather than the overall lighting model.
  • Diffuse and specular components are separated in OpenGL light sources.
  • OpenGL light sources have an alpha component. When porting your IRIS GL code, set this alpha component to 1.0, indicating 100 percent opaque. The alpha values are then determined by the alpha component of your materials only, so the objects in your scene will look the same as they did in IRIS GL.

The following table lists IRIS GL lighting and materials functions and their equivalent OpenGL functions.

IRIS GL functionOpenGL functionMeaning
Imdef(DEFLIGHT, ... ) glLight Define a light source.
Imdef(DEFLMODEL, ... ) glLightModel Define a lighting model.
Imbind glEnable ( GL_LIGHT i)Enable light i.
ImbindglEnable( GL_LIGHTING )Enable lighting.
Imdef(DEFMATERIAL, ... ) glMaterial Define a material.
Imcolor glColorMaterial Change the effect of color commands while lighting is active.
glGetMaterial Get material parameters.

 

The following table lists various IRIS GL material parameters and their equivalent OpenGL parameters.

Imdef indexglMaterial parameterDefaultMeaning
ALPHAGL_DIFFUSEThe fourth value in the GL_DIFFUSE parameter specifies the alpha value.
AMBIENTGL_AMBIENT(0.2, 0.2, 0.2, 1.0)Ambient color.
DIFFUSEGL_DIFFUSE(0.8, 0.8, 0.8, 1.0)Diffuse color.
SPECULARGL_SPECULAR(0.0, 0.0, 0.0, 1.0)Emissive color.
SHININESSGL_SHININESS

GL_AMBIENT_AND_DIFFUSE

0.0Specular exponent.

Equivalent to calling glMaterial twice with the same values.

COLORINDEXESGL_COLOR_INDEXESColor indexes for ambient, diffuse, and specular lighting.

 

When the first parameter of Imdef is DEFMODEL, the equivalent OpenGL translation is the function glLightModel. The exception is when the parameter following DEFMODEL is ATTENUATION: then the equivalent OpenGL function is glLight.

The following table lists the equivalent lighting model parameters for IRIS GL and OpenGL.

Imdef indexglLightModel parameterDefaultMeaning
AMBIENTGL_LIGHT_MODEL_AMBIENT(0.2, 0.2, 0.2, 1.0)Ambient color of scene.
ATTENUATIONSee glLight.
LOCALVIEWERGL_LIGHT_MODEL_LOCAL_VIEWERGL_FALSEViewer local (TRUE) or infinite (FALSE).
TWOSIDEGL_LIGHTMODEL_TWO_SIDEGL_FALSEUse two-sided lighting when TRUE.

 

When the first parameter of Imdef is DEFLIGHT, the equivalent OpenGL translation is the glLight function.

The following table lists the equivalent lighting parameters for IRIS GL and OpenGL.

Imdef indexglLight parameterDefaultMeaning
AMBIENTGL_AMBIENT

GL_DIFFUSE

GL_SPECULAR

(0.0, 0.0, 0.0, 1.0)

(1.0, 1.0, 1.0, 1.0)

(1.0, 1.0, 1.0, 1.0)

Ambient intensity.

Diffuse intensity.

Specular intensity.

LCOLORNo equivalent.
POSITIONGL_POSITION(0.0, 0.0, 1.0, 0.0)Position of light.
SPOTDIRECTIONGL_SPOT_DIRECTION(0, 0, 1)Direction of spotlight.
SPOTLIGHTGL_SPOT_EXPONENT

GL_SPOT_CUTOFF

0

180

Intensity distribution.

Maximum spread angle of light source.

DEFMODEL, ATTENUATIONGL_CONSTANT_ATTENUATION

GL_LINEAR_ATTENUATION

GL_QUADRATIC_ATTENUATION

(1, 0, 0)Attenuation factors.

 

 

 

Show:
© 2016 Microsoft