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\$
  • \$\begingroup\$ You are passing the D3DTS_VIEW value for both, the view and the projection matrix, in the call to SetTransform. \$\endgroup\$ – user000user Dec 15 '14 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 '14 at 15:47
  • \$\begingroup\$ viewport problems maybe \$\endgroup\$ – ratchet freak Dec 15 '14 at 23:55
  • \$\begingroup\$ It is necessary to use the viewport? \$\endgroup\$ – Ocelot Dec 16 '14 at 7:33
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 real problem was inside the auto depth stencil that was a surface in resolution of 512x512 and wasn't allow me to render scene in textures with proper size.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.