Page MenuHome

Does bgl limit area or region for readPixel
Closed, InvalidPublic

Description

System Information
Operating system: Windows 10 Home 19041
Graphics card: Geforce GTX 1060

Blender Version
Broken: 2.91.2
Worked: 2.83

Instead of glReadPixels reading from entire screen as seen in 2.8x, it seems like it's more limited in 2.9. Is there a reason for this, and how to map entire window for reading to a buffer?

Exact steps for others to reproduce the error
Here's a test script. Run it and open resulting image - it usually only shows the header of one of the panels and nothing else.

import bpy
import bgl
import numpy as np

myWidth = 500
myHeight = 500

screen_buffer = bgl.Buffer(bgl.GL_FLOAT, [myWidth, myHeight,4])
bgl.glReadPixels(0, 0,myWidth,myHeight,bgl.GL_RGBA,bgl.GL_FLOAT,screen_buffer)
channels = np.array(screen_buffer).reshape(myWidth * myHeight * 4)
channels[3::4] = 1.0

newImage = bpy.data.images.new(name = 'newImage',width=myWidth,height=myHeight,alpha=True, float_buffer=True)
newImage.pixels = channels
newImage.pack()

Event Timeline

It is not convenient to call the drawing API outside a callback that does not have a defined context.
glReadPixels works on a FrameBuffer, so you need to specify the framebuffer (I suppose you want to use BackBuffer then you would need bgl.glBindFramebuffer(bgl.GL_READ_FRAMEBUFFER, 0))

Other states that may be interesting to define:

  • glReadBuffer
  • glViewport
  • GL_SCISSOR_TEST

So this is not really a bug.
There are plans to deprecate the bgl module and implement an improved gpu module.

So this is not really a bug.

Good to know, thank you for clarifying and giving me feedback.

There are plans to deprecate the bgl module and implement an improved gpu module.

I hope so, the gpu module is easier to work with imo