I was just wondering whether there is a way to apply bullet physics to opengl drawn objects (created using glVertex3f or triangle mesh with glVertexAttribPointer). I am curr
Bullet Example Browser
The in-tree example browser has some OpenGL-physics bindings so you can easily visualize simulations.
To see it working, you can compile and run it with:
sudo apt build-dep libbullet-dev
git clone https://github.com/bulletphysics/bullet3
cd bullet3
git checkout 2.89
./build_cmake_pybullet_double.sh
./build_cmake/examples/ExampleBrowser/App_ExampleBrowser
Screenshot:
Tested on Ubuntu 20.04.
Example browser 2.83 code analysis
The Bullet example browser has moved away from the examples/ExampleBrowser/GL_ShapeDrawer.cpp by default, which uses outdated immediate OpenGL 2 methods. It can still be turned on depending on the value of the NO_OPENGL3 macro and command line arguments.
OpenGLWindow/GLInstancingRenderer.cpp is the new OpenGL 3 rendering centerpiece, and contains the glBindVertexArray call in GLInstancingRenderer::registerShape.
This method is indirectly called from OpenGLGuiHelper::autogenerateGraphicsObjects, which loops over the objects in the btDiscreteDynamicsWorld and generates a graphic version of those shapes.
The central part of the conversion seems to be OpenGLGuiHelper::createCollisionShapeGraphicsObjectInternal.
The color of the objects simply loops over 4 possible colors from OpenGLGuiHelper::sColors.
autogenerateGraphicsObjects is called from the initPhysics of several examples.
There are also some explicitly encoded cubes and spheres at: SimpleOpenGL3App.cpp, which can serve as a starting point if you want the possibility of graphics that differ from physics, as should be the case for every serious project: graphics should be more detailed, as they are less computationally expensive. Those are used only in a few examples.
If you are going to study the example browser, I recommend using an IDE with a debugger: it is too much indirection from my brain's static analysis. I've done this analysis with KDevelop4.