Results 1 to 2 of 2

Thread: Vertex Buffer Object -> Segmentation Fault

  1. #1
    Join Date
    Mar 2013
    Location
    Venezuela
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Symbian S60

    Default Vertex Buffer Object -> Segmentation Fault

    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?

  2. #2
    Join Date
    Mar 2013
    Location
    Venezuela
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Vertex Buffer Object -> Segmentation Fault

    Hi, I solved it. The problem was the “tuplasize” that I was using with the setAttributeBuffer instruction.

    It was

    Qt Code:
    1. Objects[i].indexed_vertices.size() * sizeof(vertex)
    To copy to clipboard, switch view to plain text mode 

    Now I changed it to 3 and started passing normals as vertices too, the result code is:

    Qt Code:
    1. void GLWidget::paintGL()
    2. {
    3. glClearColor(0.4765625, 0.54296875, 0.6171875, 1.0);
    4. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    5. /*
    6.   glLoadIdentity();
    7.   glTranslatef(0.0f, 0.0f, -10.0f);
    8. */
    9.  
    10. editor->setUniformValue("projectMatrix", controller->getProjectionMatrix());
    11. editor->setUniformValue("viewMatrix", controller->getViewMatrix());
    12.  
    13.  
    14. /** Ahora para las operaciones especificas de cada objeto **/
    15.  
    16. for (int i=0; i<Objects.size(); i++)
    17. {
    18. Objects[i].modelmatrix.scale(1.0, 1.0, 1.0);
    19. Objects[i].modelmatrix.rotate(1.0, 0.0, 0.0, 1.0);
    20. editor->setUniformValue("modelMatrix", Objects.at(i).modelmatrix);
    21.  
    22. glEnableClientState(GL_VERTEX_ARRAY);
    23. editor->enableAttributeArray("vertices");
    24. Objects[i].vertexbuffer->bind();
    25. //glVertexPointer(3, GL_FLOAT, 0, Objects.at(i).indexed_vertices.data());
    26. editor->setAttributeBuffer("vertices", GL_FLOAT, 0, 3); // (PROGRAM_VERTEX_ATTRIBUTE, Objects[i].vertices.data());
    27. //glDisableClientState(GL_VERTEX_ARRAY);
    28.  
    29. //glEnableClientState(GL_NORMAL_ARRAY);
    30. editor->enableAttributeArray("normals");
    31. Objects[i].normalbuffer->bind();
    32. //glVertexPointer(3, GL_FLOAT, 3, Objects.at(i).indexed_normals.data());
    33. editor->setAttributeBuffer ("normals", GL_FLOAT, 0, 3);
    34. glDisableClientState(GL_VERTEX_ARRAY);
    35.  
    36. //glDrawArrays(GL_QUADS, 0, Objects[i].vertices.size());
    37. Objects[i].elementbuffer->bind();
    38. glDrawElements(GL_QUADS, Objects[i].indices.size(), GL_UNSIGNED_SHORT, (void*)0);
    39. }
    40. }
    To copy to clipboard, switch view to plain text mode 

    Consider this thread as solved

Similar Threads

  1. Creating an object of QGraphicsScene results in segmentation fault
    By TheIndependentAquarius in forum Newbie
    Replies: 4
    Last Post: 23rd January 2014, 08:20
  2. Replies: 2
    Last Post: 30th December 2010, 17:03
  3. QGLBuffer instead of Vertex Buffer Object -> How To?
    By FlashMuller in forum Qt Programming
    Replies: 0
    Last Post: 18th November 2010, 11:41
  4. Replies: 21
    Last Post: 28th September 2010, 10:59
  5. OpenGL Vertex Buffer Array/Object
    By Denarius in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2010, 08:59

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.