• Advertisement
Sign in to follow this  

Beginning DirectX initializing a 2D or 3D environment

This topic is 1836 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

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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

Share this post


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

  • Advertisement