4
\$\begingroup\$

When I use a render target higher in resolution than 512×512, I receive an image with black borders, depending on how big this texture was.

Why is this? How can I fix it?


Here's how I create the texture and render target surface:

p_Device->CreateTexture(512, 512, 1, D3DUSAGE_RENDERTARGET,
    D3DFMT_A16B16G16R16, D3DPOOL_DEFAULT, &p_renderTexture, NULL);
p_mainRenderTexture->GetSurfaceLevel(0, &p_renderSurface);

And this is the main render-to-texture function:

void RenderSceneToTex(LPDIRECT3DDEVICE9 p_Device, D3DCOLOR clearColor,
        LPDIRECT3DSURFACE9 p_renderSurface, D3DXMATRIX matView,
        D3DXMATRIX matProjection, bool drawWater, bool drawTransparent,
        bool drawSkybox, LPSTR renderTech) {
    p_Device->SetTransform(D3DTS_VIEW, &matView);
    p_Device->SetTransform(D3DTS_VIEW, &matProjection);
    effect->SetMatrix("matView", &matView);
    effect->SetMatrix("matProjection", &matProjection);
    p_Device->SetRenderTarget(0, p_renderSurface);
    p_Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
        ((clearColor != NULL)?clearColor:D3DCOLOR_XRGB(0, 0, 0)), 1.0f, 0);
    p_Device->BeginScene();
    DrawSceneObjects(p_Device, drawWater, drawTransparent,
        drawSkybox, renderTech);
    p_Device->EndScene();
    p_Device->SetRenderTarget(0, p_dx_mainRenderSurface);
}
\$\endgroup\$
4
  • \$\begingroup\$ You are passing the D3DTS_VIEW value for both, the view and the projection matrix, in the call to SetTransform. \$\endgroup\$ Dec 15, 2014 at 15:36
  • \$\begingroup\$ I think it's not a problem, because I transform objects inside a vertex shader so these two lines of code, in fact, does nothing. \$\endgroup\$
    – Ocelot
    Dec 15, 2014 at 15:47
  • \$\begingroup\$ viewport problems maybe \$\endgroup\$ Dec 15, 2014 at 23:55
  • \$\begingroup\$ It is necessary to use the viewport? \$\endgroup\$
    – Ocelot
    Dec 16, 2014 at 7:33

1 Answer 1

2
\$\begingroup\$

The problem was inside present parameters - I forgot to set backbuffer's width and height.

dx_PresParams.Windowed = TRUE;
dx_PresParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
dx_PresParams.BackBufferFormat = D3DFMT_UNKNOWN;
dx_PresParams.BackBufferWidth = 1024;//Width
dx_PresParams.BackBufferHeight = 1024;//Height
dx_PresParams.EnableAutoDepthStencil = TRUE;
dx_PresParams.AutoDepthStencilFormat = D3DFMT_D24S8;
dx_PresParams.MultiSampleType = D3DMULTISAMPLE_8_SAMPLES;

But to be exact, the root of the problem was auto depth stencil being a surface in resolution of 512x512, so it didn't let me render scene in the whole texture.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .