I'm trying to convert a bgl.Buffer object in blender python to bytes which can be written to a file, so far I'm not sure how to do it at all? Getting error: "TypeError: a bytes-like object is required, not 'bgl.Buffer'" with code:

    draw_texture_2d(offscreen.color_texture, (10, 10), WIDTH, HEIGHT)
    buffer = bgl.Buffer(bgl.GL_BYTE, WIDTH * HEIGHT * 4)
    bgl.glReadPixels(0, 0, WIDTH, HEIGHT, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, buffer)
    #g = 1
    p = "/tmp/" 
    #array = np.asarray(buffer, dtype=np.uint8)
  #  data = array.tobytes()
    #txt = data.decode(encoding='UTF-8')
    f = open(p + "file.txt", "wb")


as you can see in the comments I tried some other methods, which didn't work (as expected), so I'm wondering if there's some way to write this bgl.Buffer to a file / send it over a socket very quickly? I saw this question bgl.Buffer() to bytes but I wasn't exactly sure how to get it into simple writable bytes


Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.