Hello I try to draw some text in the GPU offscreen.
Somehow the text is skewed and blf.aspect does not seem to have any effect.
Does anyone have an idea ?? Ideally i would like to draw text in normalized device coordinates.
There the text is way way tooo big.
MacOS High Sierra, NVIDIA driver GTX 750, Blender git,
GL Version shows 4.1 but glBegin is not supported ? Do i need to enable gl extensions on osx GL_HInt ?
Here is my script
import bpy
import gpu
import bgl
import blf
import random
from mathutils import Matrix
IMAGE_NAME = "Generated Image"
WIDTH = 500
HEIGHT = 500
offscreen = gpu.types.GPUOffScreen(WIDTH, HEIGHT)
with offscreen.bind():
bgl.glClearColor(0.2, 0.2, 0.2, 1.0)
bgl.glClear(bgl.GL_COLOR_BUFFER_BIT)
version = bgl.glGetString(bgl.GL_VERSION)
print(version)
with gpu.matrix.push_pop():
font_id = 0
blf.position(font_id, 0, 0, 0)
#blf.aspect(font_id, 0.9)
blf.size(font_id, 50, 72)
blf.color(font_id, 1.0, 1.0, 1.0, 1.0)
blf.draw(font_id, "Offscreen World")
buffer = bgl.Buffer(bgl.GL_BYTE, WIDTH * HEIGHT * 4)
bgl.glReadBuffer(bgl.GL_BACK)
bgl.glReadPixels(0, 0, WIDTH, HEIGHT, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, buffer)
offscreen.free()
if not IMAGE_NAME in bpy.data.images:
bpy.data.images.new(IMAGE_NAME, WIDTH, HEIGHT)
image = bpy.data.images[IMAGE_NAME]
image.scale(WIDTH, HEIGHT)
image.pixels = [v / 255 for v in buffer]