3
votes

I am recently started DirectX. My main source of learning is "3D game programming with DirectX 11" by Frank D. Luna. In the Input Assembler stage, in the Rendering Pipeline, it has these lines of code:

ID3DX11Effect* mFX;
ID3DX11EffectTechnique* mTech;
/* ...create the effect... */
mTech = mFX->GetTechniqueByName("Tech");
D3DX11_PASS_DESC passDesc;
mTech->GetPassByIndex(0)->GetDesc(&passDesc);
HR(md3dDevice->CreateInputLayout(vertexDesc,
4,
passDesc. pIAInputSignature,
passDesc.IAInputSignatureSize,
&mInputLayout)); 

My code is this:

  // include the basic windows header files and the Direct3D header files

#include <windows.h>
#include <windowsx.h>
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dx10.h>
#include <xnamath.h>
#include <effects.h>




#define SCREEN_WIDTH  800
#define SCREEN_HEIGHT 600

// include the Direct3D Library file
#pragma comment (lib, "d3d11.lib")
#pragma comment (lib, "d3dx11.lib")
#pragma comment (lib, "d3dx10.lib")

// global declarations
IDXGISwapChain *swapchain;             // the pointer to the swap chain interface
ID3D11Device *dev;                     // the pointer to our Direct3D device interface
ID3D11DeviceContext *devcon;           // the pointer to our Direct3D device context
ID3D11RenderTargetView *backbuffer;    // the pointer to our back buffer                                     
ID3D11VertexShader *pVS;    // the vertex shader
ID3D11PixelShader *pPS;     // the pixel shader

                                       // function prototypes
void InitD3D(HWND hWnd);    // sets up and initializes Direct3D
void RenderFrame(void);     // renders a single frame
void CleanD3D(void);        // closes Direct3D and releases memory
void IA(void);
                            // the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);


// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
{
    HWND hWnd;
    WNDCLASSEX wc;

    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = L"WindowClass";

    RegisterClassEx(&wc);

    RECT wr = { 0, 0, 800, 600 };
    AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);

    hWnd = CreateWindowEx(NULL,
        L"WindowClass",
        L"Our First Direct3D Program",
        WS_OVERLAPPEDWINDOW,
        SCREEN_WIDTH,
        SCREEN_HEIGHT,
        wr.right - wr.left,
        wr.bottom - wr.top,
        NULL,
        NULL,
        hInstance,
        NULL);

    ShowWindow(hWnd, nCmdShow);

    // set up and initialize Direct3D
    InitD3D(hWnd);

    // enter the main loop:

    MSG msg;

    while (TRUE)
    {
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);

            if (msg.message == WM_QUIT)
                break;
        }

        RenderFrame();
    }


    // clean up DirectX and COM
    CleanD3D();


    return msg.wParam;
}


// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_DESTROY:
    {
        PostQuitMessage(0);
        return 0;
    } break;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
}


// 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 = 1;                               // how many multisamples
    scd.SampleDesc.Quality = 0;                             // multisample quality level
    scd.Windowed = TRUE;
    scd.BufferDesc.Width = SCREEN_WIDTH;
    scd.BufferDesc.Height = SCREEN_HEIGHT;
    scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;

    // 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);


    // get the address of the back buffer
    ID3D11Texture2D *pBackBuffer;
    swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);

    // use the back buffer address to create the render target
    dev->CreateRenderTargetView(pBackBuffer, NULL, &backbuffer);
    pBackBuffer->Release();

    // set the render target as the back buffer
    devcon->OMSetRenderTargets(1, &backbuffer, NULL);


    // Set the viewport
    D3D11_VIEWPORT viewport;
    ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));

    viewport.TopLeftX = 0;
    viewport.TopLeftY = 0;
    viewport.Width = SCREEN_WIDTH;
    viewport.Height = SCREEN_HEIGHT;

    devcon->RSSetViewports(1, &viewport);
}


// this is the function used to render a single frame
void RenderFrame(void)
{
    // clear the back buffer to a deep blue
    devcon->ClearRenderTargetView(backbuffer, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f));

    // do 3D rendering on the back buffer here

    // switch the back buffer and the front buffer
    swapchain->Present(0, 0);
}


// this is the function that cleans up Direct3D and COM
void CleanD3D(void)
{
    swapchain->SetFullscreenState(FALSE, NULL);    // switch to windowed mode

                                                   // close and release all existing COM objects
    swapchain->Release();
    backbuffer->Release();
    dev->Release();
    devcon->Release();
    pVS->Release();
    pPS->Release();
}

//RENDERING PIPELINE//




//input layout//

