import javax.swing.*;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;



public class HelloJOGL extends JFrame{

	GLCanvas canvas;
	SceneView sv;

	public HelloJOGL() {

		sv = new SceneView(); //GLEventListener-Objekt

		GLProfile glp = GLProfile.getDefault();
		GLCapabilities caps = new GLCapabilities(glp);
		canvas = new GLCanvas(caps);

		canvas.addGLEventListener(sv);

		add(canvas);

		setTitle("Jogl Blatt 2");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(500,500);
		setVisible(true);  

	}



	class SceneView implements GLEventListener {


		public void init(GLAutoDrawable drawable) {
			GL2 gl = drawable.getGL().getGL2(); 
			gl.glClearColor(0.5f, 0.5f, 0.5f, 0f); // grey background	
		}

		public void display(GLAutoDrawable drawable) {
			GL2 gl = drawable.getGL().getGL2();         
			gl.glClear(GL2.GL_COLOR_BUFFER_BIT); // clear background


			gl.glBegin(GL2.GL_LINES); // draw x, y and z axis
			gl.glColor3d(1, 0, 0);	//red
			gl.glVertex3i(0, 0, 0);
			gl.glVertex3i(1, 0, 0);

			gl.glColor3d(1, 1, 0); //yellow
			gl.glVertex3i(0, 0, 0);
			gl.glVertex3i(0, 1, 0);

			gl.glColor3d(0, 1, 0); //green
			gl.glVertex3i(0, 0, 0);
			gl.glVertex3i(0, 0, 1);
			gl.glEnd();


		}

		public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
			GL2 gl = drawable.getGL().getGL2();
			gl.glViewport(Math.max(0,(w-h)/2), Math.max(0,(h-w)/2), Math.min(w,h), Math.min(w,h)); //reset the current viewport		
		}

		public void dispose(GLAutoDrawable drawable) {
		}


	}

	public static void main(String args[]) {
		new HelloJOGL();   
	}




}
