import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.util.FPSAnimator;
import java.nio.FloatBuffer;
import javax.media.opengl.*;

public class Main {
    
    static private class EventListener implements GLEventListener {

        float[] vertices = {
            -1.0f, -1.0f, 0.0f,
            1.0f, -1.0f, 0.0f,
            0.0f,  1.0f, 0.0f,
        };
        
        int[] vertexBuffer = new int[1];
            
        @Override
        public void init(GLAutoDrawable drawable) {
            GL3bc gl = drawable.getGL().getGL3bc();
            gl.glGenBuffers(1, vertexBuffer, 0);
            gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vertexBuffer[0]);                           
            gl.glBufferData(GL.GL_ARRAY_BUFFER, vertices.length * 4, FloatBuffer.wrap(vertices), GL.GL_STATIC_DRAW);

            gl.glClearColor(0, 0, 1.0f, 1.0f);
            gl.glColor3f(1f, 0f, 0f);

        }

        @Override
        public void dispose(GLAutoDrawable drawable) {
            GL3bc gl = drawable.getGL().getGL3bc();
            gl.glDeleteBuffers(1, vertexBuffer, 0);
        }

        @Override
        public void display(GLAutoDrawable drawable) {
            GL3bc gl = drawable.getGL().getGL3bc();

            gl.glClear(GL3.GL_COLOR_BUFFER_BIT | GL3.GL_DEPTH_BUFFER_BIT);

            gl.glEnableVertexAttribArray(0);

            gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vertexBuffer[0]);
            gl.glVertexAttribPointer(
                    0, 
                    3, 
                    GL3.GL_FLOAT, 
                    false, 
                    0, 
                    0
            );
            gl.glDrawArrays(GL3.GL_TRIANGLE_STRIP, 0, 3);

            gl.glDisableVertexAttribArray(0);              

        }

        @Override
        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {

        }
        
    }
        
    public static void main(String[] args) {
        
        GLProfile profile = GLProfile.get(GLProfile.GL3bc);
        if(!GLProfile.isAvailable(GLProfile.GL3bc)) {
            System.out.println("No OpenGL 3bc");
            System.exit(1);
        }
        GLCapabilities caps = new GLCapabilities(profile);        
        GLWindow window = GLWindow.create(caps);
        
        window.setSize(800, 600);
        window.setVisible(true);
        window.setTitle("Newt Window");
                
        window.addWindowListener(new WindowAdapter() {
            @Override
            public void windowDestroyNotify(WindowEvent arg0) {
                System.exit(0);
            }
        });
        
        window.addGLEventListener(new EventListener());
        
        FPSAnimator animator = new FPSAnimator(60);
        animator.add(window);
        animator.start();

    }
    
}