agile2d.opengl
Class AGLGraphics2D

java.lang.Object
  |
  +--java.awt.Graphics
        |
        +--java.awt.Graphics2D
              |
              +--agile2d.opengl.AGLGraphics2D
All Implemented Interfaces:
Cloneable

public final class AGLGraphics2D
extends Graphics2D
implements Cloneable

AGLGraphics2D implements a partial subset of the standard Java2D Graphics2D API. It uses OpenGL as the rendering engine. This class uses the freely available GL4Java library to access native OpenGL function calls.

Note that some API functions are marked "TBD" (to be done). Calling these functions typically has no effect - most Java2D applications should run under OpenGL, although they may not appear correctly rendered.


Constructor Summary
AGLGraphics2D(gl4java.drawable.GLDrawable drawable)
          Constructs a AGLGraphics2D that renders to a particular GL Drawable.
 
Method Summary
 void addRenderingHints(Map hints)
           
 void clearRect(int x, int y, int width, int height)
           
 void clip(Shape clip)
           
 void clipRect(int x, int y, int w, int h)
           
protected  Object clone()
           
 void copyArea(int x, int y, int width, int height, int dx, int dy)
           
 Graphics create()
           
 void dispose()
           
 void draw(Shape shape)
           
 void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
           
 void drawGlyphVector(GlyphVector g, float x, float y)
           
 void drawImage(BufferedImage img, BufferedImageOp op, int x, int y)
          TBD
 boolean drawImage(Image img, AffineTransform xform, ImageObserver obs)
           
 boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
           
 boolean drawImage(Image img, int x, int y, ImageObserver observer)
           
 boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
           
 boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
           
 boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
           
 boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
           
 void drawLine(int x1, int y1, int x2, int y2)
           
 void drawOval(int x, int y, int width, int height)
           
 void drawPolygon(int[] xPts, int[] yPts, int nPts)
           
 void drawPolyline(int[] xPts, int[] yPts, int nPts)
           
 void drawRect(int x1, int y1, int width, int height)
           
 void drawRenderableImage(RenderableImage img, AffineTransform xform)
          TBD
 void drawRenderedImage(RenderedImage img, AffineTransform xform)
          TBD
 void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
           
 void drawString(AttributedCharacterIterator iterator, float x, float y)
          TBD
 void drawString(AttributedCharacterIterator iterator, int x, int y)
          TBD
 void drawString(String string, float x, float y)
           
 void drawString(String s, int x, int y)
           
 void fill(Shape shape)
           
 void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
           
 void fillOval(int x, int y, int width, int height)
           
 void fillPolygon(int[] xPts, int[] yPts, int nPts)
           
 void fillRect(int x1, int y1, int width, int height)
           
 void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
           
 Color getBackground()
           
 Shape getClip()
           
 Rectangle getClipBounds()
           
 Rectangle getClipBounds(Rectangle r)
           
 Color getColor()
           
 Composite getComposite()
           
 GraphicsConfiguration getDeviceConfiguration()
          Falls back on Java2D: Returns Java2D's current device configuration
 Font getFont()
           
 FontMetrics getFontMetrics(Font f)
           
 FontRenderContext getFontRenderContext()
          Returns new FontRenderContext(null, true, true).
 Paint getPaint()
           
 Object getRenderingHint(RenderingHints.Key key)
           
 RenderingHints getRenderingHints()
           
 Stroke getStroke()
           
 AffineTransform getTransform()
           
 boolean hit(Rectangle rect, Shape s, boolean onStroke)
          Falls back on Java2D: Uses a Java2D graphics to do hit testing
 boolean hitClip(int x, int y, int width, int height)
           
 void resetAll()
          Resets the Graphics to its default state.
 void rotate(double theta)
           
 void rotate(double theta, double x, double y)
           
 void runGL(gl4java.drawable.GLEventListener glevent)
          Runs a GL program in the AGLGraphics2D context.
 void scale(double sx, double sy)
           
 void setBackground(Color color)
           
 void setClip(int x, int y, int width, int height)
           
 void setClip(Shape clip)
           
 void setColor(Color color)
           
 void setColor(int argb)
          AGLGraphics2D extension for specifing a color with an integer.
 void setComposite(Composite composite)
           
 void setFont(Font font)
           
 void setPaint(Paint paint)
           
 void setPaintMode()
           
 void setRenderingHint(RenderingHints.Key key, Object value)
           
 void setRenderingHints(Map hints)
           
 void setStroke(Stroke stroke)
           
 void setTransform(AffineTransform tm)
           
 void setVertexAttributes(VertexAttributes va)
           
 void setXORMode(Color xorColor)
           
 void shear(double sx, double sy)
           
 void transform(AffineTransform transform)
           
 void translate(double x, double y)
           
 void translate(int x, int y)
           
 
