C++ | DirectX | Class system ?!

Started by
36 comments, last by Mate 9 years, 5 months ago
I buy it. I tried a couple of tutorials of C++ before, but they were too basic. Its just boring to read what integers and floats are.

You can always skip the parts that you believe you know (though I for example always read them just in case - it never hurts to refresh your knowledge - and usually this is only for around 100 pages).

Thats why I tried to only ask for the differences of the two languages in here to fill the hole, without wasting time on things I know from Java.

You cannot expect other people to "fill the hole" in this case, as the differences between the two languages are neither few, nor trivial. My advice is that you pick a solid book like C++ Primer.

Now I'm searching a book exactly done for my "holes".

Don't search for such a book, just pick a good book and skip the parts you believe you already know (though I wouldn't skip anything if I were you).

Know if you want a concrete question I'll give you.

The issue is that all the questions you ask, you wouldn't need to ask if you actually picked a decent C++ book.

ID3D11DeviceContext **deviceContext, device context is a pointer to a pointer, meaning you should do something like (*deviceContext)->someMethod().

(Why are you passing the device context to your own functions?)

For example:


class Foo
{
    //...
public:
    void do() const
    {
        //...
    }
};

void do(const Foo** foo)
{
    //foo->do() //wrong
    (*foo)->do();
}
Advertisement

The issue is that all the questions you ask, you wouldn't need to ask if you actually picked a decent C++ book.

ID3D11DeviceContext **deviceContext, device context is a pointer to a pointer, meaning you should do something like (*deviceContext)->someMethod().

(Why are you passing the device context to your own functions?)

For example:


class Foo
{
    //...
public:
    void do() const
    {
        //...
    }
};

void do(const Foo** foo)
{
    //foo->do() //wrong
    (*foo)->do();
}

Thank you :)

C++ Primer is a good book. The only point holding me is, that it's in english. Thats kinda 3 times harder than reading a book in my motherlanguage. I will think of it.

Now the solution is, that for multiple pointers i have to put it in brackets ? Like :

Object ****obj

...function(Object ****obj)

(***obj)->func();

Good thank you.

If you feel not pissed enough to awnser another question, read below, otherwise better stop here :).

I'm getting an error in the Linker-stage. It tells me errors with extern symbols. I can't translate the exact error. So im getting it every time I call a method from another class in Main.cpp.

The headers are implemented already and the compiler-stage shows no errors.

And to this im getting another extern symbol error depending on my main function. "_main" in function "__tMainCTRStartUp". I don't know whats wrong at all. I see, that the Linker-stage can't find the files, but they are implemented all in main.

C++ Primer is a good book. The only point holding me is, that it's in english. Thats kinda 3 times harder than reading a book in my motherlanguage. I will think of it.

I can't help you with this - either learn English or find a good book in your language. There's plenty of good literature on programming/3d etc. subjects in English, I have no idea about other languages though.

Now the solution is, that for multiple pointers i have to put it in brackets ? Like :

Object ****obj

...function(Object ****obj)

(***obj)->func();

Nah, it has to do with the * operator. It means different thing depending on where you use it. But that's what I am talking about - this is basics - pointers, aliases, dereferencing etc. are in the first chapters of most books.

If you feel not pissed enough to awnser another question, read below, otherwise better stop here smile.png.

Nah, I am not pissed - I'm just trying to make the point that you won't go too far if you depend for every line of code on the forum community.

A copy-paste of the error would have helped. Usually linker errors stem from a redefinition of a function/class/method or a lack of definition. Let's say for example I declare a function:


void doSomething();

If I try to use this function without providing its definition (the body of the function), I'll get a linker error.

Or for example if I redefine a function:


void doSomethingElse()
{
   //...
}

//...

void doSomethingElse()
{
   //...
}

P.S. What language do you speak? Maybe somebody on the forum may know a good C++ book in your language.

You need to use brackets whenever the operator precedence dictates a different order ( * (dereference) has a lower precedence than ->).

But I wonder why you have a pointer to pointer for the device context at all. Usually you declare your DX objects as pointers, not as double pointers. Or are you confused by e.g. D3D11CreateDeviceAndSwapChain ? Note that the double pointer on the device context is a out parameter. Hmmm, a quick google search shows Java doesn't have such a thing (like the out keyword in C#). In this case you declare a pointer, but use & (address of operator)


ID3D11DeviceContext*    immediateContext = NULL;
D3D11CreateDeviceAndSwapChain( ..., &immediateContext);


Also: Be more precise when having troubles: Copy the exact error message from your compiler/linker and also copy relevant code (function definition and function call in this case). Please use code tags when you do.

PS:...and beaten.

You need to use brackets whenever the operator precedence dictates a different order ( * (dereference) has a lower precedence than ->).

But I wonder why you have a pointer to pointer for the device context at all. Usually you declare your DX objects as pointers, not as double pointers. Or are you confused by e.g. D3D11CreateDeviceAndSwapChain ? Note that the double pointer on the device context is a out parameter. Hmmm, a quick google search shows Java doesn't have such a thing (like the out keyword in C#). In this case you declare a pointer, but use & (address of operator)


ID3D11DeviceContext*    immediateContext = NULL;
D3D11CreateDeviceAndSwapChain( ..., &immediateContext);
Also: Be more precise when having troubles: Copy the exact error message from your compiler/linker and also copy relevant code (function definition and function call in this case). Please use code tags when you do.

PS:...and beaten.

Thanks. I obviosly got confused by the pointer thing. So when I have 1 pointer in one class, I can acces the original object. When I give this pointer away as one pointer to anoother class-instance am I'm accessing the same object as in the main class ? Or do I have to give a pointer to the pointer to acces the original ?

I personally thing know I can give this pointer as one.

To the error :

1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\d3d10.h(608): warning C4005: 'D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS': Makro-Neudefinition
1> c:\program files (x86)\windows kits\8.1\include\shared\winerror.h(50445): Siehe vorherige Definition von 'D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\d3d10.h(609): warning C4005: 'D3D10_ERROR_FILE_NOT_FOUND': Makro-Neudefinition
1> c:\program files (x86)\windows kits\8.1\include\shared\winerror.h(50454): Siehe vorherige Definition von 'D3D10_ERROR_FILE_NOT_FOUND'
1> Code wird generiert...
1>Main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: void __thiscall InitD3D11::initialize(struct ID3D11Device *,struct ID3D11DeviceContext *,class Window *,struct HWND__ * *,long *,struct IDXGISwapChain *,struct ID3D11RenderTargetView *,struct ID3D11DepthStencilView *,struct ID3D11Texture2D *)" (?initialize@InitD3D11@@QAEXPAUID3D11Device@@PAUID3D11DeviceContext@@PAVWindow@@PAPAUHWND__@@PAJPAUIDXGISwapChain@@PAUID3D11RenderTargetView@@PAUID3D11DepthStencilView@@PAUID3D11Texture2D@@@Z)" in Funktion ""void __cdecl init(void)" (?init@@YAXXZ)".
1>Main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: void __thiscall InitD3D11::initPipeline(long *,struct ID3D11DeviceContext *,struct ID3D11Device *,struct ID3D11VertexShader *,struct ID3D11PixelShader *,struct ID3D10Blob *,struct ID3D10Blob *,struct ID3D11InputLayout *)" (?initPipeline@InitD3D11@@QAEXPAJPAUID3D11DeviceContext@@PAUID3D11Device@@PAUID3D11VertexShader@@PAUID3D11PixelShader@@PAUID3D10Blob@@5PAUID3D11InputLayout@@@Z)" in Funktion ""void __cdecl init(void)" (?init@@YAXXZ)".
1>Main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: void __thiscall InitD3D11::InitGraphics(long,struct ID3D11Device *,struct ID3D11DeviceContext *,class Window *,struct ID3D10Blob *,struct ID3D11InputLayout *,struct ID3D11Buffer *,struct ID3D11Buffer *,struct ID3D11ShaderResourceView *,struct ID3D11SamplerState *,struct ID3D11Buffer *,class WorldHolder *)" (?InitGraphics@InitD3D11@@QAEXJPAUID3D11Device@@PAUID3D11DeviceContext@@PAVWindow@@PAUID3D10Blob@@PAUID3D11InputLayout@@PAUID3D11Buffer@@5PAUID3D11ShaderResourceView@@PAUID3D11SamplerState@@5PAVWorldHolder@@@Z)" in Funktion ""void __cdecl init(void)" (?init@@YAXXZ)".
1>Main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: void __thiscall Draw::mainLoop(struct tagMSG *,bool *,struct ID3D11DeviceContext *,struct ID3D11Device *,class WorldHolder *,struct ID3D11RenderTargetView *,struct ID3D11DepthStencilView *,struct IDXGISwapChain *)" (?mainLoop@Draw@@QAEXPAUtagMSG@@PA_NPAUID3D11DeviceContext@@PAUID3D11Device@@PAVWorldHolder@@PAUID3D11RenderTargetView@@PAUID3D11DepthStencilView@@PAUIDXGISwapChain@@@Z)" in Funktion "_WinMain@16".
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_main" in Funktion "___tmainCRTStartup".
... : fatal error LNK1120: 5 nicht aufgelöste Externe
========== Erstellen: 0 erfolgreich, 1 fehlerhaft, 0 aktuell, 0 übersprungen ==========

... I think you can see now, why I didn't just wrote the log before instand of describing it .. It's in German.

But the main error you see is "nicht aufgelöste Externe" or the same as "nicht aufgelöste externe Verweise" what means something like "unresolved external symbols".

Code :

void somevoid()

