Top Description Fields Constructors Methods
org.lwjgl.opengl

public Class AWTGLCanvas

extends Canvas
implements DrawableLWJGL, ComponentListener, HierarchyListener
Class Inheritance
All Implemented Interfaces
java.awt.event.HierarchyListener, java.util.EventListener, java.awt.event.ComponentListener, org.lwjgl.opengl.DrawableLWJGL, org.lwjgl.opengl.Drawable
Known Direct Subclasses
org.lwjgl.test.applet.OpenAL, org.lwjgl.test.applet.OpenGL, org.lwjgl.test.applet.Speed, org.lwjgl.test.opengl.awt.AWTGearsCanvas, org.lwjgl.test.opengl.awt.DemoBox.DemoBoxGLCanvas
Imports
org.lwjgl.LWJGLException, .LWJGLUtil, .PointerBuffer, .Sys, java.awt.*, java.awt.event.ComponentEvent, .ComponentListener, .HierarchyEvent, .HierarchyListener

An AWT rendering context.

Author
$Author$ $Id$
Version
$Revision$

Field Summary

Modifier and TypeField and Description
private final ContextAttribs
attribs

The ContextAttribs to use when creating the context

private ContextGL
private final Drawable
drawable

The drawable to share context with

private boolean
first_run

Tracks whether initGL() needs to be called

private static final AWTCanvasImplementation
private PeerInfo
peer_info

Context handle

private final PixelFormat
pixel_format

The requested pixel format

private int
reentry_count

re-entry counter for support for re-entrant redrawing in paint().

private static final long
private Object
private boolean

Constructor Summary

AccessConstructor and Description
public
AWTGLCanvas()

Constructor using the default PixelFormat.

public
AWTGLCanvas(PixelFormat
The desired pixel format. May not be null
pixel_format
)

Create an AWTGLCanvas with the requested PixelFormat on the default GraphicsDevice.

public
AWTGLCanvas(GraphicsDevice
the device to create the canvas on.
device
,
PixelFormat
The desired pixel format. May not be null
pixel_format
)

Create an AWTGLCanvas with the requested PixelFormat on the default GraphicsDevice.

public
AWTGLCanvas(GraphicsDevice
the device to create the canvas on.
device
,
PixelFormat
The desired pixel format. May not be null
pixel_format
,
Drawable
The Drawable to share context with
drawable
)

Create an AWTGLCanvas with the requested PixelFormat on the specified GraphicsDevice.

public
AWTGLCanvas(GraphicsDevice
the device to create the canvas on.
device
,
PixelFormat
The desired pixel format. May not be null
pixel_format
,
Drawable
The Drawable to share context with
drawable
,
ContextAttribs
The ContextAttribs to use when creating the context. (optional, may be null)
attribs
)

Create an AWTGLCanvas with the requested PixelFormat on the specified GraphicsDevice.

Method Summary

Modifier and TypeMethod and Description
public void
addNotify()

Overrides java.awt.Canvas.addNotify.

Creates the peer of the canvas.
public void
public void
componentHidden(ComponentEvent
the event to be processed
e
)

Implements java.awt.event.ComponentListener.componentHidden.

Invoked when the component has been made invisible.
public void
componentMoved(ComponentEvent
the event to be processed
e
)

Implements java.awt.event.ComponentListener.componentMoved.

Invoked when the component's position changes.
public void
componentResized(ComponentEvent
the event to be processed
e
)

Implements java.awt.event.ComponentListener.componentResized.

Invoked when the component's size changes.
public void
componentShown(ComponentEvent
the event to be processed
e
)

Implements java.awt.event.ComponentListener.componentShown.

Invoked when the component has been made visible.
pack-priv static AWTCanvasImplementation
public ContextGL
createSharedContext()

Implements org.lwjgl.opengl.DrawableLWJGL.createSharedContext.

This method should only be called internally.
public final void
destroy()

Implements org.lwjgl.opengl.Drawable.destroy.

Destroy the OpenGL context.
protected void
exceptionOccurred(LWJGLException
The exception that occurred.
exception
)

This method will be called if an unhandled LWJGLException occurs in paint().

public ContextGL
getContext()

Implements org.lwjgl.opengl.DrawableLWJGL.getContext.

This method should only be called internally.
public PixelFormatLWJGL
public void
hierarchyChanged(HierarchyEvent
the event to be processed
e
)

Implements java.awt.event.HierarchyListener.hierarchyChanged.

Called when the hierarchy has been changed.
public void
initContext(final float r, final float g, final float b)

Implements org.lwjgl.opengl.DrawableLWJGL.initContext.

protected void
initGL()

Override this to do initialising of the context.

public boolean
isCurrent()

Implements org.lwjgl.opengl.Drawable.isCurrent.

