/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.geoforge.plg3danimatedshapes.media.opengl.awt;
import java.awt.Dimension;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.fixedfunc.GLLightingFunc;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
import javax.media.opengl.glu.GLU;
/**
*
* JOGL 2.0 Example 2: Rotating 3D Shapes (GLCanvas)
*
* source: http://www3.ntu.edu.sg/home/ehchua/programming/opengl/JOGL2.0.html
*
* Java source: JOGL2Ex2Rotate3D_GLCanvas
* @author Chua Hock Chuan
*
*
*
* modified by bantchao@gmail.com
*/
public class GfrGLCanvasPlgViewerVolShps3dAni extends GLCanvas implements
GLEventListener
{
private static final int _INT_CANVAS_WIDTH_ = 320; // width of the drawable
private static final int _INT_CANVAS_HEIGHT_ = 240; // height of the drawable
// ---
// Setup OpenGL Graphics Renderer
private GLU _glu_; // for the GL Utility
public GfrGLCanvasPlgViewerVolShps3dAni()
{
super();
setSize(new Dimension(_INT_CANVAS_WIDTH_, _INT_CANVAS_HEIGHT_));
super.addGLEventListener((GLEventListener) this);
}
@Override
public void init(GLAutoDrawable drawable)
{
GL2 gl = drawable.getGL().getGL2(); // get the OpenGL graphics context
this._glu_ = new GLU(); // get GL Utilities
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background (clear) color
gl.glClearDepth(1.0f); // set clear depth value to farthest
gl.glEnable(GL.GL_DEPTH_TEST); // enables depth testing
gl.glDepthFunc(GL.GL_LEQUAL); // the type of depth test to do
gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); // best perspective correction
gl.glShadeModel(GLLightingFunc.GL_SMOOTH); // blends colors nicely, and smoothes out lighting
}
@Override
public void dispose(GLAutoDrawable glad)
{
super.removeGLEventListener((GLEventListener) this);
System.out.println("TODO: GfrGLCanvasPlgViewerVolShps3dAni.dispose()");
}
@Override
public void display(GLAutoDrawable drawable)
{
GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // clear color and depth buffers
DisplayShapePyramid.getInstance().doJob(gl);
DisplayShapeCube.getInstance().doJob(gl);
}
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
{
GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
if (height == 0) height = 1; // prevent divide by zero
float aspect = (float)width / height;
// Set the view port (display area) to cover the entire window
gl.glViewport(0, 0, width, height);
// Setup perspective projection, with aspect ratio matches viewport
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); // choose projection matrix
gl.glLoadIdentity(); // reset projection matrix
this._glu_.gluPerspective(45.0, aspect, 0.1, 100.0); // fovy, aspect, zNear, zFar
// Enable the model-view transform
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadIdentity(); // reset
}
}