Sign in to follow this  
Dawoodoz

DX11 Moving graphics engine to DLL project

Recommended Posts

Dawoodoz    461
I tried to make my graphics engine into a DLL by moving all code from the DirectX example project to a new DLL project in Visual C++ 2005.
I have made a working connection between the DLL and a testing project in the same visual studio solution so that simple calls can be made.
Now I have both DXUT.h and stdafx.h included in the whole engine but only stdafx.h is forced to be included.
I have checked that the DirectX libs and stuff are included in Visual Studio.

Here are the link errors after solving many regular errors:

1>------ Build started: Project: GameEngine, Configuration: Release Win32 ------
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>SDKmisc.cpp
1>Model.cpp
1>IntegerArray.cpp
1>DXUTmisc.cpp
1>DXUTDevice11.cpp
1>DXUTcamera.cpp
1>DXUT.cpp
1>StringMethods.cpp
1>GameEngine.cpp
1>Linking...
1> Creating library C:\Users\David\Documents\Visual Studio 2005\Projects\GameEngine\Release\GameEngine.lib and object C:\Users\David\Documents\Visual Studio 2005\Projects\GameEngine\Release\GameEngine.exp
1>GameEngine.obj : error LNK2001: unresolved external symbol _D3DXMatrixMultiply@12
1>GameEngine.obj : error LNK2001: unresolved external symbol _D3DX11CompileFromFileW@44
1>GameEngine.obj : error LNK2001: unresolved external symbol _D3DXMatrixOrthoOffCenterLH@28
1>GameEngine.obj : error LNK2001: unresolved external symbol _D3DXVec3Normalize@8
1>GameEngine.obj : error LNK2001: unresolved external symbol _D3DXVec3Transform@12
1>GameEngine.obj : error LNK2001: unresolved external symbol _D3DXVec3TransformCoord@12
1>GameEngine.obj : error LNK2001: unresolved external symbol _D3DXMatrixTranspose@8
1>GameEngine.obj : error LNK2001: unresolved external symbol _D3DXMatrixScaling@16
1>GameEngine.obj : error LNK2001: unresolved external symbol _D3DXMatrixTranslation@16
1>DXUT.obj : error LNK2001: unresolved external symbol __imp__InitCommonControls@0
1>DXUTcamera.obj : error LNK2001: unresolved external symbol _D3DXQuaternionMultiply@12
1>DXUTcamera.obj : error LNK2001: unresolved external symbol _D3DXMatrixRotationQuaternion@8
1>DXUTcamera.obj : error LNK2001: unresolved external symbol _D3DXMatrixLookAtLH@16
1>DXUTcamera.obj : error LNK2001: unresolved external symbol _D3DXMatrixInverse@12
1>DXUTcamera.obj : error LNK2001: unresolved external symbol _D3DXMatrixPerspectiveFovLH@20
1>DXUTcamera.obj : error LNK2001: unresolved external symbol _D3DXMatrixRotationYawPitchRoll@16
1>DXUTcamera.obj : error LNK2001: unresolved external symbol _D3DXQuaternionRotationMatrix@8
1>DXUTcamera.obj : error LNK2001: unresolved external symbol _D3DXVec3TransformNormal@12
1>DXUTmisc.obj : error LNK2001: unresolved external symbol _DXTraceW@20
1>DXUTmisc.obj : error LNK2001: unresolved external symbol _D3DX11SaveTextureToFileW@16
1>SDKmisc.obj : error LNK2001: unresolved external symbol _D3DX11GetImageInfoFromFileW@16
1>SDKmisc.obj : error LNK2001: unresolved external symbol _D3DX11CreateTextureFromFileW@24
1>C:\Users\David\Documents\Visual Studio 2005\Projects\GameEngine\Release\GameEngine.dll : fatal error LNK1120: 22 unresolved externals
1>Build log was saved at "file://c:\Users\David\Documents\Visual Studio 2005\Projects\GameEngine\GameEngine\Release\BuildLog.htm"
1>GameEngine - 23 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Have anyone seen that before?

Is there any good general method for solving link errors?

Share this post


Link to post
Share on other sites
_the_phantom_    11250
It looks like you don't have the lib files for the D3DX functions linked into your DLL; check which files the DLL project is linking against and compare that to your exe/original project/another D3D project which uses D3DX functions.

Share this post


