com.ryanm.glvisualiser.imp
Class TextureUtils

java.lang.Object
  extended by com.ryanm.glvisualiser.imp.TextureUtils

public class TextureUtils
extends java.lang.Object

Utility class for loading and manipulating textures

Author:
ryanm

Constructor Summary
TextureUtils()
           
 
Method Summary
static int createRGBATexture(javax.media.opengl.GLAutoDrawable drawable, java.nio.ByteBuffer pixels, int width, int height, boolean mipmap)
          Create RGBA OpenGL texture.
static int createRGBTexture(javax.media.opengl.GLAutoDrawable drawable, java.nio.ByteBuffer pixels, int width, int height, boolean mipmap)
          Create RGB OpenGL texture.
static void destroyTexture(javax.media.opengl.GL gl, int handle)
          Destroy texture.
static java.net.URL getResource(java.lang.String fileName)
          Get resource URL.
static int[] grabPixels(java.awt.image.BufferedImage bufImage)
          Get image pixels.
static java.awt.image.BufferedImage loadImage(java.lang.String filePath)
          Load image file.
static int loadTexture(java.io.File imageFile, boolean hasAlpha, boolean mipmap, javax.media.opengl.GLAutoDrawable drawable)
          Simple texture load helper.
static java.nio.ByteBuffer simpleImageConvert(int[] pixels, int width, int height, boolean hasAlpha)
          Convert image to OpenGL ready format for simple RGB/RGBA cases only!
static int textureFromImage(java.awt.image.BufferedImage image, boolean hasAlpha, boolean mipmap, javax.media.opengl.GLAutoDrawable drawable)
          Simple texture creator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextureUtils

public TextureUtils()
Method Detail

loadTexture

public static int loadTexture(java.io.File imageFile,
                              boolean hasAlpha,
                              boolean mipmap,
                              javax.media.opengl.GLAutoDrawable drawable)
                       throws java.io.IOException
Simple texture load helper.

Parameters:
imageFile - the image file
hasAlpha - Use alpha switch
mipmap - Build mipmap switch
drawable -
Returns:
Texture handle or -1 on error
Throws:
java.io.IOException

textureFromImage

public static int textureFromImage(java.awt.image.BufferedImage image,
                                   boolean hasAlpha,
                                   boolean mipmap,
                                   javax.media.opengl.GLAutoDrawable drawable)
Simple texture creator

Parameters:
image - the image
hasAlpha - Use alpha switch
mipmap - Build mipmap switch
drawable -
Returns:
Texture handle or -1 on error

destroyTexture

public static void destroyTexture(javax.media.opengl.GL gl,
                                  int handle)
Destroy texture.

Parameters:
gl -
handle - Texture handle

loadImage

public static java.awt.image.BufferedImage loadImage(java.lang.String filePath)
Load image file.

Parameters:
filePath - Path to file
Returns:
BufferedImage or null on error

getResource

public static java.net.URL getResource(java.lang.String fileName)
Get resource URL.

Parameters:
fileName - Name of file to load
Returns:
URL or null if not found

grabPixels

public static int[] grabPixels(java.awt.image.BufferedImage bufImage)
Get image pixels.

Parameters:
bufImage - Buffered image
Returns:
int array of pixels or null on error

simpleImageConvert

public static java.nio.ByteBuffer simpleImageConvert(int[] pixels,
                                                     int width,
                                                     int height,
                                                     boolean hasAlpha)
Convert image to OpenGL ready format for simple RGB/RGBA cases only!

Parameters:
pixels - int array of pixels
width - Width of image
height - Height of image
hasAlpha - Image have alpha
Returns:
a byte buffer of image data

createRGBATexture

public static int createRGBATexture(javax.media.opengl.GLAutoDrawable drawable,
                                    java.nio.ByteBuffer pixels,
                                    int width,
                                    int height,
                                    boolean mipmap)
Create RGBA OpenGL texture.

Parameters:
drawable -
pixels - ByteBuffer containing pixels
width - Width of texture
height - Height of texture
mipmap - Mipmap generation switch
Returns:
integer texture handle

createRGBTexture

public static int createRGBTexture(javax.media.opengl.GLAutoDrawable drawable,
                                   java.nio.ByteBuffer pixels,
                                   int width,
                                   int height,
                                   boolean mipmap)
Create RGB OpenGL texture.

Parameters:
drawable -
pixels - ByteBuffer containing pixels
width - Width of texture
height - Height of texture
mipmap - Mipmap generation switch
Returns:
integer texture handle