Jump to content
  • Advertisement
Sign in to follow this  
alireza.pir

OpenGL Capture what is Rendered in OpenGL

This topic is 1153 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im Making an android Game with OpenGl ES, I Want to capture what is rendered onto screen By FloatBuffer and save it for later use, For Example If this is the OutPut:

 

4QYjq.png

 

 

GBPFI.png

 

 

How can I do this?

Share this post


Link to post
Share on other sites
Advertisement

It is somewhat vague what you want exactly. Assuming that you want to read the content of output rendered by yourself, you can use glReadPixels to get the pixels. The details depend on many circumstances like reading from default framebuffer's front- or backbuffer or from an FBO attachment, the involved pixel formats, need for time continuous reading, ...

Share this post


Link to post
Share on other sites

When you say "capture", there's still a question of where you want to capture it to? Do you want to capture it to GPU memory for further GPU processing, or do you want to capture it back to CPU memory for e.g. saving to disk, or for other CPU processing?

 

If you want to capture the data to GPU memory for further GPU operations, the best way is to create a texture or a renderbuffer, and attach that to an FBO, and directly render the content to that FBO. After that you have the contents in a texture and can do whatever GPU side operations to it you want.

 

If you want to capture the data to CPU memory, then glReadPixels is your only choice if you are looking to use only core OpenGL ES 2 without assuming any extensions. glReadPixeling the default backbuffer can be very heavy, so it might be useful to use a FBO here as well, and glReadPixel the contents of the FBO instead of the default backbuffer.

 

If you are looking to use OpenGL ES 3, or have the OpenGL ES 2 https://www.khronos.org/registry/gles/extensions/NV/NV_pixel_buffer_object.txt extension, then you can use PBOs (pixelbuffer objects) as an optimized alternative to glReadPixels. (See the section "Asynchronous glReadPixels" in the description of that extension)

Share this post


Link to post
Share on other sites


If you are looking to use OpenGL ES 3, or have the OpenGL ES 2 https://www.khronos.org/registry/gles/extensions/NV/NV_pixel_buffer_object.txt extension, then you can use PBOs (pixelbuffer objects) as an optimized alternative to glReadPixels. (See the section "Asynchronous glReadPixels" in the description of that extension)

PBOs are not an alternative to glReadPixels You still need to run a glReadPixels command. The only thing is that glReadPixels can use a PBO to write the pixels to, allowing for an synchronous run.

Share this post


Link to post
Share on other sites

It is somewhat vague what you want exactly. Assuming that you want to read the content of output rendered by yourself, you can use glReadPixels to get the pixels. The details depend on many circumstances like reading from default framebuffer's front- or backbuffer or from an FBO attachment, the involved pixel formats, need for time continuous reading, ...

 

 

When you say "capture", there's still a question of where you want to capture it to? Do you want to capture it to GPU memory for further GPU processing, or do you want to capture it back to CPU memory for e.g. saving to disk, or for other CPU processing?

 

If you want to capture the data to GPU memory for further GPU operations, the best way is to create a texture or a renderbuffer, and attach that to an FBO, and directly render the content to that FBO. After that you have the contents in a texture and can do whatever GPU side operations to it you want.

 

If you want to capture the data to CPU memory, then glReadPixels is your only choice if you are looking to use only core OpenGL ES 2 without assuming any extensions. glReadPixeling the default backbuffer can be very heavy, so it might be useful to use a FBO here as well, and glReadPixel the contents of the FBO instead of the default backbuffer.

 

If you are looking to use OpenGL ES 3, or have the OpenGL ES 2 https://www.khronos.org/registry/gles/extensions/NV/NV_pixel_buffer_object.txt extension, then you can use PBOs (pixelbuffer objects) as an optimized alternative to glReadPixels. (See the section "Asynchronous glReadPixels" in the description of that extension)

 

 

let me clarify a bit, i want this capture to be reused later, i mean i want to capture the rendered opengl and then create a new rectangle with this capture as a texture on it, which of these two ways you mentioned should i use? and i will be thankful if you give me some links i follow cause im new on OpenGL.

 

i should mention that the game is on android and im coding with Eclipse

Edited by alireza.pir

Share this post


Link to post
Share on other sites

let me clarify a bit, i want this capture to be reused later, i mean i want to capture the rendered opengl and then create a new rectangle with this capture as a texture on it, which of these two ways you mentioned should i use?

This is usually not named capturing but "render to texture". The best way to do this is to not render to the default framebuffer but to an FBO (to a texture attached to an FBO, to be precise); look e.g. here to see an example. AFAIK OpenGLES 2 already supports FBOs. Use "opengl fbo tutorial" in your favorite search engine to get … well, more tutorials than ever needed ;)

Edited by haegarr

Share this post


Link to post
Share on other sites

 


let me clarify a bit, i want this capture to be reused later, i mean i want to capture the rendered opengl and then create a new rectangle with this capture as a texture on it, which of these two ways you mentioned should i use?

This is usually not named capturing but "render to texture". The best way to do this is to not render to the default framebuffer but to an FBO (to a texture attached to an FBO, to be precise); look e.g. here to see an example. AFAIK OpenGLES 2 already supports FBOs. Use "opengl fbo tutorial" in your favorite search engine to get … well, more tutorials than ever needed ;)

 

 

 

thank you for answers. and sorry im asking again, thats because i want to make it completely clear for myself.
 
i dont want the "Texture" to be rendered on screen itself, i want to Set this texture for a new Rectangle, for example if i have this in my game:
(which was a rectangle first filling with blue color, and turned to this by some functionality, the Blue and yellow DOTS Are Vertices of the mesh)
 
4QYjq.png
 
 
i want make a new rectangle polygon, by this previous rendered OutPut textured On it, meaning:
(white DOTS are new Mesh and the Blue part is as a texture on it 
 
Capture3.png
 
is your suggestion still suitable for me?
Edited by alireza.pir

Share this post


Link to post
Share on other sites


is your suggestion still suitable for me?

Yes. You do a 1st rendering pass with the folded mesh, into a texture attachment of an FBO. Then you do a 2nd render pass with mesh #2 (the orange quadrangle in the 2nd picture) with a texture mapping, and the bound texture is the one which was the render target in the 1st pass. So, the same texture is written in the 1st pass and read in the 2nd pass. That is the typical application of render to texture.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!