Rendering Multiple Vertex Buffer Objects

So can someone tell me why this works:

glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);

        for (int i = 0; i < text.size(); i++) {
            loader.getByFloat(i).bind();
            glBindBuffer(GL_ARRAY_BUFFER, text.get(i));
            glVertexPointer(3, GL_FLOAT, 0, 0);

            glBindBuffer(GL_ARRAY_BUFFER, texture);
            glTexCoordPointer(2, GL_FLOAT, 0, 0);

            glDrawArrays(GL_QUADS, 0, 24 * (chunkWidth * chunkHeight * chunkDepth));
        }

        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);

This works but is very very inefficient.

Any why this does not:

glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);

        for (int i = 0; i < text.size(); i++) {
            loader.getByFloat(i).bind();
            glBindBuffer(GL_ARRAY_BUFFER, text.get(i));
            glVertexPointer(3, GL_FLOAT, 0, 0);
        }

        glBindBuffer(GL_ARRAY_BUFFER, texture);
        glTexCoordPointer(2, GL_FLOAT, 0, 0);

        glDrawArrays(GL_QUADS, 0, 24 * (chunkWidth * chunkHeight * chunkDepth));

        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);

So I set up my program to run off of arrays, to allow easy modifying and texture changing, so I want the program to iterate through all of the VBO handles that I have, then bind the texture that matches it, then bind it, and repeat. When its done, it should draw the array. That is what my second code should do, but it doesnt show anything. Can anyone tell me why?

Because in your second one in the loop you repeatedly bind a new VBO but do nothing with it.

So is there any way to bind multiple arrays, then draw them all at one time?

Unless I’m mistaken, no. You render one thing after another, that’s how graphics programming has always worked.

Alright, maybe ill look into adding texture data into the vbo so I only have to render one thing that has multiple textures.

Oh yeah, terrible idea to only bind one texture per face unless you specifically need to (Voxel based games). You should also look into spritesheets, that way you only have To bind a texture once, and then use texture regions.

I know how to use spritesheets with Java API, but not LWJGL, but I don’t bind per-face, I bind per-buffer, so I have a vbo handle for every cube with grass textures, another one for wood, another for stone, etc…

No no no. Sorry, that’s a terrible way of doing it. You at least need to only use on buffer object per chunk (If you don’t have a chunk system, then you need to have one). Do you know how texture coordinates work in OpenGL?

I have a chunk system, sorry for the mis understanding, I have 10x10 chunks and I use vbo’s for each chunk

Spritesheet: You place all your textures in one big texture, bind it and place the coords inside the big texture for each vertex in the tex_coord buffer.

This thread expands very fast.

Make them cubic chunks (x^3). OpenGL texture coordinates range from 1 - 0, as you should know. So, you need to figure out how much space a single texture takes within these constraints. Take the number of textures on one side of your spritesheet, and divide 1 by that number. You should come up with some small number. For example, 1 / 16 textures on one side = 0.0625. So, every texture (as long as its a square) will be 0.0625 “texels” per one side. So, if you have 16 textures on one side of a spritesheet, and you’re looking for the second texture on the top row, it goes like this:
X = 0.0625f
Y = 0.0f

Just bind the spritesheet for all the tiles and pass in the correct texture coordinates per tile.

Off Topic: Didn’t you release a tool to get the texture coordinates off a sprite sheet?

Uhm, the texture coordinates are just [icode]((float)x / width, (float)y / height)[/icode]. Why would you need a tool for calculating that?

Yes, I did but I never really finished it. Currently it only supports very specific tile sizes. I still use it though because I use that tile size, and its nice for some quick calculations.