Debug draw shows only a wireframe

Post Reply
stefanejro
Posts: 12
Joined: Sun May 20, 2018 6:57 pm

Debug draw shows only a wireframe

Post by stefanejro »

Hello boys, I have a question regarding debug draw in Bullet with OpenGL. I implemented my own debug draw class which extends btIDebugDraw, implements drawLine method, etc., basically everything as in documentation.

The problem is, that in debug mode, the only thing I see is the wireframe:
Screenshot 2018-05-27 00.24.00.png
Screenshot 2018-05-27 00.24.00.png (33.33 KiB) Viewed 3264 times
What I would like to see is: wireframe together with rendering of my scene and 3d models, like here:
http://www.opengl-tutorial.org/assets/i ... tDebug.png

My draw line code below:

Code: Select all

   virtual void drawLine(const btVector3& from, const btVector3& to, const btVector3& color)
    {
        // Vertex data
        GLfloat points[12];
        
        points[0] = from.x();
        points[1] = from.y();
        points[2] = from.z();
        points[3] = color.x();
        points[4] = color.y();
        points[5] = color.z();
        
        points[6] = to.x();
        points[7] = to.y();
        points[8] = to.z();
        points[9] = color.x();
        points[10] = color.y();
        points[11] = color.z();
        
        glGenBuffers(1, &vertexbuffer);
        glGenVertexArrays(1, &VertexArrayID);
        glBindVertexArray(VertexArrayID);
        glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
        glBufferData(GL_ARRAY_BUFFER, sizeof(points), &points, GL_STATIC_DRAW);
        glEnableVertexAttribArray(0);
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0);
        glEnableVertexAttribArray(1);
        glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
        glDrawArrays(GL_LINES, 0, 2);
        glBindVertexArray(0);   
    }
stefanejro
Posts: 12
Joined: Sun May 20, 2018 6:57 pm

Re: Debug draw shows only a wireframe

Post by stefanejro »

Ok, I fixed the problem, I have the both things rendering now:
Screenshot 2018-05-27 13.26.17.png
Screenshot 2018-05-27 13.26.17.png (62.07 KiB) Viewed 3245 times
Of course the problem had nothing to do with Bullet, just my poor OpenGL knowledge.

In the last line of my drawLine method implementation I had a call glBindVertexArray(0); which was breaking my vertex array binding. Removing this line solved the issue.

Code: Select all

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
glDrawArrays(GL_LINES, 0, 2);
// glBindVertexArray(0);   <------------------ THIS WAS CAUSING PROBLEMS
stefanejro
Posts: 12
Joined: Sun May 20, 2018 6:57 pm

Re: Debug draw shows only a wireframe

Post by stefanejro »

One more thing:
Calling glDrawArrays(GL_LINES, 0, 2); inside of drawLine is probably not the best idea as it will result in a massive fps drop even for simple geometry ( one draw call per one line... ). It's probably better to call it in flushLines or some other place.
Post Reply