VBO help

Hi!

Here is my Vertex Buffer Object test code:


import com.sun.opengl.util.Animator;
import com.sun.opengl.util.BufferUtil;
import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import java.nio.IntBuffer;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
import javax.swing.JFrame;

public class VBO extends JFrame implements GLEventListener, KeyListener {
    private GL gl;
    private GLU glu;
    private GLCanvas canvas;
    private Animator anim;
	private GLCapabilities caps;
	private static final int SW = 1024;
	private static final int SH = 768;
	private boolean VBOsupported = false;
	// VBO
	private int vertexCount;    // Vertex Count
	private IntBuffer vertices;    // Vertex Data
	// Vertex Buffer Object Names
	private int[] VBOVertices = new int[1];  // Vertex VBO Name
    
    public VBO() {
		setUndecorated( true );
		caps = new GLCapabilities();
		canvas = new GLCanvas( caps );
        canvas.addGLEventListener(this);
		canvas.addKeyListener( this );
        getContentPane().add(canvas, BorderLayout.CENTER);
        setSize( SW, SH );
        setTitle("AStar");
        setVisible(true);
        anim = new Animator(canvas);            // calls display() periodically
        anim.start();
    }
    
    public static void main(String[] args) {
        new VBO();
    }

    public void init(GLAutoDrawable arg0) {
        gl = arg0.getGL();
		glu = new GLU();
        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		gl.glColor4f( 1f, 1f, 1f, 1f );
		glu.gluOrtho2D( 0.0, SW, 0.0, SH );
		gl.glDisable( GL.GL_TEXTURE_2D );
		gl.glLineWidth( 1.0f );
		gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL );
		gl.glShadeModel( GL.GL_SMOOTH );
		gl.glHint( GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST );
		
		// Check For VBO support
        VBOsupported = gl.isFunctionAvailable("glGenBuffersARB") &&
                gl.isFunctionAvailable("glBindBufferARB") &&
                gl.isFunctionAvailable("glBufferDataARB") &&
                gl.isFunctionAvailable("glDeleteBuffersARB");
		
		if ( VBOsupported ){
			debug( "VBO SUPPORTED!" );
		} else {
			debug( "VBO NOT SUPPORTED!" );
			System.exit( 0 );
		}
		
		vertexCount = 4;
		vertices = BufferUtil.newIntBuffer( vertexCount * 2 );
		vertices.put( SW/2 );
		vertices.put( SH/2 );
		
		vertices.put( SW/2 );
		vertices.put( SH/2+20 );
		
		vertices.put( SW/2+20 );
		vertices.put( SH/2+20 );
		
		vertices.put( SW/2+20 );
		vertices.put( SH/2 );
		
		// Generate And Bind The Vertex Buffer
		gl.glGenBuffersARB( 1, VBOVertices, 0 );  // Get A Valid Name
		gl.glBindBufferARB( GL.GL_ARRAY_BUFFER_ARB, VBOVertices[0] );  // Bind The Buffer
		// Load The Data
		gl.glBufferDataARB( GL.GL_ARRAY_BUFFER_ARB, vertexCount * 2 * 
				BufferUtil.SIZEOF_INT, vertices, GL.GL_STATIC_DRAW_ARB );

		// Our Copy Of The Data Is No Longer Necessary, It Is Safe In The Graphics Card
		vertices = null;
    }
	
	private void debug( String str ){
		System.out.println( "DEBUG: " + str );
	}
	
    public void display(GLAutoDrawable arg0) {
        final GL gl = arg0.getGL();
        gl.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
		//VBO
		gl.glLoadIdentity();
		// Enable Pointers
		gl.glEnableClientState( GL.GL_VERTEX_ARRAY );  // Enable Vertex Arrays
		gl.glBindBufferARB( GL.GL_ARRAY_BUFFER_ARB, VBOVertices[0] );
		// Set The Vertex Pointer To The Vertex Buffer
		gl.glVertexPointer( 2, GL.GL_INT, 0, 0 );
		gl.glDrawArrays( GL.GL_QUADS, 0, vertexCount );  
		gl.glDisableClientState( GL.GL_VERTEX_ARRAY );
    }

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

    public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {}

	public void keyTyped( KeyEvent e ){
	}

	public void keyPressed( KeyEvent e ){
		if ( e.getKeyCode() == KeyEvent.VK_ESCAPE ){
			System.exit( 0 );
		}
	}

	public void keyReleased( KeyEvent e ){
	}
}

There’s nothing on the screen. What did I wrong?
Environment:
java 1.6.0_02
jogl 1.1.1 rc8
windows xp sp2 eng 32bit
ati x1600 xt

Thanks!
Bye,
thomas

YOu need to read up on the projection matrix and the modelview matrix.

I modified the reshape method:


public void reshape( GLAutoDrawable drawable, int x, int y, int width,  int height ){
    gl.glViewport( 0, 0, width, height );
    gl.glMatrixMode( GL.GL_PROJECTION );
    gl.glLoadIdentity();

    glu.gluPerspective( 45, ( float ) width / height, 1, 1000 );
    gl.glMatrixMode( GL.GL_MODELVIEW );
    gl.glLoadIdentity();
}

But it's not work.