Hello,
Here is a small snippet that creates a copy of a texture using
cogl_texture.get_data. I'm not sure this is the best way to achieve what
you're trying to do, but it shows how to use this method.
# texture is a Texture where you have drawn, possibly a Cairo texture
cogl_t = texture.get_cogl_texture()
if cogl_t:
# there you get the graphical data of the texture
data = cogl_t.get_data(texture.get_pixel_format(),
cogl_t.get_rowstride())
width = texture.get_width()
height = texture.get_height()
pixel_format = texture.get_pixel_format()
rowstride = cogl_t.get_rowstride()
flags = texture.get_flags()
# create a new cogl texture
new_cogl_t = clutter.cogl.texture_new_from_data(
width,height, pixel_format,rowstride,
data, flags, pixel_format)
if new_cogl_t:
new_texture.set_cogl_texture(new_cogl_t)
This supposes that you are using the git version of pyclutter.
Cheers,
Julien
2010/3/16 Jesse Dhillon <[email protected]>
> Hi Julien,
>
> I saw that you had checked in some substantive changes to
> cogl-texture.overrides. I have been trying to figure out how to render to an
> offscreen buffer and then get the data from that buffer and tracking down
> even informal docs has been very hard. What I've tried doing is listed
> below, could you take a look and get me pointed in the right direction?
>
> import clutter
> import clutter.cogl as cogl
>
> target = cogl.BufferTarget(cogl.OFFSCREEN_BUFFER)
> rgba = cogl.PixelFormat(cogl.PIXEL_FORMAT_RGBA_8888)
> noneflags = cogl.TextureFlags(cogl.TEXTURE_NONE)
>
> texture = cogl.texture_with_new_size(800, 600, noneflags, rgba)
> handle = cogl.Offscreen(texture)
> cogl.set_draw_buffer(target, handle)
>
> stage = clutter.Stage()
> stage.show()
>
> rect = clutter.Rectangle()
> rect.set_color(clutter.color_from_string("red"))
> rect.set_size(100, 100)
> rect.set_position(150, 150)
>
> stage.add(rect)
> stage.show_all()
>
> data = texture.get_data(texture.get_format(), texture.get_rowstride())
>
> At this point I would expect 'data' to contain image data that I can write
> out, but it contains nothing. Texture.get_data is not returning anything. Am
> I using clutter/cogl correctly or am I missing something? Anything you can
> suggest would be helpful, thanks in advance
>
> --
>
> Jesse Dhillon
>
> 916.501.8642
>
> www.devazero.com/portfolio <http://devazero.com/portfolio>
>
> [email protected]
>