Pavor

Hello.

How to create off-screen surface in Direct3D 10 and then copy its contents to the back buffer

The way it was done in DX 9:

CreateOffscreenPlainSurface to create surface and UpdateSurface to copy image.

Could not find it in the documentation.



Re: Direct3D 10 D3D10: off-screen surface

supagu

most of the dx10 samples render off screen and then render to the back buffer using quads.
I also do this and it works fine.




Re: Direct3D 10 D3D10: off-screen surface

Pavor

Eeeee... Quads Here I'm afraid, I don't get it..

I just wanted to ask how to render a 2d image to the screen. I did it with surfaces on DX 9. Any ideas





Re: Direct3D 10 D3D10: off-screen surface

Pavor

So, no one of Microsoft pros knows how to render 2d image in DX 10 :)





Re: Direct3D 10 D3D10: off-screen surface

Alexey Barkovoy

Look at Copying and Accessing Resource Data in SDK documentation



Re: Direct3D 10 D3D10: off-screen surface

Pavor

Please hlp me with the rendering. I'm trying to create texture from .BMP file and then use GetBuffer method to get pointer to back buffer as a TextureResource, then copy the picture from the texture to the backbuffer using CopySubresourceRegion method.

Just code errors or my conception is wrong from the very beginning

// global variables

D3DX10_IMAGE_INFO g_ImageFileInfo;

ID3D10Resource* g_pTexture2d=NULL;

ID3D10Resource* g_pBuf2Copy=NULL;

 

HRESULT InitDirect3D()

{

//Do init stuff here

// Here we create a texture from file

D3DX10GetImageInfoFromFile (L"DirectX10.bmp", NULL, &g_ImageFileInfo);

D3DX10_IMAGE_LOAD_INFO img_info;

img_info.Width=200;

img_info.Height=200;

img_info.Depth=1;

img_info.FirstMipLevel=0;

img_info.MipLevels=0;

img_info.Usage=D3D10_USAGE_DEFAULT;

img_info.BindFlags=D3D10_BIND_SHADER_RESOURCE;

img_info.CpuAccessFlags=D3D10_CPU_ACCESS_READ;

img_info.MiscFlags=0;

img_info.Format=DXGI_FORMAT_R8G8B8A8_UNORM;

img_info.Filter=D3DX10_FILTER_NONE;

img_info.MipFilter=D3DX10_FILTER_NONE;

img_info.pSrcInfo=&g_ImageFileInfo;

//Error after D3DX10CreateTextureFromFile

hr=D3DX10CreateTextureFromFile(g_pd3dDevice, L"DirectX10.bmp", &img_info, NULL, &g_pTexture2d);

if FAILED (hr) // hr=E_INVALIDARG

return(hr);

g_pSwapChain->GetBuffer( 0, __uuidof( ID3D10Resource ), (LPVOID*)&g_pBuf2Copy );

return S_OK;

}

 

void Render()

{

D3D10_BOX destRegion;

destRegion.left = 0;

destRegion.right = 0;

destRegion.top = 200;

destRegion.bottom = 200;

destRegion.front = 0;

destRegion.back = 1;

g_pd3dDevice->CopySubresourceRegion( g_pBuf2Copy , 0, 0,0,0, g_pTexture2d, 0, &destRegion );

g_pSwapChain->Present( 0, 0 );

}





Re: Direct3D 10 D3D10: off-screen surface

Jack Hoxley

Bear in mind that your approach to 2D rendering, even if it worked under D3D9, is far from optimal - you might not like the idea of screen-space quads, but it is without a doubt the best approach. Clutching onto the remenants of the 'DirectDraw way' isn't a good idea

Pavor wrote:
//Error after D3DX10CreateTextureFromFile

hr=D3DX10CreateTextureFromFile(g_pd3dDevice, L"DirectX10.bmp", &img_info, NULL, &g_pTexture2d);

if FAILED (hr) // hr=E_INVALIDARG

return(hr);