{

draw.mainLoop(&msg, &ranCorrectly, deviceContext, device, &wHold, backbuffer, depthStencilView, swapChain);

....

( this is called in preInit(); and dont get called after mainLoop ):

directX.initialize(device, deviceContext, &wnd, &hWnd, &hResult, swapChain, backbuffer, depthStencilView, stencilImageBuffer);
directX.initPipeline(&hResult, deviceContext, device, vertexShader, pixelShader,VS, PS, inputLayout);
directX.InitGraphics(hResult, device, deviceContext, &wnd, VS, vertexLayout, vertexBuffer, indexBuffer, shaderTexture, samplerState, bPerObject, &wHold);

}

void initialize(ID3D11Device *device, ID3D11DeviceContext *deviceContext, Window *wnd, HWND *hWnd, HRESULT *hResult, IDXGISwapChain *swapChain, ID3D11RenderTargetView *backbuffer, ID3D11DepthStencilView* depthStencilView, ID3D11Texture2D* depthStencilBuffer)
{

DXGI_MODE_DESC bufferDesc;
DXGI_SWAP_CHAIN_DESC swapChainDescription;
ID3D11Texture2D *pBackBuffer;
D3D11_TEXTURE2D_DESC depthStencilDesc;
D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
D3D11_VIEWPORT viewport;

ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC));

bufferDesc.Width = *wnd->windowSizeX;
bufferDesc.Height = *wnd->windowSizeY;
bufferDesc.RefreshRate.Numerator = 60;
bufferDesc.RefreshRate.Denominator = 1;
bufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;





ZeroMemory(&swapChainDescription, sizeof(DXGI_SWAP_CHAIN_DESC));

swapChainDescription.BufferDesc = bufferDesc;
swapChainDescription.BufferCount = 4;
swapChainDescription.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDescription.BufferDesc.Width = *wnd->windowSizeX;
swapChainDescription.BufferDesc.Height = *wnd->windowSizeY;
swapChainDescription.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDescription.OutputWindow = *hWnd;
swapChainDescription.SampleDesc.Count = 8;
swapChainDescription.Windowed = TRUE;
swapChainDescription.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;

*hResult = D3D11CreateDeviceAndSwapChain
(NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
D3D11_CREATE_DEVICE_DEBUG,
NULL,
NULL,
D3D11_SDK_VERSION,
&swapChainDescription,
&swapChain,
&device,
NULL,
&deviceContext);
if (FAILED(hResult))
exit(*hResult);





*hResult = swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);
if (FAILED(hResult))
exit(*hResult);

*hResult = device->CreateRenderTargetView(pBackBuffer, NULL, &backbuffer);
if (FAILED(hResult))
exit(*hResult);





depthStencilDesc.Width = *wnd->windowSizeX;
depthStencilDesc.Height = *wnd->windowSizeY;
depthStencilDesc.MipLevels = 1;
depthStencilDesc.ArraySize = 1;
depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthStencilDesc.SampleDesc.Count = 8;
depthStencilDesc.SampleDesc.Quality = 0;
depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
depthStencilDesc.CPUAccessFlags = 0;
depthStencilDesc.MiscFlags = 0;

*hResult = device->CreateTexture2D(&depthStencilDesc, NULL, &depthStencilBuffer);
if (FAILED(hResult))
exit(*hResult);


ZeroMemory(&descDSV, sizeof(descDSV));

descDSV.Format = depthStencilDesc.Format;
descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
descDSV.Texture2D.MipSlice = 0;

*hResult = device->CreateDepthStencilView(depthStencilBuffer, NULL, &depthStencilView);
if (FAILED(hResult))
exit(*hResult);

deviceContext->OMSetRenderTargets(1, &backbuffer, depthStencilView);


ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));

viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = *wnd->windowSizeX;
viewport.Height = *wnd->windowSizeY;
viewport.MinDepth = 0.0F;
viewport.MaxDepth = 1.0F;

deviceContext->RSSetViewports(1, &viewport);

pBackBuffer->Release();

}


Please don't get shocked by the functions itself. I quickly wrote them in this quote and didn't copied them from original. But they key points are in.

There are some parts, that I know are total bullshit and are only for testing, I'll change it, when the tests are over.

Haha ... as I posted the code, I looked at the original code now .. I saw it. I forgot the Classname::functionname operator. What ever this is called in america. Thanks anyway, but one external error is left, this one :

Fehler 60 error LNK2019: Unresolved external symbol "_main" in function "___tmainCRTStartup". projectPath\MSVCRTD.lib(crtexe.obj)

I quickly translated

I thought it is the project type. So my main looks like :

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

and the subsystem is Windows

Google search: http://stackoverflow.com/questions/11247699/lnk2019-unresolved-external-symbol-main-referenced-in-function-tmaincrtstar

I fixed the error. It was a wrong entry point.

Not some basic errors to fix till start and I'm done then :)

Thanks to all here.

This topic is closed to new replies.

Advertisement