We can use DXGI_FORMAT_R8G8B8A8_UNORM, which is a 32-bit unsigned integer, taking 8 bits for Red, Green, Blue, and Alpha each. This is a DXGI_FORMAT enumerated type, describing the format of our display. This is a DXGI_RATIONAL type, describing the refresh rate in hertz. This is the Height of the resolution we are going to use. This is the Width of the resolution we are going to use. The DXGI_MODE_DESC structure:ĭXGI_MODE_SCANLINE_ORDER ScanlineOrdering Then we fill out our backbuffer description. Then we call ZeroMemory to make sure the object is completely cleaned out (in case we don't set all the parameters, and a parameter already has a value in it). We create a DXGI_MODE_DESC object called bufferDesc. The first thing we do in this function is describe our backbuffer. I have not included error checking in order to keep the code more clear and condensed, but I will explain at the end of this lesson how you can impliment error checking. Hr = d3d11Device->CreateRenderTargetView( BackBuffer, NULL, &renderTargetView ) ĭ3d11DevCon->OMSetRenderTargets( 1, &renderTargetView, NULL ) įirst we create an HRESULT object called hr to use for error checking. Hr = SwapChain->GetBuffer( 0, _uuidof( ID3D11Texture2D ), (void**)&BackBuffer ) Hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL,ĭ3D11_SDK_VERSION, &swapChainDesc, &SwapChain, &d3d11Device, NULL, &d3d11DevCon) SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT ![]() ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC)) ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC)) īufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM īufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED īufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED ![]() I will go through it part by part.īool InitializeDirect3dApp(HINSTANCE hInstance) It takes one parameter, which is the handle to our applications instance. This is our function which will initialize direct3d. MessageBox(0, L"Scene Initialization - Failed", MessageBox(0, L"Direct3D Initialization - Failed", If(!InitializeDirect3d11App(hInstance)) //Initialize Direct3D After that we will call our messageloop, and when our message loop is done, we release our objects, then end the program. In our winMain function, we will call InitializeDirect3d11App, then InitScene. Update scene is used to change our scene on a per-frame basis, then the draw scene is used to draw our scene to the screen, and is updated every frame too.īool InitializeDirect3d11App(HINSTANCE hInstance) The second one is to release the objects we don't need to prevent memory leaks. The first function is used to initialize direct3d. ID3D11RenderTargetView* renderTargetView The next 6 lines are used to change the color of the background, not important to the lesson. Then this texture is sent to the output merger stage of the pipeline as our render target, which will then be rendered to the screen. Basically, we do not write directly to the screen, but instead write to the render target view, which is a 2d texture (our backbuffer). ![]() So, after that, we have another interface object, which is the render target view. Its not a difficult idea to understand, so i hope you follow what i'm saying. This will take away from performance hits when loading models, creating objects, or anything like that. While the object or model is loading or creating, you can call the ID3D11DeviceContext interface object to continue rendering your scene. When you are loading something into memory, such as a model, or creating an object, you will call the ID3D11Device object. DirectX 11 has new multi-threading features, used to speed up the applications. I will better explain the reason behind splitting the ID3D11Device into two. We will use our ID3D11DeviceContext interface object to call all the rendering method, while ID3D11Device will be used to call the rest of the methods that don't have to do with rendering. The ID3D11Device interface was split into two, to help support the new multi-threading features. Now, the line after that, is a new interface that came with directx 11. The next is an Interface we will use to represent our hardware device (GPU). ![]() Otherwise, we will get scanlines, which is when we can see our program drawing our scene to the screen, from the top down usually. When we render our scene, we are rendering to the backbuffer, so by the time we present the back buffer to the monitor, it will be fully drawn. This is our SwapChain, which is used to change the backbuffer to the front buffer, and the front buffer to the back buffer. The first declaration is a COM Interface object.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |