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);
}
}
}