I cant load picture[DIRECTX 10]

Nov 27, 2011 at 3:29pm
Hello, i not long ago start to learning directx 10. I read "BeginningDirectX® 10GameProgramming" and i compilate sample codes, but program isnt work as it should. Program isnt loading texture just rendering blue window. Function who loading and get texture to back bufor looks:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
ID3D10Texture2D* GetTexture2DFromFile()
{
ID3D10Texture2D* texture2D = NULL;
//ID3D10Resource* pD3D10Resource = NULL;
// Loads the texture into a temporary ID3D10Resource object
HRESULT hr = D3DX10CreateTextureFromFile(pD3DDevice,L"picture.bmp",NULL,NULL,&pD3D10Resource,NULL);
// Make sure the texture was loaded in successfully
pD3D10Resource ->QueryInterface(__uuidof( ID3D10Texture2D),(LPVOID*)&texture2D);
pD3D10Resource ->Release();
// returns the ID3D10Texture2D object
//ID3D10Texture2D *pBackBuffer;
hr = pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D),(LPVOID*)&texture2D);

D3D10_BOX sourceRegion;
sourceRegion.left = 0;
sourceRegion.right = 640;
sourceRegion.top = 0;
sourceRegion.bottom = 480;
sourceRegion.front = 0;
sourceRegion.back = 1;
pD3DDevice->CopySubresourceRegion(texture2D, 1, 130, 120, 1, texture2D, 0,
&sourceRegion);
return texture2D;
}

pictur.bmp ist in project folder

Handles:
1
2
3
4
5
6
7
HINSTANCE hInst; 
HWND wndHandle;
ID3D10Device* pD3DDevice = NULL;
IDXGISwapChain* pSwapChain = NULL;
ID3D10RenderTargetView* pRenderTargetView = NULL;
ID3D10Device *pDevice = NULL;
ID3D10Resource* pD3D10Resource = NULL;

Messeage loop like this:
1
2
3
4
5
6
7
8
9
10
11
12
...
while (WM_QUIT != msg.message)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
GetTexture2DFromFile();
Render();
}
}
...

And Render fuction :
1
2
3
4
5
6
7
8
9
10
11
12
void Render()
{
if (pD3DDevice != NULL)
{
// clear the target buffer
float clearColor[4] = {0.0f,1.0f,1.0f,1.0f};
	pD3DDevice->ClearRenderTargetView(pRenderTargetView,clearColor);
// All drawing will go here.
// display the next item in the swap chain
pSwapChain->Present(0, 0);
}
}

Why picture is invisible
Last edited on Nov 27, 2011 at 3:30pm
Nov 27, 2011 at 3:35pm
You don't check HRESULT return code. It is good practice to use FAILED() or SUCCEEDED() macros when working with COM APIs.
Nov 27, 2011 at 3:44pm
I do and I will say about the results
Nov 27, 2011 at 5:34pm
I do what you say and i known that function ist failed, why?
HRESULT hr = D3DX10CreateTextureFromFile(pD3DDevice,L"picture.bmp",NULL,NULL,&pD3D10Resource,NULL);
Topic archived. No new replies allowed.