codeanticode.glgraphics
Class GLTexture

java.lang.Object
  extended by processing.core.PImage
      extended by codeanticode.glgraphics.GLTexture
All Implemented Interfaces:
GLConstants, java.lang.Cloneable, processing.core.PConstants

public class GLTexture
extends processing.core.PImage
implements processing.core.PConstants, GLConstants

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  boolean flippedX
           
protected  boolean flippedY
           
protected  GL gl
           
protected  GLState glstate
           
protected  int magFilter
           
protected  float maxTexCoordS
           
protected  float maxTexCoordT
           
protected  int minFilter
           
protected  PGraphicsOpenGL pgl
           
protected  int[] tex
           
protected  int texInternalFormat
           
protected  int texTarget
           
protected  boolean usingMipmaps
           
 
Fields inherited from class processing.core.PImage
cache, format, height, imageMode, modified, mx1, mx2, my1, my2, parent, pixels, saveImageFormats, smooth, width
 
Fields inherited from interface processing.core.PConstants
ADD, ALPHA, ALPHA_MASK, ALT, AMBIENT, ARGB, ARROW, BACKSPACE, BASELINE, BEVEL, BLEND, BLUE_MASK, BLUR, BOTTOM, BURN, CENTER, CENTER_RADIUS, CHATTER, CLOSE, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CUSTOM, DARKEST, DEG_TO_RAD, DELETE, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_AUTO_GZIP, DISABLE_DEPTH_TEST, DISABLE_ERROR_REPORT, DISABLE_FLYING_POO, DODGE, DOWN, DXF, ENABLE_ACCURATE_TEXTURES, ENABLE_DEPTH_SORT, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_2X_SMOOTH, ENABLE_OPENGL_4X_SMOOTH, ENTER, EPSILON, ERODE, ESC, EXCLUSION, GIF, GRAY, GREEN_MASK, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LEFT, LIGHTEST, LINES, LINUX, MACOS9, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MOVE, MULTIPLY, NORMALIZED, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PDF, PERSPECTIVE, PI, PIXEL_CENTER, POINT, POINTS, POLYGON, POSTERIZE, PROBLEM, PROJECT, QUAD_STRIP, QUADS, QUARTER_PI, RAD_TO_DEG, RADIUS, RED_MASK, REPLACE, RETURN, RGB, RIGHT, ROUND, SCREEN, SHAPE, SHIFT, SOFT_LIGHT, SPOT, SQUARE, SUBTRACT, TAB, TARGA, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, UP, WAIT, WHITESPACE, WINDOWS
 
Fields inherited from interface codeanticode.glgraphics.GLConstants
COLOR, DOUBLE4, FLOAT4, GL_DEPTH_STENCIL, GL_DEPTH24_STENCIL8, GL_UNSIGNED_INT_24_8, GLGRAPHICS, LINEAR, LINEAR_MIPMAP_LINEAR, LINEAR_MIPMAP_NEAREST, NEAREST, NEAREST_MIPMAP_LINEAR, NEAREST_MIPMAP_NEAREST, NORMAL, RECTANGULAR
 
Constructor Summary
GLTexture(processing.core.PApplet parent)
          Creates an instance of GLTexture with size 1x1.
GLTexture(processing.core.PApplet parent, int width, int height)
          Creates an instance of GLTexture with size width x height.
GLTexture(processing.core.PApplet parent, int width, int height, GLTextureParameters params)
          Creates an instance of GLTexture with size width x height and with the specified parameters.
GLTexture(processing.core.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, float fadeConst)
          Applies filter texFilter using this texture as source, destTex as multiple destinations and fadeConst as the fading constant for the filter.
 void filter(GLTextureFilter texFilter, GLTexture[] destTexArray, float fadeConst, GLTextureFilterParameters params)
          Applies filter texFilter using this texture as source, destTex as multiple destinations, fadeConst as the fading constant for the filter and params as the parameters for the filter.
 void filter(GLTextureFilter texFilter, GLTexture[] destTexArray, GLTextureFilterParameters 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, float fadeConst)
          Applies filter texFilter using this texture as source, destTex as destination and fadeConst as the fading constant for the filter.
 void filter(GLTextureFilter texFilter, GLTexture destTex, float fadeConst, GLTextureFilterParameters params)
          Applies filter texFilter using this texture as source, destTex as destination, fadeConst as the fading constant for the filter and params as the parameters for the filter.
 void filter(GLTextureFilter texFilter, GLTexture destTex, GLTextureFilterParameters params)
          Applies filter texFilter using this texture as source, destTex as destination and params as the parameters for the filter.
 void getImage(processing.core.PImage img)
          Copies texture to img.
 float getMaxTextureCoordS()
          Returns the maximum possible value for the texture coordinate S.
 float getMaxTextureCoordT()
          Returns the maximum possible value for the texture coordinate T.
 int getTextureID()
          Provides the ID of the opegl texture object.
 int getTextureInternalFormat()
          Returns the texture internal format.
 int getTextureMagFilter()
          Returns the texture magnification filter.
 int getTextureMinFilter()
          Returns the texture minimization filter.
 int getTextureTarget()
          Returns the texture target.
 void init(int width, int height)
          Sets the size of the image and texture to width x height.
 void init(int width, int height, GLTextureParameters params)
          Sets the size of the image and texture to width x height, and the parameters of the texture to params .
protected  void initTexture(int w, int h)
           
 boolean isFlippedX()
          Returns true if the texture is flipped along the horizontal direction.
 boolean isFlippedY()
          Returns true if the texture is flipped along the vertical direction.
 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(processing.core.PImage img)
          Puts img into texture, pixels and image.
