Read the bytes from a frame of the render window

Started by
5 comments, last by Hinch 14 years, 2 months ago
Hi, What I want to achieve is get all the pixel data of my rendering window without necessarily showing the window. I use a volume texture mapped onto multiple quads and with the use of alpha blending I display volumetric data. In some occasions I use just a single quad with a slice of the volume texture mapped onto it with no blending. Some of my work is done in shaders. Anyway, I need to get all the data of a frame displayed in the rendering window. Think of it as reading all the bytes from a still image. My ultimate goal is to pass this data (bytes) into a medical imaging viewer to use the image editing tools of the viewer. I could do all these operations on the CPU without using directX but it's slow and so I've done much of my work on the GPU side and ultimately I need this calculated image to be displayed via the viewer. It must be possible, isn't it? I use direct3D 9.
Advertisement
Quote:without necessarily showing the window

If this is your concern, when you create the window, don't call ShowWindow. Also, in your rendering loop, no need to call Present().

Is that what you're asking?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

No I'm not asking this. I need to put all the information the window would have displayed into a byte array. That's what I'm asking.
Search the documentation for a function called GetRenderTargetData, you probably want to use that to copy the render target data to a surface you have created in D3DPOOL_SYSTEMMEM, then you can Lock that surface to get the actual bytes.
Not an expert on this, but you can render to a texture. if you are using DirectX you can find a tutorial here: http://www.codesampler.com/dx9src/dx9src_7.htm#dx9_offscreen_rendering
Thanks for the replies guys you were both helpful. I had read about rendering to texture but I wanted to know about the most optimized way to do what I try to do. I assume Hinch's method is better and I'm going to look at it.

Is there any particular reason to prefer the System Memory than the Default pool Hinch?
Yes, default pool for textures normally means in GPU memory, so you wouldn't be able to access the bytes directly :) The docs for GetRenderTargetData state specifically "The destination surface must be either an off-screen plain surface or a level of a texture (mipmap or cube texture) created with D3DPOOL_SYSTEMMEM".

This topic is closed to new replies.

Advertisement