/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package joglrandom;

import com.jogamp.newt.event.WindowEvent;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.nio.ByteBuffer;
import javax.media.opengl.GL2;
import javax.media.opengl.GL3;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;

/**
 *
 * @author Luz
 */
public class Bugtest implements GLEventListener
{




    static public void main(String[] args)
    {
        GLProfile glp = GLProfile.get(GLProfile.GL3);


        GLCapabilities caps = new GLCapabilities(glp);
        GLCanvas canvas = new GLCanvas(caps);

        Frame frame = new Frame("AWT Window Test");
        frame.setSize(800, 600);
        frame.add(canvas);
        frame.setVisible(true);

        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        canvas.addGLEventListener(new Bugtest());

    }

    public void init(GLAutoDrawable glad)
    {
        GL3 gl = glad.getGL().getGL3();

        ByteBuffer verticiesBB = ByteBuffer.allocate(4*9);
        int[] vertexBuffer = new int[1];
        
        verticiesBB.putFloat(0);
        verticiesBB.putFloat(0.5f);
        verticiesBB.putFloat(0);

        verticiesBB.putFloat(0.5f);
        verticiesBB.putFloat(-0.5f);
        verticiesBB.putFloat(0);

        verticiesBB.putFloat(-0.5f);
        verticiesBB.putFloat(-0.5f);
        verticiesBB.putFloat(0);
        verticiesBB.rewind();
        for(int i=0; i < verticiesBB.capacity(); i+=4)
            System.out.println(verticiesBB.getFloat(i));
        gl.glGenBuffers(1, vertexBuffer, 0);

        gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vertexBuffer[0]);

        gl.glBufferData(GL3.GL_ARRAY_BUFFER, verticiesBB.capacity(), verticiesBB, GL3.GL_STATIC_DRAW);
        
        ByteBuffer bb = gl.glMapBuffer(GL3.GL_ARRAY_BUFFER, GL3.GL_READ_WRITE);
        for(int i=0; i < bb.capacity(); i+=4)
            System.err.println(bb.getFloat(i));
    }

    public void display(GLAutoDrawable glad) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void dispose(GLAutoDrawable glad) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void reshape(GLAutoDrawable glad, int i, int i1, int i2, int i3) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    


}