Link to post
Share on other sites
Dawoodoz    461
Thanks, it solved it.

Solution for anyone with the same issue:
Project's property page - Configuration Properties - Linker - Input
Additional Dependencies:
d3dcompiler.lib dxerr.lib dxguid.lib d3dx9.lib d3d9.lib winmm.lib comctl32.lib dxgi.lib d3dx11.lib d3d10.lib

Share this post


Link to post
Share on other sites
Dawoodoz    461
I have one problem remaining. I have an HLSL supershader and a header for named constant definitions used by both the HLSL shader and the engine DLL.
I don't want the user to see the HLSL file because the user would start to modify it and be unable to upgrade to another version of my engine.
If I include the shader as a static string then it can't reach the header file because that won't be released with the engine.

How can I place both files in the engine without duplicating code or making an included mess for the user?

Share this post


Link to post
Share on other sites
smasherprog    568
Have the file names declared in the header file, but defined in cpp files, not header files. So when you compile your dll, they will be in the dll, not the header.

Share this post


Link to post
Share on other sites
Dawoodoz    461
Quote:
Original post by smasherprog
Have the file names declared in the header file, but defined in cpp files, not header files. So when you compile your dll, they will be in the dll, not the header.


What would the file names refer to?

Share this post


Link to post
Share on other sites
Dawoodoz    461
Quote:
Original post by smasherprog
You said you had some constants that you want hidden from users, as well as a shader. Declare them in the header, and define them in your cpp file.


The problem is that the shader is depending on the header.
One header with macros is used by both HLSL and Cpp.


#define Common_MaxNumberOfDynamicPointLights 64

#define Common_ObjectType_Skybox 0 // This is used by the engine to draw the sky
#define Common_ObjectType_Material 1 // This is used for your objects
#define Common_ObjectType_Shadow 2 // This is used to render shadows
#define Common_ObjectType_Effect 3 // This is used for post effects
#define Common_NumberOfObjectTypes 4 // Last object type + 1

#define Common_CascadeCount 4

// The types of shaders with reused numbers in different object types to compile fewer shaders.
#define Common_FirstShadowPixelShaderType 0
#define Common_PixelShaderType_Shadow_Simple 0 //
#define Common_PixelShaderType_Shadow_Alpha 1 // D
#define Common_LastShadowPixelShaderType 1
#define Common_FirstSkyPixelShaderType 2
#define Common_PixelShaderType_Sky_Simple 2 //
#define Common_LastSkyPixelShaderType 2
#define Common_FirstMaterialPixelShaderType 3
#define Common_PixelShaderType_Material_NoTextures 3 //
#define Common_PixelShaderType_Material_DiffuseOnly 4 // D
#define Common_PixelShaderType_Material_Bump 5 // D N
#define Common_PixelShaderType_Material_SpecularBump 6 // D N S
#define Common_PixelShaderType_Material_Specular 7 // D S
#define Common_PixelShaderType_Material_Illuminated 8 // D
#define Common_PixelShaderType_Material_IlluminatedBump 9 // D N
#define Common_PixelShaderType_Material_IlluminatedSpecularBump 10 // D N S
#define Common_PixelShaderType_Material_IlluminatedSpecular 11 // D S
#define Common_LastMaterialPixelShaderType 11
#define Common_FirstEffectPixelShaderType 12
#define Common_PixelShaderType_Effect_None 12
#define Common_PixelShaderType_Effect_ADD_AB 13
#define Common_PixelShaderType_Effect_ADD_ABC 14
#define Common_PixelShaderType_Effect_ADD_ABCD 15
#define Common_PixelShaderType_Effect_Blur_Linear 16
#define Common_PixelShaderType_Effect_AddArg 17
#define Common_PixelShaderType_Effect_MultiplyWithArg 18
#define Common_PixelShaderType_Effect_RaiseToArg 19
#define Common_PixelShaderType_Effect_GrayScale 20
#define Common_LastEffectPixelShaderType 20
#define Common_NumberOfPixelShaderTypes 21 // Max pixel shader type + 1

