glmodel
Class GLMaterial

java.lang.Object
  extended by glmodel.GLMaterial

public class GLMaterial
extends java.lang.Object

Wraps properties for a material. To use: create a new material, set the material properties (setDiffuse(), setAmbient(), setSpecular(), setShininess()), call material.apply() in your render function to set the OpenGL current material properties.


Field Summary
 java.nio.FloatBuffer ambient
           
static float[] colorBeige
           
static float[] colorBlack
           
static float[] colorBlue
           
static float[] colorClear
           
static float[] colorCyan
           
static float[] colorDefaultAmbient
           
static float[] colorDefaultDiffuse
           
static float[] colorGrayDark
           
static float[] colorGrayLight
           
static float[] colorGrayMedium
           
static float[] colorGreen
           
static float[] colorMagenta
           
static float[] colorNone
           
static float[] colorRed
           
static float[] colorWhite
           
static float[] colorYellow
           
 java.nio.FloatBuffer diffuse
           
 java.nio.FloatBuffer emission
           
static float maxShine
           
static float minShine
           
 java.lang.String mtlname
           
 java.nio.FloatBuffer shininess
           
static int SIZE_FLOAT
           
 java.nio.FloatBuffer specular
           
 java.lang.String textureFile
           
 int textureHandle
           
 
Constructor Summary
GLMaterial()
           
GLMaterial(float[] color)
           
 
Method Summary
static java.nio.FloatBuffer allocFloats(float[] floatarray)
           
static java.nio.FloatBuffer allocFloats(int howmany)
           
 void apply()
          Call glMaterial() to activate these material properties in the OpenGL environment.
static void clear()
          Reset all material settings to the default values.
 float getAlpha()
          alpha value is stored in the diffuse material color alpha.
 java.lang.String getName()
           
 int getTexture()
           
 java.lang.String getTextureFile()
           
 void setAlpha(float alphaVal)
          alpha value is set in the diffuse material color.
 void setAmbient(float[] color)
          Set the ambient material color.
 void setColor(float[] color)
          Sets the material color to approximate a "real" surface color.
 void setDefaults()
          Set the material to OpenGL's default values (gray, with no reflection and no glow)
 void setDiffuse(float[] color)
          Set the diffuse material color.
 void setEmission(float[] color)
          Set the emission material color.
 void setGlowColor(float[] color)
          Make material appear to emit light
 void setName(java.lang.String s)
          set the material name.
 void setReflection(float intensity, float highlight)
          Set the reflection properties.
 void setShininess(float howShiny)
          Set size of the reflection highlight.
 void setSpecular(float[] color)
          Set the specular material color.
 void setTexture(int txtrHandle)
          Assign a texture handle to this material.
 void setTextureFile(java.lang.String s)
          Store a texture filename with the material.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

colorClear

public static final float[] colorClear

colorNone

public static final float[] colorNone

colorRed

public static final float[] colorRed

colorGreen

public static final float[] colorGreen

colorBlue

public static final float[] colorBlue

colorYellow

public static final float[] colorYellow

colorCyan

public static final float[] colorCyan

colorMagenta

public static final float[] colorMagenta

colorGrayLight

public static final float[] colorGrayLight

colorGrayMedium

public static final float[] colorGrayMedium

colorGrayDark

public static final float[] colorGrayDark

colorWhite

public static final float[] colorWhite

colorBlack

public static final float[] colorBlack

colorBeige

public static final float[] colorBeige

colorDefaultDiffuse

public static final float[] colorDefaultDiffuse

colorDefaultAmbient

public static final float[] colorDefaultAmbient

minShine

public static final float minShine
See Also:
Constant Field Values

maxShine

public static final float maxShine
See Also:
Constant Field Values

diffuse

public java.nio.FloatBuffer diffuse

ambient

public java.nio.FloatBuffer ambient

specular

public java.nio.FloatBuffer specular

emission

public java.nio.FloatBuffer emission

shininess

public java.nio.FloatBuffer shininess

mtlname

public java.lang.String mtlname

textureFile

public java.lang.String textureFile

textureHandle

public int textureHandle

SIZE_FLOAT

public static final int SIZE_FLOAT
See Also:
Constant Field Values
Constructor Detail

GLMaterial

public GLMaterial()

GLMaterial

public GLMaterial(float[] color)
Method Detail

setDefaults

public void setDefaults()
Set the material to OpenGL's default values (gray, with no reflection and no glow)


setDiffuse

public void setDiffuse(float[] color)
Set the diffuse material color. This is the color of the material where it is directly lit.


setAmbient

public void setAmbient(float[] color)
Set the ambient material color. This is the color of the material where it is lit by indirect light (light scattered off the environment). Ie. the shadowed side of an object.


setSpecular

public void setSpecular(float[] color)
Set the specular material color. This controls how much light is reflected off a glossy surface. This color value describes the brightness of the reflection and is typically a shade of gray. Pure black means that no light is reflected (ie. a very rough matte surface). Pure white means that the surface is highly reflective, see also: setShininess()


setEmission

public void setEmission(float[] color)
Set the emission material color. This controls the "glow" of the material, and can be used to make a material that seems to be lit from inside.


setShininess

public void setShininess(float howShiny)
Set size of the reflection highlight. Must also set the specular color for shininess to have any effect: setSpecular(GLMaterial.colorWhite);

Parameters:
howShiny - How sharp reflection is: 0 - 127 (127=very sharp pinpoint)

apply

public void apply()
Call glMaterial() to activate these material properties in the OpenGL environment. These properties will stay in effect until you change them or disable lighting.


clear

public static void clear()
Reset all material settings to the default values.


setColor

public void setColor(float[] color)
Sets the material color to approximate a "real" surface color. Use the same color for diffuse and ambient. To create a shadowed effect you should lower the ambient value for the light sources and lower the overall ambient light.


setReflection

public void setReflection(float intensity,
                          float highlight)
Set the reflection properties. Typically the reflection (specular color) describes the brightness of the reflection, and is a shade of gray. This function takes two params that describe the intensity of the reflection, and the size of the highlight. intensity - a float from 0-1 (0=no reflectivity, 1=maximum reflectivity) highlight - a float from 0-1 (0=soft highlight, 1=sharpest highlight) example: setReflection(1,1) creates a bright, sharp reflection setReflection(.5f,.5f) creates a softer, wider reflection


setGlowColor

public void setGlowColor(float[] color)
Make material appear to emit light


setAlpha

public void setAlpha(float alphaVal)
alpha value is set in the diffuse material color. Other material colors (ambient, specular) are not affected by alpha value.

Parameters:
alphaVal - 0 - 1

getAlpha

public float getAlpha()
alpha value is stored in the diffuse material color alpha. Other material colors (ambient, specular) are not affected by alpha value.

Returns:
alphaVal 0 - 1

setTextureFile

public void setTextureFile(java.lang.String s)
Store a texture filename with the material.


setTexture

public void setTexture(int txtrHandle)
Assign a texture handle to this material.

Parameters:
txtrHandle -

getTextureFile

public java.lang.String getTextureFile()

getTexture

public int getTexture()

setName

public void setName(java.lang.String s)
set the material name. This is the name assigned to this texture in the .mtl file. It is NOT a filename.

Parameters:
s -

getName

public java.lang.String getName()

allocFloats

public static java.nio.FloatBuffer allocFloats(int howmany)

allocFloats

public static java.nio.FloatBuffer allocFloats(float[] floatarray)