Methods inherited from class java.awt.Graphics2D
draw3DRect, fill3DRect
 
Methods inherited from class java.awt.Graphics
create, drawBytes, drawChars, drawPolygon, fillPolygon, finalize, getClipRect, getFontMetrics, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AGLGraphics2D

public AGLGraphics2D(gl4java.drawable.GLDrawable drawable)
Constructs a AGLGraphics2D that renders to a particular GL Drawable. Users of AGLGraphics2D should call resetAll in their display methods to make the OpenGL state reflect the default Java2D state.
     aglGraphics.resetAll(); // Makes the OpenGL State reflect Java2D's defaults
     aglGraphics...
 

Parameters:
drawable - the underlying GLDrawable
Method Detail

resetAll

public void resetAll()
Resets the Graphics to its default state.


dispose

public void dispose()
Specified by:
dispose in class Graphics
See Also:
Graphics.dispose()

clone

protected Object clone()
Overrides:
clone in class Object

getBackground

public Color getBackground()
Specified by:
getBackground in class Graphics2D
See Also:
Graphics2D.getBackground()

setBackground

public void setBackground(Color color)
Specified by:
setBackground in class Graphics2D
See Also:
Graphics2D.setBackground(java.awt.Color)

getColor

public Color getColor()
Specified by:
getColor in class Graphics
See Also:
Graphics.getColor()

setColor

public void setColor(Color color)
Specified by:
setColor in class Graphics
See Also:
Graphics.setColor(java.awt.Color)

setColor

public void setColor(int argb)
AGLGraphics2D extension for specifing a color with an integer.

Parameters:
argb - color with 8 bits components for the alpha, red, green and blue channels in that order from high bits to low bits.

getPaint

public Paint getPaint()
Specified by:
getPaint in class Graphics2D
See Also:
Graphics2D.getPaint()

setPaint

public void setPaint(Paint paint)
Specified by:
setPaint in class Graphics2D
See Also:
Graphics2D.setPaint(java.awt.Paint)

getComposite

public Composite getComposite()
Specified by:
getComposite in class Graphics2D
See Also:
Graphics2D.getComposite()

setComposite

public void setComposite(Composite composite)
Specified by:
setComposite in class Graphics2D
See Also:
Graphics2D.setComposite(java.awt.Composite)

setFont

public void setFont(Font font)
Specified by:
setFont in class Graphics
See Also:
Graphics.setFont(java.awt.Font)

getFont

public Font getFont()
Specified by:
getFont in class Graphics
See Also:
Graphics.getFont()

getFontMetrics

public FontMetrics getFontMetrics(Font f)
Specified by:
getFontMetrics in class Graphics
See Also:
Graphics.getFontMetrics(java.awt.Font)

getStroke

public Stroke getStroke()
Specified by:
getStroke in class Graphics2D
See Also:
Graphics2D.getStroke()

setStroke

public void setStroke(Stroke stroke)
Specified by:
setStroke in class Graphics2D
See Also:
Graphics2D.setStroke(java.awt.Stroke)

setPaintMode

public void setPaintMode()
Specified by:
setPaintMode in class Graphics
See Also:
Graphics.setPaintMode()

setXORMode

public void setXORMode(Color xorColor)
Specified by:
setXORMode in class Graphics
See Also:
Graphics.setXORMode(java.awt.Color)