protected  void putPixels(int[] pix)
           
 void putPixelsIntoTexture(processing.core.PImage img)
          Puts pixels of img into texture only.
protected  void releaseTexture()
           
 void render()
          Draws the texture using the opengl commands, inside a rectangle located at the origin with the original size of the texture.
 void render(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 render(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 setFlippedX(boolean v)
          Sets the texture as flipped or not flipped on the horizontal direction.
 void setFlippedY(boolean v)
          Sets the texture as flipped or not flipped on the vertical direction.
protected  void setTextureParams(GLTextureParameters params)
           
 void updateTexture()
          Copy texture to pixels (doesn't call updatePixels).
 boolean usingMipmaps()
          Returns true or false whether or not the texture is using mipmaps.
 
Methods inherited from class processing.core.PImage
blend, blend, blendColor, blurAlpha, blurARGB, blurRGB, buildBlurKernel, checkAlpha, clone, copy, copy, dilate, filter, filter, get, get, get, imageMode, init, intersect, loadPixels, loadTIFF, mask, mask, noSmooth, save, saveImageIO, saveTGA, saveTIFF, set, set, setImpl, smooth, updatePixels, updatePixels
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

gl

protected GL gl

pgl

protected PGraphicsOpenGL pgl

tex

protected int[] tex

texTarget

protected int texTarget

texInternalFormat

protected int texInternalFormat

minFilter

protected int minFilter

magFilter

protected int magFilter

usingMipmaps

protected boolean usingMipmaps

maxTexCoordS

protected float maxTexCoordS

maxTexCoordT

protected float maxTexCoordT

flippedX

protected boolean flippedX

flippedY

protected boolean flippedY

glstate

protected GLState glstate
Constructor Detail

GLTexture

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

Parameters:
parent - PApplet

GLTexture

public GLTexture(processing.core.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(processing.core.PApplet parent,
                 int width,
                 int height,
                 GLTextureParameters params)
Creates an instance of GLTexture with size width x height and with the specified parameters. The texture is initialized (empty) to that size.

Parameters:
parent - PApplet
width - int
height - int
params - GLTextureParameters

GLTexture

public GLTexture(processing.core.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

init

public void init(int width,
                 int height,
                 GLTextureParameters params)
Sets the size of the image and texture to width x height, and the parameters of the texture to params . 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
params - GLTextureParameters

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

getTextureInternalFormat

public int getTextureInternalFormat()
Returns the texture internal format.

Returns:
int

getTextureMinFilter

public int getTextureMinFilter()
Returns the texture minimization filter.

Returns:
int

getTextureMagFilter

public int getTextureMagFilter()
Returns the texture magnification filter.

Returns:
int

usingMipmaps

public boolean usingMipmaps()
Returns true or false whether or not the texture is using mipmaps.

Returns:
boolean

getMaxTextureCoordS

public float getMaxTextureCoordS()
Returns the maximum possible value for the texture coordinate S.

Returns:
float

getMaxTextureCoordT

public float getMaxTextureCoordT()
Returns the maximum possible value for the texture coordinate T.

Returns:
float

isFlippedX

public boolean isFlippedX()
Returns true if the texture is flipped along the horizontal direction.

Returns:
boolean;

setFlippedX

public void setFlippedX(boolean v)
Sets the texture as flipped or not flipped on the horizontal direction.

Parameters:
v - boolean;

isFlippedY

public boolean isFlippedY()
Returns true if the texture is flipped along the vertical direction.

Returns:
boolean;

setFlippedY

public void setFlippedY(boolean v)
Sets the texture as flipped or not flipped on the vertical direction.

Parameters:
v - boolean;

putImage

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

Parameters:
img - PImage

putPixelsIntoTexture

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

Parameters:
img - PImage

getImage

public void getImage(processing.core.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.

Parameters:
texFilter - GLTextureFilter
destTex - GLTexture

filter

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

Parameters:
texFilter - GLTextureFilter
destTexArray - GLTexture[]

filter

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

Parameters:
texFilter - GLTextureFilter
destTex - GLTexture
params - GLTextureFilterParameters

filter

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

Parameters:
texFilter - GLTextureFilter
destTexArray - GLTexture[]
params - GLTextureFilterParameters

filter

public void filter(GLTextureFilter texFilter,
                   GLTexture destTex,
                   float fadeConst)
Applies filter texFilter using this texture as source, destTex as destination and fadeConst as the fading constant for the filter.

Parameters:
texFilter - GLTextureFilter
destTex - GLTexture
fadeConst - float

filter

public void filter(GLTextureFilter texFilter,
                   GLTexture[] destTexArray,
                   float fadeConst)
Applies filter texFilter using this texture as source, destTex as multiple destinations and fadeConst as the fading constant for the filter.

Parameters:
texFilter - GLTextureFilter
destTexArray - GLTexture[]
fadeConst - float

filter

public void filter(GLTextureFilter texFilter,
                   GLTexture destTex,
                   float fadeConst,
                   GLTextureFilterParameters params)
Applies filter texFilter using this texture as source, destTex as destination, fadeConst as the fading constant for the filter and params as the parameters for the filter.

Parameters:
texFilter - GLTextureFilter
destTex - GLTexture
fadeConst - float

filter

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

Parameters:
texFilter - GLTextureFilter
destTexArray - GLTexture[]
fadeConst - float

render

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


render

public void render(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

render

public void render(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

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

setTextureParams

protected void setTextureParams(GLTextureParameters params)
Parameters:
target - int
params - GLTextureParameters