I figured that OpenGL (I'm using OpenGL 4.0) supports Vertex Buffer Objects which is (correct me if I'm wrong) a dynamic way to draw vertexes, binding them similar to texture binding when you can free a dynamic array of pixels after binding it to a texture and you will still be able to draw it even if the pixel data in the array is lost. I tried to make a mini-minecraft game, but after drawing 256x256x60 world (256 width and height and 60 blocks depth) the game TOTALLY got stuck. I tried just drawing 256x256x6 but it still wasn't as fast as, for example, Minecraft runs. I drew the a block the following way:
void DrawBlock(double x, double y, double z, float xx, float yy, float zz)
{
// Render a color-cube consisting of 6 quads with different colors
xx = xx / 2;
yy = yy / 2;
zz = zz / 2;
x -= xx;
y -= yy;
z -= zz;
glBegin(GL_QUADS); // Begin drawing the color cube with 6 quads
// Top face (y = z + zz)
// Define vertices in counter-clockwise (CCW) order with normal pointing out
glColor3f(0.0f, 1.0f, 0.0f); // Green
glVertex3f(x + xx, y + yy, z - zz);
glVertex3f(x - xx, y + yy, z - zz);
glVertex3f(x - xx, y + yy, z + zz);
glVertex3f(x + xx, y + yy, z + zz);
// Bottom face (y = z - zz)
glColor3f(1.0f, 0.5f, 0.0f); // Orange
glVertex3f(x + xx, y - yy, z + zz);
glVertex3f(x - xx, y - yy, z + zz);
glVertex3f(x - xx, y - yy, z - zz);
glVertex3f(x + xx, y - yy, z - zz);
// Front face (z = z + zz)
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex3f(x + xx, y + yy, z + zz);
glVertex3f(x - xx, y + yy, z + zz);
glVertex3f(x - xx, y - yy, z + zz);
glVertex3f(x + xx, y - yy, z + zz);
// Back face (z = z - zz)
glColor3f(1.0f, 1.0f, 0.0f); // Yellow
glVertex3f(x + xx, y - yy, z - zz);
glVertex3f(x - xx, y - yy, z - zz);
glVertex3f(x - xx, y + yy, z - zz);
glVertex3f(x + xx, y + yy, z - zz);
// Left face (x = z - zz)
glColor3f(0.0f, 0.0f, 1.0f); // Blue
glVertex3f(x - xx, y + yy, z + zz);
glVertex3f(x - xx, y + yy, z - zz);
glVertex3f(x - xx, y - yy, z - zz);
glVertex3f(x - xx, y - yy, z + zz);
// Right face (x = z + zz)
glColor3f(1.0f, 0.0f, 1.0f); // Magenta
glVertex3f(x + xx, y + yy, z - zz);
glVertex3f(x + xx, y + yy, z + zz);
glVertex3f(x + xx, y - yy, z + zz);
glVertex3f(x + xx, y - yy, z - zz);
glEnd(); // End of drawing color-cube
}
when the x, y and z data is in an array of structures called "Block".
I still didn't do anything but the drawing, only because the drawing keeps getting stuck,
the display function always call the DrawBlock() 256x256x6 or 256x256x60 times in EVERY run of it.
How do I do it dynamically using VBO ?
I looked at the internet but some undefined functions appeared like glGenBuffersARB() and so.
Any example code for one simple cube ?