Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Getting garbage chars when reading GLSL files

  1. #1
    Intern Contributor
    Join Date
    Mar 2011
    Location
    Israel
    Posts
    53

    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:

    Code :
     
    #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.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948

    Re: Getting garbage chars when reading GLSL files

    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.

  3. #3
    Intern Contributor
    Join Date
    Mar 2011
    Location
    Israel
    Posts
    53

    Re: Getting garbage chars when reading GLSL files

    .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:
    Code :
    void ShaderLoader::loadShaders(char * vertexShaderFile,char *fragmentShaderFile){
     
     
    	vs = loadFile(vertexShaderFile,vlen);
            fs = loadFile(fragmentShaderFile,flen);
     
    }
    char *ShaderLoader::loadFile(char *fname,GLint &amp;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;
    }

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948

    Re: Getting garbage chars when reading GLSL files

    file read based on example in cplusplus.com 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.

  5. #5
    Intern Contributor
    Join Date
    Mar 2011
    Location
    Israel
    Posts
    53

    Re: Getting garbage chars when reading GLSL files

    Thanks ,that is what I am going to do.

  6. #6
    Intern Contributor
    Join Date
    Mar 2011
    Location
    Israel
    Posts
    53

    Re: Getting garbage chars when reading GLSL files

    Solved it as follows :
    http://stackoverflow.com/questions/73446...7344802#7344802

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •