import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
/**
* Name: joglHello
* Description: Render
*
* @author: Victor Häggqvist
* @since: 2/9/14
* Package: PACKAGE_NAME
*/
class Renderer implements GLEventListener
{
private GLU glu = new GLU();
public void display(GLAutoDrawable gLDrawable)
{
final GL2 gl = gLDrawable.getGL().getGL2();
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(-1.5f, 0.0f, -10.0f);
gl.glColor3f(0f, 255f, 255f);
gl.glRotated(20,20,0,20);
gl.glBegin(GL2.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();
gl.glTranslatef(3.0f, 0.0f, 0.0f);
gl.glColor3f(0f,255f,0f);
gl.glRotated(-20,-20,0,-20);
gl.glBegin(GL2.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.glTranslatef(3.0f, 0.0f, 0.0f);
gl.glColor3f(255f,200f,0f);
gl.glRotated(45,45,0,45);
gl.glBegin(GL2.GL_QUADS);
gl.glVertex3f(-0.5f, 0.5f, 0.0f);
gl.glVertex3f(0.5f, 0.5f, 0.0f);
gl.glVertex3f(0.5f, -0.5f, 0.0f);
gl.glVertex3f(-0.5f, -0.5f, 0.0f);
gl.glEnd();
gl.glFlush();
}
public void displayChanged(GLAutoDrawable gLDrawable, boolean modeChanged, boolean deviceChanged)
{
System.out.println("displayChanged called");
}
public void init(GLAutoDrawable gLDrawable)
{
System.out.println("init() called");
GL2 gl = gLDrawable.getGL().getGL2();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glShadeModel(GL2.GL_FLAT);
}
public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height)
{
System.out.println("reshape() called: x = "+x+", y = "+y+", width = "+width+", height = "+height);
final GL2 gl = gLDrawable.getGL().getGL2();
if (height <= 0) // avoid a divide by zero error!
{
height = 1;
}
final float h = (float) width / (float) height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 1.0, 20.0);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void dispose(GLAutoDrawable arg0)
{
System.out.println("dispose() called");
}
}