codeanticode.gltexture
Class GLTexture

java.lang.Object
  extended by PImage
      extended by codeanticode.gltexture.GLTexture

public class GLTexture
extends PImage

This class adds an opengl texture to a PImage object. The texture is handled in a similar way to the pixels property: image data can be copied to and from the texture using loadTexture and updateTexture methods. However, bringing the texture down to image or pixels data can slow down the application considerably (since involves copying texture data from GPU to CPU), especially when handling large textures. So it is recommended to do all the texture handling without calling updateTexture, and doing so only at the end if the texture is needed as a regular image.


Field Summary
protected  GL gl
           
protected  GLState glstate
           
protected  PGraphicsOpenGL pgl
           
protected  int[] tex
           
 
Constructor Summary
GLTexture(PApplet parent)
          Creates an instance of GLTexture with size 1x1.
GLTexture(PApplet parent, int width, int height)
          Creates an instance of GLTexture with size width x height.
GLTexture(PApplet parent, java.lang.String filename)
          Creates an instance of GLTexture using image file filename as source.
 
Method Summary
 boolean available()
          Returns true if the texture has been initialized.
 void filter(GLTextureFilter texFilter, GLTexture destTex)
          Applies filter texFilter using this texture as source and destTex as destination.
 void filter(GLTextureFilter texFilter, GLTexture[] destTexArray)
          Applies filter texFilter using this texture as source and destTex as multiple destinations.
 void filter(GLTextureFilter texFilter, GLTexture[] destTexArray, GLTextureFilterParams params)
          Applies filter texFilter using this texture as source, destTex as multiple destinations and params as the parameters for the filter.
 void filter(GLTextureFilter texFilter, GLTexture destTex, GLTextureFilterParams params)
          Applies filter texFilter using this texture as source, destTex as destination and params as the parameters for the filter.
 void getImage(PImage img)
          Copies texture to img.
 int getTextureID()
          Provides the ID of the opegl texture object.
 int getTextureTarget()
          Returns the texture target.
 void init(int width, int height)
          Sets the size of the image and texture to width x height.
protected  void initTexture(int w, int h)
           
 void loadTexture()
          Copy pixels to texture (loadPixels should have been called beforehand).
 void loadTexture(java.lang.String filename)
          Load texture, pixels and image from file.
 void putImage(PImage img)
          Puts img into texture, pixels and image.
 void putPixels(int[] pix)
           
 void putPixelsIntoTexture(PImage img)
          Puts pixels of img into texture only.
protected  void releaseTexture()
           
 void renderTexture()
          Draws the texture using the opengl commands, inside a rectangle located at the origin with the original size of the texture.
 void renderTexture(float x, float y)
          Draws the texture using the opengl commands, inside a rectangle located at (x,y) with the original size of the texture.
 void renderTexture(float x, float y, float w, float h)
          Draws the texture using the opengl commands, inside a rectangle of width w and height h located at (x,y).
 void updateTexture()
          Copy texture to pixels (doesn't call updatePixels).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

gl

protected GL gl

pgl

protected PGraphicsOpenGL pgl

tex

protected int[] tex

glstate

protected GLState glstate
Constructor Detail

GLTexture

public GLTexture(PApplet parent)
Creates an instance of GLTexture with size 1x1. The texture is not initialized.

Parameters:
parent - PApplet

GLTexture

public GLTexture(PApplet parent,
                 int width,
                 int height)
Creates an instance of GLTexture with size width x height. The texture is initialized (empty) to that size.

Parameters:
parent - PApplet
width - int
height - int

GLTexture

public GLTexture(PApplet parent,
                 java.lang.String filename)
Creates an instance of GLTexture using image file filename as source.

Parameters:
filename - String
Method Detail

init

public void init(int width,
                 int height)
Sets the size of the image and texture to width x height. If the texture is already initialized, it first destroys the current opengl texture object and then creates a new one with the specified size.

Parameters:
width - int
height - int

available

public boolean available()
Returns true if the texture has been initialized.

Returns:
boolean

getTextureID

public int getTextureID()
Provides the ID of the opegl texture object.

Returns:
int

getTextureTarget

public int getTextureTarget()
Returns the texture target.

Returns:
int

putImage

public void putImage(PImage img)
Puts img into texture, pixels and image.

Parameters:
img - PImage

putPixelsIntoTexture

public void putPixelsIntoTexture(PImage img)
Puts pixels of img into texture only.

Parameters:
img - PImage

getImage

public void getImage(PImage img)
Copies texture to img.

Parameters:
img - PImage

loadTexture

public void loadTexture(java.lang.String filename)
Load texture, pixels and image from file.

Parameters:
filename - String

loadTexture

public void loadTexture()
Copy pixels to texture (loadPixels should have been called beforehand).


updateTexture

public void updateTexture()
Copy texture to pixels (doesn't call updatePixels).


filter

public void filter(GLTextureFilter texFilter,
                   GLTexture destTex)
Applies filter texFilter using this texture as source and destTex as destination.


filter

public void filter(GLTextureFilter texFilter,
                   GLTexture[] destTexArray)
Applies filter texFilter using this texture as source and destTex as multiple destinations.


filter

public void filter(GLTextureFilter texFilter,
                   GLTexture destTex,
                   GLTextureFilterParams params)
Applies filter texFilter using this texture as source, destTex as destination and params as the parameters for the filter.


filter

public void filter(GLTextureFilter texFilter,
                   GLTexture[] destTexArray,
                   GLTextureFilterParams params)
Applies filter texFilter using this texture as source, destTex as multiple destinations and params as the parameters for the filter.


renderTexture

public void renderTexture()
Draws the texture using the opengl commands, inside a rectangle located at the origin with the original size of the texture.


renderTexture

public void renderTexture(float x,
                          float y)
Draws the texture using the opengl commands, inside a rectangle located at (x,y) with the original size of the texture.

Parameters:
x - float
y - float

renderTexture

public void renderTexture(float x,
                          float y,
                          float w,
                          float h)
Draws the texture using the opengl commands, inside a rectangle of width w and height h located at (x,y).

Parameters:
x - float
y - float
w - float
h - float

initTexture

protected void initTexture(int w,
                           int h)
Parameters:
w - int
h - int

releaseTexture

protected void releaseTexture()

putPixels

public void putPixels(int[] pix)
Parameters:
pix - int[]