Sometimes, opengl codes do not run in virtual box due to different opengl implementation. for example in my system we can find out the opengl version by running the following command
glxinfo | grep version
which gives
server glx version string: 1.4
client glx version string: 1.4
GLX version: 1.4
Max core profile version: 0.0
Max compat profile version: 2.1
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 2.0
OpenGL version string: 2.1 Mesa 21.0.3
OpenGL shading language version string: 1.20
OpenGL ES profile version string: OpenGL ES 2.0 Mesa 21.0.3
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 1.0.16
So the supported opengl version is only 2.1, but usually to use opengl core profile we need to use version >=3.3. So mesa recommends using the following line instead while executing an opengl program.
https://superuser.com/questions/1522545/run-application-requiring-opengl-3-3-inside-virtualbox-virtual-machine-windows
LIBGL_ALWAYS_SOFTWARE=true GALLIUM_DRIVER=llvmpipe ./app_name
You could also use the following trick reported to work with WSL2.
https://stackoverflow.com/questions/52592309/0110-error-glsl-3-30-is-not-supported-ubuntu-18-04-c
export MESA_GL_VERSION_OVERRIDE=3.3
./app_name
Try the process with the following code https://github.com/medhakant/BoucingBallAnimation
remember to change the opengl version from 4.5 to 3.3 in the c++ code