Top Description Fields Constructors Methods
com.jogamp.opengl.util.awt

public Class TextureRenderer

extends Object
Class Inheritance
Imports
java.awt.Color, .Dimension, .Graphics2D, .Image, .Rectangle, java.awt.image.*, com.jogamp.opengl.*, com.jogamp.opengl.fixedfunc.GLLightingFunc, .GLMatrixFunc, com.jogamp.opengl.glu.gl2.*, com.jogamp.opengl.util.texture.*, com.jogamp.opengl.util.texture.awt.*

Provides the ability to render into an OpenGL Texture using the Java 2D APIs. This renderer class uses an internal Java 2D image (of unspecified type) for its backing store and flushes portions of that image to an OpenGL texture on demand. The resulting OpenGL texture can then be mapped on to a polygon for display.

Field Summary

Modifier and TypeField and Description
private float
a

private final boolean
private float
b

private float[]
private Rectangle
private float
g

private final GLUgl2
private BufferedImage
private final boolean
private boolean
private boolean
private float
r

private boolean
private boolean
private Texture
private AWTTextureData

Constructor Summary

AccessConstructor and Description
public
TextureRenderer(final int
the width of the texture to render into
width
,
final int
the height of the texture to render into
height
,
final boolean
whether to allocate an alpha channel for the texture
alpha
)

Creates a new renderer with backing store of the specified width and height.

public
TextureRenderer(final int
the width of the texture to render into
width
,
final int
the height of the texture to render into
height
,
final boolean
whether to allocate an alpha channel for the texture
alpha
,
final boolean
whether to attempt use of automatic mipmap generation
mipmap
)

Creates a new renderer with backing store of the specified width and height.

private
TextureRenderer(final int width, final int height, final boolean alpha, final boolean intensity, final boolean mipmap)

Method Summary

Modifier and TypeMethod and Description
public void
begin3DRendering()

Convenience method which assists in rendering portions of the OpenGL texture to the screen as 2D quads in 3D space.

public void
beginOrthoRendering(final int
the width of the current on-screen OpenGL drawable
width
,
final int
the height of the current on-screen OpenGL drawable
height
)

Convenience method which assists in rendering portions of the OpenGL texture to the screen, if the application intends to draw them as a flat overlay on to the screen.

public void
beginOrthoRendering(final int
the width of the current on-screen OpenGL drawable
width
,
final int
the height of the current on-screen OpenGL drawable
height
,
final boolean
whether the depth test should be disabled
disableDepthTest
)

Convenience method which assists in rendering portions of the OpenGL texture to the screen, if the application intends to draw them as a flat overlay on to the screen.

private void
beginRendering(final boolean ortho, final int width, final int height, final boolean disableDepthTestForOrtho)

public static TextureRenderer
createAlphaOnlyRenderer(final int width, final int height)

Creates a new renderer with a special kind of backing store which acts only as an alpha channel.

public static TextureRenderer
createAlphaOnlyRenderer(final int width, final int height, final boolean mipmap)

Creates a new renderer with a special kind of backing store which acts only as an alpha channel.

public Graphics2D

Returns:

a new Graphics2D object for rendering into the backing store of this renderer
createGraphics
()

Creates a Graphics2D instance for rendering to the backing store of this renderer.

public void
dispose()

Disposes all resources associated with this renderer.

public void
draw3DRect(final float
the x coordinate at which to draw the rectangle
x
,
final float
the y coordinate at which to draw the rectangle
y
,
final float
the z coordinate at which to draw the rectangle
z
,
final int
the x coordinate of the pixel in the texture of the lower left portion of the rectangle to draw
texturex
,
final int
the y coordinate of the pixel in the texture (relative to lower left) of the lower left portion of the rectangle to draw
texturey
,
final int
the width in texels of the rectangle to draw
width
,
final int
the height in texels of the rectangle to draw
height
,
final float
the scale factor to apply (multiplicatively) to the size of the drawn rectangle
scaleFactor
)

Draws a rectangle of the underlying texture to the specified 3D location.

public void
drawOrthoRect(final int
the on-screen x coordinate at which to draw the rectangle
screenx
,
final int
the on-screen y coordinate (relative to lower left) at which to draw the rectangle
screeny
)

Draws an orthographically projected rectangle containing all of the underlying texture to the specified location on the screen.

