hmi.graphics.opengl
Class GLTextureLoader

java.lang.Object
  extended by hmi.graphics.opengl.GLTextureLoader

public class GLTextureLoader
extends Object

A class for loading image data for GLTexture objects.


Field Summary
private static String currentFileName
           
static String DEFAULT_TEXTURE_RESOURCE_DIR
           
private static ResourcePool pool
           
(package private) static ComponentColorModel rgbaModel
           
(package private) static ComponentColorModel rgbModel
           
 
Constructor Summary
GLTextureLoader()
           
 
Method Summary
static void addTextureDirectory(String dir)
          Adds the specified directory as one of the resource directories for GLTextures
private static GLTexture convertBufferedImage(BufferedImage image, boolean rescale, boolean flip, String imageFile)
          Converts a BufferedImage into a TextureImageData object with type/format and size that suits OpenGL
static void flipImageVertically(BufferedImage image)
          Flips the supplied BufferedImage vertically.
static GLTexture getGLTexture(int texUnit, String resourceName)
          Tries to get a GLTexture with the specified resource name, either from the cache or else from loading (and caching) an image from one of the texture directories.
static GLTexture getGLTexture(int texUnit, String resourceName, boolean flip, boolean rescale)
          Tries to get a GLTexture with the specified resource name.
static GLTexture getGLTexture(String resourceName)
          Tries to get a GLTexture with the specified resource name, either from the cache or else from loading (and caching) an image from one of the texture directories.
private static int getPowerOfTwo(int size)
           
static GLTexture readFromFile(File file, boolean rescale, boolean flip)
          Like readFromStream, where the InputStream is obtained from the specified file.
static GLTexture readFromFile(String fileName, boolean rescale, boolean flip)
          Like readFromStream, where the InputStream is obtained from the specified resource file name (a OS path).
static GLTexture readFromResourceFile(Resources resources, String resourceName, boolean rescale, boolean flip)
          Like readFromStream, where the InputStream is obtained from the specified resource file.
static GLTexture readFromStream(InputStream is, boolean rescale, boolean flip, String imageFile)
          Creates a new GLTexture by reading image data from the specified InputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pool

private static ResourcePool pool

DEFAULT_TEXTURE_RESOURCE_DIR

public static final String DEFAULT_TEXTURE_RESOURCE_DIR
See Also:
Constant Field Values

currentFileName

private static String currentFileName

rgbaModel

static ComponentColorModel rgbaModel

rgbModel

static ComponentColorModel rgbModel
Constructor Detail

GLTextureLoader

public GLTextureLoader()
Method Detail

addTextureDirectory

public static void addTextureDirectory(String dir)
Adds the specified directory as one of the resource directories for GLTextures


getGLTexture

public static GLTexture getGLTexture(String resourceName)
Tries to get a GLTexture with the specified resource name, either from the cache or else from loading (and caching) an image from one of the texture directories. The image is flipped vertically and when necessary rescaled to a power-of-two size.


getGLTexture

public static GLTexture getGLTexture(int texUnit,
                                     String resourceName)
Tries to get a GLTexture with the specified resource name, either from the cache or else from loading (and caching) an image from one of the texture directories. The image is flipped vertically and when necessary rescaled to a power-of-two size.


getGLTexture

public static GLTexture getGLTexture(int texUnit,
                                     String resourceName,
                                     boolean flip,
                                     boolean rescale)
Tries to get a GLTexture with the specified resource name. GLTexture objects found and loaded will be cached. The flip and rescale attributes are used when the texture is loaded for the first time (not when a cached version is retrieved). They denote whether the image should be flipped vertically (usually they should for OpenGL texturing), and whether a non-power-of-two image should be rescaled to the next power-of-two size. (Default is to rescale)


readFromFile

public static GLTexture readFromFile(String fileName,
                                     boolean rescale,
                                     boolean flip)
                              throws IOException
Like readFromStream, where the InputStream is obtained from the specified resource file name (a OS path).

Throws:
IOException

readFromFile

public static GLTexture readFromFile(File file,
                                     boolean rescale,
                                     boolean flip)
                              throws IOException
Like readFromStream, where the InputStream is obtained from the specified file.

Throws:
IOException

readFromResourceFile

public static GLTexture readFromResourceFile(Resources resources,
                                             String resourceName,
                                             boolean rescale,
                                             boolean flip)
                                      throws IOException
Like readFromStream, where the InputStream is obtained from the specified resource file.

Throws:
IOException

readFromStream

public static GLTexture readFromStream(InputStream is,
                                       boolean rescale,
                                       boolean flip,
                                       String imageFile)
                                throws IOException
Creates a new GLTexture by reading image data from the specified InputStream. The image is rescaled to a power-of-two (when necessary) when the rescale parameter is true. Also, the image is flipped vertically when flip is true. Returns null when the InputStream is null;

Throws:
IOException

flipImageVertically

public static void flipImageVertically(BufferedImage image)
Flips the supplied BufferedImage vertically.


convertBufferedImage

private static GLTexture convertBufferedImage(BufferedImage image,
                                              boolean rescale,
                                              boolean flip,
                                              String imageFile)
Converts a BufferedImage into a TextureImageData object with type/format and size that suits OpenGL


getPowerOfTwo

private static int getPowerOfTwo(int size)