import javax.swing.*;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;


public class Mesh extends JFrame{

	GLCanvas canvas;
	SceneView sv;

	public Mesh() {

		sv = new SceneView(); //GLEventListener-Objekt

		GLProfile glp = GLProfile.getDefault();
		GLCapabilities caps = new GLCapabilities(glp);
		canvas = new GLCanvas(caps);

		canvas.addGLEventListener(sv);

		add(canvas);

		setTitle("Mesh");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(1200,600);
		setVisible(true);  

	}



	class SceneView implements GLEventListener {

		double[][] terrain = new double[100][100];


		public void init(GLAutoDrawable drawable) {
			GL2 gl = drawable.getGL().getGL2(); 	
			gl.glClearColor(0f, 0f, 0f, 0f); // grey background		
			gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE );
		}

		public void display(GLAutoDrawable drawable) {
			GL2 gl = drawable.getGL().getGL2();     
			GLU glu = new GLU();
			gl.glClear(GL2.GL_COLOR_BUFFER_BIT); // clear background
			gl.glMatrixMode(GL2.GL_MODELVIEW);
			gl.glLoadIdentity();
			glu.gluLookAt(50, 20, 100, 30, 0, -20, 0, 1, 0);
			
			for(int i = 0; i<terrain.length-1;i++){	
				gl.glBegin(GL2.GL_TRIANGLE_STRIP);

				for(int j = 0; j<terrain[0].length-1;j++){

					gl.glVertex3d(i,0, j);

					gl.glVertex3d(i+1,0, j);

					gl.glVertex3d(i,0, j+1);

					gl.glVertex3d(i+1,0, j+1);			

				}

				gl.glEnd();
			}




		}

		public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
			GL2 gl = drawable.getGL().getGL2();
			GLU glu = new GLU();

			gl.glMatrixMode(GL2.GL_PROJECTION);
			gl.glLoadIdentity();
			glu.gluPerspective(45, w/h, 0.1, 100);
		}

		public void dispose(GLAutoDrawable drawable) {
		}



	}

	public static void main(String args[]) {
		new Mesh();   
	}




}


