Package com.jogamp.opengl.util.awt
Class Overlay
java.lang.Object
com.jogamp.opengl.util.awt.Overlay
Provides a Java 2D overlay on top of an arbitrary GLDrawable,
making it easier to do things like draw text and images on top of
an OpenGL scene while still maintaining reasonably good
efficiency.
-
Constructor Summary
ConstructorsConstructorDescriptionOverlay
(GLDrawable drawable) Creates a new Java 2D overlay on top of the specified GLDrawable. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Begins the OpenGL rendering process for the overlay.boolean
Indicates whether the Java 2D contents of the overlay were lost since the last timecreateGraphics()
was called.Creates aGraphics2D
instance for rendering into the overlay.void
draw
(int x, int y, int width, int height) Draws the specified sub-rectangle of the overlay on top of the OpenGL drawable.void
draw
(int screenx, int screeny, int overlayx, int overlayy, int width, int height) Draws the specified sub-rectangle of the overlay at the specified x and y coordinate on top of the OpenGL drawable.void
drawAll()
Draws the entire contents of the overlay on top of the OpenGL drawable.void
Ends the OpenGL rendering process for the overlay.void
markDirty
(int x, int y, int width, int height) Marks the given region of the overlay as dirty.
-
Constructor Details
-
Overlay
Creates a new Java 2D overlay on top of the specified GLDrawable.
-
-
Method Details
-
createGraphics
Creates aGraphics2D
instance for rendering into the overlay. The returned object should be disposed of using the normalGraphics.dispose()
method once it is no longer being used.- Returns:
- a new
Graphics2D
object for rendering into the backing store of this renderer
-
contentsLost
public boolean contentsLost()Indicates whether the Java 2D contents of the overlay were lost since the last timecreateGraphics()
was called. This method should be called immediately after callingcreateGraphics()
to see whether the entire contents of the overlay need to be redrawn or just the region the application is interested in updating.- Returns:
- whether the contents of the overlay were lost since the last render
-
markDirty
public void markDirty(int x, int y, int width, int height) Marks the given region of the overlay as dirty. This region, and any previously set dirty regions, will be automatically synchronized with the underlying Texture during the nextdraw
ordrawAll
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
- 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 update- Throws:
GLException
- If an OpenGL context is not current when this method is called
-
drawAll
Draws the entire contents of the overlay on top of the OpenGL drawable. This is a convenience method which encapsulates all portions of the rendering process; if this method is used,beginRendering()
,endRendering()
, etc. should not be used. This method should be called while the OpenGL context for the drawable is current, and after your OpenGL scene has been rendered.- Throws:
GLException
- If an OpenGL context is not current when this method is called
-
beginRendering
Begins the OpenGL rendering process for the overlay. This is separated out so advanced applications can render independent pieces of the overlay to different portions of the drawable.- Throws:
GLException
- If an OpenGL context is not current when this method is called
-
endRendering
Ends the OpenGL rendering process for the overlay. This is separated out so advanced applications can render independent pieces of the overlay to different portions of the drawable.- Throws:
GLException
- If an OpenGL context is not current when this method is called
-
draw
Draws the specified sub-rectangle of the overlay on top of the OpenGL drawable.beginRendering()
andendRendering()
must be used in conjunction with this method to achieve proper rendering results. This method should be called while the OpenGL context for the drawable is current, and after your OpenGL scene has been rendered.- Parameters:
x
- the lower-left x coordinate (relative to the lower left of the overlay) of the rectangle to drawy
- the lower-left y coordinate (relative to the lower left of the overlay) of the rectangle to drawwidth
- the width of the rectangle to drawheight
- the height of the rectangle to draw- Throws:
GLException
- If an OpenGL context is not current when this method is called
-
draw
public void draw(int screenx, int screeny, int overlayx, int overlayy, int width, int height) throws GLException Draws the specified sub-rectangle of the overlay at the specified x and y coordinate on top of the OpenGL drawable.beginRendering()
andendRendering()
must be used in conjunction with this method to achieve proper rendering results. This method should be called while the OpenGL context for the drawable is current, and after your OpenGL scene has been rendered.- Parameters:
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 rectangleoverlayx
- the x coordinate of the pixel in the overlay of the lower left portion of the rectangle to drawoverlayy
- the y coordinate of the pixel in the overlay (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 draw- Throws:
GLException
- If an OpenGL context is not current when this method is called
-