## Recommended Posts

Hey, i'm not sure if i'm doing this right at all, but i tried to load an image and display that to the screen, for creating a HUD. But for some reason my image doesn't show at all. Hopefully someone here can tell me what i'm doing wrong: I have a function which loads the image, creates a resource for it and passes that to the backbuffer:
[source language="cpp"]
HRESULT PV2DImmediate::Load2DImageFromFile ( LPCWSTR filename )
{
HRESULT hr;

ID3D10Resource* pD3D10Resource = NULL;
hr = D3DX10CreateTextureFromFile ( g_pd3dDevice, filename, NULL, NULL, &pD3D10Resource, NULL );
if ( FAILED ( hr ) )
{
return E_FAIL;
}

ID3D10Texture2D* texture2D = NULL;
pD3D10Resource->QueryInterface(__uuidof( ID3D10Texture2D ),(LPVOID*) &texture2D);
pD3D10Resource->Release();

//// Get a pointer to the back buffer texture
ID3D10Texture2D *pBackBuffer;
hr = g_pSwapChain->GetBuffer ( 0, __uuidof ( ID3D10Texture2D ), (LPVOID*)&pBackBuffer );
if ( FAILED ( hr ) )
{
MessageBox ( NULL, L"Failed allocating backbuffer!", L"ERROR", MB_OK );
return E_FAIL;
}

D3D10_BOX sourceRegion;
sourceRegion.left = 0;
sourceRegion.right = 640;
sourceRegion.top = 0;
sourceRegion.bottom = 480;
sourceRegion.front = 0;
sourceRegion.back = 1;

g_pd3dDevice->CopySubresourceRegion ( pBackBuffer, 0, 0, 0, 0, pD3D10Resource, 0, &sourceRegion );

return S_OK;
}


Then in my WinMain right before the while loop where i do the PeekMessage and Render() i call that function above.
WinMain ( bla bla )
{
//...code

PV2DImmediate 2DImg;

while( WM_QUIT != msg.message )
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
pvCore.pvRender ( );
}
}

// some more code
}

Now all i get is a white window, i don't see my image at all. I'm also not doing anything in the renderloop with my 2D image... Well anyway, i hope someone here can tell me what i'm doing wrong. Thanks for any help.

##### Share on other sites
Typically you don't want to do a resource copy. Instead you want to create a shader resource view for your texture (you can use D3DX10CreateShaderResourceViewFromFile), and then draw it using triangles. The ID3DX10Sprite class allows you to easily draw textures using screen space positions.

##### Share on other sites
Sorry, this is all very new to me. I'm still not sure what to do.
Are you saying that with the code i have now i have to use D3DX10CreateShaderResourceViewFromFile()

Or do you mean that i just have to drop the code that i have now and move on to ID3DX10Sprite instead (without CreateShaderResourceViewFromFile())??

Or a combination of all of what you mentioned with my code..?

BTW, i want to load images of any size. Not just those with a size by the power of 2. 1,2,4,8,16,32,64,128,256,512 etc...

I'm not sure if that makes any difference in my case?

##### Share on other sites
No one that knows how to load and display an image? :(

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628400
• Total Posts
2982448

• 9
• 10
• 9
• 19
• 24