Okay, no food that doesn't require cooking so I will press forward and cover as much as I can until I pass out from starvation

You will build your JOGL application much the same as you build any other AWT application (for now):
1 2
| Frame testFrame = new Frame("TestFrame"); testFrame.setSize( 512, 384 ); |
Note here that I am creating a frame and giving that frame a size. Since at the moment I don't plan to have any extra stuff in that frame other than the rendered component this is fine and I won't worry about a layoutmanager.
The next thing you need is a warm piece of GLCanvas to draw on. Since you cannot directly instantiate GLCanvas (which is good OO design) you must obtain it from the factory that creates them. This is GLDrawableFactory. We will tell this factory that we want it to create and return to us a GLCanvas with a default set of capabilities.
1
| GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas( new GLCapabilities() ); |
The capabilities that you want a GLCanvas to have are specified in GLCapabilities. So if you want something with specific buffers, bitdepths, etc, you would create a GLCapabilities() object that has those capabilities and pass that into the factory as so:
1 2 3 4 5 6 7
| GLCapabilities glCaps = new GLCapabilities(); glCaps.setRedBits(8); glCaps.setBlueBits(8); glCaps.setGreenBits(8); glCaps.setAlphaBits(8); GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas( glCaps ); |
There is a lot of stuff you can do with GLCapabilities but I'm not going to cover that here - explore and experiment.
Now that you have your GLCanvas done you need to add it to the Frame so that people will be able to see it.
1
| testFrame.add( canvas ); |
So now you have a GLCanvas on a Frame and when that frame comes up it will do.... nothing

The reason it won't do anything is because of the architecture of JOGL. JOGL will emit a series of events that will tell you what's going on with the framework so that you can listen for those events and do the right thing. JOGL refers to this as a GLEventListener. The GLEventListener contains the methods that we're most interested in: init(), display(), reshape(), and displayChanged().
When the GLCanvas (which is a GLDrawable) is rendered for the first time, init(GLDrawable) is called. In this method you would do the same thing you would do in an init call to your old OpenGL engines. Set up any initial settings and get yourself ready to draw. If you aren't following the JOGL architecture properly, you may be able to hack some drawing into this method but DO NOT do this. You will make your life harder later. Load textures, geometry, etc here, but don't start trying to render anything in this method.
1 2 3 4 5 6 7 8 9
| public void init(GLDrawable drawable) { this.gl = drawable.getGL(); this.glDrawable = drawable;
drawable.setGL( new DebugGL(drawable.getGL() ));
System.out.println("Init GL is " + gl.getClass().getName()); } |
When a GLDrawable is told to render, this method is called. Note that this is a good way to decouple the rendering interface from any sort of frame rate limiter or timing system. Anyways, THIS is the method where you want to do your drawing.
1 2 3 4 5 6 7 8 9 10 11 12 13
| public void display(GLDrawable drawable) { gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT ); gl.glLoadIdentity();
gl.glColor3f(1.0f, 0.0f, 0.0f );
gl.glBegin( GL.GL_TRIANGLES ); gl.glVertex3f( 0.0f, 0.0f, 0.0f ); gl.glVertex3f( 1.0f, 0.0f, 0.0f ); gl.glVertex3f( 1.0f, 1.0f, 0.0f ); gl.glEnd(); } |
There has been some question as to whether or not one should reacquire gl in the display method. I have as of yet found it unnecessary to do this and I'm not sure why its recommended as the GLDrawable should not be destroyed at any point during rendering and as such should be cacheable as should GL and GLU.
The next method of interest is reshape(). Just like with GLUT, reshape is called when your context changes shape. Its useful to make camera adjustments and the like when this occurs in this method. Since I currently don't support these operations this method is undefined:
1 2 3
| public void reshape(GLDrawable drawable, int x, int y, int width, int height) { } |
The same can be said of display changed. If the device or display mode changes, JOGL will let you know so you can handle your rendering accordingly.
1 2 3
| public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) { } |
So now you have the code for what I refer to at the TestRenderer, but you can call it whatever you want so long as it implements GLEventListener.
Now that you have a GLEventListener lo and behold you application renders... nothing still

The reason is again in the JOGL architecture. Recall that the display method needs to be called before anything gets drawn to the screen. Well - you don't have anything calling display(). You COULD throw in a while loop that spun forever calling display(), but there is really a better way. JOGL includes the concept of an Animator. This animator basically holds the tempo of when display gets called. Personally I think RenderLoop might have been a better name, but hey you can extend it and call it whatever you want right

To make a long story short you need to add an Animator so that display is getting called. For this tutorial I will use the one provided for by JOGL, though one that handles frame rates properly is likely going to make a LOT more sense for anything running in a Window. No sense having JOGL running in a window yet taking up so much CPU that nothing else can really run either. The last chunk of code that you need is
1 2 3 4 5 6 7 8 9
| final Animator animator = new Animator(canvas); testFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { animator.stop(); System.exit(0); } }); testFrame.show(); animator.start(); |
There you have it. Go ahead and compile/run and you will have one cheesy triangle. The world is now yours to control because if you can draw one triangle, you can draw millions of triangles in 3D space with textures and stuff and have a real game. At this point you might want to take a look at some OpenGL resources as it won't matter whether or not you're coding in C++ or Java as OpenGL is OpenGL and it will be simple to tell what needs to be syntactically changed to work with JOGL (or LWJGL for that matter).