Drawing into the viewport with modern OpenGL

I’m fairly familiar with the old bgl drawing, however the new stuff is a little foreign to me. Can I use this to draw a custom object in the 3DView while not in the game engine? I would like to draw a cube with a custom volume texture. Basically, I think I can add a draw callback to the preview and later remove it. Is that possible with this or is there some part of the game engine that this depends on.

Can I use this to draw a custom object in the 3DView while not in the game engine?

No, this way of adding the drawing only works for the BGE and not for the Blender view port. Because the BGE is a own independent engine and has no influence to the Blender view port.

If you want to draw objects into the Blender view port, there are some BGL examples out there which are showing to do this.

Or if you want to render your own mini view port in the view port you can use the new gpu offscreen rendering module.
https://www.blender.org/api/blender_python_api_2_76_1/gpu.offscreen.html

BGL and PyOpenGL are similar. So you can do it with either one of them. I only used PyOpenGL because there are some commands (tesselation-, compute shader) and constants are missing in BGL and in some places it is easier then the BGL (eg. no bgl.Buffer() needed, adding shader is easier).

Thanks so much HG1. I am going to try and to the PyOpenGL route because bgl is missing a few things I need to render a volume texture.