Reading text files in a DLL file

Customization

Microsoft Visual Studio Professional 2015, running Windows 10 Pro
Unity 5.3.1f1 (x64)
The project is built on the example of a project provided by Unity on the site . The project can be found here.


What needs to be done

I am exploring the creation of an opengl plugin (as a dll) for use with Unity. In their code example, vertex shaders and fragment are hardcoded in the code like this:

#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 do not like this approach, and I do not need its flexibility. So I wanted to put each shader in my own file and load the file using the following code snippet.

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();
}

Problem

- .dll, , , . , , .
. " ".

, . dll, , ShaderLoader::ReadShader, ?

GetModuleFileName FindFirstFile, .

, : DLL, Visual Studio, , ?

+4
1

, , DLL, . , , , .

shaderCode ReadShader, , , . , , , , undefined.

std::string , . ( ) .

+2

All Articles