https://jogamp.org/wiki/api.php?action=feedcontributions&user=Wwalker&feedformat=atomJogampWiki - User contributions [en]2024-03-28T20:43:48ZUser contributionsMediaWiki 1.38.4https://jogamp.org/wiki/index.php?title=Setting_up_a_JogAmp_project_in_your_favorite_IDE&diff=1951Setting up a JogAmp project in your favorite IDE2016-03-03T02:39:20Z<p>Wwalker: Added -Djogamp.gluegen.UseTempJarCache=false to instructions for command line</p>
<hr />
<div>__TOC__<br />
<br />
These instructions assume that you've created a project in your favorite IDE, and now you want your project to be able to use a JogAmp library like JOGL, JOCL, JOAL, or GlueGen. We use JOGL as an example below, but these instructions work equally well for any other JogAmp library.<br />
<br />
= Download a JogAmp library =<br />
<br />
If you haven't done so already, download and extract the JogAmp library you want to use. For example, to download and extract JOGL, see the instructions at [[Downloading and installing JOGL]].<br />
<br />
To use a JogAmp library you'll do three things:<br />
<br />
* Add its JAR files to the Java classpath<br />
* Add its native libraries in one of two ways:<br />
** Either place its native JAR files in the same directory as the library JAR files<br />
** Or add its native library files(the <tt>.dll</tt>,<tt>.so</tt>, and <tt>.jnilib</tt> files) to the Java library path<br />
* Optional: Associate the *-java-src.zip files with the corresponding JAR files.<br />
<br />
Each IDE has a slightly different way to do these things, as we show below. Using the native JAR files is usually slightly easier than using the native library files directly, and native JARs make it possible for all platforms' libraries to coexist in one project, so this is the recommended method.<br />
<br />
Please note that all JogAmp libraries depend on the GlueGen runtime libraries. These are included in every JogAmp library for convenience, but are only required once in the classpath and library path of your project.<br />
<br />
See [[JogAmp JAR File Handling|JogAmp JAR File Handling]], for details on native JAR files and custom JAR bundling.<br />
<br />
= Eclipse IDE project =<br />
<br />
Probably the simplest way to use JOGL in an Eclipse project is to create another Eclipse project to contain the JOGL JARs, then make your project depend on this new JOGL project. In the example below, I include only the 64-bit Windows native JARs, but you can put native JARs for as many platforms as you wish together into the JOGL Eclipse project.<br />
<br />
=== Create a JOGL project ===<br />
<br />
* Put all the JOGL code JARs, native JARs for all platforms you wish to support, and source ZIP files in a directory called "JOGL" in your workspace directory.<br />
* Click "File > New > Java Project". Type "JOGL" as the project name and click "Next".<br />
[[File:Eclipse_project_setup_01_create_project.png|300px|thumb|none|Create JOGL project]]<br />
* Remove the native JARs from the project, leaving only gluegen-rt.jar and jogl-all.jar.<br />
[[File:Eclipse_project_setup_02_remove_native_JARs.png|300px|thumb|none|Remove native JARs]]<br />
NOTE: The gluegen-rt-natives-*-*.jar and jogl-all-natives-*-*.jar are not<br />
required in the classpath by JOGL, but are required by Eclipse to export<br />
your project as a runnable JAR file.<br />
* Expand the jogl-all and gluegen-rt JARs. For each of them, double-click "Source attachment", click "Workspace...", navigate to the corresponding <tt>*-java-src.zip</tt> file in the project, select it, click "OK", and click "OK" again to dismiss the "Source Attachment Configuration" dialog. The JARs should look like this when you're done:<br />
[[File:Eclipse_project_setup_03_JARs_with_source_attached.png|300px|thumb|none|Attach source to JARs]]<br />
* Click the "Order and Export" tab. Check both JOGL JARs, then click "Finish".<br />
[[File:Eclipse_project_setup_04_order_and_export.png|300px|thumb|none|Exporting JOGL JARs]]<br />
<br />
=== Add dependency on the JOGL project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select the "Java Build Path" on the left, then click the "Projects" tab on the right.<br />
* Click the "Add..." button, check "JOGL", and click "OK".<br />
* Your dependent project should look like this. Click "OK" to dismiss the "Properties" dialog.<br />
[[File:Eclipse_project_setup_05_project_dependency.png|300px|thumb|none|JOGL project dependency]]<br />
<br />
That's it! Your project can now use the library.<br />
<br />
= Eclipse IDE user library =<br />
<br />
If you don't want to put JOGL in a separate Eclipse project, you can put it in a user library instead. The drawback to this is that the user library is defined in your .metadata directory and contains absolute paths, so it's hard to share with others. But for a non-shared project this works fine.<br />
<br />
=== Create a user library ===<br />
<br />
* Click "Window > Preferences", then select "Java > Build Path > User Libraries" on the left.<br />
* Click the "New..." button, type "JOGL" for the library name, and click "OK".<br />
[[File:Eclipse_setup_01_create_user_library.png|300px|thumb|none|Create user library]]<br />
* Click the "Add JARs..." button, navigate to the directory where you've stored the JARs, select all the non-native JARs, then click "Open".<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Expand each non-native JAR in the list<br />
** Double-click "Source attachment", type the module's source zip name, (e.g. <tt>jogl-java-src.zip</tt> for the JAR file <tt>jogl-all.jar</tt>), and click "OK".<br />
** If you're using native library files:<br />
*** Double-click "Native library location", type the directory where native library files are stored, and click "OK".<br />
[[File:Eclipse_setup_02_set_native_library_locations.png|300px|thumb|none|Set native library locations]]<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
=== Add the user library to your project's dependencies ===<br />
<br />
* Right-click your project in the Package Explorer and click "Properties".<br />
* Select "Java Build Path" and click the "Libraries" tab.<br />
[[File:Eclipse_setup_03_add_library_to_project.png|300px|thumb|none|Add library to project]]<br />
* Click "Add Library...", select "User Library", click "Next", check "JOGL", and click "Finish".<br />
[[File:Eclipse_setup_04_add_JOGL_library_to_project.png|300px|thumb|none|Add JOGL library to project]]<br />
* Click "OK" to dismiss the Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= IntelliJ IDEA =<br />
=== Add a library dependency to your project ===<br />
<br />
* Click "File > Project Structure".<br />
* Select "Modules" on the left, then click the "Dependencies" tab on the right.<br />
* Click the "+" button on the right, then select "Library... > Java".<br />
[[File:IntelliJ_setup_01_add_library.png|300px|thumb|none|Add library]]<br />
* Navigate to the directory where you extracted the JARs, select it, and click "OK".<br />
[[File:IntelliJ_setup_02_find_library.png|300px|thumb|none|Find library]]<br />
* Click "OK" to dismiss the Configure Library dialog.<br />
[[File:IntelliJ_setup_03_configure_library.png|300px|thumb|none|Configure library]]<br />
* Click "OK" to dismiss the Project Structure dialog. The external libraries in your project should now look like this if you're using native JAR files:<br />
[[File:IntelliJ_setup_04_external_library_native_JARs.png|300px|thumb|none|Native JARs]]<br />
or like this if you're using native library files:<br />
[[File:IntelliJ_setup_04_external_library.png|300px|thumb|none|Native library files]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Edit Configurations".<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Parameters" box. Note that paths with spaces must be double-quoted on Windows.<br />
[[File:IntelliJ_setup_05_run_configuration.png|300px|thumb|none|Edit run configuration]]<br />
** Click "OK" to dismiss the Run/Debug Configurations dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= NetBeans IDE = <br />
=== Create a library and add it to your project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select "Libraries" on the left and click "Add Library...".<br />
* Click the "Create" button, then type "JOGL" for the library name and click "OK".[[File:NetBeans_setup_01_create_library.png|300px|thumb|none|Create library]]<br />
* Click "Add JAR/Folder...", then navigate to the directory you extracted the JAR files, select them and click "Add JAR/Folder".<br />
* Click "OK" to dismiss the Customize Library dialog.<br />
* Click "Add Library" to dismiss the Add Library dialog.[[File:NetBeans_setup_02_add_library.png|300px|thumb|none|Add library]]<br />
* Click "OK" to dismiss the Project Properties dialog. The libraries in your project should look like this.[[File:NetBeans_setup_03_libraries_in_project.png|300px|thumb|none|Libraries in project]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Set Project Configuration > Customize...". Select "Run" on the left if it isn't selected already.<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Options" box.<br />
** NOTE: If the library path has spaces in it, you must put quotes around it (at least on Windows) or you may get an odd NoClassDefFoundError when you try to run.[[File:NetBeans_setup_04_native_library_path.png|300px|thumb|none|Native library path]]<br />
** Click "OK" to dismiss the Project Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= Maven =<br />
<br />
Since <tt>2.0-rc11</tt>, packages for all the JogAmp projects have been pushed to<br />
[http://search.maven.org/#search|ga|1|jogamp Maven Central]. Please see the<br />
[[Maven]] page for details on how to use them in your projects.<br />
<br />
= vi and other text editors =<br />
=== Create your project with the editor of your choice ===<br />
* For example, to open vi, simply type <tt>vi</tt> and press <return>.<br />
* Type all your code, then save it.<br />
<br />
=== Compile and run your project from the command line ===<br />
* We assume your JOGL JAR files are in a directory called <tt>jar</tt>. If you're using native JARs, we assume they're also in the <tt>jar</tt> directory. If you're using native library files, we assume they're in a directory called <tt>lib</tt>.<br />
<br />
* First compile your program. We assume all your code is in a single file called <tt>name/someone/MyProject.java</tt>.<br />
** Windows: Type <tt>javac -classpath "jar\gluegen-rt.jar;jar\jogl-all.jar" name\someone\MyProject.java</tt><br />
** Linux/MacOS X: Type <tt>javac -classpath "jar/gluegen-rt.jar:jar/jogl-all.jar" name/someone/MyProject.java</tt><br />
<br />
* Then run your project. We assume your main class is <tt>name.someone.MyProject</tt>. If you're using native JARs:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl-all.jar;." name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl-all.jar:." name.someone.MyProject</tt><br />
* If you're using native library files:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl-all.jar;." -Djava.library.path=lib -Djogamp.gluegen.UseTempJarCache=false name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl-all.jar:." -Djava.library.path=lib -Djogamp.gluegen.UseTempJarCache=false name.someone.MyProject</tt><br />
<br />
That's it! You can now use the library in your project.</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Using_JOGL_in_AWT_SWT_and_Swing&diff=1753Using JOGL in AWT SWT and Swing2015-07-03T21:07:34Z<p>Wwalker: Changed javax.media to com.jogamp</p>
<hr />
<div>You can use JOGL with three different Java window toolkits: AWT, SWT, and Swing. This page shows examples of all three toolkits, plus variations on two of them. The example program just draws one triangle that fills a resizable window.<br />
<br />
= How to choose a window toolkit =<br />
<br />
Usually the window toolkit you use for JOGL is dictated by your application. If you're writing an Eclipse-based application, it makes sense to use SWT, since it's the native windowing system of Eclipse. Otherwise, Swing is probably the way to go. If you want to wrap native controls instead of drawing in software like Swing, and you're not writing an Eclipse app, AWT is your best choice.<br />
<br />
= Base class =<br />
<br />
First, a base class that we'll use in all five examples. This class abstracts out all the pure OpenGL calls that don't depend on the choice of window toolkit.<br />
<br />
<pre><br />
import com.jogamp.opengl.GL;<br />
import com.jogamp.opengl.GL2;<br />
import com.jogamp.opengl.glu.GLU;<br />
<br />
public class OneTriangle {<br />
protected static void setup( GL2 gl2, int width, int height ) {<br />
gl2.glMatrixMode( GL2.GL_PROJECTION );<br />
gl2.glLoadIdentity();<br />
<br />
// coordinate system origin at lower left with width and height same as the window<br />
GLU glu = new GLU();<br />
glu.gluOrtho2D( 0.0f, width, 0.0f, height );<br />
<br />
gl2.glMatrixMode( GL2.GL_MODELVIEW );<br />
gl2.glLoadIdentity();<br />
<br />
gl2.glViewport( 0, 0, width, height );<br />
}<br />
<br />
protected static void render( GL2 gl2, int width, int height ) {<br />
gl2.glClear( GL.GL_COLOR_BUFFER_BIT );<br />
<br />
// draw a triangle filling the window<br />
gl2.glLoadIdentity();<br />
gl2.glBegin( GL.GL_TRIANGLES );<br />
gl2.glColor3f( 1, 0, 0 );<br />
gl2.glVertex2f( 0, 0 );<br />
gl2.glColor3f( 0, 1, 0 );<br />
gl2.glVertex2f( width, 0 );<br />
gl2.glColor3f( 0, 0, 1 );<br />
gl2.glVertex2f( width / 2, height );<br />
gl2.glEnd();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in AWT =<br />
<br />
The Abstract Window Toolkit (AWT) was Java's first window toolkit. It's a thin layer over each platform's native window toolkit. Here's how to use JOGL in AWT.<br />
<br />
<pre><br />
import com.jogamp.opengl.GLAutoDrawable;<br />
import com.jogamp.opengl.GLEventListener;<br />
import com.jogamp.opengl.GLProfile;<br />
import com.jogamp.opengl.GLCapabilities;<br />
import com.jogamp.opengl.awt.GLCanvas;<br />
<br />
import java.awt.Frame;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an AWT Frame.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleAWT {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final Frame frame = new Frame( "One Triangle AWT" );<br />
frame.add( glcanvas );<br />
frame.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
frame.remove( glcanvas );<br />
frame.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
frame.setSize( 640, 480 );<br />
frame.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in SWT =<br />
<br />
The [http://www.eclipse.org/swt/ Standard Widget Toolkit (SWT)] is a thin layer over each platform's native window toolkit. SWT is the toolkit used in Eclipse, so it makes sense to use SWT in Eclipse-based applications. To compile this, you'll need the swt.jar file for your platform which you can get [http://www.eclipse.org/swt/ here].<br />
<br />
When running this code on Mac OS X, you'll need to give the <tt>-XstartOnFirstThread</tt> argument to the JVM. This insures that the SWT windowing code sends and recieves messages on thread 0, which is required by Cocoa.<br />
<br />
<pre><br />
import org.eclipse.swt.SWT;<br />
import org.eclipse.swt.events.PaintEvent;<br />
import org.eclipse.swt.events.PaintListener;<br />
import org.eclipse.swt.graphics.Rectangle;<br />
import org.eclipse.swt.layout.FillLayout;<br />
import org.eclipse.swt.opengl.GLCanvas;<br />
import org.eclipse.swt.opengl.GLData;<br />
import org.eclipse.swt.widgets.Composite;<br />
import org.eclipse.swt.widgets.Display;<br />
import org.eclipse.swt.widgets.Event;<br />
import org.eclipse.swt.widgets.Listener;<br />
import org.eclipse.swt.widgets.Shell;<br />
<br />
import com.jogamp.opengl.GLProfile;<br />
import com.jogamp.opengl.GLContext;<br />
import com.jogamp.opengl.GLDrawableFactory;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an SWT Composite.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSWT {<br />
<br />
public static void main( String [] args ) {<br />
Display display = new Display();<br />
final Shell shell = new Shell( display );<br />
shell.setText( "OneTriangle SWT" );<br />
shell.setLayout( new FillLayout() );<br />
shell.setSize( 640, 480 );<br />
<br />
final Composite composite = new Composite( shell, SWT.NONE );<br />
composite.setLayout( new FillLayout() );<br />
<br />
GLData gldata = new GLData();<br />
gldata.doubleBuffer = true;<br />
// need SWT.NO_BACKGROUND to prevent SWT from clearing the window<br />
// at the wrong times (we use glClear for this instead)<br />
final GLCanvas glcanvas = new GLCanvas( composite, SWT.NO_BACKGROUND, gldata );<br />
glcanvas.setCurrent();<br />
GLProfile glprofile = GLProfile.getDefault();<br />
final GLContext glcontext = GLDrawableFactory.getFactory( glprofile ).createExternalGLContext();<br />
<br />
// fix the viewport when the user resizes the window<br />
glcanvas.addListener( SWT.Resize, new Listener() {<br />
public void handleEvent(Event event) {<br />
Rectangle rectangle = glcanvas.getClientArea();<br />
glcanvas.setCurrent();<br />
glcontext.makeCurrent();<br />
OneTriangle.setup( glcontext.getGL().getGL2(), rectangle.width, rectangle.height );<br />
glcontext.release(); <br />
}<br />
});<br />
<br />
// draw the triangle when the OS tells us that any part of the window needs drawing<br />
glcanvas.addPaintListener( new PaintListener() {<br />
public void paintControl( PaintEvent paintevent ) {<br />
Rectangle rectangle = glcanvas.getClientArea();<br />
glcanvas.setCurrent();<br />
glcontext.makeCurrent();<br />
OneTriangle.render(glcontext.getGL().getGL2(), rectangle.width, rectangle.height);<br />
glcanvas.swapBuffers();<br />
glcontext.release(); <br />
}<br />
});<br />
<br />
shell.open();<br />
<br />
while( !shell.isDisposed() ) {<br />
if( !display.readAndDispatch() )<br />
display.sleep();<br />
}<br />
<br />
glcanvas.dispose();<br />
display.dispose();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in SWT using the SWT-AWT bridge =<br />
<br />
The SWT-AWT bridge was created to allow SWT applications to use the AWT GLCanvas. You should use this if you have problems with the SWT GLCanvas. For example, the SWT GLCanvas doesn't currently support multisampling on Windows (see [https://bugs.eclipse.org/bugs/show_bug.cgi?id=136514 here] and [http://jogamp.762907.n3.nabble.com/New-tutorial-on-AWT-SWT-Swing-GLJPanel-GLCanvas-tp2363921p2366724.html here] for details).<br />
<br />
As with normal SWT, to compile this you'll need the swt.jar file for your platform which you can get [http://www.eclipse.org/swt/ here]. And just as with normal SWT, when running this code on Mac OS X, you'll need to give the <tt>-XstartOnFirstThread</tt> argument to the JVM.<br />
<br />
<pre><br />
import java.awt.Frame;<br />
<br />
import org.eclipse.swt.SWT;<br />
import org.eclipse.swt.awt.SWT_AWT;<br />
import org.eclipse.swt.layout.FillLayout;<br />
import org.eclipse.swt.widgets.Composite;<br />
import org.eclipse.swt.widgets.Display;<br />
import org.eclipse.swt.widgets.Shell;<br />
<br />
import com.jogamp.opengl.GLAutoDrawable;<br />
import com.jogamp.opengl.GLCapabilities;<br />
import com.jogamp.opengl.GLEventListener;<br />
import com.jogamp.opengl.GLProfile;<br />
import com.jogamp.opengl.awt.GLCanvas;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an SWT Composite using an<br />
* embedded AWT Frame and the AWT GLCanvas via the SWT-AWT bridge.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSWTAWTBridge {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
Display display = new Display();<br />
final Shell shell = new Shell( display );<br />
shell.setText( "OneTriangle SWT AWT Bridge" );<br />
shell.setLayout( new FillLayout() );<br />
shell.setSize( 640, 480 );<br />
<br />
final Composite composite = new Composite( shell, SWT.EMBEDDED );<br />
composite.setLayout( new FillLayout() );<br />
<br />
Frame frame = SWT_AWT.new_Frame( composite );<br />
frame.add( glcanvas );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
shell.open();<br />
<br />
while( !shell.isDisposed() ) {<br />
if( !display.readAndDispatch() )<br />
display.sleep();<br />
}<br />
<br />
display.dispose();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in Swing =<br />
<br />
Swing is the primary Java window toolkit since Java 1.2 in 1997. It's based on AWT at a low level, but draws all its own controls instead of wrapping native controls. Here's how to use JOGL in Swing.<br />
<br />
<pre><br />
import com.jogamp.opengl.GLAutoDrawable;<br />
import com.jogamp.opengl.GLEventListener;<br />
import com.jogamp.opengl.GLProfile;<br />
import com.jogamp.opengl.GLCapabilities;<br />
import com.jogamp.opengl.awt.GLCanvas;<br />
import javax.swing.JFrame;<br />
<br />
import java.awt.BorderLayout;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in a Swing JFrame using the AWT GLCanvas.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSwingGLCanvas {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final JFrame jframe = new JFrame( "One Triangle Swing GLCanvas" ); <br />
jframe.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
jframe.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
jframe.getContentPane().add( glcanvas, BorderLayout.CENTER );<br />
jframe.setSize( 640, 480 );<br />
jframe.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in Swing using the GLJPanel =<br />
<br />
In cases where the AWT GLCanvas has problems integrating with Swing components correctly, you can use the GLJPanel instead. For example, JInternalFrames behave incorrectly when used with a GLCanvas -- you have to add JInternalFrames to the Frame that holds the GLCanvas, and when you drag the JInternalFrames around, the GLCanvas doesn't redraw properly underneath it.<br />
<br />
In contrast, GLJPanel is supposed integrate 100% correctly into Swing, but with lower performance due to extra copying of the frame buffer. Here's how to do it.<br />
<br />
<pre><br />
import com.jogamp.opengl.GLAutoDrawable;<br />
import com.jogamp.opengl.GLEventListener;<br />
import com.jogamp.opengl.GLProfile;<br />
import com.jogamp.opengl.GLCapabilities;<br />
import com.jogamp.opengl.awt.GLJPanel;<br />
import javax.swing.JFrame;<br />
<br />
import java.awt.BorderLayout;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in a Swing JFrame using the AWT GLJPanel.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSwingGLJPanel {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
GLJPanel gljpanel = new GLJPanel( glcapabilities ); <br />
<br />
gljpanel.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final JFrame jframe = new JFrame( "One Triangle Swing GLJPanel" ); <br />
jframe.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
jframe.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
jframe.getContentPane().add( gljpanel, BorderLayout.CENTER );<br />
jframe.setSize( 640, 480 );<br />
jframe.setVisible( true );<br />
}<br />
}<br />
</pre></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Using_JOGL_in_AWT_SWT_and_Swing&diff=1752Using JOGL in AWT SWT and Swing2015-07-03T21:06:28Z<p>Wwalker: Changed javax.media to com.jogamp</p>
<hr />
<div>You can use JOGL with three different Java window toolkits: AWT, SWT, and Swing. This page shows examples of all three toolkits, plus variations on two of them. The example program just draws one triangle that fills a resizable window.<br />
<br />
= How to choose a window toolkit =<br />
<br />
Usually the window toolkit you use for JOGL is dictated by your application. If you're writing an Eclipse-based application, it makes sense to use SWT, since it's the native windowing system of Eclipse. Otherwise, Swing is probably the way to go. If you want to wrap native controls instead of drawing in software like Swing, and you're not writing an Eclipse app, AWT is your best choice.<br />
<br />
= Base class =<br />
<br />
First, a base class that we'll use in all five examples. This class abstracts out all the pure OpenGL calls that don't depend on the choice of window toolkit.<br />
<br />
<pre><br />
import com.jogamp.opengl.GL;<br />
import com.jogamp.opengl.GL2;<br />
import com.jogamp.opengl.glu.GLU;<br />
<br />
public class OneTriangle {<br />
protected static void setup( GL2 gl2, int width, int height ) {<br />
gl2.glMatrixMode( GL2.GL_PROJECTION );<br />
gl2.glLoadIdentity();<br />
<br />
// coordinate system origin at lower left with width and height same as the window<br />
GLU glu = new GLU();<br />
glu.gluOrtho2D( 0.0f, width, 0.0f, height );<br />
<br />
gl2.glMatrixMode( GL2.GL_MODELVIEW );<br />
gl2.glLoadIdentity();<br />
<br />
gl2.glViewport( 0, 0, width, height );<br />
}<br />
<br />
protected static void render( GL2 gl2, int width, int height ) {<br />
gl2.glClear( GL.GL_COLOR_BUFFER_BIT );<br />
<br />
// draw a triangle filling the window<br />
gl2.glLoadIdentity();<br />
gl2.glBegin( GL.GL_TRIANGLES );<br />
gl2.glColor3f( 1, 0, 0 );<br />
gl2.glVertex2f( 0, 0 );<br />
gl2.glColor3f( 0, 1, 0 );<br />
gl2.glVertex2f( width, 0 );<br />
gl2.glColor3f( 0, 0, 1 );<br />
gl2.glVertex2f( width / 2, height );<br />
gl2.glEnd();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in AWT =<br />
<br />
The Abstract Window Toolkit (AWT) was Java's first window toolkit. It's a thin layer over each platform's native window toolkit. Here's how to use JOGL in AWT.<br />
<br />
<pre><br />
import com.jogamp.opengl.GLAutoDrawable;<br />
import com.jogamp.opengl.GLEventListener;<br />
import com.jogamp.opengl.GLProfile;<br />
import com.jogamp.opengl.GLCapabilities;<br />
import com.jogamp.opengl.awt.GLCanvas;<br />
<br />
import java.awt.Frame;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an AWT Frame.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleAWT {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final Frame frame = new Frame( "One Triangle AWT" );<br />
frame.add( glcanvas );<br />
frame.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
frame.remove( glcanvas );<br />
frame.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
frame.setSize( 640, 480 );<br />
frame.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in SWT =<br />
<br />
The [http://www.eclipse.org/swt/ Standard Widget Toolkit (SWT)] is a thin layer over each platform's native window toolkit. SWT is the toolkit used in Eclipse, so it makes sense to use SWT in Eclipse-based applications. To compile this, you'll need the swt.jar file for your platform which you can get [http://www.eclipse.org/swt/ here].<br />
<br />
When running this code on Mac OS X, you'll need to give the <tt>-XstartOnFirstThread</tt> argument to the JVM. This insures that the SWT windowing code sends and recieves messages on thread 0, which is required by Cocoa.<br />
<br />
<pre><br />
import org.eclipse.swt.SWT;<br />
import org.eclipse.swt.events.PaintEvent;<br />
import org.eclipse.swt.events.PaintListener;<br />
import org.eclipse.swt.graphics.Rectangle;<br />
import org.eclipse.swt.layout.FillLayout;<br />
import org.eclipse.swt.opengl.GLCanvas;<br />
import org.eclipse.swt.opengl.GLData;<br />
import org.eclipse.swt.widgets.Composite;<br />
import org.eclipse.swt.widgets.Display;<br />
import org.eclipse.swt.widgets.Event;<br />
import org.eclipse.swt.widgets.Listener;<br />
import org.eclipse.swt.widgets.Shell;<br />
<br />
import com.jogamp.opengl.GLProfile;<br />
import com.jogamp.opengl.GLContext;<br />
import com.jogamp.opengl.GLDrawableFactory;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an SWT Composite.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSWT {<br />
<br />
public static void main( String [] args ) {<br />
Display display = new Display();<br />
final Shell shell = new Shell( display );<br />
shell.setText( "OneTriangle SWT" );<br />
shell.setLayout( new FillLayout() );<br />
shell.setSize( 640, 480 );<br />
<br />
final Composite composite = new Composite( shell, SWT.NONE );<br />
composite.setLayout( new FillLayout() );<br />
<br />
GLData gldata = new GLData();<br />
gldata.doubleBuffer = true;<br />
// need SWT.NO_BACKGROUND to prevent SWT from clearing the window<br />
// at the wrong times (we use glClear for this instead)<br />
final GLCanvas glcanvas = new GLCanvas( composite, SWT.NO_BACKGROUND, gldata );<br />
glcanvas.setCurrent();<br />
GLProfile glprofile = GLProfile.getDefault();<br />
final GLContext glcontext = GLDrawableFactory.getFactory( glprofile ).createExternalGLContext();<br />
<br />
// fix the viewport when the user resizes the window<br />
glcanvas.addListener( SWT.Resize, new Listener() {<br />
public void handleEvent(Event event) {<br />
Rectangle rectangle = glcanvas.getClientArea();<br />
glcanvas.setCurrent();<br />
glcontext.makeCurrent();<br />
OneTriangle.setup( glcontext.getGL().getGL2(), rectangle.width, rectangle.height );<br />
glcontext.release(); <br />
}<br />
});<br />
<br />
// draw the triangle when the OS tells us that any part of the window needs drawing<br />
glcanvas.addPaintListener( new PaintListener() {<br />
public void paintControl( PaintEvent paintevent ) {<br />
Rectangle rectangle = glcanvas.getClientArea();<br />
glcanvas.setCurrent();<br />
glcontext.makeCurrent();<br />
OneTriangle.render(glcontext.getGL().getGL2(), rectangle.width, rectangle.height);<br />
glcanvas.swapBuffers();<br />
glcontext.release(); <br />
}<br />
});<br />
<br />
shell.open();<br />
<br />
while( !shell.isDisposed() ) {<br />
if( !display.readAndDispatch() )<br />
display.sleep();<br />
}<br />
<br />
glcanvas.dispose();<br />
display.dispose();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in SWT using the SWT-AWT bridge =<br />
<br />
The SWT-AWT bridge was created to allow SWT applications to use the AWT GLCanvas. You should use this if you have problems with the SWT GLCanvas. For example, the SWT GLCanvas doesn't currently support multisampling on Windows (see [https://bugs.eclipse.org/bugs/show_bug.cgi?id=136514 here] and [http://jogamp.762907.n3.nabble.com/New-tutorial-on-AWT-SWT-Swing-GLJPanel-GLCanvas-tp2363921p2366724.html here] for details).<br />
<br />
As with normal SWT, to compile this you'll need the swt.jar file for your platform which you can get [http://www.eclipse.org/swt/ here]. And just as with normal SWT, when running this code on Mac OS X, you'll need to give the <tt>-XstartOnFirstThread</tt> argument to the JVM.<br />
<br />
<pre><br />
import java.awt.Frame;<br />
<br />
import org.eclipse.swt.SWT;<br />
import org.eclipse.swt.awt.SWT_AWT;<br />
import org.eclipse.swt.layout.FillLayout;<br />
import org.eclipse.swt.widgets.Composite;<br />
import org.eclipse.swt.widgets.Display;<br />
import org.eclipse.swt.widgets.Shell;<br />
<br />
import com.jogamp.opengl.GLAutoDrawable;<br />
import com.jogamp.opengl.GLCapabilities;<br />
import com.jogamp.opengl.GLEventListener;<br />
import com.jogamp.opengl.GLProfile;<br />
import com.jogamp.opengl.awt.GLCanvas;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an SWT Composite using an<br />
* embedded AWT Frame and the AWT GLCanvas via the SWT-AWT bridge.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSWTAWTBridge {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
Display display = new Display();<br />
final Shell shell = new Shell( display );<br />
shell.setText( "OneTriangle SWT AWT Bridge" );<br />
shell.setLayout( new FillLayout() );<br />
shell.setSize( 640, 480 );<br />
<br />
final Composite composite = new Composite( shell, SWT.EMBEDDED );<br />
composite.setLayout( new FillLayout() );<br />
<br />
Frame frame = SWT_AWT.new_Frame( composite );<br />
frame.add( glcanvas );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
shell.open();<br />
<br />
while( !shell.isDisposed() ) {<br />
if( !display.readAndDispatch() )<br />
display.sleep();<br />
}<br />
<br />
display.dispose();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in Swing =<br />
<br />
Swing is the primary Java window toolkit since Java 1.2 in 1997. It's based on AWT at a low level, but draws all its own controls instead of wrapping native controls. Here's how to use JOGL in Swing.<br />
<br />
<pre><br />
import com.jogamp.opengl.GLAutoDrawable;<br />
import com.jogamp.opengl.GLEventListener;<br />
import com.jogamp.opengl.GLProfile;<br />
import com.jogamp.opengl.GLCapabilities;<br />
import com.jogamp.opengl.awt.GLCanvas;<br />
import javax.swing.JFrame;<br />
<br />
import java.awt.BorderLayout;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in a Swing JFrame using the AWT GLCanvas.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSwingGLCanvas {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final JFrame jframe = new JFrame( "One Triangle Swing GLCanvas" ); <br />
jframe.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
jframe.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
jframe.getContentPane().add( glcanvas, BorderLayout.CENTER );<br />
jframe.setSize( 640, 480 );<br />
jframe.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in Swing using the GLJPanel =<br />
<br />
In cases where the AWT GLCanvas has problems integrating with Swing components correctly, you can use the GLJPanel instead. For example, JInternalFrames behave incorrectly when used with a GLCanvas -- you have to add JInternalFrames to the Frame that holds the GLCanvas, and when you drag the JInternalFrames around, the GLCanvas doesn't redraw properly underneath it.<br />
<br />
In contrast, GLJPanel is supposed integrate 100% correctly into Swing, but with lower performance due to extra copying of the frame buffer. Here's how to do it.<br />
<br />
<pre><br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLJPanel;<br />
import javax.swing.JFrame;<br />
<br />
import java.awt.BorderLayout;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in a Swing JFrame using the AWT GLJPanel.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSwingGLJPanel {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
GLJPanel gljpanel = new GLJPanel( glcapabilities ); <br />
<br />
gljpanel.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final JFrame jframe = new JFrame( "One Triangle Swing GLJPanel" ); <br />
jframe.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
jframe.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
jframe.getContentPane().add( gljpanel, BorderLayout.CENTER );<br />
jframe.setSize( 640, 480 );<br />
jframe.setVisible( true );<br />
}<br />
}<br />
</pre></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Using_JOGL_in_AWT_SWT_and_Swing&diff=1751Using JOGL in AWT SWT and Swing2015-07-03T21:04:47Z<p>Wwalker: Changed javax.media to com.jogamp</p>
<hr />
<div>You can use JOGL with three different Java window toolkits: AWT, SWT, and Swing. This page shows examples of all three toolkits, plus variations on two of them. The example program just draws one triangle that fills a resizable window.<br />
<br />
= How to choose a window toolkit =<br />
<br />
Usually the window toolkit you use for JOGL is dictated by your application. If you're writing an Eclipse-based application, it makes sense to use SWT, since it's the native windowing system of Eclipse. Otherwise, Swing is probably the way to go. If you want to wrap native controls instead of drawing in software like Swing, and you're not writing an Eclipse app, AWT is your best choice.<br />
<br />
= Base class =<br />
<br />
First, a base class that we'll use in all five examples. This class abstracts out all the pure OpenGL calls that don't depend on the choice of window toolkit.<br />
<br />
<pre><br />
import com.jogamp.opengl.GL;<br />
import com.jogamp.opengl.GL2;<br />
import com.jogamp.opengl.glu.GLU;<br />
<br />
public class OneTriangle {<br />
protected static void setup( GL2 gl2, int width, int height ) {<br />
gl2.glMatrixMode( GL2.GL_PROJECTION );<br />
gl2.glLoadIdentity();<br />
<br />
// coordinate system origin at lower left with width and height same as the window<br />
GLU glu = new GLU();<br />
glu.gluOrtho2D( 0.0f, width, 0.0f, height );<br />
<br />
gl2.glMatrixMode( GL2.GL_MODELVIEW );<br />
gl2.glLoadIdentity();<br />
<br />
gl2.glViewport( 0, 0, width, height );<br />
}<br />
<br />
protected static void render( GL2 gl2, int width, int height ) {<br />
gl2.glClear( GL.GL_COLOR_BUFFER_BIT );<br />
<br />
// draw a triangle filling the window<br />
gl2.glLoadIdentity();<br />
gl2.glBegin( GL.GL_TRIANGLES );<br />
gl2.glColor3f( 1, 0, 0 );<br />
gl2.glVertex2f( 0, 0 );<br />
gl2.glColor3f( 0, 1, 0 );<br />
gl2.glVertex2f( width, 0 );<br />
gl2.glColor3f( 0, 0, 1 );<br />
gl2.glVertex2f( width / 2, height );<br />
gl2.glEnd();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in AWT =<br />
<br />
The Abstract Window Toolkit (AWT) was Java's first window toolkit. It's a thin layer over each platform's native window toolkit. Here's how to use JOGL in AWT.<br />
<br />
<pre><br />
import com.jogamp.opengl.GLAutoDrawable;<br />
import com.jogamp.opengl.GLEventListener;<br />
import com.jogamp.opengl.GLProfile;<br />
import com.jogamp.opengl.GLCapabilities;<br />
import com.jogamp.opengl.awt.GLCanvas;<br />
<br />
import java.awt.Frame;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an AWT Frame.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleAWT {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final Frame frame = new Frame( "One Triangle AWT" );<br />
frame.add( glcanvas );<br />
frame.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
frame.remove( glcanvas );<br />
frame.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
frame.setSize( 640, 480 );<br />
frame.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in SWT =<br />
<br />
The [http://www.eclipse.org/swt/ Standard Widget Toolkit (SWT)] is a thin layer over each platform's native window toolkit. SWT is the toolkit used in Eclipse, so it makes sense to use SWT in Eclipse-based applications. To compile this, you'll need the swt.jar file for your platform which you can get [http://www.eclipse.org/swt/ here].<br />
<br />
When running this code on Mac OS X, you'll need to give the <tt>-XstartOnFirstThread</tt> argument to the JVM. This insures that the SWT windowing code sends and recieves messages on thread 0, which is required by Cocoa.<br />
<br />
<pre><br />
import org.eclipse.swt.SWT;<br />
import org.eclipse.swt.events.PaintEvent;<br />
import org.eclipse.swt.events.PaintListener;<br />
import org.eclipse.swt.graphics.Rectangle;<br />
import org.eclipse.swt.layout.FillLayout;<br />
import org.eclipse.swt.opengl.GLCanvas;<br />
import org.eclipse.swt.opengl.GLData;<br />
import org.eclipse.swt.widgets.Composite;<br />
import org.eclipse.swt.widgets.Display;<br />
import org.eclipse.swt.widgets.Event;<br />
import org.eclipse.swt.widgets.Listener;<br />
import org.eclipse.swt.widgets.Shell;<br />
<br />
import com.jogamp.opengl.GLProfile;<br />
import com.jogamp.opengl.GLContext;<br />
import com.jogamp.opengl.GLDrawableFactory;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an SWT Composite.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSWT {<br />
<br />
public static void main( String [] args ) {<br />
Display display = new Display();<br />
final Shell shell = new Shell( display );<br />
shell.setText( "OneTriangle SWT" );<br />
shell.setLayout( new FillLayout() );<br />
shell.setSize( 640, 480 );<br />
<br />
final Composite composite = new Composite( shell, SWT.NONE );<br />
composite.setLayout( new FillLayout() );<br />
<br />
GLData gldata = new GLData();<br />
gldata.doubleBuffer = true;<br />
// need SWT.NO_BACKGROUND to prevent SWT from clearing the window<br />
// at the wrong times (we use glClear for this instead)<br />
final GLCanvas glcanvas = new GLCanvas( composite, SWT.NO_BACKGROUND, gldata );<br />
glcanvas.setCurrent();<br />
GLProfile glprofile = GLProfile.getDefault();<br />
final GLContext glcontext = GLDrawableFactory.getFactory( glprofile ).createExternalGLContext();<br />
<br />
// fix the viewport when the user resizes the window<br />
glcanvas.addListener( SWT.Resize, new Listener() {<br />
public void handleEvent(Event event) {<br />
Rectangle rectangle = glcanvas.getClientArea();<br />
glcanvas.setCurrent();<br />
glcontext.makeCurrent();<br />
OneTriangle.setup( glcontext.getGL().getGL2(), rectangle.width, rectangle.height );<br />
glcontext.release(); <br />
}<br />
});<br />
<br />
// draw the triangle when the OS tells us that any part of the window needs drawing<br />
glcanvas.addPaintListener( new PaintListener() {<br />
public void paintControl( PaintEvent paintevent ) {<br />
Rectangle rectangle = glcanvas.getClientArea();<br />
glcanvas.setCurrent();<br />
glcontext.makeCurrent();<br />
OneTriangle.render(glcontext.getGL().getGL2(), rectangle.width, rectangle.height);<br />
glcanvas.swapBuffers();<br />
glcontext.release(); <br />
}<br />
});<br />
<br />
shell.open();<br />
<br />
while( !shell.isDisposed() ) {<br />
if( !display.readAndDispatch() )<br />
display.sleep();<br />
}<br />
<br />
glcanvas.dispose();<br />
display.dispose();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in SWT using the SWT-AWT bridge =<br />
<br />
The SWT-AWT bridge was created to allow SWT applications to use the AWT GLCanvas. You should use this if you have problems with the SWT GLCanvas. For example, the SWT GLCanvas doesn't currently support multisampling on Windows (see [https://bugs.eclipse.org/bugs/show_bug.cgi?id=136514 here] and [http://jogamp.762907.n3.nabble.com/New-tutorial-on-AWT-SWT-Swing-GLJPanel-GLCanvas-tp2363921p2366724.html here] for details).<br />
<br />
As with normal SWT, to compile this you'll need the swt.jar file for your platform which you can get [http://www.eclipse.org/swt/ here]. And just as with normal SWT, when running this code on Mac OS X, you'll need to give the <tt>-XstartOnFirstThread</tt> argument to the JVM.<br />
<br />
<pre><br />
import java.awt.Frame;<br />
<br />
import org.eclipse.swt.SWT;<br />
import org.eclipse.swt.awt.SWT_AWT;<br />
import org.eclipse.swt.layout.FillLayout;<br />
import org.eclipse.swt.widgets.Composite;<br />
import org.eclipse.swt.widgets.Display;<br />
import org.eclipse.swt.widgets.Shell;<br />
<br />
import com.jogamp.opengl.GLAutoDrawable;<br />
import com.jogamp.opengl.GLCapabilities;<br />
import com.jogamp.opengl.GLEventListener;<br />
import com.jogamp.opengl.GLProfile;<br />
import com.jogamp.opengl.awt.GLCanvas;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an SWT Composite using an<br />
* embedded AWT Frame and the AWT GLCanvas via the SWT-AWT bridge.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSWTAWTBridge {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
Display display = new Display();<br />
final Shell shell = new Shell( display );<br />
shell.setText( "OneTriangle SWT AWT Bridge" );<br />
shell.setLayout( new FillLayout() );<br />
shell.setSize( 640, 480 );<br />
<br />
final Composite composite = new Composite( shell, SWT.EMBEDDED );<br />
composite.setLayout( new FillLayout() );<br />
<br />
Frame frame = SWT_AWT.new_Frame( composite );<br />
frame.add( glcanvas );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
shell.open();<br />
<br />
while( !shell.isDisposed() ) {<br />
if( !display.readAndDispatch() )<br />
display.sleep();<br />
}<br />
<br />
display.dispose();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in Swing =<br />
<br />
Swing is the primary Java window toolkit since Java 1.2 in 1997. It's based on AWT at a low level, but draws all its own controls instead of wrapping native controls. Here's how to use JOGL in Swing.<br />
<br />
<pre><br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLCanvas;<br />
import javax.swing.JFrame;<br />
<br />
import java.awt.BorderLayout;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in a Swing JFrame using the AWT GLCanvas.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSwingGLCanvas {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final JFrame jframe = new JFrame( "One Triangle Swing GLCanvas" ); <br />
jframe.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
jframe.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
jframe.getContentPane().add( glcanvas, BorderLayout.CENTER );<br />
jframe.setSize( 640, 480 );<br />
jframe.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in Swing using the GLJPanel =<br />
<br />
In cases where the AWT GLCanvas has problems integrating with Swing components correctly, you can use the GLJPanel instead. For example, JInternalFrames behave incorrectly when used with a GLCanvas -- you have to add JInternalFrames to the Frame that holds the GLCanvas, and when you drag the JInternalFrames around, the GLCanvas doesn't redraw properly underneath it.<br />
<br />
In contrast, GLJPanel is supposed integrate 100% correctly into Swing, but with lower performance due to extra copying of the frame buffer. Here's how to do it.<br />
<br />
<pre><br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLJPanel;<br />
import javax.swing.JFrame;<br />
<br />
import java.awt.BorderLayout;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in a Swing JFrame using the AWT GLJPanel.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSwingGLJPanel {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
GLJPanel gljpanel = new GLJPanel( glcapabilities ); <br />
<br />
gljpanel.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final JFrame jframe = new JFrame( "One Triangle Swing GLJPanel" ); <br />
jframe.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
jframe.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
jframe.getContentPane().add( gljpanel, BorderLayout.CENTER );<br />
jframe.setSize( 640, 480 );<br />
jframe.setVisible( true );<br />
}<br />
}<br />
</pre></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Using_JOGL_in_AWT_SWT_and_Swing&diff=1750Using JOGL in AWT SWT and Swing2015-07-03T21:03:29Z<p>Wwalker: Changed javax.media to com.jogamp</p>
<hr />
<div>You can use JOGL with three different Java window toolkits: AWT, SWT, and Swing. This page shows examples of all three toolkits, plus variations on two of them. The example program just draws one triangle that fills a resizable window.<br />
<br />
= How to choose a window toolkit =<br />
<br />
Usually the window toolkit you use for JOGL is dictated by your application. If you're writing an Eclipse-based application, it makes sense to use SWT, since it's the native windowing system of Eclipse. Otherwise, Swing is probably the way to go. If you want to wrap native controls instead of drawing in software like Swing, and you're not writing an Eclipse app, AWT is your best choice.<br />
<br />
= Base class =<br />
<br />
First, a base class that we'll use in all five examples. This class abstracts out all the pure OpenGL calls that don't depend on the choice of window toolkit.<br />
<br />
<pre><br />
import com.jogamp.opengl.GL;<br />
import com.jogamp.opengl.GL2;<br />
import com.jogamp.opengl.glu.GLU;<br />
<br />
public class OneTriangle {<br />
protected static void setup( GL2 gl2, int width, int height ) {<br />
gl2.glMatrixMode( GL2.GL_PROJECTION );<br />
gl2.glLoadIdentity();<br />
<br />
// coordinate system origin at lower left with width and height same as the window<br />
GLU glu = new GLU();<br />
glu.gluOrtho2D( 0.0f, width, 0.0f, height );<br />
<br />
gl2.glMatrixMode( GL2.GL_MODELVIEW );<br />
gl2.glLoadIdentity();<br />
<br />
gl2.glViewport( 0, 0, width, height );<br />
}<br />
<br />
protected static void render( GL2 gl2, int width, int height ) {<br />
gl2.glClear( GL.GL_COLOR_BUFFER_BIT );<br />
<br />
// draw a triangle filling the window<br />
gl2.glLoadIdentity();<br />
gl2.glBegin( GL.GL_TRIANGLES );<br />
gl2.glColor3f( 1, 0, 0 );<br />
gl2.glVertex2f( 0, 0 );<br />
gl2.glColor3f( 0, 1, 0 );<br />
gl2.glVertex2f( width, 0 );<br />
gl2.glColor3f( 0, 0, 1 );<br />
gl2.glVertex2f( width / 2, height );<br />
gl2.glEnd();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in AWT =<br />
<br />
The Abstract Window Toolkit (AWT) was Java's first window toolkit. It's a thin layer over each platform's native window toolkit. Here's how to use JOGL in AWT.<br />
<br />
<pre><br />
import com.jogamp.opengl.GLAutoDrawable;<br />
import com.jogamp.opengl.GLEventListener;<br />
import com.jogamp.opengl.GLProfile;<br />
import com.jogamp.opengl.GLCapabilities;<br />
import com.jogamp.opengl.awt.GLCanvas;<br />
<br />
import java.awt.Frame;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an AWT Frame.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleAWT {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final Frame frame = new Frame( "One Triangle AWT" );<br />
frame.add( glcanvas );<br />
frame.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
frame.remove( glcanvas );<br />
frame.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
frame.setSize( 640, 480 );<br />
frame.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in SWT =<br />
<br />
The [http://www.eclipse.org/swt/ Standard Widget Toolkit (SWT)] is a thin layer over each platform's native window toolkit. SWT is the toolkit used in Eclipse, so it makes sense to use SWT in Eclipse-based applications. To compile this, you'll need the swt.jar file for your platform which you can get [http://www.eclipse.org/swt/ here].<br />
<br />
When running this code on Mac OS X, you'll need to give the <tt>-XstartOnFirstThread</tt> argument to the JVM. This insures that the SWT windowing code sends and recieves messages on thread 0, which is required by Cocoa.<br />
<br />
<pre><br />
import org.eclipse.swt.SWT;<br />
import org.eclipse.swt.events.PaintEvent;<br />
import org.eclipse.swt.events.PaintListener;<br />
import org.eclipse.swt.graphics.Rectangle;<br />
import org.eclipse.swt.layout.FillLayout;<br />
import org.eclipse.swt.opengl.GLCanvas;<br />
import org.eclipse.swt.opengl.GLData;<br />
import org.eclipse.swt.widgets.Composite;<br />
import org.eclipse.swt.widgets.Display;<br />
import org.eclipse.swt.widgets.Event;<br />
import org.eclipse.swt.widgets.Listener;<br />
import org.eclipse.swt.widgets.Shell;<br />
<br />
import com.jogamp.opengl.GLProfile;<br />
import com.jogamp.opengl.GLContext;<br />
import com.jogamp.opengl.GLDrawableFactory;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an SWT Composite.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSWT {<br />
<br />
public static void main( String [] args ) {<br />
Display display = new Display();<br />
final Shell shell = new Shell( display );<br />
shell.setText( "OneTriangle SWT" );<br />
shell.setLayout( new FillLayout() );<br />
shell.setSize( 640, 480 );<br />
<br />
final Composite composite = new Composite( shell, SWT.NONE );<br />
composite.setLayout( new FillLayout() );<br />
<br />
GLData gldata = new GLData();<br />
gldata.doubleBuffer = true;<br />
// need SWT.NO_BACKGROUND to prevent SWT from clearing the window<br />
// at the wrong times (we use glClear for this instead)<br />
final GLCanvas glcanvas = new GLCanvas( composite, SWT.NO_BACKGROUND, gldata );<br />
glcanvas.setCurrent();<br />
GLProfile glprofile = GLProfile.getDefault();<br />
final GLContext glcontext = GLDrawableFactory.getFactory( glprofile ).createExternalGLContext();<br />
<br />
// fix the viewport when the user resizes the window<br />
glcanvas.addListener( SWT.Resize, new Listener() {<br />
public void handleEvent(Event event) {<br />
Rectangle rectangle = glcanvas.getClientArea();<br />
glcanvas.setCurrent();<br />
glcontext.makeCurrent();<br />
OneTriangle.setup( glcontext.getGL().getGL2(), rectangle.width, rectangle.height );<br />
glcontext.release(); <br />
}<br />
});<br />
<br />
// draw the triangle when the OS tells us that any part of the window needs drawing<br />
glcanvas.addPaintListener( new PaintListener() {<br />
public void paintControl( PaintEvent paintevent ) {<br />
Rectangle rectangle = glcanvas.getClientArea();<br />
glcanvas.setCurrent();<br />
glcontext.makeCurrent();<br />
OneTriangle.render(glcontext.getGL().getGL2(), rectangle.width, rectangle.height);<br />
glcanvas.swapBuffers();<br />
glcontext.release(); <br />
}<br />
});<br />
<br />
shell.open();<br />
<br />
while( !shell.isDisposed() ) {<br />
if( !display.readAndDispatch() )<br />
display.sleep();<br />
}<br />
<br />
glcanvas.dispose();<br />
display.dispose();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in SWT using the SWT-AWT bridge =<br />
<br />
The SWT-AWT bridge was created to allow SWT applications to use the AWT GLCanvas. You should use this if you have problems with the SWT GLCanvas. For example, the SWT GLCanvas doesn't currently support multisampling on Windows (see [https://bugs.eclipse.org/bugs/show_bug.cgi?id=136514 here] and [http://jogamp.762907.n3.nabble.com/New-tutorial-on-AWT-SWT-Swing-GLJPanel-GLCanvas-tp2363921p2366724.html here] for details).<br />
<br />
As with normal SWT, to compile this you'll need the swt.jar file for your platform which you can get [http://www.eclipse.org/swt/ here]. And just as with normal SWT, when running this code on Mac OS X, you'll need to give the <tt>-XstartOnFirstThread</tt> argument to the JVM.<br />
<br />
<pre><br />
import java.awt.Frame;<br />
<br />
import org.eclipse.swt.SWT;<br />
import org.eclipse.swt.awt.SWT_AWT;<br />
import org.eclipse.swt.layout.FillLayout;<br />
import org.eclipse.swt.widgets.Composite;<br />
import org.eclipse.swt.widgets.Display;<br />
import org.eclipse.swt.widgets.Shell;<br />
<br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.awt.GLCanvas;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an SWT Composite using an<br />
* embedded AWT Frame and the AWT GLCanvas via the SWT-AWT bridge.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSWTAWTBridge {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
Display display = new Display();<br />
final Shell shell = new Shell( display );<br />
shell.setText( "OneTriangle SWT AWT Bridge" );<br />
shell.setLayout( new FillLayout() );<br />
shell.setSize( 640, 480 );<br />
<br />
final Composite composite = new Composite( shell, SWT.EMBEDDED );<br />
composite.setLayout( new FillLayout() );<br />
<br />
Frame frame = SWT_AWT.new_Frame( composite );<br />
frame.add( glcanvas );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
shell.open();<br />
<br />
while( !shell.isDisposed() ) {<br />
if( !display.readAndDispatch() )<br />
display.sleep();<br />
}<br />
<br />
display.dispose();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in Swing =<br />
<br />
Swing is the primary Java window toolkit since Java 1.2 in 1997. It's based on AWT at a low level, but draws all its own controls instead of wrapping native controls. Here's how to use JOGL in Swing.<br />
<br />
<pre><br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLCanvas;<br />
import javax.swing.JFrame;<br />
<br />
import java.awt.BorderLayout;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in a Swing JFrame using the AWT GLCanvas.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSwingGLCanvas {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final JFrame jframe = new JFrame( "One Triangle Swing GLCanvas" ); <br />
jframe.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
jframe.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
jframe.getContentPane().add( glcanvas, BorderLayout.CENTER );<br />
jframe.setSize( 640, 480 );<br />
jframe.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in Swing using the GLJPanel =<br />
<br />
In cases where the AWT GLCanvas has problems integrating with Swing components correctly, you can use the GLJPanel instead. For example, JInternalFrames behave incorrectly when used with a GLCanvas -- you have to add JInternalFrames to the Frame that holds the GLCanvas, and when you drag the JInternalFrames around, the GLCanvas doesn't redraw properly underneath it.<br />
<br />
In contrast, GLJPanel is supposed integrate 100% correctly into Swing, but with lower performance due to extra copying of the frame buffer. Here's how to do it.<br />
<br />
<pre><br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLJPanel;<br />
import javax.swing.JFrame;<br />
<br />
import java.awt.BorderLayout;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in a Swing JFrame using the AWT GLJPanel.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSwingGLJPanel {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
GLJPanel gljpanel = new GLJPanel( glcapabilities ); <br />
<br />
gljpanel.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final JFrame jframe = new JFrame( "One Triangle Swing GLJPanel" ); <br />
jframe.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
jframe.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
jframe.getContentPane().add( gljpanel, BorderLayout.CENTER );<br />
jframe.setSize( 640, 480 );<br />
jframe.setVisible( true );<br />
}<br />
}<br />
</pre></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Using_JOGL_in_AWT_SWT_and_Swing&diff=1749Using JOGL in AWT SWT and Swing2015-07-03T20:56:26Z<p>Wwalker: Changed javax.media to com.jogamp</p>
<hr />
<div>You can use JOGL with three different Java window toolkits: AWT, SWT, and Swing. This page shows examples of all three toolkits, plus variations on two of them. The example program just draws one triangle that fills a resizable window.<br />
<br />
= How to choose a window toolkit =<br />
<br />
Usually the window toolkit you use for JOGL is dictated by your application. If you're writing an Eclipse-based application, it makes sense to use SWT, since it's the native windowing system of Eclipse. Otherwise, Swing is probably the way to go. If you want to wrap native controls instead of drawing in software like Swing, and you're not writing an Eclipse app, AWT is your best choice.<br />
<br />
= Base class =<br />
<br />
First, a base class that we'll use in all five examples. This class abstracts out all the pure OpenGL calls that don't depend on the choice of window toolkit.<br />
<br />
<pre><br />
import com.jogamp.opengl.GL;<br />
import com.jogamp.opengl.GL2;<br />
import com.jogamp.opengl.glu.GLU;<br />
<br />
public class OneTriangle {<br />
protected static void setup( GL2 gl2, int width, int height ) {<br />
gl2.glMatrixMode( GL2.GL_PROJECTION );<br />
gl2.glLoadIdentity();<br />
<br />
// coordinate system origin at lower left with width and height same as the window<br />
GLU glu = new GLU();<br />
glu.gluOrtho2D( 0.0f, width, 0.0f, height );<br />
<br />
gl2.glMatrixMode( GL2.GL_MODELVIEW );<br />
gl2.glLoadIdentity();<br />
<br />
gl2.glViewport( 0, 0, width, height );<br />
}<br />
<br />
protected static void render( GL2 gl2, int width, int height ) {<br />
gl2.glClear( GL.GL_COLOR_BUFFER_BIT );<br />
<br />
// draw a triangle filling the window<br />
gl2.glLoadIdentity();<br />
gl2.glBegin( GL.GL_TRIANGLES );<br />
gl2.glColor3f( 1, 0, 0 );<br />
gl2.glVertex2f( 0, 0 );<br />
gl2.glColor3f( 0, 1, 0 );<br />
gl2.glVertex2f( width, 0 );<br />
gl2.glColor3f( 0, 0, 1 );<br />
gl2.glVertex2f( width / 2, height );<br />
gl2.glEnd();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in AWT =<br />
<br />
The Abstract Window Toolkit (AWT) was Java's first window toolkit. It's a thin layer over each platform's native window toolkit. Here's how to use JOGL in AWT.<br />
<br />
<pre><br />
import com.jogamp.opengl.GLAutoDrawable;<br />
import com.jogamp.opengl.GLEventListener;<br />
import com.jogamp.opengl.GLProfile;<br />
import com.jogamp.opengl.GLCapabilities;<br />
import com.jogamp.opengl.awt.GLCanvas;<br />
<br />
import java.awt.Frame;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an AWT Frame.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleAWT {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final Frame frame = new Frame( "One Triangle AWT" );<br />
frame.add( glcanvas );<br />
frame.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
frame.remove( glcanvas );<br />
frame.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
frame.setSize( 640, 480 );<br />
frame.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in SWT =<br />
<br />
The [http://www.eclipse.org/swt/ Standard Widget Toolkit (SWT)] is a thin layer over each platform's native window toolkit. SWT is the toolkit used in Eclipse, so it makes sense to use SWT in Eclipse-based applications. To compile this, you'll need the swt.jar file for your platform which you can get [http://www.eclipse.org/swt/ here].<br />
<br />
When running this code on Mac OS X, you'll need to give the <tt>-XstartOnFirstThread</tt> argument to the JVM. This insures that the SWT windowing code sends and recieves messages on thread 0, which is required by Cocoa.<br />
<br />
<pre><br />
import org.eclipse.swt.SWT;<br />
import org.eclipse.swt.events.PaintEvent;<br />
import org.eclipse.swt.events.PaintListener;<br />
import org.eclipse.swt.graphics.Rectangle;<br />
import org.eclipse.swt.layout.FillLayout;<br />
import org.eclipse.swt.opengl.GLCanvas;<br />
import org.eclipse.swt.opengl.GLData;<br />
import org.eclipse.swt.widgets.Composite;<br />
import org.eclipse.swt.widgets.Display;<br />
import org.eclipse.swt.widgets.Event;<br />
import org.eclipse.swt.widgets.Listener;<br />
import org.eclipse.swt.widgets.Shell;<br />
<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLContext;<br />
import javax.media.opengl.GLDrawableFactory;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an SWT Composite.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSWT {<br />
<br />
public static void main( String [] args ) {<br />
Display display = new Display();<br />
final Shell shell = new Shell( display );<br />
shell.setText( "OneTriangle SWT" );<br />
shell.setLayout( new FillLayout() );<br />
shell.setSize( 640, 480 );<br />
<br />
final Composite composite = new Composite( shell, SWT.NONE );<br />
composite.setLayout( new FillLayout() );<br />
<br />
GLData gldata = new GLData();<br />
gldata.doubleBuffer = true;<br />
// need SWT.NO_BACKGROUND to prevent SWT from clearing the window<br />
// at the wrong times (we use glClear for this instead)<br />
final GLCanvas glcanvas = new GLCanvas( composite, SWT.NO_BACKGROUND, gldata );<br />
glcanvas.setCurrent();<br />
GLProfile glprofile = GLProfile.getDefault();<br />
final GLContext glcontext = GLDrawableFactory.getFactory( glprofile ).createExternalGLContext();<br />
<br />
// fix the viewport when the user resizes the window<br />
glcanvas.addListener( SWT.Resize, new Listener() {<br />
public void handleEvent(Event event) {<br />
Rectangle rectangle = glcanvas.getClientArea();<br />
glcanvas.setCurrent();<br />
glcontext.makeCurrent();<br />
OneTriangle.setup( glcontext.getGL().getGL2(), rectangle.width, rectangle.height );<br />
glcontext.release(); <br />
}<br />
});<br />
<br />
// draw the triangle when the OS tells us that any part of the window needs drawing<br />
glcanvas.addPaintListener( new PaintListener() {<br />
public void paintControl( PaintEvent paintevent ) {<br />
Rectangle rectangle = glcanvas.getClientArea();<br />
glcanvas.setCurrent();<br />
glcontext.makeCurrent();<br />
OneTriangle.render(glcontext.getGL().getGL2(), rectangle.width, rectangle.height);<br />
glcanvas.swapBuffers();<br />
glcontext.release(); <br />
}<br />
});<br />
<br />
shell.open();<br />
<br />
while( !shell.isDisposed() ) {<br />
if( !display.readAndDispatch() )<br />
display.sleep();<br />
}<br />
<br />
glcanvas.dispose();<br />
display.dispose();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in SWT using the SWT-AWT bridge =<br />
<br />
The SWT-AWT bridge was created to allow SWT applications to use the AWT GLCanvas. You should use this if you have problems with the SWT GLCanvas. For example, the SWT GLCanvas doesn't currently support multisampling on Windows (see [https://bugs.eclipse.org/bugs/show_bug.cgi?id=136514 here] and [http://jogamp.762907.n3.nabble.com/New-tutorial-on-AWT-SWT-Swing-GLJPanel-GLCanvas-tp2363921p2366724.html here] for details).<br />
<br />
As with normal SWT, to compile this you'll need the swt.jar file for your platform which you can get [http://www.eclipse.org/swt/ here]. And just as with normal SWT, when running this code on Mac OS X, you'll need to give the <tt>-XstartOnFirstThread</tt> argument to the JVM.<br />
<br />
<pre><br />
import java.awt.Frame;<br />
<br />
import org.eclipse.swt.SWT;<br />
import org.eclipse.swt.awt.SWT_AWT;<br />
import org.eclipse.swt.layout.FillLayout;<br />
import org.eclipse.swt.widgets.Composite;<br />
import org.eclipse.swt.widgets.Display;<br />
import org.eclipse.swt.widgets.Shell;<br />
<br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.awt.GLCanvas;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an SWT Composite using an<br />
* embedded AWT Frame and the AWT GLCanvas via the SWT-AWT bridge.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSWTAWTBridge {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
Display display = new Display();<br />
final Shell shell = new Shell( display );<br />
shell.setText( "OneTriangle SWT AWT Bridge" );<br />
shell.setLayout( new FillLayout() );<br />
shell.setSize( 640, 480 );<br />
<br />
final Composite composite = new Composite( shell, SWT.EMBEDDED );<br />
composite.setLayout( new FillLayout() );<br />
<br />
Frame frame = SWT_AWT.new_Frame( composite );<br />
frame.add( glcanvas );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
shell.open();<br />
<br />
while( !shell.isDisposed() ) {<br />
if( !display.readAndDispatch() )<br />
display.sleep();<br />
}<br />
<br />
display.dispose();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in Swing =<br />
<br />
Swing is the primary Java window toolkit since Java 1.2 in 1997. It's based on AWT at a low level, but draws all its own controls instead of wrapping native controls. Here's how to use JOGL in Swing.<br />
<br />
<pre><br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLCanvas;<br />
import javax.swing.JFrame;<br />
<br />
import java.awt.BorderLayout;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in a Swing JFrame using the AWT GLCanvas.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSwingGLCanvas {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final JFrame jframe = new JFrame( "One Triangle Swing GLCanvas" ); <br />
jframe.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
jframe.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
jframe.getContentPane().add( glcanvas, BorderLayout.CENTER );<br />
jframe.setSize( 640, 480 );<br />
jframe.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in Swing using the GLJPanel =<br />
<br />
In cases where the AWT GLCanvas has problems integrating with Swing components correctly, you can use the GLJPanel instead. For example, JInternalFrames behave incorrectly when used with a GLCanvas -- you have to add JInternalFrames to the Frame that holds the GLCanvas, and when you drag the JInternalFrames around, the GLCanvas doesn't redraw properly underneath it.<br />
<br />
In contrast, GLJPanel is supposed integrate 100% correctly into Swing, but with lower performance due to extra copying of the frame buffer. Here's how to do it.<br />
<br />
<pre><br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLJPanel;<br />
import javax.swing.JFrame;<br />
<br />
import java.awt.BorderLayout;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in a Swing JFrame using the AWT GLJPanel.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSwingGLJPanel {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
GLJPanel gljpanel = new GLJPanel( glcapabilities ); <br />
<br />
gljpanel.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final JFrame jframe = new JFrame( "One Triangle Swing GLJPanel" ); <br />
jframe.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
jframe.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
jframe.getContentPane().add( gljpanel, BorderLayout.CENTER );<br />
jframe.setSize( 640, 480 );<br />
jframe.setVisible( true );<br />
}<br />
}<br />
</pre></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Using_JOGL_in_AWT_SWT_and_Swing&diff=1748Using JOGL in AWT SWT and Swing2015-07-03T20:55:06Z<p>Wwalker: Changed javax.media to com.jogamp</p>
<hr />
<div>You can use JOGL with three different Java window toolkits: AWT, SWT, and Swing. This page shows examples of all three toolkits, plus variations on two of them. The example program just draws one triangle that fills a resizable window.<br />
<br />
= How to choose a window toolkit =<br />
<br />
Usually the window toolkit you use for JOGL is dictated by your application. If you're writing an Eclipse-based application, it makes sense to use SWT, since it's the native windowing system of Eclipse. Otherwise, Swing is probably the way to go. If you want to wrap native controls instead of drawing in software like Swing, and you're not writing an Eclipse app, AWT is your best choice.<br />
<br />
= Base class =<br />
<br />
First, a base class that we'll use in all five examples. This class abstracts out all the pure OpenGL calls that don't depend on the choice of window toolkit.<br />
<br />
<pre><br />
import com.jogamp.opengl.GL;<br />
import com.jogamp.opengl.GL2;<br />
import com.jogamp.opengl.glu.GLU;<br />
<br />
public class OneTriangle {<br />
protected static void setup( GL2 gl2, int width, int height ) {<br />
gl2.glMatrixMode( GL2.GL_PROJECTION );<br />
gl2.glLoadIdentity();<br />
<br />
// coordinate system origin at lower left with width and height same as the window<br />
GLU glu = new GLU();<br />
glu.gluOrtho2D( 0.0f, width, 0.0f, height );<br />
<br />
gl2.glMatrixMode( GL2.GL_MODELVIEW );<br />
gl2.glLoadIdentity();<br />
<br />
gl2.glViewport( 0, 0, width, height );<br />
}<br />
<br />
protected static void render( GL2 gl2, int width, int height ) {<br />
gl2.glClear( GL.GL_COLOR_BUFFER_BIT );<br />
<br />
// draw a triangle filling the window<br />
gl2.glLoadIdentity();<br />
gl2.glBegin( GL.GL_TRIANGLES );<br />
gl2.glColor3f( 1, 0, 0 );<br />
gl2.glVertex2f( 0, 0 );<br />
gl2.glColor3f( 0, 1, 0 );<br />
gl2.glVertex2f( width, 0 );<br />
gl2.glColor3f( 0, 0, 1 );<br />
gl2.glVertex2f( width / 2, height );<br />
gl2.glEnd();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in AWT =<br />
<br />
The Abstract Window Toolkit (AWT) was Java's first window toolkit. It's a thin layer over each platform's native window toolkit. Here's how to use JOGL in AWT.<br />
<br />
<pre><br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLCanvas;<br />
<br />
import java.awt.Frame;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an AWT Frame.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleAWT {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final Frame frame = new Frame( "One Triangle AWT" );<br />
frame.add( glcanvas );<br />
frame.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
frame.remove( glcanvas );<br />
frame.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
frame.setSize( 640, 480 );<br />
frame.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in SWT =<br />
<br />
The [http://www.eclipse.org/swt/ Standard Widget Toolkit (SWT)] is a thin layer over each platform's native window toolkit. SWT is the toolkit used in Eclipse, so it makes sense to use SWT in Eclipse-based applications. To compile this, you'll need the swt.jar file for your platform which you can get [http://www.eclipse.org/swt/ here].<br />
<br />
When running this code on Mac OS X, you'll need to give the <tt>-XstartOnFirstThread</tt> argument to the JVM. This insures that the SWT windowing code sends and recieves messages on thread 0, which is required by Cocoa.<br />
<br />
<pre><br />
import org.eclipse.swt.SWT;<br />
import org.eclipse.swt.events.PaintEvent;<br />
import org.eclipse.swt.events.PaintListener;<br />
import org.eclipse.swt.graphics.Rectangle;<br />
import org.eclipse.swt.layout.FillLayout;<br />
import org.eclipse.swt.opengl.GLCanvas;<br />
import org.eclipse.swt.opengl.GLData;<br />
import org.eclipse.swt.widgets.Composite;<br />
import org.eclipse.swt.widgets.Display;<br />
import org.eclipse.swt.widgets.Event;<br />
import org.eclipse.swt.widgets.Listener;<br />
import org.eclipse.swt.widgets.Shell;<br />
<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLContext;<br />
import javax.media.opengl.GLDrawableFactory;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an SWT Composite.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSWT {<br />
<br />
public static void main( String [] args ) {<br />
Display display = new Display();<br />
final Shell shell = new Shell( display );<br />
shell.setText( "OneTriangle SWT" );<br />
shell.setLayout( new FillLayout() );<br />
shell.setSize( 640, 480 );<br />
<br />
final Composite composite = new Composite( shell, SWT.NONE );<br />
composite.setLayout( new FillLayout() );<br />
<br />
GLData gldata = new GLData();<br />
gldata.doubleBuffer = true;<br />
// need SWT.NO_BACKGROUND to prevent SWT from clearing the window<br />
// at the wrong times (we use glClear for this instead)<br />
final GLCanvas glcanvas = new GLCanvas( composite, SWT.NO_BACKGROUND, gldata );<br />
glcanvas.setCurrent();<br />
GLProfile glprofile = GLProfile.getDefault();<br />
final GLContext glcontext = GLDrawableFactory.getFactory( glprofile ).createExternalGLContext();<br />
<br />
// fix the viewport when the user resizes the window<br />
glcanvas.addListener( SWT.Resize, new Listener() {<br />
public void handleEvent(Event event) {<br />
Rectangle rectangle = glcanvas.getClientArea();<br />
glcanvas.setCurrent();<br />
glcontext.makeCurrent();<br />
OneTriangle.setup( glcontext.getGL().getGL2(), rectangle.width, rectangle.height );<br />
glcontext.release(); <br />
}<br />
});<br />
<br />
// draw the triangle when the OS tells us that any part of the window needs drawing<br />
glcanvas.addPaintListener( new PaintListener() {<br />
public void paintControl( PaintEvent paintevent ) {<br />
Rectangle rectangle = glcanvas.getClientArea();<br />
glcanvas.setCurrent();<br />
glcontext.makeCurrent();<br />
OneTriangle.render(glcontext.getGL().getGL2(), rectangle.width, rectangle.height);<br />
glcanvas.swapBuffers();<br />
glcontext.release(); <br />
}<br />
});<br />
<br />
shell.open();<br />
<br />
while( !shell.isDisposed() ) {<br />
if( !display.readAndDispatch() )<br />
display.sleep();<br />
}<br />
<br />
glcanvas.dispose();<br />
display.dispose();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in SWT using the SWT-AWT bridge =<br />
<br />
The SWT-AWT bridge was created to allow SWT applications to use the AWT GLCanvas. You should use this if you have problems with the SWT GLCanvas. For example, the SWT GLCanvas doesn't currently support multisampling on Windows (see [https://bugs.eclipse.org/bugs/show_bug.cgi?id=136514 here] and [http://jogamp.762907.n3.nabble.com/New-tutorial-on-AWT-SWT-Swing-GLJPanel-GLCanvas-tp2363921p2366724.html here] for details).<br />
<br />
As with normal SWT, to compile this you'll need the swt.jar file for your platform which you can get [http://www.eclipse.org/swt/ here]. And just as with normal SWT, when running this code on Mac OS X, you'll need to give the <tt>-XstartOnFirstThread</tt> argument to the JVM.<br />
<br />
<pre><br />
import java.awt.Frame;<br />
<br />
import org.eclipse.swt.SWT;<br />
import org.eclipse.swt.awt.SWT_AWT;<br />
import org.eclipse.swt.layout.FillLayout;<br />
import org.eclipse.swt.widgets.Composite;<br />
import org.eclipse.swt.widgets.Display;<br />
import org.eclipse.swt.widgets.Shell;<br />
<br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.awt.GLCanvas;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an SWT Composite using an<br />
* embedded AWT Frame and the AWT GLCanvas via the SWT-AWT bridge.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSWTAWTBridge {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
Display display = new Display();<br />
final Shell shell = new Shell( display );<br />
shell.setText( "OneTriangle SWT AWT Bridge" );<br />
shell.setLayout( new FillLayout() );<br />
shell.setSize( 640, 480 );<br />
<br />
final Composite composite = new Composite( shell, SWT.EMBEDDED );<br />
composite.setLayout( new FillLayout() );<br />
<br />
Frame frame = SWT_AWT.new_Frame( composite );<br />
frame.add( glcanvas );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
shell.open();<br />
<br />
while( !shell.isDisposed() ) {<br />
if( !display.readAndDispatch() )<br />
display.sleep();<br />
}<br />
<br />
display.dispose();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in Swing =<br />
<br />
Swing is the primary Java window toolkit since Java 1.2 in 1997. It's based on AWT at a low level, but draws all its own controls instead of wrapping native controls. Here's how to use JOGL in Swing.<br />
<br />
<pre><br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLCanvas;<br />
import javax.swing.JFrame;<br />
<br />
import java.awt.BorderLayout;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in a Swing JFrame using the AWT GLCanvas.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSwingGLCanvas {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final JFrame jframe = new JFrame( "One Triangle Swing GLCanvas" ); <br />
jframe.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
jframe.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
jframe.getContentPane().add( glcanvas, BorderLayout.CENTER );<br />
jframe.setSize( 640, 480 );<br />
jframe.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in Swing using the GLJPanel =<br />
<br />
In cases where the AWT GLCanvas has problems integrating with Swing components correctly, you can use the GLJPanel instead. For example, JInternalFrames behave incorrectly when used with a GLCanvas -- you have to add JInternalFrames to the Frame that holds the GLCanvas, and when you drag the JInternalFrames around, the GLCanvas doesn't redraw properly underneath it.<br />
<br />
In contrast, GLJPanel is supposed integrate 100% correctly into Swing, but with lower performance due to extra copying of the frame buffer. Here's how to do it.<br />
<br />
<pre><br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLJPanel;<br />
import javax.swing.JFrame;<br />
<br />
import java.awt.BorderLayout;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in a Swing JFrame using the AWT GLJPanel.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSwingGLJPanel {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
GLJPanel gljpanel = new GLJPanel( glcapabilities ); <br />
<br />
gljpanel.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final JFrame jframe = new JFrame( "One Triangle Swing GLJPanel" ); <br />
jframe.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
jframe.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
jframe.getContentPane().add( gljpanel, BorderLayout.CENTER );<br />
jframe.setSize( 640, 480 );<br />
jframe.setVisible( true );<br />
}<br />
}<br />
</pre></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Using_JOGL_in_AWT_SWT_and_Swing&diff=1552Using JOGL in AWT SWT and Swing2014-08-30T17:51:39Z<p>Wwalker: Changed getWidth() and getHeight() to getSurfaceWidth() and getSurfaceHeight()</p>
<hr />
<div>You can use JOGL with three different Java window toolkits: AWT, SWT, and Swing. This page shows examples of all three toolkits, plus variations on two of them. The example program just draws one triangle that fills a resizable window.<br />
<br />
= How to choose a window toolkit =<br />
<br />
Usually the window toolkit you use for JOGL is dictated by your application. If you're writing an Eclipse-based application, it makes sense to use SWT, since it's the native windowing system of Eclipse. Otherwise, Swing is probably the way to go. If you want to wrap native controls instead of drawing in software like Swing, and you're not writing an Eclipse app, AWT is your best choice.<br />
<br />
= Base class =<br />
<br />
First, a base class that we'll use in all five examples. This class abstracts out all the pure OpenGL calls that don't depend on the choice of window toolkit.<br />
<br />
<pre><br />
import javax.media.opengl.GL;<br />
import javax.media.opengl.GL2;<br />
import javax.media.opengl.glu.GLU;<br />
<br />
public class OneTriangle {<br />
protected static void setup( GL2 gl2, int width, int height ) {<br />
gl2.glMatrixMode( GL2.GL_PROJECTION );<br />
gl2.glLoadIdentity();<br />
<br />
// coordinate system origin at lower left with width and height same as the window<br />
GLU glu = new GLU();<br />
glu.gluOrtho2D( 0.0f, width, 0.0f, height );<br />
<br />
gl2.glMatrixMode( GL2.GL_MODELVIEW );<br />
gl2.glLoadIdentity();<br />
<br />
gl2.glViewport( 0, 0, width, height );<br />
}<br />
<br />
protected static void render( GL2 gl2, int width, int height ) {<br />
gl2.glClear( GL.GL_COLOR_BUFFER_BIT );<br />
<br />
// draw a triangle filling the window<br />
gl2.glLoadIdentity();<br />
gl2.glBegin( GL.GL_TRIANGLES );<br />
gl2.glColor3f( 1, 0, 0 );<br />
gl2.glVertex2f( 0, 0 );<br />
gl2.glColor3f( 0, 1, 0 );<br />
gl2.glVertex2f( width, 0 );<br />
gl2.glColor3f( 0, 0, 1 );<br />
gl2.glVertex2f( width / 2, height );<br />
gl2.glEnd();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in AWT =<br />
<br />
The Abstract Window Toolkit (AWT) was Java's first window toolkit. It's a thin layer over each platform's native window toolkit. Here's how to use JOGL in AWT.<br />
<br />
<pre><br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLCanvas;<br />
<br />
import java.awt.Frame;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an AWT Frame.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleAWT {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final Frame frame = new Frame( "One Triangle AWT" );<br />
frame.add( glcanvas );<br />
frame.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
frame.remove( glcanvas );<br />
frame.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
frame.setSize( 640, 480 );<br />
frame.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in SWT =<br />
<br />
The [http://www.eclipse.org/swt/ Standard Widget Toolkit (SWT)] is a thin layer over each platform's native window toolkit. SWT is the toolkit used in Eclipse, so it makes sense to use SWT in Eclipse-based applications. To compile this, you'll need the swt.jar file for your platform which you can get [http://www.eclipse.org/swt/ here].<br />
<br />
When running this code on Mac OS X, you'll need to give the <tt>-XstartOnFirstThread</tt> argument to the JVM. This insures that the SWT windowing code sends and recieves messages on thread 0, which is required by Cocoa.<br />
<br />
<pre><br />
import org.eclipse.swt.SWT;<br />
import org.eclipse.swt.events.PaintEvent;<br />
import org.eclipse.swt.events.PaintListener;<br />
import org.eclipse.swt.graphics.Rectangle;<br />
import org.eclipse.swt.layout.FillLayout;<br />
import org.eclipse.swt.opengl.GLCanvas;<br />
import org.eclipse.swt.opengl.GLData;<br />
import org.eclipse.swt.widgets.Composite;<br />
import org.eclipse.swt.widgets.Display;<br />
import org.eclipse.swt.widgets.Event;<br />
import org.eclipse.swt.widgets.Listener;<br />
import org.eclipse.swt.widgets.Shell;<br />
<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLContext;<br />
import javax.media.opengl.GLDrawableFactory;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an SWT Composite.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSWT {<br />
<br />
public static void main( String [] args ) {<br />
Display display = new Display();<br />
final Shell shell = new Shell( display );<br />
shell.setText( "OneTriangle SWT" );<br />
shell.setLayout( new FillLayout() );<br />
shell.setSize( 640, 480 );<br />
<br />
final Composite composite = new Composite( shell, SWT.NONE );<br />
composite.setLayout( new FillLayout() );<br />
<br />
GLData gldata = new GLData();<br />
gldata.doubleBuffer = true;<br />
// need SWT.NO_BACKGROUND to prevent SWT from clearing the window<br />
// at the wrong times (we use glClear for this instead)<br />
final GLCanvas glcanvas = new GLCanvas( composite, SWT.NO_BACKGROUND, gldata );<br />
glcanvas.setCurrent();<br />
GLProfile glprofile = GLProfile.getDefault();<br />
final GLContext glcontext = GLDrawableFactory.getFactory( glprofile ).createExternalGLContext();<br />
<br />
// fix the viewport when the user resizes the window<br />
glcanvas.addListener( SWT.Resize, new Listener() {<br />
public void handleEvent(Event event) {<br />
Rectangle rectangle = glcanvas.getClientArea();<br />
glcanvas.setCurrent();<br />
glcontext.makeCurrent();<br />
OneTriangle.setup( glcontext.getGL().getGL2(), rectangle.width, rectangle.height );<br />
glcontext.release(); <br />
}<br />
});<br />
<br />
// draw the triangle when the OS tells us that any part of the window needs drawing<br />
glcanvas.addPaintListener( new PaintListener() {<br />
public void paintControl( PaintEvent paintevent ) {<br />
Rectangle rectangle = glcanvas.getClientArea();<br />
glcanvas.setCurrent();<br />
glcontext.makeCurrent();<br />
OneTriangle.render(glcontext.getGL().getGL2(), rectangle.width, rectangle.height);<br />
glcanvas.swapBuffers();<br />
glcontext.release(); <br />
}<br />
});<br />
<br />
shell.open();<br />
<br />
while( !shell.isDisposed() ) {<br />
if( !display.readAndDispatch() )<br />
display.sleep();<br />
}<br />
<br />
glcanvas.dispose();<br />
display.dispose();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in SWT using the SWT-AWT bridge =<br />
<br />
The SWT-AWT bridge was created to allow SWT applications to use the AWT GLCanvas. You should use this if you have problems with the SWT GLCanvas. For example, the SWT GLCanvas doesn't currently support multisampling on Windows (see [https://bugs.eclipse.org/bugs/show_bug.cgi?id=136514 here] and [http://jogamp.762907.n3.nabble.com/New-tutorial-on-AWT-SWT-Swing-GLJPanel-GLCanvas-tp2363921p2366724.html here] for details).<br />
<br />
As with normal SWT, to compile this you'll need the swt.jar file for your platform which you can get [http://www.eclipse.org/swt/ here]. And just as with normal SWT, when running this code on Mac OS X, you'll need to give the <tt>-XstartOnFirstThread</tt> argument to the JVM.<br />
<br />
<pre><br />
import java.awt.Frame;<br />
<br />
import org.eclipse.swt.SWT;<br />
import org.eclipse.swt.awt.SWT_AWT;<br />
import org.eclipse.swt.layout.FillLayout;<br />
import org.eclipse.swt.widgets.Composite;<br />
import org.eclipse.swt.widgets.Display;<br />
import org.eclipse.swt.widgets.Shell;<br />
<br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.awt.GLCanvas;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an SWT Composite using an<br />
* embedded AWT Frame and the AWT GLCanvas via the SWT-AWT bridge.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSWTAWTBridge {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
Display display = new Display();<br />
final Shell shell = new Shell( display );<br />
shell.setText( "OneTriangle SWT AWT Bridge" );<br />
shell.setLayout( new FillLayout() );<br />
shell.setSize( 640, 480 );<br />
<br />
final Composite composite = new Composite( shell, SWT.EMBEDDED );<br />
composite.setLayout( new FillLayout() );<br />
<br />
Frame frame = SWT_AWT.new_Frame( composite );<br />
frame.add( glcanvas );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
shell.open();<br />
<br />
while( !shell.isDisposed() ) {<br />
if( !display.readAndDispatch() )<br />
display.sleep();<br />
}<br />
<br />
display.dispose();<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in Swing =<br />
<br />
Swing is the primary Java window toolkit since Java 1.2 in 1997. It's based on AWT at a low level, but draws all its own controls instead of wrapping native controls. Here's how to use JOGL in Swing.<br />
<br />
<pre><br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLCanvas;<br />
import javax.swing.JFrame;<br />
<br />
import java.awt.BorderLayout;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in a Swing JFrame using the AWT GLCanvas.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSwingGLCanvas {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final JFrame jframe = new JFrame( "One Triangle Swing GLCanvas" ); <br />
jframe.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
jframe.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
jframe.getContentPane().add( glcanvas, BorderLayout.CENTER );<br />
jframe.setSize( 640, 480 );<br />
jframe.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= JOGL in Swing using the GLJPanel =<br />
<br />
In cases where the AWT GLCanvas has problems integrating with Swing components correctly, you can use the GLJPanel instead. For example, JInternalFrames behave incorrectly when used with a GLCanvas -- you have to add JInternalFrames to the Frame that holds the GLCanvas, and when you drag the JInternalFrames around, the GLCanvas doesn't redraw properly underneath it.<br />
<br />
In contrast, GLJPanel is supposed integrate 100% correctly into Swing, but with lower performance due to extra copying of the frame buffer. Here's how to do it.<br />
<br />
<pre><br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLJPanel;<br />
import javax.swing.JFrame;<br />
<br />
import java.awt.BorderLayout;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in a Swing JFrame using the AWT GLJPanel.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleSwingGLJPanel {<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
GLJPanel gljpanel = new GLJPanel( glcapabilities ); <br />
<br />
gljpanel.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() );<br />
}<br />
});<br />
<br />
final JFrame jframe = new JFrame( "One Triangle Swing GLJPanel" ); <br />
jframe.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
jframe.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
jframe.getContentPane().add( gljpanel, BorderLayout.CENTER );<br />
jframe.setSize( 640, 480 );<br />
jframe.setVisible( true );<br />
}<br />
}<br />
</pre></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Maintainer_and_Contacts&diff=1458Maintainer and Contacts2014-04-26T20:01:19Z<p>Wwalker: Removed JOCL from "open positions" list</p>
<hr />
<div>= Maintainer =<br />
<br />
* JogAmp IT Infrastructure, Architecture and Janitor<br />
** [[#Sven Gothel|Sven Gothel]]<br />
* Gluegen<br />
** [[#Sven Gothel|Sven Gothel]]<br />
** [[#Harvey Harrison|Harvey Harrison]]<br />
* JOAL<br />
** [[#Xerxes RÃ¥nby|Xerxes RÃ¥nby]]<br />
** [[#Sven Gothel|Sven Gothel]]<br />
* JOGL<br />
** [[#Sven Gothel|Sven Gothel]]<br />
** GPU Curve Rendering<br />
*** [[#Rami Santina|Rami Santina]]<br />
** SWT Support<br />
*** [[#Petros Koutsolampros|Petros Koutsolampros]]<br />
* Java3D<br />
** [[#Harvey Harrison|Harvey Harrison]]<br />
* JOCL<br />
** [[#Wade Walker|Wade Walker]]<br />
** [[#Sven Gothel|Sven Gothel]]<br />
* Engine Support<br />
** [[#Julien Gouesse|Julien Gouesse]]<br />
* Maven packages<br />
** [[#Mark Raynsford|Mark Raynsford]]<br />
* Art (graphics, demos, ..)<br />
** [[#Dominik Ströhlein|Dominik Ströhlein]]<br />
* ''Open Positions''<br />
** jogl-utils<br />
<br />
= Contacts =<br />
<br />
You can address the JogAmp Community via:<br />
* [http://jogamp.org/ Web]<br />
* [http://forum.jogamp.org/ Forum/Mailinglist]<br />
* [http://jogamp.org/wiki/index.php/Chatroom JogAmp IRC]<br />
* Email<br />
** mediastream [@] jogamp.org<br />
<br />
<br />
<div id="Contact_Maintainer"><br />
Please feel welcome to contact the maintainers for commercial support inquiries,<br />
specific questions you seem not fit for public discussions or to fund the work.<br />
</div><br />
<br />
== Sven Gothel ==<br />
* sgothel [@] jausoft.com<br />
* http://jausoft.com/blog/tag/jogl/<br />
* Contracting and funding<br />
** via ''Göthel Software e.K., contact jogamp [@] jausoft.com''<br />
** LTC LfuPJNftZhd6bRTHdfqnMppimhh654hjzK<br />
** BTC 12i2WscESWueXhpSWJebiyV6Ti4ChGDffw<br />
** micro payments [http://flattr.com/thing/1028522/JogAmp-Maintainer-Sven-Gothel via Flattr]<br />
===== Acknowledgment =====<br />
Göthel Software e.K. and I like to express our gratitude to <br />
[http://c3d.com/ CCT International], who is supporting this project since May 2010.<br />
<br />
== Julien Gouesse ==<br />
* gouessej [@] orange.fr<br />
* http://gouessej.wordpress.com/tag/jogl/<br />
<br />
== Harvey Harrison ==<br />
* harvey.harrison [@] gmail.com<br />
* https://github.com/hharrison<br />
<br />
== Petros Koutsolampros ==<br />
* http://orange-vertex.net/<br />
<br />
== Xerxes RÃ¥nby ==<br />
* xerxes [@] gudinna.com<br />
* http://labb.zafena.se/?category_name=jogamp<br />
* http://twitter.com/xranby<br />
** Micro payments via flatter: http://flattr.com/thing/1074999/JogAmp-JOAL-Maintainer-Xerxes-Rnby<br />
<br />
== Mark Raynsford ==<br />
* http://io7m.com/<br />
<br />
== Rami Santina ==<br />
* http://ramisantina.com/blog/<br />
<br />
== Dominik Ströhlein ==<br />
* http://copypastaresearch.tumblr.com/<br />
<br />
== Wade Walker ==<br />
* http://wadeawalker.wordpress.com/<br />
<br />
<br />
= Support =<br />
<br />
We are confident to make your JogAmp experience a successful story.<br />
<br />
If you have commercial support requests or like to fund our work<br><br />
please feel free to contact the module maintainer [[#Contact_Maintainer|as listed above]].</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Jogamp_SCM_Repositories&diff=1457Jogamp SCM Repositories2014-04-26T19:47:20Z<p>Wwalker: Update JOCL maintainer</p>
<hr />
<div>Modules:<br />
* applet-launcher.git<br />
* gluegen<br />
* jogl<br />
* jogl-demos<br />
* jocl<br />
* jocl-demos<br />
* joal<br />
* joal-demos<br />
<br />
<br />
Developer and hence master repos:<br />
* https://github.com/sgothel/<br />
** applet-launcher.git<br />
** gluegen<br />
** joal<br />
** joal-demos<br />
** jogl<br />
** jogl-demos<br />
* https://github.com/WadeWalker<br />
** jocl<br />
** jocl-demos<br />
* https://github.com/rsantina/<br />
* https://github.com/snmvaughan/<br />
<br />
<br />
Staging and release repos:<br />
* http://jogamp.org/git/<br />
** <pre>git clone git://jogamp.com/srv/scm/<module>.git <module></pre><br />
** <pre>git clone http://jogamp.org/git/<module>.git <module></pre><br />
* http://jausoft.com/git/<br />
** <pre>git clone git://jausoft.com/srv/scm/<module>.git <module></pre><br />
** <pre>git clone http://jausoft.com/git/<module>.git <module></pre></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=SW_Tracking_Report_Objectives_for_the_release_2.1.5&diff=1446SW Tracking Report Objectives for the release 2.1.52014-03-10T20:26:10Z<p>Wwalker: Put bugs in correct list</p>
<hr />
<div>= Bugs =<br />
<br />
List started on 2014-02-01, concluding [[SW Tracking Report Objectives for the release 2.1.4|Release 2.1.4]] - '''Open''' - continuation @ [[SW Tracking Report Objectives for the release 2.2.0|Release 2.2.0]].<br />
<br />
This is a bugfix and enhancement release..<br />
<br />
* [{{SERVER}}/bugzilla/buglist.cgi?chfield=bug_status&chfieldfrom=2014-02-01&chfieldto=2014-02-21&chfieldvalue=RESOLVED&classification=Unclassified&classification=JogAmp_Core&query_format=advanced&resolution=---&resolution=FIXED&resolution=INVALID&resolution=WONTFIX&resolution=DUPLICATE&resolution=WORKSFORME&resolution=MOVED&title=Bug%20List:%20Progress_2_1_5 Closed bugs 2.1.5] [{{SERVER}}/bugzilla/buglist.cgi?chfield=bug_status&chfieldfrom=2014-02-01&chfieldto=2014-02-21&chfieldvalue=RESOLVED&classification=Unclassified&classification=JogAmp_Core&query_format=advanced&resolution=---&resolution=FIXED&resolution=INVALID&resolution=WONTFIX&resolution=DUPLICATE&resolution=WORKSFORME&resolution=MOVED&title=Bug%20List:%20Progress_2_1_5&ctype=atom RSS Feed]<br />
<br />
== Bugs already fixed for this release ==<br />
<br />
{{#bugzilla:<br />
|disablecache=1<br />
|status=resolved,verified<br />
|id=684,927,958,962,970,972,974,975,980,984,987,990,991,992<br />
|columns=id,priority,status,severity,component,summary,votes<br />
|sort=id<br />
|order=desc<br />
|noresultsmessage=Lazy devs}}<br />
<br />
== JOCL Bugs already fixed for this release ===<br />
<br />
{{#bugzilla:<br />
|disablecache=1<br />
|status=resolved,verified<br />
|id=920,959,960,963,964,978,979,981<br />
|columns=id,priority,status,severity,component,summary,votes<br />
|sort=id<br />
|order=desc<br />
|noresultsmessage=Lazy devs}}<br />
<br />
== Bugs to fix for this release w/ low effort (root causes clearly identified, reporter available) ==<br />
<br />
{{#bugzilla:<br />
|disablecache=1<br />
|status=unconfirmed,in_progress,confirmed<br />
|id=684,927,980,984<br />
|columns=id,priority,status,severity,component,summary,votes<br />
|sort=id<br />
|order=desc<br />
|noresultsmessage=We have no bugs quickly fixable to fix for this release}}</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=SW_Tracking_Report_Objectives_for_the_release_2.1.5&diff=1445SW Tracking Report Objectives for the release 2.1.52014-03-10T20:25:07Z<p>Wwalker: Added three gluegen warning removal bugs to the list</p>
<hr />
<div>= Bugs =<br />
<br />
List started on 2014-02-01, concluding [[SW Tracking Report Objectives for the release 2.1.4|Release 2.1.4]] - '''Open''' - continuation @ [[SW Tracking Report Objectives for the release 2.2.0|Release 2.2.0]].<br />
<br />
This is a bugfix and enhancement release..<br />
<br />
* [{{SERVER}}/bugzilla/buglist.cgi?chfield=bug_status&chfieldfrom=2014-02-01&chfieldto=2014-02-21&chfieldvalue=RESOLVED&classification=Unclassified&classification=JogAmp_Core&query_format=advanced&resolution=---&resolution=FIXED&resolution=INVALID&resolution=WONTFIX&resolution=DUPLICATE&resolution=WORKSFORME&resolution=MOVED&title=Bug%20List:%20Progress_2_1_5 Closed bugs 2.1.5] [{{SERVER}}/bugzilla/buglist.cgi?chfield=bug_status&chfieldfrom=2014-02-01&chfieldto=2014-02-21&chfieldvalue=RESOLVED&classification=Unclassified&classification=JogAmp_Core&query_format=advanced&resolution=---&resolution=FIXED&resolution=INVALID&resolution=WONTFIX&resolution=DUPLICATE&resolution=WORKSFORME&resolution=MOVED&title=Bug%20List:%20Progress_2_1_5&ctype=atom RSS Feed]<br />
<br />
== Bugs already fixed for this release ==<br />
<br />
{{#bugzilla:<br />
|disablecache=1<br />
|status=resolved,verified<br />
|id=684,927,958,962,970,972,974,975,980,984,991<br />
|columns=id,priority,status,severity,component,summary,votes<br />
|sort=id<br />
|order=desc<br />
|noresultsmessage=Lazy devs}}<br />
<br />
== JOCL Bugs already fixed for this release ===<br />
<br />
{{#bugzilla:<br />
|disablecache=1<br />
|status=resolved,verified<br />
|id=920,959,960,963,964,978,979,981,987,990,992<br />
|columns=id,priority,status,severity,component,summary,votes<br />
|sort=id<br />
|order=desc<br />
|noresultsmessage=Lazy devs}}<br />
<br />
== Bugs to fix for this release w/ low effort (root causes clearly identified, reporter available) ==<br />
<br />
{{#bugzilla:<br />
|disablecache=1<br />
|status=unconfirmed,in_progress,confirmed<br />
|id=684,927,980,984<br />
|columns=id,priority,status,severity,component,summary,votes<br />
|sort=id<br />
|order=desc<br />
|noresultsmessage=We have no bugs quickly fixable to fix for this release}}</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=File:IntelliJ_setup_04_external_library.png&diff=1360File:IntelliJ setup 04 external library.png2014-01-12T16:24:52Z<p>Wwalker: uploaded a new version of "File:IntelliJ setup 04 external library.png":&#32;Changed jogl.all.jar to jogl-all.jar</p>
<hr />
<div></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=File:IntelliJ_setup_04_external_library_native_JARs.png&diff=1359File:IntelliJ setup 04 external library native JARs.png2014-01-12T16:23:05Z<p>Wwalker: uploaded a new version of "File:IntelliJ setup 04 external library native JARs.png":&#32;Changed jogl.all.jar to jogl-all.jar</p>
<hr />
<div></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=File:NetBeans_setup_03_libraries_in_project.png&diff=1358File:NetBeans setup 03 libraries in project.png2014-01-12T16:18:33Z<p>Wwalker: uploaded a new version of "File:NetBeans setup 03 libraries in project.png":&#32;Changed jogl.all.jar to jogl-all.jar</p>
<hr />
<div>Picture for NetBeans project setup instructions</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Setting_up_a_JogAmp_project_in_your_favorite_IDE&diff=1357Setting up a JogAmp project in your favorite IDE2014-01-12T16:12:24Z<p>Wwalker: Added picture for removal of native JARs</p>
<hr />
<div>__TOC__<br />
<br />
These instructions assume that you've created a project in your favorite IDE, and now you want your project to be able to use a JogAmp library like JOGL, JOCL, JOAL, or GlueGen. We use JOGL as an example below, but these instructions work equally well for any other JogAmp library.<br />
<br />
= Download a JogAmp library =<br />
<br />
If you haven't done so already, download and extract the JogAmp library you want to use. For example, to download and extract JOGL, see the instructions at [[Downloading and installing JOGL]].<br />
<br />
To use a JogAmp library you'll do three things:<br />
<br />
* Add its JAR files to the Java classpath<br />
* Add its native libraries in one of two ways:<br />
** Either place its native JAR files in the same directory as the library JAR files<br />
** Or add its native library files(the <tt>.dll</tt>,<tt>.so</tt>, and <tt>.jnilib</tt> files) to the Java library path<br />
* Optional: Associate the *-java-src.zip files with the corresponding JAR files.<br />
<br />
Each IDE has a slightly different way to do these things, as we show below. Using the native JAR files is usually slightly easier than using the native library files directly, and native JARs make it possible for all platforms' libraries to coexist in one project, so this is the recommended method.<br />
<br />
Please note that all JogAmp libraries depend on the GlueGen runtime libraries. These are included in every JogAmp library for convenience, but are only required once in the classpath and library path of your project.<br />
<br />
See [[JogAmp JAR File Handling|JogAmp JAR File Handling]], for details on native JAR files and custom JAR bundling.<br />
<br />
= Eclipse IDE project =<br />
<br />
Probably the simplest way to use JOGL in an Eclipse project is to create another Eclipse project to contain the JOGL JARs, then make your project depend on this new JOGL project. In the example below, I include only the 64-bit Windows native JARs, but you can put native JARs for as many platforms as you wish together into the JOGL Eclipse project.<br />
<br />
=== Create a JOGL project ===<br />
<br />
* Put all the JOGL code JARs, native JARs for all platforms you wish to support, and source ZIP files in a directory called "JOGL" in your workspace directory.<br />
* Click "File > New > Java Project". Type "JOGL" as the project name and click "Next".<br />
[[File:Eclipse_project_setup_01_create_project.png|300px|thumb|none|Create JOGL project]]<br />
* Remove the native JARs from the project, leaving only gluegen-rt.jar and jogl-all.jar.<br />
[[File:Eclipse_project_setup_02_remove_native_JARs.png|300px|thumb|none|Remove native JARs]]<br />
NOTE: The gluegen-rt-natives-*-*.jar and jogl-all-natives-*-*.jar are not<br />
required in the classpath by JOGL, but are required by Eclipse to export<br />
your project as a runnable JAR file.<br />
* Expand the jogl-all and gluegen-rt JARs. For each of them, double-click "Source attachment", click "Workspace...", navigate to the corresponding <tt>*-java-src.zip</tt> file in the project, select it, click "OK", and click "OK" again to dismiss the "Source Attachment Configuration" dialog. The JARs should look like this when you're done:<br />
[[File:Eclipse_project_setup_03_JARs_with_source_attached.png|300px|thumb|none|Attach source to JARs]]<br />
* Click the "Order and Export" tab. Check both JOGL JARs, then click "Finish".<br />
[[File:Eclipse_project_setup_04_order_and_export.png|300px|thumb|none|Exporting JOGL JARs]]<br />
<br />
=== Add dependency on the JOGL project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select the "Java Build Path" on the left, then click the "Projects" tab on the right.<br />
* Click the "Add..." button, check "JOGL", and click "OK".<br />
* Your dependent project should look like this. Click "OK" to dismiss the "Properties" dialog.<br />
[[File:Eclipse_project_setup_05_project_dependency.png|300px|thumb|none|JOGL project dependency]]<br />
<br />
That's it! Your project can now use the library.<br />
<br />
= Eclipse IDE user library =<br />
<br />
If you don't want to put JOGL in a separate Eclipse project, you can put it in a user library instead. The drawback to this is that the user library is defined in your .metadata directory and contains absolute paths, so it's hard to share with others. But for a non-shared project this works fine.<br />
<br />
=== Create a user library ===<br />
<br />
* Click "Window > Preferences", then select "Java > Build Path > User Libraries" on the left.<br />
* Click the "New..." button, type "JOGL" for the library name, and click "OK".<br />
[[File:Eclipse_setup_01_create_user_library.png|300px|thumb|none|Create user library]]<br />
* Click the "Add JARs..." button, navigate to the directory where you've stored the JARs, select all the non-native JARs, then click "Open".<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Expand each non-native JAR in the list<br />
** Double-click "Source attachment", type the module's source zip name, (e.g. <tt>jogl-java-src.zip</tt> for the JAR file <tt>jogl-all.jar</tt>), and click "OK".<br />
** If you're using native library files:<br />
*** Double-click "Native library location", type the directory where native library files are stored, and click "OK".<br />
[[File:Eclipse_setup_02_set_native_library_locations.png|300px|thumb|none|Set native library locations]]<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
=== Add the user library to your project's dependencies ===<br />
<br />
* Right-click your project in the Package Explorer and click "Properties".<br />
* Select "Java Build Path" and click the "Libraries" tab.<br />
[[File:Eclipse_setup_03_add_library_to_project.png|300px|thumb|none|Add library to project]]<br />
* Click "Add Library...", select "User Library", click "Next", check "JOGL", and click "Finish".<br />
[[File:Eclipse_setup_04_add_JOGL_library_to_project.png|300px|thumb|none|Add JOGL library to project]]<br />
* Click "OK" to dismiss the Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= IntelliJ IDEA =<br />
=== Add a library dependency to your project ===<br />
<br />
* Click "File > Project Structure".<br />
* Select "Modules" on the left, then click the "Dependencies" tab on the right.<br />
* Click the "+" button on the right, then select "Library... > Java".<br />
[[File:IntelliJ_setup_01_add_library.png|300px|thumb|none|Add library]]<br />
* Navigate to the directory where you extracted the JARs, select it, and click "OK".<br />
[[File:IntelliJ_setup_02_find_library.png|300px|thumb|none|Find library]]<br />
* Click "OK" to dismiss the Configure Library dialog.<br />
[[File:IntelliJ_setup_03_configure_library.png|300px|thumb|none|Configure library]]<br />
* Click "OK" to dismiss the Project Structure dialog. The external libraries in your project should now look like this if you're using native JAR files:<br />
[[File:IntelliJ_setup_04_external_library_native_JARs.png|300px|thumb|none|Native JARs]]<br />
or like this if you're using native library files:<br />
[[File:IntelliJ_setup_04_external_library.png|300px|thumb|none|Native library files]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Edit Configurations".<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Parameters" box. Note that paths with spaces must be double-quoted on Windows.<br />
[[File:IntelliJ_setup_05_run_configuration.png|300px|thumb|none|Edit run configuration]]<br />
** Click "OK" to dismiss the Run/Debug Configurations dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= NetBeans IDE = <br />
=== Create a library and add it to your project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select "Libraries" on the left and click "Add Library...".<br />
* Click the "Create" button, then type "JOGL" for the library name and click "OK".[[File:NetBeans_setup_01_create_library.png|300px|thumb|none|Create library]]<br />
* Click "Add JAR/Folder...", then navigate to the directory you extracted the JAR files, select them and click "Add JAR/Folder".<br />
* Click "OK" to dismiss the Customize Library dialog.<br />
* Click "Add Library" to dismiss the Add Library dialog.[[File:NetBeans_setup_02_add_library.png|300px|thumb|none|Add library]]<br />
* Click "OK" to dismiss the Project Properties dialog. The libraries in your project should look like this.[[File:NetBeans_setup_03_libraries_in_project.png|300px|thumb|none|Libraries in project]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Set Project Configuration > Customize...". Select "Run" on the left if it isn't selected already.<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Options" box.<br />
** NOTE: If the library path has spaces in it, you must put quotes around it (at least on Windows) or you may get an odd NoClassDefFoundError when you try to run.[[File:NetBeans_setup_04_native_library_path.png|300px|thumb|none|Native library path]]<br />
** Click "OK" to dismiss the Project Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= Maven =<br />
<br />
Since <tt>2.0-rc11</tt>, packages for all the JogAmp projects have been pushed to<br />
[http://search.maven.org/#search|ga|1|jogamp Maven Central]. Please see the<br />
[[Maven]] page for details on how to use them in your projects.<br />
<br />
= vi and other text editors =<br />
=== Create your project with the editor of your choice ===<br />
* For example, to open vi, simply type <tt>vi</tt> and press <return>.<br />
* Type all your code, then save it.<br />
<br />
=== Compile and run your project from the command line ===<br />
* We assume your JOGL JAR files are in a directory called <tt>jar</tt>. If you're using native JARs, we assume they're also in the <tt>jar</tt> directory. If you're using native library files, we assume they're in a directory called <tt>lib</tt>.<br />
<br />
* First compile your program. We assume all your code is in a single file called <tt>name/someone/MyProject.java</tt>.<br />
** Windows: Type <tt>javac -classpath "jar\gluegen-rt.jar;jar\jogl-all.jar" name\someone\MyProject.java</tt><br />
** Linux/MacOS X: Type <tt>javac -classpath "jar/gluegen-rt.jar:jar/jogl-all.jar" name/someone/MyProject.java</tt><br />
<br />
* Then run your project. We assume your main class is <tt>name.someone.MyProject</tt>. If you're using native JARs:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl-all.jar;." name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl-all.jar:." name.someone.MyProject</tt><br />
* If you're using native library files:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl-all.jar;." -Djava.library.path=lib name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl-all.jar:." -Djava.library.path=lib name.someone.MyProject</tt><br />
<br />
That's it! You can now use the library in your project.</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=File:Eclipse_project_setup_05_project_dependency.png&diff=1356File:Eclipse project setup 05 project dependency.png2014-01-12T16:08:02Z<p>Wwalker: uploaded a new version of "File:Eclipse project setup 05 project dependency.png":&#32;Updated to change jogl.all.jar to jogl-all.jar (also updated to Windows 8 and Eclipse 3.8 screenshot).</p>
<hr />
<div></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=File:Eclipse_project_setup_04_order_and_export.png&diff=1355File:Eclipse project setup 04 order and export.png2014-01-12T16:07:41Z<p>Wwalker: uploaded a new version of "File:Eclipse project setup 04 order and export.png":&#32;Updated to change jogl.all.jar to jogl-all.jar (also updated to Windows 8 and Eclipse 3.8 screenshot).</p>
<hr />
<div></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=File:Eclipse_project_setup_03_JARs_with_source_attached.png&diff=1354File:Eclipse project setup 03 JARs with source attached.png2014-01-12T16:07:09Z<p>Wwalker: uploaded a new version of "File:Eclipse project setup 03 JARs with source attached.png"</p>
<hr />
<div></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=File:Eclipse_project_setup_02_remove_native_JARs.png&diff=1353File:Eclipse project setup 02 remove native JARs.png2014-01-12T16:06:46Z<p>Wwalker: uploaded a new version of "File:Eclipse project setup 02 remove native JARs.png":&#32;Updated to change jogl.all.jar to jogl-all.jar (also updated to Windows 8 and Eclipse 3.8 screenshot).</p>
<hr />
<div></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=File:Eclipse_project_setup_01_create_project.png&diff=1352File:Eclipse project setup 01 create project.png2014-01-12T16:05:22Z<p>Wwalker: uploaded a new version of "File:Eclipse project setup 01 create project.png":&#32;Updated to change jogl.all.jar to jogl-all.jar (also updated to Windows 8 and Eclipse 3.8 screenshot).</p>
<hr />
<div></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Building_JOGL_on_the_command_line&diff=903Building JOGL on the command line2013-04-13T20:25:38Z<p>Wwalker: Fixed instructions for 64-bit Windows MinGW</p>
<hr />
<div>= Overview =<br />
<br />
To build JOGL on the command line, we'll need to install prerequisites like Ant, pull the code from a Git repository, and run the Ant build scripts.<br />
<br />
= Supported platforms =<br />
<br />
Currently we support building JOGL on Linux (x86 32- and 64-bit), Windows XP/Vista/7 (32- and 64-bit) and Mac OS X (x86 32- and 64-bit). Additional platforms like Solaris/OpenSolaris, FreeBSD and HP/UX are handled by the build system, but are not officially supported.<br />
<br />
= Install a JDK =<br />
<br />
The first thing we need is a Java Development Kit (JDK). JOGL will work with [http://openjdk.java.net/ OpenJDK] and [http://icedtea.classpath.org/ IcedTea], but here we use Oracle's and Apple's JDKs as examples.<br />
<br />
* Check if you have a JDK<br />
** You must use a JDK, not a JRE, because Ant needs <tt>bin/javac</tt>, which doesn't come in the JRE. On Windows and Linux, Ant also needs <tt>lib/tools.jar</tt>, which doesn't come in the JRE.<br />
** On Windows and Linux, if you've got some kind of Java installed, but you're not sure whether it's a JDK or a Java Runtime Environment (JRE), look inside the directory. If it's got a <tt>jre</tt> subdirectory inside, it's a JDK. A JRE contains only <tt>bin</tt> and <tt>lib</tt> directories.<br />
** On Mac OS X, Apple's JDK 6 may be included with the operating system, depending on what version you're running. It would be at <tt>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk</tt>. If you want to use Java 7, you'll need to install that yourself (see below).<br />
* Get a JDK if needed<br />
** On Windows and Linux, download the JDK from at http://www.oracle.com/technetwork/java/javase/downloads/index.html. Make sure you get Java SE 6 update 24 or later. You can install the JDK wherever you like.<br />
** On Mac OS X, for Java 7 and later, you can download it from http://www.oracle.com/technetwork/java/javase/downloads/index.html just like on Windows and Linux. If you're using Apple's JDK 6, click "Apple menu > Software update..." to update Apple's JDK.<br />
* Add the JDK's <tt>bin</tt> directory to your path.<br />
** On Windows, append <tt>;your JDK\bin</tt> to your Path environment variable.<br />
** On Linux, append <tt>:your JDK/bin</tt> to your PATH environment variable.<br />
** On Mac OS X, prepend <tt>/Library/Java/JavaVirtualMachines/jdk1.7.x_x.jdk/Contents/Home/bin:</tt> (or <tt>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin:</tt> for Apple's JDK 6) to your PATH environment variable.<br />
* Set the <tt>JAVA_HOME</tt> environment variable<br />
** On Windows and Linux, set the <tt>JAVA_HOME</tt> environment variable to your JDK path.<br />
** On Mac OS X, set <tt>JAVA_HOME</tt> to <tt>/Library/Java/JavaVirtualMachines/jdk1.7.x_x.jdk/Contents/Home</tt> (or <tt>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home</tt> for Apple's JDK 6).<br />
* Test your JDK by opening a shell and typing <tt>java -version</tt> and <tt>javac -version</tt><br />
<br />
If you're using an existing JDK instead of installing a new one, make sure you don't have any JOGL or ANTLR JARs in its extension directory. This can cause strange build or runtime problems.<br />
* On Windows and Linux, delete any JOGL or ANTLR JARs from <tt>jre/lib/ext</tt><br />
* On Mac OS X, delete any JOGL or ANTLR JARs from <tt>/Library/Java/Extensions</tt> and <tt>~/Library/Java/Extensions</tt><br />
<br />
= Install Ant =<br />
<br />
If you don't already have Ant installed, or your version is older than 1.8, you'll need to install a new version of Ant.<br />
<br />
* Download Ant 1.8 or later from http://ant.apache.org/bindownload.cgi.<br />
** For example, download the file apache-ant-1.8.2-bin.zip and unzip it to your desired installation directory.<br />
* Set your <tt>ANT_HOME</tt> environment variable to the new installation directory.<br />
* Add Ant executables to your path<br />
** On Windows, append <tt>;your Ant dir\bin</tt> to your Path environment variable.<br />
** On Linux, append <tt>:your Ant dir/bin</tt> to your PATH environment variable.<br />
** On Mac OS X, prepend <tt>your Ant dir/bin:</tt> to your PATH environment variable.<br />
* Test your Ant installation by opening a shell and typing <tt>ant -version</tt><br />
** If you have problems, more detailed installation instructions are at http://ant.apache.org/manual/index.html.<br />
<br />
= Unset the classpath =<br />
<br />
Unset the CLASSPATH environment variable if it exists. Having this set with random JARs on it is one of the main causes of build problems.<br />
<br />
* On Windows, remove it from the list of environment variables in "My Computer > Properties > Advanced > Environment Variables > System Variables".<br />
* On Linux, remove it from your <tt>.cshrc</tt> or equivalent shell setup file.<br />
* On Mac OS X, remove it from your <tt>.bash_profile</tt> or equivalent shell setup file.<br />
<br />
= Install Git =<br />
<br />
The JOGL project uses Git for source code management and collaboration. If you don't already have it, you'll need to install Git 1.6.0 or later.<br />
<br />
* On Windows<br />
** Go to http://code.google.com/p/msysgit/downloads/list.<br />
** Click the download link for an installer (for example <tt>Git-1.7.7.1-preview20111027.exe</tt>), then run it.<br />
** Choose "Run Git from the Windows Command Prompt" during the install process.<br />
* On Linux and Solaris<br />
** Download in your preferred format from http://git-scm.com/download.<br />
* On Mac OS X<br />
** Go to http://code.google.com/p/git-osx-installer/downloads/list.<br />
** Click the download link for an installer (for example <tt>git-1.7.7-intel-universal-snow-leopard.dmg</tt>). Once it's downloaded, click "Downloads > git-1.7.7-intel-universal-snow-leopard.dmg" to open it.<br />
** Double-click the icon for <tt>git-1.7.7-intel-universal-snow-leopard.pkg</tt> and follow the instructions to install it.<br />
** Prepend <tt>/usr/local/git/bin:</tt> to your PATH environment variable.<br />
* Test your Git installation by opening a new shell and typing <tt>git --version</tt><br />
<br />
= Install MinGW (Windows only) =<br />
<br />
For the JOGL build scripts to run on Windows, you'll need Minimalist GNU for Windows (MinGW) so you can use the GCC compiler.<br />
<br />
* Create a <tt>C:\MinGW</tt> directory.<br />
* Append <tt>;C:\MinGW\bin</tt> to the end of your Path environment variable.<br />
* 32-bit Windows: Download the installer from http://sourceforge.net/projects/mingw/files/Installer/mingw-get/ into the new MinGW directory.<br />
** For example, version mingw-get-0.5-beta-20120426-1 is in a file called <tt>mingw-get-0.5-mingw32-beta-20120426-1-bin.zip</tt><br />
** Unzip the file.<br />
*** The <tt>bin</tt>, <tt>libexec</tt>, and <tt>var</tt> directories should be directly inside <tt>C:\MinGW</tt><br />
** Open new shell and type <tt>mingw-get install gcc</tt><br />
*** This may take a few minutes to download and install the rest of 32-bit gcc.<br />
* 64-bit Windows: Download the zipped installation from http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/ into the new MinGW directory.<br />
** For example, version sezero_4.5_20111101 is in a file called <tt>mingw-w64-bin_x86_64-mingw_20111101_sezero.zip</tt><br />
** Unzip the file.<br />
** The <tt>bin</tt>, <tt>libexec</tt>, <tt>lib64</tt>, and other directories should be directly inside <tt>C:\MinGW</tt><br />
** No further installation is needed for the 64-bit version.<br />
* Test your MinGW installation by opening a new shell and typing <tt>gcc --version</tt><br />
<br />
= Check and install developer packages (Linux and Solaris only) =<br />
<br />
Depending on your Linux or Solaris flavor and version, you may need to install some developer packages to build JOGL. See the [[Required developer packages|list of developer packages for each operating system distribution]] to check if you're missing one.<br />
<br />
= Install Xcode (Mac OS X only) =<br />
<br />
The easiest way to set up GCC on Mac OS X is to install Xcode 4. It's a cheap download from the Mac App Store. Once you've installed it, open a new shell and type <tt>gcc --version</tt> to make sure GCC is available.<br />
<br />
= Pull the JOGL source code from GitHub or JogAmp =<br />
<br />
You'll need to get the source code for two projects, gluegen and jogl. The simple way to get it is by cloning the canonical repository.<br />
<br />
* Open a shell and cd to where you want the code to go.<br />
* Type <tt>git clone git://github.com/sgothel/gluegen.git gluegen</tt> and wait for the code to download.<br />
* Type <tt>git clone git://github.com/sgothel/jogl.git jogl</tt> and wait for the code to download.<br />
<br />
If you wish, you can clone from <tt>git://jogamp.com/srv/scm</tt> instead of <tt>git://github.com/sgothel</tt>. The contents of the two repositories should be the same.<br />
<br />
If you're going to be contributing fixes or doing development, you'll need to check out from your own GitHub account. The instructions at [[Contributing a new feature or fix|"Contributing a new feature or fix"]] explain how to do that.<br />
<br />
After this is done, you should see a <tt>gluegen</tt> and a <tt>jogl</tt> directory side by side in your working directory. They need to be together like this or the build won't work properly.<br />
<br />
= Build JOGL =<br />
<br />
You actually have to build gluegen first, then jogl.<br />
<br />
* Build gluegen<br />
** cd to <tt>gluegen/make</tt><br />
** Type <tt>ant clean</tt><br />
** Type <tt>ant</tt><br />
* Build jogl<br />
** cd to <tt>jogl/make</tt><br />
** Type <tt>ant clean</tt><br />
** Type <tt>ant</tt><br />
<br />
<br />
During the build, ANTLR produces lots of warnings about the C grammar and our modifications to some of the signatures of the productions. The C grammar warnings have been documented by the author of the grammar as having been investigated completely and harmless, and the warnings about our modifications are also harmless.<br />
<br />
= Test the JOGL build =<br />
<br />
Before runing the tests, make sure the Z-Zip file archiver is installed.<br />
* If you don't have it, download the latest version from http://www.7-zip.org/ and install it.<br />
* Make sure <tt>7z</tt> is visible in a command shell.<br />
** On Windows, append <tt>;C:\Program Files\7-Zip</tt> to your PATH environment variable.<br />
* Test 7-Zip by opening a new shell and typing <tt>7z</tt><br />
<br />
Then to run the full suite of JUnit tests:<br />
* For gluegen, cd to <tt>gluegen/make</tt> and type <tt>ant junit.run</tt><br />
* For jogl, cd to <tt>jogl/make</tt> and type <tt>ant junit.run</tt><br />
<br />
= Build Javadoc (optional) =<br />
<br />
Type <tt>ant javadoc</tt> in the <tt>jogl/make</tt> directory. This will produce the end-user documentation for JOGL along with some auxiliary utility packages.<br />
<br />
= Set up custom Ant properties (optional) =<br />
<br />
If you want to set different options for components and compilers during the Ant build, copy <tt>gluegen/make/gluegen.properties</tt> and/or <tt>jogl/make/jogl.properties</tt> into your home directory (pointed to by the Java system property <tt>user.home</tt>) and edit them as desired.<br />
<br />
For example, if you want to build JOGL with extra debugging information in the JARs and native libraries, create a <tt>jogl.properties</tt> file in your home directory and add these lines to it:<br />
<br />
<pre>javacdebuglevel=source,lines,vars<br />
c.compiler.debug=true</pre><br />
<br />
The first line puts debugging information in the class files so you can step through Java files. The second line puts debugging information in the native libraries so you can step through C files containing JNI code.<br />
<br />
WARNING: Make sure there are no trailing spaces on the property lines in this file, or they may have no effect. This seems to be due to the way Ant reads these files.<br />
<br />
= Try the experimental nvidia Cg toolkit binding (optional) =<br />
<br />
If you want to try the experimental binding to nvidia's Cg shader language, first download the [http://developer.nvidia.com/object/cg_download.html Cg toolkit] for your platform. Then, when you build the jogl project, add the <tt>-Djogl.cg=1</tt> option to the ant command line. The Cg binding has been tested on Windows, Linux, and Mac OS X.<br />
<br />
= Acknowledgements =<br />
<br />
* Original JOGL build instructions by Christopher Kline and Kenneth Russell, June 2003 (revised November 2006).<br />
* Revised by Sven Gothel and Michael Bien, May 2010.<br />
* Revised by Wade Walker, January-March 2011.</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Building_JOGL_on_the_command_line&diff=848Building JOGL on the command line2013-02-12T21:57:57Z<p>Wwalker: Added Mac JDK 7 paths</p>
<hr />
<div>= Overview =<br />
<br />
To build JOGL on the command line, we'll need to install prerequisites like Ant, pull the code from a Git repository, and run the Ant build scripts.<br />
<br />
= Supported platforms =<br />
<br />
Currently we support building JOGL on Linux (x86 32- and 64-bit), Windows XP/Vista/7 (32- and 64-bit) and Mac OS X (x86 32- and 64-bit). Additional platforms like Solaris/OpenSolaris, FreeBSD and HP/UX are handled by the build system, but are not officially supported.<br />
<br />
= Install a JDK =<br />
<br />
The first thing we need is a Java Development Kit (JDK). JOGL will work with [http://openjdk.java.net/ OpenJDK] and [http://icedtea.classpath.org/ IcedTea], but here we use Oracle's and Apple's JDKs as examples.<br />
<br />
* Check if you have a JDK<br />
** You must use a JDK, not a JRE, because Ant needs <tt>bin/javac</tt>, which doesn't come in the JRE. On Windows and Linux, Ant also needs <tt>lib/tools.jar</tt>, which doesn't come in the JRE.<br />
** On Windows and Linux, if you've got some kind of Java installed, but you're not sure whether it's a JDK or a Java Runtime Environment (JRE), look inside the directory. If it's got a <tt>jre</tt> subdirectory inside, it's a JDK. A JRE contains only <tt>bin</tt> and <tt>lib</tt> directories.<br />
** On Mac OS X, Apple's JDK 6 may be included with the operating system, depending on what version you're running. It would be at <tt>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk</tt>. If you want to use Java 7, you'll need to install that yourself (see below).<br />
* Get a JDK if needed<br />
** On Windows and Linux, download the JDK from at http://www.oracle.com/technetwork/java/javase/downloads/index.html. Make sure you get Java SE 6 update 24 or later. You can install the JDK wherever you like.<br />
** On Mac OS X, for Java 7 and later, you can download it from http://www.oracle.com/technetwork/java/javase/downloads/index.html just like on Windows and Linux. If you're using Apple's JDK 6, click "Apple menu > Software update..." to update Apple's JDK.<br />
* Add the JDK's <tt>bin</tt> directory to your path.<br />
** On Windows, append <tt>;your JDK\bin</tt> to your Path environment variable.<br />
** On Linux, append <tt>:your JDK/bin</tt> to your PATH environment variable.<br />
** On Mac OS X, prepend <tt>/Library/Java/JavaVirtualMachines/jdk1.7.x_x.jdk/Contents/Home/bin:</tt> (or <tt>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin:</tt> for Apple's JDK 6) to your PATH environment variable.<br />
* Set the <tt>JAVA_HOME</tt> environment variable<br />
** On Windows and Linux, set the <tt>JAVA_HOME</tt> environment variable to your JDK path.<br />
** On Mac OS X, set <tt>JAVA_HOME</tt> to <tt>/Library/Java/JavaVirtualMachines/jdk1.7.x_x.jdk/Contents/Home</tt> (or <tt>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home</tt> for Apple's JDK 6).<br />
* Test your JDK by opening a shell and typing <tt>java -version</tt> and <tt>javac -version</tt><br />
<br />
If you're using an existing JDK instead of installing a new one, make sure you don't have any JOGL or ANTLR JARs in its extension directory. This can cause strange build or runtime problems.<br />
* On Windows and Linux, delete any JOGL or ANTLR JARs from <tt>jre/lib/ext</tt><br />
* On Mac OS X, delete any JOGL or ANTLR JARs from <tt>/Library/Java/Extensions</tt> and <tt>~/Library/Java/Extensions</tt><br />
<br />
= Install Ant =<br />
<br />
If you don't already have Ant installed, or your version is older than 1.8, you'll need to install a new version of Ant.<br />
<br />
* Download Ant 1.8 or later from http://ant.apache.org/bindownload.cgi.<br />
** For example, download the file apache-ant-1.8.2-bin.zip and unzip it to your desired installation directory.<br />
* Set your <tt>ANT_HOME</tt> environment variable to the new installation directory.<br />
* Add Ant executables to your path<br />
** On Windows, append <tt>;your Ant dir\bin</tt> to your Path environment variable.<br />
** On Linux, append <tt>:your Ant dir/bin</tt> to your PATH environment variable.<br />
** On Mac OS X, prepend <tt>your Ant dir/bin:</tt> to your PATH environment variable.<br />
* Test your Ant installation by opening a shell and typing <tt>ant -version</tt><br />
** If you have problems, more detailed installation instructions are at http://ant.apache.org/manual/index.html.<br />
<br />
= Unset the classpath =<br />
<br />
Unset the CLASSPATH environment variable if it exists. Having this set with random JARs on it is one of the main causes of build problems.<br />
<br />
* On Windows, remove it from the list of environment variables in "My Computer > Properties > Advanced > Environment Variables > System Variables".<br />
* On Linux, remove it from your <tt>.cshrc</tt> or equivalent shell setup file.<br />
* On Mac OS X, remove it from your <tt>.bash_profile</tt> or equivalent shell setup file.<br />
<br />
= Install Git =<br />
<br />
The JOGL project uses Git for source code management and collaboration. If you don't already have it, you'll need to install Git 1.6.0 or later.<br />
<br />
* On Windows<br />
** Go to http://code.google.com/p/msysgit/downloads/list.<br />
** Click the download link for an installer (for example <tt>Git-1.7.7.1-preview20111027.exe</tt>), then run it.<br />
** Choose "Run Git from the Windows Command Prompt" during the install process.<br />
* On Linux and Solaris<br />
** Download in your preferred format from http://git-scm.com/download.<br />
* On Mac OS X<br />
** Go to http://code.google.com/p/git-osx-installer/downloads/list.<br />
** Click the download link for an installer (for example <tt>git-1.7.7-intel-universal-snow-leopard.dmg</tt>). Once it's downloaded, click "Downloads > git-1.7.7-intel-universal-snow-leopard.dmg" to open it.<br />
** Double-click the icon for <tt>git-1.7.7-intel-universal-snow-leopard.pkg</tt> and follow the instructions to install it.<br />
** Prepend <tt>/usr/local/git/bin:</tt> to your PATH environment variable.<br />
* Test your Git installation by opening a new shell and typing <tt>git --version</tt><br />
<br />
= Install MinGW (Windows only) =<br />
<br />
For the JOGL build scripts to run on Windows, you'll need Minimalist GNU for Windows (MinGW) so you can use the GCC compiler.<br />
<br />
* Create a <tt>C:\MinGW</tt> directory.<br />
* Download the installer from http://sourceforge.net/projects/mingw/files/Installer/mingw-get/ into the new MinGW directory.<br />
** For example, version mingw-get-0.4-alpha-1 is in a file called <tt>mingw-get-0.4-mingw32-alpha-1-bin.zip</tt><br />
* Extract the installer file.<br />
** The <tt>bin</tt>, <tt>libexec</tt>, and <tt>var</tt> directories should be directly inside <tt>C:\MinGW</tt><br />
* Append <tt>;C:\MinGW\bin</tt> to the end of your Path environment variable.<br />
* Open new shell and type <tt>mingw-get install gcc</tt><br />
** This may take a few minutes to download and install the rest of MinGW.<br />
* Test your MinGW installation by opening a new shell and typing <tt>gcc --version</tt><br />
<br />
= Check and install developer packages (Linux and Solaris only) =<br />
<br />
Depending on your Linux or Solaris flavor and version, you may need to install some developer packages to build JOGL. See the [[Required developer packages|list of developer packages for each operating system distribution]] to check if you're missing one.<br />
<br />
= Install Xcode (Mac OS X only) =<br />
<br />
The easiest way to set up GCC on Mac OS X is to install Xcode 4. It's a cheap download from the Mac App Store. Once you've installed it, open a new shell and type <tt>gcc --version</tt> to make sure GCC is available.<br />
<br />
= Pull the JOGL source code from GitHub or JogAmp =<br />
<br />
You'll need to get the source code for two projects, gluegen and jogl. The simple way to get it is by cloning the canonical repository.<br />
<br />
* Open a shell and cd to where you want the code to go.<br />
* Type <tt>git clone git://github.com/sgothel/gluegen.git gluegen</tt> and wait for the code to download.<br />
* Type <tt>git clone git://github.com/sgothel/jogl.git jogl</tt> and wait for the code to download.<br />
<br />
If you wish, you can clone from <tt>git://jogamp.com/srv/scm</tt> instead of <tt>git://github.com/sgothel</tt>. The contents of the two repositories should be the same.<br />
<br />
If you're going to be contributing fixes or doing development, you'll need to check out from your own GitHub account. The instructions at [[Contributing a new feature or fix|"Contributing a new feature or fix"]] explain how to do that.<br />
<br />
After this is done, you should see a <tt>gluegen</tt> and a <tt>jogl</tt> directory side by side in your working directory. They need to be together like this or the build won't work properly.<br />
<br />
= Build JOGL =<br />
<br />
You actually have to build gluegen first, then jogl.<br />
<br />
* Build gluegen<br />
** cd to <tt>gluegen/make</tt><br />
** Type <tt>ant clean</tt><br />
** Type <tt>ant</tt><br />
* Build jogl<br />
** cd to <tt>jogl/make</tt><br />
** Type <tt>ant clean</tt><br />
** Type <tt>ant</tt><br />
<br />
<br />
During the build, ANTLR produces lots of warnings about the C grammar and our modifications to some of the signatures of the productions. The C grammar warnings have been documented by the author of the grammar as having been investigated completely and harmless, and the warnings about our modifications are also harmless.<br />
<br />
= Test the JOGL build =<br />
<br />
Before runing the tests, make sure the Z-Zip file archiver is installed.<br />
* If you don't have it, download the latest version from http://www.7-zip.org/ and install it.<br />
* Make sure <tt>7z</tt> is visible in a command shell.<br />
** On Windows, append <tt>;C:\Program Files\7-Zip</tt> to your PATH environment variable.<br />
* Test 7-Zip by opening a new shell and typing <tt>7z</tt><br />
<br />
Then to run the full suite of JUnit tests:<br />
* For gluegen, cd to <tt>gluegen/make</tt> and type <tt>ant junit.run</tt><br />
* For jogl, cd to <tt>jogl/make</tt> and type <tt>ant junit.run</tt><br />
<br />
= Build Javadoc (optional) =<br />
<br />
Type <tt>ant javadoc</tt> in the <tt>jogl/make</tt> directory. This will produce the end-user documentation for JOGL along with some auxiliary utility packages.<br />
<br />
= Set up custom Ant properties (optional) =<br />
<br />
If you want to set different options for components and compilers during the Ant build, copy <tt>gluegen/make/gluegen.properties</tt> and/or <tt>jogl/make/jogl.properties</tt> into your home directory (pointed to by the Java system property <tt>user.home</tt>) and edit them as desired.<br />
<br />
For example, if you want to build JOGL with extra debugging information in the JARs and native libraries, create a <tt>jogl.properties</tt> file in your home directory and add these lines to it:<br />
<br />
<pre>javacdebuglevel=source,lines,vars<br />
c.compiler.debug=true</pre><br />
<br />
The first line puts debugging information in the class files so you can step through Java files. The second line puts debugging information in the native libraries so you can step through C files containing JNI code.<br />
<br />
WARNING: Make sure there are no trailing spaces on the property lines in this file, or they may have no effect. This seems to be due to the way Ant reads these files.<br />
<br />
= Try the experimental nvidia Cg toolkit binding (optional) =<br />
<br />
If you want to try the experimental binding to nvidia's Cg shader language, first download the [http://developer.nvidia.com/object/cg_download.html Cg toolkit] for your platform. Then, when you build the jogl project, add the <tt>-Djogl.cg=1</tt> option to the ant command line. The Cg binding has been tested on Windows, Linux, and Mac OS X.<br />
<br />
= Acknowledgements =<br />
<br />
* Original JOGL build instructions by Christopher Kline and Kenneth Russell, June 2003 (revised November 2006).<br />
* Revised by Sven Gothel and Michael Bien, May 2010.<br />
* Revised by Wade Walker, January-March 2011.</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Building_JOGL_in_Eclipse&diff=847Building JOGL in Eclipse2013-02-12T21:50:22Z<p>Wwalker: Added location of Mac eclipse.ini</p>
<hr />
<div>= Why build in Eclipse? =<br />
<br />
Building JOGL inside Eclipse lets you use the Eclipse debugger, profiler, and unit test framework. It also gives you useful editing features like auto-complete and red underlines for syntax errors.<br />
<br />
= Prerequisites =<br />
<br />
Before you can build JOGL in Eclipse, make sure you can [[Building JOGL on the command line|build it from the command line]]. Then double-check these things:<br />
<br />
* Make sure you've got a JDK installed and set up properly.<br />
** Make sure <tt>JAVA_HOME</tt> is set to your JDK directory. You must use a JDK, not a JRE, because Ant needs <tt>$JAVA_HOME/lib/tools.jar</tt> (on Windows and Linux).<br />
** Make sure the <tt>$JAVA_HOME/bin</tt> directory is on your PATH. You must use a JDK bin directory, not a JRE bin directory, because Ant needs <tt>$JAVA_HOME/bin/javac</tt>.<br />
* Delete the CLASSPATH variable from your system environment variables, <tt>.cshrc</tt>, <tt>.bash_profile</tt> or other location.<br />
** Having this set with random old JARs on it is one of the leading causes of build problems.<br />
* Make sure you've got Ant 1.8.0 or later installed.<br />
* Make sure <tt>ANT_HOME</tt> is set to your Ant installation directory.<br />
* Make sure <tt>ANT_HOME/bin</tt> is on your PATH.<br />
<br />
= Overview =<br />
<br />
To build JOGL in Eclipse, we'll set up Eclipse's JRE and Ant version, create Eclipse projects for the gluegen and jogl projects, then add Ant builders to those projects to invoke the JOGL command-line Ant build.<br />
<br />
= Set up Eclipse's workbench VM =<br />
<br />
The workbench VM is the version of Java that Eclipse uses to launch itself. Eclipse can find a Java VM on its own by looking in your system's default locations, but we don't want that, because it might pick a JRE instead of a JDK, which won't work with the JOGL Ant build.<br />
<br />
* Go to your Eclipse installation directory, and edit the <tt>eclipse.ini</tt> file (on Mac OS X, it's at <tt>&lt;eclipse installation directory&gt;/Eclipse.app/Contents/MacOS/eclipse.ini</tt>).<br />
* If they don't exist already, add these lines before the <tt>-vmargs</tt> line.<br />
Windows:<br />
<pre><br />
-vm<br />
<your JAVA_HOME directory>\jre\bin\javaw.exe<br />
</pre><br />
Linux and Mac OS X:<br />
<pre><br />
-vm<br />
<your JAVA_HOME directory>/jre/bin/java<br />
</pre><br />
* Save and close the file.<br />
* If Eclipse is running, you must restart it for the setting to take effect.<br />
<br />
If you haven't done this step, the <tt>javah</tt> task may fail in the Ant build.<br />
<br />
= Switch workspace to the parent of gluegen and jogl =<br />
<br />
You need to set your Eclipse workspace to the parent directory of the gluegen and jogl projects. This tells Eclipse where to create its <tt>.metadata</tt> directory, where it will store your settings for this group of projects.<br />
<br />
* Click "File > Switch Workspace > Other...".<br />
* Click the "Browse..." button.<br />
* Navigate to the parent directory of the gluegen and jogl projects, select it, and click "OK".<br />
* Click "OK" to dismiss the Workspace Launcher dialog.<br />
<br />
= Set up Eclipse's project JRE =<br />
<br />
This is the version of Java that Eclipse runs and debugs your projects with. Eclipse will already have some project JRE installed, but we need to make sure that it's set up properly.<br />
<br />
* Click "Window > Preferences" (it's "Eclipse > Preferences..." on Mac OS X), then select "Java > Installed JREs" on the left.<br />
* Select the checked JRE on the right, then click the "Edit..." button.<br />
* Make sure the JRE home is set to the same directory that you've got <tt>JAVA_HOME</tt> set to in your environment. If it's not, click "Directory..." to change it.<br />
** This should be a JDK directory.<br />
** The list of JRE system libraries should show a list of <tt>$JAVA_HOME/jre/lib/*.jar</tt> entries (on Windows and Linux) or a list of <tt>$JAVA_HOME/../Contents/Classes/*.jar</tt> entries (on Mac OS X).<br />
* Click "Finish" to close the Edit JRE dialog, and "OK" to close the Preferences dialog.<br />
<br />
= Update and customize Eclipse's Ant version =<br />
<br />
Ant comes bundled inside Eclipse, but we need Ant 1.8 or later to build JOGL, and Eclipse 3.6 still contains Ant 1.7. So we tell Eclipse to use your local Ant installation when it launches Ant.<br />
<br />
* Click "Window > Preferences" (it's "Eclipse > Preferences..." on Mac OS X), then select "Ant > Runtime" on the left.<br />
* Look inside "Ant Home Entries" on the "Classpath" tab. If it shows files for Ant 1.8 or later, you don't need to change the Ant home. But if your Ant is older than 1.8, click the "Ant Home..." button, navigate to your Ant home directory and click "Open".<br />
<br />
On Windows, we also need to tell Ant where the JDK directory is, so it can find <tt>jni.h</tt> and other files in the JDK.<br />
<br />
* On Windows, click the "Properties" tab, click "Add Property...", set the name to "java.home", and set the value to your <tt>$JAVA_HOME/jre</tt> directory. This is needed to get some paths in the Ant build correct.<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
= Create an Ant user library =<br />
<br />
We've told Eclipse which version of Ant to launch for external builds, but JOGL also contains code that uses classes in the Ant JARs. So we also need a way to tell our projects where those JARs are.<br />
<br />
* Click "Window > Preferences" (it's "Eclipse > Preferences..." on Mac OS X), then select "Java > Build Path > User Libraries" on the left.<br />
* Click the "New..." button, type "Ant" for the library name, and click "OK".<br />
* Click the "Add JARs..." button, navigate to your <tt>$ANT_HOME/lib</tt> directory, select all the JARs inside, and click "Open".<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
= Create an SWT user library =<br />
<br />
To build the SWT tests in JOGL, Eclipse needs to know where the SWT JAR files are.<br />
<br />
* Click "Window > Preferences" (it's "Eclipse > Preferences..." on Mac OS X), then select "Java > Build Path > User Libraries" on the left.<br />
* Click the "New..." button, type "SWT" for the library name, and click "OK".<br />
* Click the "Add JARs..." button, navigate to your <tt>jogl\make\lib\swt\your-platform</tt> directory, select <tt>swt-debug.jar</tt>, and click "Open".<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
= Import the gluegen and jogl projects =<br />
<br />
The Eclipse project files for gluegen and jogl should have been checked out along with the source code, so you should be able to import the two projects.<br />
<br />
* Click "File > Import...", then select "General > Existing Projects into Workspace".<br />
* Click "Next".<br />
* Click "Browse", then select your workspace directory and click "OK".<br />
* Uncheck any projects in the list except gluegen and jogl.<br />
* Click "Finish".<br />
<br />
= Create the gluegen project (optional) =<br />
<br />
Since the gluegen project files are checked out along with the code, you shouldn't have to create them yourself. But just for reference, if you did have to create them for some reason, here's how to do it.<br />
<br />
First we create the new gluegen project with default settings.<br />
<br />
* Select "File > New > Project...".<br />
* Expand "Java", click "Java Project", and click the "Next" button.<br />
* Set "gluegen" as the project name and click the "Next" button.<br />
* To the "Remove all generated resources" dialog, click "Yes".<br />
* Click "Finish". This creates the <tt>.project</tt> and <tt>.classpath</tt> files in the <tt>gluegen</tt> directory.<br />
<br />
Next we set up the source paths for the project so Eclipse knows which Java files to build. When we created the project, Eclipse automatically found these, but it doesn't have all the properties set like we want them.<br />
<br />
* Right-click the "gluegen" project and select "Properties".<br />
* Select "Java Build Path", then click the "Source" tab.<br />
* Click "Allow output folders for source folders". This allows the Java files in each source folder to be compiled to a different output folder, which we need to match the Ant build.<br />
* Set the default output folder to <tt>gluegen/build/classes</tt>.<br />
* Set the output folders, excluded patterns, and native library locations to the values in this table. Remove any source path entries that are not in this list.<br />
<br />
{| border="1"<br />
! source<br />
! native<br />
! output<br />
! excluding<br />
|-<br />
| build/gensrc/java<br />
| gluegen/build/obj<br />
| build/classes<br />
|<br />
|-<br />
| build/test/build/gensrc/classes<br />
| gluegen/build/obj<br />
| build/test/build/classes<br />
|<br />
|-<br />
| src/java<br />
| gluegen/build/obj<br />
| build/classes<br />
| com/jogamp/gluegen/runtime/BufferFactoryInternal.java<br />
|-<br />
| src/junit<br />
| gluegen/build/obj<br />
| build/test/build/classes<br />
|<br />
|-<br />
| test/junit<br />
| gluegen/build/obj<br />
| build/test/build/classes<br />
| com/jogamp/gluegen/StructValidator.java<br />
|}<br />
<br />
Now we set up the libraries that are needed to build the project.<br />
<br />
* Click the "Libraries" tab.<br />
* Remove all the JARs except <tt>gluegen/make/lib/antlr.jar</tt> from the list.<br />
* Click "Add Library...", select "JUnit", click "Next", select "JUnit 4", and click "Finish".<br />
* The JRE System Library should already be on this list. If it's not, click "Add Library...", select "JRE System Library", click "Next", and click "Finish".<br />
* Click "Add Library...", select "User Library", click "Next", check "Ant", and click "Finish".<br />
* Click "OK" to dismiss the Properties dialog.<br />
<br />
Finally we can set up the Ant builder. This lets Eclipse invoke our command-line Ant build.<br />
<br />
* Right-click the "gluegen" project, select "Properties".<br />
* Click the "Builders" tab on the left.<br />
* Uncheck the "Java Builder". Click "OK" when it asks you to confirm. This is needed to prevent Eclipse from rebuilding class files that the Ant builder is responsible for.<br />
* Click the "New..." button, select "Ant Builder", and click "OK".<br />
* Type "gluegen builder" as the name.<br />
* Set the buildfile to <tt>${workspace_loc:/gluegen/make/build.xml}</tt><br />
* Set the base directory to <tt>${workspace_loc:/gluegen/make}</tt><br />
* Click the "Refresh" tab, check "Refresh resources upon completion", click "The project containing the selected resource".<br />
* Click the "Targets" tab.<br />
* Click the "Set Targets..." button to the right of "Auto Build". Then check "all" and click "OK".<br />
* Click the "Set Targets..." button to the right of "During a "Clean"". Then uncheck "all", check "clean", and click "OK".<br />
* Click "OK" to dismiss the Edit Configuration dialog.<br />
* Click "OK" to save and dismiss the Properties dialog. This creates the <tt>.externalToolBuilders</tt> directory in the glugen project.<br />
<br />
= Create the jogl project (optional) =<br />
<br />
Since the jogl project files are checked out along with the code, you shouldn't have to create them yourself. But just for reference, if you did have to create them for some reason, here's how to do it.<br />
<br />
To create the jogl project, we do exactly what we did to create the gluegen project, but with different names and paths substituted. First we create the new jogl project with default settings.<br />
<br />
* Select "File > New > Project...".<br />
* Expand "Java", click "Java Project", and click the "Next" button.<br />
* Set "jogl" as the project name and click the "Next" button.<br />
* To the "Remove all generated resources" dialog, click "Yes".<br />
* Click "Finish".<br />
<br />
Next we set up the source directories for the project.<br />
<br />
* Right-click the "jogl" project and select "Properties".<br />
* Select "Java Build Path", then click the "Source" tab.<br />
* Click "Allow output folders for source folders".<br />
* Set the default output folder to <tt>jogl/build/jogl/classes</tt>.<br />
* Set the output folders, excluded patterns, and native library locations to the values in this table. Remove any source path entries that are not in this list.<br />
<br />
{| border="1"<br />
! source<br />
! native<br />
! output<br />
! excluding<br />
|-<br />
| build/jogl/gensrc/classes<br />
| jogl/build/jogl/obj<br />
| build/jogl/classes<br />
|<br />
|-<br />
| build/nativewindow/gensrc/classes<br />
| jogl/build/nativewindow/obj<br />
| build/nativewindow/classes<br />
|<br />
|-<br />
| src/jogl/classes<br />
| jogl/build/jogl/obj<br />
| build/jogl/classes<br />
| com/jogamp/audio/windows/waveout/TestSpatialization.java, jogamp/opengl/gl2/fixme/<br />
|-<br />
| src/nativewindow/classes<br />
| jogl/build/nativewindow/obj<br />
| build/nativewindow/classes<br />
|<br />
|-<br />
| src/newt/classes<br />
| jogl/build/newt/obj<br />
| build/newt/classes<br />
|<br />
|-<br />
| src/test<br />
|<br />
| build/test/build/classes<br />
|<br />
|}<br />
<br />
The jogl project depends on the gluegen project being built first, so we need to set the dependency between them.<br />
* Click the "Projects" tab, click "Add...", check "gluegen", click "OK".<br />
<br />
Now we set up the libraries that are needed to build the project.<br />
<br />
* Click the "Libraries" tab.<br />
* Remove all the JARs from the list.<br />
* Click "Add Library...", select "JUnit", click "Next", select "JUnit 4", and click "Finish".<br />
* The JRE System Library should already be on this list. If it's not, click "Add Library...", select "JRE System Library", click "Next", and click "Finish".<br />
* Click "Add Library...", select "User Library", click "Next", check "Ant" and "SWT", and click "Finish".<br />
* Click "OK" to dismiss the Properties dialog.<br />
<br />
Finally we can set up the Ant builder.<br />
<br />
* Right-click the "jogl" project, select "Properties".<br />
* Click the "Builders" tab on the left.<br />
* Uncheck the "Java Builder". Click "OK" when it asks you to confirm. This is needed to prevent Eclipse from rebuilding class files that the Ant builder is responsible for.<br />
* Click the "New..." button, select "Ant Builder", and click "OK".<br />
* Type "jogl builder" as the name.<br />
* Set the buildfile to <tt>${workspace_loc:/jogl/make/build.xml}</tt><br />
* Set the base directory to <tt>${workspace_loc:/jogl/make}</tt><br />
* Click the "Refresh" tab, check "Refresh resources upon completion", click "The project containing the selected resource".<br />
* Click the "Targets" tab.<br />
* Click the "Set Targets..." button to the right of "After a "Clean"". Then uncheck "all", check "all.ide", and click "OK".<br />
* Click the "Set Targets..." button to the right of "Manual Build". Then uncheck "all", check "all.ide", and click "OK".<br />
* Click the "Set Targets..." button to the right of "Auto Build". Then check "all.ide" and click "OK".<br />
* Click the "Set Targets..." button to the right of "During a "Clean"". Then uncheck "all", check "clean", click "OK".<br />
* Click "OK" to dismiss the Edit Configuration dialog.<br />
* Click "OK" to save and dismiss the Properties dialog.<br />
<br />
Now we can clean and build both projects in Eclipse.<br />
<br />
* Select "Project > Clean", click "Clean all projects" and click "OK".<br />
<br />
= Install EGit in Eclipse (Eclipse 3.6 and earlier) =<br />
<br />
After the build works we can install EGit in Eclipse. This lets you perform Git source control operations from inside Eclipse, though it doesn't yet support every feature of the command line version. EGit is pre-installed in Eclipse 3.7 and later, so check your Eclipse version before doing this.<br />
<br />
* Click "Help > Install New Software...".<br />
* Type <tt>http://download.eclipse.org/egit/updates</tt> in the "Work with" box and press enter.<br />
* Check "Eclipse Git Team Provider" and "Eclipse JGit" and install them.<br />
<br />
= Associate Eclipse projects with Git =<br />
<br />
After we install EGit, we have to tell Eclipse that gluegen and jogl are Git projects.<br />
<br />
* Right-click "gluegen", select "Team > Share Project...", select "Git", click "Next", select the .git repository, and click "Finish".<br />
* Do the same thing for the "jogl" project.<br />
<br />
Now when you right-click projects or files in the Package Explorer, you can see the Git operations in the "Team" menu.</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Building_JOGL_in_Eclipse&diff=846Building JOGL in Eclipse2013-02-12T21:46:26Z<p>Wwalker: Fixed Eclipse workbench VM instructions to mention Mac OS X</p>
<hr />
<div>= Why build in Eclipse? =<br />
<br />
Building JOGL inside Eclipse lets you use the Eclipse debugger, profiler, and unit test framework. It also gives you useful editing features like auto-complete and red underlines for syntax errors.<br />
<br />
= Prerequisites =<br />
<br />
Before you can build JOGL in Eclipse, make sure you can [[Building JOGL on the command line|build it from the command line]]. Then double-check these things:<br />
<br />
* Make sure you've got a JDK installed and set up properly.<br />
** Make sure <tt>JAVA_HOME</tt> is set to your JDK directory. You must use a JDK, not a JRE, because Ant needs <tt>$JAVA_HOME/lib/tools.jar</tt> (on Windows and Linux).<br />
** Make sure the <tt>$JAVA_HOME/bin</tt> directory is on your PATH. You must use a JDK bin directory, not a JRE bin directory, because Ant needs <tt>$JAVA_HOME/bin/javac</tt>.<br />
* Delete the CLASSPATH variable from your system environment variables, <tt>.cshrc</tt>, <tt>.bash_profile</tt> or other location.<br />
** Having this set with random old JARs on it is one of the leading causes of build problems.<br />
* Make sure you've got Ant 1.8.0 or later installed.<br />
* Make sure <tt>ANT_HOME</tt> is set to your Ant installation directory.<br />
* Make sure <tt>ANT_HOME/bin</tt> is on your PATH.<br />
<br />
= Overview =<br />
<br />
To build JOGL in Eclipse, we'll set up Eclipse's JRE and Ant version, create Eclipse projects for the gluegen and jogl projects, then add Ant builders to those projects to invoke the JOGL command-line Ant build.<br />
<br />
= Set up Eclipse's workbench VM =<br />
<br />
The workbench VM is the version of Java that Eclipse uses to launch itself. Eclipse can find a Java VM on its own by looking in your system's default locations, but we don't want that, because it might pick a JRE instead of a JDK, which won't work with the JOGL Ant build.<br />
<br />
* Go to your Eclipse installation directory, and edit the <tt>eclipse.ini</tt> file.<br />
* If they don't exist already, add these lines before the <tt>-vmargs</tt> line.<br />
Windows:<br />
<pre><br />
-vm<br />
<your JAVA_HOME directory>\jre\bin\javaw.exe<br />
</pre><br />
Linux and Mac OS X:<br />
<pre><br />
-vm<br />
<your JAVA_HOME directory>/jre/bin/java<br />
</pre><br />
* Save and close the file.<br />
* If Eclipse is running, you must restart it for the setting to take effect.<br />
<br />
If you haven't done this step, the <tt>javah</tt> task may fail in the Ant build.<br />
<br />
= Switch workspace to the parent of gluegen and jogl =<br />
<br />
You need to set your Eclipse workspace to the parent directory of the gluegen and jogl projects. This tells Eclipse where to create its <tt>.metadata</tt> directory, where it will store your settings for this group of projects.<br />
<br />
* Click "File > Switch Workspace > Other...".<br />
* Click the "Browse..." button.<br />
* Navigate to the parent directory of the gluegen and jogl projects, select it, and click "OK".<br />
* Click "OK" to dismiss the Workspace Launcher dialog.<br />
<br />
= Set up Eclipse's project JRE =<br />
<br />
This is the version of Java that Eclipse runs and debugs your projects with. Eclipse will already have some project JRE installed, but we need to make sure that it's set up properly.<br />
<br />
* Click "Window > Preferences" (it's "Eclipse > Preferences..." on Mac OS X), then select "Java > Installed JREs" on the left.<br />
* Select the checked JRE on the right, then click the "Edit..." button.<br />
* Make sure the JRE home is set to the same directory that you've got <tt>JAVA_HOME</tt> set to in your environment. If it's not, click "Directory..." to change it.<br />
** This should be a JDK directory.<br />
** The list of JRE system libraries should show a list of <tt>$JAVA_HOME/jre/lib/*.jar</tt> entries (on Windows and Linux) or a list of <tt>$JAVA_HOME/../Contents/Classes/*.jar</tt> entries (on Mac OS X).<br />
* Click "Finish" to close the Edit JRE dialog, and "OK" to close the Preferences dialog.<br />
<br />
= Update and customize Eclipse's Ant version =<br />
<br />
Ant comes bundled inside Eclipse, but we need Ant 1.8 or later to build JOGL, and Eclipse 3.6 still contains Ant 1.7. So we tell Eclipse to use your local Ant installation when it launches Ant.<br />
<br />
* Click "Window > Preferences" (it's "Eclipse > Preferences..." on Mac OS X), then select "Ant > Runtime" on the left.<br />
* Look inside "Ant Home Entries" on the "Classpath" tab. If it shows files for Ant 1.8 or later, you don't need to change the Ant home. But if your Ant is older than 1.8, click the "Ant Home..." button, navigate to your Ant home directory and click "Open".<br />
<br />
On Windows, we also need to tell Ant where the JDK directory is, so it can find <tt>jni.h</tt> and other files in the JDK.<br />
<br />
* On Windows, click the "Properties" tab, click "Add Property...", set the name to "java.home", and set the value to your <tt>$JAVA_HOME/jre</tt> directory. This is needed to get some paths in the Ant build correct.<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
= Create an Ant user library =<br />
<br />
We've told Eclipse which version of Ant to launch for external builds, but JOGL also contains code that uses classes in the Ant JARs. So we also need a way to tell our projects where those JARs are.<br />
<br />
* Click "Window > Preferences" (it's "Eclipse > Preferences..." on Mac OS X), then select "Java > Build Path > User Libraries" on the left.<br />
* Click the "New..." button, type "Ant" for the library name, and click "OK".<br />
* Click the "Add JARs..." button, navigate to your <tt>$ANT_HOME/lib</tt> directory, select all the JARs inside, and click "Open".<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
= Create an SWT user library =<br />
<br />
To build the SWT tests in JOGL, Eclipse needs to know where the SWT JAR files are.<br />
<br />
* Click "Window > Preferences" (it's "Eclipse > Preferences..." on Mac OS X), then select "Java > Build Path > User Libraries" on the left.<br />
* Click the "New..." button, type "SWT" for the library name, and click "OK".<br />
* Click the "Add JARs..." button, navigate to your <tt>jogl\make\lib\swt\your-platform</tt> directory, select <tt>swt-debug.jar</tt>, and click "Open".<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
= Import the gluegen and jogl projects =<br />
<br />
The Eclipse project files for gluegen and jogl should have been checked out along with the source code, so you should be able to import the two projects.<br />
<br />
* Click "File > Import...", then select "General > Existing Projects into Workspace".<br />
* Click "Next".<br />
* Click "Browse", then select your workspace directory and click "OK".<br />
* Uncheck any projects in the list except gluegen and jogl.<br />
* Click "Finish".<br />
<br />
= Create the gluegen project (optional) =<br />
<br />
Since the gluegen project files are checked out along with the code, you shouldn't have to create them yourself. But just for reference, if you did have to create them for some reason, here's how to do it.<br />
<br />
First we create the new gluegen project with default settings.<br />
<br />
* Select "File > New > Project...".<br />
* Expand "Java", click "Java Project", and click the "Next" button.<br />
* Set "gluegen" as the project name and click the "Next" button.<br />
* To the "Remove all generated resources" dialog, click "Yes".<br />
* Click "Finish". This creates the <tt>.project</tt> and <tt>.classpath</tt> files in the <tt>gluegen</tt> directory.<br />
<br />
Next we set up the source paths for the project so Eclipse knows which Java files to build. When we created the project, Eclipse automatically found these, but it doesn't have all the properties set like we want them.<br />
<br />
* Right-click the "gluegen" project and select "Properties".<br />
* Select "Java Build Path", then click the "Source" tab.<br />
* Click "Allow output folders for source folders". This allows the Java files in each source folder to be compiled to a different output folder, which we need to match the Ant build.<br />
* Set the default output folder to <tt>gluegen/build/classes</tt>.<br />
* Set the output folders, excluded patterns, and native library locations to the values in this table. Remove any source path entries that are not in this list.<br />
<br />
{| border="1"<br />
! source<br />
! native<br />
! output<br />
! excluding<br />
|-<br />
| build/gensrc/java<br />
| gluegen/build/obj<br />
| build/classes<br />
|<br />
|-<br />
| build/test/build/gensrc/classes<br />
| gluegen/build/obj<br />
| build/test/build/classes<br />
|<br />
|-<br />
| src/java<br />
| gluegen/build/obj<br />
| build/classes<br />
| com/jogamp/gluegen/runtime/BufferFactoryInternal.java<br />
|-<br />
| src/junit<br />
| gluegen/build/obj<br />
| build/test/build/classes<br />
|<br />
|-<br />
| test/junit<br />
| gluegen/build/obj<br />
| build/test/build/classes<br />
| com/jogamp/gluegen/StructValidator.java<br />
|}<br />
<br />
Now we set up the libraries that are needed to build the project.<br />
<br />
* Click the "Libraries" tab.<br />
* Remove all the JARs except <tt>gluegen/make/lib/antlr.jar</tt> from the list.<br />
* Click "Add Library...", select "JUnit", click "Next", select "JUnit 4", and click "Finish".<br />
* The JRE System Library should already be on this list. If it's not, click "Add Library...", select "JRE System Library", click "Next", and click "Finish".<br />
* Click "Add Library...", select "User Library", click "Next", check "Ant", and click "Finish".<br />
* Click "OK" to dismiss the Properties dialog.<br />
<br />
Finally we can set up the Ant builder. This lets Eclipse invoke our command-line Ant build.<br />
<br />
* Right-click the "gluegen" project, select "Properties".<br />
* Click the "Builders" tab on the left.<br />
* Uncheck the "Java Builder". Click "OK" when it asks you to confirm. This is needed to prevent Eclipse from rebuilding class files that the Ant builder is responsible for.<br />
* Click the "New..." button, select "Ant Builder", and click "OK".<br />
* Type "gluegen builder" as the name.<br />
* Set the buildfile to <tt>${workspace_loc:/gluegen/make/build.xml}</tt><br />
* Set the base directory to <tt>${workspace_loc:/gluegen/make}</tt><br />
* Click the "Refresh" tab, check "Refresh resources upon completion", click "The project containing the selected resource".<br />
* Click the "Targets" tab.<br />
* Click the "Set Targets..." button to the right of "Auto Build". Then check "all" and click "OK".<br />
* Click the "Set Targets..." button to the right of "During a "Clean"". Then uncheck "all", check "clean", and click "OK".<br />
* Click "OK" to dismiss the Edit Configuration dialog.<br />
* Click "OK" to save and dismiss the Properties dialog. This creates the <tt>.externalToolBuilders</tt> directory in the glugen project.<br />
<br />
= Create the jogl project (optional) =<br />
<br />
Since the jogl project files are checked out along with the code, you shouldn't have to create them yourself. But just for reference, if you did have to create them for some reason, here's how to do it.<br />
<br />
To create the jogl project, we do exactly what we did to create the gluegen project, but with different names and paths substituted. First we create the new jogl project with default settings.<br />
<br />
* Select "File > New > Project...".<br />
* Expand "Java", click "Java Project", and click the "Next" button.<br />
* Set "jogl" as the project name and click the "Next" button.<br />
* To the "Remove all generated resources" dialog, click "Yes".<br />
* Click "Finish".<br />
<br />
Next we set up the source directories for the project.<br />
<br />
* Right-click the "jogl" project and select "Properties".<br />
* Select "Java Build Path", then click the "Source" tab.<br />
* Click "Allow output folders for source folders".<br />
* Set the default output folder to <tt>jogl/build/jogl/classes</tt>.<br />
* Set the output folders, excluded patterns, and native library locations to the values in this table. Remove any source path entries that are not in this list.<br />
<br />
{| border="1"<br />
! source<br />
! native<br />
! output<br />
! excluding<br />
|-<br />
| build/jogl/gensrc/classes<br />
| jogl/build/jogl/obj<br />
| build/jogl/classes<br />
|<br />
|-<br />
| build/nativewindow/gensrc/classes<br />
| jogl/build/nativewindow/obj<br />
| build/nativewindow/classes<br />
|<br />
|-<br />
| src/jogl/classes<br />
| jogl/build/jogl/obj<br />
| build/jogl/classes<br />
| com/jogamp/audio/windows/waveout/TestSpatialization.java, jogamp/opengl/gl2/fixme/<br />
|-<br />
| src/nativewindow/classes<br />
| jogl/build/nativewindow/obj<br />
| build/nativewindow/classes<br />
|<br />
|-<br />
| src/newt/classes<br />
| jogl/build/newt/obj<br />
| build/newt/classes<br />
|<br />
|-<br />
| src/test<br />
|<br />
| build/test/build/classes<br />
|<br />
|}<br />
<br />
The jogl project depends on the gluegen project being built first, so we need to set the dependency between them.<br />
* Click the "Projects" tab, click "Add...", check "gluegen", click "OK".<br />
<br />
Now we set up the libraries that are needed to build the project.<br />
<br />
* Click the "Libraries" tab.<br />
* Remove all the JARs from the list.<br />
* Click "Add Library...", select "JUnit", click "Next", select "JUnit 4", and click "Finish".<br />
* The JRE System Library should already be on this list. If it's not, click "Add Library...", select "JRE System Library", click "Next", and click "Finish".<br />
* Click "Add Library...", select "User Library", click "Next", check "Ant" and "SWT", and click "Finish".<br />
* Click "OK" to dismiss the Properties dialog.<br />
<br />
Finally we can set up the Ant builder.<br />
<br />
* Right-click the "jogl" project, select "Properties".<br />
* Click the "Builders" tab on the left.<br />
* Uncheck the "Java Builder". Click "OK" when it asks you to confirm. This is needed to prevent Eclipse from rebuilding class files that the Ant builder is responsible for.<br />
* Click the "New..." button, select "Ant Builder", and click "OK".<br />
* Type "jogl builder" as the name.<br />
* Set the buildfile to <tt>${workspace_loc:/jogl/make/build.xml}</tt><br />
* Set the base directory to <tt>${workspace_loc:/jogl/make}</tt><br />
* Click the "Refresh" tab, check "Refresh resources upon completion", click "The project containing the selected resource".<br />
* Click the "Targets" tab.<br />
* Click the "Set Targets..." button to the right of "After a "Clean"". Then uncheck "all", check "all.ide", and click "OK".<br />
* Click the "Set Targets..." button to the right of "Manual Build". Then uncheck "all", check "all.ide", and click "OK".<br />
* Click the "Set Targets..." button to the right of "Auto Build". Then check "all.ide" and click "OK".<br />
* Click the "Set Targets..." button to the right of "During a "Clean"". Then uncheck "all", check "clean", click "OK".<br />
* Click "OK" to dismiss the Edit Configuration dialog.<br />
* Click "OK" to save and dismiss the Properties dialog.<br />
<br />
Now we can clean and build both projects in Eclipse.<br />
<br />
* Select "Project > Clean", click "Clean all projects" and click "OK".<br />
<br />
= Install EGit in Eclipse (Eclipse 3.6 and earlier) =<br />
<br />
After the build works we can install EGit in Eclipse. This lets you perform Git source control operations from inside Eclipse, though it doesn't yet support every feature of the command line version. EGit is pre-installed in Eclipse 3.7 and later, so check your Eclipse version before doing this.<br />
<br />
* Click "Help > Install New Software...".<br />
* Type <tt>http://download.eclipse.org/egit/updates</tt> in the "Work with" box and press enter.<br />
* Check "Eclipse Git Team Provider" and "Eclipse JGit" and install them.<br />
<br />
= Associate Eclipse projects with Git =<br />
<br />
After we install EGit, we have to tell Eclipse that gluegen and jogl are Git projects.<br />
<br />
* Right-click "gluegen", select "Team > Share Project...", select "Git", click "Next", select the .git repository, and click "Finish".<br />
* Do the same thing for the "jogl" project.<br />
<br />
Now when you right-click projects or files in the Package Explorer, you can see the Git operations in the "Team" menu.</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=JogAmp_BOF_SIGGRAPH_2012_PLANNING&diff=743JogAmp BOF SIGGRAPH 2012 PLANNING2012-07-07T22:04:01Z<p>Wwalker: /* Confirmed */</p>
<hr />
<div>= Preface = <br />
<br />
IMHO it would be great if everybody of the <br />
team, who likes to have his content shown,<br />
could produce a 'small' summary [maybe w/ links].<br />
<br />
Even if you cannot attend personally, you can have us show <br />
your content. You will be referenced of course.<br />
<br />
A small introduction of each person could be helpful as well,<br />
so we can add this to our web page / presentation, eg:<br />
* full name<br />
* 'related' professional history<br />
* project relation<br />
* etc<br />
<br />
= BOF Team =<br />
<br />
== Confirmed == <br />
* Julien<br />
** Saturday, 4th August<br />
* Rami<br />
** Saturday, 4th August<br />
* Sven<br />
** Sunday, 5th August<br />
* Wade<br />
** Sunday, 5th August - arriving 10:40am<br />
* Xerxes<br />
** ?????<br />
<br />
== Unconfirmed ==<br />
* Dominik (probably not)<br />
* ??<br />
<br />
== Schedule ==<br />
<br />
=== Remote ===<br />
* 20th July<br />
** Collect all slides from all members<br />
** Discussions<br />
* 23th July<br />
** Merge slides, create draft<br />
** Discussions<br />
<br />
=== On Site ===<br />
* Sunday, 5th August<br />
** First meeting, brainstorming<br />
* Monday, 6th August<br />
** Finalize presentation<br />
** Test demos<br />
** Have fun<br />
* Tuesday, 7th August<br />
** 2:30 pm - 3:30 pm Be at door & set-up<br />
** 3:30 pm - 5:00 pm BOF<br />
** 5:30 pm - x:xx pm Dinner, party ..<br />
<br />
= JOGAMP BOF Items =<br />
<br />
== Overview ==<br />
Who? ALL!<br />
<br />
Time: 10 - 15 minutes<br />
<br />
Idea is to have a short introduction<br />
while mentioning all the supported platforms<br />
while showing demos, applications as applets <br />
and standalone applications on different platforms.<br />
<br />
Might look a bit like the video I showed: [http://jausoft.com/blog/2012/04/19/jogljogamp-status-update/ JogAmp 2012].<br />
<br />
(see below)<br />
<br />
=== History ===<br />
<br />
=== Modules ===<br />
* GlueGen (Who? Sven)<br />
* JOAL (Who? Julien)<br />
* JOGL (Who? Sven, et.al.)<br />
<br />
.. maybe:<br />
* JOCL (Who?)<br />
* Jinput (Who? Julien, ..)<br />
* Java3D (Who? Julien)<br />
<br />
.. maybe even:<br />
* GLG2D (Who???)<br />
<br />
=== Supported Platforms ===<br />
<br />
( Official JogAmp Builds )<br />
<br />
* Linux<br />
** arm<br />
*** soft-float<br />
*** hard-float<br />
** x86<br />
** x86_64<br />
* Android API Level 9 (Gingerbread) and greater<br />
** arm soft-float<br />
** x86 (TBD)<br />
** x86_64 (TBD)<br />
* Windows<br />
** x86<br />
** x86_64<br />
* Solaris / OpenIndiana<br />
** x86<br />
** x86_64<br />
* OSX<br />
** x86<br />
** x86_64<br />
<br />
'Mobile'' Linux devices known to work:<br />
* Beagleboard w/ Ubuntu and Android<br />
* Pandaboard w/ Ubuntu and Android<br />
* N900 Maemo<br />
* Raspberry Pi ?<br />
<br />
=== Showcase ===<br />
<br />
* Applets <br />
* Standalone<br />
* Platforms<br />
* Applications, Games, ..<br />
* Demos, Demos, Demos .. Ahh .. Ohh<br />
** Dominik's Demos<br />
<br />
== Middle Level and High Level Toolkits / APIs ==<br />
<br />
=== Java3D ===<br />
Who? Julien<br />
<br />
==== Arabian Flights ====<br />
[http://arabian.sourceforge.net Arabian Flights]<br />
<br />
=== Ardor3D ===<br />
Who? Julien<br />
<br />
=== Nifty GUI ===<br />
Who? Julien<br />
<br />
=== Jzy3D ===<br />
Who? Julien (?)<br />
<br />
=== LibGDX ===<br />
<br />
Who?<br />
<br />
== Applications / Tools ==<br />
<br />
=== CAD Massive Model Visualization Tool for mega construction Projects ===<br />
Who? Rami<br />
<br />
C3D as a Massive Model Visualization Tool <br />
for mega construction projects build on-top of Jogl/Newt<br />
<br />
=== Processing ===<br />
Who? Xerxes<br />
<br />
== Development / Internals ==<br />
<br />
=== Deployment / Availability ===<br />
Who? Sven, Xerxes, Wade, ..<br />
<br />
* Applets<br />
* Webstart<br />
* Standalone<br />
* Maven ?<br />
<br />
Maybe Xerxes can also speak about <br />
* OpenJDK<br />
* IcedTea<br />
* IcedTea-Web<br />
and its mobile / deployment progress etc.<br />
<br />
=== JOGL / Graph ===<br />
Who? Sven, Rami.<br />
<br />
* Curverendering API<br />
* Textrendering API<br />
* UI API<br />
<br />
=== JOGL / Multimedia ===<br />
Who ? Sven, Xerxes, .. ?<br />
<br />
== Eclipse IDE ==<br />
Who? Wade, ..<br />
<br />
=== General Usage ===<br />
<br />
=== Simulator of nonlinear Elasticity ===<br />
<br />
== Game Development ==<br />
Who? Julien<br />
<br />
=== TUER ===<br />
Who? Julien<br />
<br />
[http://tuer.sourceforge.net/very_experimental/tuer.jnlp pre-beta version, demo using Java Web Start]</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Using_JOGL_in_Java_Web_Start&diff=689Using JOGL in Java Web Start2012-04-19T17:03:21Z<p>Wwalker: Explained differences between hosted and local JARs more clearly</p>
<hr />
<div>You can use JOGL in a [http://download.oracle.com/javase/6/docs/technotes/guides/javaws/ Java Web Start (JWS)] application, which lets you launch a full-featured, standalone Java program from a web page. This page shows an example of how to do this. The example program just draws one triangle that fills a resizable window.<br />
<br />
= Base class =<br />
<br />
First, a base class that we've used before [[Using JOGL in AWT SWT and Swing|here]]. This class draws one triangle, abstracting out all the pure OpenGL calls that don't depend on the choice of window toolkit. Save this file as <tt>OneTriangle.java</tt>.<br />
<br />
<pre><br />
package name.wadewalker.jogl2tests.onetriangle;<br />
<br />
import javax.media.opengl.GL;<br />
import javax.media.opengl.GL2;<br />
import javax.media.opengl.glu.GLU;<br />
<br />
public class OneTriangle {<br />
protected static void setup( GL2 gl2, int width, int height ) {<br />
gl2.glMatrixMode( GL2.GL_PROJECTION );<br />
gl2.glLoadIdentity();<br />
<br />
// coordinate system origin at lower left with width and height same as the window<br />
GLU glu = new GLU();<br />
glu.gluOrtho2D( 0.0f, width, 0.0f, height );<br />
<br />
gl2.glMatrixMode( GL2.GL_MODELVIEW );<br />
gl2.glLoadIdentity();<br />
<br />
gl2.glViewport( 0, 0, width, height );<br />
}<br />
<br />
protected static void render( GL2 gl2, int width, int height ) {<br />
gl2.glClear( GL.GL_COLOR_BUFFER_BIT );<br />
<br />
// draw a triangle filling the window<br />
gl2.glLoadIdentity();<br />
gl2.glBegin( GL.GL_TRIANGLES );<br />
gl2.glColor3f( 1, 0, 0 );<br />
gl2.glVertex2f( 0, 0 );<br />
gl2.glColor3f( 0, 1, 0 );<br />
gl2.glVertex2f( width, 0 );<br />
gl2.glColor3f( 0, 0, 1 );<br />
gl2.glVertex2f( width / 2, height );<br />
gl2.glEnd();<br />
}<br />
}<br />
</pre><br />
<br />
= Drawing a triangle with AWT =<br />
<br />
Now, a class that draws the triangle in an AWT Frame. Java Web Start can use any Java windowing toolkit, we've just chosen this one for convenience. Save this file as <tt>OneTriangleAWT.java.</tt><br />
<br />
<pre><br />
package name.wadewalker.jogl2tests.onetriangle;<br />
<br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLCanvas;<br />
<br />
import java.awt.Frame;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an AWT Frame.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleAWT {<br />
<br />
static {<br />
// setting this true causes window events not to get sent on Linux if you run from inside Eclipse<br />
GLProfile.initSingleton( false );<br />
}<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getWidth(), glautodrawable.getHeight() );<br />
}<br />
});<br />
<br />
final Frame frame = new Frame( "One Triangle AWT" );<br />
frame.add( glcanvas );<br />
frame.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
frame.remove( glcanvas );<br />
frame.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
frame.setSize( 640, 480 );<br />
frame.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= Setting up the application directory =<br />
<br />
* Create a directory to hold your JWS application.<br />
* Create a subdirectory <tt>name/wadewalker/jogl2tests/onetriangle</tt> inside your application directory. Or if you changed the packages of the files above, create a subdirectory that matches your package names.<br />
* Put your <tt>OneTriangle.java</tt> and <tt>OneTriangleAWT.java</tt> files inside the subdirectory.<br />
<br />
== Get local copies of the JogAmp JAR files (optional) ==<br />
<br />
A Java Web Start app can either use its own local copies of the [{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#GluegenJARs GlueGen], [{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#JOGLAllInOneJARs JOGL], and native JAR files, or it can use the copies hosted at jogamp.org.<br />
<br />
Using local copies of the JogAmp JAR files gives you complete control over which version of JOGL your app uses, and guarantees that version will never change unexpectedly. However, it does require more work on your part to install and sign the JARs, and it increases the load on your server.<br />
<br />
To get local copies of the JogAmp JAR files, do this:<br />
<br />
* Read [[Downloading_and_installing_JOGL]] for instructions on how to get the autobuild or released JAR files.<br />
* Copy the following JAR files into the application directory:<br />
<br />
<pre><br />
gluegen-rt.jar<br />
jogl.all.jar<br />
<br />
gluegen-rt-natives-windows-i586.jar<br />
jogl-all-natives-windows-i586.jar<br />
<br />
gluegen-rt-natives-windows-amd64.jar<br />
jogl-all-natives-linux-amd64.jar<br />
<br />
gluegen-rt-natives-linux-i586.jar<br />
jogl-all-natives-linux-i586.jar<br />
<br />
gluegen-rt-natives-linux-amd64.jar<br />
jogl-all-natives-linux-amd64.jar<br />
<br />
gluegen-rt-natives-macosx-universal.jar<br />
jogl-all-natives-macosx-universal.jar<br />
</pre><br />
<br />
= Compiling and JARing your program =<br />
<br />
This step assumes you have Java set up so you can use it from the command line. For instructions on this, see [https://jogamp.org/wiki/index.php/Building_JOGL_on_the_command_line#Install_a_JDK here].<br />
<br />
To compile the program on Windows, cd to your application directory and type<br />
<br />
<pre><br />
javac -classpath "gluegen-rt.jar;jogl.all.jar" name\wadewalker\jogl2tests\onetriangle\*.java<br />
</pre><br />
<br />
To compile the program on Linux or Mac OS X, cd to your application directory and type<br />
<br />
<pre><br />
javac -classpath "gluegen-rt.jar:jogl.all.jar" name\wadewalker\jogl2tests\onetriangle\*.java<br />
</pre><br />
<br />
To JAR the program, type<br />
<br />
<pre><br />
jar cvf onetriangle.jar name\wadewalker\jogl2tests\onetriangle\*.class<br />
</pre><br />
<br />
= Testing your program outside JWS =<br />
<br />
It's probably a good idea to test your program outside JWS first, to make sure it does what you think it should. To do that, you'll need to unzip the native binaries so Java can see them. Since I ran first on Windows 7 64-bit, I unzipped all the <tt>*-natives-windows-amd64.jar</tt> files, the collected the DLLs inside into a directory called <tt>lib-windows-amd64</tt>. Since I test on the other platforms too, I did the same for the other four platforms, creating four more directories <tt>lib-windows-i586</tt>, <tt>lib-linux-i586</tt>, <tt>lib-linux-amd64</tt>, and <tt>lib-macosx-universal</tt>.<br />
<br />
Then to test your program on 64-bit Windows, cd to your application directory and type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar;jogl.all.jar;onetriangle.jar" -Djava.library.path=lib-windows-amd64 name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
On 64-bit Linux, type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar:jogl.all.jar:onetriangle.jar" -Djava.library.path=lib-linux-amd64 name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
On Mac OS X, type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar:jogl.all.jar:onetriangle.jar" -Djava.library.path=lib-macosx-universal name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
The result should look like this:<br />
<br />
[[File:JWS-cmdline-test.png|300px|thumb|none|JWS OneTriangle test]]<br />
<br />
= Writing the JNLP files =<br />
<br />
In general we will have one JNLP file for each JWS application, which will reference the JOGL extension's JNLP file.<br />
The latter may reference even more JNLP files, but this does not matter in this discussion. Read the JWS [http://download.oracle.com/javase/1,5.0/docs/guide/javaws/developersguide/syntax.html Java Network Launching Protocol (JNLP)] specification for details of the JNLP syntax.<br />
<br />
== Option 1: Use JogAmp's hosted JAR and JNLP files ==<br />
<br />
If you're using JogAmp's hosted JAR and JNLP files, you only have to write your application's JNLP file, since it will reference JogAmp's official release as an extension.<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="OneTriangleWebStart.jnlp"><br />
<br />
<information><br />
<title>OneTriangle Demo</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>OneTriangle Java Web Start Demo</description><br />
<description kind="short">The simplest possible JOGL Java Web Start demo - draws one triangle.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<resources><br />
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/><br />
<property name="sun.java2d.noddraw" value="true"/><br />
<extension name="jogl-all-awt" href="http://jogamp.org/deployment/jogamp-current/jogl-all-awt.jnlp" /><br />
<jar href="onetriangle.jar" main="true"/><br />
</resources><br />
<br />
<application-desc main-class="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT"><br />
</application-desc><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>OneTriangleWebStart.jnlp</tt>.<br />
<br />
If you are using JogAmp's hosted files you can skip the next chapter.<br />
<br />
== Option 2: Use local copies of the JogAmp JAR files ==<br />
<br />
Here we have to write one JNLP file for our application and one for our self-deployed JogAmp extension.<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="OneTriangleWebStart.jnlp"><br />
<br />
<information><br />
<title>OneTriangle Demo</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>OneTriangle Java Web Start Demo</description><br />
<description kind="short">The simplest possible JOGL Java Web Start demo - draws one triangle.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<resources><br />
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/><br />
<property name="sun.java2d.noddraw" value="true"/><br />
<extension name="JOGL" href="JOGL.jnlp" /><br />
<jar href="onetriangle.jar" main="true"/><br />
</resources><br />
<br />
<application-desc main-class="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT"><br />
</application-desc><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>OneTriangleWebStart.jnlp</tt>.<br />
<br />
Our extension JNLP file for the JOGL JARs looks like this:<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="JOGL.jnlp"><br />
<br />
<information><br />
<title>JOGL libraries</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>JOGL libraries</description><br />
<description kind="short">All JARs and native libraries for JOGL.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<security><br />
<all-permissions/><br />
</security><br />
<br />
<resources><br />
<jar href="gluegen-rt.jar" /><br />
<jar href="jogl.all.jar" /><br />
</resources><br />
<br />
<resources os="Windows" arch="x86"><br />
<nativelib href = "gluegen-rt-natives-windows-i586.jar" /><br />
<nativelib href = "jogl-all-natives-windows-i586.jar" /><br />
</resources><br />
<resources os="Windows" arch="amd64"><br />
<nativelib href = "gluegen-rt-natives-windows-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-windows-amd64.jar" /><br />
</resources><br />
<resources os="Windows" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-windows-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-windows-amd64.jar" /><br />
</resources><br />
<resources os="Linux" arch="i386"><br />
<nativelib href = "gluegen-rt-natives-linux-i586.jar" /><br />
<nativelib href = "jogl-all-natives-linux-i586.jar" /><br />
</resources><br />
<resources os="Linux" arch="x86"><br />
<nativelib href = "gluegen-rt-natives-linux-i586.jar" /><br />
<nativelib href = "jogl-all-natives-linux-i586.jar" /><br />
</resources><br />
<resources os="Linux" arch="amd64"><br />
<nativelib href = "gluegen-rt-natives-linux-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-linux-amd64.jar" /><br />
</resources><br />
<resources os="Linux" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-linux-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-linux-amd64.jar" /><br />
</resources><br />
<resources os="Mac OS X" arch="i386"><br />
<nativelib href = "gluegen-rt-natives-macosx-universal.jar" /><br />
<nativelib href = "jogl-all-natives-macosx-universal.jar" /><br />
</resources><br />
<resources os="Mac OS X" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-macosx-universal.jar" /><br />
<nativelib href = "jogl-all-natives-macosx-universal.jar" /><br />
</resources><br />
<br />
<component-desc /><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>JOGL.jnlp</tt>.<br />
<br />
Note that the <tt>codebase</tt> values are set to the current working directory, and the <tt>href</tt> values are simple filenames. This is so we can test the JNLP app locally, without using a web server. When we put the app on a web server later, the <tt>codebase</tt> and <tt>href</tt> become full URLs.<br />
<br />
=== Signing your local copies of the JogAmp JARs ===<br />
<br />
For the JWS app to work properly in a web browser, all its JARs must be signed with the same key. Note that none of your applet JAR files needs to be signed. Only the JogAmp files (GlueGen, JOGL, et cetera) require code signing.<br />
<br />
If you don't already have a key you want to use, you can create one like this<br />
<br />
<tt>keytool -genkey -keystore testKeys -alias ww</tt><br />
<br />
The <tt>alias</tt> can be anything, I just chose <tt>ww</tt> for this example. Once you have a key, you can sign the JARs like this:<br />
<br />
<pre><br />
jarsigner -keystore testKeys gluegen-rt.jar ww<br />
jarsigner -keystore testKeys jogl.all.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-windows-i586.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-windows-i586.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-windows-amd64.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-windows-amd64.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-linux-i586.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-linux-i586.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-linux-amd64.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-linux-amd64.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-macosx-universal.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-macosx-universal.jar ww<br />
</pre><br />
<br />
Unfortunately, if you sign this way you'll have to type your password every time. Alternately, you can use the [http://ant.apache.org/manual/Tasks/signjar.html Ant &lt;signjar&gt; task] to sign these from an Ant file that contains your password.<br />
<br />
= Running the JWS application locally =<br />
<br />
To run the JWS app locally without a web server, cd to the application directory and type<br />
<br />
<pre>javaws OneTriangleWebStart.jnlp</pre><br />
<br />
This runs the app with the JWS launcher. The result should look just like when we ran the app without the launcher, but there'll be a dialog box that pops up first asking the user's permission to load the app. If you have any JAR signing problems, they should show up at this point.<br />
<br />
= Clearing the JWS cache =<br />
<br />
JWS caches JAR and JNLP files to reduce load time. Unfortunately, if you edit one of these files and re-launch, sometimes you won't see your changes because JWS is still using the cached copy. To clear the JWS cache, type<br />
<br />
<pre>javaws -Xclearcache</pre><br />
<br />
=Running the JWS application from a web server=<br />
<br />
'''*This section is unfinished*'''<br />
<br />
Once you're sure that the JWS application launches correctly from the local file system, you're ready to deploy it to a web server.<br />
<br />
* Create or choose an application directory on your web server.<br />
* Change the <tt>codebase</tt> entries in the JNLP from directory names to URLs that refer to the application directory on your web server.<br />
* Copy all the JAR and JNLP files from your local application directory to the application directory on your web server.<br />
* Put a link to the <tt>OneTriangleWebStart.jnlp</tt> file on a page on your web server (more details [http://download.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/launch.html here]).</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Using_JOGL_in_Java_Web_Start&diff=688Using JOGL in Java Web Start2012-04-19T16:53:54Z<p>Wwalker: Removed nativewindow and newt JARs from command lines</p>
<hr />
<div>You can use JOGL in a [http://download.oracle.com/javase/6/docs/technotes/guides/javaws/ Java Web Start (JWS)] application, which lets you launch a full-featured, standalone Java program from a web page. This page shows an example of how to do this. The example program just draws one triangle that fills a resizable window.<br />
<br />
= Base class =<br />
<br />
First, a base class that we've used before [[Using JOGL in AWT SWT and Swing|here]]. This class draws one triangle, abstracting out all the pure OpenGL calls that don't depend on the choice of window toolkit. Save this file as <tt>OneTriangle.java</tt>.<br />
<br />
<pre><br />
package name.wadewalker.jogl2tests.onetriangle;<br />
<br />
import javax.media.opengl.GL;<br />
import javax.media.opengl.GL2;<br />
import javax.media.opengl.glu.GLU;<br />
<br />
public class OneTriangle {<br />
protected static void setup( GL2 gl2, int width, int height ) {<br />
gl2.glMatrixMode( GL2.GL_PROJECTION );<br />
gl2.glLoadIdentity();<br />
<br />
// coordinate system origin at lower left with width and height same as the window<br />
GLU glu = new GLU();<br />
glu.gluOrtho2D( 0.0f, width, 0.0f, height );<br />
<br />
gl2.glMatrixMode( GL2.GL_MODELVIEW );<br />
gl2.glLoadIdentity();<br />
<br />
gl2.glViewport( 0, 0, width, height );<br />
}<br />
<br />
protected static void render( GL2 gl2, int width, int height ) {<br />
gl2.glClear( GL.GL_COLOR_BUFFER_BIT );<br />
<br />
// draw a triangle filling the window<br />
gl2.glLoadIdentity();<br />
gl2.glBegin( GL.GL_TRIANGLES );<br />
gl2.glColor3f( 1, 0, 0 );<br />
gl2.glVertex2f( 0, 0 );<br />
gl2.glColor3f( 0, 1, 0 );<br />
gl2.glVertex2f( width, 0 );<br />
gl2.glColor3f( 0, 0, 1 );<br />
gl2.glVertex2f( width / 2, height );<br />
gl2.glEnd();<br />
}<br />
}<br />
</pre><br />
<br />
= Drawing a triangle with AWT =<br />
<br />
Now, a class that draws the triangle in an AWT Frame. Java Web Start can use any Java windowing toolkit, we've just chosen this one for convenience. Save this file as <tt>OneTriangleAWT.java.</tt><br />
<br />
<pre><br />
package name.wadewalker.jogl2tests.onetriangle;<br />
<br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLCanvas;<br />
<br />
import java.awt.Frame;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an AWT Frame.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleAWT {<br />
<br />
static {<br />
// setting this true causes window events not to get sent on Linux if you run from inside Eclipse<br />
GLProfile.initSingleton( false );<br />
}<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getWidth(), glautodrawable.getHeight() );<br />
}<br />
});<br />
<br />
final Frame frame = new Frame( "One Triangle AWT" );<br />
frame.add( glcanvas );<br />
frame.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
frame.remove( glcanvas );<br />
frame.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
frame.setSize( 640, 480 );<br />
frame.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= Setting up the application directory =<br />
<br />
* Create a directory to hold your JWS application.<br />
* Create a subdirectory <tt>name/wadewalker/jogl2tests/onetriangle</tt> inside your application directory. Or if you changed the packages of the files above, create a subdirectory that matches your package names.<br />
* Put your <tt>OneTriangle.java</tt> and <tt>OneTriangleAWT.java</tt> files inside the subdirectory.<br />
<br />
== Get local copies of the JogAmp JAR files (optional) ==<br />
<br />
A Java Web Start app can either use its own local copies of the [{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#GluegenJARs GlueGen], [{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#JOGLAllInOneJARs JOGL], and native JAR files, or it can use the copies hosted at jogamp.org.<br />
<br />
Using local copies of the JogAmp JAR files gives you complete control over which version of JOGL your app uses, and guarantees that version will never change unexpectedly. However, it does require more work on your part to install and sign the JARs, and it increases the load on your server.<br />
<br />
To get local copies of the JogAmp JAR files, do this:<br />
<br />
* Read [[Downloading_and_installing_JOGL]] for instructions on how to get the autobuild or released JAR files.<br />
* Copy the following JAR files into the application directory:<br />
<br />
<pre><br />
gluegen-rt.jar<br />
jogl.all.jar<br />
<br />
gluegen-rt-natives-windows-i586.jar<br />
jogl-all-natives-windows-i586.jar<br />
<br />
gluegen-rt-natives-windows-amd64.jar<br />
jogl-all-natives-linux-amd64.jar<br />
<br />
gluegen-rt-natives-linux-i586.jar<br />
jogl-all-natives-linux-i586.jar<br />
<br />
gluegen-rt-natives-linux-amd64.jar<br />
jogl-all-natives-linux-amd64.jar<br />
<br />
gluegen-rt-natives-macosx-universal.jar<br />
jogl-all-natives-macosx-universal.jar<br />
</pre><br />
<br />
= Compiling and JARing your program =<br />
<br />
This step assumes you have Java set up so you can use it from the command line. For instructions on this, see [https://jogamp.org/wiki/index.php/Building_JOGL_on_the_command_line#Install_a_JDK here].<br />
<br />
To compile the program on Windows, cd to your application directory and type<br />
<br />
<pre><br />
javac -classpath "gluegen-rt.jar;jogl.all.jar" name\wadewalker\jogl2tests\onetriangle\*.java<br />
</pre><br />
<br />
To compile the program on Linux or Mac OS X, cd to your application directory and type<br />
<br />
<pre><br />
javac -classpath "gluegen-rt.jar:jogl.all.jar" name\wadewalker\jogl2tests\onetriangle\*.java<br />
</pre><br />
<br />
To JAR the program, type<br />
<br />
<pre><br />
jar cvf onetriangle.jar name\wadewalker\jogl2tests\onetriangle\*.class<br />
</pre><br />
<br />
= Testing your program outside JWS =<br />
<br />
It's probably a good idea to test your program outside JWS first, to make sure it does what you think it should. To do that, you'll need to unzip the native binaries so Java can see them. Since I ran first on Windows 7 64-bit, I unzipped all the <tt>*-natives-windows-amd64.jar</tt> files, the collected the DLLs inside into a directory called <tt>lib-windows-amd64</tt>. Since I test on the other platforms too, I did the same for the other four platforms, creating four more directories <tt>lib-windows-i586</tt>, <tt>lib-linux-i586</tt>, <tt>lib-linux-amd64</tt>, and <tt>lib-macosx-universal</tt>.<br />
<br />
Then to test your program on 64-bit Windows, cd to your application directory and type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar;jogl.all.jar;onetriangle.jar" -Djava.library.path=lib-windows-amd64 name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
On 64-bit Linux, type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar:jogl.all.jar:onetriangle.jar" -Djava.library.path=lib-linux-amd64 name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
On Mac OS X, type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar:jogl.all.jar:onetriangle.jar" -Djava.library.path=lib-macosx-universal name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
The result should look like this:<br />
<br />
[[File:JWS-cmdline-test.png|300px|thumb|none|JWS OneTriangle test]]<br />
<br />
= Writing the JNLP files =<br />
<br />
Read the JWS [http://download.oracle.com/javase/1,5.0/docs/guide/javaws/developersguide/syntax.html Java Network Launching Protocol (JNLP)] specification for details.<br />
<br />
In general we will have one exclusive JNLP file for each application, which will reference the JOGL extension's JNLP file.<br />
The latter may reference even more JNLP files, but this shall not matter in this discussion.<br />
<br />
== Use JogAmp's deployed files ==<br />
<br />
We only have to write our application's JNLP file, since it will reference JogAmp's official released as an extension.<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="OneTriangleWebStart.jnlp"><br />
<br />
<information><br />
<title>OneTriangle Demo</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>OneTriangle Java Web Start Demo</description><br />
<description kind="short">The simplest possible JOGL Java Web Start demo - draws one triangle.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<resources><br />
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/><br />
<property name="sun.java2d.noddraw" value="true"/><br />
<extension name="jogl-all-awt" href="http://jogamp.org/deployment/jogamp-current/jogl-all-awt.jnlp" /><br />
<jar href="onetriangle.jar" main="true"/><br />
</resources><br />
<br />
<application-desc main-class="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT"><br />
</application-desc><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>OneTriangleWebStart.jnlp</tt>.<br />
<br />
If you decide to use our JogAmp signed Jar and Jnlp files you can skip the next chapter.<br />
<br />
== Use your own JogAmp files ==<br />
<br />
Here we have to write the JNLP file for our application and once for our self deployed JogAmp extension.<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="OneTriangleWebStart.jnlp"><br />
<br />
<information><br />
<title>OneTriangle Demo</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>OneTriangle Java Web Start Demo</description><br />
<description kind="short">The simplest possible JOGL Java Web Start demo - draws one triangle.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<resources><br />
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/><br />
<property name="sun.java2d.noddraw" value="true"/><br />
<extension name="JOGL" href="JOGL.jnlp" /><br />
<jar href="onetriangle.jar" main="true"/><br />
</resources><br />
<br />
<application-desc main-class="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT"><br />
</application-desc><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>OneTriangleWebStart.jnlp</tt>.<br />
<br />
Our extension JNLP file for the JOGL JARs looks like this:<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="JOGL.jnlp"><br />
<br />
<information><br />
<title>JOGL libraries</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>JOGL libraries</description><br />
<description kind="short">All JARs and native libraries for JOGL.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<security><br />
<all-permissions/><br />
</security><br />
<br />
<resources><br />
<jar href="gluegen-rt.jar" /><br />
<jar href="jogl.all.jar" /><br />
</resources><br />
<br />
<resources os="Windows" arch="x86"><br />
<nativelib href = "gluegen-rt-natives-windows-i586.jar" /><br />
<nativelib href = "jogl-all-natives-windows-i586.jar" /><br />
</resources><br />
<resources os="Windows" arch="amd64"><br />
<nativelib href = "gluegen-rt-natives-windows-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-windows-amd64.jar" /><br />
</resources><br />
<resources os="Windows" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-windows-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-windows-amd64.jar" /><br />
</resources><br />
<resources os="Linux" arch="i386"><br />
<nativelib href = "gluegen-rt-natives-linux-i586.jar" /><br />
<nativelib href = "jogl-all-natives-linux-i586.jar" /><br />
</resources><br />
<resources os="Linux" arch="x86"><br />
<nativelib href = "gluegen-rt-natives-linux-i586.jar" /><br />
<nativelib href = "jogl-all-natives-linux-i586.jar" /><br />
</resources><br />
<resources os="Linux" arch="amd64"><br />
<nativelib href = "gluegen-rt-natives-linux-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-linux-amd64.jar" /><br />
</resources><br />
<resources os="Linux" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-linux-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-linux-amd64.jar" /><br />
</resources><br />
<resources os="Mac OS X" arch="i386"><br />
<nativelib href = "gluegen-rt-natives-macosx-universal.jar" /><br />
<nativelib href = "jogl-all-natives-macosx-universal.jar" /><br />
</resources><br />
<resources os="Mac OS X" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-macosx-universal.jar" /><br />
<nativelib href = "jogl-all-natives-macosx-universal.jar" /><br />
</resources><br />
<br />
<component-desc /><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>JOGL.jnlp</tt>.<br />
<br />
Note that the <tt>codebase</tt> values are set to the current working directory, and the <tt>href</tt> values are simple filenames. This is so we can test the JNLP app locally, without using a web server. When we put the app on a web server later, the <tt>codebase</tt> and <tt>href</tt> become full URLs.<br />
<br />
=== Signing your JARs ===<br />
<br />
For the JWS app to work properly in a web browser, all its JARs must be signed with the same key. Note that none of your applet JAR files needs to be signed. Only the JogAmp files (GlueGen, JOGL, et cetera) require code signing.<br />
<br />
If you don't already have a key you want to use, you can create one like this<br />
<br />
<tt>keytool -genkey -keystore testKeys -alias ww</tt><br />
<br />
The <tt>alias</tt> can be anything, I just chose <tt>ww</tt> for this example. Once you have a key, you can sign the JARs like this:<br />
<br />
<pre><br />
jarsigner -keystore testKeys gluegen-rt.jar ww<br />
jarsigner -keystore testKeys jogl.all.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-windows-i586.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-windows-i586.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-windows-amd64.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-windows-amd64.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-linux-i586.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-linux-i586.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-linux-amd64.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-linux-amd64.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-macosx-universal.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-macosx-universal.jar ww<br />
</pre><br />
<br />
Unfortunately, if you sign this way you'll have to type your password every time. Alternately, you can use the [http://ant.apache.org/manual/Tasks/signjar.html Ant &lt;signjar&gt; task] to sign these from an Ant file that contains your password.<br />
<br />
= Running the JWS application locally =<br />
<br />
To run the JWS app locally without a web server, cd to the application directory and type<br />
<br />
<pre>javaws OneTriangleWebStart.jnlp</pre><br />
<br />
This runs the app with the JWS launcher. The result should look just like when we ran the app without the launcher, but there'll be a dialog box that pops up first asking the user's permission to load the app. If you have any JAR signing problems, they should show up at this point.<br />
<br />
= Clearing the JWS cache =<br />
<br />
JWS caches JAR and JNLP files to reduce load time. Unfortunately, if you edit one of these files and re-launch, sometimes you won't see your changes because JWS is still using the cached copy. To clear the JWS cache, type<br />
<br />
<pre>javaws -Xclearcache</pre><br />
<br />
=Running the JWS application from a web server=<br />
<br />
'''*This section is unfinished*'''<br />
<br />
Once you're sure that the JWS application launches correctly from the local file system, you're ready to deploy it to a web server.<br />
<br />
* Create or choose an application directory on your web server.<br />
* Change the <tt>codebase</tt> entries in the JNLP from directory names to URLs that refer to the application directory on your web server.<br />
* Copy all the JAR and JNLP files from your local application directory to the application directory on your web server.<br />
* Put a link to the <tt>OneTriangleWebStart.jnlp</tt> file on a page on your web server (more details [http://download.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/launch.html here]).</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Using_JOGL_in_Java_Web_Start&diff=687Using JOGL in Java Web Start2012-04-19T16:51:52Z<p>Wwalker: Augmented explanation of local vs. hosted JAR files</p>
<hr />
<div>You can use JOGL in a [http://download.oracle.com/javase/6/docs/technotes/guides/javaws/ Java Web Start (JWS)] application, which lets you launch a full-featured, standalone Java program from a web page. This page shows an example of how to do this. The example program just draws one triangle that fills a resizable window.<br />
<br />
= Base class =<br />
<br />
First, a base class that we've used before [[Using JOGL in AWT SWT and Swing|here]]. This class draws one triangle, abstracting out all the pure OpenGL calls that don't depend on the choice of window toolkit. Save this file as <tt>OneTriangle.java</tt>.<br />
<br />
<pre><br />
package name.wadewalker.jogl2tests.onetriangle;<br />
<br />
import javax.media.opengl.GL;<br />
import javax.media.opengl.GL2;<br />
import javax.media.opengl.glu.GLU;<br />
<br />
public class OneTriangle {<br />
protected static void setup( GL2 gl2, int width, int height ) {<br />
gl2.glMatrixMode( GL2.GL_PROJECTION );<br />
gl2.glLoadIdentity();<br />
<br />
// coordinate system origin at lower left with width and height same as the window<br />
GLU glu = new GLU();<br />
glu.gluOrtho2D( 0.0f, width, 0.0f, height );<br />
<br />
gl2.glMatrixMode( GL2.GL_MODELVIEW );<br />
gl2.glLoadIdentity();<br />
<br />
gl2.glViewport( 0, 0, width, height );<br />
}<br />
<br />
protected static void render( GL2 gl2, int width, int height ) {<br />
gl2.glClear( GL.GL_COLOR_BUFFER_BIT );<br />
<br />
// draw a triangle filling the window<br />
gl2.glLoadIdentity();<br />
gl2.glBegin( GL.GL_TRIANGLES );<br />
gl2.glColor3f( 1, 0, 0 );<br />
gl2.glVertex2f( 0, 0 );<br />
gl2.glColor3f( 0, 1, 0 );<br />
gl2.glVertex2f( width, 0 );<br />
gl2.glColor3f( 0, 0, 1 );<br />
gl2.glVertex2f( width / 2, height );<br />
gl2.glEnd();<br />
}<br />
}<br />
</pre><br />
<br />
= Drawing a triangle with AWT =<br />
<br />
Now, a class that draws the triangle in an AWT Frame. Java Web Start can use any Java windowing toolkit, we've just chosen this one for convenience. Save this file as <tt>OneTriangleAWT.java.</tt><br />
<br />
<pre><br />
package name.wadewalker.jogl2tests.onetriangle;<br />
<br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLCanvas;<br />
<br />
import java.awt.Frame;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an AWT Frame.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleAWT {<br />
<br />
static {<br />
// setting this true causes window events not to get sent on Linux if you run from inside Eclipse<br />
GLProfile.initSingleton( false );<br />
}<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getWidth(), glautodrawable.getHeight() );<br />
}<br />
});<br />
<br />
final Frame frame = new Frame( "One Triangle AWT" );<br />
frame.add( glcanvas );<br />
frame.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
frame.remove( glcanvas );<br />
frame.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
frame.setSize( 640, 480 );<br />
frame.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= Setting up the application directory =<br />
<br />
* Create a directory to hold your JWS application.<br />
* Create a subdirectory <tt>name/wadewalker/jogl2tests/onetriangle</tt> inside your application directory. Or if you changed the packages of the files above, create a subdirectory that matches your package names.<br />
* Put your <tt>OneTriangle.java</tt> and <tt>OneTriangleAWT.java</tt> files inside the subdirectory.<br />
<br />
== Get local copies of the JogAmp JAR files (optional) ==<br />
<br />
A Java Web Start app can either use its own local copies of the [{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#GluegenJARs GlueGen], [{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#JOGLAllInOneJARs JOGL], and native JAR files, or it can use the copies hosted at jogamp.org.<br />
<br />
Using local copies of the JogAmp JAR files gives you complete control over which version of JOGL your app uses, and guarantees that version will never change unexpectedly. However, it does require more work on your part to install and sign the JARs, and it increases the load on your server.<br />
<br />
To get local copies of the JogAmp JAR files, do this:<br />
<br />
* Read [[Downloading_and_installing_JOGL]] for instructions on how to get the autobuild or released JAR files.<br />
* Copy the following JAR files into the application directory:<br />
<br />
<pre><br />
gluegen-rt.jar<br />
jogl.all.jar<br />
<br />
gluegen-rt-natives-windows-i586.jar<br />
jogl-all-natives-windows-i586.jar<br />
<br />
gluegen-rt-natives-windows-amd64.jar<br />
jogl-all-natives-linux-amd64.jar<br />
<br />
gluegen-rt-natives-linux-i586.jar<br />
jogl-all-natives-linux-i586.jar<br />
<br />
gluegen-rt-natives-linux-amd64.jar<br />
jogl-all-natives-linux-amd64.jar<br />
<br />
gluegen-rt-natives-macosx-universal.jar<br />
jogl-all-natives-macosx-universal.jar<br />
</pre><br />
<br />
= Compiling and JARing your program =<br />
<br />
This step assumes you have Java set up so you can use it from the command line. For instructions on this, see [https://jogamp.org/wiki/index.php/Building_JOGL_on_the_command_line#Install_a_JDK here].<br />
<br />
To compile the program on Windows, cd to your application directory and type<br />
<br />
<pre><br />
javac -classpath "gluegen-rt.jar;nativewindow.all.jar;jogl.all.jar;newt.all.jar" name\wadewalker\jogl2tests\onetriangle\*.java<br />
</pre><br />
<br />
To compile the program on Linux or Mac OS X, cd to your application directory and type<br />
<br />
<pre><br />
javac -classpath "gluegen-rt.jar:nativewindow.all.jar:jogl.all.jar:newt.all.jar" name\wadewalker\jogl2tests\onetriangle\*.java<br />
</pre><br />
<br />
To JAR the program, type<br />
<br />
<pre><br />
jar cvf onetriangle.jar name\wadewalker\jogl2tests\onetriangle\*.class<br />
</pre><br />
<br />
= Testing your program outside JWS =<br />
<br />
It's probably a good idea to test your program outside JWS first, to make sure it does what you think it should. To do that, you'll need to unzip the native binaries so Java can see them. Since I ran first on Windows 7 64-bit, I unzipped all the <tt>*-natives-windows-amd64.jar</tt> files, the collected the DLLs inside into a directory called <tt>lib-windows-amd64</tt>. Since I test on the other platforms too, I did the same for the other four platforms, creating four more directories <tt>lib-windows-i586</tt>, <tt>lib-linux-i586</tt>, <tt>lib-linux-amd64</tt>, and <tt>lib-macosx-universal</tt>.<br />
<br />
Then to test your program on 64-bit Windows, cd to your application directory and type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar;jogl.all.jar;onetriangle.jar" -Djava.library.path=lib-windows-amd64 name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
On 64-bit Linux, type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar:jogl.all.jar:onetriangle.jar" -Djava.library.path=lib-linux-amd64 name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
On Mac OS X, type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar:jogl.all.jar:onetriangle.jar" -Djava.library.path=lib-macosx-universal name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
The result should look like this:<br />
<br />
[[File:JWS-cmdline-test.png|300px|thumb|none|JWS OneTriangle test]]<br />
<br />
= Writing the JNLP files =<br />
<br />
Read the JWS [http://download.oracle.com/javase/1,5.0/docs/guide/javaws/developersguide/syntax.html Java Network Launching Protocol (JNLP)] specification for details.<br />
<br />
In general we will have one exclusive JNLP file for each application, which will reference the JOGL extension's JNLP file.<br />
The latter may reference even more JNLP files, but this shall not matter in this discussion.<br />
<br />
== Use JogAmp's deployed files ==<br />
<br />
We only have to write our application's JNLP file, since it will reference JogAmp's official released as an extension.<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="OneTriangleWebStart.jnlp"><br />
<br />
<information><br />
<title>OneTriangle Demo</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>OneTriangle Java Web Start Demo</description><br />
<description kind="short">The simplest possible JOGL Java Web Start demo - draws one triangle.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<resources><br />
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/><br />
<property name="sun.java2d.noddraw" value="true"/><br />
<extension name="jogl-all-awt" href="http://jogamp.org/deployment/jogamp-current/jogl-all-awt.jnlp" /><br />
<jar href="onetriangle.jar" main="true"/><br />
</resources><br />
<br />
<application-desc main-class="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT"><br />
</application-desc><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>OneTriangleWebStart.jnlp</tt>.<br />
<br />
If you decide to use our JogAmp signed Jar and Jnlp files you can skip the next chapter.<br />
<br />
== Use your own JogAmp files ==<br />
<br />
Here we have to write the JNLP file for our application and once for our self deployed JogAmp extension.<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="OneTriangleWebStart.jnlp"><br />
<br />
<information><br />
<title>OneTriangle Demo</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>OneTriangle Java Web Start Demo</description><br />
<description kind="short">The simplest possible JOGL Java Web Start demo - draws one triangle.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<resources><br />
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/><br />
<property name="sun.java2d.noddraw" value="true"/><br />
<extension name="JOGL" href="JOGL.jnlp" /><br />
<jar href="onetriangle.jar" main="true"/><br />
</resources><br />
<br />
<application-desc main-class="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT"><br />
</application-desc><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>OneTriangleWebStart.jnlp</tt>.<br />
<br />
Our extension JNLP file for the JOGL JARs looks like this:<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="JOGL.jnlp"><br />
<br />
<information><br />
<title>JOGL libraries</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>JOGL libraries</description><br />
<description kind="short">All JARs and native libraries for JOGL.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<security><br />
<all-permissions/><br />
</security><br />
<br />
<resources><br />
<jar href="gluegen-rt.jar" /><br />
<jar href="jogl.all.jar" /><br />
</resources><br />
<br />
<resources os="Windows" arch="x86"><br />
<nativelib href = "gluegen-rt-natives-windows-i586.jar" /><br />
<nativelib href = "jogl-all-natives-windows-i586.jar" /><br />
</resources><br />
<resources os="Windows" arch="amd64"><br />
<nativelib href = "gluegen-rt-natives-windows-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-windows-amd64.jar" /><br />
</resources><br />
<resources os="Windows" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-windows-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-windows-amd64.jar" /><br />
</resources><br />
<resources os="Linux" arch="i386"><br />
<nativelib href = "gluegen-rt-natives-linux-i586.jar" /><br />
<nativelib href = "jogl-all-natives-linux-i586.jar" /><br />
</resources><br />
<resources os="Linux" arch="x86"><br />
<nativelib href = "gluegen-rt-natives-linux-i586.jar" /><br />
<nativelib href = "jogl-all-natives-linux-i586.jar" /><br />
</resources><br />
<resources os="Linux" arch="amd64"><br />
<nativelib href = "gluegen-rt-natives-linux-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-linux-amd64.jar" /><br />
</resources><br />
<resources os="Linux" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-linux-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-linux-amd64.jar" /><br />
</resources><br />
<resources os="Mac OS X" arch="i386"><br />
<nativelib href = "gluegen-rt-natives-macosx-universal.jar" /><br />
<nativelib href = "jogl-all-natives-macosx-universal.jar" /><br />
</resources><br />
<resources os="Mac OS X" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-macosx-universal.jar" /><br />
<nativelib href = "jogl-all-natives-macosx-universal.jar" /><br />
</resources><br />
<br />
<component-desc /><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>JOGL.jnlp</tt>.<br />
<br />
Note that the <tt>codebase</tt> values are set to the current working directory, and the <tt>href</tt> values are simple filenames. This is so we can test the JNLP app locally, without using a web server. When we put the app on a web server later, the <tt>codebase</tt> and <tt>href</tt> become full URLs.<br />
<br />
=== Signing your JARs ===<br />
<br />
For the JWS app to work properly in a web browser, all its JARs must be signed with the same key. Note that none of your applet JAR files needs to be signed. Only the JogAmp files (GlueGen, JOGL, et cetera) require code signing.<br />
<br />
If you don't already have a key you want to use, you can create one like this<br />
<br />
<tt>keytool -genkey -keystore testKeys -alias ww</tt><br />
<br />
The <tt>alias</tt> can be anything, I just chose <tt>ww</tt> for this example. Once you have a key, you can sign the JARs like this:<br />
<br />
<pre><br />
jarsigner -keystore testKeys gluegen-rt.jar ww<br />
jarsigner -keystore testKeys jogl.all.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-windows-i586.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-windows-i586.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-windows-amd64.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-windows-amd64.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-linux-i586.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-linux-i586.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-linux-amd64.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-linux-amd64.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-macosx-universal.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-macosx-universal.jar ww<br />
</pre><br />
<br />
Unfortunately, if you sign this way you'll have to type your password every time. Alternately, you can use the [http://ant.apache.org/manual/Tasks/signjar.html Ant &lt;signjar&gt; task] to sign these from an Ant file that contains your password.<br />
<br />
= Running the JWS application locally =<br />
<br />
To run the JWS app locally without a web server, cd to the application directory and type<br />
<br />
<pre>javaws OneTriangleWebStart.jnlp</pre><br />
<br />
This runs the app with the JWS launcher. The result should look just like when we ran the app without the launcher, but there'll be a dialog box that pops up first asking the user's permission to load the app. If you have any JAR signing problems, they should show up at this point.<br />
<br />
= Clearing the JWS cache =<br />
<br />
JWS caches JAR and JNLP files to reduce load time. Unfortunately, if you edit one of these files and re-launch, sometimes you won't see your changes because JWS is still using the cached copy. To clear the JWS cache, type<br />
<br />
<pre>javaws -Xclearcache</pre><br />
<br />
=Running the JWS application from a web server=<br />
<br />
'''*This section is unfinished*'''<br />
<br />
Once you're sure that the JWS application launches correctly from the local file system, you're ready to deploy it to a web server.<br />
<br />
* Create or choose an application directory on your web server.<br />
* Change the <tt>codebase</tt> entries in the JNLP from directory names to URLs that refer to the application directory on your web server.<br />
* Copy all the JAR and JNLP files from your local application directory to the application directory on your web server.<br />
* Put a link to the <tt>OneTriangleWebStart.jnlp</tt> file on a page on your web server (more details [http://download.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/launch.html here]).</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Using_JOGL_in_Java_Web_Start&diff=686Using JOGL in Java Web Start2012-04-19T15:48:15Z<p>Wwalker: Moved mention of which JARs must be signed into the signing section</p>
<hr />
<div>You can use JOGL in a [http://download.oracle.com/javase/6/docs/technotes/guides/javaws/ Java Web Start (JWS)] application, which lets you launch a full-featured, standalone Java program from a web page. This page shows an example of how to do this. The example program just draws one triangle that fills a resizable window.<br />
<br />
= Base class =<br />
<br />
First, a base class that we've used before [[Using JOGL in AWT SWT and Swing|here]]. This class draws one triangle, abstracting out all the pure OpenGL calls that don't depend on the choice of window toolkit. Save this file as <tt>OneTriangle.java</tt>.<br />
<br />
<pre><br />
package name.wadewalker.jogl2tests.onetriangle;<br />
<br />
import javax.media.opengl.GL;<br />
import javax.media.opengl.GL2;<br />
import javax.media.opengl.glu.GLU;<br />
<br />
public class OneTriangle {<br />
protected static void setup( GL2 gl2, int width, int height ) {<br />
gl2.glMatrixMode( GL2.GL_PROJECTION );<br />
gl2.glLoadIdentity();<br />
<br />
// coordinate system origin at lower left with width and height same as the window<br />
GLU glu = new GLU();<br />
glu.gluOrtho2D( 0.0f, width, 0.0f, height );<br />
<br />
gl2.glMatrixMode( GL2.GL_MODELVIEW );<br />
gl2.glLoadIdentity();<br />
<br />
gl2.glViewport( 0, 0, width, height );<br />
}<br />
<br />
protected static void render( GL2 gl2, int width, int height ) {<br />
gl2.glClear( GL.GL_COLOR_BUFFER_BIT );<br />
<br />
// draw a triangle filling the window<br />
gl2.glLoadIdentity();<br />
gl2.glBegin( GL.GL_TRIANGLES );<br />
gl2.glColor3f( 1, 0, 0 );<br />
gl2.glVertex2f( 0, 0 );<br />
gl2.glColor3f( 0, 1, 0 );<br />
gl2.glVertex2f( width, 0 );<br />
gl2.glColor3f( 0, 0, 1 );<br />
gl2.glVertex2f( width / 2, height );<br />
gl2.glEnd();<br />
}<br />
}<br />
</pre><br />
<br />
= Drawing a triangle with AWT =<br />
<br />
Now, a class that draws the triangle in an AWT Frame. Java Web Start can use any Java windowing toolkit, we've just chosen this one for convenience. Save this file as <tt>OneTriangleAWT.java.</tt><br />
<br />
<pre><br />
package name.wadewalker.jogl2tests.onetriangle;<br />
<br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLCanvas;<br />
<br />
import java.awt.Frame;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an AWT Frame.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleAWT {<br />
<br />
static {<br />
// setting this true causes window events not to get sent on Linux if you run from inside Eclipse<br />
GLProfile.initSingleton( false );<br />
}<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getWidth(), glautodrawable.getHeight() );<br />
}<br />
});<br />
<br />
final Frame frame = new Frame( "One Triangle AWT" );<br />
frame.add( glcanvas );<br />
frame.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
frame.remove( glcanvas );<br />
frame.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
frame.setSize( 640, 480 );<br />
frame.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= Setting up the application directory =<br />
<br />
* Create a directory to hold your JWS application.<br />
* Create a subdirectory <tt>name/wadewalker/jogl2tests/onetriangle</tt> inside your application directory. Or if you changed the packages of the files above, create a subdirectory that matches your package names.<br />
* Put your <tt>OneTriangle.java</tt> and <tt>OneTriangleAWT.java</tt> files inside the subdirectory.<br />
<br />
== Using your own signed JogAmp JAR files (optional) ==<br />
<br />
A Java Web Start app can either use its own local copies of the [{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#GluegenJARs GlueGen] and [{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#JOGLAllInOneJARs JOGL] JAR files, or it can use the copies hosted at jogamp.org. To use local JAR files, do this:<br />
<br />
* Read [[Downloading_and_installing_JOGL]] for instructions on how to get the autobuild or released JAR files.<br />
* Copy the following JAR files into the application directory:<br />
<br />
<pre><br />
gluegen-rt.jar<br />
jogl.all.jar<br />
<br />
gluegen-rt-natives-windows-i586.jar<br />
jogl-all-natives-windows-i586.jar<br />
<br />
gluegen-rt-natives-windows-amd64.jar<br />
jogl-all-natives-linux-amd64.jar<br />
<br />
gluegen-rt-natives-linux-i586.jar<br />
jogl-all-natives-linux-i586.jar<br />
<br />
gluegen-rt-natives-linux-amd64.jar<br />
jogl-all-natives-linux-amd64.jar<br />
<br />
gluegen-rt-natives-macosx-universal.jar<br />
jogl-all-natives-macosx-universal.jar<br />
</pre><br />
<br />
= Compiling and JARing your program =<br />
<br />
This step assumes you have Java set up so you can use it from the command line. For instructions on this, see [https://jogamp.org/wiki/index.php/Building_JOGL_on_the_command_line#Install_a_JDK here].<br />
<br />
To compile the program on Windows, cd to your application directory and type<br />
<br />
<pre><br />
javac -classpath "gluegen-rt.jar;nativewindow.all.jar;jogl.all.jar;newt.all.jar" name\wadewalker\jogl2tests\onetriangle\*.java<br />
</pre><br />
<br />
To compile the program on Linux or Mac OS X, cd to your application directory and type<br />
<br />
<pre><br />
javac -classpath "gluegen-rt.jar:nativewindow.all.jar:jogl.all.jar:newt.all.jar" name\wadewalker\jogl2tests\onetriangle\*.java<br />
</pre><br />
<br />
To JAR the program, type<br />
<br />
<pre><br />
jar cvf onetriangle.jar name\wadewalker\jogl2tests\onetriangle\*.class<br />
</pre><br />
<br />
= Testing your program outside JWS =<br />
<br />
It's probably a good idea to test your program outside JWS first, to make sure it does what you think it should. To do that, you'll need to unzip the native binaries so Java can see them. Since I ran first on Windows 7 64-bit, I unzipped all the <tt>*-natives-windows-amd64.jar</tt> files, the collected the DLLs inside into a directory called <tt>lib-windows-amd64</tt>. Since I test on the other platforms too, I did the same for the other four platforms, creating four more directories <tt>lib-windows-i586</tt>, <tt>lib-linux-i586</tt>, <tt>lib-linux-amd64</tt>, and <tt>lib-macosx-universal</tt>.<br />
<br />
Then to test your program on 64-bit Windows, cd to your application directory and type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar;jogl.all.jar;onetriangle.jar" -Djava.library.path=lib-windows-amd64 name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
On 64-bit Linux, type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar:jogl.all.jar:onetriangle.jar" -Djava.library.path=lib-linux-amd64 name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
On Mac OS X, type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar:jogl.all.jar:onetriangle.jar" -Djava.library.path=lib-macosx-universal name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
The result should look like this:<br />
<br />
[[File:JWS-cmdline-test.png|300px|thumb|none|JWS OneTriangle test]]<br />
<br />
= Writing the JNLP files =<br />
<br />
Read the JWS [http://download.oracle.com/javase/1,5.0/docs/guide/javaws/developersguide/syntax.html Java Network Launching Protocol (JNLP)] specification for details.<br />
<br />
In general we will have one exclusive JNLP file for each application, which will reference the JOGL extension's JNLP file.<br />
The latter may reference even more JNLP files, but this shall not matter in this discussion.<br />
<br />
== Use JogAmp's deployed files ==<br />
<br />
We only have to write our application's JNLP file, since it will reference JogAmp's official released as an extension.<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="OneTriangleWebStart.jnlp"><br />
<br />
<information><br />
<title>OneTriangle Demo</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>OneTriangle Java Web Start Demo</description><br />
<description kind="short">The simplest possible JOGL Java Web Start demo - draws one triangle.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<resources><br />
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/><br />
<property name="sun.java2d.noddraw" value="true"/><br />
<extension name="jogl-all-awt" href="http://jogamp.org/deployment/jogamp-current/jogl-all-awt.jnlp" /><br />
<jar href="onetriangle.jar" main="true"/><br />
</resources><br />
<br />
<application-desc main-class="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT"><br />
</application-desc><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>OneTriangleWebStart.jnlp</tt>.<br />
<br />
If you decide to use our JogAmp signed Jar and Jnlp files you can skip the next chapter.<br />
<br />
== Use your own JogAmp files ==<br />
<br />
Here we have to write the JNLP file for our application and once for our self deployed JogAmp extension.<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="OneTriangleWebStart.jnlp"><br />
<br />
<information><br />
<title>OneTriangle Demo</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>OneTriangle Java Web Start Demo</description><br />
<description kind="short">The simplest possible JOGL Java Web Start demo - draws one triangle.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<resources><br />
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/><br />
<property name="sun.java2d.noddraw" value="true"/><br />
<extension name="JOGL" href="JOGL.jnlp" /><br />
<jar href="onetriangle.jar" main="true"/><br />
</resources><br />
<br />
<application-desc main-class="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT"><br />
</application-desc><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>OneTriangleWebStart.jnlp</tt>.<br />
<br />
Our extension JNLP file for the JOGL JARs looks like this:<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="JOGL.jnlp"><br />
<br />
<information><br />
<title>JOGL libraries</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>JOGL libraries</description><br />
<description kind="short">All JARs and native libraries for JOGL.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<security><br />
<all-permissions/><br />
</security><br />
<br />
<resources><br />
<jar href="gluegen-rt.jar" /><br />
<jar href="jogl.all.jar" /><br />
</resources><br />
<br />
<resources os="Windows" arch="x86"><br />
<nativelib href = "gluegen-rt-natives-windows-i586.jar" /><br />
<nativelib href = "jogl-all-natives-windows-i586.jar" /><br />
</resources><br />
<resources os="Windows" arch="amd64"><br />
<nativelib href = "gluegen-rt-natives-windows-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-windows-amd64.jar" /><br />
</resources><br />
<resources os="Windows" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-windows-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-windows-amd64.jar" /><br />
</resources><br />
<resources os="Linux" arch="i386"><br />
<nativelib href = "gluegen-rt-natives-linux-i586.jar" /><br />
<nativelib href = "jogl-all-natives-linux-i586.jar" /><br />
</resources><br />
<resources os="Linux" arch="x86"><br />
<nativelib href = "gluegen-rt-natives-linux-i586.jar" /><br />
<nativelib href = "jogl-all-natives-linux-i586.jar" /><br />
</resources><br />
<resources os="Linux" arch="amd64"><br />
<nativelib href = "gluegen-rt-natives-linux-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-linux-amd64.jar" /><br />
</resources><br />
<resources os="Linux" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-linux-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-linux-amd64.jar" /><br />
</resources><br />
<resources os="Mac OS X" arch="i386"><br />
<nativelib href = "gluegen-rt-natives-macosx-universal.jar" /><br />
<nativelib href = "jogl-all-natives-macosx-universal.jar" /><br />
</resources><br />
<resources os="Mac OS X" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-macosx-universal.jar" /><br />
<nativelib href = "jogl-all-natives-macosx-universal.jar" /><br />
</resources><br />
<br />
<component-desc /><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>JOGL.jnlp</tt>.<br />
<br />
Note that the <tt>codebase</tt> values are set to the current working directory, and the <tt>href</tt> values are simple filenames. This is so we can test the JNLP app locally, without using a web server. When we put the app on a web server later, the <tt>codebase</tt> and <tt>href</tt> become full URLs.<br />
<br />
=== Signing your JARs ===<br />
<br />
For the JWS app to work properly in a web browser, all its JARs must be signed with the same key. Note that none of your applet JAR files needs to be signed. Only the JogAmp files (GlueGen, JOGL, et cetera) require code signing.<br />
<br />
If you don't already have a key you want to use, you can create one like this<br />
<br />
<tt>keytool -genkey -keystore testKeys -alias ww</tt><br />
<br />
The <tt>alias</tt> can be anything, I just chose <tt>ww</tt> for this example. Once you have a key, you can sign the JARs like this:<br />
<br />
<pre><br />
jarsigner -keystore testKeys gluegen-rt.jar ww<br />
jarsigner -keystore testKeys jogl.all.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-windows-i586.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-windows-i586.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-windows-amd64.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-windows-amd64.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-linux-i586.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-linux-i586.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-linux-amd64.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-linux-amd64.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-macosx-universal.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-macosx-universal.jar ww<br />
</pre><br />
<br />
Unfortunately, if you sign this way you'll have to type your password every time. Alternately, you can use the [http://ant.apache.org/manual/Tasks/signjar.html Ant &lt;signjar&gt; task] to sign these from an Ant file that contains your password.<br />
<br />
= Running the JWS application locally =<br />
<br />
To run the JWS app locally without a web server, cd to the application directory and type<br />
<br />
<pre>javaws OneTriangleWebStart.jnlp</pre><br />
<br />
This runs the app with the JWS launcher. The result should look just like when we ran the app without the launcher, but there'll be a dialog box that pops up first asking the user's permission to load the app. If you have any JAR signing problems, they should show up at this point.<br />
<br />
= Clearing the JWS cache =<br />
<br />
JWS caches JAR and JNLP files to reduce load time. Unfortunately, if you edit one of these files and re-launch, sometimes you won't see your changes because JWS is still using the cached copy. To clear the JWS cache, type<br />
<br />
<pre>javaws -Xclearcache</pre><br />
<br />
=Running the JWS application from a web server=<br />
<br />
'''*This section is unfinished*'''<br />
<br />
Once you're sure that the JWS application launches correctly from the local file system, you're ready to deploy it to a web server.<br />
<br />
* Create or choose an application directory on your web server.<br />
* Change the <tt>codebase</tt> entries in the JNLP from directory names to URLs that refer to the application directory on your web server.<br />
* Copy all the JAR and JNLP files from your local application directory to the application directory on your web server.<br />
* Put a link to the <tt>OneTriangleWebStart.jnlp</tt> file on a page on your web server (more details [http://download.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/launch.html here]).</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Using_JOGL_in_Java_Web_Start&diff=685Using JOGL in Java Web Start2012-04-19T15:46:30Z<p>Wwalker: Added explanation of self-hosted vs. JogAmp-hosted JAR files</p>
<hr />
<div>You can use JOGL in a [http://download.oracle.com/javase/6/docs/technotes/guides/javaws/ Java Web Start (JWS)] application, which lets you launch a full-featured, standalone Java program from a web page. This page shows an example of how to do this. The example program just draws one triangle that fills a resizable window.<br />
<br />
= Base class =<br />
<br />
First, a base class that we've used before [[Using JOGL in AWT SWT and Swing|here]]. This class draws one triangle, abstracting out all the pure OpenGL calls that don't depend on the choice of window toolkit. Save this file as <tt>OneTriangle.java</tt>.<br />
<br />
<pre><br />
package name.wadewalker.jogl2tests.onetriangle;<br />
<br />
import javax.media.opengl.GL;<br />
import javax.media.opengl.GL2;<br />
import javax.media.opengl.glu.GLU;<br />
<br />
public class OneTriangle {<br />
protected static void setup( GL2 gl2, int width, int height ) {<br />
gl2.glMatrixMode( GL2.GL_PROJECTION );<br />
gl2.glLoadIdentity();<br />
<br />
// coordinate system origin at lower left with width and height same as the window<br />
GLU glu = new GLU();<br />
glu.gluOrtho2D( 0.0f, width, 0.0f, height );<br />
<br />
gl2.glMatrixMode( GL2.GL_MODELVIEW );<br />
gl2.glLoadIdentity();<br />
<br />
gl2.glViewport( 0, 0, width, height );<br />
}<br />
<br />
protected static void render( GL2 gl2, int width, int height ) {<br />
gl2.glClear( GL.GL_COLOR_BUFFER_BIT );<br />
<br />
// draw a triangle filling the window<br />
gl2.glLoadIdentity();<br />
gl2.glBegin( GL.GL_TRIANGLES );<br />
gl2.glColor3f( 1, 0, 0 );<br />
gl2.glVertex2f( 0, 0 );<br />
gl2.glColor3f( 0, 1, 0 );<br />
gl2.glVertex2f( width, 0 );<br />
gl2.glColor3f( 0, 0, 1 );<br />
gl2.glVertex2f( width / 2, height );<br />
gl2.glEnd();<br />
}<br />
}<br />
</pre><br />
<br />
= Drawing a triangle with AWT =<br />
<br />
Now, a class that draws the triangle in an AWT Frame. Java Web Start can use any Java windowing toolkit, we've just chosen this one for convenience. Save this file as <tt>OneTriangleAWT.java.</tt><br />
<br />
<pre><br />
package name.wadewalker.jogl2tests.onetriangle;<br />
<br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLCanvas;<br />
<br />
import java.awt.Frame;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an AWT Frame.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleAWT {<br />
<br />
static {<br />
// setting this true causes window events not to get sent on Linux if you run from inside Eclipse<br />
GLProfile.initSingleton( false );<br />
}<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getWidth(), glautodrawable.getHeight() );<br />
}<br />
});<br />
<br />
final Frame frame = new Frame( "One Triangle AWT" );<br />
frame.add( glcanvas );<br />
frame.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
frame.remove( glcanvas );<br />
frame.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
frame.setSize( 640, 480 );<br />
frame.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= Setting up the application directory =<br />
<br />
* Create a directory to hold your JWS application.<br />
* Create a subdirectory <tt>name/wadewalker/jogl2tests/onetriangle</tt> inside your application directory. Or if you changed the packages of the files above, create a subdirectory that matches your package names.<br />
* Put your <tt>OneTriangle.java</tt> and <tt>OneTriangleAWT.java</tt> files inside the subdirectory.<br />
<br />
Note that none of your applet JAR files needs to be signed. Only the JogAmp files (GlueGen, JOGL, et cetera) require code signing.<br />
<br />
== Using your own signed JogAmp JAR files (optional) ==<br />
<br />
A Java Web Start app can either use its own local copies of the [{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#GluegenJARs GlueGen] and [{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#JOGLAllInOneJARs JOGL] JAR files, or it can use the copies hosted at jogamp.org. To use local JAR files, do this:<br />
<br />
* Read [[Downloading_and_installing_JOGL]] for instructions on how to get the autobuild or released JAR files.<br />
* Copy the following JAR files into the application directory:<br />
<br />
<pre><br />
gluegen-rt.jar<br />
jogl.all.jar<br />
<br />
gluegen-rt-natives-windows-i586.jar<br />
jogl-all-natives-windows-i586.jar<br />
<br />
gluegen-rt-natives-windows-amd64.jar<br />
jogl-all-natives-linux-amd64.jar<br />
<br />
gluegen-rt-natives-linux-i586.jar<br />
jogl-all-natives-linux-i586.jar<br />
<br />
gluegen-rt-natives-linux-amd64.jar<br />
jogl-all-natives-linux-amd64.jar<br />
<br />
gluegen-rt-natives-macosx-universal.jar<br />
jogl-all-natives-macosx-universal.jar<br />
</pre><br />
<br />
= Compiling and JARing your program =<br />
<br />
This step assumes you have Java set up so you can use it from the command line. For instructions on this, see [https://jogamp.org/wiki/index.php/Building_JOGL_on_the_command_line#Install_a_JDK here].<br />
<br />
To compile the program on Windows, cd to your application directory and type<br />
<br />
<pre><br />
javac -classpath "gluegen-rt.jar;nativewindow.all.jar;jogl.all.jar;newt.all.jar" name\wadewalker\jogl2tests\onetriangle\*.java<br />
</pre><br />
<br />
To compile the program on Linux or Mac OS X, cd to your application directory and type<br />
<br />
<pre><br />
javac -classpath "gluegen-rt.jar:nativewindow.all.jar:jogl.all.jar:newt.all.jar" name\wadewalker\jogl2tests\onetriangle\*.java<br />
</pre><br />
<br />
To JAR the program, type<br />
<br />
<pre><br />
jar cvf onetriangle.jar name\wadewalker\jogl2tests\onetriangle\*.class<br />
</pre><br />
<br />
= Testing your program outside JWS =<br />
<br />
It's probably a good idea to test your program outside JWS first, to make sure it does what you think it should. To do that, you'll need to unzip the native binaries so Java can see them. Since I ran first on Windows 7 64-bit, I unzipped all the <tt>*-natives-windows-amd64.jar</tt> files, the collected the DLLs inside into a directory called <tt>lib-windows-amd64</tt>. Since I test on the other platforms too, I did the same for the other four platforms, creating four more directories <tt>lib-windows-i586</tt>, <tt>lib-linux-i586</tt>, <tt>lib-linux-amd64</tt>, and <tt>lib-macosx-universal</tt>.<br />
<br />
Then to test your program on 64-bit Windows, cd to your application directory and type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar;jogl.all.jar;onetriangle.jar" -Djava.library.path=lib-windows-amd64 name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
On 64-bit Linux, type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar:jogl.all.jar:onetriangle.jar" -Djava.library.path=lib-linux-amd64 name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
On Mac OS X, type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar:jogl.all.jar:onetriangle.jar" -Djava.library.path=lib-macosx-universal name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
The result should look like this:<br />
<br />
[[File:JWS-cmdline-test.png|300px|thumb|none|JWS OneTriangle test]]<br />
<br />
= Writing the JNLP files =<br />
<br />
Read the JWS [http://download.oracle.com/javase/1,5.0/docs/guide/javaws/developersguide/syntax.html Java Network Launching Protocol (JNLP)] specification for details.<br />
<br />
In general we will have one exclusive JNLP file for each application, which will reference the JOGL extension's JNLP file.<br />
The latter may reference even more JNLP files, but this shall not matter in this discussion.<br />
<br />
== Use JogAmp's deployed files ==<br />
<br />
We only have to write our application's JNLP file, since it will reference JogAmp's official released as an extension.<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="OneTriangleWebStart.jnlp"><br />
<br />
<information><br />
<title>OneTriangle Demo</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>OneTriangle Java Web Start Demo</description><br />
<description kind="short">The simplest possible JOGL Java Web Start demo - draws one triangle.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<resources><br />
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/><br />
<property name="sun.java2d.noddraw" value="true"/><br />
<extension name="jogl-all-awt" href="http://jogamp.org/deployment/jogamp-current/jogl-all-awt.jnlp" /><br />
<jar href="onetriangle.jar" main="true"/><br />
</resources><br />
<br />
<application-desc main-class="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT"><br />
</application-desc><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>OneTriangleWebStart.jnlp</tt>.<br />
<br />
If you decide to use our JogAmp signed Jar and Jnlp files you can skip the next chapter.<br />
<br />
== Use your own JogAmp files ==<br />
<br />
Here we have to write the JNLP file for our application and once for our self deployed JogAmp extension.<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="OneTriangleWebStart.jnlp"><br />
<br />
<information><br />
<title>OneTriangle Demo</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>OneTriangle Java Web Start Demo</description><br />
<description kind="short">The simplest possible JOGL Java Web Start demo - draws one triangle.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<resources><br />
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/><br />
<property name="sun.java2d.noddraw" value="true"/><br />
<extension name="JOGL" href="JOGL.jnlp" /><br />
<jar href="onetriangle.jar" main="true"/><br />
</resources><br />
<br />
<application-desc main-class="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT"><br />
</application-desc><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>OneTriangleWebStart.jnlp</tt>.<br />
<br />
Our extension JNLP file for the JOGL JARs looks like this:<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="JOGL.jnlp"><br />
<br />
<information><br />
<title>JOGL libraries</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>JOGL libraries</description><br />
<description kind="short">All JARs and native libraries for JOGL.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<security><br />
<all-permissions/><br />
</security><br />
<br />
<resources><br />
<jar href="gluegen-rt.jar" /><br />
<jar href="jogl.all.jar" /><br />
</resources><br />
<br />
<resources os="Windows" arch="x86"><br />
<nativelib href = "gluegen-rt-natives-windows-i586.jar" /><br />
<nativelib href = "jogl-all-natives-windows-i586.jar" /><br />
</resources><br />
<resources os="Windows" arch="amd64"><br />
<nativelib href = "gluegen-rt-natives-windows-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-windows-amd64.jar" /><br />
</resources><br />
<resources os="Windows" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-windows-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-windows-amd64.jar" /><br />
</resources><br />
<resources os="Linux" arch="i386"><br />
<nativelib href = "gluegen-rt-natives-linux-i586.jar" /><br />
<nativelib href = "jogl-all-natives-linux-i586.jar" /><br />
</resources><br />
<resources os="Linux" arch="x86"><br />
<nativelib href = "gluegen-rt-natives-linux-i586.jar" /><br />
<nativelib href = "jogl-all-natives-linux-i586.jar" /><br />
</resources><br />
<resources os="Linux" arch="amd64"><br />
<nativelib href = "gluegen-rt-natives-linux-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-linux-amd64.jar" /><br />
</resources><br />
<resources os="Linux" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-linux-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-linux-amd64.jar" /><br />
</resources><br />
<resources os="Mac OS X" arch="i386"><br />
<nativelib href = "gluegen-rt-natives-macosx-universal.jar" /><br />
<nativelib href = "jogl-all-natives-macosx-universal.jar" /><br />
</resources><br />
<resources os="Mac OS X" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-macosx-universal.jar" /><br />
<nativelib href = "jogl-all-natives-macosx-universal.jar" /><br />
</resources><br />
<br />
<component-desc /><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>JOGL.jnlp</tt>.<br />
<br />
Note that the <tt>codebase</tt> values are set to the current working directory, and the <tt>href</tt> values are simple filenames. This is so we can test the JNLP app locally, without using a web server. When we put the app on a web server later, the <tt>codebase</tt> and <tt>href</tt> become full URLs.<br />
<br />
=== Signing your JARs ===<br />
<br />
For the JWS app to work properly in a web browser, all its JARs must be signed with the same key. If you don't already have a key you want to use, you can create one like this<br />
<br />
<tt>keytool -genkey -keystore testKeys -alias ww</tt><br />
<br />
The <tt>alias</tt> can be anything, I just chose <tt>ww</tt> for this example. Once you have a key, you can sign the JARs like this:<br />
<br />
<pre><br />
jarsigner -keystore testKeys gluegen-rt.jar ww<br />
jarsigner -keystore testKeys jogl.all.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-windows-i586.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-windows-i586.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-windows-amd64.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-windows-amd64.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-linux-i586.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-linux-i586.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-linux-amd64.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-linux-amd64.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-macosx-universal.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-macosx-universal.jar ww<br />
</pre><br />
<br />
Unfortunately, if you sign this way you'll have to type your password every time. Alternately, you can use the [http://ant.apache.org/manual/Tasks/signjar.html Ant &lt;signjar&gt; task] to sign these from an Ant file that contains your password.<br />
<br />
= Running the JWS application locally =<br />
<br />
To run the JWS app locally without a web server, cd to the application directory and type<br />
<br />
<pre>javaws OneTriangleWebStart.jnlp</pre><br />
<br />
This runs the app with the JWS launcher. The result should look just like when we ran the app without the launcher, but there'll be a dialog box that pops up first asking the user's permission to load the app. If you have any JAR signing problems, they should show up at this point.<br />
<br />
= Clearing the JWS cache =<br />
<br />
JWS caches JAR and JNLP files to reduce load time. Unfortunately, if you edit one of these files and re-launch, sometimes you won't see your changes because JWS is still using the cached copy. To clear the JWS cache, type<br />
<br />
<pre>javaws -Xclearcache</pre><br />
<br />
=Running the JWS application from a web server=<br />
<br />
'''*This section is unfinished*'''<br />
<br />
Once you're sure that the JWS application launches correctly from the local file system, you're ready to deploy it to a web server.<br />
<br />
* Create or choose an application directory on your web server.<br />
* Change the <tt>codebase</tt> entries in the JNLP from directory names to URLs that refer to the application directory on your web server.<br />
* Copy all the JAR and JNLP files from your local application directory to the application directory on your web server.<br />
* Put a link to the <tt>OneTriangleWebStart.jnlp</tt> file on a page on your web server (more details [http://download.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/launch.html here]).</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Using_JOGL_in_Java_Web_Start&diff=684Using JOGL in Java Web Start2012-04-19T15:39:05Z<p>Wwalker: Fixed links href text</p>
<hr />
<div>You can use JOGL in a [http://download.oracle.com/javase/6/docs/technotes/guides/javaws/ Java Web Start (JWS)] application, which lets you launch a full-featured, standalone Java program from a web page. This page shows an example of how to do this. The example program just draws one triangle that fills a resizable window.<br />
<br />
= Base class =<br />
<br />
First, a base class that we've used before [[Using JOGL in AWT SWT and Swing|here]]. This class draws one triangle, abstracting out all the pure OpenGL calls that don't depend on the choice of window toolkit. Save this file as <tt>OneTriangle.java</tt>.<br />
<br />
<pre><br />
package name.wadewalker.jogl2tests.onetriangle;<br />
<br />
import javax.media.opengl.GL;<br />
import javax.media.opengl.GL2;<br />
import javax.media.opengl.glu.GLU;<br />
<br />
public class OneTriangle {<br />
protected static void setup( GL2 gl2, int width, int height ) {<br />
gl2.glMatrixMode( GL2.GL_PROJECTION );<br />
gl2.glLoadIdentity();<br />
<br />
// coordinate system origin at lower left with width and height same as the window<br />
GLU glu = new GLU();<br />
glu.gluOrtho2D( 0.0f, width, 0.0f, height );<br />
<br />
gl2.glMatrixMode( GL2.GL_MODELVIEW );<br />
gl2.glLoadIdentity();<br />
<br />
gl2.glViewport( 0, 0, width, height );<br />
}<br />
<br />
protected static void render( GL2 gl2, int width, int height ) {<br />
gl2.glClear( GL.GL_COLOR_BUFFER_BIT );<br />
<br />
// draw a triangle filling the window<br />
gl2.glLoadIdentity();<br />
gl2.glBegin( GL.GL_TRIANGLES );<br />
gl2.glColor3f( 1, 0, 0 );<br />
gl2.glVertex2f( 0, 0 );<br />
gl2.glColor3f( 0, 1, 0 );<br />
gl2.glVertex2f( width, 0 );<br />
gl2.glColor3f( 0, 0, 1 );<br />
gl2.glVertex2f( width / 2, height );<br />
gl2.glEnd();<br />
}<br />
}<br />
</pre><br />
<br />
= Drawing a triangle with AWT =<br />
<br />
Now, a class that draws the triangle in an AWT Frame. Java Web Start can use any Java windowing toolkit, we've just chosen this one for convenience. Save this file as <tt>OneTriangleAWT.java.</tt><br />
<br />
<pre><br />
package name.wadewalker.jogl2tests.onetriangle;<br />
<br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLCanvas;<br />
<br />
import java.awt.Frame;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an AWT Frame.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleAWT {<br />
<br />
static {<br />
// setting this true causes window events not to get sent on Linux if you run from inside Eclipse<br />
GLProfile.initSingleton( false );<br />
}<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getWidth(), glautodrawable.getHeight() );<br />
}<br />
});<br />
<br />
final Frame frame = new Frame( "One Triangle AWT" );<br />
frame.add( glcanvas );<br />
frame.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
frame.remove( glcanvas );<br />
frame.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
frame.setSize( 640, 480 );<br />
frame.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= Setting up the application directory =<br />
<br />
Note that none of your applet JAR files needs to be signed. Only the JogAmp files (GlueGen, JOGL, et cetera) require code signing.<br />
<br />
* Create a directory to hold your JWS application.<br />
* Create a subdirectory <tt>name/wadewalker/jogl2tests/onetriangle</tt> inside your application directory. Or if you changed the packages of the files above, create a subdirectory that matches your package names.<br />
* Put your <tt>OneTriangle.java</tt> and <tt>OneTriangleAWT.java</tt> files inside the subdirectory.<br />
<br />
If you decide to use the signed JAR and JNLP files hosted by JogAmp you can skip the next chapter.<br />
<br />
== Using your own signed JAR and JNLP files ==<br />
* Copy all JogAmp JAR files (both [{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#GluegenJARs GlueGen] and [{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#JOGLAllInOneJARs JOGL]) into the application directory. <br />
** Read [[Downloading_and_installing_JOGL]] for instructions on how to get the autobuild or released JAR and JNLP files.<br />
* Copy the JogAmp [{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#JNLPFiles JNLP files] into that application directory<br />
<br />
Here's a list of the files you should copy:<br />
<br />
<pre><br />
gluegen-rt.jar<br />
jogl.all.jar<br />
<br />
gluegen-rt-natives-windows-i586.jar<br />
jogl-all-natives-windows-i586.jar<br />
<br />
gluegen-rt-natives-windows-amd64.jar<br />
jogl-all-natives-linux-amd64.jar<br />
<br />
gluegen-rt-natives-linux-i586.jar<br />
jogl-all-natives-linux-i586.jar<br />
<br />
gluegen-rt-natives-linux-amd64.jar<br />
jogl-all-natives-linux-amd64.jar<br />
<br />
gluegen-rt-natives-macosx-universal.jar<br />
jogl-all-natives-macosx-universal.jar<br />
</pre><br />
<br />
= Compiling and JARing your program =<br />
<br />
This step assumes you have Java set up so you can use it from the command line. For instructions on this, see [https://jogamp.org/wiki/index.php/Building_JOGL_on_the_command_line#Install_a_JDK here].<br />
<br />
To compile the program on Windows, cd to your application directory and type<br />
<br />
<pre><br />
javac -classpath "gluegen-rt.jar;nativewindow.all.jar;jogl.all.jar;newt.all.jar" name\wadewalker\jogl2tests\onetriangle\*.java<br />
</pre><br />
<br />
To compile the program on Linux or Mac OS X, cd to your application directory and type<br />
<br />
<pre><br />
javac -classpath "gluegen-rt.jar:nativewindow.all.jar:jogl.all.jar:newt.all.jar" name\wadewalker\jogl2tests\onetriangle\*.java<br />
</pre><br />
<br />
To JAR the program, type<br />
<br />
<pre><br />
jar cvf onetriangle.jar name\wadewalker\jogl2tests\onetriangle\*.class<br />
</pre><br />
<br />
= Testing your program outside JWS =<br />
<br />
It's probably a good idea to test your program outside JWS first, to make sure it does what you think it should. To do that, you'll need to unzip the native binaries so Java can see them. Since I ran first on Windows 7 64-bit, I unzipped all the <tt>*-natives-windows-amd64.jar</tt> files, the collected the DLLs inside into a directory called <tt>lib-windows-amd64</tt>. Since I test on the other platforms too, I did the same for the other four platforms, creating four more directories <tt>lib-windows-i586</tt>, <tt>lib-linux-i586</tt>, <tt>lib-linux-amd64</tt>, and <tt>lib-macosx-universal</tt>.<br />
<br />
Then to test your program on 64-bit Windows, cd to your application directory and type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar;jogl.all.jar;onetriangle.jar" -Djava.library.path=lib-windows-amd64 name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
On 64-bit Linux, type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar:jogl.all.jar:onetriangle.jar" -Djava.library.path=lib-linux-amd64 name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
On Mac OS X, type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar:jogl.all.jar:onetriangle.jar" -Djava.library.path=lib-macosx-universal name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
The result should look like this:<br />
<br />
[[File:JWS-cmdline-test.png|300px|thumb|none|JWS OneTriangle test]]<br />
<br />
= Writing the JNLP files =<br />
<br />
Read the JWS [http://download.oracle.com/javase/1,5.0/docs/guide/javaws/developersguide/syntax.html Java Network Launching Protocol (JNLP)] specification for details.<br />
<br />
In general we will have one exclusive JNLP file for each application, which will reference the JOGL extension's JNLP file.<br />
The latter may reference even more JNLP files, but this shall not matter in this discussion.<br />
<br />
== Use JogAmp's deployed files ==<br />
<br />
We only have to write our application's JNLP file, since it will reference JogAmp's official released as an extension.<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="OneTriangleWebStart.jnlp"><br />
<br />
<information><br />
<title>OneTriangle Demo</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>OneTriangle Java Web Start Demo</description><br />
<description kind="short">The simplest possible JOGL Java Web Start demo - draws one triangle.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<resources><br />
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/><br />
<property name="sun.java2d.noddraw" value="true"/><br />
<extension name="jogl-all-awt" href="http://jogamp.org/deployment/jogamp-current/jogl-all-awt.jnlp" /><br />
<jar href="onetriangle.jar" main="true"/><br />
</resources><br />
<br />
<application-desc main-class="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT"><br />
</application-desc><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>OneTriangleWebStart.jnlp</tt>.<br />
<br />
If you decide to use our JogAmp signed Jar and Jnlp files you can skip the next chapter.<br />
<br />
== Use your own JogAmp files ==<br />
<br />
Here we have to write the JNLP file for our application and once for our self deployed JogAmp extension.<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="OneTriangleWebStart.jnlp"><br />
<br />
<information><br />
<title>OneTriangle Demo</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>OneTriangle Java Web Start Demo</description><br />
<description kind="short">The simplest possible JOGL Java Web Start demo - draws one triangle.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<resources><br />
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/><br />
<property name="sun.java2d.noddraw" value="true"/><br />
<extension name="JOGL" href="JOGL.jnlp" /><br />
<jar href="onetriangle.jar" main="true"/><br />
</resources><br />
<br />
<application-desc main-class="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT"><br />
</application-desc><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>OneTriangleWebStart.jnlp</tt>.<br />
<br />
Our extension JNLP file for the JOGL JARs looks like this:<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="JOGL.jnlp"><br />
<br />
<information><br />
<title>JOGL libraries</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>JOGL libraries</description><br />
<description kind="short">All JARs and native libraries for JOGL.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<security><br />
<all-permissions/><br />
</security><br />
<br />
<resources><br />
<jar href="gluegen-rt.jar" /><br />
<jar href="jogl.all.jar" /><br />
</resources><br />
<br />
<resources os="Windows" arch="x86"><br />
<nativelib href = "gluegen-rt-natives-windows-i586.jar" /><br />
<nativelib href = "jogl-all-natives-windows-i586.jar" /><br />
</resources><br />
<resources os="Windows" arch="amd64"><br />
<nativelib href = "gluegen-rt-natives-windows-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-windows-amd64.jar" /><br />
</resources><br />
<resources os="Windows" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-windows-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-windows-amd64.jar" /><br />
</resources><br />
<resources os="Linux" arch="i386"><br />
<nativelib href = "gluegen-rt-natives-linux-i586.jar" /><br />
<nativelib href = "jogl-all-natives-linux-i586.jar" /><br />
</resources><br />
<resources os="Linux" arch="x86"><br />
<nativelib href = "gluegen-rt-natives-linux-i586.jar" /><br />
<nativelib href = "jogl-all-natives-linux-i586.jar" /><br />
</resources><br />
<resources os="Linux" arch="amd64"><br />
<nativelib href = "gluegen-rt-natives-linux-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-linux-amd64.jar" /><br />
</resources><br />
<resources os="Linux" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-linux-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-linux-amd64.jar" /><br />
</resources><br />
<resources os="Mac OS X" arch="i386"><br />
<nativelib href = "gluegen-rt-natives-macosx-universal.jar" /><br />
<nativelib href = "jogl-all-natives-macosx-universal.jar" /><br />
</resources><br />
<resources os="Mac OS X" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-macosx-universal.jar" /><br />
<nativelib href = "jogl-all-natives-macosx-universal.jar" /><br />
</resources><br />
<br />
<component-desc /><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>JOGL.jnlp</tt>.<br />
<br />
Note that the <tt>codebase</tt> values are set to the current working directory, and the <tt>href</tt> values are simple filenames. This is so we can test the JNLP app locally, without using a web server. When we put the app on a web server later, the <tt>codebase</tt> and <tt>href</tt> become full URLs.<br />
<br />
=== Signing your JARs ===<br />
<br />
For the JWS app to work properly in a web browser, all its JARs must be signed with the same key. If you don't already have a key you want to use, you can create one like this<br />
<br />
<tt>keytool -genkey -keystore testKeys -alias ww</tt><br />
<br />
The <tt>alias</tt> can be anything, I just chose <tt>ww</tt> for this example. Once you have a key, you can sign the JARs like this:<br />
<br />
<pre><br />
jarsigner -keystore testKeys gluegen-rt.jar ww<br />
jarsigner -keystore testKeys jogl.all.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-windows-i586.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-windows-i586.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-windows-amd64.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-windows-amd64.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-linux-i586.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-linux-i586.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-linux-amd64.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-linux-amd64.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-macosx-universal.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-macosx-universal.jar ww<br />
</pre><br />
<br />
Unfortunately, if you sign this way you'll have to type your password every time. Alternately, you can use the [http://ant.apache.org/manual/Tasks/signjar.html Ant &lt;signjar&gt; task] to sign these from an Ant file that contains your password.<br />
<br />
= Running the JWS application locally =<br />
<br />
To run the JWS app locally without a web server, cd to the application directory and type<br />
<br />
<pre>javaws OneTriangleWebStart.jnlp</pre><br />
<br />
This runs the app with the JWS launcher. The result should look just like when we ran the app without the launcher, but there'll be a dialog box that pops up first asking the user's permission to load the app. If you have any JAR signing problems, they should show up at this point.<br />
<br />
= Clearing the JWS cache =<br />
<br />
JWS caches JAR and JNLP files to reduce load time. Unfortunately, if you edit one of these files and re-launch, sometimes you won't see your changes because JWS is still using the cached copy. To clear the JWS cache, type<br />
<br />
<pre>javaws -Xclearcache</pre><br />
<br />
=Running the JWS application from a web server=<br />
<br />
'''*This section is unfinished*'''<br />
<br />
Once you're sure that the JWS application launches correctly from the local file system, you're ready to deploy it to a web server.<br />
<br />
* Create or choose an application directory on your web server.<br />
* Change the <tt>codebase</tt> entries in the JNLP from directory names to URLs that refer to the application directory on your web server.<br />
* Copy all the JAR and JNLP files from your local application directory to the application directory on your web server.<br />
* Put a link to the <tt>OneTriangleWebStart.jnlp</tt> file on a page on your web server (more details [http://download.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/launch.html here]).</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Using_JOGL_in_Java_Web_Start&diff=683Using JOGL in Java Web Start2012-04-19T15:28:30Z<p>Wwalker: Fixed caps</p>
<hr />
<div>You can use JOGL in a [http://download.oracle.com/javase/6/docs/technotes/guides/javaws/ Java Web Start (JWS)] application, which lets you launch a full-featured, standalone Java program from a web page. This page shows an example of how to do this. The example program just draws one triangle that fills a resizable window.<br />
<br />
= Base class =<br />
<br />
First, a base class that we've used before [[Using JOGL in AWT SWT and Swing|here]]. This class draws one triangle, abstracting out all the pure OpenGL calls that don't depend on the choice of window toolkit. Save this file as <tt>OneTriangle.java</tt>.<br />
<br />
<pre><br />
package name.wadewalker.jogl2tests.onetriangle;<br />
<br />
import javax.media.opengl.GL;<br />
import javax.media.opengl.GL2;<br />
import javax.media.opengl.glu.GLU;<br />
<br />
public class OneTriangle {<br />
protected static void setup( GL2 gl2, int width, int height ) {<br />
gl2.glMatrixMode( GL2.GL_PROJECTION );<br />
gl2.glLoadIdentity();<br />
<br />
// coordinate system origin at lower left with width and height same as the window<br />
GLU glu = new GLU();<br />
glu.gluOrtho2D( 0.0f, width, 0.0f, height );<br />
<br />
gl2.glMatrixMode( GL2.GL_MODELVIEW );<br />
gl2.glLoadIdentity();<br />
<br />
gl2.glViewport( 0, 0, width, height );<br />
}<br />
<br />
protected static void render( GL2 gl2, int width, int height ) {<br />
gl2.glClear( GL.GL_COLOR_BUFFER_BIT );<br />
<br />
// draw a triangle filling the window<br />
gl2.glLoadIdentity();<br />
gl2.glBegin( GL.GL_TRIANGLES );<br />
gl2.glColor3f( 1, 0, 0 );<br />
gl2.glVertex2f( 0, 0 );<br />
gl2.glColor3f( 0, 1, 0 );<br />
gl2.glVertex2f( width, 0 );<br />
gl2.glColor3f( 0, 0, 1 );<br />
gl2.glVertex2f( width / 2, height );<br />
gl2.glEnd();<br />
}<br />
}<br />
</pre><br />
<br />
= Drawing a triangle with AWT =<br />
<br />
Now, a class that draws the triangle in an AWT Frame. Java Web Start can use any Java windowing toolkit, we've just chosen this one for convenience. Save this file as <tt>OneTriangleAWT.java.</tt><br />
<br />
<pre><br />
package name.wadewalker.jogl2tests.onetriangle;<br />
<br />
import javax.media.opengl.GLAutoDrawable;<br />
import javax.media.opengl.GLEventListener;<br />
import javax.media.opengl.GLProfile;<br />
import javax.media.opengl.GLCapabilities;<br />
import javax.media.opengl.awt.GLCanvas;<br />
<br />
import java.awt.Frame;<br />
import java.awt.event.WindowAdapter;<br />
import java.awt.event.WindowEvent;<br />
<br />
/**<br />
* A minimal program that draws with JOGL in an AWT Frame.<br />
*<br />
* @author Wade Walker<br />
*/<br />
public class OneTriangleAWT {<br />
<br />
static {<br />
// setting this true causes window events not to get sent on Linux if you run from inside Eclipse<br />
GLProfile.initSingleton( false );<br />
}<br />
<br />
public static void main( String [] args ) {<br />
GLProfile glprofile = GLProfile.getDefault();<br />
GLCapabilities glcapabilities = new GLCapabilities( glprofile );<br />
final GLCanvas glcanvas = new GLCanvas( glcapabilities );<br />
<br />
glcanvas.addGLEventListener( new GLEventListener() {<br />
<br />
@Override<br />
public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {<br />
OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );<br />
}<br />
<br />
@Override<br />
public void init( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void dispose( GLAutoDrawable glautodrawable ) {<br />
}<br />
<br />
@Override<br />
public void display( GLAutoDrawable glautodrawable ) {<br />
OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getWidth(), glautodrawable.getHeight() );<br />
}<br />
});<br />
<br />
final Frame frame = new Frame( "One Triangle AWT" );<br />
frame.add( glcanvas );<br />
frame.addWindowListener( new WindowAdapter() {<br />
public void windowClosing( WindowEvent windowevent ) {<br />
frame.remove( glcanvas );<br />
frame.dispose();<br />
System.exit( 0 );<br />
}<br />
});<br />
<br />
frame.setSize( 640, 480 );<br />
frame.setVisible( true );<br />
}<br />
}<br />
</pre><br />
<br />
= Setting up the application directory =<br />
<br />
Note that none of your applet JAR files needs to be signed. Only the JogAmp files (GlueGen, JOGL, et cetera) require code signing.<br />
<br />
* Create a directory to hold your JWS application.<br />
* Create a subdirectory <tt>name/wadewalker/jogl2tests/onetriangle</tt> inside your application directory. Or if you changed the packages of the files above, create a subdirectory that matches your package names.<br />
* Put your <tt>OneTriangle.java</tt> and <tt>OneTriangleAWT.java</tt> files inside the subdirectory.<br />
<br />
If you decide to use the signed JAR and JNLP files hosted by JogAmp you can skip the next chapter.<br />
<br />
== Using your own signed JAR and JNLP files ==<br />
* Copy all JogAmp JAR files ([[{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#GluegenJARs|GlueGen]] and [[{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#JOGLAllInOneJARs|JOGL]]) into the application directory. <br />
** Read [[Downloading_and_installing_JOGL]] for getting the autobuild or released JAR and JNLP files<br />
* Copy the JogAmp [[{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#JNLPFiles|JNLP files]] into that application directory<br />
<br />
<pre><br />
gluegen-rt.jar<br />
jogl.all.jar<br />
<br />
gluegen-rt-natives-windows-i586.jar<br />
jogl-all-natives-windows-i586.jar<br />
<br />
gluegen-rt-natives-windows-amd64.jar<br />
jogl-all-natives-linux-amd64.jar<br />
<br />
gluegen-rt-natives-linux-i586.jar<br />
jogl-all-natives-linux-i586.jar<br />
<br />
gluegen-rt-natives-linux-amd64.jar<br />
jogl-all-natives-linux-amd64.jar<br />
<br />
gluegen-rt-natives-macosx-universal.jar<br />
jogl-all-natives-macosx-universal.jar<br />
</pre><br />
<br />
= Compiling and JARing your program =<br />
<br />
This step assumes you have Java set up so you can use it from the command line. For instructions on this, see [https://jogamp.org/wiki/index.php/Building_JOGL_on_the_command_line#Install_a_JDK here].<br />
<br />
To compile the program on Windows, cd to your application directory and type<br />
<br />
<pre><br />
javac -classpath "gluegen-rt.jar;nativewindow.all.jar;jogl.all.jar;newt.all.jar" name\wadewalker\jogl2tests\onetriangle\*.java<br />
</pre><br />
<br />
To compile the program on Linux or Mac OS X, cd to your application directory and type<br />
<br />
<pre><br />
javac -classpath "gluegen-rt.jar:nativewindow.all.jar:jogl.all.jar:newt.all.jar" name\wadewalker\jogl2tests\onetriangle\*.java<br />
</pre><br />
<br />
To JAR the program, type<br />
<br />
<pre><br />
jar cvf onetriangle.jar name\wadewalker\jogl2tests\onetriangle\*.class<br />
</pre><br />
<br />
= Testing your program outside JWS =<br />
<br />
It's probably a good idea to test your program outside JWS first, to make sure it does what you think it should. To do that, you'll need to unzip the native binaries so Java can see them. Since I ran first on Windows 7 64-bit, I unzipped all the <tt>*-natives-windows-amd64.jar</tt> files, the collected the DLLs inside into a directory called <tt>lib-windows-amd64</tt>. Since I test on the other platforms too, I did the same for the other four platforms, creating four more directories <tt>lib-windows-i586</tt>, <tt>lib-linux-i586</tt>, <tt>lib-linux-amd64</tt>, and <tt>lib-macosx-universal</tt>.<br />
<br />
Then to test your program on 64-bit Windows, cd to your application directory and type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar;jogl.all.jar;onetriangle.jar" -Djava.library.path=lib-windows-amd64 name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
On 64-bit Linux, type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar:jogl.all.jar:onetriangle.jar" -Djava.library.path=lib-linux-amd64 name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
On Mac OS X, type<br />
<br />
<pre><br />
java -classpath "gluegen-rt.jar:jogl.all.jar:onetriangle.jar" -Djava.library.path=lib-macosx-universal name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT<br />
</pre><br />
<br />
The result should look like this:<br />
<br />
[[File:JWS-cmdline-test.png|300px|thumb|none|JWS OneTriangle test]]<br />
<br />
= Writing the JNLP files =<br />
<br />
Read the JWS [http://download.oracle.com/javase/1,5.0/docs/guide/javaws/developersguide/syntax.html Java Network Launching Protocol (JNLP)] specification for details.<br />
<br />
In general we will have one exclusive JNLP file for each application, which will reference the JOGL extension's JNLP file.<br />
The latter may reference even more JNLP files, but this shall not matter in this discussion.<br />
<br />
== Use JogAmp's deployed files ==<br />
<br />
We only have to write our application's JNLP file, since it will reference JogAmp's official released as an extension.<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="OneTriangleWebStart.jnlp"><br />
<br />
<information><br />
<title>OneTriangle Demo</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>OneTriangle Java Web Start Demo</description><br />
<description kind="short">The simplest possible JOGL Java Web Start demo - draws one triangle.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<resources><br />
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/><br />
<property name="sun.java2d.noddraw" value="true"/><br />
<extension name="jogl-all-awt" href="http://jogamp.org/deployment/jogamp-current/jogl-all-awt.jnlp" /><br />
<jar href="onetriangle.jar" main="true"/><br />
</resources><br />
<br />
<application-desc main-class="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT"><br />
</application-desc><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>OneTriangleWebStart.jnlp</tt>.<br />
<br />
If you decide to use our JogAmp signed Jar and Jnlp files you can skip the next chapter.<br />
<br />
== Use your own JogAmp files ==<br />
<br />
Here we have to write the JNLP file for our application and once for our self deployed JogAmp extension.<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="OneTriangleWebStart.jnlp"><br />
<br />
<information><br />
<title>OneTriangle Demo</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>OneTriangle Java Web Start Demo</description><br />
<description kind="short">The simplest possible JOGL Java Web Start demo - draws one triangle.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<resources><br />
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/><br />
<property name="sun.java2d.noddraw" value="true"/><br />
<extension name="JOGL" href="JOGL.jnlp" /><br />
<jar href="onetriangle.jar" main="true"/><br />
</resources><br />
<br />
<application-desc main-class="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWT"><br />
</application-desc><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>OneTriangleWebStart.jnlp</tt>.<br />
<br />
Our extension JNLP file for the JOGL JARs looks like this:<br />
<br />
<pre><br />
<?xml version="1.0" encoding="utf-8"?><br />
<jnlp spec="1.0+" codebase="./"<br />
href="JOGL.jnlp"><br />
<br />
<information><br />
<title>JOGL libraries</title><br />
<vendor>JogAmp Community</vendor><br />
<homepage href="http://jogamp.org/"/><br />
<description>JOGL libraries</description><br />
<description kind="short">All JARs and native libraries for JOGL.</description><br />
<offline-allowed/><br />
</information><br />
<update check="background" policy="always"/><br />
<br />
<security><br />
<all-permissions/><br />
</security><br />
<br />
<resources><br />
<jar href="gluegen-rt.jar" /><br />
<jar href="jogl.all.jar" /><br />
</resources><br />
<br />
<resources os="Windows" arch="x86"><br />
<nativelib href = "gluegen-rt-natives-windows-i586.jar" /><br />
<nativelib href = "jogl-all-natives-windows-i586.jar" /><br />
</resources><br />
<resources os="Windows" arch="amd64"><br />
<nativelib href = "gluegen-rt-natives-windows-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-windows-amd64.jar" /><br />
</resources><br />
<resources os="Windows" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-windows-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-windows-amd64.jar" /><br />
</resources><br />
<resources os="Linux" arch="i386"><br />
<nativelib href = "gluegen-rt-natives-linux-i586.jar" /><br />
<nativelib href = "jogl-all-natives-linux-i586.jar" /><br />
</resources><br />
<resources os="Linux" arch="x86"><br />
<nativelib href = "gluegen-rt-natives-linux-i586.jar" /><br />
<nativelib href = "jogl-all-natives-linux-i586.jar" /><br />
</resources><br />
<resources os="Linux" arch="amd64"><br />
<nativelib href = "gluegen-rt-natives-linux-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-linux-amd64.jar" /><br />
</resources><br />
<resources os="Linux" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-linux-amd64.jar" /><br />
<nativelib href = "jogl-all-natives-linux-amd64.jar" /><br />
</resources><br />
<resources os="Mac OS X" arch="i386"><br />
<nativelib href = "gluegen-rt-natives-macosx-universal.jar" /><br />
<nativelib href = "jogl-all-natives-macosx-universal.jar" /><br />
</resources><br />
<resources os="Mac OS X" arch="x86_64"><br />
<nativelib href = "gluegen-rt-natives-macosx-universal.jar" /><br />
<nativelib href = "jogl-all-natives-macosx-universal.jar" /><br />
</resources><br />
<br />
<component-desc /><br />
</jnlp><br />
</pre><br />
<br />
Save this file to your application directory as <tt>JOGL.jnlp</tt>.<br />
<br />
Note that the <tt>codebase</tt> values are set to the current working directory, and the <tt>href</tt> values are simple filenames. This is so we can test the JNLP app locally, without using a web server. When we put the app on a web server later, the <tt>codebase</tt> and <tt>href</tt> become full URLs.<br />
<br />
=== Signing your JARs ===<br />
<br />
For the JWS app to work properly in a web browser, all its JARs must be signed with the same key. If you don't already have a key you want to use, you can create one like this<br />
<br />
<tt>keytool -genkey -keystore testKeys -alias ww</tt><br />
<br />
The <tt>alias</tt> can be anything, I just chose <tt>ww</tt> for this example. Once you have a key, you can sign the JARs like this:<br />
<br />
<pre><br />
jarsigner -keystore testKeys gluegen-rt.jar ww<br />
jarsigner -keystore testKeys jogl.all.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-windows-i586.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-windows-i586.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-windows-amd64.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-windows-amd64.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-linux-i586.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-linux-i586.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-linux-amd64.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-linux-amd64.jar ww<br />
<br />
jarsigner -keystore testKeys gluegen-rt-natives-macosx-universal.jar ww<br />
jarsigner -keystore testKeys jogl-all-natives-macosx-universal.jar ww<br />
</pre><br />
<br />
Unfortunately, if you sign this way you'll have to type your password every time. Alternately, you can use the [http://ant.apache.org/manual/Tasks/signjar.html Ant &lt;signjar&gt; task] to sign these from an Ant file that contains your password.<br />
<br />
= Running the JWS application locally =<br />
<br />
To run the JWS app locally without a web server, cd to the application directory and type<br />
<br />
<pre>javaws OneTriangleWebStart.jnlp</pre><br />
<br />
This runs the app with the JWS launcher. The result should look just like when we ran the app without the launcher, but there'll be a dialog box that pops up first asking the user's permission to load the app. If you have any JAR signing problems, they should show up at this point.<br />
<br />
= Clearing the JWS cache =<br />
<br />
JWS caches JAR and JNLP files to reduce load time. Unfortunately, if you edit one of these files and re-launch, sometimes you won't see your changes because JWS is still using the cached copy. To clear the JWS cache, type<br />
<br />
<pre>javaws -Xclearcache</pre><br />
<br />
=Running the JWS application from a web server=<br />
<br />
'''*This section is unfinished*'''<br />
<br />
Once you're sure that the JWS application launches correctly from the local file system, you're ready to deploy it to a web server.<br />
<br />
* Create or choose an application directory on your web server.<br />
* Change the <tt>codebase</tt> entries in the JNLP from directory names to URLs that refer to the application directory on your web server.<br />
* Copy all the JAR and JNLP files from your local application directory to the application directory on your web server.<br />
* Put a link to the <tt>OneTriangleWebStart.jnlp</tt> file on a page on your web server (more details [http://download.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/launch.html here]).</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=File:NetBeans_setup_03_libraries_in_project.png&diff=682File:NetBeans setup 03 libraries in project.png2012-04-16T17:42:36Z<p>Wwalker: uploaded a new version of "File:NetBeans setup 03 libraries in project.png"</p>
<hr />
<div>Picture for NetBeans project setup instructions</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Setting_up_a_JogAmp_project_in_your_favorite_IDE&diff=681Setting up a JogAmp project in your favorite IDE2012-04-16T17:36:03Z<p>Wwalker: Fixed image popup text</p>
<hr />
<div>__TOC__<br />
<br />
These instructions assume that you've created a project in your favorite IDE, and now you want your project to be able to use a JogAmp library like JOGL, JOCL, JOAL, or GlueGen. We use JOGL as an example below, but these instructions work equally well for any other JogAmp library.<br />
<br />
= Download a JogAmp library =<br />
<br />
If you haven't done so already, download and extract the JogAmp library you want to use. For example, to download and extract JOGL, see the instructions at [[Downloading and installing JOGL]].<br />
<br />
To use a JogAmp library you'll do three things:<br />
<br />
* Add its JAR files to the Java classpath<br />
* Add its native libraries in one of two ways:<br />
** Either place its native JAR files in the same directory as the library JAR files<br />
** Or add its native library files(the <tt>.dll</tt>,<tt>.so</tt>, and <tt>.jnilib</tt> files) to the Java library path<br />
* Optional: Associate the *-java-src.zip files with the corresponding JAR files.<br />
<br />
Each IDE has a slightly different way to do these things, as we show below. Using the native JAR files is usually slightly easier than using the native library files directly, and native JARs make it possible for all platforms' libraries to coexist in one project, so this is the recommended method.<br />
<br />
Please note that all JogAmp libraries depend on the GlueGen runtime libraries. These are included in every JogAmp library for convenience, but are only required once in the classpath and library path of your project.<br />
<br />
= Eclipse IDE project =<br />
<br />
Probably the simplest way to use JOGL in an Eclipse project is to create another Eclipse project to contain the JOGL JARs, then make your project depend on this new JOGL project. In the example below, I include only the 64-bit Windows native JARs, but you can put native JARs for as many platforms as you wish together into the JOGL Eclipse project.<br />
<br />
=== Create a JOGL project ===<br />
<br />
* Put all the JOGL code JARs, native JARs for all platforms you wish to support, and source ZIP files in a directory called "JOGL" in your workspace directory.<br />
* Click "File > New > Java Project". Type "JOGL" as the project name and click "Next".<br />
[[File:Eclipse_project_setup_01_create_project.png|300px|thumb|none|Create JOGL project]]<br />
* Click the "Libraries" tab, select the native JARs, and click "Remove".<br />
[[File:Eclipse_project_setup_02_remove_native_JARs.png|300px|thumb|none|Remove native JARs]]<br />
* Expand the remaining JARs. For each of them, double-click "Source attachment", click "Workspace...", navigate to the corresponding <tt>*-java-src.zip</tt> file in the project, select it, click "OK", and click "OK" again to dismiss the "Source Attachment Configuration" dialog. The JARs should look like this when you're done:<br />
[[File:Eclipse_project_setup_03_JARs_with_source_attached.png|300px|thumb|none|Attach source to JARs]]<br />
* Click the "Order and Export" tab. Check both JOGL JARs, then click "Finish".<br />
[[File:Eclipse_project_setup_04_order_and_export.png|300px|thumb|none|Exporting JOGL JARs]]<br />
<br />
=== Add dependency on the JOGL project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select the "Java Build Path" on the left, then click the "Projects" tab on the right.<br />
* Click the "Add..." button, check "JOGL", and click "OK".<br />
* Your dependent project should look like this. Click "OK" to dismiss the "Properties" dialog.<br />
[[File:Eclipse_project_setup_05_project_dependency.png|300px|thumb|none|JOGL project dependency]]<br />
<br />
That's it! Your project can now use the library.<br />
<br />
= Eclipse IDE user library =<br />
<br />
If you don't want to put JOGL in a separate Eclipse project, you can put it in a user library instead. The drawback to this is that the user library is defined in your .metadata directory and contains absolute paths, so it's hard to share with others. But for a non-shared project this works fine.<br />
<br />
=== Create a user library ===<br />
<br />
* Click "Window > Preferences", then select "Java > Build Path > User Libraries" on the left.<br />
* Click the "New..." button, type "JOGL" for the library name, and click "OK".<br />
[[File:Eclipse_setup_01_create_user_library.png|300px|thumb|none|Create user library]]<br />
* Click the "Add JARs..." button, navigate to the directory where you've stored the JARs, select all the non-native JARs, then click "Open".<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Expand each non-native JAR in the list<br />
** Double-click "Source attachment", type the module's source zip name, (e.g. <tt>jogl-java-src.zip</tt> for the JAR file <tt>jogl.all.jar</tt>), and click "OK".<br />
** If you're using native library files:<br />
*** Double-click "Native library location", type the directory where native library files are stored, and click "OK".<br />
[[File:Eclipse_setup_02_set_native_library_locations.png|300px|thumb|none|Set native library locations]]<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
=== Add the user library to your project's dependencies ===<br />
<br />
* Right-click your project in the Package Explorer and click "Properties".<br />
* Select "Java Build Path" and click the "Libraries" tab.<br />
[[File:Eclipse_setup_03_add_library_to_project.png|300px|thumb|none|Add library to project]]<br />
* Click "Add Library...", select "User Library", click "Next", check "JOGL", and click "Finish".<br />
[[File:Eclipse_setup_04_add_JOGL_library_to_project.png|300px|thumb|none|Add JOGL library to project]]<br />
* Click "OK" to dismiss the Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= IntelliJ IDEA =<br />
=== Add a library dependency to your project ===<br />
<br />
* Click "File > Project Structure".<br />
* Select "Modules" on the left, then click the "Dependencies" tab on the right.<br />
* Click the "+" button on the right, then select "Library... > Java".<br />
[[File:IntelliJ_setup_01_add_library.png|300px|thumb|none|Add library]]<br />
* Navigate to the directory where you extracted the JARs, select it, and click "OK".<br />
[[File:IntelliJ_setup_02_find_library.png|300px|thumb|none|Find library]]<br />
* Click "OK" to dismiss the Configure Library dialog.<br />
[[File:IntelliJ_setup_03_configure_library.png|300px|thumb|none|Configure library]]<br />
* Click "OK" to dismiss the Project Structure dialog. The external libraries in your project should now look like this if you're using native JAR files:<br />
[[File:IntelliJ_setup_04_external_library_native_JARs.png|300px|thumb|none|Native JARs]]<br />
or like this if you're using native library files:<br />
[[File:IntelliJ_setup_04_external_library.png|300px|thumb|none|Native library files]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Edit Configurations".<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Parameters" box. Note that paths with spaces must be double-quoted on Windows.<br />
[[File:IntelliJ_setup_05_run_configuration.png|300px|thumb|none|Edit run configuration]]<br />
** Click "OK" to dismiss the Run/Debug Configurations dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= NetBeans IDE = <br />
=== Create a library and add it to your project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select "Libraries" on the left and click "Add Library...".<br />
* Click the "Create" button, then type "JOGL" for the library name and click "OK".[[File:NetBeans_setup_01_create_library.png|300px|thumb|none|Create library]]<br />
* Click "Add JAR/Folder...", then navigate to the directory you extracted the JAR files, select them and click "Add JAR/Folder".<br />
* Click "OK" to dismiss the Customize Library dialog.<br />
* Click "Add Library" to dismiss the Add Library dialog.[[File:NetBeans_setup_02_add_library.png|300px|thumb|none|Add library]]<br />
* Click "OK" to dismiss the Project Properties dialog. The libraries in your project should look like this.[[File:NetBeans_setup_03_libraries_in_project.png|300px|thumb|none|Libraries in project]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Set Project Configuration > Customize...". Select "Run" on the left if it isn't selected already.<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Options" box.<br />
** NOTE: If the library path has spaces in it, you must put quotes around it (at least on Windows) or you may get an odd NoClassDefFoundError when you try to run.[[File:NetBeans_setup_04_native_library_path.png|300px|thumb|none|Native library path]]<br />
** Click "OK" to dismiss the Project Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= vi and other text editors =<br />
=== Create your project with the editor of your choice ===<br />
* For example, to open vi, simply type <tt>vi</tt> and press <return>.<br />
* Type all your code, then save it.<br />
<br />
=== Compile and run your project from the command line ===<br />
* We assume your JOGL JAR files are in a directory called <tt>jar</tt>. If you're using native JARs, we assume they're also in the <tt>jar</tt> directory. If you're using native library files, we assume they're in a directory called <tt>lib</tt>.<br />
<br />
* First compile your program. We assume all your code is in a single file called <tt>name/someone/MyProject.java</tt>.<br />
** Windows: Type <tt>javac -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar" name\someone\MyProject.java</tt><br />
** Linux/MacOS X: Type <tt>javac -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar" name/someone/MyProject.java</tt><br />
<br />
* Then run your project. We assume your main class is <tt>name.someone.MyProject</tt>. If you're using native JARs:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." name.someone.MyProject</tt><br />
* If you're using native library files:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." -Djava.library.path=lib name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." -Djava.library.path=lib name.someone.MyProject</tt><br />
<br />
That's it! You can now use the library in your project.</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=File:IntelliJ_setup_04_external_library.png&diff=680File:IntelliJ setup 04 external library.png2012-04-16T17:33:49Z<p>Wwalker: uploaded a new version of "File:IntelliJ setup 04 external library.png"</p>
<hr />
<div></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=File:IntelliJ_setup_04_external_library_native_JARs.png&diff=679File:IntelliJ setup 04 external library native JARs.png2012-04-16T17:33:25Z<p>Wwalker: uploaded a new version of "File:IntelliJ setup 04 external library native JARs.png"</p>
<hr />
<div></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Setting_up_a_JogAmp_project_in_your_favorite_IDE&diff=678Setting up a JogAmp project in your favorite IDE2012-04-16T17:27:30Z<p>Wwalker: Improved summary paragraph</p>
<hr />
<div>__TOC__<br />
<br />
These instructions assume that you've created a project in your favorite IDE, and now you want your project to be able to use a JogAmp library like JOGL, JOCL, JOAL, or GlueGen. We use JOGL as an example below, but these instructions work equally well for any other JogAmp library.<br />
<br />
= Download a JogAmp library =<br />
<br />
If you haven't done so already, download and extract the JogAmp library you want to use. For example, to download and extract JOGL, see the instructions at [[Downloading and installing JOGL]].<br />
<br />
To use a JogAmp library you'll do three things:<br />
<br />
* Add its JAR files to the Java classpath<br />
* Add its native libraries in one of two ways:<br />
** Either place its native JAR files in the same directory as the library JAR files<br />
** Or add its native library files(the <tt>.dll</tt>,<tt>.so</tt>, and <tt>.jnilib</tt> files) to the Java library path<br />
* Optional: Associate the *-java-src.zip files with the corresponding JAR files.<br />
<br />
Each IDE has a slightly different way to do these things, as we show below. Using the native JAR files is usually slightly easier than using the native library files directly, and native JARs make it possible for all platforms' libraries to coexist in one project, so this is the recommended method.<br />
<br />
Please note that all JogAmp libraries depend on the GlueGen runtime libraries. These are included in every JogAmp library for convenience, but are only required once in the classpath and library path of your project.<br />
<br />
= Eclipse IDE project =<br />
<br />
Probably the simplest way to use JOGL in an Eclipse project is to create another Eclipse project to contain the JOGL JARs, then make your project depend on this new JOGL project. In the example below, I include only the 64-bit Windows native JARs, but you can put native JARs for as many platforms as you wish together into the JOGL Eclipse project.<br />
<br />
=== Create a JOGL project ===<br />
<br />
* Put all the JOGL code JARs, native JARs for all platforms you wish to support, and source ZIP files in a directory called "JOGL" in your workspace directory.<br />
* Click "File > New > Java Project". Type "JOGL" as the project name and click "Next".<br />
[[File:Eclipse_project_setup_01_create_project.png|300px|thumb|none|Create JOGL project]]<br />
* Click the "Libraries" tab, select the native JARs, and click "Remove".<br />
[[File:Eclipse_project_setup_02_remove_native_JARs.png|300px|thumb|none|Remove native JARs]]<br />
* Expand the remaining JARs. For each of them, double-click "Source attachment", click "Workspace...", navigate to the corresponding <tt>*-java-src.zip</tt> file in the project, select it, click "OK", and click "OK" again to dismiss the "Source Attachment Configuration" dialog. The JARs should look like this when you're done:<br />
[[File:Eclipse_project_setup_03_JARs_with_source_attached.png|300px|thumb|none|Attach source to JARs]]<br />
* Click the "Order and Export" tab. Check both JOGL JARs, then click "Finish".<br />
[[File:Eclipse_project_setup_04_order_and_export.png|300px|thumb|none|Exporting JOGL JARs]]<br />
<br />
=== Add dependency on the JOGL project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select the "Java Build Path" on the left, then click the "Projects" tab on the right.<br />
* Click the "Add..." button, check "JOGL", and click "OK".<br />
* Your dependent project should look like this. Click "OK" to dismiss the "Properties" dialog.<br />
[[File:Eclipse_project_setup_05_project_dependency.png|300px|thumb|none|JOGL project dependency]]<br />
<br />
That's it! Your project can now use the library.<br />
<br />
= Eclipse IDE user library =<br />
<br />
If you don't want to put JOGL in a separate Eclipse project, you can put it in a user library instead. The drawback to this is that the user library is defined in your .metadata directory and contains absolute paths, so it's hard to share with others. But for a non-shared project this works fine.<br />
<br />
=== Create a user library ===<br />
<br />
* Click "Window > Preferences", then select "Java > Build Path > User Libraries" on the left.<br />
* Click the "New..." button, type "JOGL" for the library name, and click "OK".<br />
[[File:Eclipse_setup_01_create_user_library.png|300px|thumb|none|Create user library]]<br />
* Click the "Add JARs..." button, navigate to the directory where you've stored the JARs, select all the non-native JARs, then click "Open".<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Expand each non-native JAR in the list<br />
** Double-click "Source attachment", type the module's source zip name, (e.g. <tt>jogl-java-src.zip</tt> for the JAR file <tt>jogl.all.jar</tt>), and click "OK".<br />
** If you're using native library files:<br />
*** Double-click "Native library location", type the directory where native library files are stored, and click "OK".<br />
[[File:Eclipse_setup_02_set_native_library_locations.png|300px|thumb|none|Set native library locations]]<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
=== Add the user library to your project's dependencies ===<br />
<br />
* Right-click your project in the Package Explorer and click "Properties".<br />
* Select "Java Build Path" and click the "Libraries" tab.<br />
[[File:Eclipse_setup_03_add_library_to_project.png|300px|thumb|none|Add library to project]]<br />
* Click "Add Library...", select "User Library", click "Next", check "JOGL", and click "Finish".<br />
[[File:Eclipse_setup_04_add_JOGL_library_to_project.png|300px|thumb|none|Add JOGL library to project]]<br />
* Click "OK" to dismiss the Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= IntelliJ IDEA =<br />
=== Add a library dependency to your project ===<br />
<br />
* Click "File > Project Structure".<br />
* Select "Modules" on the left, then click the "Dependencies" tab on the right.<br />
* Click the "+" button on the right, then select "Library... > Java".<br />
[[File:IntelliJ_setup_01_add_library.png|300px|thumb|none|Add library]]<br />
* Navigate to the directory where you extracted the JARs, select it, and click "OK".<br />
[[File:IntelliJ_setup_02_find_library.png|300px|thumb|none|Find library]]<br />
* Click "OK" to dismiss the Configure Library dialog.<br />
[[File:IntelliJ_setup_03_configure_library.png|300px|thumb|none|Configure library]]<br />
* Click "OK" to dismiss the Project Structure dialog. The external libraries in your project should now look like this if you're using native JAR files:<br />
[[File:IntelliJ_setup_04_external_library_native_JARs.png|300px|thumb|none|External libraries]]<br />
or like this if you're using native library files:<br />
[[File:IntelliJ_setup_04_external_library.png|300px|thumb|none|External libraries]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Edit Configurations".<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Parameters" box. Note that paths with spaces must be double-quoted on Windows.<br />
[[File:IntelliJ_setup_05_run_configuration.png|300px|thumb|none|Edit run configuration]]<br />
** Click "OK" to dismiss the Run/Debug Configurations dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= NetBeans IDE = <br />
=== Create a library and add it to your project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select "Libraries" on the left and click "Add Library...".<br />
* Click the "Create" button, then type "JOGL" for the library name and click "OK".[[File:NetBeans_setup_01_create_library.png|300px|thumb|none|Create library]]<br />
* Click "Add JAR/Folder...", then navigate to the directory you extracted the JAR files, select them and click "Add JAR/Folder".<br />
* Click "OK" to dismiss the Customize Library dialog.<br />
* Click "Add Library" to dismiss the Add Library dialog.[[File:NetBeans_setup_02_add_library.png|300px|thumb|none|Add library]]<br />
* Click "OK" to dismiss the Project Properties dialog. The libraries in your project should look like this.[[File:NetBeans_setup_03_libraries_in_project.png|300px|thumb|none|Libraries in project]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Set Project Configuration > Customize...". Select "Run" on the left if it isn't selected already.<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Options" box.<br />
** NOTE: If the library path has spaces in it, you must put quotes around it (at least on Windows) or you may get an odd NoClassDefFoundError when you try to run.[[File:NetBeans_setup_04_native_library_path.png|300px|thumb|none|Native library path]]<br />
** Click "OK" to dismiss the Project Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= vi and other text editors =<br />
=== Create your project with the editor of your choice ===<br />
* For example, to open vi, simply type <tt>vi</tt> and press <return>.<br />
* Type all your code, then save it.<br />
<br />
=== Compile and run your project from the command line ===<br />
* We assume your JOGL JAR files are in a directory called <tt>jar</tt>. If you're using native JARs, we assume they're also in the <tt>jar</tt> directory. If you're using native library files, we assume they're in a directory called <tt>lib</tt>.<br />
<br />
* First compile your program. We assume all your code is in a single file called <tt>name/someone/MyProject.java</tt>.<br />
** Windows: Type <tt>javac -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar" name\someone\MyProject.java</tt><br />
** Linux/MacOS X: Type <tt>javac -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar" name/someone/MyProject.java</tt><br />
<br />
* Then run your project. We assume your main class is <tt>name.someone.MyProject</tt>. If you're using native JARs:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." name.someone.MyProject</tt><br />
* If you're using native library files:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." -Djava.library.path=lib name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." -Djava.library.path=lib name.someone.MyProject</tt><br />
<br />
That's it! You can now use the library in your project.</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Setting_up_a_JogAmp_project_in_your_favorite_IDE&diff=677Setting up a JogAmp project in your favorite IDE2012-04-16T17:26:15Z<p>Wwalker: Improved summary para</p>
<hr />
<div>__TOC__<br />
<br />
These instructions assume that you've created a project in your favorite IDE, and now you want your project to be able to use a JogAmp library like JOGL, JOCL, JOAL, or GlueGen. We use JOGL as an example below, but these instructions work equally well for any other JogAmp library.<br />
<br />
= Download a JogAmp library =<br />
<br />
If you haven't done so already, download and extract the JogAmp library you want to use. For example, to download and extract JOGL, see the instructions at [[Downloading and installing JOGL]].<br />
<br />
To use a JogAmp library you'll do three things:<br />
<br />
* Add its JAR files to the Java classpath<br />
* Add its native libraries in one of two ways:<br />
** Either place its native JAR files in the same directory as the library JAR files<br />
** Or add its native library files(the <tt>.dll</tt>,<tt>.so</tt>, and <tt>.jnilib</tt> files) to the Java library path<br />
* Optional: Associate the *-java-src.zip files with the corresponding JAR files.<br />
<br />
Each IDE has a slightly different way to do these things, as we show below. Using the native JAR files is usually slightly easier than using the native library files directly, and native JARs make it possible for all platforms' libraries to coexist in one project, so this is the recommended method.<br />
<br />
Please note that all JogAmp libraries depend on the GlueGen runtime libraries. These are included in every JogAmp library for convenience, but are only required once in the classpath and library path of your project.<br />
<br />
= Eclipse IDE project =<br />
<br />
Probably the simplest way to use JOGL in an Eclipse project is to create another Eclipse project to contain the JOGL JARs, then make your project depend on this new JOGL project. In the example below, I include only the 64-bit Windows native JARs, but you can put native JARs for as many platforms as you wish together into the JOGL Eclipse project.<br />
<br />
=== Create a JOGL project ===<br />
<br />
* Put all the JOGL code JARs, native JARs for all platforms you wish to support, and source ZIP files in a directory called "JOGL" in your workspace directory.<br />
* Click "File > New > Java Project". Type "JOGL" as the project name and click "Next".<br />
[[File:Eclipse_project_setup_01_create_project.png|300px|thumb|none|Create JOGL project]]<br />
* Click the "Libraries" tab, select the native JARs, and click "Remove".<br />
[[File:Eclipse_project_setup_02_remove_native_JARs.png|300px|thumb|none|Remove native JARs]]<br />
* Expand the remaining JARs. For each of them, double-click "Source attachment", click "Workspace...", navigate to the corresponding <tt>*-java-src.zip</tt> file in the project, select it, click "OK", and click "OK" again to dismiss the "Source Attachment Configuration" dialog. The JARs should look like this when you're done:<br />
[[File:Eclipse_project_setup_03_JARs_with_source_attached.png|300px|thumb|none|Attach source to JARs]]<br />
* Click the "Order and Export" tab. Check both JOGL JARs, then click "Finish".<br />
[[File:Eclipse_project_setup_04_order_and_export.png|300px|thumb|none|Exporting JOGL JARs]]<br />
<br />
=== Add dependency on the JOGL project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select the "Java Build Path" on the left, then click the "Projects" tab on the right.<br />
* Click the "Add..." button, check "JOGL", and click "OK".<br />
* Your dependent project should look like this. Click "OK" to dismiss the "Properties" dialog.<br />
[[File:Eclipse_project_setup_05_project_dependency.png|300px|thumb|none|JOGL project dependency]]<br />
<br />
That's it! Your project can now use the library.<br />
<br />
= Eclipse IDE user library =<br />
<br />
If you don't want to put JOGL in an Eclipse project, you can put it in a user library instead. The drawbacks to this are that the user library is defined in your .metadata directory and contains absolute paths, so it's hard to share with others. But for a non-shared project this works fine.<br />
<br />
=== Create a user library ===<br />
<br />
* Click "Window > Preferences", then select "Java > Build Path > User Libraries" on the left.<br />
* Click the "New..." button, type "JOGL" for the library name, and click "OK".<br />
[[File:Eclipse_setup_01_create_user_library.png|300px|thumb|none|Create user library]]<br />
* Click the "Add JARs..." button, navigate to the directory where you've stored the JARs, select all the non-native JARs, then click "Open".<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Expand each non-native JAR in the list<br />
** Double-click "Source attachment", type the module's source zip name, (e.g. <tt>jogl-java-src.zip</tt> for the JAR file <tt>jogl.all.jar</tt>), and click "OK".<br />
** If you're using native library files:<br />
*** Double-click "Native library location", type the directory where native library files are stored, and click "OK".<br />
[[File:Eclipse_setup_02_set_native_library_locations.png|300px|thumb|none|Set native library locations]]<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
=== Add the user library to your project's dependencies ===<br />
<br />
* Right-click your project in the Package Explorer and click "Properties".<br />
* Select "Java Build Path" and click the "Libraries" tab.<br />
[[File:Eclipse_setup_03_add_library_to_project.png|300px|thumb|none|Add library to project]]<br />
* Click "Add Library...", select "User Library", click "Next", check "JOGL", and click "Finish".<br />
[[File:Eclipse_setup_04_add_JOGL_library_to_project.png|300px|thumb|none|Add JOGL library to project]]<br />
* Click "OK" to dismiss the Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= IntelliJ IDEA =<br />
=== Add a library dependency to your project ===<br />
<br />
* Click "File > Project Structure".<br />
* Select "Modules" on the left, then click the "Dependencies" tab on the right.<br />
* Click the "+" button on the right, then select "Library... > Java".<br />
[[File:IntelliJ_setup_01_add_library.png|300px|thumb|none|Add library]]<br />
* Navigate to the directory where you extracted the JARs, select it, and click "OK".<br />
[[File:IntelliJ_setup_02_find_library.png|300px|thumb|none|Find library]]<br />
* Click "OK" to dismiss the Configure Library dialog.<br />
[[File:IntelliJ_setup_03_configure_library.png|300px|thumb|none|Configure library]]<br />
* Click "OK" to dismiss the Project Structure dialog. The external libraries in your project should now look like this if you're using native JAR files:<br />
[[File:IntelliJ_setup_04_external_library_native_JARs.png|300px|thumb|none|External libraries]]<br />
or like this if you're using native library files:<br />
[[File:IntelliJ_setup_04_external_library.png|300px|thumb|none|External libraries]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Edit Configurations".<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Parameters" box. Note that paths with spaces must be double-quoted on Windows.<br />
[[File:IntelliJ_setup_05_run_configuration.png|300px|thumb|none|Edit run configuration]]<br />
** Click "OK" to dismiss the Run/Debug Configurations dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= NetBeans IDE = <br />
=== Create a library and add it to your project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select "Libraries" on the left and click "Add Library...".<br />
* Click the "Create" button, then type "JOGL" for the library name and click "OK".[[File:NetBeans_setup_01_create_library.png|300px|thumb|none|Create library]]<br />
* Click "Add JAR/Folder...", then navigate to the directory you extracted the JAR files, select them and click "Add JAR/Folder".<br />
* Click "OK" to dismiss the Customize Library dialog.<br />
* Click "Add Library" to dismiss the Add Library dialog.[[File:NetBeans_setup_02_add_library.png|300px|thumb|none|Add library]]<br />
* Click "OK" to dismiss the Project Properties dialog. The libraries in your project should look like this.[[File:NetBeans_setup_03_libraries_in_project.png|300px|thumb|none|Libraries in project]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Set Project Configuration > Customize...". Select "Run" on the left if it isn't selected already.<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Options" box.<br />
** NOTE: If the library path has spaces in it, you must put quotes around it (at least on Windows) or you may get an odd NoClassDefFoundError when you try to run.[[File:NetBeans_setup_04_native_library_path.png|300px|thumb|none|Native library path]]<br />
** Click "OK" to dismiss the Project Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= vi and other text editors =<br />
=== Create your project with the editor of your choice ===<br />
* For example, to open vi, simply type <tt>vi</tt> and press <return>.<br />
* Type all your code, then save it.<br />
<br />
=== Compile and run your project from the command line ===<br />
* We assume your JOGL JAR files are in a directory called <tt>jar</tt>. If you're using native JARs, we assume they're also in the <tt>jar</tt> directory. If you're using native library files, we assume they're in a directory called <tt>lib</tt>.<br />
<br />
* First compile your program. We assume all your code is in a single file called <tt>name/someone/MyProject.java</tt>.<br />
** Windows: Type <tt>javac -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar" name\someone\MyProject.java</tt><br />
** Linux/MacOS X: Type <tt>javac -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar" name/someone/MyProject.java</tt><br />
<br />
* Then run your project. We assume your main class is <tt>name.someone.MyProject</tt>. If you're using native JARs:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." name.someone.MyProject</tt><br />
* If you're using native library files:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." -Djava.library.path=lib name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." -Djava.library.path=lib name.someone.MyProject</tt><br />
<br />
That's it! You can now use the library in your project.</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Setting_up_a_JogAmp_project_in_your_favorite_IDE&diff=676Setting up a JogAmp project in your favorite IDE2012-04-16T17:25:03Z<p>Wwalker: Added mention of multiple platforms</p>
<hr />
<div>__TOC__<br />
<br />
These instructions assume that you've created a project in your favorite IDE, and now you want your project to be able to use a JogAmp library like JOGL, JOCL, JOAL, or GlueGen. We use JOGL as an example below, but these instructions work equally well for any other JogAmp library.<br />
<br />
= Download a JogAmp library =<br />
<br />
If you haven't done so already, download and extract the JogAmp library you want to use. For example, to download and extract JOGL, see the instructions at [[Downloading and installing JOGL]].<br />
<br />
To use a JogAmp library you'll do three things:<br />
<br />
* Add its JAR files to the Java classpath<br />
* Add its native libraries in one of two ways:<br />
** Either place its native JAR files in the same directory as the library JAR files<br />
** Or add its native library files(the <tt>.dll</tt>,<tt>.so</tt>, and <tt>.jnilib</tt> files) to the Java library path<br />
* Optional: Associate the *-java-src.zip files with the corresponding JAR files.<br />
<br />
Each IDE has a slightly different way to do these things, as we show below. Using the native JAR files is usually slightly easier than using the native library files directly, and native JARs make it possible for all platforms' libraries to coexist in one project, so this is the recommended method.<br />
<br />
Please note that all JogAmp libraries depend on the GlueGen runtime libraries. These are included in every JogAmp library for convenience, but are only required once in the classpath and library path of your project.<br />
<br />
= Eclipse IDE project =<br />
<br />
Probably the simplest way to use JOGL in an Eclipse project is to create another Eclipse project to contain the JOGL JARs (both the code JARs and the native JARs). In the example below, I include only the 64-bit Windows native JARs, but you can put native JARs for as many platforms as you wish together into the JOGL Eclipse project.<br />
<br />
=== Create a JOGL project ===<br />
<br />
* Put all the JOGL code JARs, native JARs for all platforms you wish to support, and source ZIP files in a directory called "JOGL" in your workspace directory.<br />
* Click "File > New > Java Project". Type "JOGL" as the project name and click "Next".<br />
[[File:Eclipse_project_setup_01_create_project.png|300px|thumb|none|Create JOGL project]]<br />
* Click the "Libraries" tab, select the native JARs, and click "Remove".<br />
[[File:Eclipse_project_setup_02_remove_native_JARs.png|300px|thumb|none|Remove native JARs]]<br />
* Expand the remaining JARs. For each of them, double-click "Source attachment", click "Workspace...", navigate to the corresponding <tt>*-java-src.zip</tt> file in the project, select it, click "OK", and click "OK" again to dismiss the "Source Attachment Configuration" dialog. The JARs should look like this when you're done:<br />
[[File:Eclipse_project_setup_03_JARs_with_source_attached.png|300px|thumb|none|Attach source to JARs]]<br />
* Click the "Order and Export" tab. Check both JOGL JARs, then click "Finish".<br />
[[File:Eclipse_project_setup_04_order_and_export.png|300px|thumb|none|Exporting JOGL JARs]]<br />
<br />
=== Add dependency on the JOGL project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select the "Java Build Path" on the left, then click the "Projects" tab on the right.<br />
* Click the "Add..." button, check "JOGL", and click "OK".<br />
* Your dependent project should look like this. Click "OK" to dismiss the "Properties" dialog.<br />
[[File:Eclipse_project_setup_05_project_dependency.png|300px|thumb|none|JOGL project dependency]]<br />
<br />
That's it! Your project can now use the library.<br />
<br />
= Eclipse IDE user library =<br />
<br />
If you don't want to put JOGL in an Eclipse project, you can put it in a user library instead. The drawbacks to this are that the user library is defined in your .metadata directory and contains absolute paths, so it's hard to share with others. But for a non-shared project this works fine.<br />
<br />
=== Create a user library ===<br />
<br />
* Click "Window > Preferences", then select "Java > Build Path > User Libraries" on the left.<br />
* Click the "New..." button, type "JOGL" for the library name, and click "OK".<br />
[[File:Eclipse_setup_01_create_user_library.png|300px|thumb|none|Create user library]]<br />
* Click the "Add JARs..." button, navigate to the directory where you've stored the JARs, select all the non-native JARs, then click "Open".<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Expand each non-native JAR in the list<br />
** Double-click "Source attachment", type the module's source zip name, (e.g. <tt>jogl-java-src.zip</tt> for the JAR file <tt>jogl.all.jar</tt>), and click "OK".<br />
** If you're using native library files:<br />
*** Double-click "Native library location", type the directory where native library files are stored, and click "OK".<br />
[[File:Eclipse_setup_02_set_native_library_locations.png|300px|thumb|none|Set native library locations]]<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
=== Add the user library to your project's dependencies ===<br />
<br />
* Right-click your project in the Package Explorer and click "Properties".<br />
* Select "Java Build Path" and click the "Libraries" tab.<br />
[[File:Eclipse_setup_03_add_library_to_project.png|300px|thumb|none|Add library to project]]<br />
* Click "Add Library...", select "User Library", click "Next", check "JOGL", and click "Finish".<br />
[[File:Eclipse_setup_04_add_JOGL_library_to_project.png|300px|thumb|none|Add JOGL library to project]]<br />
* Click "OK" to dismiss the Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= IntelliJ IDEA =<br />
=== Add a library dependency to your project ===<br />
<br />
* Click "File > Project Structure".<br />
* Select "Modules" on the left, then click the "Dependencies" tab on the right.<br />
* Click the "+" button on the right, then select "Library... > Java".<br />
[[File:IntelliJ_setup_01_add_library.png|300px|thumb|none|Add library]]<br />
* Navigate to the directory where you extracted the JARs, select it, and click "OK".<br />
[[File:IntelliJ_setup_02_find_library.png|300px|thumb|none|Find library]]<br />
* Click "OK" to dismiss the Configure Library dialog.<br />
[[File:IntelliJ_setup_03_configure_library.png|300px|thumb|none|Configure library]]<br />
* Click "OK" to dismiss the Project Structure dialog. The external libraries in your project should now look like this if you're using native JAR files:<br />
[[File:IntelliJ_setup_04_external_library_native_JARs.png|300px|thumb|none|External libraries]]<br />
or like this if you're using native library files:<br />
[[File:IntelliJ_setup_04_external_library.png|300px|thumb|none|External libraries]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Edit Configurations".<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Parameters" box. Note that paths with spaces must be double-quoted on Windows.<br />
[[File:IntelliJ_setup_05_run_configuration.png|300px|thumb|none|Edit run configuration]]<br />
** Click "OK" to dismiss the Run/Debug Configurations dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= NetBeans IDE = <br />
=== Create a library and add it to your project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select "Libraries" on the left and click "Add Library...".<br />
* Click the "Create" button, then type "JOGL" for the library name and click "OK".[[File:NetBeans_setup_01_create_library.png|300px|thumb|none|Create library]]<br />
* Click "Add JAR/Folder...", then navigate to the directory you extracted the JAR files, select them and click "Add JAR/Folder".<br />
* Click "OK" to dismiss the Customize Library dialog.<br />
* Click "Add Library" to dismiss the Add Library dialog.[[File:NetBeans_setup_02_add_library.png|300px|thumb|none|Add library]]<br />
* Click "OK" to dismiss the Project Properties dialog. The libraries in your project should look like this.[[File:NetBeans_setup_03_libraries_in_project.png|300px|thumb|none|Libraries in project]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Set Project Configuration > Customize...". Select "Run" on the left if it isn't selected already.<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Options" box.<br />
** NOTE: If the library path has spaces in it, you must put quotes around it (at least on Windows) or you may get an odd NoClassDefFoundError when you try to run.[[File:NetBeans_setup_04_native_library_path.png|300px|thumb|none|Native library path]]<br />
** Click "OK" to dismiss the Project Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= vi and other text editors =<br />
=== Create your project with the editor of your choice ===<br />
* For example, to open vi, simply type <tt>vi</tt> and press <return>.<br />
* Type all your code, then save it.<br />
<br />
=== Compile and run your project from the command line ===<br />
* We assume your JOGL JAR files are in a directory called <tt>jar</tt>. If you're using native JARs, we assume they're also in the <tt>jar</tt> directory. If you're using native library files, we assume they're in a directory called <tt>lib</tt>.<br />
<br />
* First compile your program. We assume all your code is in a single file called <tt>name/someone/MyProject.java</tt>.<br />
** Windows: Type <tt>javac -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar" name\someone\MyProject.java</tt><br />
** Linux/MacOS X: Type <tt>javac -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar" name/someone/MyProject.java</tt><br />
<br />
* Then run your project. We assume your main class is <tt>name.someone.MyProject</tt>. If you're using native JARs:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." name.someone.MyProject</tt><br />
* If you're using native library files:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." -Djava.library.path=lib name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." -Djava.library.path=lib name.someone.MyProject</tt><br />
<br />
That's it! You can now use the library in your project.</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=File:Eclipse_project_setup_05_project_dependency.png&diff=675File:Eclipse project setup 05 project dependency.png2012-04-16T17:20:57Z<p>Wwalker: </p>
<hr />
<div></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=File:Eclipse_project_setup_04_order_and_export.png&diff=674File:Eclipse project setup 04 order and export.png2012-04-16T17:20:45Z<p>Wwalker: </p>
<hr />
<div></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=File:Eclipse_project_setup_03_JARs_with_source_attached.png&diff=673File:Eclipse project setup 03 JARs with source attached.png2012-04-16T17:20:32Z<p>Wwalker: </p>
<hr />
<div></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=File:Eclipse_project_setup_02_remove_native_JARs.png&diff=672File:Eclipse project setup 02 remove native JARs.png2012-04-16T17:20:12Z<p>Wwalker: </p>
<hr />
<div></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=File:Eclipse_project_setup_01_create_project.png&diff=671File:Eclipse project setup 01 create project.png2012-04-16T17:19:01Z<p>Wwalker: </p>
<hr />
<div></div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Setting_up_a_JogAmp_project_in_your_favorite_IDE&diff=670Setting up a JogAmp project in your favorite IDE2012-04-15T17:50:47Z<p>Wwalker: Added instructions on setting up JOGL as an Eclipse project</p>
<hr />
<div>__TOC__<br />
<br />
These instructions assume that you've created a project in your favorite IDE, and now you want your project to be able to use a JogAmp library like JOGL, JOCL, JOAL, or GlueGen. We use JOGL as an example below, but these instructions work equally well for any other JogAmp library.<br />
<br />
= Download a JogAmp library =<br />
<br />
If you haven't done so already, download and extract the JogAmp library you want to use. For example, to download and extract JOGL, see the instructions at [[Downloading and installing JOGL]].<br />
<br />
To use a JogAmp library you'll do three things:<br />
<br />
* Add its JAR files to the Java classpath<br />
* Add its native libraries in one of two ways:<br />
** Either place its native JAR files in the same directory as the library JAR files<br />
** Or add its native library files(the <tt>.dll</tt>,<tt>.so</tt>, and <tt>.jnilib</tt> files) to the Java library path<br />
* Optional: Associate the *-java-src.zip files with the corresponding JAR files.<br />
<br />
Each IDE has a slightly different way to do these things, as we show below. Using the native JAR files is usually slightly easier than using the native library files directly, and native JARs make it possible for all platforms' libraries to coexist in one project, so this is the recommended method.<br />
<br />
Please note that all JogAmp libraries depend on the GlueGen runtime libraries. These are included in every JogAmp library for convenience, but are only required once in the classpath and library path of your project.<br />
<br />
= Eclipse IDE project =<br />
<br />
Probably the simplest way to use JOGL in an Eclipse project is to create another Eclipse project to contain the JOGL JARs.<br />
<br />
=== Create a JOGL project ===<br />
<br />
* Put all the JOGL JARs, native JARs, and source ZIP files in a directory called "JOGL" in your workspace directory.<br />
* Click "File > New > Java Project". Type "JOGL" as the project name and click "Next".<br />
[[File:Eclipse_project_setup_01_create_project.png|300px|thumb|none|Create JOGL project]]<br />
* Click the "Libraries" tab, select the native JARs, and click "Remove".<br />
[[File:Eclipse_project_setup_02_remove_native_JARs.png|300px|thumb|none|Remove native JARs]]<br />
* Expand the remaining JARs. For each of them, double-click "Source attachment", click "Workspace...", navigate to the corresponding <tt>*-java-src.zip</tt> file in the project, select it, click "OK", and click "OK" again to dismiss the "Source Attachment Configuration" dialog. The JARs should look like this when you're done:<br />
[[File:Eclipse_project_setup_03_JARs_with_source_attached.png|300px|thumb|none|Attach source to JARs]]<br />
* Click the "Order and Export" tab. Check both JOGL JARs, then click "Finish".<br />
[[File:Eclipse_project_setup_04_order_and_export.png|300px|thumb|none|Exporting JOGL JARs]]<br />
<br />
=== Add dependency on the JOGL project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select the "Java Build Path" on the left, then click the "Projects" tab on the right.<br />
* Click the "Add..." button, check "JOGL", and click "OK".<br />
* Your dependent project should look like this. Click "OK" to dismiss the "Properties" dialog.<br />
[[File:Eclipse_project_setup_05_project_dependency.png|300px|thumb|none|JOGL project dependency]]<br />
<br />
That's it! Your project can now use the library.<br />
<br />
= Eclipse IDE user library =<br />
<br />
If you don't want to put JOGL in an Eclipse project, you can put it in a user library instead. The drawbacks to this are that the user library is defined in your .metadata directory and contains absolute paths, so it's hard to share with others. But for a non-shared project this works fine.<br />
<br />
=== Create a user library ===<br />
<br />
* Click "Window > Preferences", then select "Java > Build Path > User Libraries" on the left.<br />
* Click the "New..." button, type "JOGL" for the library name, and click "OK".<br />
[[File:Eclipse_setup_01_create_user_library.png|300px|thumb|none|Create user library]]<br />
* Click the "Add JARs..." button, navigate to the directory where you've stored the JARs, select all the non-native JARs, then click "Open".<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Expand each non-native JAR in the list<br />
** Double-click "Source attachment", type the module's source zip name, (e.g. <tt>jogl-java-src.zip</tt> for the JAR file <tt>jogl.all.jar</tt>), and click "OK".<br />
** If you're using native library files:<br />
*** Double-click "Native library location", type the directory where native library files are stored, and click "OK".<br />
[[File:Eclipse_setup_02_set_native_library_locations.png|300px|thumb|none|Set native library locations]]<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
=== Add the user library to your project's dependencies ===<br />
<br />
* Right-click your project in the Package Explorer and click "Properties".<br />
* Select "Java Build Path" and click the "Libraries" tab.<br />
[[File:Eclipse_setup_03_add_library_to_project.png|300px|thumb|none|Add library to project]]<br />
* Click "Add Library...", select "User Library", click "Next", check "JOGL", and click "Finish".<br />
[[File:Eclipse_setup_04_add_JOGL_library_to_project.png|300px|thumb|none|Add JOGL library to project]]<br />
* Click "OK" to dismiss the Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= IntelliJ IDEA =<br />
=== Add a library dependency to your project ===<br />
<br />
* Click "File > Project Structure".<br />
* Select "Modules" on the left, then click the "Dependencies" tab on the right.<br />
* Click the "+" button on the right, then select "Library... > Java".<br />
[[File:IntelliJ_setup_01_add_library.png|300px|thumb|none|Add library]]<br />
* Navigate to the directory where you extracted the JARs, select it, and click "OK".<br />
[[File:IntelliJ_setup_02_find_library.png|300px|thumb|none|Find library]]<br />
* Click "OK" to dismiss the Configure Library dialog.<br />
[[File:IntelliJ_setup_03_configure_library.png|300px|thumb|none|Configure library]]<br />
* Click "OK" to dismiss the Project Structure dialog. The external libraries in your project should now look like this if you're using native JAR files:<br />
[[File:IntelliJ_setup_04_external_library_native_JARs.png|300px|thumb|none|External libraries]]<br />
or like this if you're using native library files:<br />
[[File:IntelliJ_setup_04_external_library.png|300px|thumb|none|External libraries]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Edit Configurations".<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Parameters" box. Note that paths with spaces must be double-quoted on Windows.<br />
[[File:IntelliJ_setup_05_run_configuration.png|300px|thumb|none|Edit run configuration]]<br />
** Click "OK" to dismiss the Run/Debug Configurations dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= NetBeans IDE = <br />
=== Create a library and add it to your project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select "Libraries" on the left and click "Add Library...".<br />
* Click the "Create" button, then type "JOGL" for the library name and click "OK".[[File:NetBeans_setup_01_create_library.png|300px|thumb|none|Create library]]<br />
* Click "Add JAR/Folder...", then navigate to the directory you extracted the JAR files, select them and click "Add JAR/Folder".<br />
* Click "OK" to dismiss the Customize Library dialog.<br />
* Click "Add Library" to dismiss the Add Library dialog.[[File:NetBeans_setup_02_add_library.png|300px|thumb|none|Add library]]<br />
* Click "OK" to dismiss the Project Properties dialog. The libraries in your project should look like this.[[File:NetBeans_setup_03_libraries_in_project.png|300px|thumb|none|Libraries in project]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Set Project Configuration > Customize...". Select "Run" on the left if it isn't selected already.<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Options" box.<br />
** NOTE: If the library path has spaces in it, you must put quotes around it (at least on Windows) or you may get an odd NoClassDefFoundError when you try to run.[[File:NetBeans_setup_04_native_library_path.png|300px|thumb|none|Native library path]]<br />
** Click "OK" to dismiss the Project Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= vi and other text editors =<br />
=== Create your project with the editor of your choice ===<br />
* For example, to open vi, simply type <tt>vi</tt> and press <return>.<br />
* Type all your code, then save it.<br />
<br />
=== Compile and run your project from the command line ===<br />
* We assume your JOGL JAR files are in a directory called <tt>jar</tt>. If you're using native JARs, we assume they're also in the <tt>jar</tt> directory. If you're using native library files, we assume they're in a directory called <tt>lib</tt>.<br />
<br />
* First compile your program. We assume all your code is in a single file called <tt>name/someone/MyProject.java</tt>.<br />
** Windows: Type <tt>javac -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar" name\someone\MyProject.java</tt><br />
** Linux/MacOS X: Type <tt>javac -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar" name/someone/MyProject.java</tt><br />
<br />
* Then run your project. We assume your main class is <tt>name.someone.MyProject</tt>. If you're using native JARs:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." name.someone.MyProject</tt><br />
* If you're using native library files:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." -Djava.library.path=lib name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." -Djava.library.path=lib name.someone.MyProject</tt><br />
<br />
That's it! You can now use the library in your project.</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Setting_up_a_JogAmp_project_in_your_favorite_IDE&diff=669Setting up a JogAmp project in your favorite IDE2012-04-15T17:08:25Z<p>Wwalker: Typo</p>
<hr />
<div>__TOC__<br />
<br />
These instructions assume that you've created a project in your favorite IDE, and now you want your project to be able to use a JogAmp library like JOGL, JOCL, JOAL, or GlueGen. We use JOGL as an example below, but these instructions work equally well for any other JogAmp library.<br />
<br />
= Download a JogAmp library =<br />
<br />
If you haven't done so already, download and extract the JogAmp library you want to use. For example, to download and extract JOGL, see the instructions at [[Downloading and installing JOGL]].<br />
<br />
To use a JogAmp library you'll do three things:<br />
<br />
* Add its JAR files to the Java classpath<br />
* Add its native libraries in one of two ways:<br />
** Either place its native JAR files in the same directory as the library JAR files<br />
** Or add its native library files(the <tt>.dll</tt>,<tt>.so</tt>, and <tt>.jnilib</tt> files) to the Java library path<br />
* Optional: Associate the *-java-src.zip files with the corresponding JAR files.<br />
<br />
Each IDE has a slightly different way to do these things, as we show below. Using the native JAR files is usually slightly easier than using the native library files directly, and native JARs make it possible for all platforms' libraries to coexist in one project, so this is the recommended method.<br />
<br />
Please note that all JogAmp libraries depend on the GlueGen runtime libraries. These are included in every JogAmp library for convenience, but are only required once in the classpath and library path of your project.<br />
<br />
= Eclipse IDE =<br />
=== Create a user library ===<br />
<br />
You can make your new Eclipse project depend directly on all the JARs and native libraries, but it's inconvenient to do that every time you create a new project. Creating a user library bundles all the files together so you can include them in one step.<br />
<br />
* Click "Window > Preferences", then select "Java > Build Path > User Libraries" on the left.<br />
* Click the "New..." button, type "JOGL" for the library name, and click "OK".<br />
[[File:Eclipse_setup_01_create_user_library.png|300px|thumb|none|Create user library]]<br />
* Click the "Add JARs..." button, navigate to the directory where you've stored the JARs, select all the non-native JARs, then click "Open".<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Expand each non-native JAR in the list<br />
** Double-click "Source attachment", type the module's source zip name, (e.g. <tt>jogl-java-src.zip</tt> for the JAR file <tt>jogl.all.jar</tt>), and click "OK".<br />
** If you're using native library files:<br />
*** Double-click "Native library location", type the directory where native library files are stored, and click "OK".<br />
[[File:Eclipse_setup_02_set_native_library_locations.png|300px|thumb|none|Set native library locations]]<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
=== Add the user library to your project's dependencies ===<br />
<br />
* Right-click your project in the Package Explorer and click "Properties".<br />
* Select "Java Build Path" and click the "Libraries" tab.<br />
[[File:Eclipse_setup_03_add_library_to_project.png|300px|thumb|none|Add library to project]]<br />
* Click "Add Library...", select "User Library", click "Next", check "JOGL", and click "Finish".<br />
[[File:Eclipse_setup_04_add_JOGL_library_to_project.png|300px|thumb|none|Add JOGL library to project]]<br />
* Click "OK" to dismiss the Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= IntelliJ IDEA =<br />
=== Add a library dependency to your project ===<br />
<br />
* Click "File > Project Structure".<br />
* Select "Modules" on the left, then click the "Dependencies" tab on the right.<br />
* Click the "+" button on the right, then select "Library... > Java".<br />
[[File:IntelliJ_setup_01_add_library.png|300px|thumb|none|Add library]]<br />
* Navigate to the directory where you extracted the JARs, select it, and click "OK".<br />
[[File:IntelliJ_setup_02_find_library.png|300px|thumb|none|Find library]]<br />
* Click "OK" to dismiss the Configure Library dialog.<br />
[[File:IntelliJ_setup_03_configure_library.png|300px|thumb|none|Configure library]]<br />
* Click "OK" to dismiss the Project Structure dialog. The external libraries in your project should now look like this if you're using native JAR files:<br />
[[File:IntelliJ_setup_04_external_library_native_JARs.png|300px|thumb|none|External libraries]]<br />
or like this if you're using native library files:<br />
[[File:IntelliJ_setup_04_external_library.png|300px|thumb|none|External libraries]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Edit Configurations".<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Parameters" box. Note that paths with spaces must be double-quoted on Windows.<br />
[[File:IntelliJ_setup_05_run_configuration.png|300px|thumb|none|Edit run configuration]]<br />
** Click "OK" to dismiss the Run/Debug Configurations dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= NetBeans IDE = <br />
=== Create a library and add it to your project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select "Libraries" on the left and click "Add Library...".<br />
* Click the "Create" button, then type "JOGL" for the library name and click "OK".[[File:NetBeans_setup_01_create_library.png|300px|thumb|none|Create library]]<br />
* Click "Add JAR/Folder...", then navigate to the directory you extracted the JAR files, select them and click "Add JAR/Folder".<br />
* Click "OK" to dismiss the Customize Library dialog.<br />
* Click "Add Library" to dismiss the Add Library dialog.[[File:NetBeans_setup_02_add_library.png|300px|thumb|none|Add library]]<br />
* Click "OK" to dismiss the Project Properties dialog. The libraries in your project should look like this.[[File:NetBeans_setup_03_libraries_in_project.png|300px|thumb|none|Libraries in project]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Set Project Configuration > Customize...". Select "Run" on the left if it isn't selected already.<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Options" box.<br />
** NOTE: If the library path has spaces in it, you must put quotes around it (at least on Windows) or you may get an odd NoClassDefFoundError when you try to run.[[File:NetBeans_setup_04_native_library_path.png|300px|thumb|none|Native library path]]<br />
** Click "OK" to dismiss the Project Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= vi and other text editors =<br />
=== Create your project with the editor of your choice ===<br />
* For example, to open vi, simply type <tt>vi</tt> and press <return>.<br />
* Type all your code, then save it.<br />
<br />
=== Compile and run your project from the command line ===<br />
* We assume your JOGL JAR files are in a directory called <tt>jar</tt>. If you're using native JARs, we assume they're also in the <tt>jar</tt> directory. If you're using native library files, we assume they're in a directory called <tt>lib</tt>.<br />
<br />
* First compile your program. We assume all your code is in a single file called <tt>name/someone/MyProject.java</tt>.<br />
** Windows: Type <tt>javac -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar" name\someone\MyProject.java</tt><br />
** Linux/MacOS X: Type <tt>javac -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar" name/someone/MyProject.java</tt><br />
<br />
* Then run your project. We assume your main class is <tt>name.someone.MyProject</tt>. If you're using native JARs:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." name.someone.MyProject</tt><br />
* If you're using native library files:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." -Djava.library.path=lib name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." -Djava.library.path=lib name.someone.MyProject</tt><br />
<br />
That's it! You can now use the library in your project.</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Setting_up_a_JogAmp_project_in_your_favorite_IDE&diff=668Setting up a JogAmp project in your favorite IDE2012-04-15T17:01:09Z<p>Wwalker: Added mention of source zip association</p>
<hr />
<div>__TOC__<br />
<br />
These instructions assume that you've created a project in your favorite IDE, and now you want your project to be able to use a JogAmp library like JOGL, JOCL, JOAL, or GlueGen. We use JOGL as an example below, but these instructions work equally well for any other JogAmp library.<br />
<br />
= Download a JogAmp library =<br />
<br />
If you haven't done so already, download and extract the JogAmp library you want to use. For example, to download and extract JOGL, see the instructions at [[Downloading and installing JOGL]].<br />
<br />
To use a JogAmp library you'll do three things:<br />
<br />
* Add its JAR files to the Java classpath<br />
* Add its native libraries in one of two ways:<br />
** Either place its native JAR files in the same directory as the library JAR files<br />
** Or add its native library files(the <tt>.dll</tt>,<tt>.so</tt>, and <tt>.jnilib</tt> files) to the Java library path<br />
* Optional: Associate the *-java-src.zip files with the corresponding JAR files.<br />
<br />
Each IDE has a slightly different way to do these things, as we show below. Using the native JAR files is usually slightly easier than using the native library files directly, and native JARs make it possible for all platforms' libraries to coexist in one project, so this is the recommended method.<br />
<br />
Please note that all JogAmp libraries depend on the GlueGen runtime libraries. These are included in every JogAmp library for convenience, but are only required once in the classpath and library path of your project.<br />
<br />
= Eclipse IDE =<br />
=== Create a user library ===<br />
<br />
You can make your new Eclipse project depend directly on all the JARs and native libraries, but it's inconvenient to do that every time you create a new project. Creating a user library bundles all the files together so you can include them in one step.<br />
<br />
* Click "Window > Preferences", then select "Java > Build Path > User Libraries" on the left.<br />
* Click the "New..." button, type "JOGL" for the library name, and click "OK".<br />
[[File:Eclipse_setup_01_create_user_library.png|300px|thumb|none|Create user library]]<br />
* Click the "Add JARs..." button, navigate to the directory where you've stored the JARs, select all the non-native JARs, then click "Open".<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Expand each non-native JAR in the list<br />
** Double-click "Source attachment", type the module's source zip name, (e.g. <tt>jogl-java-src.zip</tt> for the JAR file <tt>jogl.all.jar</tt>), and click "OK".<br />
** If you're using native library files:<br />
*** Double-click "Native library location", type the directory where native library files are stored, and click "OK".<br />
[[File:Eclipse_setup_02_set_native_library_locations.png|300px|thumb|none|Set native library locations]]<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
=== Add the user library to your project's dependencies ===<br />
<br />
* Right-click your project in the Package Explorer and clock "Properties".<br />
* Select "Java Build Path" and click the "Libraries" tab.<br />
[[File:Eclipse_setup_03_add_library_to_project.png|300px|thumb|none|Add library to project]]<br />
* Click "Add Library...", select "User Library", click "Next", check "JOGL", and click "Finish".<br />
[[File:Eclipse_setup_04_add_JOGL_library_to_project.png|300px|thumb|none|Add JOGL library to project]]<br />
* Click "OK" to dismiss the Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= IntelliJ IDEA =<br />
=== Add a library dependency to your project ===<br />
<br />
* Click "File > Project Structure".<br />
* Select "Modules" on the left, then click the "Dependencies" tab on the right.<br />
* Click the "+" button on the right, then select "Library... > Java".<br />
[[File:IntelliJ_setup_01_add_library.png|300px|thumb|none|Add library]]<br />
* Navigate to the directory where you extracted the JARs, select it, and click "OK".<br />
[[File:IntelliJ_setup_02_find_library.png|300px|thumb|none|Find library]]<br />
* Click "OK" to dismiss the Configure Library dialog.<br />
[[File:IntelliJ_setup_03_configure_library.png|300px|thumb|none|Configure library]]<br />
* Click "OK" to dismiss the Project Structure dialog. The external libraries in your project should now look like this if you're using native JAR files:<br />
[[File:IntelliJ_setup_04_external_library_native_JARs.png|300px|thumb|none|External libraries]]<br />
or like this if you're using native library files:<br />
[[File:IntelliJ_setup_04_external_library.png|300px|thumb|none|External libraries]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Edit Configurations".<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Parameters" box. Note that paths with spaces must be double-quoted on Windows.<br />
[[File:IntelliJ_setup_05_run_configuration.png|300px|thumb|none|Edit run configuration]]<br />
** Click "OK" to dismiss the Run/Debug Configurations dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= NetBeans IDE = <br />
=== Create a library and add it to your project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select "Libraries" on the left and click "Add Library...".<br />
* Click the "Create" button, then type "JOGL" for the library name and click "OK".[[File:NetBeans_setup_01_create_library.png|300px|thumb|none|Create library]]<br />
* Click "Add JAR/Folder...", then navigate to the directory you extracted the JAR files, select them and click "Add JAR/Folder".<br />
* Click "OK" to dismiss the Customize Library dialog.<br />
* Click "Add Library" to dismiss the Add Library dialog.[[File:NetBeans_setup_02_add_library.png|300px|thumb|none|Add library]]<br />
* Click "OK" to dismiss the Project Properties dialog. The libraries in your project should look like this.[[File:NetBeans_setup_03_libraries_in_project.png|300px|thumb|none|Libraries in project]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Set Project Configuration > Customize...". Select "Run" on the left if it isn't selected already.<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Options" box.<br />
** NOTE: If the library path has spaces in it, you must put quotes around it (at least on Windows) or you may get an odd NoClassDefFoundError when you try to run.[[File:NetBeans_setup_04_native_library_path.png|300px|thumb|none|Native library path]]<br />
** Click "OK" to dismiss the Project Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= vi and other text editors =<br />
=== Create your project with the editor of your choice ===<br />
* For example, to open vi, simply type <tt>vi</tt> and press <return>.<br />
* Type all your code, then save it.<br />
<br />
=== Compile and run your project from the command line ===<br />
* We assume your JOGL JAR files are in a directory called <tt>jar</tt>. If you're using native JARs, we assume they're also in the <tt>jar</tt> directory. If you're using native library files, we assume they're in a directory called <tt>lib</tt>.<br />
<br />
* First compile your program. We assume all your code is in a single file called <tt>name/someone/MyProject.java</tt>.<br />
** Windows: Type <tt>javac -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar" name\someone\MyProject.java</tt><br />
** Linux/MacOS X: Type <tt>javac -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar" name/someone/MyProject.java</tt><br />
<br />
* Then run your project. We assume your main class is <tt>name.someone.MyProject</tt>. If you're using native JARs:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." name.someone.MyProject</tt><br />
* If you're using native library files:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." -Djava.library.path=lib name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." -Djava.library.path=lib name.someone.MyProject</tt><br />
<br />
That's it! You can now use the library in your project.</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Setting_up_a_JogAmp_project_in_your_favorite_IDE&diff=667Setting up a JogAmp project in your favorite IDE2012-04-15T16:47:45Z<p>Wwalker: Made it clearer what should be done to native JARs vs non-native JARs</p>
<hr />
<div>__TOC__<br />
<br />
These instructions assume that you've created a project in your favorite IDE, and now you want your project to be able to use a JogAmp library like JOGL, JOCL, JOAL, or GlueGen. We use JOGL as an example below, but these instructions work equally well for any other JogAmp library.<br />
<br />
= Download a JogAmp library =<br />
<br />
If you haven't done so already, download and extract the JogAmp library you want to use. For example, to download and extract JOGL, see the instructions at [[Downloading and installing JOGL]].<br />
<br />
To use a JogAmp library you'll have to do two things:<br />
<br />
* Add its JAR files to the Java classpath<br />
* Add its native libraries in one of two ways:<br />
** Either place its native JAR files in the same directory as the library JAR files<br />
** Or add its native library files(the <tt>.dll</tt>,<tt>.so</tt>, and <tt>.jnilib</tt> files) to the Java library path<br />
<br />
Each IDE has a slightly different way to do these things, as we show below. Using the native JAR files is usually slightly easier than using the native library files directly, and native JARs make it possible for all platforms' libraries to coexist in one project, so this is the recommended method.<br />
<br />
Please note that all JogAmp libraries depend on the GlueGen runtime libraries. These are included in every JogAmp library for convenience, but are only required once in the classpath and library path of your project.<br />
<br />
= Eclipse IDE =<br />
=== Create a user library ===<br />
<br />
You can make your new Eclipse project depend directly on all the JARs and native libraries, but it's inconvenient to do that every time you create a new project. Creating a user library bundles all the files together so you can include them in one step.<br />
<br />
* Click "Window > Preferences", then select "Java > Build Path > User Libraries" on the left.<br />
* Click the "New..." button, type "JOGL" for the library name, and click "OK".<br />
[[File:Eclipse_setup_01_create_user_library.png|300px|thumb|none|Create user library]]<br />
* Click the "Add JARs..." button, navigate to the directory where you've stored the JARs, select all the non-native JARs, then click "Open".<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Expand each non-native JAR in the list<br />
** Double-click "Source attachment", type the module's source zip name, (e.g. <tt>jogl-java-src.zip</tt> for the JAR file <tt>jogl.all.jar</tt>), and click "OK".<br />
** If you're using native library files:<br />
*** Double-click "Native library location", type the directory where native library files are stored, and click "OK".<br />
[[File:Eclipse_setup_02_set_native_library_locations.png|300px|thumb|none|Set native library locations]]<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
=== Add the user library to your project's dependencies ===<br />
<br />
* Right-click your project in the Package Explorer and clock "Properties".<br />
* Select "Java Build Path" and click the "Libraries" tab.<br />
[[File:Eclipse_setup_03_add_library_to_project.png|300px|thumb|none|Add library to project]]<br />
* Click "Add Library...", select "User Library", click "Next", check "JOGL", and click "Finish".<br />
[[File:Eclipse_setup_04_add_JOGL_library_to_project.png|300px|thumb|none|Add JOGL library to project]]<br />
* Click "OK" to dismiss the Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= IntelliJ IDEA =<br />
=== Add a library dependency to your project ===<br />
<br />
* Click "File > Project Structure".<br />
* Select "Modules" on the left, then click the "Dependencies" tab on the right.<br />
* Click the "+" button on the right, then select "Library... > Java".<br />
[[File:IntelliJ_setup_01_add_library.png|300px|thumb|none|Add library]]<br />
* Navigate to the directory where you extracted the JARs, select it, and click "OK".<br />
[[File:IntelliJ_setup_02_find_library.png|300px|thumb|none|Find library]]<br />
* Click "OK" to dismiss the Configure Library dialog.<br />
[[File:IntelliJ_setup_03_configure_library.png|300px|thumb|none|Configure library]]<br />
* Click "OK" to dismiss the Project Structure dialog. The external libraries in your project should now look like this if you're using native JAR files:<br />
[[File:IntelliJ_setup_04_external_library_native_JARs.png|300px|thumb|none|External libraries]]<br />
or like this if you're using native library files:<br />
[[File:IntelliJ_setup_04_external_library.png|300px|thumb|none|External libraries]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Edit Configurations".<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Parameters" box. Note that paths with spaces must be double-quoted on Windows.<br />
[[File:IntelliJ_setup_05_run_configuration.png|300px|thumb|none|Edit run configuration]]<br />
** Click "OK" to dismiss the Run/Debug Configurations dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= NetBeans IDE = <br />
=== Create a library and add it to your project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select "Libraries" on the left and click "Add Library...".<br />
* Click the "Create" button, then type "JOGL" for the library name and click "OK".[[File:NetBeans_setup_01_create_library.png|300px|thumb|none|Create library]]<br />
* Click "Add JAR/Folder...", then navigate to the directory you extracted the JAR files, select them and click "Add JAR/Folder".<br />
* Click "OK" to dismiss the Customize Library dialog.<br />
* Click "Add Library" to dismiss the Add Library dialog.[[File:NetBeans_setup_02_add_library.png|300px|thumb|none|Add library]]<br />
* Click "OK" to dismiss the Project Properties dialog. The libraries in your project should look like this.[[File:NetBeans_setup_03_libraries_in_project.png|300px|thumb|none|Libraries in project]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Set Project Configuration > Customize...". Select "Run" on the left if it isn't selected already.<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Options" box.<br />
** NOTE: If the library path has spaces in it, you must put quotes around it (at least on Windows) or you may get an odd NoClassDefFoundError when you try to run.[[File:NetBeans_setup_04_native_library_path.png|300px|thumb|none|Native library path]]<br />
** Click "OK" to dismiss the Project Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= vi and other text editors =<br />
=== Create your project with the editor of your choice ===<br />
* For example, to open vi, simply type <tt>vi</tt> and press <return>.<br />
* Type all your code, then save it.<br />
<br />
=== Compile and run your project from the command line ===<br />
* We assume your JOGL JAR files are in a directory called <tt>jar</tt>. If you're using native JARs, we assume they're also in the <tt>jar</tt> directory. If you're using native library files, we assume they're in a directory called <tt>lib</tt>.<br />
<br />
* First compile your program. We assume all your code is in a single file called <tt>name/someone/MyProject.java</tt>.<br />
** Windows: Type <tt>javac -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar" name\someone\MyProject.java</tt><br />
** Linux/MacOS X: Type <tt>javac -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar" name/someone/MyProject.java</tt><br />
<br />
* Then run your project. We assume your main class is <tt>name.someone.MyProject</tt>. If you're using native JARs:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." name.someone.MyProject</tt><br />
* If you're using native library files:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." -Djava.library.path=lib name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." -Djava.library.path=lib name.someone.MyProject</tt><br />
<br />
That's it! You can now use the library in your project.</div>Wwalkerhttps://jogamp.org/wiki/index.php?title=Setting_up_a_JogAmp_project_in_your_favorite_IDE&diff=666Setting up a JogAmp project in your favorite IDE2012-04-13T14:50:18Z<p>Wwalker: Fix picture alignment, but correctly this time</p>
<hr />
<div>__TOC__<br />
<br />
These instructions assume that you've created a project in your favorite IDE, and now you want your project to be able to use a JogAmp library like JOGL, JOCL, JOAL, or GlueGen. We use JOGL as an example below, but these instructions work equally well for any other JogAmp library.<br />
<br />
= Download a JogAmp library =<br />
<br />
If you haven't done so already, download and extract the JogAmp library you want to use. For example, to download and extract JOGL, see the instructions at [[Downloading and installing JOGL]].<br />
<br />
To use a JogAmp library you'll have to do two things:<br />
<br />
* Add its JAR files to the Java classpath<br />
* Add its native libraries in one of two ways:<br />
** Either place its native JAR files in the same directory as the library JAR files<br />
** Or add its native library files(the <tt>.dll</tt>,<tt>.so</tt>, and <tt>.jnilib</tt> files) to the Java library path<br />
<br />
Each IDE has a slightly different way to do these things, as we show below. Using the native JAR files is usually slightly easier than using the native library files directly, and native JARs make it possible for all platforms' libraries to coexist in one project, so this is the recommended method.<br />
<br />
Please note that all JogAmp libraries depend on the GlueGen runtime libraries. These are included in every JogAmp library for convenience, but are only required once in the classpath and library path of your project.<br />
<br />
= Eclipse IDE =<br />
=== Create a user library ===<br />
<br />
You can make your new Eclipse project depend directly on all the JARs and native libraries, but it's inconvenient to do that every time you create a new project. Creating a user library bundles all the files together so you can include them in one step.<br />
<br />
* Click "Window > Preferences", then select "Java > Build Path > User Libraries" on the left.<br />
* Click the "New..." button, type "JOGL" for the library name, and click "OK".<br />
[[File:Eclipse_setup_01_create_user_library.png|300px|thumb|none|Create user library]]<br />
* Click the "Add JARs..." button, navigate to the directory where you've stored the JARs, select them, then click "Open".<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Expand each JAR in the list<br />
** Double-click "Source attachment", type the module's source zip name, (e.g. <tt>jogl-java-src.zip</tt> for the JAR file <tt>jogl.all.jar</tt>), and click "OK".<br />
** If you're using native library files:<br />
*** Double-click "Native library location", type the directory where native library files are stored, and click "OK".<br />
[[File:Eclipse_setup_02_set_native_library_locations.png|300px|thumb|none|Set native library locations]]<br />
* Click "OK" to exit Preferences dialog.<br />
<br />
=== Add the user library to your project's dependencies ===<br />
<br />
* Right-click your project in the Package Explorer and clock "Properties".<br />
* Select "Java Build Path" and click the "Libraries" tab.<br />
[[File:Eclipse_setup_03_add_library_to_project.png|300px|thumb|none|Add library to project]]<br />
* Click "Add Library...", select "User Library", click "Next", check "JOGL", and click "Finish".<br />
[[File:Eclipse_setup_04_add_JOGL_library_to_project.png|300px|thumb|none|Add JOGL library to project]]<br />
* Click "OK" to dismiss the Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= IntelliJ IDEA =<br />
=== Add a library dependency to your project ===<br />
<br />
* Click "File > Project Structure".<br />
* Select "Modules" on the left, then click the "Dependencies" tab on the right.<br />
* Click the "+" button on the right, then select "Library... > Java".<br />
[[File:IntelliJ_setup_01_add_library.png|300px|thumb|none|Add library]]<br />
* Navigate to the directory where you extracted the JARs, select it, and click "OK".<br />
[[File:IntelliJ_setup_02_find_library.png|300px|thumb|none|Find library]]<br />
* Click "OK" to dismiss the Configure Library dialog.<br />
[[File:IntelliJ_setup_03_configure_library.png|300px|thumb|none|Configure library]]<br />
* Click "OK" to dismiss the Project Structure dialog. The external libraries in your project should now look like this if you're using native JAR files:<br />
[[File:IntelliJ_setup_04_external_library_native_JARs.png|300px|thumb|none|External libraries]]<br />
or like this if you're using native library files:<br />
[[File:IntelliJ_setup_04_external_library.png|300px|thumb|none|External libraries]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Edit Configurations".<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Parameters" box. Note that paths with spaces must be double-quoted on Windows.<br />
[[File:IntelliJ_setup_05_run_configuration.png|300px|thumb|none|Edit run configuration]]<br />
** Click "OK" to dismiss the Run/Debug Configurations dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= NetBeans IDE = <br />
=== Create a library and add it to your project ===<br />
<br />
* Right-click your project and click "Properties".<br />
* Select "Libraries" on the left and click "Add Library...".<br />
* Click the "Create" button, then type "JOGL" for the library name and click "OK".[[File:NetBeans_setup_01_create_library.png|300px|thumb|none|Create library]]<br />
* Click "Add JAR/Folder...", then navigate to the directory you extracted the JAR files, select them and click "Add JAR/Folder".<br />
* Click "OK" to dismiss the Customize Library dialog.<br />
* Click "Add Library" to dismiss the Add Library dialog.[[File:NetBeans_setup_02_add_library.png|300px|thumb|none|Add library]]<br />
* Click "OK" to dismiss the Project Properties dialog. The libraries in your project should look like this.[[File:NetBeans_setup_03_libraries_in_project.png|300px|thumb|none|Libraries in project]]<br />
<br />
* If you're using native JAR files:<br />
** Make sure the <tt>gluegen-rt-natives-*-*.jar</tt> and <tt>jogl-all-natives-*-*.jar</tt> files for each platform you want to run on are in the same directory as the other JAR files. The native JAR files don't need to be added to the classpath.<br />
* Otherwise, if you're using native library files:<br />
** Click "Run > Set Project Configuration > Customize...". Select "Run" on the left if it isn't selected already.<br />
** Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Options" box.<br />
** NOTE: If the library path has spaces in it, you must put quotes around it (at least on Windows) or you may get an odd NoClassDefFoundError when you try to run.[[File:NetBeans_setup_04_native_library_path.png|300px|thumb|none|Native library path]]<br />
** Click "OK" to dismiss the Project Properties dialog.<br />
<br />
That's it! You can now use the library in your project.<br />
<br />
= vi and other text editors =<br />
=== Create your project with the editor of your choice ===<br />
* For example, to open vi, simply type <tt>vi</tt> and press <return>.<br />
* Type all your code, then save it.<br />
<br />
=== Compile and run your project from the command line ===<br />
* We assume your JOGL JAR files are in a directory called <tt>jar</tt>. If you're using native JARs, we assume they're also in the <tt>jar</tt> directory. If you're using native library files, we assume they're in a directory called <tt>lib</tt>.<br />
<br />
* First compile your program. We assume all your code is in a single file called <tt>name/someone/MyProject.java</tt>.<br />
** Windows: Type <tt>javac -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar" name\someone\MyProject.java</tt><br />
** Linux/MacOS X: Type <tt>javac -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar" name/someone/MyProject.java</tt><br />
<br />
* Then run your project. We assume your main class is <tt>name.someone.MyProject</tt>. If you're using native JARs:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." name.someone.MyProject</tt><br />
* If you're using native library files:<br />
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\jogl.all.jar;." -Djava.library.path=lib name.someone.MyProject</tt><br />
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/jogl.all.jar:." -Djava.library.path=lib name.someone.MyProject</tt><br />
<br />
That's it! You can now use the library in your project.</div>Wwalker