public class TextureRenderer extends Object
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.Constructor and Description |
---|
TextureRenderer(int width,
int height,
boolean alpha)
Creates a new renderer with backing store of the specified width
and height.
|
TextureRenderer(int width,
int height,
boolean alpha,
boolean mipmap)
Creates a new renderer with backing store of the specified width
and height.
|
Modifier and Type | Method and Description |
---|---|
void |
begin3DRendering()
Convenience method which assists in rendering portions of the
OpenGL texture to the screen as 2D quads in 3D space.
|
void |
beginOrthoRendering(int width,
int 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.
|
void |
beginOrthoRendering(int width,
int height,
boolean 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.
|
static TextureRenderer |
createAlphaOnlyRenderer(int width,
int height)
Creates a new renderer with a special kind of backing store
which acts only as an alpha channel.
|
static TextureRenderer |
createAlphaOnlyRenderer(int width,
int height,
boolean mipmap)
Creates a new renderer with a special kind of backing store
which acts only as an alpha channel.
|
Graphics2D |
createGraphics()
Creates a
Graphics2D instance for
rendering to the backing store of this renderer. |
void |
dispose()
Disposes all resources associated with this renderer.
|
void |
draw3DRect(float x,
float y,
float z,
int texturex,
int texturey,
int width,
int height,
float scaleFactor)
Draws a rectangle of the underlying texture to the specified 3D
location.
|
void |
drawOrthoRect(int screenx,
int screeny)
Draws an orthographically projected rectangle containing all of
the underlying texture to the specified location on the
screen.
|
void |
drawOrthoRect(int screenx,
int screeny,
int texturex,
int texturey,
int width,
int height)
Draws an orthographically projected rectangle of the underlying
texture to the specified location on the screen.
|
void |
end3DRendering()
Convenience method which assists in rendering portions of the
OpenGL texture to the screen as 2D quads in 3D space.
|
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.
|
int |
getHeight()
Returns the height of the backing store of this renderer.
|
Image |
getImage()
Returns the underlying Java 2D
Image
being rendered into. |
Dimension |
getSize()
Returns the size of the backing store of this renderer in a
newly-allocated
Dimension object. |
Dimension |
getSize(Dimension d)
Returns the size of the backing store of this renderer.
|
boolean |
getSmoothing()
Returns whether smoothing is enabled for the OpenGL texture; see
setSmoothing . |
Texture |
getTexture()
Returns the underlying OpenGL Texture object associated with
this renderer, synchronizing any dirty regions of the
TextureRenderer with the underlying OpenGL texture.
|
int |
getWidth()
Returns the width of the backing store of this renderer.
|
boolean |
isUsingAutoMipmapGeneration()
Indicates whether automatic mipmap generation is in use for this
TextureRenderer.
|
void |
markDirty(int x,
int y,
int width,
int height)
Marks the given region of the TextureRenderer as dirty.
|
void |
setColor(Color color)
Changes the current color of this TextureRenderer to the
supplied one.
|
void |
setColor(float r,
float g,
float b,
float a)
Changes the color of the polygons, and therefore the drawn
images, this TextureRenderer produces.
|
void |
setSize(Dimension d)
Sets the size of the backing store of this renderer.
|
void |
setSize(int width,
int height)
Sets the size of the backing store of this renderer.
|
void |
setSmoothing(boolean smoothing)
Sets whether smoothing is enabled for the OpenGL texture; if so,
uses GL_LINEAR interpolation for the minification and
magnification filters.
|
public TextureRenderer(int width, int height, boolean alpha)
alpha
is true, allocates an alpha
channel in the backing store image. No mipmap support is
requested.width
- the width of the texture to render intoheight
- the height of the texture to render intoalpha
- whether to allocate an alpha channel for the texturepublic TextureRenderer(int width, int height, boolean alpha, boolean mipmap)
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.width
- the width of the texture to render intoheight
- the height of the texture to render intoalpha
- whether to allocate an alpha channel for the texturemipmap
- whether to attempt use of automatic mipmap generationpublic static TextureRenderer createAlphaOnlyRenderer(int width, int height)
public static TextureRenderer createAlphaOnlyRenderer(int width, int height, boolean mipmap)
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.public int getWidth()
public int getHeight()
public Dimension getSize()
Dimension
object.public Dimension getSize(Dimension d)
Dimension
object if one is supplied,
or allocates a new one if null is passed.d
- a Dimension
object in which
to store the results, or null to allocate a new onepublic void setSize(int width, int height) throws GLException
getTexture
when it is needed.width
- the new width of the backing store of this rendererheight
- the new height of the backing store of this rendererGLException
- If an OpenGL context is not current when this method is calledpublic void setSize(Dimension d) throws GLException
d
- the new size of the backing store of this rendererGLException
- If an OpenGL context is not current when this method is calledpublic void setSmoothing(boolean smoothing)
beginOrthoRendering
.smoothing
- whether smoothing is enabled for the OpenGL texturepublic boolean getSmoothing()
setSmoothing
. Defaults to true.public Graphics2D createGraphics()
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.Graphics2D
object for
rendering into the backing store of this rendererpublic void markDirty(int x, int y, int width, int height)
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.x
- the x coordinate (in Java 2D coordinates -- relative to
upper left) of the region to updatey
- the y coordinate (in Java 2D coordinates -- relative to
upper left) of the region to updatewidth
- the width of the region to updateheight
- the height of the region to updatepublic Texture getTexture() throws GLException
GLException
- If an OpenGL context is not current when this method is calledpublic void dispose() throws GLException
GLException
- If an OpenGL context is not current when this method is calledpublic void beginOrthoRendering(int width, int height) throws GLException
endOrthoRendering()
must be used in conjunction with this
method to restore all OpenGL states.width
- the width of the current on-screen OpenGL drawableheight
- the height of the current on-screen OpenGL drawableGLException
- If an OpenGL context is not current when this method is calledpublic void beginOrthoRendering(int width, int height, boolean disableDepthTest) throws GLException
endOrthoRendering()
must be used in conjunction with this method
to restore all OpenGL states.width
- the width of the current on-screen OpenGL drawableheight
- the height of the current on-screen OpenGL drawabledisableDepthTest
- whether the depth test should be disabledGLException
- If an OpenGL context is not current when this method is calledpublic void begin3DRendering() throws GLException
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.GLException
- If an OpenGL context is not current when this method is calledpublic void setColor(float r, float g, float b, float a) throws GLException
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.
r
- the red component of the new colorg
- the green component of the new colorb
- the blue component of the new colora
- the alpha component of the new color, 0.0f = completely
transparent, 1.0f = completely opaqueGLException
- If an OpenGL context is not current when this method is calledpublic void setColor(Color color) throws GLException
setColor
for more details.color
- the new color to use for renderingGLException
- If an OpenGL context is not current when this method is calledpublic void drawOrthoRect(int screenx, int screeny) throws GLException
drawOrthoRect(screenx, screeny, 0, 0, getWidth(),
getHeight());
.screenx
- the on-screen x coordinate at which to draw the rectanglescreeny
- the on-screen y coordinate (relative to lower left) at
which to draw the rectangleGLException
- If an OpenGL context is not current when this method is calledpublic void drawOrthoRect(int screenx, int screeny, int texturex, int texturey, int width, int height) throws GLException
screenx
- the on-screen x coordinate at which to draw the rectanglescreeny
- the on-screen y coordinate (relative to lower left) at
which to draw the rectangletexturex
- the x coordinate of the pixel in the texture of
the lower left portion of the rectangle to drawtexturey
- the y coordinate of the pixel in the texture
(relative to lower left) of the lower left portion of the
rectangle to drawwidth
- the width of the rectangle to drawheight
- the height of the rectangle to drawGLException
- If an OpenGL context is not current when this method is calledpublic void draw3DRect(float x, float y, float z, int texturex, int texturey, int width, int height, float scaleFactor) throws GLException
x
- the x coordinate at which to draw the rectangley
- the y coordinate at which to draw the rectanglez
- the z coordinate at which to draw the rectangletexturex
- the x coordinate of the pixel in the texture of
the lower left portion of the rectangle to drawtexturey
- the y coordinate of the pixel in the texture
(relative to lower left) of the lower left portion of the
rectangle to drawwidth
- the width in texels of the rectangle to drawheight
- the height in texels of the rectangle to drawscaleFactor
- the scale factor to apply (multiplicatively)
to the size of the drawn rectangleGLException
- If an OpenGL context is not current when this method is calledpublic void endOrthoRendering() throws GLException
beginOrthoRendering(int, int)
is used to set up the rendering stage for
this overlay.GLException
- If an OpenGL context is not current when this method is calledpublic void end3DRendering() throws GLException
begin3DRendering()
is used to set up the
rendering stage for this overlay.GLException
- If an OpenGL context is not current when this method is calledpublic boolean isUsingAutoMipmapGeneration()
Copyright 2010 JogAmp Community.