The Setup
Microsoft Visual Studio Professional 2015, running on Windows 10 Pro
Unity 5.3.1f1 (x64)
The project is built upon an example project provided by Unity on their site. The project can be found here.
That which needs to be done
I'm looking into creating a opengl plugin (in the form of a dll) for use with Unity. In their example code the vertex and fragment shaders are hard coded in the code like so:
#define VPROG_SRC(ver, attr, varying) \
ver \
attr " highp vec3 pos;\n" \
attr " lowp vec4 color;\n" \
"\n" \
varying " lowp vec4 ocolor;\n" \
"\n" \
"uniform highp mat4 worldMatrix;\n" \
"uniform highp mat4 projMatrix;\n" \
"\n" \
"void main()\n" \
"{\n" \
" gl_Position = (projMatrix * worldMatrix) * vec4(pos,1);\n" \
" ocolor = color;\n" \
"}\n" \
I don't like this approach and I don't need it's flexibility. So I wanted to put each shader in their own file and load the file using the following piece of code.
const char* ShaderLoader::ReadShader(char *filename)
{
std::string shaderCode;
std::ifstream file(filename, std::ios::in);
if (!file.good())
{
std::cout << "Can't read file " << filename << std::endl;
return nullptr;
}
file.seekg(0, std::ios::end);
shaderCode.resize((unsigned int)file.tellg());
file.seekg(0, std::ios::beg);
file.read(&shaderCode[0], shaderCode.size());
file.close();
return shaderCode.c_str();
}
The Problem
The output of my project is a .dll file and I wanted my two shaders included in that file, where they could be loaded. Maybe this is not possible, I don't know.
I've added the shaders to the project. I've also right clicked each file and chosen Include In Project.
I don't where the two files end up. Are they included in the dll file and if so what path do I need to pass to ShaderLoader::ReadShader
to read them?
I've tried to figure that out by using GetModuleFileName
and FindFirstFile
but to no success.
So ultimately the question is: Is it possible to include text files in dll libraries built with Visual Studio and if so how do I go about it?