#define Common_FirstShadowVertexShaderType 0
#define Common_VertexShaderType_Shadow 0
#define Common_VertexShaderType_AlphaShadow 1
#define Common_LastShadowVertexShaderType 1
#define Common_FirstSkyVertexShaderType 2
#define Common_VertexShaderType_Sky 2
#define Common_LastSkyVertexShaderType 2
#define Common_FirstMaterialVertexShaderType 3
#define Common_VertexShaderType_Material_Flat 3
#define Common_VertexShaderType_Material_Bump 4
#define Common_LastMaterialVertexShaderType 4
#define Common_FirstEffectVertexShaderType 5
#define Common_VertexShaderType_Effect_Standard 5
#define Common_LastEffectVertexShaderType 5
#define Common_NumberOfVertexShaderTypes 6 // Max vertex shader type + 1

Share this post


Link to post
Share on other sites
Dawoodoz    461
Quote:
Original post by smasherprog
Well, try changing them to extern const ? You are kind of stuck if you use defines and want to hide them from users in a dll.


OK, I haven't used extern constants before.
How do I reach them in both compiletime and runtime?

Share this post


Link to post
Share on other sites
smasherprog    568
Well, I havent compiled a dll and linked it to a library, so, hopefully it will work :P


In your header, do this


extern const int NumberOfLights;


In your cpp, define it

const int NumberOfLights = 10;


Then compile your dll, link it to your project, and see if it works.

Share this post


Link to post
Share on other sites
Dawoodoz    461
That seems more complicated than having to copy the header to a constant shader string because I add values more than I change them.

Can I reach the same header as both a Visual Studio resource and a regular header?

Share this post


Link to post
Share on other sites
smasherprog    568
If you are inclined to put everything into a dll, then you must compile it each time something within it changes. So, if you want to "hide" information from people who use your dll, then you will have to recompile it each time to add/change/remove something.

If your code is in a header, everyone can see it or modify it. If its in a cpp file, then you can compile it into your dll. That is really the end of it. Decide what you want to do. If its not convenient to recompile the dll for each change you make, then don't put it into a dll.

It is unnecessary to think you need to rebuild the dll for every little change you make . . . Just build everything using the full source code, and build your dll only when you want to release a build.

Share this post