public void
drawOrthoRect(final int
the on-screen x coordinate at which to draw the rectangle
screenx
,
final int
the on-screen y coordinate (relative to lower left) at which to draw the rectangle
screeny
,
final int
the x coordinate of the pixel in the texture of the lower left portion of the rectangle to draw
texturex
,
final int
the y coordinate of the pixel in the texture (relative to lower left) of the lower left portion of the rectangle to draw
texturey
,
final int
the width of the rectangle to draw
width
,
final int
the height of the rectangle to draw
height
)

Draws an orthographically projected rectangle of the underlying texture to the specified location on the screen.

public void
end3DRendering()

Convenience method which assists in rendering portions of the OpenGL texture to the screen as 2D quads in 3D space.

public void
endOrthoRendering()

Convenience method which assists in rendering portions of the OpenGL texture to the screen, if the application intends to draw them as a flat overlay on to the screen.

private void
endRendering(final boolean ortho)

private boolean
public int

Returns:

the height of the backing store of this renderer
getHeight
()

Returns the height of the backing store of this renderer.

public Image
getImage()

Returns the underlying Java 2D Image being rendered into.

public Dimension

Returns:

the size of the backing store of this renderer
getSize
()

Returns the size of the backing store of this renderer in a newly-allocated Dimension object.

public Dimension

Returns:

the size of the backing store of this renderer
getSize
(Dimension
a Dimension object in which to store the results, or null to allocate a new one
d
)

Returns the size of the backing store of this renderer.

public boolean

Returns:

whether smoothing is enabled for the OpenGL texture
getSmoothing
()

Returns whether smoothing is enabled for the OpenGL texture; see setSmoothing.

public Texture
getTexture()

Returns the underlying OpenGL Texture object associated with this renderer, synchronizing any dirty regions of the TextureRenderer with the underlying OpenGL texture.

public int

Returns:

the width of the backing store of this renderer
getWidth
()

Returns the width of the backing store of this renderer.

private void
init(final int width, final int height)

public boolean
isUsingAutoMipmapGeneration()

Indicates whether automatic mipmap generation is in use for this TextureRenderer.

public void
markDirty(final int
the x coordinate (in Java 2D coordinates -- relative to upper left) of the region to update
x
,
final int
the y coordinate (in Java 2D coordinates -- relative to upper left) of the region to update
y
,
final int
the width of the region to update
width
,
final int
the height of the region to update
height
)

Marks the given region of the TextureRenderer as dirty.

public void
setColor(final float
the red component of the new color
r
,
final float
the green component of the new color
g
,
final float
the blue component of the new color
b
,
final float
the alpha component of the new color, 0.0f = completely transparent, 1.0f = completely opaque
a
)

Changes the color of the polygons, and therefore the drawn images, this TextureRenderer produces.

public void
setColor(final Color
the new color to use for rendering
color
)

Changes the current color of this TextureRenderer to the supplied one.

public void
setSize(final int
the new width of the backing store of this renderer
width
,
final int
the new height of the backing store of this renderer
height
)

Sets the size of the backing store of this renderer.

public void
setSize(final Dimension
the new size of the backing store of this renderer
d
)

Sets the size of the backing store of this renderer.

public void
setSmoothing(final boolean
whether smoothing is enabled for the OpenGL texture
smoothing
)

Sets whether smoothing is enabled for the OpenGL texture; if so, uses GL_LINEAR interpolation for the minification and magnification filters.

private void
sync(final int
the x coordinate (in Java 2D coordinates -- relative to upper left) of the region to update
x
,
final int
the y coordinate (in Java 2D coordinates -- relative to upper left) of the region to update
y
,
final int
the width of the region to update
width
,
final int
the height of the region to update
height
)

Synchronizes the specified region of the backing store down to the underlying OpenGL texture.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aback to summary
private float a
alphaback to summary
private final boolean alpha
bback to summary
private float b
compArrayback to summary
private float[] compArray
dirtyRegionback to summary
private Rectangle dirtyRegion
gback to summary
private float g
gluback to summary
private final GLUgl2 glu
imageback to summary
private BufferedImage image
intensityback to summary
private final boolean intensity
mipmapback to summary
private boolean mipmap
mustReallocateTextureback to summary
private boolean mustReallocateTexture
rback to summary
private float r
smoothingback to summary
private boolean smoothing
smoothingChangedback to summary
private boolean smoothingChanged
textureback to summary
private Texture texture
textureDataback to summary
private AWTTextureData textureData

Constructor Detail

TextureRendererback to summary
public TextureRenderer(final int width, final int height, final boolean alpha)

Creates a new renderer with backing store of the specified width and height. If alpha is true, allocates an alpha channel in the backing store image. No mipmap support is requested.

