I have this code (Doesn't work at all)
static void initGl() {
glViewport(0, 0, Display.getWidth(), Display.getHeight());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLU.gluPerspective(45.0f, Display.getWidth() / Display.getHeight(),
1.0f, 1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
public static void renderGL() {
glViewport(0, 0, Display.getWidth(), Display.getHeight());
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -60.0f);
drawCube();
}
public static void drawCube() {
for (int x = 0; x < 100; x++) {
for (int y = 0; y < 100; y++) {
for (int z = 0; z < 100; z++) {
glBegin(GL_QUADS);
glColor3f(1, 0, 0);
glVertex3f(-x, -y, z);
glVertex3f(x, -y, z);
glVertex3f(x, y, z);
glVertex3f(-x, y, z);
glColor3f(1, 0, 1);
glVertex3f(x, -y, -z);
glVertex3f(-x, -y, -z);
glVertex3f(-x, y, -z);
glVertex3f(x, y, -z);
glColor3f(1, 1, 1);
glVertex3f(-x, y, z);
glVertex3f(x, y, z);
glVertex3f(x, y, -z);
glVertex3f(-x, y, -z);
glColor3f(0, 0, 1);
glVertex3f(x, -y, z);
glVertex3f(-x, -y, z);
glVertex3f(-x, -y, -z);
glVertex3f(x, -y, -z);
glColor3f(1, 1, 0);
glVertex3f(x, -y, z);
glVertex3f(x, -y, -z);
glVertex3f(x, y, -z);
glVertex3f(x, y, z);
glColor3f(0, 2, 1);
glVertex3f(-x, -y, -z);
glVertex3f(-x, -y, z);
glVertex3f(-x, y, z);
glVertex3f(-x, y, -z);
glEnd();
}
}
}
All it does it freeze up the program and eventually it will render the red side of the cube. This obviously has to do with gltranslatef, but I don't know why that isn't working. My question is, how do I render multiple cubes at once? Are there any tutorials out there on voxel engines? Sorry for the horrible code, I realize I probably need a array to do this. I'm quite new at opengl.