Beginning DirectX initializing a 2D or 3D environment

Started by
2 comments, last by mathacka 11 years, 3 months ago

Hi, I'm having a hard time understanding the minimum requirements I need to initialize Direct2D and Direct3D. It seems when I look at another init() function I get a different way to do it, here's one I picked off the internet:


// this function initializes and prepares Direct3D for use
void InitD3D(HWND hWnd)
{
    // create a struct to hold information about the swap chain
    DXGI_SWAP_CHAIN_DESC scd;

    // clear out the struct for use
    ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));

    // fill the swap chain description struct
    scd.BufferCount = 1;                                    // one back buffer
    scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;     // use 32-bit color
    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;      // how swap chain is to be used
    scd.OutputWindow = hWnd;                                // the window to be used
    scd.SampleDesc.Count = 4;                               // how many multisamples
    scd.Windowed = TRUE;                                    // windowed/full-screen mode

    // create a device, device context and swap chain using the information in the scd struct
    D3D11CreateDeviceAndSwapChain(NULL,
                                  D3D_DRIVER_TYPE_HARDWARE,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  D3D11_SDK_VERSION,
                                  &scd,
                                  &swapchain,
                                  &dev,
                                  NULL,
                                  &devcon);
}

Then in another one it begins with this and uses a ton of code!


bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen, 
			  float screenDepth, float screenNear)
{
	HRESULT result;
	IDXGIFactory* factory;
	IDXGIAdapter* adapter;
	IDXGIOutput* adapterOutput;
	unsigned int numModes, i, numerator, denominator, stringLength;
	DXGI_MODE_DESC* displayModeList;
	DXGI_ADAPTER_DESC adapterDesc;
	int error;
	DXGI_SWAP_CHAIN_DESC swapChainDesc;
	ID3D10Texture2D* backBufferPtr;
	D3D10_TEXTURE2D_DESC depthBufferDesc;
	D3D10_DEPTH_STENCIL_DESC depthStencilDesc;
	D3D10_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
	D3D10_VIEWPORT viewport;
	float fieldOfView, screenAspect;
	D3D10_RASTERIZER_DESC rasterDesc;

What is it that I'm missing, I have a ton of books, but I can't seem to understand DirectX?

Also, Direct2D uses presentation perameters more often, what's the difference?

Advertisement

Ok, so I've done a bit more research. I took a look at this site and I think I'm understanding a bit more.

So when you initialize directX, your making an interface to hardware, and you don't know what hardware is supported and what is not.

So step one is to check for some basic operations, display mode, hardware acceleration, and capabliities, then you tell the interface what you'd like to make with presentation parameters and attempt to create the device.

It's all making more sense now.

Are there any comments on anything I might be missing in these statements?

I would suggest you try and follow one of the many tutorials available or get a good book on the subject.<br /><br />http://www.rastertek.com/tutdx11.html<br />http://www.braynzarsoft.net/index.php?p=DX11Lessons<br /><br />http://www.amazon.com/gp/product/1936420228/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=braysoft-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1936420228<br /><br />

Thank you, I'm thinking about getting the game coding complete book!

This topic is closed to new replies.

Advertisement