Hi everyone, I've been developing a 3D creator but I'm still stuck in the first stages since I haven't been able to draw with VBO.

This is a piece of my glwidget.cpp code, where all the objects are drawn
Qt Code:
  1. void GLWidget::initializeGL()
  2. {
  3. #define PROGRAM_VERTEX_ATTRIBUTE 0
  4. #define PROGRAM_NORMALS_ATTRIBUTE 1
  5.  
  6. //glEnable(GL_DEPTH_TEST);
  7. //glEnable(GL_CULL_FACE);
  8.  
  9.  
  10. vShader= new QGLShader (QGLShader::Vertex, this);
  11. vShader->compileSourceFile("../src/shaders/editorVshader.glsl");
  12.  
  13. fShader= new QGLShader (QGLShader::Fragment, this);
  14. fShader->compileSourceFile("../src/shaders/editorFshader.glsl");
  15.  
  16. editor= new QGLShaderProgram (this);
  17. editor->addShader(vShader);
  18. editor->addShader(fShader);
  19. editor->bindAttributeLocation("vertices", PROGRAM_VERTEX_ATTRIBUTE);
  20. editor->bindAttributeLocation("normals", PROGRAM_NORMALS_ATTRIBUTE);
  21. editor->link();
  22. editor->bind();
  23. }
  24.  
  25. void GLWidget::paintGL()
  26. {
  27. glClearColor(0.4765625, 0.54296875, 0.6171875, 1.0);
  28. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  29. /*
  30.   glLoadIdentity();
  31.   glTranslatef(0.0f, 0.0f, -10.0f);
  32. */
  33.  
  34. editor->setUniformValue("projectMatrix", controller->getProjectionMatrix());
  35. editor->setUniformValue("viewMatrix", controller->getViewMatrix());
  36.  
  37.  
  38. /** Ahora para las operaciones especificas de cada objeto **/
  39.  
  40. for (int i=0; i<Objects.size(); i++)
  41. {
  42. Objects[i].modelmatrix.scale(1.0, 1.0, 1.0);
  43. Objects[i].modelmatrix.rotate(1.0, 0.0, 0.0, 1.0);
  44. editor->setUniformValue("modelMatrix", Objects.at(i).modelmatrix);
  45.  
  46. glEnableClientState(GL_VERTEX_ARRAY);
  47. Objects[i].vertexbuffer->bind();
  48. glVertexPointer(3, GL_FLOAT, 0, Objects.at(i).indexed_vertices.data());
  49. editor->enableAttributeArray("vertices");
  50. editor->setAttributeBuffer("vertices", GL_FLOAT, 0, Objects[i].indexed_vertices.size() * sizeof(vertex)); // (PROGRAM_VERTEX_ATTRIBUTE, Objects[i].vertices.data());
  51. /*
  52.   Objects[i].normalbuffer.bind();
  53.   //glVertexPointer(3, GL_FLOAT, 3, Objects.at(i).indexed_normals.data());
  54.   glEnableClientState(GL_NORMAL_ARRAY);
  55.   editor->enableAttributeArray(PROGRAM_NORMALS_ATTRIBUTE);
  56.   editor->setAttributeBuffer (PROGRAM_NORMALS_ATTRIBUTE, GL_FLOAT, 0, Objects[i].indexed_normals.size() * sizeof(vertex));*/
  57.  
  58. //glDrawArrays(GL_QUADS, 0, Objects[i].vertices.size());
  59. Objects[i].elementbuffer->bind();
  60. glDrawElements(GL_QUADS, Objects[i].indices.size(), GL_UNSIGNED_SHORT, (void*)0);
  61. }
  62. }
To copy to clipboard, switch view to plain text mode 

It explodes when it tries to execute the glDrawElements instruction. I've been tracking down the problem but I can't find what's wrong. I'm even doubting about the right way to use QGLBuffer in Qt. Can anyone help me?