Parameters
width:int

the width of the texture to render into

height:int

the height of the texture to render into

alpha:boolean

whether to allocate an alpha channel for the texture

TextureRendererback to summary
public TextureRenderer(final int width, final int height, final boolean alpha, final boolean mipmap)

Creates a new renderer with backing store of the specified width and height. If alpha is true, allocates an alpha channel in the backing store image. If mipmap is true, attempts to use OpenGL's automatic mipmap generation for better smoothing when rendering the TextureRenderer's contents at a distance.

Parameters
width:int

the width of the texture to render into

height:int

the height of the texture to render into

alpha:boolean

whether to allocate an alpha channel for the texture

mipmap:boolean

whether to attempt use of automatic mipmap generation

TextureRendererback to summary
private TextureRenderer(final int width, final int height, final boolean alpha, final boolean intensity, final boolean mipmap)

Method Detail

begin3DRenderingback to summary
public void begin3DRendering() throws GLException

Convenience method which assists in rendering portions of the OpenGL texture to the screen as 2D quads in 3D space. Pushes OpenGL state (GL_ENABLE_BIT); disables lighting; and enables the texture in this renderer. Unlike beginOrthoRendering, does not modify the depth test, back-face culling, lighting, or the modelview or projection matrices. The user is responsible for setting up the view matrices for correct results of draw3DRect. end3DRendering must be used in conjunction with this method to restore all OpenGL states.

Exceptions
GLException:
If an OpenGL context is not current when this method is called
beginOrthoRenderingback to summary
public void beginOrthoRendering(final int width, final int height) throws GLException

Convenience method which assists in rendering portions of the OpenGL texture to the screen, if the application intends to draw them as a flat overlay on to the screen. Pushes OpenGL state bits (GL_ENABLE_BIT, GL_DEPTH_BUFFER_BIT and GL_TRANSFORM_BIT); disables the depth test, back-face culling, and lighting; enables the texture in this renderer; and sets up the viewing matrices for orthographic rendering where the coordinates go from (0, 0) at the lower left to (width, height) at the upper right. Equivalent to beginOrthoRendering(width, height, true). endOrthoRendering must be used in conjunction with this method to restore all OpenGL states.

Parameters
width:int

the width of the current on-screen OpenGL drawable

height:int

the height of the current on-screen OpenGL drawable

Exceptions
GLException:
If an OpenGL context is not current when this method is called
beginOrthoRenderingback to summary
public void beginOrthoRendering(final int width, final int height, final boolean disableDepthTest) throws GLException

Convenience method which assists in rendering portions of the OpenGL texture to the screen, if the application intends to draw them as a flat overlay on to the screen. Pushes OpenGL state bits (GL_ENABLE_BIT, GL_DEPTH_BUFFER_BIT and GL_TRANSFORM_BIT); disables the depth test (if the "disableDepthTest" argument is true), back-face culling, and lighting; enables the texture in this renderer; and sets up the viewing matrices for orthographic rendering where the coordinates go from (0, 0) at the lower left to (width, height) at the upper right. endOrthoRendering must be used in conjunction with this method to restore all OpenGL states.

Parameters
width:int

the width of the current on-screen OpenGL drawable

height:int

the height of the current on-screen OpenGL drawable

disableDepthTest:boolean

whether the depth test should be disabled

Exceptions
GLException:
If an OpenGL context is not current when this method is called
beginRenderingback to summary
private void beginRendering(final boolean ortho, final int width, final int height, final boolean disableDepthTestForOrtho)
createAlphaOnlyRendererback to summary
public static TextureRenderer createAlphaOnlyRenderer(final int width, final int height)

Creates a new renderer with a special kind of backing store which acts only as an alpha channel. No mipmap support is requested. Internally, this associates a GL_INTENSITY OpenGL texture with the backing store.

createAlphaOnlyRendererback to summary
public static TextureRenderer createAlphaOnlyRenderer(final int width, final int height, final boolean mipmap)

Creates a new renderer with a special kind of backing store which acts only as an alpha channel. If mipmap is true, attempts to use OpenGL's automatic mipmap generation for better smoothing when rendering the TextureRenderer's contents at a distance. Internally, this associates a GL_INTENSITY OpenGL texture with the backing store.

createGraphicsback to summary
public Graphics2D createGraphics()

Creates a Graphics2D instance for rendering to the backing store of this renderer. The returned object should be disposed of using the normal Graphics.dispose() method once it is no longer being used.

Returns:Graphics2D

a new Graphics2D object for rendering into the backing store of this renderer