setTransform

public void setTransform(AffineTransform tm)
Specified by:
setTransform in class Graphics2D
See Also:
Graphics2D.setTransform(java.awt.geom.AffineTransform)

getTransform

public AffineTransform getTransform()
Specified by:
getTransform in class Graphics2D
See Also:
Graphics2D.getTransform()

scale

public void scale(double sx,
                  double sy)
Specified by:
scale in class Graphics2D
See Also:
Graphics2D.scale(double, double)

shear

public void shear(double sx,
                  double sy)
Specified by:
shear in class Graphics2D
See Also:
Graphics2D.shear(double, double)

rotate

public void rotate(double theta,
                   double x,
                   double y)
Specified by:
rotate in class Graphics2D
See Also:
Graphics2D.rotate(double, double, double)

rotate

public void rotate(double theta)
Specified by:
rotate in class Graphics2D
See Also:
Graphics2D.rotate(double)

translate

public void translate(double x,
                      double y)
Specified by:
translate in class Graphics2D
See Also:
Graphics2D.translate(double, double)

translate

public void translate(int x,
                      int y)
Specified by:
translate in class Graphics2D
See Also:
Graphics.translate(int, int)

transform

public void transform(AffineTransform transform)
Specified by:
transform in class Graphics2D
See Also:
Graphics2D.transform(java.awt.geom.AffineTransform)

addRenderingHints

public void addRenderingHints(Map hints)
Specified by:
addRenderingHints in class Graphics2D
See Also:
Graphics2D.addRenderingHints(java.util.Map)

getRenderingHint

public Object getRenderingHint(RenderingHints.Key key)
Specified by:
getRenderingHint in class Graphics2D
See Also:
Graphics2D.getRenderingHint(java.awt.RenderingHints.Key)

setRenderingHint

public void setRenderingHint(RenderingHints.Key key,
                             Object value)
Specified by:
setRenderingHint in class Graphics2D
See Also:
Graphics2D.setRenderingHint(java.awt.RenderingHints.Key, java.lang.Object)

setRenderingHints

public void setRenderingHints(Map hints)
Specified by:
setRenderingHints in class Graphics2D
See Also:
Graphics2D.setRenderingHints(java.util.Map)

getRenderingHints

public RenderingHints getRenderingHints()
Specified by:
getRenderingHints in class Graphics2D
See Also:
Graphics2D.getRenderingHints()

setClip

public void setClip(Shape clip)
Specified by:
setClip in class Graphics
See Also:
Graphics.setClip(java.awt.Shape)

setClip

public void setClip(int x,
                    int y,
                    int width,
                    int height)
Specified by:
setClip in class Graphics
See Also:
Graphics.setClip(int,int,int,int)

clip

public void clip(Shape clip)
Specified by:
clip in class Graphics2D
See Also:
Graphics2D.clip(java.awt.Shape)

clipRect

public void clipRect(int x,
                     int y,
                     int w,
                     int h)
Specified by:
clipRect in class Graphics
See Also:
Graphics.clipRect(int, int, int, int)

getClip

public Shape getClip()
Specified by:
getClip in class Graphics
See Also:
Graphics.getClip()

getClipBounds

public Rectangle getClipBounds()
Specified by:
getClipBounds in class Graphics
See Also:
Graphics.getClipBounds()

getClipBounds

public Rectangle getClipBounds(Rectangle r)
Overrides:
getClipBounds in class Graphics
See Also:
Graphics.getClipBounds(java.awt.Rectangle)

hitClip

public boolean hitClip(int x,
                       int y,
                       int width,
                       int height)
Overrides:
hitClip in class Graphics
See Also:
Graphics.hitClip(int, int, int, int)

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
Specified by:
drawLine in class Graphics
See Also:
Graphics.drawLine(int, int, int, int)

drawPolyline

public void drawPolyline(int[] xPts,
                         int[] yPts,
                         int nPts)
Specified by:
drawPolyline in class Graphics
See Also:
Graphics.drawPolygon(int[], int[], int), Graphics.drawPolyline(int[], int[], int)

