Vulkan
Vulkan copied to clipboard
Using getAssetPath() for all data accessing
https://github.com/SaschaWillems/Vulkan/blob/e1e348ac7a5b468aadc958bfd998497d6570cb49/base/VulkanUIOverlay.cpp#L75
Currently VulkanUIOverlay references the "Roboto-Medium.ttf" by relative path to the compiled binary which can results in the following error:
I suggest using getAssetPath() for all data file accessing which is defined in: https://github.com/SaschaWillems/Vulkan/blob/e1e348ac7a5b468aadc958bfd998497d6570cb49/base/vulkanexamplebase.cpp#L106
The getAssetPath is an Absolute Path. And it is defined in your cmake.
@engineer1109 Right. Absolute path is needed because the compiled binary is located in ${CMAKE_CURRENT_BINARY_DIR}/bin
which can be anywhere.
See #470 and #477
I suggest to write a smart file checker function for both relative and absolute path.
#ifndef VULKAN_BASICENGINE_FILESYSTEM_H
#define VULKAN_BASICENGINE_FILESYSTEM_H
#include <string>
#include <iostream>
#include <experimental/filesystem>
class FS{
public:
static std::string getAssetPath(std::string p){
using namespace std::experimental::filesystem;
path pa=path(std::string("../data/"+p).c_str()); //for vs2015 compatibility
path pb=path(std::string(PROJECT_ABSOLUTE_PATH+("/data/"+p)).c_str());
// std::cout<<pa.c_str()<<std::endl;
// std::cout<<pb.c_str()<<std::endl;
if(exists(pa)){
return std::string("../data/"+p);
}
else if(exists(pb)){
return std::string(PROJECT_ABSOLUTE_PATH+("/data/"+p));
}
else {
std::cout<<"Error!Could not find this file:"<<p<<std::endl;
exit(1);
}
}
};
#endif // VULKAN_BASICENGINE_FILESYSTEM_H
Look my project
https://github.com/engineer1109/LearnVulkan/blob/master/include/basicengine/vulkan_basicengine_filesystem.h
I have slightly reworked this and centralized the code for asset path handling. Loading font is now done using the getAssetPath function.