package org.yourorghere;
import com.sun.opengl.util.Animator;
import com.sun.opengl.util.GLUT;
import java.awt.Frame;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
/**
* GLRenderer.java <BR>
* author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P>
*
* This version is equal to Brian Paul's version 1.2 1999/10/21
*/
public class GLRenderer implements GLEventListener, KeyListener, MouseListener {
public static void main(String[] args) {
Frame frame = new Frame("Simple JOGL Application");
GLCanvas canvas = new GLCanvas();
canvas.addGLEventListener((GLEventListener) new SimpleGLJPanel());
frame.add(canvas);
frame.setSize(640, 480);
final Animator animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
new Thread(new Runnable() {
public void run() {
animator.stop();
System.exit(0);
}
}).start();
}
});
// Center frame
frame.setLocationRelativeTo(null);
frame.setVisible(true);
animator.start();
}
public void init(GLAutoDrawable drawable) {
// Use debug pipeline
// drawable.setGL(new DebugGL(drawable.getGL()));
GL gl = drawable.getGL();
drawable.addKeyListener(this);
drawable.addMouseListener(this);
// Setup the drawing area and shading mode
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glEnable(gl.GL_DEPTH_TEST);
gl.glClearDepth(1.0);
gl.glDepthFunc(GL.GL_LESS);
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
GL gl = drawable.getGL();
GLU glu = new GLU();
gl.glViewport(x,y,width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
if (width <= height) {
gl.glOrtho(-2,2,-2*((double) height)/(double) width,2*((double) height)/(double)width,-5,5);
}
else{ gl.glOrtho( -2*((double) width)/(double) height ,2*((double)width )/(double)height,-2,2,-5,5);}
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
glu.gluLookAt(0.5, 0.5, 0.5, 0, 0, 0, 0, 1, 0);
}
public void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
GLUT glut = new GLUT();
for(int i = 0; i < 6; i++) {
gl.glPushMatrix();
//gl.glRotatef(viewRotX, 1.0f, 0.0f, 0.0f);
//gl.glRotatef(viewRotY, 0.0f, 1.0f, 0.0f);
gl.glColor3f(1.0f,1.0f,1.0f);
glut.glutWireCube(0.8f);
gl.glColor3f(1.0f, 0.5f, 0.0f); // ORANGE
if (i < 4) {gl.glRotatef(i * 90.0f, 0.0f, 1.0f, 0.0f);}
if (i == 4) {gl.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);}
if (i == 5) {gl.glRotatef(90.0f,-1.0f, 0.0f, 0.0f);}
gl.glTranslatef(0.0f, 0.0f, 1.5f);
gl.glBegin(GL.GL_LINES); {
gl.glVertex3f( 0.0f, 0.0f, 0.0f);
gl.glVertex3f( 0.0f, 0.0f,-1.5f);}
gl.glEnd();
glut.glutWireCone(0.05f, 0.25f, 10, 5);
gl.glRasterPos3f(-0.1f, 0.1f, 0.4f);
switch (i) {
case 0: drawText("Z"); break;
case 1: drawText("X"); break;
case 2: drawText("-Z"); break;
case 3: drawText("-X"); break;
case 4: drawText("-Y"); break;
case 5: drawText("Y"); break;
}
gl.glPopMatrix();
}
}
private void drawText (String text){
GLUT glut = new GLUT();
for (int i = 0; i < text.length(); i++)
{ glut.glutBitmapCharacter(GLUT.BITMAP_9_BY_15, text.charAt(i));}}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
}
public void keyTyped(KeyEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void keyPressed(KeyEvent e) {
System.out.println("38");
}
public void keyReleased(KeyEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void mouseClicked(MouseEvent e) {
int i = e.getX();
System.out.println(i);
}
public void mousePressed(MouseEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void mouseReleased(MouseEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void mouseEntered(MouseEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void mouseExited(MouseEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
//public class MyGLEventListener Implements GLEventListener, KeyListener {
//
//
//}
}