com.hermetica.util3d
Class Texture

java.lang.Object
  |
  +--com.hermetica.util3d.Texture

public class Texture
extends java.lang.Object
implements java.awt.image.ImageConsumer

Encapsulation of a chunk of texture information. This class provides the programmer with the ability to retrieve images, such as GIF and JPEG images, from arbitrary URLs and use them in OpenGL as texture maps. This class will handle the processing of the images into arrays of data that OpenGL uses for texture-map specification. The isValid() method should be invoked prior to using the texture to make sure it has completely downloaded, due to the asynchronous nature of Java's AWT.

In addition to this, all textures exist in the RGBA colourspace, thereby allowing you to easily build textures with transparency.

Version:
$Id: Texture.java,v 1.21 1998/07/17 19:13:59 descarte Exp descarte $
Author:
Alligator Descartes <descarte@hermetica.com>
See Also:
GL.glTexImage1D(int, int, int, int, int, int, int, byte[]), GL.glTexImage2D(int, int, int, int, int, int, int, int, byte[])

Field Summary
static int SCALE_DONT
          Don't scale the texture at all.
static int SCALE_MAGNIFY
          Scale the texture up on both axes
static int SCALE_MINIFY
          Scale the texture down on both axes
static int SCALE_NEAREST
          Scale the texture to the nearest ^2 in each axis.
 
Constructor Summary
Texture(java.awt.Image image, GLDrawable component)
          Default constructor with just the image we wish to create the texture from
Texture(java.awt.Image image, GLDrawable component, int scaling)
          Slightly more sophisticated constructor that allows us to specify what we wish to do with regards to scaling the texture.
Texture(java.awt.image.ImageProducer producer, GLDrawable component)
          Default constructor with just the ImageProducer we wish to create the texture from
Texture(java.awt.image.ImageProducer producer, GLDrawable component, int scaling)
          Slightly more sophisticated constructor that allows us to specify what we wish to do with regards to scaling the texture.
 
Method Summary
 int getHeight()
          Returns the height of the texture
 byte[] getTexture()
          Returns the textureData array
 int getWidth()
          Returns the width of the texture
 void imageComplete(int status)
          Indicates the image is complete
 boolean isInitialized()
          Handy object-orientated store that signifies whether or not you have used your texture yet.
 boolean isValid()
          Returns whether or not this texture is valid, ie, whether all the data has been received and processed into suitable OpenGL data.
static int nearestPower2(int value, int scaleRule)
          Calculates the nearest power of two to the given number
 void setColorModel(java.awt.image.ColorModel model)
          Sets the colour model of this texture
 void setDimensions(int width, int height)
          Sets the dimensions of the texture
 void setHints(int hintflags)
          Sets any hints on image production
 void setPixels(int x, int y, int w, int h, java.awt.image.ColorModel model, byte[] pixels, int off, int scansize)
          Sets the pixels of the image in byte format
 void setPixels(int x, int y, int w, int h, java.awt.image.ColorModel model, int[] pixels, int off, int scansize)
          Sets the pixels of the image in byte format
 void setProperties(java.util.Hashtable props)
          Sets the properties of this ImageConsumer
 java.lang.String toAWTByteArray(java.lang.String variableName)
          Returns a String containing a byte array declaration of this texture in a format suitable for use within AWT
 java.lang.String toAWTIntArray(java.lang.String variableName)
          Returns a String containing an int[] declaration of this texture for use with AWT, ie, each 4 component pixel is packed into a 24-bit value ( ALPHA | RED | GREEN | BLUE )
 java.lang.String toOpenGLIntArray(java.lang.String variableName)
          Returns a String containing an int[] declaration of this texture for use with OpenGL's texture mapping routines.
 java.lang.String toString()
          Returns a String representation of the texture
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SCALE_DONT

public static final int SCALE_DONT
Don't scale the texture at all. No way, Jose

SCALE_NEAREST