Link to post
Share on other sites
Dawoodoz    461
I have configured the solution so that modified modules in the engine DLL is compiled automatically when when starting the testing project.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By gomidas
      I am trying to add normal map to my project I have an example of a cube: 
      I have normal in my shader I think. Then I set shader resource view for texture (NOT BUMP)
                  device.ImmediateContext.PixelShader.SetShaderResource(0, textureView);             device.ImmediateContext.Draw(VerticesCount,0); What should I do to set my normal map or how it is done in dx11 generally example c++?
    • By fighting_falcon93
      Imagine that we have a vertex structure that looks like this:
      struct Vertex { XMFLOAT3 position; XMFLOAT4 color; }; The vertex shader looks like this:
      cbuffer MatrixBuffer { matrix world; matrix view; matrix projection; }; struct VertexInput { float4 position : POSITION; float4 color : COLOR; }; struct PixelInput { float4 position : SV_POSITION; float4 color : COLOR; }; PixelInput main(VertexInput input) { PixelInput output; input.position.w = 1.0f; output.position = mul(input.position, world); output.position = mul(output.position, view); output.position = mul(output.position, projection); output.color = input.color; return output; } And the pixel shader looks like this:
      struct PixelInput { float4 position : SV_POSITION; float4 color : COLOR; }; float4 main(PixelInput input) : SV_TARGET { return input.color; } Now let's create a quad consisting of 2 triangles and the vertices A, B, C and D:
      // Vertex A. vertices[0].position = XMFLOAT3(-1.0f, 1.0f, 0.0f); vertices[0].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // Vertex B. vertices[1].position = XMFLOAT3( 1.0f, 1.0f, 0.0f); vertices[1].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // Vertex C. vertices[2].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); vertices[2].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // Vertex D. vertices[3].position = XMFLOAT3( 1.0f, -1.0f, 0.0f); vertices[3].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // 1st triangle. indices[0] = 0; // Vertex A. indices[1] = 3; // Vertex D. indices[2] = 2; // Vertex C. // 2nd triangle. indices[3] = 0; // Vertex A. indices[4] = 1; // Vertex B. indices[5] = 3; // Vertex D. This will result in a grey quad as shown in the image below. I've outlined the edges in red color to better illustrate the triangles:

      Now imagine that we’d want our quad to have a different color in vertex A:
      // Vertex A. vertices[0].position = XMFLOAT3(-1.0f, 1.0f, 0.0f); vertices[0].color = XMFLOAT4( 0.0f, 0.0f, 0.0f, 1.0f);
      That works as expected since there’s now an interpolation between the black color in vertex A and the grey color in vertices B, C and D. Let’s revert the previus changes and instead change the color of vertex C:
      // Vertex C. vertices[2].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); vertices[2].color = XMFLOAT4( 0.0f, 0.0f, 0.0f, 1.0f);
      As you can see, the interpolation is only done half of the way across the first triangle and not across the entire quad. This is because there's no edge between vertex C and vertex B.
      Which brings us to my question:
      I want the interpolation to go across the entire quad and not only across the triangle. So regardless of which vertex we decide to change the color of, the color interpolation should always go across the entire quad. Is there any efficient way of achieving this without adding more vertices and triangles?
      An illustration of what I'm trying to achieve is shown in the image below:

       
      Background
      This is just a very brief explanation of the problems background in case that would make it easier for you to understand the problems roots and maybe help you with finding a better solution to the problem.
      I'm trying to texture a terrain mesh in DirectX11. It's working, but I'm a bit unsatisfied with the result. When changing the terrain texture of a single vertex, the interpolation with the other vertices results in a hexagon shape instead of a squared shape:

      As the red arrows illustrate, I'd like the texture to be interpolated all the way into the corners of the quads.
    • By -Tau-
      Hello, I'm close to releasing my first game to Steam however, my game keeps failing the review process because it keeps crashing. The problem is that the game doesn't crash on my computer, on my laptop, on our family computer, on fathers laptop and i also gave 3 beta keys to people i know and they said the game hasn't crashed.
      Steam reports that the game doesn't crash on startup but few frames after a level has been started.
      What could cause something like this? I have no way of debugging this as the game works fine on every computer i have.
       
      Game is written in C++, using DirectX 11 and DXUT framework.
    • By haiiry
      I'm trying to get, basically, screenshot (each 1 second, without saving) of Direct3D11 application. Code works fine on my PC(Intel CPU, Radeon GPU) but crashes after few iterations on 2 others (Intel CPU + Intel integrated GPU, Intel CPU + Nvidia GPU).
      void extractBitmap(void* texture) { if (texture) { ID3D11Texture2D* d3dtex = (ID3D11Texture2D*)texture; ID3D11Texture2D* pNewTexture = NULL; D3D11_TEXTURE2D_DESC desc; d3dtex->GetDesc(&desc); desc.BindFlags = 0; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; desc.Usage = D3D11_USAGE_STAGING; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; HRESULT hRes = D3D11Device->CreateTexture2D(&desc, NULL, &pNewTexture); if (FAILED(hRes)) { printCon(std::string("CreateTexture2D FAILED:" + format_error(hRes)).c_str()); if (hRes == DXGI_ERROR_DEVICE_REMOVED) printCon(std::string("DXGI_ERROR_DEVICE_REMOVED -- " + format_error(D3D11Device->GetDeviceRemovedReason())).c_str()); } else { if (pNewTexture) { D3D11DeviceContext->CopyResource(pNewTexture, d3dtex); // Wokring with texture pNewTexture->Release(); } } } return; } D3D11SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast< void** >(&pBackBuffer)); extractBitmap(pBackBuffer); pBackBuffer->Release(); Crash log:
      CreateTexture2D FAILED:887a0005 DXGI_ERROR_DEVICE_REMOVED -- 887a0020 Once I comment out 
      D3D11DeviceContext->CopyResource(pNewTexture, d3dtex); 
      code works fine on all 3 PC's.
    • By Fluffy10
      Hi i'm new to this forum and was wondering if there are any good places to start learning directX 11. I bought Frank D Luna's book but it's really outdated and the projects won't even compile. I was excited to start learning from this book because it gives detailed explanations on the functions being used as well as the mathematics. Are there any tutorials / courses /books that are up to date which goes over the 3D math and functions in a detailed manner? Or where does anyone here learn directX 11? I've followed some tutorials from this website http://www.directxtutorial.com/LessonList.aspx?listid=11 which did a nice job but it doesn't explain what's happening with the math so I feel like I'm not actually learning, and it only goes up until color blending. Rasteriks tutorials doesn't go over the functions much at all or the math involved either. I'd really appreciate it if anyone can point me in the right direction, I feel really lost. Thank you
  • Popular Now