Exemple #1
0
func (c *Context) FramebufferPixels(f Framebuffer, width, height int) ([]uint8, error) {
	gl.Flush()

	gl.BindFramebuffer(gl.FRAMEBUFFER, uint32(f))

	pixels := make([]uint8, 4*width*height)
	gl.ReadPixels(0, 0, int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(pixels))
	if e := gl.GetError(); e != gl.NO_ERROR {
		return nil, errors.New(fmt.Sprintf("glReadPixels: %d", e))
	}
	return pixels, nil
}
func (c *Context) FramebufferPixels(f Framebuffer, width, height int) ([]uint8, error) {
	var pixels []uint8
	if err := c.runOnContextThread(func() error {
		gl.Flush()
		return nil
	}); err != nil {
		return nil, err
	}
	if err := c.bindFramebuffer(f); err != nil {
		return nil, err
	}
	if err := c.runOnContextThread(func() error {
		pixels = make([]uint8, 4*width*height)
		gl.ReadPixels(0, 0, int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(pixels))
		if e := gl.GetError(); e != gl.NO_ERROR {
			pixels = nil
			return fmt.Errorf("opengl: glReadPixels: %d", e)
		}
		return nil
	}); err != nil {
		return nil, err
	}
	return pixels, nil
}
Exemple #3
0
// ReadPixels returns pixel data from a buffer.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glReadPixels.xhtml
func ReadPixels(dst []byte, x, y, width, height int, format, ty Enum) {
	gl.ReadPixels(int32(x), int32(y), int32(width), int32(height), uint32(format), uint32(ty), gl.Ptr(&dst[0]))
}