Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 30511 Details for
Bug 110757
[OpenGL] Support the JOGL GLDrawable API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Example using a generic SWT Canvas with JOGL
GenericCanvasDemo.java (text/plain), 4.65 KB, created by
Justin Couch
on 2005-11-23 19:10:02 EST
(
hide
)
Description:
Example using a generic SWT Canvas with JOGL
Filename:
MIME Type:
Creator:
Justin Couch
Created:
2005-11-23 19:10:02 EST
Size:
4.65 KB
patch
obsolete
>/***************************************************************************** > * Yumetech, Inc Copyright (c) 2005 > * Java Source > * > * This source is licensed under the BSD-style License > * Please read http://www.opensource.org/licenses/bsd-license.php for more > * information or docs/BSD.txt in the downloaded code. > * > * This software comes with the standard NO WARRANTY disclaimer for any > * purpose. Use it at your own risk. If there's a problem you get to fix it. > * > ****************************************************************************/ > >// External imports >import org.eclipse.swt.graphics.*; >import org.eclipse.swt.widgets.*; > >import javax.media.opengl.GL; >import javax.media.opengl.GLContext; >import javax.media.opengl.GLDrawable; >import javax.media.opengl.GLDrawableFactory; > >import org.eclipse.swt.SWT; >import org.eclipse.swt.events.DisposeEvent; >import org.eclipse.swt.events.DisposeListener; >import org.eclipse.swt.layout.FillLayout; > >// Local imports >import org.j3d.opengl.swt.GLCanvas; > >/** > * The first demonstration of using the SWT bindings to the JSR-231 code. > * <p> > * > * The demo creates the basic application output and then manually deals with > * refreshing the OpenGL state. It does this by creating an endless thread that > * just loops calling makeCurrent(), painting a basic rectangle, then releasing > * the context, sleeping a little bit, then repeating over and over. > * > * @author Justin Couch > * @version $Revision: 2.8 $ > */ >public class GenericCanvasDemo implements Runnable >{ > /** The GLContext we're drawing with */ > private GLContext context; > > /** The GLDrawble we're drawing to */ > private GLDrawable drawable; > > /** The display we're drawing to */ > private static Display display; > > /** > * Create a new demo that runs on the given shell as parent. > */ > public GenericCanvasDemo(Shell parent) > { > Canvas canvas = new Canvas(parent, SWT.NONE); > > GLDrawableFactory factory = GLDrawableFactory.getFactory(); > drawable = factory.getGLDrawable(canvas, null, null); > drawable.setRealized(true); > context = drawable.createContext(null); > > canvas.addDisposeListener( > new DisposeListener() > { > public void widgetDisposed(DisposeEvent e) > { > context.destroy(); > drawable.setRealized(false); > } > } > ); > } > > public static void main(String [] args) > { > System.setProperty("opengl.factory.class.name", > "org.j3d.opengl.swt.SWTDrawableFactory"); > > Shell shell = new Shell(); > shell.setLayout(new FillLayout()); > GenericCanvasDemo demo = new GenericCanvasDemo(shell); > > shell.setSize (640, 480); > shell.open(); > > display = shell.getDisplay(); > > Thread th = new Thread(demo); > th.start(); > > > while(!shell.isDisposed()) > { > if(!display.readAndDispatch()) > display.sleep(); > } > > display.dispose(); > } > > //---------------------------------------------------------- > // Methods defined by Runnable > //---------------------------------------------------------- > > /** > * Run the repainting thread now. > */ > public void run() > { > // Do our initial setup of the GL pipeline > int state = context.makeCurrent(); > > GL gl = context.getGL(); > > System.out.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR)); > > gl.glViewport(0, 0, 640, 480); > gl.glEnable(GL.GL_DEPTH_TEST); > gl.glEnable(GL.GL_NORMALIZE); > > context.release(); > > while(true) > { > context.makeCurrent(); > gl = context.getGL(); > > gl.glClear(GL.GL_DEPTH_BUFFER_BIT | GL.GL_COLOR_BUFFER_BIT); > > gl.glLoadIdentity(); > gl.glTranslatef(-0.5f,0,-0.9f); > gl.glBegin(GL.GL_TRIANGLES); > gl.glColor3f(1, 0, 0); > gl.glVertex3f( 0.0f, 0.3f, 0); > gl.glVertex3f(-0.3f,-0.3f, 0); > gl.glVertex3f( 0.3f,-0.3f, 0); > gl.glEnd(); > > gl.glTranslatef(1f, 0, 0); > gl.glBegin(GL.GL_QUADS); > gl.glColor3f(0, 1, 0); > gl.glVertex3f(-0.3f, 0.3f, 0); > gl.glVertex3f( 0.3f, 0.3f, 0); > gl.glVertex3f( 0.3f,-0.3f, 0); > gl.glVertex3f(-0.3f,-0.3f, 0); > gl.glEnd(); > > drawable.swapBuffers(); > context.release(); > > try > { > Thread.sleep(100); > } > catch(InterruptedException ie) > { > } > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 110757
:
27685
|
28912
|
30386
| 30511