VBOs and elements issue

Hey all,

I'm trying to optimize my program to a relatively modern openGL standard. In that interest, I'm trying to write a class for 3D objects with a model and texture loading function (with SOIL) as well as a display function for the VBOs generated in the loader functions. However, nothing ever shows up on the screen. I think I might be mixing something up with the element array.

I don't see where my error is, however I'm pretty certain, as I wrote, that something is not quite right about the handling of the elements. I haev a whole bunch of glGetError() calls in between (deleted those here for readability), they return no errors. If any of you pros around here might give the code a quick look, it'd be appreciated.

Do I really need a VAO? I never used them before, and many of the tutorials I've seen online don't mention them.

edit: I don't think I do, do I? I've gotten my code to the point now where the models show on screen, just the faces don't seem to be quite right.
On the left is the model in Blender (I used a snake texture because it has more irregularities than human skin) and on the right is the output in the program.
As for the red box, it's the same problem - there seems to be a corner missing.

edit2:
For sake of completion, here is my current code for getting the vertices and elements (I'm omitting the code for normals and UVs here to keep it short, but it's basically the same) and drawing them:

You do need a valid non-zero VAO to be bound as the specs of core OpenGL says. In a compatibility mode - not sure. But better to do so.
I believe your problem actually comes from reading the obj file. Inspect it in text editor. Obj may have different number of normals, texcoords and vertices. Normally, you have to load all three into separate arrays, then using the faces' indices unpack and group all three attributes into a single interleaved array (VBO) tesselating polygons into triangles, then gen and bind VAO, map the VBO using glVertexAttribPointer & glEnableVertexAttribArray, and then draw arrays using GL_TRIANGLES. When you feel a superman enough, think about packing the triangles into something more optimal and use indexed drawing.
Good luck!

It's worth noting that glEnableVertexAttribArray, glBindBuffer, glVertexAttribPointer and friends existed in OpenGL before VAOs did (in versions 1.5 and 2.0, to be precise). You can also check the GL_VERSION that an extension is written against, and that it requires: if either predates VAOs then you can safely use it in compatibility or downlevel contexts without VAOs too.

For example: GL_ARB_direct_state_access is specified as requiring GL 2.0, so you can code to GL 2.0 but use that extension if available and without VAOs for it's buffer object and vertex specification calls.

I'm having a problem understanding why the error might be in the obj file. I just exported it from Blender, when I re-import it it looks just fine.
The file does have a different number of data sets for vertices, tex coords and normals, however that's why I'm sorting them in my function. After I do that, the std::vectors storing the data are the same length (though the uv vector is only 2/3 of the other's length).
From what I understand, I don't explicitly have to put all the vertex, uv and normal data into one big VBO, I can just as well keep them in different ones and send them to the vertex shader by themselves.
However, I tried doing so, but the code crashes more specifically, the for loop crashes and I got no idea why.

how you ca see by the comment i put in your code you are picking the same vertices again and again, i leave you the easy fun part: find how to solve it (really, is not that complicated)

also i think that your program crashes at for loop because probably your final_uvs, final_normals and final_vertex have not the same size so, since you are looping until "i" < final_vertices.size() -2 (why final_vertices.size() -2?) after some loops "i" becomes bigger than the size of one or more of your vectors and more precisely of your final_uvs and/or final_normals, sorry but you have to find another way. good job

In obj files numeration starts at 1, not 0.
And here:
glVertexAttribPointer(shaderAttributes[0], 3, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), 0);
glVertexAttribPointer(shaderAttributes[1], 2, GL_FLOAT, GL_FALSE, 6*sizeof(GLfloat), (GLvoid*)12);
glVertexAttribPointer(shaderAttributes[2], 3, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), (GLvoid*)20);
You specify different stride for each attrib pointer, that is wrong. Aside from that, the VBO must be bound BEFORE the glVertexAttribPointer called, because the mapping is performed for the buffer currently bound.
Simply saying, your code is just full of bugs. How can we help you?
By giving an advice to put more attention to what you are writing? Or read the docs for the functions you are using?