Simple Application

Step 1 - Create a frame



There are two types of OpenGL "windows" in JOGL, a GLCanvas and a GLJPanel. The GLJPanel is for use with the normal Java2D API while the GLCanvas is a high performace version. To create an OpenGL window first create a Frame and the simply add a GLCanvas to it.
Frame frame = new Frame("PBuffers") ;
GLCanvas canvas = new GLCanvas() ;
canvas.addGLEventListener(this);
frame.add(canvas);
frame.setSize(640, 480);

The application is notified of OpenGL events via 4 simple callbacks that are called following the registration of the GLEventListener listener via the canvas.addGLEventListener(this) call. It's easier to use the GLU functions with can be called from the GLU object.

Step 2 - Initilize the OpenGL context


The init() method is called when the windows is first created. The display() function is only called when the display needs to be repainted so the Animator class be used to update the display periodically.

public void init(GLAutoDrawable drawable) 
{
final GL gl = drawable.getGL();
gl.setSwapInterval(0);
animator = new Animator(canvas);
animator.setRunAsFastAsPossible(true) ;
animator.start() ;
}

Step 3 - Add a display callback


The display() method is called when the window needs to be updated and is where all the OpenGL drawing should take place.

public void display(GLAutoDrawable drawable) 
{
GL gl = drawable.getGL() ;
}

Step 4 - Add a reshape callback


The reshape() method is called when the window size changes. This callback is called once when the application is started.

public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) 
{
GL gl = drawable.getGL();
float h = (float) width / (float) height;
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective( 40.0, h, 1.00, 100.0 );
}

Step 5 - Add a displayChanged callback


The displayChanged() method is called then the display is changed.

public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) 
{
}

Notes:

  • If the GLUT objects appear to be rendered back to front (or inside out) then try gl.glEnable(GL.GL_CW) as GLUT polygons are rendered in clock-wise order.

  • Setup light sources with all options as LIGHT0 has defaults that the others lights do not appear to have.

    gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, light2pos, 0);
    gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, light2amb, 0);
    gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, light2diff, 0);
    gl.glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, light2spec, 0);
    gl.glEnable(GL.GL_LIGHT1);


Labels

Web Search Gmail Google Docs Mobile YouTube Google Maps Google Chrome User interface Tips iGoogle Social Google Reader Traffic Making Devices cpp programming Ads Image Search Google Calendar tips dan trik Google Video Google Translate web programming Picasa Web Albums Blogger Google News Google Earth Yahoo Android Google Talk Google Plus Greasemonkey Security software download info Firefox extensions Google Toolbar Software OneBox Google Apps Google Suggest SEO Traffic tips Book Search API Acquisitions InOut Visualization Web Design Method for Getting Ultimate Traffic Webmasters Google Desktop How to Blogging Music Nostalgia orkut Google Chrome OS Google Contacts Google Notebook SQL programming Google Local Make Money Windows Live GDrive Google Gears April Fools Day Google Analytics Google Co-op visual basic Knowledge java programming Google Checkout Google Instant Google Bookmarks Google Phone Google Trends Web History mp3 download Easter Egg Google Profiles Blog Search Google Buzz Google Services Site Map for Ur Site game download games trick Google Pack Spam cerita hidup Picasa Product's Marketing Universal Search FeedBurner Google Groups Month in review Twitter Traffic AJAX Search Google Dictionary Google Sites Google Update Page Creator Game Google Finance Google Goggles Google Music file download Annoyances Froogle Google Base Google Latitude Google Voice Google Wave Google Health Google Scholar PlusBox SearchMash teknologi unik video download windows Facebook Traffic Social Media Marketing Yahoo Pipes Google Play Google Promos Google TV SketchUp WEB Domain WWW World Wide Service chord Improve Adsence Earning jurnalistik sistem operasi AdWords Traffic App Designing Tips and Tricks WEB Hosting linux How to Get Hosting Linux Kernel WEB Errors Writing Content award business communication ubuntu unik