Returns true if the Drawable's context is current in the current thread.
public void
makeCurrent()

Implements org.lwjgl.opengl.Drawable.makeCurrent.

Make the canvas' context current.
public final void
paint(Graphics
the specified Graphics context
g
)

Overrides java.awt.Canvas.paint.

The default paint() operation makes the context current and calls paintGL() which should be overridden to do GL operations.
protected void
paintGL()

Override this to do painting

public void
releaseContext()

Implements org.lwjgl.opengl.Drawable.releaseContext.

If the Drawable's context is current in the current thread, no context will be current after a call to this method.
public void
removeNotify()

Overrides java.awt.Component.removeNotify.

Makes this Component undisplayable by destroying it native screen resource.
public void
setBounds(int
the new x-coordinate of this component
x
,
int
the new y-coordinate of this component
y
,
int
the new width of this component
width
,
int
the new height of this component
height
)

Overrides java.awt.Component.setBounds.

Moves and resizes this component.
public final void
setCLSharingProperties(final PointerBuffer
The target properties buffer. It must have at least 4 positions remaining.
properties
)

Implements org.lwjgl.opengl.Drawable.setCLSharingProperties.

Sets the appropriate khr_gl_sharing properties in the target PointerBuffer, so that if it is used in a clCreateContext(FromType) call, the created CL context will be sharing objects with this Drawable's GL context.
public void
setLocation(int
the x-coordinate of the new location's top-left corner in the parent's coordinate space
x
,
int
the y-coordinate of the new location's top-left corner in the parent's coordinate space
y
)

Overrides java.awt.Component.setLocation.

Moves this component to a new location.
public void
setLocation(Point
the point defining the top-left corner of the new location, given in the coordinate space of this component's parent
p
)

Overrides java.awt.Component.setLocation.

Moves this component to a new location.
public void
public void
public void
setSize(Dimension
the dimension specifying the new size of this component
d
)

Overrides java.awt.Component.setSize.

Resizes this component so that it has width d.width and height d.height.
public void
setSize(int
the new width of this component in pixels
width
,
int
the new height of this component in pixels
height
)

Overrides java.awt.Component.setSize.

Resizes this component so that it has width width and height height.
public void
setSwapInterval(int swap_interval)

Implements org.lwjgl.opengl.DrawableLWJGL.setSwapInterval.

Set swap interval.
private void
public void
setVSyncEnabled(boolean enabled)

Enable vsync

public void
swapBuffers()

Implements org.lwjgl.opengl.DrawableLWJGL.swapBuffers.

Swap the canvas' buffer
public void
update(Graphics
the specified Graphics context
g
)

Overrides java.awt.Canvas.update.

override update to avoid clearing
Inherited from java.awt.Canvas:
createBufferStrategycreateBufferStrategygetAccessibleContextgetBufferStrategy

Field Detail

attribsback to summary
private final ContextAttribs attribs

The ContextAttribs to use when creating the context

contextback to summary
private ContextGL context
drawableback to summary
private final Drawable drawable

The drawable to share context with

first_runback to summary
private boolean first_run

Tracks whether initGL() needs to be called

implementationback to summary
private static final AWTCanvasImplementation implementation
peer_infoback to summary
private PeerInfo peer_info

Context handle

pixel_formatback to summary
private final PixelFormat pixel_format

The requested pixel format

reentry_countback to summary
private int reentry_count

re-entry counter for support for re-entrant redrawing in paint(). It happens when using dialog boxes.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.awt.Canvas.serialVersionUID.

SYNC_LOCKback to summary
private Object SYNC_LOCK
update_contextback to summary
private boolean update_context

Constructor Detail

AWTGLCanvasback to summary
public AWTGLCanvas() throws LWJGLException

Constructor using the default PixelFormat.

AWTGLCanvasback to summary
public AWTGLCanvas(PixelFormat pixel_format) throws LWJGLException

Create an AWTGLCanvas with the requested PixelFormat on the default GraphicsDevice.

Parameters
pixel_format:PixelFormat

The desired pixel format. May not be null

AWTGLCanvasback to summary
public AWTGLCanvas(GraphicsDevice device, PixelFormat pixel_format) throws LWJGLException

Create an AWTGLCanvas with the requested PixelFormat on the default GraphicsDevice.

Parameters
device:GraphicsDevice

the device to create the canvas on.

pixel_format:PixelFormat

The desired pixel format. May not be null

AWTGLCanvasback to summary
public AWTGLCanvas(GraphicsDevice device, PixelFormat pixel_format, Drawable drawable) throws LWJGLException

Create an AWTGLCanvas with the requested PixelFormat on the specified GraphicsDevice.

Parameters
device:GraphicsDevice

the device to create the canvas on.

pixel_format:PixelFormat