drawPolygon

public void drawPolygon(int[] xPts,
                        int[] yPts,
                        int nPts)
Specified by:
drawPolygon in class Graphics
See Also:
Graphics.drawPolygon(int[], int[], int)

drawRect

public void drawRect(int x1,
                     int y1,
                     int width,
                     int height)
Overrides:
drawRect in class Graphics
See Also:
Graphics.drawRect(int, int, int, int)

drawRoundRect

public void drawRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Specified by:
drawRoundRect in class Graphics
See Also:
Graphics.drawRoundRect(int, int, int, int, int, int)

drawOval

public void drawOval(int x,
                     int y,
                     int width,
                     int height)
Specified by:
drawOval in class Graphics
See Also:
Graphics.drawOval(int, int, int, int)

drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
Specified by:
drawArc in class Graphics
See Also:
Graphics.drawArc(int, int, int, int, int, int)

draw

public void draw(Shape shape)
Specified by:
draw in class Graphics2D
See Also:
Graphics2D.draw(java.awt.Shape)

fillRect

public void fillRect(int x1,
                     int y1,
                     int width,
                     int height)
Specified by:
fillRect in class Graphics
See Also:
Graphics.fillRect(int, int, int, int)

clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height)
Specified by:
clearRect in class Graphics
See Also:
Graphics.clearRect(int, int, int, int)

fillRoundRect

public void fillRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Specified by:
fillRoundRect in class Graphics
See Also:
Graphics.fillRoundRect(int, int, int, int, int, int)

fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height)
Specified by:
fillOval in class Graphics
See Also:
Graphics.fillOval(int, int, int, int)

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
Specified by:
fillArc in class Graphics
See Also:
Graphics.fillArc(int, int, int, int, int, int)

fillPolygon

public void fillPolygon(int[] xPts,
                        int[] yPts,
                        int nPts)
Specified by:
fillPolygon in class Graphics
See Also:
Graphics.fillPolygon(int[], int[], int)

fill

public void fill(Shape shape)
Specified by:
fill in class Graphics2D
See Also:
Graphics2D.fill(java.awt.Shape)

drawString

public void drawString(String s,
                       int x,
                       int y)
Specified by:
drawString in class Graphics2D
See Also:
Graphics.drawString(java.lang.String, int, int)

drawString

public void drawString(String string,
                       float x,
                       float y)
Specified by:
drawString in class Graphics2D
See Also:
Graphics2D.drawString(java.lang.String, float, float)

create

public Graphics create()
Specified by:
create in class Graphics
See Also:
Graphics.create()

copyArea

public void copyArea(int x,
                     int y,
                     int width,
                     int height,
                     int dx,
                     int dy)
Specified by:
copyArea in class Graphics
See Also:
Graphics.copyArea(int, int, int, int, int, int)

drawImage

public boolean drawImage(Image img,
                         int x,
                         int y,
                         ImageObserver observer)
Specified by:
drawImage in class Graphics
See Also:
Graphics.drawImage(java.awt.Image, int, int, java.awt.image.ImageObserver)

drawImage

public boolean drawImage(Image img,
                         int x,
                         int y,
                         int width,
                         int height,
                         ImageObserver observer)
Specified by:
drawImage in class Graphics
See Also:
Graphics.drawImage(java.awt.Image, int, int, int, int, java.awt.image.ImageObserver)

drawImage

public boolean drawImage(Image img,
                         int x,
                         int y,
                         Color bgcolor,
                         ImageObserver observer)
Specified by:
drawImage in class Graphics
See Also:
Graphics.drawImage(java.awt.Image, int, int, java.awt.Color, java.awt.image.ImageObserver)

drawImage

public boolean drawImage(Image img,
                         int x,
                         int y,
                         int width,
                         int height,
                         Color bgcolor,
                         ImageObserver observer)
Specified by:
drawImage in class Graphics
See Also:
Graphics.drawImage(java.awt.Image, int, int, int, int, java.awt.Color, java.awt.image.ImageObserver)

drawImage

