direct drawing into a texture

82 views
Skip to first unread message

val

unread,
Nov 28, 2008, 5:48:53 PM11/28/08
to pyglet...@googlegroups.com
i'm trying to draw into a context that is bigger than my screen. my
final goal is to get pictures of like 4000*3000px, and my screen is at
most 1440*900.
it doesn't work with setting a size bigger than my resolution, as the
part offscreen isn't draw, ie not saved in the picture a save.

i've found this link (
http://pyglet.googlecode.com/svn/trunk/examples/fixed_resolution.py ),
but it seems to be meant to achieve the opposite i want (enlarged
texture), and the way it's coded doesn't help me much (although i may
not have well understood it).

i've found that i can use pyglet.image.Texture to manipulate data that
isn't the window's size, but i'm not sure i understood it well.

here's my "screenshot" method:

def save(self,filename):
texture=pyglet.image.Texture.create(1600,1200,rectangle=True)
src=pyglet.image.get_buffer_manager().get_color_buffer().get_texture().image_data
texture.blit_into(src,0,0,0)
texture.save(filename)

the problem is that the output picture has the window resolution, not
the texture's one. i need something to stretch up while
'blit_into-ing', but can't find it in the doc.
anything i missed ?

Alex Holkner

unread,
Nov 28, 2008, 6:12:26 PM11/28/08
to pyglet...@googlegroups.com
On Sat, Nov 29, 2008 at 9:48 AM, val <val.b...@gmail.com> wrote:
>
> i'm trying to draw into a context that is bigger than my screen. my
> final goal is to get pictures of like 4000*3000px, and my screen is at
> most 1440*900.

In general OpenGL isn't suitable for this sort of work -- it's
designed for real-time (on-screen) compositing. There are some GPU
Gems articles around that describe how to composite into massive
images by dividing the final image into a series of 1024x1024 "tiles"
and rendering each one separately. The final stitching of the tiles
must be done in software though (e.g., you could use PIL).

> i've found this link (
> http://pyglet.googlecode.com/svn/trunk/examples/fixed_resolution.py ),
> but it seems to be meant to achieve the opposite i want (enlarged
> texture), and the way it's coded doesn't help me much (although i may
> not have well understood it).

Not really a relevant example for your problem.

> i've found that i can use pyglet.image.Texture to manipulate data that
> isn't the window's size, but i'm not sure i understood it well.
>
> here's my "screenshot" method:
>
> def save(self,filename):
> texture=pyglet.image.Texture.create(1600,1200,rectangle=True)
> src=pyglet.image.get_buffer_manager().get_color_buffer().get_texture().image_data
> texture.blit_into(src,0,0,0)
> texture.save(filename)
>
> the problem is that the output picture has the window resolution, not
> the texture's one. i need something to stretch up while
> 'blit_into-ing', but can't find it in the doc.

You can't stretch with blit_into, as it's just a data copy operation.
You need to have something you can composite into in order to scale
with OpenGL, such as a framebuffer. Since on-screen framebuffers are
(more or less) limited to your screen resolution, you'll need a
texture framebuffer (FBO with texture attachment). pyglet doesn't
have any support for this, you'll need to delve into the OpenGL calls
yourself. I believe the cocos2d people use FBOs in this way, there's
probably some sample code there.

Alex.

val

unread,
Nov 28, 2008, 6:56:54 PM11/28/08
to pyglet...@googlegroups.com
ok thanks. i'll have a look at cocos2d then, and post back if i find anything.
bye

On Sat, Nov 29, 2008 at 12:12 AM, Alex Holkner <alex.h...@gmail.com> wrote

meushi

unread,
Dec 1, 2008, 3:37:26 PM12/1/08
to pyglet-users
me again. the FBO has to wait a bit. i have another problem with
textures.

i save a texture of the screen at the beggining with this (p is the
window):

p.backgroundImage=pyglet.image.Texture.create
(p.width,p.height,rectangle=True)
src=pyglet.image.get_buffer_manager().get_color_buffer().get_texture
().image_data
p.backgroundImage.blit_into(src,0,0,0)

the texture isn't empty, everything okay til now. but later i use

p.backgroundImage.blit(0,0)

and it just doesn't do anything =/
i'm sure i didn't erase the image, as calling save on it works at any
moment.

could you tell me what i am missing with blit ?



On Nov 29, 12:56 am, val <val.bis...@gmail.com> wrote:
> ok thanks. i'll have a look at cocos2d then, and post back if i find anything.
> bye
>
> On Sat, Nov 29, 2008 at 12:12 AM, Alex Holkner <alex.holk...@gmail.com> wrote
> > You can't stretch withblit_into, as it's just a data copy operation.
Reply all
Reply to author
Forward
0 new messages