disposeback to summary
public void dispose() throws GLException

Disposes all resources associated with this renderer. It is not valid to use this renderer after calling this method.

Exceptions
GLException:
If an OpenGL context is not current when this method is called
draw3DRectback to summary
public void draw3DRect(final float x, final float y, final float z, final int texturex, final int texturey, final int width, final int height, final float scaleFactor) throws GLException

Draws a rectangle of the underlying texture to the specified 3D location. In the current coordinate system, the lower left corner of the rectangle is placed at (x, y, z), and the upper right corner is placed at (x + width * scaleFactor, y + height * scaleFactor, z). The lower left corner of the sub-rectangle of the texture is (texturex, texturey) and the upper right corner is (texturex + width, texturey + height). For back-face culling purposes, the rectangle is drawn with counterclockwise orientation of the vertices when viewed from the front.

Parameters
x:float

the x coordinate at which to draw the rectangle

y:float

the y coordinate at which to draw the rectangle

z:float

the z coordinate at which to draw the rectangle

texturex:int

the x coordinate of the pixel in the texture of the lower left portion of the rectangle to draw

texturey:int

the y coordinate of the pixel in the texture (relative to lower left) of the lower left portion of the rectangle to draw

width:int

the width in texels of the rectangle to draw

height:int

the height in texels of the rectangle to draw

scaleFactor:float

the scale factor to apply (multiplicatively) to the size of the drawn rectangle

Exceptions
GLException:
If an OpenGL context is not current when this method is called
drawOrthoRectback to summary
public void drawOrthoRect(final int screenx, final int screeny) throws GLException

Draws an orthographically projected rectangle containing all of the underlying texture to the specified location on the screen. All (x, y) coordinates are specified relative to the lower left corner of either the texture image or the current OpenGL drawable. This method is equivalent to drawOrthoRect(screenx, screeny, 0, 0, getWidth(), getHeight());.

Parameters
screenx:int

the on-screen x coordinate at which to draw the rectangle

screeny:int

the on-screen y coordinate (relative to lower left) at which to draw the rectangle

Exceptions
GLException:
If an OpenGL context is not current when this method is called
drawOrthoRectback to summary
public void drawOrthoRect(final int screenx, final int screeny, final int texturex, final int texturey, final int width, final int height) throws GLException

Draws an orthographically projected rectangle of the underlying texture to the specified location on the screen. All (x, y) coordinates are specified relative to the lower left corner of either the texture image or the current OpenGL drawable.

Parameters
screenx:int

the on-screen x coordinate at which to draw the rectangle

screeny:int

the on-screen y coordinate (relative to lower left) at which to draw the rectangle

texturex:int

the x coordinate of the pixel in the texture of the lower left portion of the rectangle to draw

texturey:int

the y coordinate of the pixel in the texture (relative to lower left) of the lower left portion of the rectangle to draw

width:int

the width of the rectangle to draw

height:int

the height of the rectangle to draw

Exceptions
GLException:
If an OpenGL context is not current when this method is called
end3DRenderingback to summary
public void end3DRendering() throws GLException

Convenience method which assists in rendering portions of the OpenGL texture to the screen as 2D quads in 3D space. Must be used if begin3DRendering is used to set up the rendering stage for this overlay.

Exceptions
GLException:
If an OpenGL context is not current when this method is called
endOrthoRenderingback to summary
public void endOrthoRendering() throws GLException

Convenience method which assists in rendering portions of the OpenGL texture to the screen, if the application intends to draw them as a flat overlay on to the screen. Must be used if beginOrthoRendering is used to set up the rendering stage for this overlay.

Exceptions
GLException:
If an OpenGL context is not current when this method is called
endRenderingback to summary
private void endRendering(final boolean ortho)
ensureTextureback to summary
private boolean ensureTexture()
getHeightback to summary
public int getHeight()

Returns the height of the backing store of this renderer.

Returns:int

the height of the backing store of this renderer

getImageback to summary
public Image getImage()

Returns the underlying Java 2D Image being rendered into.

getSizeback to summary
public Dimension getSize()

Returns the size of the backing store of this renderer in a newly-allocated Dimension object.

Returns:Dimension

the size of the backing store of this renderer

getSizeback to summary
public Dimension getSize(Dimension d)

Returns the size of the backing store of this renderer. Uses the Dimension object if one is supplied, or allocates a new one if null is passed.

Parameters
d:Dimension

a Dimension object in which to store the results, or null to allocate a new one

Returns:Dimension

