Sign in to follow this  
Romanturbo

Post Process: My RenderTarget texture is always black

Recommended Posts

Hi! I,m trying to implement post process in my project. I´ve implemented a RenderTarget Class as follow:
class RenderTarget {
public:
    LPDIRECT3DTEXTURE9 texture; //La textura donde realmente voy a pintar.
    LPDIRECT3DSURFACE9 surface; //La surface de la textura anterior donde se va a pintar realmente.
    LPD3DXRENDERTOSURFACE render_to_surface; //Para gestionar el cambio.
    bool uses_active_zbuffer;
    std::string shader_tech; //Por defecto, "PostProcessTech".
    
    RenderTarget() : texture(NULL), surface(NULL), render_to_surface(NULL), uses_active_zbuffer(false), shader_tech("PostProcessTech") {}
    void init(int, int, bool);
    void beginRender();
    void endRender();
    void renderPostProcess();
    void save(std::string);
    void destroy();
};


The implementation of the init, beginRender, endRender and save methods is the following:
void RenderTarget::init(int xres, int yres, bool a_uses_active_zbuffer) {
    uses_active_zbuffer = a_uses_active_zbuffer;
    HRESULT hr = D3DXCreateTexture( g_pd3dDevice, xres, yres, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture);
    assert(hr == D3D_OK);
    hr = texture->GetSurfaceLevel(0, &surface);
    assert(hr == D3D_OK);
    hr = D3DXCreateRenderToSurface( g_pd3dDevice, xres, yres, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN, &render_to_surface);
    assert(hr == D3D_OK);
}
void RenderTarget::beginRender() {
    LPDIRECT3DSURFACE9 depth_surface;
    HRESULT hr;
    if(uses_active_zbuffer) {
        hr = g_pd3dDevice->GetDepthStencilSurface(&depth_surface); assert(hr == D3D_OK);
    }
    assert(render_to_surface != NULL);
    hr = render_to_surface->BeginScene(surface, NULL);
    assert(hr == D3D_OK);
    if(uses_active_zbuffer) {
        g_pd3dDevice->SetDepthStencilSurface(depth_surface); assert(hr == D3D_OK);
        depth_surface->Release();
    }
}
void RenderTarget::endRender() {
    assert(render_to_surface != NULL);
    HRESULT hr = render_to_surface->EndScene(0);
    assert(hr == D3D_OK);
}
void RenderTarget::save(std::string file_name) {
    HRESULT hr = D3DXSaveTextureToFile(file_name.c_str(), D3DXIFF_JPG, texture, NULL);
    assert(hr == D3D_OK);
}


The general render method is:
void render(float delta_time) {
     renderTarget.beginRender();
     g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x80808080, 1.0f, 0);
     renderWorld();  //My scene render.
     renderTarget.endRender();
     
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
     {
          renderTarget.renderPostProcess();      
          g_pd3dDevice->EndScene();
     } 
      g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}


I have a method to save the RenderTarget texture, so I can see the texture. The texture is not the actual frame of the scene, IT IS ALWAYS BLACK. All DirectX method returns a S_OK, the texture has the same size than the main window of the application. And, of course, the renderWorld method works fine. Any idea? Thanks and sorry for my poor English. EDIT: Fixed up your 'source' tags and gave the thread a meaningful title [Edited by - Romanturbo on September 17, 2008 9:43:38 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Romanturbo
I have a method to save the RenderTarget texture.
Do you mean save the contents of the texture to a disk that you can open in a 3rd party graphics/paint program?

If so, I see no code in your above to perform this operation - you'll need to show it to us if you want any help.

Before you do that, run with the debug runtimes to see if they tell you why you're not getting anything (S_OK is useful, but not the complete picture). Also, do a PIX capture and see what is stored internally.

hth
Jack

Share this post


Link to post
Share on other sites
I´m sorry, I have not explained it well.
The save method works fine and the application too, but the RenderTarget texture is black, even when I change the color in the Clear method of the D3D device.

Thanks and sorry again.

[Edited by - Romanturbo on September 17, 2008 9:22:25 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this