void IA()
{

    struct Vertex
    {
        XMFLOAT3 Pos; //0 bit
        XMFLOAT3 Normal; // 12 bit
        XMFLOAT3 tex0; // 24 bit
        XMFLOAT3 tex1; // 32 bit
    };


    D3D11_INPUT_ELEMENT_DESC VertexDesc[] = {
    { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "TEXCOORD", 1, DXGI_FORMAT_R32G32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0 }
    };


    ID3D10Effect * mFX;
    ID3D10EffectTechnique * mTech;
    ID3D11InputLayout* mInputLayout;
    D3D10_PASS_DESC passDesc;


    mTech = mFX->GetTechniqueByName("Tech");
    mTech->GetPassByIndex(0)->GetDesc(&passDesc);

    dev->CreateInputLayout(
        VertexDesc,
        4,
        passDesc.pIAInputSignature,
        passDesc.IAInputSignatureSize,
        &mInputLayout);

    //Set I.L to the device
    devcon->IAGetInputLayout(&mInputLayout);



}

After compiling a get the error:

C4700 uninitialized local variable 'mFX' used

But also these errors that I already had I think:

Severity Code Description Project File Line Warning C4005 'D3D10_ERROR_FILE_NOT_FOUND': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\d3d10.h 609 Warning C4005 'D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\d3d10.h 608 Warning C4005 'D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\d3d11.h 920 Warning C4005 'D3D11_ERROR_FILE_NOT_FOUND': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\d3d11.h 918 Warning C4005 'D3D11_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\d3d11.h 917 Warning C4005 'D3D11_ERROR_TOO_MANY_UNIQUE_VIEW_OBJECTS': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\d3d11.h 919 Warning C4005 'DXGI_ERROR_DEVICE_HUNG': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 26 Warning C4005 'DXGI_ERROR_DEVICE_REMOVED': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 25 Warning C4005 'DXGI_ERROR_DEVICE_RESET': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 27 Warning C4005 'DXGI_ERROR_DRIVER_INTERNAL_ERROR': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 31 Warning C4005 'DXGI_ERROR_FRAME_STATISTICS_DISJOINT': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 29 Warning C4005 'DXGI_ERROR_GRAPHICS_VIDPN_SOURCE_IN_USE': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 30 Warning C4005 'DXGI_ERROR_INVALID_CALL': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 21 Warning C4005 'DXGI_ERROR_MORE_DATA': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 23 Warning C4005 'DXGI_ERROR_NONEXCLUSIVE': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 32 Warning C4005 'DXGI_ERROR_NOT_CURRENTLY_AVAILABLE': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 33 Warning C4005 'DXGI_ERROR_NOT_FOUND': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 22 Warning C4005 'DXGI_ERROR_REMOTE_CLIENT_DISCONNECTED': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 34 Warning C4005 'DXGI_ERROR_REMOTE_OUTOFMEMORY': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 35 Warning C4005 'DXGI_ERROR_UNSUPPORTED': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 24 Warning C4005 'DXGI_ERROR_WAS_STILL_DRAWING': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 28 Warning C4005 'DXGI_STATUS_CLIPPED': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 13 Warning C4005 'DXGI_STATUS_GRAPHICS_VIDPN_SOURCE_IN_USE': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 16 Warning C4005 'DXGI_STATUS_MODE_CHANGED': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 17 Warning C4005 'DXGI_STATUS_MODE_CHANGE_IN_PROGRESS': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 18 Warning C4005 'DXGI_STATUS_NO_DESKTOP_ACCESS': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 15 Warning C4005 'DXGI_STATUS_NO_REDIRECTION': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 14 Warning C4005 'DXGI_STATUS_OCCLUDED': macro redefinition DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\dxgitype.h 12 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2662 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2663 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2664 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2665 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2666 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2667 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2668 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2689 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2690 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2691 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2694 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2695 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2698 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2702 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2712 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2713 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2715 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2716 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2717 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2727 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2728 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2729 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2730 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2731 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2732 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2742 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2743 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamath.h 2754 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamathconvert.inl 2254 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamathconvert.inl 4523 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamathconvert.inl 4577 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamathconvert.inl 4639 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamathconvert.inl 4707 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamathconvert.inl 4770 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamathconvert.inl 4832 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamathmisc.inl 518 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamathmisc.inl 519 Warning C4838 conversion from 'unsigned int' to 'INT' requires a narrowing conversion DX11proj c:\users\spyros\documents\microsoft directx sdk (june 2010)\include\xnamathvector.inl 1269

I am using Visual Studio 2015

Thanks in advance for all this bunch of code you read. I probably shouldn't have put all of it in one file.

1
Your mTech = mFX->GetTechniqueByName("Tech"); function fails because mFX is not initialized. You should use CreateFromFile (or something similar) prior the GetTechniqueByName call. If that's fixed you can check the other errors.Stefan

1 Answers

1
votes

You must first create an effect by calling function.

D3D10CreateEffectFromMemory(<paste_here_your_effect_data_buffer>, <paste_here_your_effect_data_buffer_length>,
        0, <device_interface>, <effect_pool>, &mFX);

Where effect data you can read from effect file.

reading data process

    std::fstream file;
    file.open("effect.fx", std::ios::binary | std::ios::in);

    char* pcbBuffer = NULL;

    file.seekg(0, std::ios::end);
    size_t nLength = file.tellg();
    file.seekg(0, std::ios::beg);

    pcbBuffer = new char[nLength];

    file.read(pcbBuffer, nLength);
    file.close();

where pcbBuffer will be our effect data, nLength our buffer length.