Pathetically Simple VBO Problem

Ok, please don’t bash me, and I feel really stupid for even having to ask for help right now, but this is my first attempt with Vertex Buffer Objects doing anything and I’m failing miserably. It doesn’t help matters I’m using an old Win98 computer right now which likes to crash every 3-10 minutes depending on it’s mood. I did check and it does say it supports VBOs however. Anyway, I’m using the methods listed on this http://lwjgl.org/wiki/doku.php/lwjgl/tutorials/opengl/basicvbo tutorial. All significant code is as follows:

Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
Display.create();			
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(-WIDTH/2, WIDTH/2, -HEIGHT/2, HEIGHT/2, -1, 1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);				
GL11.glLoadIdentity();			

int id = createVBOID();
ByteBuffer bytebuffer = ByteBuffer.allocateDirect(6 * 4);
bytebuffer.order(ByteOrder.nativeOrder());
FloatBuffer fbuffer = bytebuffer.asFloatBuffer();
fbuffer.put(-10f);
fbuffer.put(-10f);
fbuffer.put(10f);
fbuffer.put(-10f);
fbuffer.put(10f);
fbuffer.put(10f);

bufferData(id, fbuffer);
long start = System.nanoTime();
int frames = 10000;
for (int i = 0; i < frames; i++){
	GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

	GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
	ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, id);
	GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
	GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3);
//	GL11.glBegin(GL11.GL_TRIANGLES);
//	GL11.glVertex2f(-10, -10);
//	GL11.glVertex2f(10, -10);
//	GL11.glVertex2f(10, 10);
//	GL11.glEnd();
	Display.update();
}

The commented out code at the bottom draws a little white triangle in the center of the screen if I uncomment it. Code as is draws nothing, a blank black screen. I looked through several tutorials and thought I copied everything I needed, but evidently I didn’t. Could someone point out what I missed?

You use the ‘region’ of the FloatBuffer that is between the ‘position’ and the ‘limit’

After you ‘put’ all your values in the FloatBuffer, the ‘position’ is after the actual data.

So you want to set the position to 0, and the limit to where your data ends (the current position).

fb.limit(fb.position());
fb.position(0);

a convinience method for this is:
fb.flip();

Ah, yes, it works now, I have a white triangle!!! Thank you so much!

Unfortunately most of the tutorials I was looking at were written in C++ so I guess that function call wasn’t necessary. I’m surprised the LWJGL basic VBO tutorial doesn’t mention flip()ing or rewind()ing anywhere on the page. I had actually heard about rewinding somewhere and was attempting to use it, but I kept rewinding the byte buffer or the float buffer before adding the data, not after (I guess that didn’t make much sense now that I think about it but I didn’t really know what it was doing).

I wrote that tutorial with the assumption that you know how to use Vertex Arrays, and with VA’s, you need to flip()/rewind() to get them to work…I’ll add a little reminder near the bottom when I have a chance. Thanks for pointing that out tho.

DP :slight_smile: