javax.media.opengl
Class GLJPanel
JPanel
javax.media.opengl.GLJPanel
- ComponentEvents, GLAutoDrawable, GLDrawable
public class GLJPanel
extends JPanel
A lightweight Swing component which provides OpenGL rendering
support. Provided for compatibility with Swing user interfaces
when adding a heavyweight doesn't work either because of
Z-ordering or LayoutManager problems.
The GLJPanel can be made transparent by creating it with a
GLCapabilities object with alpha bits specified and calling
setOpaque(boolean)
(false). Pixels with resulting OpenGL alpha values less
than 1.0 will be overlaid on any underlying Swing rendering.
Notes specific to the Reference Implementation: This component
attempts to use hardware-accelerated rendering via pbuffers and
falls back on to software rendering if problems occur.
Note that because this component attempts to use pbuffers for
rendering, and because pbuffers can not be resized, somewhat
surprising behavior may occur during resize operations; the
GLEventListener.init(GLAutoDrawable)
method may be called multiple times as the
pbuffer is resized to be able to cover the size of the GLJPanel.
This behavior is correct, as the textures and display lists for
the GLJPanel will have been lost during the resize operation. The
application should attempt to make its GLEventListener.init()
methods as side-effect-free as possible.
GLJPanel() - Creates a new GLJPanel component with a default set of OpenGL
capabilities and using the default OpenGL capabilities selection
mechanism.
|
GLJPanel(GLCapabilities capabilities) - Creates a new GLJPanel component with the requested set of
OpenGL capabilities, using the default OpenGL capabilities
selection mechanism.
|
GLJPanel(GLCapabilities capabilities, GLCapabilitiesChooser chooser, GLContext shareWith) - Creates a new GLJPanel component.
|
GLJPanel
public GLJPanel()
Creates a new GLJPanel component with a default set of OpenGL
capabilities and using the default OpenGL capabilities selection
mechanism.
GLJPanel
public GLJPanel(GLCapabilities capabilities)
Creates a new GLJPanel component with the requested set of
OpenGL capabilities, using the default OpenGL capabilities
selection mechanism.
GLJPanel
public GLJPanel(GLCapabilities capabilities,
GLCapabilitiesChooser chooser,
GLContext shareWith)
Creates a new GLJPanel component. The passed GLCapabilities
specifies the OpenGL capabilities for the component; if null, a
default set of capabilities is used. The GLCapabilitiesChooser
specifies the algorithm for selecting one of the available
GLCapabilities for the component; a DefaultGLCapabilitesChooser
is used if null is passed for this argument. The passed
GLContext specifies an OpenGL context with which to share
textures, display lists and other OpenGL state, and may be null
if sharing is not desired. See the note in the overview documentation on
context sharing.
addNotify
public void addNotify()
Overridden to track when this component is added to a container.
Subclasses which override this method must call
super.addNotify() in their addNotify() method in order to
function properly.
Overrides:
addNotify
java.awt.Component
createContext
public GLContext createContext(GLContext shareWith)
Creates a new context for drawing to this drawable that will
optionally share display lists and other server-side OpenGL
objects with the specified GLContext.
The GLContext
share
need not be associated with this
GLDrawable and may be null if sharing of display lists and other
objects is not desired. See the note in the overview
documentation on
context sharing.
- createContext in interface GLDrawable
getChosenGLCapabilities
public GLCapabilities getChosenGLCapabilities()
Fetches the
GLCapabilities
corresponding to the chosen
OpenGL capabilities (pixel format / visual) for this drawable.
Some drawables, in particular on-screen drawables, may be
created lazily; null is returned if the drawable is not
currently created or if its pixel format has not been set yet.
On some platforms, the pixel format is not directly associated
with the drawable; a best attempt is made to return a reasonable
value in this case.
- getChosenGLCapabilities in interface GLDrawable
paintComponent
protected void paintComponent(Graphics g)
Overridden to cause OpenGL rendering to be performed during
repaint cycles. Subclasses which override this method must call
super.paintComponent() in their paintComponent() method in order
to function properly.
Overrides:
paintComponent
javax.swing.JComponent
removeNotify
public void removeNotify()
Overridden to track when this component is removed from a
container. Subclasses which override this method must call
super.removeNotify() in their removeNotify() method in order to
function properly.
Overrides:
removeNotify
java.awt.Component
reshape
public void reshape(int x,
int y,
int width,
int height)
Overridden to cause
GLDrawableHelper.reshape
to be
called on all registered
GLEventListener
s. Subclasses
which override this method must call super.reshape() in
their reshape() method in order to function properly.
Overrides:
reshape
java.awt.Component
setOpaque
public void setOpaque(boolean opaque)
setRealized
public void setRealized(boolean realized)
Indicates to on-screen GLDrawable implementations whether the
underlying window has been created and can be drawn into. This
method must be called from GLDrawables obtained from the
GLDrawableFactory via the
GLDrawableFactory.getGLDrawable()
method. It must typically be
called with an argument of
true
in the
addNotify
method of components performing OpenGL
rendering and with an argument of
false
in the
removeNotify
method. Calling this method has no
other effects. For example, if
removeNotify
is
called on a Canvas implementation for which a GLDrawable has been
created, it is also necessary to destroy all OpenGL contexts
associated with that GLDrawable. This is not done automatically
by the implementation. It is not necessary to call
setRealized
on a GLCanvas, a GLJPanel, or a
GLPbuffer, as these perform the appropriate calls on their
underlying GLDrawables internally..
- setRealized in interface GLDrawable
shouldPreserveColorBufferIfTranslucent
public boolean shouldPreserveColorBufferIfTranslucent()
For a translucent GLJPanel (one for which
setOpaque
(false) has been called), indicates whether the
application should preserve the OpenGL color buffer
(GL_COLOR_BUFFER_BIT) for correct rendering of the GLJPanel and
underlying widgets which may show through portions of the
GLJPanel with alpha values less than 1. Most Swing
implementations currently expect the GLJPanel to be completely
cleared (e.g., by
glClear(GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT)
), but for certain optimized Swing
implementations which use OpenGL internally, it may be possible
to perform OpenGL rendering using the GLJPanel into the same
OpenGL drawable as the Swing implementation uses.
swapBuffers
public void swapBuffers()
Swaps the front and back buffers of this drawable. For
GLAutoDrawable
implementations, when automatic buffer swapping
is enabled (as is the default), this method is called
automatically and should not be called by the end user.
- swapBuffers in interface GLDrawable
Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.