This tutorial is based upon the tutorial written by Hideya Kawahara.

Aim: To demonstrate the basic steps of creating a 3D application within the lg3d framework
Requirements: To use this tutorial you will need a functional installation of the of lg3d (the stable version is the best version to begin with). This can be found at the lg3d-core web site. Follow the "Getting started with Project Looking Glass" link for installation instructions. You do not need to run the lg3d-session version.
  Additionally, you need to have the Java 1.5 SDK. This is available at the Sun Java web site.
  If you have been following the previous versions of the tutorials, you will note some changes. Throughout this tutorial I will note the changes, and advantages of the changes made to the API. The 0.6.2 marks a major change in the API to support many animation tasks.
 
Steps:
  1. Create a root container
  2. Create a box to put in the container
  3. Put the box in the container
  4. Initialize the container
  5. Compile the code
  6. Package the Tutorial to run in LG3D
  7. Run our application
 
 
Step 1: Create a root container
  First, we need to create the root container for this 3D application. The Frame3D class serves for this purpose. We can extend Frame3D, or simply create one and add components to it. In this example, we'll take the later approach.
 
 
    Frame3D frame3d = new Frame3D();
 
Step 2: Create a box to put in the container
 
  Now, let's try to put a box of 8cm x 6cm x 4cm at the center of this application. Predefined shapes found under org.jdesktop.lg3d.utils.shape are handy for this purpose.
By the way, what color would you like to paint it? Let's try pale green for this example. Therefore we need to create an appearance object to handle the color of the box. The API also provides a handy class to specify color, which is SimpleAppearance. Additionally you can specify the object's color in a more detailed manner, including shininess and what color it shines, translucency and textures applied to it. You can find out more by looking at the API documentation for Appearance, Material and Texture.
 
 
    SimpleAppearance app = new SimpleAppearance(0.6f, 0.8f, 0.6f);
 
  Now that we have a default appearance, we can create the box of 8cm x 6cm x 4cm. Note that we need to specify half the length of each dimension to the constructor of the predefined Box class. It creates a box that lies within the bounding box, [-x, -y, -z] and [x, y, z], where x, y and z are the first three arguments to the constructor.
Change Note:The Primitive.GEOMETRY_NOT_SHARED and Primitive.GENERATE_NORMALS flags are not needed in the version 0.6.2 of the API, they are handled internally.
 
 
    Box box = new Box(0.04f, 0.03f, 0.02f, app);
  Project Looking Glass 3D APIs are based on Java 3D. In Java 3D, by default, the metric system is used, where one (1) unit equals one meter. And if configured correctly, by drawing an object of size 0.02 units turns into an object approximately 2cm in size on the screen.
Please note that the default configuration for lg3d is for a perspective view, therefore the drawing size varies depending upon how far away, or how close the object is. By default, the 3D scene manager of lg3d will position the object at a reasonable position where the size is close to the size intended.
 
Step 3: Put the box in the container
  To display the box on the screen, we must add the box to the top level container. The box cannot be added directly to the Frame3D, only a Component3D can be added to Frame3Ds (this functionality is inherited from Container3D). Component3D is the base component for all the lg3d components. One component can have multiple Shape3D objects to define its shape (note that Box inherits Shape3D), and a Frame3D can host multiple Component3Ds (including nested Container3Ds).
Therefore we must create a Component3D.
 
 
    Component3D comp = new Component3D();
 
  Then add the box to the Component3D.
 
 
    comp.addChild(box);
 
  Now the Component3D can be added to the root container.
 
 
    frame3d.addChild(comp);
 
Step 4: Initialize the container
  Change Note:The call to setCapabilities() is not longer needed, default capabilities are automatically set, and applied to any children when they are added to the Frame3D
 
  To assist the SceneManager (at least in the default scene manager - GlassySceneManager) it is useful to set the size hint for the Frame3D. This is used by the SceneManager to arrange 3D applications in the 3D space it manages.
Change Note:The naming scheme has been changed from previous versions of API to follow the Swing API standards, therefore setSize has been changed to the more appropriate setPreferredSize(Vector3f).
 
 
    frame3d.setPreferredSize(new Vector3f(0.08f, 0.06f, 0.04f));
  To make the frame visible two steps are required.
First, the frame needs to be added to the scenegraph. The changeEnabled(boolean) call does this. More precisely, the call initiates interaction with the 3D SceneManager and the manager handles the details of the policy for presenting the application (e.g. location, size, etc.).
Change note: Previously this was done by the setActive(boolean) method. The function call has been renamed to follow standard Java practices of using setEnabled(boolean) to enable a component. The method setEnabled(boolean) can also be used in the same way, however using changeEnabled(boolean) allows for animated changes of enabled status, whereas setEnabled(boolean) will work immediately. This naming convention is standard across the API.
 
 
    frame3d.changeEnabled(true);
  Second, although the frame is active, it must also be made visible. Note setVisible(boolean) is fairly light-weight compared to the changeEnabled() call, therefore changeVisible() should be used to temporarily hide an object.
Change note:Like the changeEnabled note above, this has been changed to allow for animations while making the Frame3D visible within the SceneManager.
 
 
    frame3d.changeVisible(true);
 
Step 5: Compile the code
  We have finished writing the code. The full version includes the required import statements, and various constructor and main methods. Download Tutorial1.java
Now we need to compile the source file. The tutorial requires the lg3d core library and Java 1.5 to compile. The core library can be found under the lib directory of the lg3d distribution (replace $LG3DHOME with the path to the lg3d distribution).
 
 
    javac -cp "$LG3DHOME/lib/ext/lg3d-core.jar" Tutorial1.java
 
Step 6: Package the Tutorial to run in LG3D
Starting with release 0.7.0 applications can be easily added to the taskbar so they can be run. Upon initialization LG3D looks for packaged applications in the ext/app directory. Therefore to run our tutorial we just need to create a jar file and specify some parameters in the manifest file.
Manifest files provide basic information about the data contained within the jar file. More information about Manifest files can be read at http://java.sun.com/docs/books/tutorial/jar/manifest/index.html.
We will create a simple manifest file to run this application. Edit a file Tutorial1.MF:
 
    Implementation-Title: Tutorial 1
    Main-Class: Tutorial1
  These parameters mean:
    Implementation-Title: The name of the application.
    Main-Class: This is the standard manifest parameter that specifies the class file to execute when executing a jar file (e.g. java -jar syntax).

Next we create a jar file using the manifiest file and the Tutorial1.class file.
 
    jar cmvf Tutorial1.MF Tutorial1.jar Tutorial1.class
  Copy the Tutorial1.jar to $LG3DHOME/ext/app creating the directory if it does not exist.
Step 7: Run our application
Now that the jar file is copied into the ext/app directory you just need to start lg3d as normal, and the tutorial will be added to the taskbar. It uses the default application icon.
    ./lg3d-dev
Click on the lg3d button. The lg3d desktop should be displayed with a pale green screen box in the center (as you see below). In actual fact, only a pale green square can be seen - in the next tutorial the box will be rotated to make it look like a box.
The pale green box from Tutorial1