public static final int SCALE_NEAREST
Scale the texture to the nearest ^2 in each axis. Note that this will scale the texture in the same direction in both axes depending on how the first axis calculates to preserve the aspect ratio

SCALE_MAGNIFY

public static final int SCALE_MAGNIFY
Scale the texture up on both axes

SCALE_MINIFY

public static final int SCALE_MINIFY
Scale the texture down on both axes
Constructor Detail

Texture

public Texture(java.awt.Image image,
               GLDrawable component)
Default constructor with just the image we wish to create the texture from

Texture

public Texture(java.awt.Image image,
               GLDrawable component,
               int scaling)
Slightly more sophisticated constructor that allows us to specify what we wish to do with regards to scaling the texture. The Texture class can either create the texture as is, scale it to the nearest sizes, scale it arbitrarily up, or scale it arbitrarily down.

Texture

public Texture(java.awt.image.ImageProducer producer,
               GLDrawable component)
Default constructor with just the ImageProducer we wish to create the texture from

Texture

public Texture(java.awt.image.ImageProducer producer,
               GLDrawable component,
               int scaling)
Slightly more sophisticated constructor that allows us to specify what we wish to do with regards to scaling the texture. The Texture class can either create the texture as is, scale it to the nearest sizes, scale it arbitrarily up, or scale it arbitrarily down.
Method Detail

getWidth

public int getWidth()
Returns the width of the texture

getHeight

public int getHeight()
Returns the height of the texture

isValid

public boolean isValid()
Returns whether or not this texture is valid, ie, whether all the data has been received and processed into suitable OpenGL data.

isInitialized

public boolean isInitialized()
Handy object-orientated store that signifies whether or not you have used your texture yet.

getTexture

public byte[] getTexture()
Returns the textureData array

imageComplete

public void imageComplete(int status)
Indicates the image is complete
Specified by:
imageComplete in interface java.awt.image.ImageConsumer

setColorModel

public void setColorModel(java.awt.image.ColorModel model)
Sets the colour model of this texture
Specified by:
setColorModel in interface java.awt.image.ImageConsumer

setDimensions

public void setDimensions(int width,
                          int height)
Sets the dimensions of the texture
Specified by:
setDimensions in interface java.awt.image.ImageConsumer

setHints

public void setHints(int hintflags)
Sets any hints on image production
Specified by:
setHints in interface java.awt.image.ImageConsumer

setPixels

public void setPixels(int x,
                      int y,
                      int w,
                      int h,
                      java.awt.image.ColorModel model,
                      byte[] pixels,
                      int off,
                      int scansize)
Sets the pixels of the image in byte format
Specified by:
setPixels in interface java.awt.image.ImageConsumer

setPixels

public void setPixels(int x,
                      int y,
                      int w,
                      int h,
                      java.awt.image.ColorModel model,
                      int[] pixels,
                      int off,
                      int scansize)
Sets the pixels of the image in byte format
Specified by:
setPixels in interface java.awt.image.ImageConsumer

setProperties

public void setProperties(java.util.Hashtable props)
Sets the properties of this ImageConsumer
Specified by:
setProperties in interface java.awt.image.ImageConsumer

toString

public java.lang.String toString()
Returns a String representation of the texture
Overrides:
toString in class java.lang.Object

toAWTByteArray

public java.lang.String toAWTByteArray(java.lang.String variableName)
Returns a String containing a byte array declaration of this texture in a format suitable for use within AWT

toAWTIntArray

public java.lang.String toAWTIntArray(java.lang.String variableName)
Returns a String containing an int[] declaration of this texture for use with AWT, ie, each 4 component pixel is packed into a 24-bit value ( ALPHA | RED | GREEN | BLUE )

toOpenGLIntArray

public java.lang.String toOpenGLIntArray(java.lang.String variableName)
Returns a String containing an int[] declaration of this texture for use with OpenGL's texture mapping routines.

nearestPower2

public static int nearestPower2(int value,
                                int scaleRule)
Calculates the nearest power of two to the given number