I ran into the following problem. I load my shaders from files. A shader program when trying to compile these errors for vertex and fragment shaders:
Vertex information
0 (12): error C0000: syntax error, unexpected $ undefined in token ""
Fragment Information
0 (10): error C0000: syntax error, unexpected $ undefined in token ""
When checking the downloaded contents of the files, I see that all kinds of garbage text are attached at the beginning and at the ends of the shader files. Like this:
#version 330 layout (location = 0) in vec4 position; layout (location = 1) in vec4 color; smooth out vec4 theColor; void main() { gl_Position = position; theColor = color; }ýýýý««««««««þîþîþîþ
Shader loading methods are as follows:
void ShaderLoader::loadShaders(char * vertexShaderFile,char *fragmentShaderFile){ vs = loadFile(vertexShaderFile,vlen); fs = loadFile(fragmentShaderFile,flen); } char *ShaderLoader::loadFile(char *fname,GLint &fSize){ ifstream::pos_type size; char * memblock; string text; // file read based on example in cplusplus.com tutorial ifstream file (fname, ios::in|ios::binary|ios::ate); if (file.is_open()) { size = file.tellg(); fSize = (GLuint) size; memblock = new char [size]; file.seekg (0, ios::beg); file.read (memblock, size); file.close(); cout << "file " << fname << " loaded" << endl; text.assign(memblock); } else { cout << "Unable to open file " << fname << endl; exit(1); } return memblock; }
I tried to change the encoding from UTF-8 top ANSI, also tried to edit the external visual studio, but the problem still persists. Any help on this would be greatly appreciated.
source share