Jump to content
  • Advertisement
Sign in to follow this  
tom_mai78101

DirectX 10: Two Problems (REFERENCE/HARDWARE and Texture2DtoBackBuffer() confusion...

This topic is 2758 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[font="Times New Roman"]1. REFERENCE/HARDWARE problem
[/font]

Here's the code:



bool InitDirect3D(HWND hWnd, int width, int height, ID3D10Device** ppDevice, IDXGISwapChain** ppSwapChain, ID3D10RenderTargetView** ppTarget)
{
DXGI_SWAP_CHAIN_DESC SwapChain;
ZeroMemory(&SwapChain, sizeof(DXGI_SWAP_CHAIN_DESC));
SwapChain.BufferCount = 1;
SwapChain.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
SwapChain.BufferDesc.Height = height;
SwapChain.BufferDesc.RefreshRate.Denominator = 1;
SwapChain.BufferDesc.RefreshRate.Numerator = 60;
SwapChain.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
SwapChain.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
SwapChain.BufferDesc.Width = width;
SwapChain.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
SwapChain.Flags = NULL;
SwapChain.OutputWindow = hWnd;
SwapChain.SampleDesc.Count = 1;
SwapChain.SampleDesc.Quality = 0;
SwapChain.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
SwapChain.Windowed = TRUE;

HRESULT hResult = D3D10CreateDeviceAndSwapChain( NULL,
D3D10_DRIVER_TYPE_REFERENCE, //<---------------------------------------
NULL,
NULL,
D3D10_SDK_VERSION,
&SwapChain,
ppSwapChain,
ppDevice);
if (FAILED(hResult))
{
MessageBox(NULL, TEXT("Error: D3D10CreateDeviceAndSwapChain() failed. Hard one, indeed."), TEXT(__FUNCTION__), MB_OK);
return false;
}
//........
//........So many other checking/rechecking...
//........
}


The part the arrow is pointing at. When I change it to the default mode: D3D10_DRIVER_TYPE_HARDWARE, I get an HRESULT error E_OUTOFMEMORY. If I change it back to D3D10_DRIVER_TYPE_REFERENCE, everything's normal. I don't know why, but this E_OUTOFMEMORY seems to be affected by my hardware graphics card... What is the problem?

Computer Specs: Windows 7 x64, (Gigabyte) Nvidia GTS250 1GB, Visual Studio 2010 Express SP1 Beta (Can't use atlbase.h, did not install the boost class library), 8 GB of RAM. I chose to go raw DirectX, and it's my preference. :)


[font="Times New Roman"]2. Texture2DtoBackbuffer() Confusion - Including RenderFunction()

[/font][font="Arial"]Here's the code for RenderFunction():


bool RenderFunction(ID3D10Device* pDevice, IDXGISwapChain* pSwapChain, ID3D10RenderTargetView* pTarget, const int WIDTH, const int HEIGHT)
{
if (pDevice != NULL)
{
ID3D10Texture2D* pTexture2D = NULL;
ID3D10Resource* pResource = NULL;
pTexture2D = GetTexture2DFromFile(pDevice, TEXT("C:\\test.bmp"));
if (pTexture2D == NULL)
{
MessageBox(NULL, TEXT("Error: GetTexture2DFromFile() failed. Texture file must be missing."), TEXT(__FUNCTION__), MB_OK);
return false;
}
pDevice->ClearRenderTargetView(pTarget, D3DXCOLOR(0.9f, 0.1f, 0.6f, 0.0f));
Texture2DtoBackBuffer(&pDevice, &pTexture2D, &pSwapChain, WIDTH, HEIGHT);
pSwapChain->Present(0, NULL);
}
else
return false;
return true;
}


The Texture2DtoBackBuffer() function works correctly, as I step through the function and it didn't have any errors. The only problem left is, where should I put this function in RenderFunction()? Currently, it gives me a blank, non-colored background and stays there. The background's color is purple, defined when registering the WNDCLASSEX. I'm trying to draw a small 100x100 BMP image onto my background. I suspected it's the function's location (position) that's not working correctly.

If it's not the RenderFunction() problem, are there any problems in my Texture2DtoBackBuffer()? Here's the code for it, just in case...


void Texture2DtoBackBuffer(ID3D10Device** ppDevice, ID3D10Texture2D** ppTexture2D, IDXGISwapChain** ppSwapChain, const int WIDTH, const int HEIGHT)
{
ID3D10Texture2D* pBackBuffer = NULL;
HRESULT hResult = (*ppSwapChain)->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer);
if (FAILED(hResult))
{
MessageBox(NULL, TEXT("Error: Texture2DtoBackBuffer() failed. IDXGISwapChain* failed."), TEXT(__FUNCTION__), MB_OK);
return;
}
D3D10_BOX sourceRegion;
sourceRegion.back = 1;
sourceRegion.bottom = HEIGHT;
sourceRegion.front = 0;
sourceRegion.left = 0;
sourceRegion.right = WIDTH;
sourceRegion.top = 0;
(*ppDevice)->CopySubresourceRegion( pBackBuffer,
NULL,
NULL,
NULL,
NULL,
*ppTexture2D,
NULL,
&sourceRegion);
(*ppTexture2D)->Release();
return;
}


Thanks in advance.[/font]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!