tripleplay.util.Layers.capture in tripleplay 2.x

43 views
Skip to first unread message

Tom Fisher

unread,
Jul 7, 2015, 10:39:12 AM7/7/15
to pl...@googlegroups.com
Hi Michael,

We are planning to update to PlayN2.x, but tripleplay.util.Layers.capture() in 1.x is still not provided in 2.x.  Image capturing is one of important features of our project and we cannot live without it.
Would you please give me some clue about how to implement it in 2.x?

Thanks.

Michael Bayne

unread,
Jul 7, 2015, 11:16:26 AM7/7/15
to pl...@googlegroups.com
On Tue, Jul 7, 2015 at 7:39 AM, Tom Fisher <tom.x....@gmail.com> wrote:
We are planning to update to PlayN2.x, but tripleplay.util.Layers.capture() in 1.x is still not provided in 2.x.  Image capturing is one of important features of our project and we cannot live without it.
Would you please give me some clue about how to implement it in 2.x?

"Capturing" is not a thing in PlayN 2.x because the rendering system is designed such that you can just render your scene graph anywhere you like. Specifically to a TextureSurface to capture the rendering in a texture:

Platform plat = ...;
SceneGame game = ...;
TextureSurface surf = new TextureSurface(plat.graphics(), game.defaultBatch, width, height);
Layer root = ...;
root.paint(surf);
// now surf.texture is a texture that has 'root' rendered to it; you can put it in an ImageLayer or do what you like with it


Tom Fisher

unread,
Jul 8, 2015, 6:57:17 PM7/8/15
to pl...@googlegroups.com

Thanks a lot. 

Tom Fisher

unread,
Jul 12, 2015, 6:49:36 AM7/12/15
to pl...@googlegroups.com

I'd been looking for how to convert or paint the painted texture into a canvas in the playn2.0 source code so that I can use flush the canvas.image to an image file or a movie. Or is there a way of saving the surface into an image? 

Tom Fisher

unread,
Jul 14, 2015, 6:06:54 AM7/14/15
to pl...@googlegroups.com
I was planning to achieve that with glGetTexImage, but it may be not supported by OpenGL ES 2.0 and not provided in GL20.java, then turned to glReadPixels.


It seems that glReadPixels reads data much slower than using glGetBufferSubData in conjunction with  PBO, as discussed as in http://stackoverflow.com/questions/25127751/opengl-read-pixels-faster-than-glreadpixels 


But some constants mentioned in the above link are not defined in GL20.java, such as GL_PIXEL_PACK_BUFFER. Is it safe to pass the constant value directly to the api call?


I don't have any GL experiences, any suggestions are welcome :) 


Thanks

Michael Bayne

unread,
Jul 14, 2015, 4:31:54 PM7/14/15
to pl...@googlegroups.com
On Tue, Jul 14, 2015 at 3:06 AM, Tom Fisher <tom.x....@gmail.com> wrote:

It seems that glReadPixels reads data much slower than using glGetBufferSubData in conjunction with  PBO, as discussed as in http://stackoverflow.com/questions/25127751/opengl-read-pixels-faster-than-glreadpixels 

OpenGL ES 2.0 does not support PBOs as far as I know.

If you're really doing something performance sensitive (like capturing full screen animation) then you can explore more complicated solutions which may work on some devices: GL ES 3.0 supports PBOs, or the EGL_KHR_image_base may be supported by some phones:

https://vec.io/posts/faster-alternatives-to-glreadpixels-and-glteximage2d-in-opengl-es

But you're getting pretty deep into crazy land at that point. I'd stick with glReadPixels unless this was something utterly essential to making your game awesome.


Tom Fisher

unread,
Jul 14, 2015, 7:34:12 PM7/14/15
to pl...@googlegroups.com

As a GL newbie, I choose to start with the simplest solution :) 

Thanks.

Andres Q

unread,
May 17, 2020, 1:13:52 PM5/17/20
to PlayN
Hijacking a 5 year old thread, I couldn't find how to do this, specifically I want to be able to take a screenshot but only from a part of the screen (highscores) to allow the player to share that to friends.

I know I can render to a Texture but I was unable to find out how to produce an Image from a Texture. As you might suspect already, I have almost 0 knowledge of OpenGL :(

Any hints? Thanks

El martes, 14 de julio de 2015, 17:31:54 (UTC-3), Michael Bayne escribió:
Reply all
Reply to author
Forward
0 new messages