the size of the backing store of this renderer

getSmoothingback to summary
public boolean getSmoothing()

Returns whether smoothing is enabled for the OpenGL texture; see setSmoothing. Defaults to true.

Returns:boolean

whether smoothing is enabled for the OpenGL texture

getTextureback to summary
public Texture getTexture() throws GLException

Returns the underlying OpenGL Texture object associated with this renderer, synchronizing any dirty regions of the TextureRenderer with the underlying OpenGL texture.

Exceptions
GLException:
If an OpenGL context is not current when this method is called
getWidthback to summary
public int getWidth()

Returns the width of the backing store of this renderer.

Returns:int

the width of the backing store of this renderer

initback to summary
private void init(final int width, final int height)
isUsingAutoMipmapGenerationback to summary
public boolean isUsingAutoMipmapGeneration()

Indicates whether automatic mipmap generation is in use for this TextureRenderer. The result of this method may change from true to false if it is discovered during allocation of the TextureRenderer's backing store that automatic mipmap generation is not supported at the OpenGL level.

markDirtyback to summary
public void markDirty(final int x, final int y, final int width, final int height)

Marks the given region of the TextureRenderer as dirty. This region, and any previously set dirty regions, will be automatically synchronized with the underlying Texture during the next getTexture operation, at which point the dirty region will be cleared. It is not necessary for an OpenGL context to be current when this method is called.

Parameters
x:int

the x coordinate (in Java 2D coordinates -- relative to upper left) of the region to update

y:int

the y coordinate (in Java 2D coordinates -- relative to upper left) of the region to update

width:int

the width of the region to update

height:int

the height of the region to update

setColorback to summary
public void setColor(final float r, final float g, final float b, final float a) throws GLException

Changes the color of the polygons, and therefore the drawn images, this TextureRenderer produces. Use of this method is optional. The TextureRenderer uses the GL_MODULATE texture environment mode, which causes the portions of the rendered texture to be multiplied by the color of the rendered polygons. The polygon color can be varied to achieve effects like tinting of the overall output or fading in and out by changing the alpha of the color.

Each component ranges from 0.0f - 1.0f. The alpha component, if used, does not need to be premultiplied into the color channels as described in the documentation for Texture, although premultiplied colors are used internally. The default color is opaque white.

Parameters
r:float

the red component of the new color

g:float

the green component of the new color

b:float

the blue component of the new color

a:float

the alpha component of the new color, 0.0f = completely transparent, 1.0f = completely opaque

Exceptions
GLException:
If an OpenGL context is not current when this method is called
setColorback to summary
public void setColor(final Color color) throws GLException

Changes the current color of this TextureRenderer to the supplied one. The default color is opaque white. See setColor for more details.

Parameters
color:Color

the new color to use for rendering

Exceptions
GLException:
If an OpenGL context is not current when this method is called
setSizeback to summary
public void setSize(final int width, final int height) throws GLException

Sets the size of the backing store of this renderer. This may cause the OpenGL texture object associated with this renderer to be invalidated; it is not recommended to cache this texture object outside this class but to instead call getTexture when it is needed.

Parameters
width:int

the new width of the backing store of this renderer

height:int

the new height of the backing store of this renderer

Exceptions
GLException:
If an OpenGL context is not current when this method is called
setSizeback to summary
public void setSize(final Dimension d) throws GLException

Sets the size of the backing store of this renderer. This may cause the OpenGL texture object associated with this renderer to be invalidated.

Parameters
d:Dimension

the new size of the backing store of this renderer

Exceptions
GLException:
If an OpenGL context is not current when this method is called
setSmoothingback to summary
public void setSmoothing(final boolean smoothing)

Sets whether smoothing is enabled for the OpenGL texture; if so, uses GL_LINEAR interpolation for the minification and magnification filters. Defaults to true. Changes to this setting will not take effect until the next call to beginOrthoRendering.

Parameters
smoothing:boolean

whether smoothing is enabled for the OpenGL texture

syncback to summary
private void sync(final int x, final int y, final int width, final int height) throws GLException

Synchronizes the specified region of the backing store down to the underlying OpenGL texture. If markDirty is used instead to indicate the regions that are out of sync, this method does not need to be called.

Parameters
x:int

the x coordinate (in Java 2D coordinates -- relative to upper left) of the region to update

y:int

the y coordinate (in Java 2D coordinates -- relative to upper left) of the region to update

width:int

the width of the region to update

height:int

the height of the region to update

Exceptions
GLException:
If an OpenGL context is not current when this method is called