public boolean drawImage(Image img,
                         int dx1,
                         int dy1,
                         int dx2,
                         int dy2,
                         int sx1,
                         int sy1,
                         int sx2,
                         int sy2,
                         ImageObserver observer)
Specified by:
drawImage in class Graphics
See Also:
Graphics.drawImage(java.awt.Image, int, int, int, int, int, int, int, int, java.awt.image.ImageObserver)

drawImage

public boolean drawImage(Image img,
                         AffineTransform xform,
                         ImageObserver obs)
Specified by:
drawImage in class Graphics2D
See Also:
Graphics2D.drawImage(java.awt.Image, java.awt.geom.AffineTransform, java.awt.image.ImageObserver)

drawImage

public boolean drawImage(Image img,
                         int dx1,
                         int dy1,
                         int dx2,
                         int dy2,
                         int sx1,
                         int sy1,
                         int sx2,
                         int sy2,
                         Color bgcolor,
                         ImageObserver observer)
Specified by:
drawImage in class Graphics
See Also:
Graphics.drawImage(java.awt.Image, int, int, int, int, int, int, int, int, java.awt.Color, java.awt.image.ImageObserver)

drawGlyphVector

public void drawGlyphVector(GlyphVector g,
                            float x,
                            float y)
Specified by:
drawGlyphVector in class Graphics2D
See Also:
Graphics2D.drawGlyphVector(java.awt.font.GlyphVector, float, float)

hit

public boolean hit(Rectangle rect,
                   Shape s,
                   boolean onStroke)
Falls back on Java2D: Uses a Java2D graphics to do hit testing

Specified by:
hit in class Graphics2D
See Also:
Graphics2D.hit(Rectangle, Shape, boolean)

getDeviceConfiguration

public GraphicsConfiguration getDeviceConfiguration()
Falls back on Java2D: Returns Java2D's current device configuration

Specified by:
getDeviceConfiguration in class Graphics2D
See Also:
Graphics2D.getDeviceConfiguration()

getFontRenderContext

public FontRenderContext getFontRenderContext()
Returns new FontRenderContext(null, true, true).

Specified by:
getFontRenderContext in class Graphics2D
Returns:
new FontRenderContext(null, true, true).

drawString

public void drawString(AttributedCharacterIterator iterator,
                       int x,
                       int y)
TBD

Specified by:
drawString in class Graphics2D
Parameters:
iterator - DOCUMENT ME!
x - DOCUMENT ME!
y - DOCUMENT ME!

drawImage

public void drawImage(BufferedImage img,
                      BufferedImageOp op,
                      int x,
                      int y)
TBD

Specified by:
drawImage in class Graphics2D
Parameters:
img - DOCUMENT ME!
op - DOCUMENT ME!
x - DOCUMENT ME!
y - DOCUMENT ME!

drawRenderedImage

public void drawRenderedImage(RenderedImage img,
                              AffineTransform xform)
TBD

Specified by:
drawRenderedImage in class Graphics2D
Parameters:
img - DOCUMENT ME!
xform - DOCUMENT ME!

drawRenderableImage

public void drawRenderableImage(RenderableImage img,
                                AffineTransform xform)
TBD

Specified by:
drawRenderableImage in class Graphics2D
Parameters:
img - DOCUMENT ME!
xform - DOCUMENT ME!

drawString

public void drawString(AttributedCharacterIterator iterator,
                       float x,
                       float y)
TBD

Specified by:
drawString in class Graphics2D
Parameters:
iterator - DOCUMENT ME!
x - DOCUMENT ME!
y - DOCUMENT ME!

setVertexAttributes

public void setVertexAttributes(VertexAttributes va)

runGL

public void runGL(gl4java.drawable.GLEventListener glevent)
Runs a GL program in the AGLGraphics2D context. The GL state is left as it was when the GLEventListener it called: transform, clip, states. All the graphic attributes are saved, but the GL state can still be broken if the stacks are popped for example.

Parameters:
glevent - the GLEventListener which will be called.


Copyright © 2002 by University of Maryland, USA All rights reserved.