@author krunde
*/
public class MyRenderer extends Renderer {
public MyRenderer(){
//Does nothing for now
}
/**
* @see template.Renderer#customInit(net.java.games.jogl.GLDrawable)
*/
public void customInit(GLDrawable drawable){
GL gl = drawable.getGL();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glShadeModel(GL.GL_FLAT);
}
/**
* @see net.java.games.jogl.GLEventListener#display(net.java.games.jogl.GLDrawable)
*/
public void display(GLDrawable drawable) {
//System.out.println(“display called”);
GL gl;
gl = drawable.getGL();
//Reset OpenGL Clear the screen and depth buffer. Then reset the view.
gl.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
//Move us over to draw the Triangle
gl.glTranslated(-1.5f, 0.0f, -6.0f);
//Draw a triangle
gl.glBegin(GL.GL_TRIANGLES);
gl.glVertex3f(0.0f, 1.0f, 0.0f);
gl.glVertex3f(-1.0f, -1.0f, 0.0f);
gl.glVertex3f(1.0f, -1.0f, 0.0f);
gl.glEnd();
//Move us over to draw the Square
gl.glTranslated(3.0f, 0.0f, 0.0f);
gl.glBegin(GL.GL_QUADS);
gl.glVertex3f(-1.0f, 1.0f, 0.0f);
gl.glVertex3f(1.0f, 1.0f, 0.0f);
gl.glVertex3f(1.0f, -1.0f, 0.0f);
gl.glVertex3f(-1.0f, -1.0f, 0.0f);
gl.glEnd();
gl.glFlush();
}
/** Called by the drawable during the first repaint after the component has
* been resized. The client can update the viewport and view volume of the
* window appropriately, for example by a call to
* GL.glViewport(int, int, int, int); note that for convenience the component
* has already called GL.glViewport(int, int, int, int)(x, y, width, height)
* when this method is called, so the client may not have to do anything in
* this method.
*
* @param gLDrawable The GLDrawable object.
* @param x The X Coordinate of the viewport rectangle.
* @param y The Y coordinate of the viewport rectanble.
* @param width The new width of the window.
* @param height The new height of the window.
*/
public void reshape(GLDrawable gLDrawable, int x, int y, int width, int height){
final GL gl = gLDrawable.getGL();
final GLU glu = gLDrawable.getGLU();
if(height <= 0){
height = 1;
}
final float h = (float)width / (float)height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 1.0, 20.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
}