Hi,
Ok, I’ve done the following to put a whole chunk into a display list:
// Create a chunk and store in display list
private void createChunkVoxel() {
chunkList = glGenLists(1); // this hard coded value will need changing as some point
glNewList(chunkList, GL_COMPILE);
createDisplayList();
glEndList();
}
private void createDisplayList() {
Chunk c = ChunkManager.getInsance().GetChunk(0);
for (int x = 0; x < c.CHUNK_SIZE; x++) {
for (int y = 0; y < c.CHUNK_SIZE; y++) {
for (int z = 0; z < c.CHUNK_SIZE; z++) {
GL11.glPushMatrix();
glTranslatef(x,y,z);
// Only create block if it is active
if(c.GetBlock(x,y,z).isActive())
renderCube();
GL11.glPopMatrix();
}
}
}
}
private void renderCube() {
//GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
glBegin(GL11.GL_QUADS);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(1.0f, 1.0f, 1.0f);
glColor3f(0.0f, 0.4f, 0.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glColor3f(0.0f, 0.8f, 0.0f);
glVertex3f(1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glColor3f(0.0f, 0.7f, 0.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, -1.0f);
glColor3f(0.0f, 0.6f, 0.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glColor3f(0.0f, 0.5f, 0.0f);
glVertex3f(1.0f, 1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glEnd();
}
And then in my update I just call:
glCallList(chunkList);
This does the whole chunk in one go, does this seem correct?
Before I was create a display list just for one cube, not a whole chunk, now just have one call to
draw a chunk, not 4096 (which is 4096 glTranslatef calls too!).
I guess I need to have an array of display lists for each chunk? How many display lists
can you have? PS - I’m doing it this way before eventually moving onto VBO’s, want to walk
before I can run, and hey, Notch used display lists
Thanks