org.gljava.opengl

Class TextureFactory

public class TextureFactory extends Object

Factory for easy loading of Textures.

Version: $Id: TextureFactory.java,v 1.2 2005/02/02 19:22:28 ivan_ganza Exp $

Author: Ivan Z. Ganza

Field Summary
ColorModelglAlphaColorModel
Colour model including alpha for the GL image
ColorModelglColorModel
colour model for the GL image
static TextureFactoryinstance
Factory instance
HashMaptextureCache
Cache of loaded Textures
IntBuffertextureIDBuffer
buffer for texture ID's
Constructor Summary
TextureFactory()
Creates a new TextureFactory instance.
Method Summary
ByteBufferconvertImageData(BufferedImage bufferedImage, Texture texture)
Convert the buffered image to byte buffer with the data in appropriate format to pass to opengl
intcreateTextureID(GL gl)
Create a new texture ID
intgetClosestGreaterPowerOf2(int target)
Get the closest greater power of 2
static TextureFactorygetFactory()
initialization
BufferedImageloadImage(String path)
Describe loadImage method here.
BufferedImageloadImage(URL url)
Describe loadImage method here.
BufferedImageloadImageResource(String resourceName)
Describe loadImageResource method here.
TextureloadSubTexture2D(GL gl, String path, int xOffset, int yOffset, int width, int height)
TextureloadSubTexture2D(GL gl, BufferedImage bufferedImage, int target, int dstPixelFormat, int minFilter, int magFilter, int xOffset, int yOffset, int width, int height)
Describe loadSubTexture method here.
TextureloadTexture(GL gl, String path)
Load a Texture from the filesystem
TextureloadTexture(GL gl, URL url)
Load a Texture from the given URL
TextureloadTexture(GL gl, BufferedImage bufferedImage, int target, int dstPixelFormat, int minFilter, int magFilter)
Describe loadTexture method here.
TextureloadTextureResource(GL gl, String resourceName)
Load a Texture as a resource with the given name
TextureloadTextureResource(GL gl, String resourceName, int target, int dstPixelFormat, int minFilter, int magFilter)
Load a Texture as a resource with the given name

Field Detail

glAlphaColorModel

ColorModel glAlphaColorModel
Colour model including alpha for the GL image

glColorModel

ColorModel glColorModel
colour model for the GL image

instance

static TextureFactory instance
Factory instance

textureCache

HashMap textureCache
Cache of loaded Textures

textureIDBuffer

IntBuffer textureIDBuffer
buffer for texture ID's

Constructor Detail

TextureFactory

public TextureFactory()
Creates a new TextureFactory instance.

Method Detail

convertImageData

ByteBuffer convertImageData(BufferedImage bufferedImage, Texture texture)
Convert the buffered image to byte buffer with the data in appropriate format to pass to opengl

Parameters: bufferedImage The image to convert to a texture texture The texture to store the data into

Returns: A buffer containing the data

createTextureID

int createTextureID(GL gl)
Create a new texture ID

Returns: A new texture ID

getClosestGreaterPowerOf2

final int getClosestGreaterPowerOf2(int target)
Get the closest greater power of 2

Parameters: target The target number

Returns: The power of 2

getFactory

public static TextureFactory getFactory()
initialization

loadImage

BufferedImage loadImage(String path)
Describe loadImage method here.

Parameters: path a String value

Returns: a BufferedImage value

Throws: IOException if an error occurs

loadImage

BufferedImage loadImage(URL url)
Describe loadImage method here.

Parameters: url an URL value

Returns: a BufferedImage value

Throws: IOException if an error occurs

loadImageResource

BufferedImage loadImageResource(String resourceName)
Describe loadImageResource method here.

Parameters: url an URL value

Returns: a BufferedImage value

Throws: IOException if an error occurs

loadSubTexture2D

public Texture loadSubTexture2D(GL gl, String path, int xOffset, int yOffset, int width, int height)

loadSubTexture2D

public Texture loadSubTexture2D(GL gl, BufferedImage bufferedImage, int target, int dstPixelFormat, int minFilter, int magFilter, int xOffset, int yOffset, int width, int height)
Describe loadSubTexture method here.

Parameters: gl a GL value bufferedImage a BufferedImage value target an int value dstPixelFormat an int value minFilter an int value magFilter an int value width an int value height an int value

Returns: a Texture value

Throws: IOException if an error occurs

loadTexture

public Texture loadTexture(GL gl, String path)
Load a Texture from the filesystem

Parameters: gl a GL value path The path on the filesystem to the Texture

Returns: a Texture value

Throws: IOException if an error occurs

loadTexture

public Texture loadTexture(GL gl, URL url)
Load a Texture from the given URL

Parameters: gl a GL value url an URL value

Returns: a Texture value

Throws: IOException if an error occurs

loadTexture

public Texture loadTexture(GL gl, BufferedImage bufferedImage, int target, int dstPixelFormat, int minFilter, int magFilter)
Describe loadTexture method here.

Parameters: gl a GL value image a BufferedImage value target an int value dstPixelFormat an int value minFilter an int value magFilter an int value

Returns: a Texture value

Throws: IOException if an error occurs

loadTextureResource

public Texture loadTextureResource(GL gl, String resourceName)
Load a Texture as a resource with the given name

Parameters: gl a GL value resourceName a String value

Returns: a Texture value

Throws: IOException if an error occurs

loadTextureResource

public Texture loadTextureResource(GL gl, String resourceName, int target, int dstPixelFormat, int minFilter, int magFilter)
Load a Texture as a resource with the given name

Parameters: gl a GL value resourceName a String value target an int value dstPixelFormat an int value minFilter an int value magFilter an int value

Returns: a Texture value

Throws: IOException if an error occurs