Top Description Fields Constructors Methods
org.lwjgl.examples.spaceinvaders

public Class TextureLoader

extends Object
Class Inheritance
Imports
java.awt.Color, .Graphics, .Image, java.awt.color.ColorSpace, java.awt.image.BufferedImage, .ColorModel, .ComponentColorModel, .DataBuffer, .DataBufferByte, .Raster, .WritableRaster, java.io.IOException, java.net.URL, java.nio.ByteBuffer, .ByteOrder, .IntBuffer, java.util.HashMap, .Hashtable, javax.swing.ImageIcon, org.lwjgl.BufferUtils

A utility class to load textures for OpenGL. This source is based on a texture that can be found in the Java Gaming (www.javagaming.org) Wiki. It has been simplified slightly for explicit 2D graphics use. OpenGL uses a particular image format. Since the images that are loaded from disk may not match this format this loader introduces a intermediate image which the source image is copied into. In turn, this image is used as source for the OpenGL texture.
Authors
Kevin Glass, Brian Matzon

Field Summary

Modifier and TypeField and Description
private ColorModel
glAlphaColorModel

The colour model including alpha for the GL image

private ColorModel
glColorModel

The colour model for the GL image

private HashMap<String, Texture>
table

The table of textures that have been loaded in this loader

private IntBuffer
textureIDBuffer

Scratch buffer for texture ID's

Constructor Summary

AccessConstructor and Description
public
TextureLoader()

Create a new texture loader based on the game panel

Method Summary

Modifier and TypeMethod and Description
private ByteBuffer

Returns:

A buffer containing the data
convertImageData
(BufferedImage
The image to convert to a texture
bufferedImage
,
Texture
The texture to store the data into
texture
)

Convert the buffered image to a texture

private int

Returns:

A new texture ID
createTextureID
()

Create a new texture ID

private static int

Returns:

The power of 2
get2Fold
(int
The target number
fold
)

Get the closest greater power of 2 to the fold number

public Texture

Returns:

The loaded texture
getTexture
(String
The location of the resource to load
resourceName
)

Load a texture

public Texture

Returns:

The loaded texture
getTexture
(String
The location of the resource to load
resourceName
,
int
The GL target to load the texture against
target
,
int
The pixel format of the screen
dstPixelFormat
,
int
The minimising filter
minFilter
,
int
The magnification filter
magFilter
)

Load a texture into OpenGL from a image reference on disk.

private BufferedImage

Returns:

The loaded buffered image
loadImage
(String
The location of the resource to load
ref
)

Load a given resource as a buffered image

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

glAlphaColorModelback to summary
private ColorModel glAlphaColorModel

The colour model including alpha for the GL image

glColorModelback to summary
private ColorModel glColorModel

The colour model for the GL image

tableback to summary
private HashMap<String, Texture> table

The table of textures that have been loaded in this loader

textureIDBufferback to summary
private IntBuffer textureIDBuffer

Scratch buffer for texture ID's

Constructor Detail

TextureLoaderback to summary
public TextureLoader()

Create a new texture loader based on the game panel

Method Detail

convertImageDataback to summary
private ByteBuffer convertImageData(BufferedImage bufferedImage, Texture texture)

Convert the buffered image to a texture

Parameters
bufferedImage:BufferedImage

The image to convert to a texture

texture:Texture

The texture to store the data into

Returns:ByteBuffer

A buffer containing the data

createTextureIDback to summary
private int createTextureID()

Create a new texture ID

Returns:int

A new texture ID

get2Foldback to summary
private static int get2Fold(int fold)

Get the closest greater power of 2 to the fold number

Parameters
fold:int

The target number

Returns:int

The power of 2

getTextureback to summary
public Texture getTexture(String resourceName) throws IOException

Load a texture

Parameters
resourceName:String

The location of the resource to load

Returns:Texture

The loaded texture

Exceptions
IOException:
Indicates a failure to access the resource
getTextureback to summary
public Texture getTexture(String resourceName, int target, int dstPixelFormat, int minFilter, int magFilter) throws IOException

Load a texture into OpenGL from a image reference on disk.

Parameters
resourceName:String

The location of the resource to load

target:int

The GL target to load the texture against

dstPixelFormat:int

The pixel format of the screen

minFilter:int

The minimising filter

magFilter:int

The magnification filter

Returns:Texture

The loaded texture

Exceptions
IOException:
Indicates a failure to access the resource
loadImageback to summary
private BufferedImage loadImage(String ref) throws IOException

Load a given resource as a buffered image

Parameters
ref:String

The location of the resource to load

Returns:BufferedImage

The loaded buffered image

Exceptions
IOException:
Indicates a failure to find a resource