public class GLG2DCanvas extends JComponent
G2DGLCanvas
is more
appropriate when rendering a complex scene using
JComponent.paintComponent(Graphics)
and the Graphics2D
object.
GL drawing can be enabled or disabled using the setGLDrawing(boolean)
method. If GL drawing is enabled, all full paint requests are intercepted and
the drawable component is drawn to the OpenGL canvas.
Override createGLComponent(GLCapabilitiesImmutable, GLContext)
to
create the OpenGL canvas. The returned canvas may be a GLJPanel
or a
GLCanvas
. createG2DListener(JComponent)
is used to create
the GLEventListener
that will draw to the OpenGL canvas. Use
getGLDrawable()
if you want to attach an Animator
.
Otherwise, paints will only happen when requested (either with
repaint()
or from AWT).
JComponent.AccessibleJComponent
Component.BaselineResizeBehavior
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
GLG2DCanvas()
Creates a new, blank
G2DGLCanvas using the default capabilities
from getDefaultCapabalities() . |
GLG2DCanvas(GLCapabilities capabilities)
Creates a new, blank
G2DGLCanvas using the given OpenGL
capabilities. |
GLG2DCanvas(GLCapabilities capabilities,
JComponent drawableComponent)
Creates a new
G2DGLCanvas where drawableComponent fills the
canvas. |
GLG2DCanvas(JComponent drawableComponent)
Creates a new
G2DGLCanvas where drawableComponent fills the
canvas. |
Modifier and Type | Method and Description |
---|---|
static GLCapabilities |
getDefaultCapabalities()
Returns the default, desired OpenGL capabilities needed for this component.
|
JComponent |
getDrawableComponent()
Gets the
JComponent to be drawn to the OpenGL canvas. |
GLAutoDrawable |
getGLDrawable()
Gets the
GLAutoDrawable used for drawing. |
boolean |
isGLDrawing()
Returns
true if the drawableComonent is drawn using OpenGL
libraries. |
void |
paint(Graphics g) |
void |
removeNotify()
Calling
GLCanvas.removeNotify() destroys the GLContext. |
void |
setDrawableComponent(JComponent component)
Sets the
JComponent that will be drawn to the OpenGL canvas. |
void |
setGLDrawing(boolean drawGL)
Sets the drawing path,
true for OpenGL, false for normal
Java2D. |
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public GLG2DCanvas()
G2DGLCanvas
using the default capabilities
from getDefaultCapabalities()
.public GLG2DCanvas(GLCapabilities capabilities)
G2DGLCanvas
using the given OpenGL
capabilities.public GLG2DCanvas(JComponent drawableComponent)
G2DGLCanvas
where drawableComponent
fills the
canvas. This uses the default capabilities from
getDefaultCapabalities()
.public GLG2DCanvas(GLCapabilities capabilities, JComponent drawableComponent)
G2DGLCanvas
where drawableComponent
fills the
canvas.public static GLCapabilities getDefaultCapabalities()
public boolean isGLDrawing()
true
if the drawableComonent
is drawn using OpenGL
libraries. If false
, it is using normal Java2D drawing routines.public void setGLDrawing(boolean drawGL)
true
for OpenGL, false
for normal
Java2D.isGLDrawing()
public JComponent getDrawableComponent()
JComponent
to be drawn to the OpenGL canvas.public void setDrawableComponent(JComponent component)
JComponent
that will be drawn to the OpenGL canvas.public GLAutoDrawable getGLDrawable()
GLAutoDrawable
used for drawing. By default this is a
GLCanvas
, but can be changed by overriding
createGLComponent(GLCapabilitiesImmutable, GLContext)
.
Use the returned GLAutoDrawable
as input to an Animator
to
automate painting.
public void removeNotify()
GLCanvas.removeNotify()
destroys the GLContext. We could
mess with that internally, but this is slightly easier.
This method is particularly important for docking frameworks and moving the
panel from one window to another. This is simple for normal Swing
components, but GL contexts are destroyed when removeNotify()
is
called.
Our workaround is to use context sharing. The pbuffer is initialized and by drawing into it at least once, we automatically share all textures, etc. with the new pbuffer. This pbuffer holds the data until we can initialize our new JOGL canvas. We share the pbuffer canvas with the new JOGL canvas and everything works nicely from then on.
This has the unfortunate side-effect of leaking memory. I'm not sure how to fix this yet.
removeNotify
in class JComponent
public void paint(Graphics g)
paint
in class JComponent
Copyright © 2010-2013. All Rights Reserved.