Esempio n. 1
0
def read_fbo_color_rgba32f(fbo):
    """
    Read the color attachment from a FBO, assuming it is GL_RGBA_32F
    """
    buffer = fbo.color_buffer
    h, w = buffer.shape[:2]
    x, y = 0, 0
    im = gl.glReadPixels(x, y, w, h, GL.GL_RGBA, GL.GL_FLOAT)
    im = np.frombuffer(im, np.float32)
    im.shape = h, w, 4
    im = im[::-1, :]
    return im
Esempio n. 2
0
def _screenshot(viewport=None):
    """ Take a screenshot using glReadPixels. Not sure where to put this 
    yet, so a private function for now. Used in make.py.
    """
    import numpy as np
    from vispy.gloo import gl
    #gl.glReadBuffer(gl.GL_BACK)  Not avaliable in ES 2.0
    if viewport is None:
        viewport = gl.glGetIntegerv(gl.GL_VIEWPORT)
    x, y, w, h = viewport
    gl.glPixelStorei(gl.GL_PACK_ALIGNMENT, 1)  # PACK, not UNPACK
    im = gl.glReadPixels(x, y, w, h, gl.GL_RGB, gl.GL_UNSIGNED_BYTE)
    gl.glPixelStorei(gl.GL_PACK_ALIGNMENT, 4)
    # reshape, flip, and return
    if not isinstance(im, np.ndarray):
        im = np.frombuffer(im, np.uint8)
    im.shape = h, w, 3
    im = np.flipud(im)
    return im
Esempio n. 3
0
def _screenshot(viewport=None):
    """ Take a screenshot using glReadPixels. Not sure where to put this 
    yet, so a private function for now. Used in make.py.
    """
    import numpy as np
    from vispy.gloo import gl
    #gl.glReadBuffer(gl.GL_BACK)  Not avaliable in ES 2.0
    if viewport is None:
        viewport = gl.glGetIntegerv(gl.GL_VIEWPORT)
    x,y,w,h = viewport
    gl.glPixelStorei(gl.GL_PACK_ALIGNMENT, 1)  # PACK, not UNPACK
    im = gl.glReadPixels(x, y, w, h, gl.GL_RGB, gl.GL_UNSIGNED_BYTE)
    gl.glPixelStorei(gl.GL_PACK_ALIGNMENT, 4)
    # reshape, flip, and return
    if not isinstance(im, np.ndarray):
        im = np.frombuffer(im, np.uint8)
    im.shape = h,w,3
    im = np.flipud(im)
    return im
Esempio n. 4
0
def _check_result(assert_result=True):
    """Test the color of each quadrant by picking the center pixel
    of each quadrant and comparing it with the reference color.
    """
    # Take screenshot
    x, y, w, h = gl.glGetParameter(gl.GL_VIEWPORT)
    data = gl.glReadPixels(x, y, w, h, gl.GL_RGB, gl.GL_UNSIGNED_BYTE)
    im = np.frombuffer(data, np.uint8)
    im.shape = h, w, 3

    # Get center pixel from each quadrant
    pix1 = tuple(im[int(1*h/4), int(1*w/4)])
    pix2 = tuple(im[int(3*h/4), int(1*w/4)])
    pix3 = tuple(im[int(3*h/4), int(3*w/4)])
    pix4 = tuple(im[int(1*h/4), int(3*w/4)])
    # print(pix1, pix2, pix3, pix4)

    if assert_result:
        # Test their value
        assert_equal(pix1, (0, 0, 0))
        assert_equal(pix2, (255, 0, 0))
        assert_equal(pix3, (0, 255, 0))
        assert_equal(pix4, (0, 0, 255))
Esempio n. 5
0
def _check_result(assert_result=True):
    """ Test the color of each quadrant by picking the center pixel 
    of each quadrant and comparing it with the reference color.
    """
    
    # Take screenshot
    x, y, w, h = gl.glGetParameter(gl.GL_VIEWPORT)
    data = gl.glReadPixels(x, y, w, h, gl.GL_RGB, gl.GL_UNSIGNED_BYTE)
    im = np.frombuffer(data, np.uint8)
    im.shape = h, w, 3
    
    # Get center pixel from each quadrant
    pix1 = tuple(im[int(1*h/4), int(1*w/4)])
    pix2 = tuple(im[int(3*h/4), int(1*w/4)])
    pix3 = tuple(im[int(3*h/4), int(3*w/4)])
    pix4 = tuple(im[int(1*h/4), int(3*w/4)])
    #print(pix1, pix2, pix3, pix4)
   
    if assert_result:
        # Test their value
        assert_equal(pix1, (0, 0, 0))
        assert_equal(pix2, (255, 0, 0))
        assert_equal(pix3, (0, 255, 0))
        assert_equal(pix4, (0, 0, 255))