Getting garbage chars when reading GLSL files

Hi All .I run into the following problem.I load my shaders from files.The shader program ,when trying to compile, throws these errors for the vertex and fragment shaders:

Vertex info

0(12) : error C0000: syntax error, unexpected $undefined at token “<undefined>”

Fragment info

0(10) : error C0000: syntax error, unexpected $undefined at token “<undefined>”

When inspecting the loaded content of the files I can see all kinds of garbage text is attached at the beginnings and the ends of the shader files.Like this one:

#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;

I tried to change the encoding from UTF-8 top ANSI ,also tried to edit outside the visual studio but the problem still persists .Any help on this will be greatly appreciated.

Hey, that naming convention looks like some of my code.

How are you loading the shader? Since that code doesn’t look like it has any non-ASCII characters, the encoding would work just the same as UTF-8 or ASCII.

:slight_smile: .Indeed ,Alfonse,this is your code.I have been learning from your great manual. Look I am using my own “loader” not the one located in the framework class.And it worked till recently.Now it gives me all that garbage and I have no a single clue where the problem may come from.My loading code looks 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 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); (memblock, size);
	cout << "file " << fname << " loaded" << endl;
	cout << "Unable to open file " << fname << endl;
	return memblock;

file read based on example in tutorial

That code was in the section marked “Binary files”. I would be suspicious of any code that uses ios::binary when loading text files.

Really, I’d suggest going back and using the code I used.

Thanks ,that is what I am going to do.

Solved it as follows :…7344802#7344802

But still can see some garbage before “#version 330” line.Gonna switch to framework loading class.