Render BGL overlay into images

I would like to render my overlay opengl (bgl and blf) to images. I know that’s possible because Measure-it addon is able to do it but I have some difficulties to understand the script of the addon.

Does someone can point me the way to get the opengl overlay to pixels? what part of the API should I use?

Thanks :slight_smile:

I have an example script for just that on the team project’s page under “MassiveOnline LOD and scenary preprocessing”.

Do you want to use opengl to draw over an image? or into the viewport?

hi, afaik, measureit is the only addon that does this.
What the op wants is to render his image & have his bgl drawn on top automatically in the render.

The script from this post may be what OP wants…

For the new blender versions, we must change the line:

tex = img.bindcode

to:

tex = img.bindcode[0]

edit: the 8th line should be also changed (the path), for non Windows OS

Both. Drawing on top of the viewport is quite easy but to render it over an image, I could render a “screenshot” of the viewport and crop the area I want to keep but the problem is that I need to render it over an image that has a higher resolution than my viewport/screen.
That’s probably why the measure-it addon is using tiles to get rid of this problem but it seems quite complex to me.

As a workaround for the moment, to save the opengl overlay on a rendered image, I send all the drawing information (lines and text) to ImageMagick with subprocess (or PILLOW, which is also working) and draw the overlay from there. I feel like I’m doing twice the script but at least it’s working well. Tell me if you have better idea.

This might be possible with a combination of offscreen rendering and glReadPixels, as shown in this example.