Can't get indexed VBOs to work.

I’ve been fiddling with this for days and just can’t get my indexed VBO to work. The program should render a large matrix of blocks, like minecraft. The vertex buffer itself is created via an external class which I have already confirmed working. Why is this not rendering/how to fix?

Additional info:
Code is in Java, using LWJGL.

My GLULookAt is just a placeholder to move the camera between debugs. It doesn’t show anything no matter what I set it to (yes I understand how it works). I don’t have any culling enabled, and even with no camera shifts from the origin I see nothing.

I was rendering from a very poorly optimized function with this same VBO structure before, so the VBO data isn’t the issue. It is most likely that I didn’t set the indexes right to access the VBO vertexes and draw the quads. The VBO is structured like this: for each block, add 8 vertexes to the VBO, (bottom left front, bottom left back, bottom right back, bottom right front, top left front, top left back, top right back, top right front). Top is +y, front is +z, and right is +x. I THOUGHT I did the indexes right for that data.

public class Main {
	/** frames per second */
	int fps;
	/** last fps time */
	long lastFPS;

	static long seed = (100);
	static int chunklimit=1;
	static int chunkvertexvolume=(16*16*256*3*8);
	Random seedresult;
	public void start() {
		
		blockmemory bmem=new blockmemory(chunklimit, chunkvertexvolume/24);
		FloatBuffer color;
		IntBuffer indexes;
		try {
			Display.setDisplayMode(new DisplayMode(800,600));
			Display.create();
			seedresult= new Random(seed);
			bmem.regenerate(seedresult);
		} catch (LWJGLException e) {
		    e.printStackTrace();
		}
		// init OpenGL here
		int colorBufferID=createVBOID();
		int vbid = createVBOID();
		int Iid=createVBOID();
		GL11.glMatrixMode(GL11.GL_PROJECTION);
		GL11.glLoadIdentity();
		GLU.gluPerspective (50.00f, 800.00f/600.00f, 0.01f, 100.00f); 
		GL11.glMatrixMode(GL11.GL_MODELVIEW);
		GL11.glLoadIdentity();
		GLU.gluLookAt(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
		GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
		  GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
		  
		GL11.glClearColor(0.5f,0.5f,1.0f, 0.0f); 
		GL11.glClearDepth(1.0f); 
		GL11.glEnable(GL11.GL_DEPTH_TEST);
		GL11.glDepthFunc(GL11.GL_LEQUAL);
		bmem.updatebuffers();
		//
		color = BufferUtils.createFloatBuffer(3);
		color.put(0.2f);
		color.put(0.5f);
		color.put(0.3f);
		indexes=BufferUtils.createIntBuffer(24);
			int[] indexlist={
					0, 3, 7, 4,
					2, 1, 5, 6,
					1, 0, 4, 5,
					2, 3, 6, 7,
					0, 1, 2, 3,
					4, 7, 6, 5
			};
			indexes.put(indexlist);
		bufferElementData(Iid, indexes);
	    ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, colorBufferID);
	    ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, color, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);
			System.out.println("Buffering complete.");
		    lastFPS = Sys.getTime();
		while (!Display.isCloseRequested()) {
			Display.sync(60);		    
			GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
		    // render OpenGL here
			//v
			//v						  
			for(int i=0; i<bmem.vbuffers.length; i++){
				bufferData(vbid, bmem.vbuffers[i]);
				  ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vbid);
				GL11.glVertexPointer(3, GL11.GL_INT, 0, 0);
				  ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, colorBufferID);
				GL11.glColorPointer(3, GL11.GL_FLOAT, 0, 0);
				GL11.glDrawElements(GL11.GL_QUADS, 24, GL11.GL_UNSIGNED_INT, 0);
			}
			
			    if (Sys.getTime() - lastFPS > 1000) {
			        Display.setTitle("FPS: " + fps); 
			        fps = 0; //reset the FPS counter
			        lastFPS += 1000; //add one second
			    }
			    fps++;

		    Display.update();
			//finished rendering
		}
			
		Display.destroy();
	    }
public static void main(String[] argv) {
    Main datmain = new Main();
datmain.start();
}
public static int createVBOID() {
	  if (GLContext.getCapabilities().GL_ARB_vertex_buffer_object) {
	    IntBuffer buffer = BufferUtils.createIntBuffer(1);
	    ARBVertexBufferObject.glGenBuffersARB(buffer);
	    return buffer.get(0);
	  }
	  return 0;
	}
public static void bufferData(int id, IntBuffer buffer) {
	  if (GLContext.getCapabilities().GL_ARB_vertex_buffer_object) {
	    ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, id);
	    ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, buffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);
	  }
	}
public static void bufferElementData(int id, IntBuffer buffer) {
	  if (GLContext.getCapabilities().GL_ARB_vertex_buffer_object) {
	    ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, id);
	    ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, buffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);
	  }
	}

}

I see that you are using signed int for your element array. It can only be unsigned.

If it does not fix the issue, use glGetError() between every OpenGL call to figure out if there is any mis-used of OpenGL.

Unsigned numbers are not supported by java. I tried a web code bit to put unsigned integer values into the regular integer array, but that also didn’t fix it. I tried putting glGetError() between everything and also got no returns. I finally tried changing the index type on on my drawelements call to GL_INT, and no love.

Maybe someone could post a concise working lwjgl indexed VBO cube rendering function?

I’m at the level of frustration now that I am willing to take the performance hit of just not using indexes and adding redundant vertexes to my array. If someone could tell me how to recode this snippet for that (just in case) it would be massively appreciated. I’m not sure which function call to use if I change to redundant arrays, drawArrays gave me some trouble, as well as drawArray in a for loop. I have a custom rendering function I can use, but it’s extremely inefficient (renders from regular ram). In the future I will be using an interleaved array with vertexes and texture coordinates, so whatever is more portable to that will be best.

Have you looked at this (7th item if you google “java opengl vbo drawelements” )?

http://math.hws.edu/graphicsnotes/c3/s4.html

Thanks, that page is infinitely more helpful than the other stuff I’ve found. Gonna fiddle with it today.

It’s working! I ended up finding out my block data was WAY off, as well as most of my parameters. Thanks overlay, I wouldn’t have figured it out without that example.

SOLVED: My data was at the wrong points, and my indexes were not accurate (you need an index for every single vertex, not just a list of offsets. IE: 0, 1, 3, 4, 6 as a list of 24 is not enough, you need a VERY long list containing the location of each vertex within the vertex array IE: 23, 767, 12).