The desired pixel format. May not be null

drawable:Drawable

The Drawable to share context with

AWTGLCanvasback to summary
public AWTGLCanvas(GraphicsDevice device, PixelFormat pixel_format, Drawable drawable, ContextAttribs attribs) throws LWJGLException

Create an AWTGLCanvas with the requested PixelFormat on the specified GraphicsDevice.

Parameters
device:GraphicsDevice

the device to create the canvas on.

pixel_format:PixelFormat

The desired pixel format. May not be null

drawable:Drawable

The Drawable to share context with

attribs:ContextAttribs

The ContextAttribs to use when creating the context. (optional, may be null)

Method Detail

addNotifyback to summary
public void addNotify()

Overrides java.awt.Canvas.addNotify.

Doc from java.awt.Canvas.addNotify.

Creates the peer of the canvas. This peer allows you to change the user interface of the canvas without changing its functionality.

checkGLErrorback to summary
public void checkGLError()

Implements org.lwjgl.opengl.DrawableLWJGL.checkGLError.

componentHiddenback to summary
public void componentHidden(ComponentEvent e)

Implements java.awt.event.ComponentListener.componentHidden.

Doc from java.awt.event.ComponentListener.componentHidden.

Invoked when the component has been made invisible.

Parameters
e:ComponentEvent

the event to be processed

componentMovedback to summary
public void componentMoved(ComponentEvent e)

Implements java.awt.event.ComponentListener.componentMoved.

Doc from java.awt.event.ComponentListener.componentMoved.

Invoked when the component's position changes.

Parameters
e:ComponentEvent

the event to be processed

componentResizedback to summary
public void componentResized(ComponentEvent e)

Implements java.awt.event.ComponentListener.componentResized.

Doc from java.awt.event.ComponentListener.componentResized.

Invoked when the component's size changes.

Parameters
e:ComponentEvent

the event to be processed

componentShownback to summary
public void componentShown(ComponentEvent e)

Implements java.awt.event.ComponentListener.componentShown.

Doc from java.awt.event.ComponentListener.componentShown.

Invoked when the component has been made visible.

Parameters
e:ComponentEvent

the event to be processed

createImplementationback to summary
pack-priv static AWTCanvasImplementation createImplementation()
createSharedContextback to summary
public ContextGL createSharedContext() throws LWJGLException

Implements org.lwjgl.opengl.DrawableLWJGL.createSharedContext.

This method should only be called internally.

Returns:ContextGL

Doc from org.lwjgl.opengl.DrawableLWJGL.createSharedContext.

a Context shared with the Drawable's Context.

destroyback to summary
public final void destroy()

Implements org.lwjgl.opengl.Drawable.destroy.

Destroy the OpenGL context. This happens when the component becomes undisplayable

exceptionOccurredback to summary
protected void exceptionOccurred(LWJGLException exception)

This method will be called if an unhandled LWJGLException occurs in paint(). Override this method to be notified of this.

Parameters
exception:LWJGLException

The exception that occurred.

getContextback to summary
public ContextGL getContext()

Implements org.lwjgl.opengl.DrawableLWJGL.getContext.

This method should only be called internally.

Returns:ContextGL

Doc from org.lwjgl.opengl.DrawableLWJGL.getContext.

the Drawable's Context

getPixelFormatback to summary
public PixelFormatLWJGL getPixelFormat()

Implements org.lwjgl.opengl.DrawableLWJGL.getPixelFormat.

hierarchyChangedback to summary
public void hierarchyChanged(HierarchyEvent e)

Implements java.awt.event.HierarchyListener.hierarchyChanged.

Doc from java.awt.event.HierarchyListener.hierarchyChanged.

Called when the hierarchy has been changed. To discern the actual type of change, call HierarchyEvent.getChangeFlags().

Parameters
e:HierarchyEvent

the event to be processed

initContextback to summary
public void initContext(final float r, final float g, final float b)

Implements org.lwjgl.opengl.DrawableLWJGL.initContext.

initGLback to summary
protected void initGL()

Override this to do initialising of the context. It will be called once from paint(), immediately after the context is created and made current.

isCurrentback to summary
public boolean isCurrent() throws LWJGLException

Implements org.lwjgl.opengl.Drawable.isCurrent.

Doc from org.lwjgl.opengl.Drawable.isCurrent.

Returns true if the Drawable's context is current in the current thread.

makeCurrentback to summary
public void makeCurrent() throws LWJGLException

Implements org.lwjgl.opengl.Drawable.makeCurrent.

Make the canvas' context current. It is highly recommended that the context is only made current inside the AWT thread (for example in an overridden paintGL()).

paintback to summary
public final void paint(Graphics g)

Overrides java.awt.Canvas.paint.

The default paint() operation makes the context current and calls paintGL() which should be overridden to do GL operations.

Parameters
g:Graphics

Doc from java.awt.Canvas.paint.

the specified Graphics context

paintGLback to summary
protected void paintGL()

Override this to do painting

releaseContextback to summary
public void releaseContext() throws LWJGLException

Implements org.lwjgl.opengl.Drawable.releaseContext.

Doc from org.lwjgl.opengl.Drawable.releaseContext.

If the Drawable's context is current in the current thread, no context will be current after a call to this method.

removeNotifyback to summary
public void removeNotify()

Overrides java.awt.Component.removeNotify.

Doc from java.awt.Component.removeNotify.

Makes this Component undisplayable by destroying it native screen resource.

This method is called by the toolkit internally and should not be called directly by programs. Code overriding this method should call super.removeNotify as the first line of the overriding method.

setBoundsback to summary
public void setBounds(int x, int y, int width, int height)

Overrides java.awt.Component.setBounds.

Doc from java.awt.Component.setBounds.

Moves and resizes this component. The new location of the top-left corner is specified by x and y, and the new size is specified by width and height.

This method changes layout-related information, and therefore, invalidates the component hierarchy.

Parameters
x:int

the new x-coordinate of this component

y:int

the new y-coordinate of this component

width:int

the new width of this component

height:int

the new height of this component

setCLSharingPropertiesback to summary
public final void setCLSharingProperties(final PointerBuffer properties) throws LWJGLException

Implements org.lwjgl.opengl.Drawable.setCLSharingProperties.

Doc from org.lwjgl.opengl.Drawable.setCLSharingProperties.

Sets the appropriate khr_gl_sharing properties in the target PointerBuffer, so that if it is used in a clCreateContext(FromType) call, the created CL context will be sharing objects with this Drawable's GL context. After a call to this method, the target buffer position will have advanced by 2 to 4 positions, depending on the implementation.

Parameters
properties:PointerBuffer

The target properties buffer. It must have at least 4 positions remaining.

setLocationback to summary
public void setLocation(int x, int y)

Overrides java.awt.Component.setLocation.

Doc from java.awt.Component.setLocation.

Moves this component to a new location. The top-left corner of the new location is specified by the x and y parameters in the coordinate space of this component's parent.

This method changes layout-related information, and therefore, invalidates the component hierarchy.

Parameters
x:int

the x-coordinate of the new location's top-left corner in the parent's coordinate space

y:int

the y-coordinate of the new location's top-left corner in the parent's coordinate space

setLocationback to summary
public void setLocation(Point p)

Overrides java.awt.Component.setLocation.

Doc from java.awt.Component.setLocation.

Moves this component to a new location. The top-left corner of the new location is specified by point p. Point p is given in the parent's coordinate space.

This method changes layout-related information, and therefore, invalidates the component hierarchy.

Parameters
p:Point

the point defining the top-left corner of the new location, given in the coordinate space of this component's parent

setPixelFormatback to summary
public void setPixelFormat(final PixelFormatLWJGL pf) throws LWJGLException

Implements org.lwjgl.opengl.DrawableLWJGL.setPixelFormat.

setPixelFormatback to summary
public void setPixelFormat(final PixelFormatLWJGL pf, final ContextAttribs attribs) throws LWJGLException

Implements org.lwjgl.opengl.DrawableLWJGL.setPixelFormat.

setSizeback to summary
public void setSize(Dimension d)

Overrides java.awt.Component.setSize.

Doc from java.awt.Component.setSize.

Resizes this component so that it has width d.width and height d.height.

This method changes layout-related information, and therefore, invalidates the component hierarchy.

Parameters
d:Dimension

the dimension specifying the new size of this component

setSizeback to summary
public void setSize(int width, int height)

Overrides java.awt.Component.setSize.

Doc from java.awt.Component.setSize.

Resizes this component so that it has width width and height height.

This method changes layout-related information, and therefore, invalidates the component hierarchy.

Parameters
width:int

the new width of this component in pixels

height:int

the new height of this component in pixels

setSwapIntervalback to summary
public void setSwapInterval(int swap_interval)

Implements org.lwjgl.opengl.DrawableLWJGL.setSwapInterval.

Set swap interval.

setUpdateback to summary
private void setUpdate()
setVSyncEnabledback to summary
public void setVSyncEnabled(boolean enabled)

Enable vsync

swapBuffersback to summary
public void swapBuffers() throws LWJGLException

Implements org.lwjgl.opengl.DrawableLWJGL.swapBuffers.

Swap the canvas' buffer

updateback to summary
public void update(Graphics g)

Overrides java.awt.Canvas.update.

override update to avoid clearing

Parameters
g:Graphics

Doc from java.awt.Canvas.update.

the specified Graphics context