The problem is that you're sending the cube data to the GPU each frame, which gets rather slow when you have a lot of cubes (or other objects). I'd suggest looking into vertex buffer objects (VBOs). These allow you to create a buffer on the GPU to store your cube data, and then you just draw the cubes each frame using the data that's in the buffer on the GPU.
So, instead of saying to the GPU:
"Draw a cube at position X" 500 times
You first upload the cube data:
"GPU, here's the data for all my cubes, store it in a VBO buffer in GPU memory for me."
And each frame:
"GPU, draw that data I sent you before."
You're just uploading the data once, and then drawing the data each frame from the buffer on the GPU rather than sending it across again and again to the GPU.
It's gets a little complicated if you want to start animating the cubes as the data in the buffer needs to be updated if you're going to move things around individually. I'm doing something similar in my intro. My solution was to store transformation data for the cubes in a texture coordinate VBO. For each cube vertex, I store a start and end position (and rotation) for the vertex and then draw everything using a custom shader. The shader looks up the associated texture coordinates (which I'm using to store position info) for each vertex and uses a time value fed into the shader to transition the vertex location between the start and end points stored in the texture coordinates. This allows me to animate lots of cubes without resending loads of data to the GPU each frame. From memory, I think I've got about 65,000 blocks or so flying about.
As well as drawing all the vertices in the vbo, you can just draw a section of the data (first 24 vertices, vertices 24 to 48 etc). This is what I was doing previously. I uploaded all my cube data into a VBO without transformations, and then drew the data in chunks of 24 vertices (1 cubes worth). In each iteration of the loop, I used glTranslate and glRotate to handle the position and rotation for the cube. This worked reasonably well, but is much, much slower than the method mentioned above. I think I was maxing out at around 5,000 cubes. It worked like this (excuse bad pseudo code):
for i = 0 to numCubes do
// translate/rotate according to cube position/angle
glTranslate (cube(i).translation)
glRotate(cube(i).rotation)
// draw 24 cube vertices at origin 0,0,0
DrawCube()
// undo translate/rotate ready for next cube draw
glRotate(-cube(i).rotation)
glTranslate (-cube(i).translation)
next i
That's probably not helped massively, but hopefully you get the gist a little. I had quite a job getting my VBO stuff working and understanding the concepts, so bear with it.
If you like, I'll package up my work-in-progress entry and send it to you. The code is quite messy, but may be of some use...
EDIT: Goddamn BBCode
