Hey sorry, I was away for the weekend. First off you don’t need to enable the clientstate for immediate mode, in fact you should avoid it.
OK, so let me preface this with I’m not an expert and I will try to push you in the right direction, but some of the info follow won’t be 100% true, I’ll specify where I’m not sure. Also, take a look at cplusplusguy on youtube, not really easy to follow and he does some bad stuff (code smells), but good info overall.
Anyway, the code I posted is for VBOs (vertex buffer object). Anytime you’re calling drawArray() you’re working with a VAO (vertex array object) drawElements() is a VBO, which can contain multiple VAOs (something I’m fuzzy on so that may not be right, but I’m sticking with it until told otherwise) - http://stackoverflow.com/questions/11821336/what-are-vertex-array-objects.
Regardless the process is the same, just the calls are different. FYI the gl.gl* is because I use JOGL
//m_vbo_handle is the "index"/start position of the buffer we want to draw (positional and color data are stored in here)
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, m_vbo_handle[0]);
//vert_pos is an index in GLSL referencing the bind position of this array (basically where
//the positional data is in the shader)
gl.glEnableVertexAttribArray(vert_pos);
//same as vert_pos but for color data
gl.glEnableVertexAttribArray(color);
//similar to calling glEnableClientState(GL_VERTEX_ARRAY)
//glVertexAttribPointer(bind_position, number of values, type of values, ... , size in bytes, position of first element in array
gl.glVertexAttribPointer(vert_pos, 3, GL.GL_FLOAT, false, Buffers.SIZEOF_FLOAT * Vertex.SIZE, 0);//start
//similar to calling glEnableClientState(GL_COLOR_ARRAY)
//glVertexAttribPointer(bind_position, number of values, type of values, ... , size in bytes, position of first element in array
gl.glVertexAttribPointer(color, 3, GL.GL_FLOAT, false, Buffers.SIZEOF_FLOAT * Vertex.SIZE, Buffers.SIZEOF_FLOAT * 3);//12
//m_ind_handle is the "index"/start position of the buffer we use to reference the correct order in which to draw the above buffer
gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, m_ind_handle[0]);
gl.glDrawElements(GL.GL_TRIANGLES, m_index_array.length, GL.GL_UNSIGNED_INT, 0);
//Unbind the buffers so we don't render this again anywhere else
gl.glDisableVertexAttribArray(vert_pos);
gl.glDisableVertexAttribArray(color);
So a similar process for VAOs would be:
drawVAO()
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
//Think of it as equivalent to glEnableVertexAttribArray(vert_pos), but remember it's not
glBindBuffer(GL_ARRAY_BUFFER, pos_handle);
//Similar to glVertexAttribPointer() for the positional data in the above example
glVertexPointer(3, GL_FLOAT, /* stride */3 << 2, 0L);
//Think of it as equivalent to glEnableVertexAttribArray(color), but remember it's not
glBindBuffer(GL_ARRAY_BUFFER, color_handle);
//Similar to glVertexAttribPointer() for the positional data in the above example
glColorPointer(3, GL_FLOAT, /* stride */3 << 2, 0L);
// Draw
glDrawArrays(GL_TRIANGLES, 0, 3 /* elements */);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
Now, in your code you’re deleting the buffers after the draw calls
glDeleteBuffers();
You don’t want to be doing this every frame, or before you’re done drawing that object forever(basically), as it opens that bind position to overrides. Meaning another buffer can be stored in that location like a quad or something. Instead you should just be unbinding the data:
glBindBuffer(GL_ARRAY_BUFFER, 0);
and disable the bind target in the appropriate manner either by disableClientState() or disableVertexAttribPointer().
I fell like it’s a good time to say that vertices are not only positions, they contain can colors, normals, texture coordinates, alpha values, and various other bits of data. So try to keep that in mind.
So in review:
public static void drawThem(){
// Initialize States
glEnableClientState(GL_VERTEX_ARRAY); //<-- Remove
glEnableClientState(GL_COLOR_ARRAY); //<-- Remove
drawImmediateMode();
glTranslatef(0.05f, -0.05f, 0);
drawVertexArrays(); //Add enable/disable in this function
glTranslatef(0.05f, -0.05f, 0);
drawVBO(); //Add enable/disable in this function
glTranslatef(0.05f, -0.05f, 0);
drawVBOIndexed(); //Add enable/disable in this function
glTranslatef(0.05f, -0.05f, 0);
drawVBOInterleaved1(); //Add enable/disable in this function
glTranslatef(0.05f, -0.05f, 0);
drawVBOInterleaved2(); //Add enable/disable in this function
glTranslatef(0.05f, -0.05f, 0);
drawVBOInterleaved3Mapped(); //Add enable/disable in this function
// Clean up States
glDisableClientState(GL_COLOR_ARRAY); //<-- Remove
glDisableClientState(GL_VERTEX_ARRAY); //<-- Remove
}
and don’t forget to remove deleteBuffers from the draw code! Should have a cleanup function when closing the program instead.