LukasBanana / LLGL

Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal
BSD 3-Clause "New" or "Revised" License
2.05k stars 139 forks source link

Can't run the examples #61

Closed duckdoom4 closed 3 years ago

duckdoom4 commented 3 years ago

Hi, I'm trying to run the examples, but I can't get it to work.

I followed the setup instructions to install everything and it all builds fine. (I'm using visual studio 2019)

When I run the develop build for the PBR example and pick the DirectX12 option in the console I get a "failed to open file: Example.hlsl" error

I then manually setup the Debugging->Working Directory to point to the project directory, and that fixed the loading issue.

After that I get a crash on D3D12CommandContext::SetPipelineState

traced it down to:

D3D12MipGenerator::CreateComputePSO if (auto blob = DXCreateBlobFromResource(resourceID)) returning null

/* Load resource from binary data (*.rc file) */
if (HRSRC resource = FindResource(moduleHandle, MAKEINTRESOURCE(resourceID), RT_RCDATA))

I don't seem to have this .rc file. Did I miss something?

LukasBanana commented 3 years ago

Hi, unfortunately I'm not aware of a command in CMake to change the working directory, so I know this is not optimal. That being said, I described this in the first paragraph of the README.md document of the tutorials/Cpp folder.

For D3D12, all resource files are described in D3D12Builtin.rc and also the precompiled .cso files are available in the repository. Can you make sure this resource file is linked into the LLGL_Direct3D12.dll file?

duckdoom4 commented 3 years ago

I completely missed the README file in the tutorial section, so sorry for that.

And I think I know the issue now, I selected the BUILD_STATIC_LIB option. This means there is no .dll file to attach the resource to. I guess I have to manually include it to the final executable in that case?

LukasBanana commented 3 years ago

That's possible as I only run LLGL in the same project solution, so the resource files are linked to the example executables. That's of course inconvenient, but I should definitely add this info somewhere.

duckdoom4 commented 3 years ago

Thanks for the help. I managed to get it running by dragging in the .rc and .h files (onto the example project), creating a link to the original file. After that they showed up in the resource view and the project was running like it should.

beldenfox commented 3 years ago

There is a CMake solution for setting the debug working directory for both Visual Studio and Xcode. This needs some cleanup (that temporary variable annoys me) but it shows how to do it.

macro(ADD_EXAMPLE_PROJECT TEST_NAME TEST_FILES LIB_FILES)
    if(APPLE)
        add_executable(${TEST_NAME} MACOSX_BUNDLE ${TEST_FILES})
    elseif(LLGL_ANDROID_PLATFORM)
        add_library(${TEST_NAME} SHARED ${TEST_FILES})
        target_link_libraries(${TEST_NAME} log)
    else()
        add_executable(${TEST_NAME} ${TEST_FILES})
    endif()
    target_link_libraries(${TEST_NAME} ${LIB_FILES})
    set_target_properties(${TEST_NAME} PROPERTIES LINKER_LANGUAGE CXX DEBUG_POSTFIX "D")

    if(APPLE)
        get_filename_component(TMP_FOLDER ${TEST_FILES} DIRECTORY)
        set_target_properties(${TEST_NAME} PROPERTIES
            XCODE_GENERATE_SCHEME TRUE
            XCODE_SCHEME_WORKING_DIRECTORY ${TMP_FOLDER})
    endif()

    if(MSVC)
       get_filename_component(TMP_FOLDER ${TEST_FILES} DIRECTORY)
       set_target_properties(${TEST_NAME} PROPERTIES
           VS_DEBUGGER_WORKING_DIRECTORY ${TMP_FOLDER})
    endif()
endmacro() 
LukasBanana commented 3 years ago

Closing the issue as this seems to be resolved.