You can probably help yourself - get the debug runtimes enabled and see what it reveals. The HRESULT's rarely give much info (except, in your case, pointing out that img_info is probably the culprit) but the debug runtimes do.

Check the SDK documentation for valid combinations of D3DX10_IMAGE_LOAD_INFO fields. I don't have my doc's to hand, but it's probably a safe bet that you've put something invalid in here...

hth
Jack






Re: Direct3D 10 D3D10: off-screen surface

Pavor

OK. No DirectDraw :)

What about sprites This code runs ok, but there is a colored rectangle in the middle of the window instead of the picture in the file "DirectX10.bmp"

//Global variables

ID3D10ShaderResourceView* g_pShaderResource = NULL;

ID3DX10Sprite * g_pSprite = NULL;

HRESULT InitDirect3D10()

{

// Init stuff here.........

D3DX10_IMAGE_INFO InfoFromFile;

D3DX10_IMAGE_LOAD_INFO LoadImageInfo;

// Reading info from the file

D3DX10GetImageInfoFromFile(L"DirectX10.bmp", NULL, &InfoFromFile);

LoadImageInfo.Width = InfoFromFile.Width;

LoadImageInfo.Height = InfoFromFile.Height;

LoadImageInfo.Depth = InfoFromFile.Depth;

LoadImageInfo.FirstMipLevel = 1;

LoadImageInfo.MipLevels = InfoFromFile.MipLevels;

LoadImageInfo.Usage = D3D10_USAGE_DEFAULT;

LoadImageInfo.BindFlags = D3D10_BIND_SHADER_RESOURCE ;

LoadImageInfo.CpuAccessFlags = 0;

LoadImageInfo.MiscFlags = 0;

LoadImageInfo.Format = InfoFromFile.Format;

LoadImageInfo.Filter = D3DX10_FILTER_NONE;

LoadImageInfo.MipFilter = D3DX10_FILTER_NONE;

LoadImageInfo.pSrcInfo = &InfoFromFile;

hr = D3DX10CreateShaderResourceViewFromFile(g_pd3dDevice, L"DirectX10.bmp", &LoadImageInfo, NULL, &g_pShaderResource);

if( FAILED(hr) )

return hr;

hr = D3DX10CreateSprite(g_pd3dDevice, 1, &g_pSprite);

if( FAILED(hr) )

return hr;

}

void Render()

{

D3DXMATRIX MatrixWorld;

D3DXMatrixIdentity( &MatrixWorld );

D3DX10_SPRITE SpriteToDraw;

SpriteToDraw.matWorld = MatrixWorld;

SpriteToDraw.TexCoord.x = 0;

SpriteToDraw.TexCoord.y = 0;

SpriteToDraw.TexSize.x = 200;

SpriteToDraw.TexSize.y = 200;

SpriteToDraw.ColorModulate = D3DXCOLOR(1.0f,1.0f,1.0f,1.0f);

SpriteToDraw.pTexture = g_pShaderResource;

SpriteToDraw.TextureIndex = 0;

float ClearColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f };

//Clear screen

g_pd3dDevice->ClearRenderTargetView( g_pRenderTargetView, ClearColor );

g_pSprite->Begin( D3DX10_SPRITE_SORT_TEXTURE );

g_pSprite->DrawSpritesBuffered(&SpriteToDraw, 1);

g_pSprite->Flush();

g_pSprite->End();

g_pSwapChain->Present( 0, 0 );

}





Re: Direct3D 10 D3D10: off-screen surface

Pavor

So, nobody knows



Re: Direct3D 10 D3D10: off-screen surface

Pavor

if you want something to be done well, do it yourself

well, for the ones still looking for the answer:

SpriteToDraw.TexCoord.x = 0.0f;

SpriteToDraw.TexCoord.y = 0.0f;

SpriteToDraw.TexSize.x = 1.0f;

SpriteToDraw.TexSize.y = 1.0f;

et voila...

TextSize are actually u and v texture coordinates, took me long to figure it out